feat: integrate audit logging across authentication, course management, and user operations

Add comprehensive audit trail tracking by integrating auditService throughout the application. Track user authentication (LOGIN, REGISTER), course lifecycle (CREATE, APPROVE_COURSE, REJECT_COURSE, ENROLL), content management (CREATE/DELETE Chapter/Lesson), file operations (UPLOAD_FILE, DELETE_FILE for videos and attachments), password management (CHANGE_PASSWORD, RESET_PASSWORD), user role updates (UPDATE
This commit is contained in:
JakkrapartXD 2026-02-05 17:35:37 +07:00
parent 923c8b727a
commit 108f1b73f2
10 changed files with 701 additions and 0 deletions

View file

@ -0,0 +1,65 @@
import { AuditAction } from '@prisma/client';
export interface CreateAuditLogParams {
userId?: number;
action: AuditAction;
entityType: string;
entityId?: number;
oldValue?: any;
newValue?: any;
ipAddress?: string;
userAgent?: string;
metadata?: any;
}
export interface AuditLogFilters {
userId?: number;
action?: AuditAction;
entityType?: string;
entityId?: number;
startDate?: Date;
endDate?: Date;
page?: number;
limit?: number;
}
export interface AuditLogResponse {
id: number;
user_id: number | null;
action: AuditAction;
entity_type: string;
entity_id: number | null;
old_value: any;
new_value: any;
ip_address: string | null;
user_agent: string | null;
metadata: any;
created_at: Date;
user?: {
id: number;
username: string;
email: string;
} | null;
}
export interface ListAuditLogsResponse {
data: AuditLogResponse[];
pagination: {
page: number;
limit: number;
total: number;
totalPages: number;
};
}
export interface AuditLogSummary {
action: AuditAction;
count: number;
}
export interface AuditLogStats {
totalLogs: number;
todayLogs: number;
actionSummary: AuditLogSummary[];
recentActivity: AuditLogResponse[];
}