@dynamatix/cat-shared 0.0.84 → 0.0.85
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.
|
@@ -166,12 +166,29 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
166
166
|
const entityDescription = await resolveEntityDescription(result, auditConfig);
|
|
167
167
|
|
|
168
168
|
for (const field of auditConfig.fields) {
|
|
169
|
+
|
|
169
170
|
const hasChanged =
|
|
170
171
|
update?.$set?.hasOwnProperty(field) || update?.hasOwnProperty(field);
|
|
171
172
|
|
|
172
173
|
if (hasChanged) {
|
|
173
174
|
const newValue = update?.$set?.[field] ?? update?.[field];
|
|
174
175
|
const oldValue = this._originalDoc ? this._originalDoc[field] : '';
|
|
176
|
+
let lookupOldName;
|
|
177
|
+
let lookupNewName;
|
|
178
|
+
if (field.endsWith('Lid')) {
|
|
179
|
+
const newlookupDoc = await mongoose.models['Lookup'].findById(newValue).lean();
|
|
180
|
+
if (newlookupDoc) {
|
|
181
|
+
lookupOldName = newlookupDoc.name;
|
|
182
|
+
} else {
|
|
183
|
+
lookupOldName = '';
|
|
184
|
+
}
|
|
185
|
+
const oldlookupDoc = await mongoose.models['Lookup'].findById(oldValue).lean();
|
|
186
|
+
if (oldlookupDoc) {
|
|
187
|
+
lookupNewName = oldlookupDoc.name;
|
|
188
|
+
} else {
|
|
189
|
+
lookupNewName = '';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
175
192
|
|
|
176
193
|
if (oldValue !== newValue) {
|
|
177
194
|
const fieldDescription = await resolveDescription(field, result);
|
|
@@ -179,8 +196,8 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
179
196
|
name: fieldDescription,
|
|
180
197
|
entity: entityDescription,
|
|
181
198
|
recordId: contextId || result._id,
|
|
182
|
-
oldValue,
|
|
183
|
-
newValue,
|
|
199
|
+
oldValue: lookupOldName || oldValue,
|
|
200
|
+
newValue: lookupNewName || newValue,
|
|
184
201
|
createdBy: userId,
|
|
185
202
|
externalData: {
|
|
186
203
|
description: entityDescription,
|