refactor(api): replace new Logger() with DI LoggerService and split large files
- Migrate 30 files from `new Logger(ClassName.name)` to injected LoggerService for consistent PII masking and centralized logging config - Split prisma-admin-query.repository.ts (313→121 lines) into admin-stats.queries.ts and admin-user.queries.ts - Split admin.controller.ts (285→154 lines) into admin-moderation.controller.ts - Split prisma-listing.repository.ts (274→111 lines) into listing-read.queries.ts - Update 28 test files with mock LoggerService - All 831 tests passing, zero direct new Logger() calls remaining Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import { Injectable, Logger, type CanActivate, type ExecutionContext } from '@nestjs/common';
|
||||
import { Injectable, type CanActivate, type ExecutionContext } from '@nestjs/common';
|
||||
import { type Reflector } from '@nestjs/core';
|
||||
import { type UserRole } from '@prisma/client';
|
||||
import { type LoggerService } from '@modules/shared';
|
||||
import { ROLES_KEY } from '../decorators/roles.decorator';
|
||||
|
||||
@Injectable()
|
||||
export class RolesGuard implements CanActivate {
|
||||
private readonly logger = new Logger(RolesGuard.name);
|
||||
|
||||
constructor(private readonly reflector: Reflector) {}
|
||||
constructor(
|
||||
private readonly reflector: Reflector,
|
||||
private readonly logger: LoggerService,
|
||||
) {}
|
||||
|
||||
canActivate(context: ExecutionContext): boolean {
|
||||
const requiredRoles = this.reflector.getAllAndOverride<UserRole[]>(ROLES_KEY, [
|
||||
@@ -30,6 +32,7 @@ export class RolesGuard implements CanActivate {
|
||||
this.logger.warn(
|
||||
`Access denied: userId=${user?.sub ?? 'unknown'}, role=${user?.role ?? 'none'}, ` +
|
||||
`required=${requiredRoles.join(',')}, action=${controller}.${handler}, ip=${ip}`,
|
||||
'RolesGuard',
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user