Files
cve-dashboard/backend/helpers/auditLog.js

20 lines
724 B
JavaScript
Raw Permalink Normal View History

2026-01-29 15:10:29 -07:00
// Audit Log Helper
// Fire-and-forget insert - never blocks the response
const pool = require('../db');
2026-01-29 15:10:29 -07:00
function logAudit({ userId, username, action, entityType, entityId, details, ipAddress }) {
2026-01-29 15:10:29 -07:00
const detailsStr = details && typeof details === 'object'
? JSON.stringify(details)
: details || null;
pool.query(
2026-01-29 15:10:29 -07:00
`INSERT INTO audit_logs (user_id, username, action, entity_type, entity_id, details, ip_address)
VALUES ($1, $2, $3, $4, $5, $6, $7)`,
[userId || null, username || 'unknown', action, entityType, entityId || null, detailsStr, ipAddress || null]
).catch((err) => {
console.error('Audit log error:', err.message);
});
2026-01-29 15:10:29 -07:00
}
module.exports = logAudit;