@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.
@@ -7,52 +7,73 @@ import FormConfigurationModel from '../models/form-configuration.model.js';
7
7
 
8
8
  let onAuditLogCreated = null;
9
9
 
10
- // Utility function to safely access nested properties
10
+ // Simple utility to get nested property - much cleaner approach
11
11
  function getNestedProperty(obj, path) {
12
- if (!path || !obj) return undefined;
12
+ if (!obj || !path) return undefined;
13
13
 
14
- // Handle simple property access
15
- if (!path.includes('.')) {
14
+ // Handle flattened MongoDB keys first
15
+ if (obj[path] !== undefined) {
16
16
  return obj[path];
17
17
  }
18
18
 
19
- // First check if the flattened key exists (MongoDB style: "additionalData.statusLid")
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
- return current && current[key] !== undefined ? current[key] : undefined;
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
- // Utility function to check if nested property exists in object
37
+ // Simple utility to check if nested property exists
31
38
  function hasNestedProperty(obj, path) {
32
- if (!path || !obj) return false;
39
+ if (!obj || !path) return false;
33
40
 
34
- // Handle simple property access
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
- // Then check nested object structure
46
+ // Check nested path
45
47
  const keys = path.split('.');
46
48
  let current = obj;
47
49
 
48
- for (let i = 0; i < keys.length - 1; i++) {
49
- if (!current || !current.hasOwnProperty(keys[i])) {
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 current && current.hasOwnProperty(keys[keys.length - 1]);
76
+ return true;
56
77
  }
57
78
 
58
79
  // Optionally, define custom resolvers here
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/cat-shared",
3
- "version": "0.0.132",
3
+ "version": "0.0.133",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"