forked from wangziqi/gongxue-base
feat(rbac): register RbacModule and PermissionGuard in AppModule
This commit is contained in:
@@ -3,9 +3,15 @@ import { APP_GUARD } from '@nestjs/core';
|
||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
|
||||
import { Student, Room, Occupancy, RoomExpense, PersonalExpense, Bill, BillItem, User, OperationLog, Deposit, Classroom, Tenant, ClassroomRental } from './entities';
|
||||
import {
|
||||
Student, Room, Occupancy, RoomExpense, PersonalExpense,
|
||||
Bill, BillItem, User, OperationLog, Deposit, Classroom,
|
||||
Tenant, ClassroomRental, Permission, Role,
|
||||
} from './entities';
|
||||
import { AuthModule } from './auth/auth.module';
|
||||
import { RbacModule } from './rbac/rbac.module';
|
||||
import { StudentsModule } from './students/students.module';
|
||||
import { PermissionGuard } from './auth/guards/permission.guard';
|
||||
import { RoomsModule } from './rooms/rooms.module';
|
||||
import { OccupanciesModule } from './occupancies/occupancies.module';
|
||||
import { ExpensesModule } from './expenses/expenses.module';
|
||||
@@ -29,6 +35,11 @@ import { ClassroomRentalsModule } from './classroom-rentals/classroom-rentals.mo
|
||||
inject: [ConfigService],
|
||||
useFactory: (config: ConfigService): any => {
|
||||
const dbType = config.get('DB_TYPE', 'sqlite');
|
||||
const allEntities = [
|
||||
Student, Room, Occupancy, RoomExpense, PersonalExpense,
|
||||
Bill, BillItem, User, OperationLog, Deposit, Classroom,
|
||||
Tenant, ClassroomRental, Permission, Role,
|
||||
];
|
||||
if (dbType === 'mysql') {
|
||||
return {
|
||||
type: 'mysql' as const,
|
||||
@@ -37,7 +48,7 @@ import { ClassroomRentalsModule } from './classroom-rentals/classroom-rentals.mo
|
||||
username: config.get('DB_USERNAME', 'root'),
|
||||
password: config.get('DB_PASSWORD', ''),
|
||||
database: config.get('DB_DATABASE', 'dorm_billing'),
|
||||
entities: [Student, Room, Occupancy, RoomExpense, PersonalExpense, Bill, BillItem, User, OperationLog, Deposit, Classroom, Tenant, ClassroomRental],
|
||||
entities: allEntities,
|
||||
synchronize: true,
|
||||
charset: 'utf8mb4',
|
||||
};
|
||||
@@ -45,12 +56,13 @@ import { ClassroomRentalsModule } from './classroom-rentals/classroom-rentals.mo
|
||||
return {
|
||||
type: 'better-sqlite3' as const,
|
||||
database: config.get('DB_DATABASE', 'dorm_billing.db'),
|
||||
entities: [Student, Room, Occupancy, RoomExpense, PersonalExpense, Bill, BillItem, User, OperationLog, Deposit, Classroom, Tenant, ClassroomRental],
|
||||
entities: allEntities,
|
||||
synchronize: true,
|
||||
};
|
||||
},
|
||||
}),
|
||||
AuthModule,
|
||||
RbacModule,
|
||||
StudentsModule,
|
||||
RoomsModule,
|
||||
OccupanciesModule,
|
||||
@@ -65,6 +77,7 @@ import { ClassroomRentalsModule } from './classroom-rentals/classroom-rentals.mo
|
||||
],
|
||||
providers: [
|
||||
{ provide: APP_GUARD, useClass: ThrottlerGuard },
|
||||
{ provide: APP_GUARD, useClass: PermissionGuard },
|
||||
],
|
||||
})
|
||||
export class AppModule {}
|
||||
|
||||
Reference in New Issue
Block a user