@dynamatix/cat-shared 0.0.88 → 0.0.90
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -87,6 +87,13 @@ async function resolveEntityDescription(doc, auditConfig) {
|
|
|
87
87
|
return value;
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
// Add new function to resolve deletion description
|
|
91
|
+
async function resolveDeletionDescription(doc, auditConfig) {
|
|
92
|
+
if (!auditConfig.descriptionResolutorForDeletion) return '';
|
|
93
|
+
const expression = auditConfig.descriptionResolutorForDeletion;
|
|
94
|
+
return await resolveExpressionDescription(doc, expression, 'direct');
|
|
95
|
+
}
|
|
96
|
+
|
|
90
97
|
function applyAuditMiddleware(schema, collectionName) {
|
|
91
98
|
// Handle creation audit
|
|
92
99
|
schema.post('save', async function (doc) {
|
|
@@ -103,6 +110,7 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
103
110
|
// Per-field logs
|
|
104
111
|
if (auditConfig.fields?.length) {
|
|
105
112
|
for (const field of auditConfig.fields) {
|
|
113
|
+
let lookupName;
|
|
106
114
|
const newValue = doc[field];
|
|
107
115
|
if (field.endsWith('Lid')) {
|
|
108
116
|
const newlookupDoc = await mongoose.models['Lookup'].findById(newValue).lean();
|
|
@@ -222,9 +230,10 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
222
230
|
const contextId = context?.contextId;
|
|
223
231
|
|
|
224
232
|
const entityDescription = await resolveEntityDescription(result, auditConfig);
|
|
233
|
+
const deletionDescription = await resolveDeletionDescription(result, auditConfig);
|
|
225
234
|
|
|
226
235
|
const log = {
|
|
227
|
-
name: 'Entity Deletion',
|
|
236
|
+
name: deletionDescription || 'Entity Deletion',
|
|
228
237
|
entity: entityDescription,
|
|
229
238
|
recordId: contextId || result._id,
|
|
230
239
|
oldValue: '',
|
|
@@ -6,6 +6,7 @@ const auditConfigSchema = new mongoose.Schema({
|
|
|
6
6
|
trackCreation: { type: Boolean, default: false },
|
|
7
7
|
trackDeletion: { type: Boolean, default: false },
|
|
8
8
|
descriptionResolutorForExternalData: { type: String, default: null },
|
|
9
|
+
descriptionResolutorForDeletion: { type: String, default: null },
|
|
9
10
|
});
|
|
10
11
|
|
|
11
12
|
const AuditConfigModel = mongoose.models.AuditConfig || mongoose.model('AuditConfig', auditConfigSchema);
|