forked from UKSOURCE/cms.hailearning.edu.vn
feat: implement comprehensive audit logging system
This commit is contained in:
25
audit/writeAuditLog.js
Normal file
25
audit/writeAuditLog.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const AuditLog = require("../models/auditLog");
|
||||
const RequestMeta = require("../utils/requestMeta");
|
||||
async function writeAuditLog({
|
||||
model,
|
||||
documentId,
|
||||
action,
|
||||
before,
|
||||
after,
|
||||
changes = [],
|
||||
req,
|
||||
}) {
|
||||
await AuditLog.create({
|
||||
model,
|
||||
documentId,
|
||||
action,
|
||||
before,
|
||||
after,
|
||||
changes,
|
||||
ipAddress: RequestMeta.getClientIp(req),
|
||||
userAgent: RequestMeta.getUserAgent(req),
|
||||
performedBy: req.session?.user?.id || req.user?.id || null,
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = writeAuditLog;
|
||||
Reference in New Issue
Block a user