payservedb 8.8.2 → 8.8.4
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
|
@@ -52,7 +52,7 @@ const customerTicketSchema = new mongoose.Schema({
|
|
|
52
52
|
},
|
|
53
53
|
source: {
|
|
54
54
|
type: String,
|
|
55
|
-
enum: ['portal', 'email', 'phone', 'chat', 'in_person', 'mobile_app'],
|
|
55
|
+
enum: ['portal', 'email', 'phone', 'chat', 'in_person', 'mobile_app', 'whatsapp'],
|
|
56
56
|
default: 'portal'
|
|
57
57
|
},
|
|
58
58
|
custom_caller: {
|
|
@@ -99,27 +99,46 @@ const waterMeterSchema = new mongoose.Schema({
|
|
|
99
99
|
type: String,
|
|
100
100
|
trim: true
|
|
101
101
|
},
|
|
102
|
-
valveType: {
|
|
102
|
+
valveType: {
|
|
103
103
|
type: String,
|
|
104
104
|
enum: ['automatic', 'manual'],
|
|
105
105
|
default: 'automatic'
|
|
106
106
|
},
|
|
107
|
-
accountBalance: {
|
|
107
|
+
accountBalance: {
|
|
108
108
|
type: Number,
|
|
109
109
|
default: 0
|
|
110
110
|
},
|
|
111
|
-
negativeBalance: {
|
|
111
|
+
negativeBalance: {
|
|
112
112
|
type: Number,
|
|
113
113
|
default: 0
|
|
114
114
|
},
|
|
115
|
+
|
|
116
|
+
// --- Meter Classification ---
|
|
117
|
+
meterCategory: {
|
|
118
|
+
type: String,
|
|
119
|
+
required: true,
|
|
120
|
+
enum: ['unit', 'bulk', 'floor'],
|
|
121
|
+
default: 'unit',
|
|
122
|
+
index: true
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
// Retained for backward compatibility — mirrors meterCategory === 'bulk'
|
|
115
126
|
bulkMeter: {
|
|
116
127
|
type: Boolean,
|
|
117
|
-
default: false,
|
|
128
|
+
default: false,
|
|
118
129
|
index: true
|
|
119
130
|
},
|
|
131
|
+
|
|
132
|
+
// Used when meterCategory === 'bulk'
|
|
120
133
|
bulkMeterDescription: {
|
|
121
134
|
type: String,
|
|
122
|
-
enum: ['City Council Bulk', 'Borehole Bulk', 'Bulk Inlet', 'Bulk Outlet','Bulk Borehole Outlet', 'Common Area'],
|
|
135
|
+
enum: ['City Council Bulk', 'Borehole Bulk', 'Bulk Inlet', 'Bulk Outlet', 'Bulk Borehole Outlet', 'Common Area'],
|
|
136
|
+
trim: true
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
// Used when meterCategory === 'floor' — free-text floor label e.g. "Ground Floor", "Floor 3"
|
|
140
|
+
floorDescription: {
|
|
141
|
+
type: String,
|
|
123
142
|
trim: true
|
|
124
143
|
}
|
|
125
144
|
|
|
@@ -127,6 +146,30 @@ const waterMeterSchema = new mongoose.Schema({
|
|
|
127
146
|
timestamps: true
|
|
128
147
|
});
|
|
129
148
|
|
|
149
|
+
// --- Validation: enforce category-specific field rules ---
|
|
150
|
+
waterMeterSchema.pre('validate', function (next) {
|
|
151
|
+
// Keep bulkMeter boolean in sync with meterCategory
|
|
152
|
+
if (this.meterCategory === 'bulk') {
|
|
153
|
+
this.bulkMeter = true;
|
|
154
|
+
|
|
155
|
+
if (!this.bulkMeterDescription) {
|
|
156
|
+
return next(new Error('bulkMeterDescription is required for bulk meters'));
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
this.bulkMeter = false;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (this.meterCategory === 'floor' && !this.floorDescription) {
|
|
163
|
+
return next(new Error('floorDescription is required for floor meters'));
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
if (this.meterCategory === 'unit' && !this.unitId) {
|
|
167
|
+
return next(new Error('unitId is required for unit meters'));
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
next();
|
|
171
|
+
});
|
|
172
|
+
|
|
130
173
|
waterMeterSchema.index({ meterNumber: 1, status: 1 });
|
|
131
174
|
|
|
132
175
|
const WaterMeter = mongoose.model('WaterMeter', waterMeterSchema);
|