payservedb 6.6.6 → 6.6.7

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": "payservedb",
3
- "version": "6.6.6",
3
+ "version": "6.6.7",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -65,6 +65,35 @@ const LevyContractSchema = new Schema(
65
65
  updatedBy: {
66
66
  type: mongoose.Schema.Types.ObjectId,
67
67
  ref: 'User'
68
+ },
69
+ // New termination-specific fields
70
+ terminationDate: {
71
+ type: Date
72
+ },
73
+ terminationReason: {
74
+ type: String
75
+ },
76
+ terminatedBy: {
77
+ type: mongoose.Schema.Types.ObjectId,
78
+ ref: 'User'
79
+ },
80
+ // Disable/reactivation tracking
81
+ disabledDate: {
82
+ type: Date
83
+ },
84
+ disabledBy: {
85
+ type: mongoose.Schema.Types.ObjectId,
86
+ ref: 'User'
87
+ },
88
+ disabledReason: {
89
+ type: String
90
+ },
91
+ reactivatedDate: {
92
+ type: Date
93
+ },
94
+ reactivatedBy: {
95
+ type: mongoose.Schema.Types.ObjectId,
96
+ ref: 'User'
68
97
  }
69
98
  },
70
99
  {
@@ -107,10 +136,32 @@ LevyContractSchema.pre('save', function (next) {
107
136
  }
108
137
  });
109
138
 
139
+ // Pre-save middleware to handle termination and disable date logic
140
+ LevyContractSchema.pre('save', function (next) {
141
+ // Set termination date when status changes to Terminated
142
+ if (this.status === 'Terminated' && !this.terminationDate) {
143
+ this.terminationDate = new Date();
144
+ }
145
+
146
+ // Set disabled date when status changes to Inactive
147
+ if (this.status === 'Inactive' && !this.disabledDate && this.isModified('status')) {
148
+ this.disabledDate = new Date();
149
+ }
150
+
151
+ // Set reactivated date when status changes from Inactive to Active
152
+ if (this.status === 'Active' && this.isModified('status') && this.disabledDate) {
153
+ this.reactivatedDate = new Date();
154
+ }
155
+
156
+ next();
157
+ });
158
+
110
159
  // Index for efficient queries
111
160
  LevyContractSchema.index({ levyId: 1, unitId: 1, status: 1 });
112
161
  LevyContractSchema.index({ facilityId: 1 });
113
162
  LevyContractSchema.index({ customerId: 1 });
163
+ LevyContractSchema.index({ status: 1 });
164
+ LevyContractSchema.index({ terminationDate: 1 });
114
165
 
115
166
  module.exports = {
116
167
  schema: LevyContractSchema,