You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Every admin action (create, update, delete, login, logout) is recorded in the audit log. The AuditLog entity stores what happened, who did it, and when. The AuditService is injected into other modules to log events at key points.
Acceptance Criteria
Create backend/src/modules/audit/audit-log.entity.ts with @Entity("audit_logs"):
Index on (restaurantId, createdAt DESC) — primary read pattern
Create backend/src/modules/audit/audit.service.ts with AuditService:
log(entry: Partial<AuditLog>): Promise<void> — creates and saves an audit log entry; never throws (wrap in try/catch and console.error on failure — audit logging must not break the main flow)
Labels:
backenddatabaseauditnestjsArea:
backend/src/modules/audit/audit-log.entity.ts,backend/src/modules/audit/audit.service.ts,backend/src/modules/audit/audit.module.tsDifficulty: Intermediate
Description
Every admin action (create, update, delete, login, logout) is recorded in the audit log. The
AuditLogentity stores what happened, who did it, and when. TheAuditServiceis injected into other modules to log events at key points.Acceptance Criteria
backend/src/modules/audit/audit-log.entity.tswith@Entity("audit_logs"):id(UUID, primary, generated),action(varchar 50 — action label like"CREATE_MENU_ITEM"),entityType(varchar 50 — e.g."menu"),entityId(varchar, nullable),adminId(UUID, nullable),adminUsername(varchar 100, nullable — denormalised for speed),details(text, nullable — human-readable summary),ipAddress(varchar 45, nullable),userAgent(text, nullable),restaurantId(UUID),createdAt(CreateDateColumn)(restaurantId, createdAt DESC)— primary read patternbackend/src/modules/audit/audit.service.tswithAuditService:log(entry: Partial<AuditLog>): Promise<void>— creates and saves an audit log entry; never throws (wrap in try/catch andconsole.erroron failure — audit logging must not break the main flow)findAll(restaurantId: string, limit?: number): Promise<AuditLog[]>— ordered bycreatedAt DESC, limitedfindByAdmin(adminId: string, restaurantId: string): Promise<AuditLog[]>backend/src/modules/audit/audit.module.ts— exportsAuditServiceso other modules can inject itAuditService.logis intentionally fire-and-forget — callers do notawaitit in hot paths