Audit logging feature files
This commit is contained in:
21
backend/helpers/auditLog.js
Normal file
21
backend/helpers/auditLog.js
Normal file
@@ -0,0 +1,21 @@
|
||||
// Audit Log Helper
|
||||
// Fire-and-forget insert - never blocks the response
|
||||
|
||||
function logAudit(db, { userId, username, action, entityType, entityId, details, ipAddress }) {
|
||||
const detailsStr = details && typeof details === 'object'
|
||||
? JSON.stringify(details)
|
||||
: details || null;
|
||||
|
||||
db.run(
|
||||
`INSERT INTO audit_logs (user_id, username, action, entity_type, entity_id, details, ip_address)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?)`,
|
||||
[userId || null, username || 'unknown', action, entityType, entityId || null, detailsStr, ipAddress || null],
|
||||
(err) => {
|
||||
if (err) {
|
||||
console.error('Audit log error:', err.message);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
module.exports = logAudit;
|
||||
Reference in New Issue
Block a user