File size: 748 Bytes
cfbb685
 
 
 
 
 
 
 
 
 
 
 
 
 
7b0c22b
cfbb685
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import { prisma } from './prisma';
import { logger } from '../logger';

export const auditService = {
    /**
     * Log a sensitive action to the AuditLog table.
     */
    async log(params: {
        action: string;
        actorId?: string;
        resourceId?: string;
        details?: Record<string, any>;
    }) {
        try {
            await prisma.auditLog.create({
                data: {
                    action: params.action,
                    actorId: params.actorId,
                    resourceId: params.resourceId,
                    details: params.details || {}
                }
            });
        } catch (err) {
            logger.error({ err, params }, '[AUDIT] Failed to save audit log');
        }
    }
};