payservedb 8.8.2 → 8.8.3

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": "8.8.2",
3
+ "version": "8.8.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -42,6 +42,7 @@ const serviceRequestSchema = new mongoose.Schema({
42
42
  frequency: { type: String },
43
43
  amount: { type: Number },
44
44
  attachment: { type: String },
45
+ quote: { type: String },
45
46
  notes: { type: String },
46
47
  }, {
47
48
  timestamps: true
@@ -99,27 +99,46 @@ const waterMeterSchema = new mongoose.Schema({
99
99
  type: String,
100
100
  trim: true
101
101
  },
102
- valveType: { // Specific to smart meters
102
+ valveType: {
103
103
  type: String,
104
104
  enum: ['automatic', 'manual'],
105
105
  default: 'automatic'
106
106
  },
107
- accountBalance: { // Specific to smart meters
107
+ accountBalance: {
108
108
  type: Number,
109
109
  default: 0
110
110
  },
111
- negativeBalance: { // Specific to smart meters
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, // false means normal meter
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);