@dynamatix/cat-shared 0.0.74 → 0.0.76
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.
|
@@ -56,6 +56,7 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
56
56
|
log.externalData.contextId = contextId;
|
|
57
57
|
}
|
|
58
58
|
await AuditLog.create(log);
|
|
59
|
+
await updateContextAuditCount(contextId, 1);
|
|
59
60
|
|
|
60
61
|
if (onAuditLogCreated) {
|
|
61
62
|
await onAuditLogCreated([log], contextId);
|
|
@@ -94,7 +95,7 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
94
95
|
const { oldValue: resolvedOld, newValue: resolvedNew } =
|
|
95
96
|
await resolveAuditValues(field, oldValue, newValue);
|
|
96
97
|
|
|
97
|
-
|
|
98
|
+
let externalData = {};
|
|
98
99
|
if (auditConfig.descriptionResolutorForExternalData) {
|
|
99
100
|
externalData.description = await resolveExternalData(auditConfig.descriptionResolutorForExternalData, result[auditConfig.descriptionResolutorForExternalData])
|
|
100
101
|
externalData.contextId = contextId || result._id;
|
|
@@ -113,6 +114,7 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
113
114
|
|
|
114
115
|
if (logs.length) {
|
|
115
116
|
await AuditLog.insertMany(logs);
|
|
117
|
+
await updateContextAuditCount(contextId, logs.length);
|
|
116
118
|
if (onAuditLogCreated) {
|
|
117
119
|
await onAuditLogCreated(logs, contextId);
|
|
118
120
|
}
|
|
@@ -120,6 +122,14 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
120
122
|
});
|
|
121
123
|
}
|
|
122
124
|
|
|
125
|
+
async function updateContextAuditCount(contextId, count) {
|
|
126
|
+
if(!contextId) return;
|
|
127
|
+
const model = mongoose.models['Application'];
|
|
128
|
+
const context = await model.findById(contextId);
|
|
129
|
+
context.newAuditRecordsCount = Number(context.newAuditRecordsCount || 0) + Number(count ? count : 1);
|
|
130
|
+
await context.save();
|
|
131
|
+
}
|
|
132
|
+
|
|
123
133
|
export function registerAuditHook(callback) {
|
|
124
134
|
onAuditLogCreated = callback;
|
|
125
135
|
}
|