- Introduced new columns `status`, `created_by`, and `updated_by` in the `users` table to track user status and ownership. - Updated the `employees` table to include a foreign key reference to the `users` table via `user_id`. - Created migration script `0012_users_primary.sql` to apply these changes to the database schema. - Enhanced the `EmployeesService` and `EmployeesRepository` to support user assignments and related data retrieval. - Updated DTOs and service methods to reflect the new user and employee relationships. - Added unit tests to validate the new functionality and ensure data integrity. - Modified existing controllers to accommodate the new fields and relationships in user and employee management.
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
import { Module } from '@nestjs/common';
|
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
|
import { APP_GUARD } from '@nestjs/core';
|
|
import { JwtModule } from '@nestjs/jwt';
|
|
import { PassportModule } from '@nestjs/passport';
|
|
import { ThrottlerGuard, ThrottlerModule } from '@nestjs/throttler';
|
|
import { JwtAuthGuard } from '../../common/guards/jwt-auth.guard';
|
|
import { PrivilegesGuard } from '../../common/guards/privileges.guard';
|
|
import { PrivilegesModule } from '../privileges/privileges.module';
|
|
import { UsersModule } from '../users/users.module';
|
|
import { AuthController } from './auth.controller';
|
|
import { AuthService } from './auth.service';
|
|
import { RefreshTokensRepository } from './refresh-tokens.repository';
|
|
import { RevokedAccessTokensRepository } from './revoked-access-tokens.repository';
|
|
import { JwtStrategy } from './strategies/jwt.strategy';
|
|
|
|
@Module({
|
|
imports: [
|
|
UsersModule,
|
|
PrivilegesModule,
|
|
PassportModule.register({ defaultStrategy: 'jwt' }),
|
|
JwtModule.registerAsync({
|
|
imports: [ConfigModule],
|
|
inject: [ConfigService],
|
|
useFactory: (config: ConfigService) => ({
|
|
secret: config.getOrThrow<string>('JWT_ACCESS_SECRET'),
|
|
signOptions: {
|
|
expiresIn: config.getOrThrow<string>(
|
|
'JWT_ACCESS_EXPIRES_IN',
|
|
) as `${number}${'s' | 'm' | 'h' | 'd'}`,
|
|
},
|
|
}),
|
|
}),
|
|
ThrottlerModule.forRoot({
|
|
skipIf: () => process.env.NODE_ENV === 'test',
|
|
throttlers: [{ ttl: 60_000, limit: 100 }],
|
|
}),
|
|
],
|
|
controllers: [AuthController],
|
|
providers: [
|
|
AuthService,
|
|
RefreshTokensRepository,
|
|
RevokedAccessTokensRepository,
|
|
JwtStrategy,
|
|
// Registration order = execution order: JWT before privileges.
|
|
{ provide: APP_GUARD, useClass: JwtAuthGuard },
|
|
{ provide: APP_GUARD, useClass: PrivilegesGuard },
|
|
{ provide: APP_GUARD, useClass: ThrottlerGuard },
|
|
],
|
|
exports: [AuthService],
|
|
})
|
|
export class AuthModule {}
|