import { Global, Module } from '@nestjs/common'; import { APP_INTERCEPTOR } from '@nestjs/core'; import { TypeOrmModule } from '@nestjs/typeorm'; import { AuditController } from './audit.controller'; import { AuditInterceptor } from './audit.interceptor'; import { AuditLog } from './entities/audit-log.entity'; import { AuditLogRepository } from './audit-log.repository'; import { AuditService } from './audit.service'; /** * Backoffice audit trail. * * `AuditInterceptor` is bound through `APP_INTERCEPTOR`, so it applies to every * route in the application without touching the 488 mutating handlers * individually. Coverage therefore follows `AUDIT_ENDPOINTS`: a new route is * audited as soon as it appears in that map, and unknown routes are skipped * rather than recorded with an empty title. * * Global so other modules can inject `AuditService` to record domain events * that do not map cleanly onto an HTTP request. */ @Global() @Module({ imports: [TypeOrmModule.forFeature([AuditLog])], controllers: [AuditController], providers: [ AuditLogRepository, AuditService, { provide: APP_INTERCEPTOR, useClass: AuditInterceptor }, ], exports: [AuditService, AuditLogRepository], }) export class AuditModule {}