payservedb 6.6.5 → 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.5",
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,
@@ -15,12 +15,16 @@ const visitLogSchema = new mongoose.Schema({
15
15
  type: String,
16
16
  required: false
17
17
  },
18
+ phoneNumber: {
19
+ type: String,
20
+ trim: true
21
+ },
18
22
  residentId: {
19
23
  type: mongoose.Schema.Types.ObjectId,
20
24
  },
21
- qrCode:{
22
- type:Boolean,
23
- required:false
25
+ qrCode: {
26
+ type: Boolean,
27
+ required: false
24
28
  },
25
29
  houseNumber: {
26
30
  type: String,
@@ -34,26 +38,26 @@ const visitLogSchema = new mongoose.Schema({
34
38
  type: Date, // Changed to Date for better handling of time
35
39
  required: false
36
40
  },
37
- days:{
38
- type:Number,
39
- required:false
41
+ days: {
42
+ type: Number,
43
+ required: false
40
44
  },
41
- division:{
42
- type:String,
43
- required:false
45
+ division: {
46
+ type: String,
47
+ required: false
44
48
  },
45
- entryPoint:{
46
- type:String,
47
- required:false
49
+ entryPoint: {
50
+ type: String,
51
+ required: false
48
52
  },
49
- exitPoint:{
50
- type:String,
51
- required:false
53
+ exitPoint: {
54
+ type: String,
55
+ required: false
52
56
  },
53
57
  status: {
54
58
  type: String,
55
59
  required: true,
56
- enum: ['Visit Confirmation', 'Scheduled', 'Checked In','Checked Out', 'Cancelled'] // Define valid statuses
60
+ enum: ['Visit Confirmation', 'Scheduled', 'Checked In', 'Checked Out', 'Cancelled'] // Define valid statuses
57
61
  // Define valid statuses
58
62
  },
59
63
  vehicle: {
@@ -66,10 +70,10 @@ const visitLogSchema = new mongoose.Schema({
66
70
  type: Number,
67
71
  required: false
68
72
  },
69
- requestedBy:{
70
- type:mongoose.Schema.Types.ObjectId,
71
- ref:"User",
72
- required:false
73
+ requestedBy: {
74
+ type: mongoose.Schema.Types.ObjectId,
75
+ ref: "User",
76
+ required: false
73
77
  },
74
78
  facilityId: {
75
79
  type: mongoose.Schema.Types.ObjectId,