@dynamatix/cat-shared 0.0.132 → 0.0.133
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 +45 -24
- package/package.json +1 -1
|
@@ -7,52 +7,73 @@ import FormConfigurationModel from '../models/form-configuration.model.js';
|
|
|
7
7
|
|
|
8
8
|
let onAuditLogCreated = null;
|
|
9
9
|
|
|
10
|
-
//
|
|
10
|
+
// Simple utility to get nested property - much cleaner approach
|
|
11
11
|
function getNestedProperty(obj, path) {
|
|
12
|
-
if (!
|
|
12
|
+
if (!obj || !path) return undefined;
|
|
13
13
|
|
|
14
|
-
// Handle
|
|
15
|
-
if (
|
|
14
|
+
// Handle flattened MongoDB keys first
|
|
15
|
+
if (obj[path] !== undefined) {
|
|
16
16
|
return obj[path];
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
//
|
|
20
|
-
if (obj.hasOwnProperty(path)) {
|
|
21
|
-
return obj[path];
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// Then try nested object structure
|
|
19
|
+
// Handle nested path
|
|
25
20
|
return path.split('.').reduce((current, key) => {
|
|
26
|
-
|
|
21
|
+
if (current == null) return undefined;
|
|
22
|
+
|
|
23
|
+
// Try Mongoose get method first
|
|
24
|
+
if (current.get && typeof current.get === 'function') {
|
|
25
|
+
try {
|
|
26
|
+
return current.get(key);
|
|
27
|
+
} catch (e) {
|
|
28
|
+
// Fall through to direct access
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Direct access or _doc access for Mongoose
|
|
33
|
+
return current[key] ?? current._doc?.[key];
|
|
27
34
|
}, obj);
|
|
28
35
|
}
|
|
29
36
|
|
|
30
|
-
//
|
|
37
|
+
// Simple utility to check if nested property exists
|
|
31
38
|
function hasNestedProperty(obj, path) {
|
|
32
|
-
if (!
|
|
39
|
+
if (!obj || !path) return false;
|
|
33
40
|
|
|
34
|
-
// Handle
|
|
35
|
-
if (!path.includes('.')) {
|
|
36
|
-
return obj.hasOwnProperty(path);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// First check if the flattened key exists (MongoDB style: "additionalData.statusLid")
|
|
41
|
+
// Handle flattened MongoDB keys first
|
|
40
42
|
if (obj.hasOwnProperty(path)) {
|
|
41
43
|
return true;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
|
-
//
|
|
46
|
+
// Check nested path
|
|
45
47
|
const keys = path.split('.');
|
|
46
48
|
let current = obj;
|
|
47
49
|
|
|
48
|
-
for (
|
|
49
|
-
if (
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
if (current == null) return false;
|
|
52
|
+
|
|
53
|
+
// Try Mongoose get method first
|
|
54
|
+
if (current.get && typeof current.get === 'function') {
|
|
55
|
+
try {
|
|
56
|
+
const value = current.get(key);
|
|
57
|
+
if (value !== undefined) {
|
|
58
|
+
current = value;
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
} catch (e) {
|
|
62
|
+
// Fall through to direct access
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// Check direct access or _doc access
|
|
67
|
+
if (current[key] !== undefined) {
|
|
68
|
+
current = current[key];
|
|
69
|
+
} else if (current._doc?.[key] !== undefined) {
|
|
70
|
+
current = current._doc[key];
|
|
71
|
+
} else {
|
|
50
72
|
return false;
|
|
51
73
|
}
|
|
52
|
-
current = current[keys[i]];
|
|
53
74
|
}
|
|
54
75
|
|
|
55
|
-
return
|
|
76
|
+
return true;
|
|
56
77
|
}
|
|
57
78
|
|
|
58
79
|
// Optionally, define custom resolvers here
|