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 { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
import { TypeOrmModule } from '@nestjs/typeorm';
|
import { TypeOrmModule } from '@nestjs/typeorm';
|
||||||
import { ThrottlerModule, ThrottlerGuard } from '@nestjs/throttler';
|
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 { AuthModule } from './auth/auth.module';
|
||||||
|
import { RbacModule } from './rbac/rbac.module';
|
||||||
import { StudentsModule } from './students/students.module';
|
import { StudentsModule } from './students/students.module';
|
||||||
|
import { PermissionGuard } from './auth/guards/permission.guard';
|
||||||
import { RoomsModule } from './rooms/rooms.module';
|
import { RoomsModule } from './rooms/rooms.module';
|
||||||
import { OccupanciesModule } from './occupancies/occupancies.module';
|
import { OccupanciesModule } from './occupancies/occupancies.module';
|
||||||
import { ExpensesModule } from './expenses/expenses.module';
|
import { ExpensesModule } from './expenses/expenses.module';
|
||||||
@@ -29,6 +35,11 @@ import { ClassroomRentalsModule } from './classroom-rentals/classroom-rentals.mo
|
|||||||
inject: [ConfigService],
|
inject: [ConfigService],
|
||||||
useFactory: (config: ConfigService): any => {
|
useFactory: (config: ConfigService): any => {
|
||||||
const dbType = config.get('DB_TYPE', 'sqlite');
|
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') {
|
if (dbType === 'mysql') {
|
||||||
return {
|
return {
|
||||||
type: 'mysql' as const,
|
type: 'mysql' as const,
|
||||||
@@ -37,7 +48,7 @@ import { ClassroomRentalsModule } from './classroom-rentals/classroom-rentals.mo
|
|||||||
username: config.get('DB_USERNAME', 'root'),
|
username: config.get('DB_USERNAME', 'root'),
|
||||||
password: config.get('DB_PASSWORD', ''),
|
password: config.get('DB_PASSWORD', ''),
|
||||||
database: config.get('DB_DATABASE', 'dorm_billing'),
|
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,
|
synchronize: true,
|
||||||
charset: 'utf8mb4',
|
charset: 'utf8mb4',
|
||||||
};
|
};
|
||||||
@@ -45,12 +56,13 @@ import { ClassroomRentalsModule } from './classroom-rentals/classroom-rentals.mo
|
|||||||
return {
|
return {
|
||||||
type: 'better-sqlite3' as const,
|
type: 'better-sqlite3' as const,
|
||||||
database: config.get('DB_DATABASE', 'dorm_billing.db'),
|
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,
|
synchronize: true,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
AuthModule,
|
AuthModule,
|
||||||
|
RbacModule,
|
||||||
StudentsModule,
|
StudentsModule,
|
||||||
RoomsModule,
|
RoomsModule,
|
||||||
OccupanciesModule,
|
OccupanciesModule,
|
||||||
@@ -65,6 +77,7 @@ import { ClassroomRentalsModule } from './classroom-rentals/classroom-rentals.mo
|
|||||||
],
|
],
|
||||||
providers: [
|
providers: [
|
||||||
{ provide: APP_GUARD, useClass: ThrottlerGuard },
|
{ provide: APP_GUARD, useClass: ThrottlerGuard },
|
||||||
|
{ provide: APP_GUARD, useClass: PermissionGuard },
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class AppModule {}
|
export class AppModule {}
|
||||||
|
|||||||
Reference in New Issue
Block a user