feat: implement audit logging system with service, controller, and interceptor to track user actions across core services
This commit is contained in:
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user