@dynamatix/gb-schemas 0.21.1 → 0.21.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/gb-schemas",
3
- "version": "0.21.1",
3
+ "version": "0.21.2",
4
4
  "description": "All the schemas for gatehouse bank back-end.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -37,6 +37,16 @@ export default function mongooseEncryption(schema, options) {
37
37
  }
38
38
  });
39
39
 
40
+
41
+ // Encrypt before update operations (single or multiple documents)
42
+ schema.pre("update", function (result) {
43
+ if (Array.isArray(result)) {
44
+ result.forEach(doc => doc.set(decryptObject(doc.toObject(), collectionName)));
45
+ } else {
46
+ result.set(encryptObject(result.toObject(), collectionName)); // Decrypt single document
47
+ }
48
+ });
49
+
40
50
  // Decrypt after update operations (single or multiple documents)
41
51
  schema.post("update", function (result) {
42
52
  if (Array.isArray(result)) {
@@ -46,6 +56,13 @@ export default function mongooseEncryption(schema, options) {
46
56
  }
47
57
  });
48
58
 
59
+ // Encrypt after updateOne operations
60
+ schema.pre("updateOne", function (result) {
61
+ if (result && result.toObject) {
62
+ result.set(encryptObject(result.toObject(), collectionName)); // Decrypt single document
63
+ }
64
+ });
65
+
49
66
  // Decrypt after updateOne operations
50
67
  schema.post("updateOne", function (result) {
51
68
  if (result && result.toObject) {
@@ -53,6 +70,12 @@ export default function mongooseEncryption(schema, options) {
53
70
  }
54
71
  });
55
72
 
73
+ schema.pre("findOneAndUpdate", function (result) {
74
+ if (result && result.toObject) {
75
+ result.set(encryptObject(result.toObject(), collectionName)); // Decrypt single document
76
+ }
77
+ });
78
+
56
79
  // Decrypt after find operations (e.g., find, findMany)
57
80
  schema.post("find", function (docs) {
58
81
  console.log("find", docs);
@@ -73,6 +96,7 @@ export default function mongooseEncryption(schema, options) {
73
96
  if (doc) doc.set(decryptObject(doc.toObject(), collectionName)); // Decrypt single document
74
97
  });
75
98
 
99
+
76
100
  // Decrypt after findOneAndUpdate operations
77
101
  schema.post("findOneAndUpdate", function (doc) {
78
102
  console.log("findOneAndUpdate", doc);