@dynamatix/cat-shared 0.0.71 → 0.0.73

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.
@@ -29,8 +29,8 @@ async function resolveExternalData(descriptionResolutorForExternalData, recordId
29
29
  const map = await ValueReferenceMap.findOne({ field: descriptionResolutorForExternalData });
30
30
  const Model = mongoose.models[map.model];
31
31
  if (!Model) return "";
32
- const doc = Model.findById(recordId).lean()
33
- return doc[descriptionResolutorForExternalData];
32
+ const doc = await Model.findById(recordId).lean()
33
+ return doc[map.displayField];
34
34
  }
35
35
 
36
36
  function applyAuditMiddleware(schema, collectionName) {
@@ -45,14 +45,15 @@ function applyAuditMiddleware(schema, collectionName) {
45
45
 
46
46
  const log = {
47
47
  name: `${collectionName} created`,
48
- recordId: doc._id,
48
+ recordId: contextId || doc._id,
49
49
  oldValue: null,
50
50
  newValue: 'Document created',
51
51
  createdBy: userId,
52
52
  contextId
53
53
  };
54
54
  if (auditConfig.descriptionResolutorForExternalData) {
55
- log.externalData.description = resolveExternalData(auditConfig.descriptionResolutorForExternalData, doc[descriptionResolutorForExternalData])
55
+ log.externalData.description = await resolveExternalData(auditConfig.descriptionResolutorForExternalData, doc[descriptionResolutorForExternalData])
56
+ log.externalData.contextId = contextId;
56
57
  }
57
58
  await AuditLog.create(log);
58
59
 
@@ -95,15 +96,15 @@ function applyAuditMiddleware(schema, collectionName) {
95
96
 
96
97
  let externalData={};
97
98
  if (auditConfig.descriptionResolutorForExternalData) {
98
- externalData.description = resolveExternalData(auditConfig.descriptionResolutorForExternalData, doc[descriptionResolutorForExternalData])
99
+ externalData.description = await resolveExternalData(auditConfig.descriptionResolutorForExternalData, result[auditConfig.descriptionResolutorForExternalData])
100
+ externalData.contextId = contextId || result._id;
99
101
  }
100
102
  logs.push({
101
103
  name: `${collectionName}.${field}`,
102
- recordId: result._id,
104
+ recordId: contextId || result._id,
103
105
  oldValue: resolvedOld,
104
106
  newValue: resolvedNew,
105
107
  createdBy: userId,
106
- contextId,
107
108
  externalData
108
109
  });
109
110
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/cat-shared",
3
- "version": "0.0.71",
3
+ "version": "0.0.73",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"