@dynamatix/gb-schemas 1.3.302 → 1.3.304

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.
@@ -1 +1 @@
1
- {"version":3,"file":"applicant-expenditure.model.d.ts","sourceRoot":"","sources":["../../applicants/applicant-expenditure.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,KAAK,EAAe,MAAM,wBAAwB,CAAC;AAoH5D,QAAA,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAsE,CAAC;AACtG,eAAe,yBAAyB,CAAC"}
1
+ {"version":3,"file":"applicant-expenditure.model.d.ts","sourceRoot":"","sources":["../../applicants/applicant-expenditure.model.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,QAAQ,MAAM,UAAU,CAAC;AAChC,OAAO,EAAE,KAAK,EAAe,MAAM,wBAAwB,CAAC;AA0J5D,QAAA,MAAM,yBAAyB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAAsE,CAAC;AACtG,eAAe,yBAAyB,CAAC"}
@@ -55,6 +55,10 @@ const applicantExpenditureSchema = new mongoose.Schema({
55
55
  toJSON: { virtuals: true },
56
56
  toObject: { virtuals: true },
57
57
  });
58
+ // Helper function to extract actual value from update object
59
+ function extractActualValue(update) {
60
+ return update.actual !== undefined ? update.actual : (update.$set && update.$set.actual !== undefined ? update.$set.actual : undefined);
61
+ }
58
62
  // Middleware to track actual field updates
59
63
  applicantExpenditureSchema.pre('save', function (next) {
60
64
  if (this.isModified('actual')) {
@@ -65,25 +69,51 @@ applicantExpenditureSchema.pre('save', function (next) {
65
69
  // Middleware for update operations
66
70
  applicantExpenditureSchema.pre('findOneAndUpdate', function (next) {
67
71
  const update = this.getUpdate();
68
- if (update && (update.actual !== undefined || (update.$set && update.$set.actual !== undefined))) {
69
- this.set({ isActualUpdated: true });
72
+ const newActualValue = extractActualValue(update);
73
+ if (newActualValue !== undefined) {
74
+ // We need to get the existing document to compare the new value with the current value
75
+ // This requires an async operation, so we'll handle it differently
76
+ const query = this.getQuery();
77
+ // Find the current document to get the existing actual value
78
+ ApplicantExpenditureModel.findOne(query).then(existingDoc => {
79
+ if (existingDoc && existingDoc.actual !== newActualValue) {
80
+ // Values are different, so we'll set isActualUpdated in the post-hook
81
+ this._shouldSetActualUpdated = true;
82
+ }
83
+ next();
84
+ }).catch(err => {
85
+ next(err);
86
+ });
87
+ return; // Don't call next() here, we'll call it in the promise
70
88
  }
71
89
  next();
72
90
  });
73
91
  applicantExpenditureSchema.pre('updateOne', function (next) {
74
92
  const update = this.getUpdate();
75
- if (update && (update.actual !== undefined || (update.$set && update.$set.actual !== undefined))) {
93
+ const newActualValue = extractActualValue(update);
94
+ if (newActualValue !== undefined) {
76
95
  this.set({ isActualUpdated: true });
77
96
  }
78
97
  next();
79
98
  });
80
99
  applicantExpenditureSchema.pre('updateMany', function (next) {
81
100
  const update = this.getUpdate();
82
- if (update && (update.actual !== undefined || (update.$set && update.$set.actual !== undefined))) {
101
+ const newActualValue = extractActualValue(update);
102
+ if (newActualValue !== undefined) {
83
103
  this.set({ isActualUpdated: true });
84
104
  }
85
105
  next();
86
106
  });
107
+ // Post middleware for findOneAndUpdate to check if actual value actually changed
108
+ applicantExpenditureSchema.post('findOneAndUpdate', function (doc) {
109
+ if (doc && this._shouldSetActualUpdated === true) {
110
+ // The pre-hook determined that the actual value actually changed
111
+ doc.isActualUpdated = true;
112
+ doc.save(); // Save the updated flag
113
+ // Clean up the flag
114
+ delete this._shouldSetActualUpdated;
115
+ }
116
+ });
87
117
  // Virtual property for essentialExpenditure
88
118
  const virtualEssentialExpenditure = applicantExpenditureSchema.virtual("ExpenditureType", {
89
119
  ref: "Lookup",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dynamatix/gb-schemas",
3
- "version": "1.3.302",
3
+ "version": "1.3.304",
4
4
  "description": "All the schemas for gatehouse bank back-end",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",