@dynamatix/cat-shared 0.0.83 → 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.
@@ -32,7 +32,7 @@ async function resolveExpressionDescription(doc, expression, resolverType) {
32
32
  async function resolveDescription(field, doc) {
33
33
  const modelName = doc.constructor.modelName;
34
34
  const config = await ValueReferenceMap.findOne({ field, model: modelName });
35
- if (!config) return '';
35
+ if (!config) return field;
36
36
 
37
37
  if (config.descriptionField && config.descriptionField.includes('${')) {
38
38
  return await resolveExpressionDescription(doc, config.descriptionField, config.descriptionResolverType);
@@ -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,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/cat-shared",
3
- "version": "0.0.83",
3
+ "version": "0.0.85",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"