forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauditService.js
More file actions
54 lines (50 loc) · 1.93 KB
/
Copy pathauditService.js
File metadata and controls
54 lines (50 loc) · 1.93 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
const logger = require('../lib/logger');
const auditLogRepository = require('../db/auditLogRepository');
class AuditService {
/**
* Log an action to the audit logs
* @param {Object} params
* @param {string} params.entityType - e.g., 'campaign', 'reward', 'user'
* @param {number|string} params.entityId - ID of the affected resource
* @param {string} params.action - e.g., 'CREATE', 'UPDATE', 'DELETE'
* @param {number} params.performedBy - User ID of the actor
* @param {Object} [params.beforeState] - Previous state of the resource
* @param {Object} [params.afterState] - New state of the resource
* @param {string} [params.source] - e.g., 'admin_panel', 'api'
* @param {Object} [params.details] - Any extra details
*/
static async log({ entityType, entityId, action, performedBy, beforeState, afterState, source, details }) {
try {
return await auditLogRepository.logAudit({
entityType,
entityId,
action,
performedBy,
beforeState,
afterState,
source,
details
});
} catch (error) {
// We don't want audit logging failure to crash the main transaction usually,
// but we should log it aggressively.
logger.error('AuditLogService Error:', error);
throw error;
}
}
/**
* Query audit logs
* @param {Object} filters
*/
static async getLogs(filters) {
return await auditLogRepository.getAuditLogs(filters);
}
/**
* Export audit logs as CSV
* @param {Object} filters - Same filters as getLogs
*/
static async exportCSV(filters) {
return await auditLogRepository.exportAuditLogsCSV(filters);
}
}
module.exports = AuditService;