diff --git a/src/modules/admin-auth/admin-audit.service.ts b/src/modules/admin-auth/admin-audit.service.ts index 0f5871b..d98be51 100644 --- a/src/modules/admin-auth/admin-audit.service.ts +++ b/src/modules/admin-auth/admin-audit.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@nestjs/common'; -import { QueueService } from '../../infrastructure/queue/queue.service'; +import { PrismaService } from '../../infrastructure/database/prisma.service'; export interface AuditLogInput { adminUserId: string; @@ -16,21 +16,22 @@ export interface AuditLogInput { @Injectable() export class AdminAuditService { - constructor(private readonly queue: QueueService) {} + constructor(private readonly prisma: PrismaService) {} - /** Async audit log via BullMQ — never blocks the main operation */ async log(input: AuditLogInput) { - await this.queue.add('audit-logs', { - adminUserId: input.adminUserId, - action: input.action, - resourceType: input.resourceType ?? null, - resourceId: input.resourceId ?? null, - beforeJson: input.beforeJson ?? null, - afterJson: input.afterJson ?? null, - ip: input.ip ?? null, - userAgent: input.userAgent ?? null, - riskLevel: input.riskLevel ?? this.defaultRisk(input.action), - reason: input.reason ?? null, + await this.prisma.adminAuditLog.create({ + data: { + adminUserId: input.adminUserId, + action: input.action, + resourceType: input.resourceType ?? null, + resourceId: input.resourceId ?? null, + beforeJson: input.beforeJson ?? null, + afterJson: input.afterJson ?? null, + ip: input.ip ?? null, + userAgent: input.userAgent ?? null, + riskLevel: input.riskLevel ?? this.defaultRisk(input.action), + reason: input.reason ?? null, + }, }); }