@dynamatix/cat-shared 0.0.99 → 0.0.100
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.
- package/middlewares/audit.middleware.js +13 -11
- package/package.json +1 -1
|
@@ -97,18 +97,20 @@ async function resolveDeletionDescription(doc, auditConfig) {
|
|
|
97
97
|
return await resolveExpressionDescription(doc, expression, 'direct');
|
|
98
98
|
}
|
|
99
99
|
|
|
100
|
-
// Utility to build a fieldName -> dataType map from formConfig.sections
|
|
101
|
-
function
|
|
100
|
+
// Utility to build a fieldName -> dataType map from multiple formConfig.sections
|
|
101
|
+
function buildFieldTypeMapFromConfigs(formConfigs) {
|
|
102
102
|
const map = {};
|
|
103
|
-
function
|
|
103
|
+
function extractFields(sections) {
|
|
104
104
|
for (const section of sections || []) {
|
|
105
105
|
if (section.fields) {
|
|
106
106
|
for (const f of section.fields) map[f.fieldName] = f.dataType;
|
|
107
107
|
}
|
|
108
|
-
if (section.sections)
|
|
108
|
+
if (section.sections) extractFields(section.sections);
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
|
-
|
|
111
|
+
for (const config of formConfigs) {
|
|
112
|
+
extractFields(config.sections);
|
|
113
|
+
}
|
|
112
114
|
return map;
|
|
113
115
|
}
|
|
114
116
|
|
|
@@ -118,9 +120,9 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
118
120
|
const auditConfig = await AuditConfigModel.findOne({ collectionName });
|
|
119
121
|
if (!auditConfig?.trackCreation) return;
|
|
120
122
|
|
|
121
|
-
// Fetch form
|
|
122
|
-
const
|
|
123
|
-
const fieldTypeMap =
|
|
123
|
+
// Fetch all form configs and build fieldTypeMap once
|
|
124
|
+
const formConfigs = await FormConfigurationModel.find({ collectionName });
|
|
125
|
+
const fieldTypeMap = buildFieldTypeMapFromConfigs(formConfigs);
|
|
124
126
|
|
|
125
127
|
const context = getContext();
|
|
126
128
|
const userId = context?.userId || 'anonymous';
|
|
@@ -191,9 +193,9 @@ function applyAuditMiddleware(schema, collectionName) {
|
|
|
191
193
|
const auditConfig = await AuditConfigModel.findOne({ collectionName });
|
|
192
194
|
if (!auditConfig?.fields?.length) return;
|
|
193
195
|
|
|
194
|
-
// Fetch form
|
|
195
|
-
const
|
|
196
|
-
const fieldTypeMap =
|
|
196
|
+
// Fetch all form configs and build fieldTypeMap once
|
|
197
|
+
const formConfigs = await FormConfigurationModel.find({ collectionName });
|
|
198
|
+
const fieldTypeMap = buildFieldTypeMapFromConfigs(formConfigs);
|
|
197
199
|
|
|
198
200
|
const update = this.getUpdate();
|
|
199
201
|
let logs = [];
|