26 lines
921 B
JavaScript
26 lines
921 B
JavaScript
'use strict';
|
|
|
|
module.exports = (sequelize, DataTypes) => {
|
|
const AuditLog = sequelize.define('AuditLog', {
|
|
id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
|
|
organizationId: { type: DataTypes.INTEGER },
|
|
userId: { type: DataTypes.INTEGER },
|
|
userRole: { type: DataTypes.STRING },
|
|
action: { type: DataTypes.STRING, allowNull: false },
|
|
entityType: { type: DataTypes.STRING },
|
|
entityId: { type: DataTypes.INTEGER },
|
|
details: {
|
|
type: DataTypes.TEXT,
|
|
get() { try { return JSON.parse(this.getDataValue('details') || '{}'); } catch { return {}; } },
|
|
set(v) { this.setDataValue('details', JSON.stringify(v)); },
|
|
},
|
|
ipAddress: { type: DataTypes.STRING },
|
|
userAgent: { type: DataTypes.STRING },
|
|
}, {
|
|
updatedAt: false,
|
|
createdAt: 'createdAt',
|
|
});
|
|
|
|
return { AuditLog };
|
|
};
|