@dynamatix/cat-shared 0.0.84 → 0.0.86
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.
|
@@ -104,13 +104,21 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
104
104
|
if (auditConfig.fields?.length) {
|
|
105
105
|
for (const field of auditConfig.fields) {
|
|
106
106
|
const newValue = doc[field];
|
|
107
|
+
if (field.endsWith('Lid')) {
|
|
108
|
+
const newlookupDoc = await mongoose.models['Lookup'].findById(newValue).lean();
|
|
109
|
+
if (newlookupDoc) {
|
|
110
|
+
lookupName = newlookupDoc.name;
|
|
111
|
+
} else {
|
|
112
|
+
lookupName = '';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
107
115
|
const fieldDescription = await resolveDescription(field, doc);
|
|
108
116
|
logs.push({
|
|
109
117
|
name: fieldDescription,
|
|
110
118
|
entity: entityDescription,
|
|
111
119
|
recordId: contextId || doc._id,
|
|
112
120
|
oldValue: null,
|
|
113
|
-
newValue,
|
|
121
|
+
newValue: lookupName || newValue,
|
|
114
122
|
createdBy: userId,
|
|
115
123
|
externalData: {
|
|
116
124
|
description: entityDescription,
|
|
@@ -166,12 +174,29 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
166
174
|
const entityDescription = await resolveEntityDescription(result, auditConfig);
|
|
167
175
|
|
|
168
176
|
for (const field of auditConfig.fields) {
|
|
177
|
+
|
|
169
178
|
const hasChanged =
|
|
170
179
|
update?.$set?.hasOwnProperty(field) || update?.hasOwnProperty(field);
|
|
171
180
|
|
|
172
181
|
if (hasChanged) {
|
|
173
182
|
const newValue = update?.$set?.[field] ?? update?.[field];
|
|
174
183
|
const oldValue = this._originalDoc ? this._originalDoc[field] : '';
|
|
184
|
+
let lookupOldName;
|
|
185
|
+
let lookupNewName;
|
|
186
|
+
if (field.endsWith('Lid')) {
|
|
187
|
+
const newlookupDoc = await mongoose.models['Lookup'].findById(newValue).lean();
|
|
188
|
+
if (newlookupDoc) {
|
|
189
|
+
lookupOldName = newlookupDoc.name;
|
|
190
|
+
} else {
|
|
191
|
+
lookupOldName = '';
|
|
192
|
+
}
|
|
193
|
+
const oldlookupDoc = await mongoose.models['Lookup'].findById(oldValue).lean();
|
|
194
|
+
if (oldlookupDoc) {
|
|
195
|
+
lookupNewName = oldlookupDoc.name;
|
|
196
|
+
} else {
|
|
197
|
+
lookupNewName = '';
|
|
198
|
+
}
|
|
199
|
+
}
|
|
175
200
|
|
|
176
201
|
if (oldValue !== newValue) {
|
|
177
202
|
const fieldDescription = await resolveDescription(field, result);
|
|
@@ -179,8 +204,8 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
179
204
|
name: fieldDescription,
|
|
180
205
|
entity: entityDescription,
|
|
181
206
|
recordId: contextId || result._id,
|
|
182
|
-
oldValue,
|
|
183
|
-
newValue,
|
|
207
|
+
oldValue: lookupOldName || oldValue,
|
|
208
|
+
newValue: lookupNewName || newValue,
|
|
184
209
|
createdBy: userId,
|
|
185
210
|
externalData: {
|
|
186
211
|
description: entityDescription,
|