feat: implement audit logging system with service, controller, and interceptor to track user actions across core services

This commit is contained in:
pradeepkumar
2026-04-28 11:12:25 +05:30
parent 4eda556059
commit 80c6fd1d71
27 changed files with 895 additions and 29 deletions

View File

@@ -166,6 +166,9 @@ model User {
// Verification actions (admin)
verificationActions VerificationHistory[] @relation("VerificationActions")
// Audit Log (actor)
auditLogs AuditLog[]
@@index([email])
@@index([role])
@@index([status])
@@ -797,3 +800,27 @@ model VerificationHistory {
@@index([createdAt])
@@map("verification_history")
}
// ============================================
// AUDIT LOG
// ============================================
model AuditLog {
id String @id @default(uuid())
actorId String? // null = system / unauthenticated
actorRole String? // USER, AGENT, ADMIN, SUPER_ADMIN, SYSTEM
action String // see AuditAction enum in audit.constants.ts
resourceType String? // User, AgentProfile, Subscription, Payment, etc.
resourceId String?
metadata Json? // { before, after, reason, params, ... }
ipAddress String?
userAgent String?
createdAt DateTime @default(now())
actor User? @relation(fields: [actorId], references: [id], onDelete: SetNull)
@@index([actorId, createdAt])
@@index([resourceType, resourceId])
@@index([action, createdAt])
@@index([createdAt])
@@map("audit_logs")
}