payservedb 10.0.1 → 10.0.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/index.js CHANGED
@@ -163,6 +163,7 @@ const models = {
163
163
  MonthlyWaterMeterHistory: require("./src/models/water_meter_monthly_history"),
164
164
  WaterPrepaidCredit: require("./src/models/water_prepaid_credit"),
165
165
  WaterPrepaidDebit: require("./src/models/water_prepaid_debit"),
166
+ WaterSensorGateway: require("./src/models/water_sensor_gateway"),
166
167
  MeterLog: require("./src/models/water_meter_communication_logs"),
167
168
  CashPayment: require("./src/models/cashpayment"),
168
169
  VasPayment: require("./src/models/vas_payments"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "10.0.1",
3
+ "version": "10.0.3",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -147,7 +147,7 @@ const combinedInvoiceSchema = new mongoose.Schema(
147
147
  type: {
148
148
  type: String,
149
149
  required: true,
150
- enum: ["levy", "lease", "water", "service", "utility", "contract"],
150
+ enum: ["levy", "lease", "water", "power", "service", "utility", "contract"],
151
151
  },
152
152
  description: {
153
153
  type: String,
@@ -159,8 +159,21 @@ const LevyContractSchema = new Schema(
159
159
  type: Number,
160
160
  default: 0
161
161
  },
162
+ // Was declared as [String] while updateUpfrontPaymentTracking
163
+ // (generate_upfront_invoice.js) has always pushed structured
164
+ // objects here - every upfront invoice's tracking update threw a
165
+ // CastError after the invoice itself was already created and
166
+ // synced, making the whole generation look like it failed.
162
167
  processedPeriods: {
163
- type: [String],
168
+ type: [{
169
+ _id: false,
170
+ label: String,
171
+ rangeStart: Date,
172
+ rangeEnd: Date,
173
+ isProrated: Boolean,
174
+ invoiceId: { type: mongoose.Schema.Types.ObjectId, ref: 'Invoice', default: null },
175
+ processedAt: { type: Date, default: Date.now },
176
+ }],
164
177
  default: []
165
178
  },
166
179
  numberOfMonths: {
@@ -86,9 +86,14 @@ quickBooksInvoiceMappingSchema.index(
86
86
  { facilityId: 1, qbConfigId: 1, sourceType: 1, payserveInvoiceId: 1 },
87
87
  { unique: true },
88
88
  );
89
+ // sparse is a no-op on a compound index once every other key (facilityId,
90
+ // qbConfigId) is always present - MongoDB only excludes a doc from a sparse
91
+ // compound index when ALL of its keys are missing, so every mapping row
92
+ // missing qbInvoiceId still got indexed as qbInvoiceId: null and collided.
93
+ // partialFilterExpression is the correct null-safe fix.
89
94
  quickBooksInvoiceMappingSchema.index(
90
95
  { facilityId: 1, qbConfigId: 1, qbInvoiceId: 1 },
91
- { unique: true, sparse: true },
96
+ { unique: true, partialFilterExpression: { qbInvoiceId: { $type: "string" } } },
92
97
  );
93
98
 
94
99
  module.exports = { schema: quickBooksInvoiceMappingSchema };
@@ -13,9 +13,12 @@ const quickBooksOutboundSyncStateSchema = new mongoose.Schema(
13
13
  ref: "QuickBooksConfig",
14
14
  required: true,
15
15
  },
16
+ // "Invoice" is invoice_service's own scheduler leg; "InvoiceCreate" is
17
+ // backend_main's outbound_sync.js leg - two distinct sync passes writing
18
+ // to this shared collection, not a naming duplicate.
16
19
  entity: {
17
20
  type: String,
18
- enum: ["Customer", "Invoice", "Payment", "InvoiceVoid", "Vendor"],
21
+ enum: ["Customer", "Invoice", "InvoiceCreate", "Payment", "InvoiceVoid", "Vendor"],
19
22
  required: true,
20
23
  },
21
24
  status: {
@@ -29,6 +32,18 @@ const quickBooksOutboundSyncStateSchema = new mongoose.Schema(
29
32
  processed: { type: Number, default: 0 },
30
33
  skipped: { type: Number, default: 0 },
31
34
  errors: { type: Number, default: 0 },
35
+ // Capped per-record breakdown for admin visibility ("what actually got
36
+ // looked at"), not just aggregate counts. Each sync run overwrites this
37
+ // with its own findings - not a running log.
38
+ details: [
39
+ {
40
+ _id: false,
41
+ id: String,
42
+ label: String,
43
+ status: { type: String, enum: ["processed", "skipped", "error"] },
44
+ error: String,
45
+ },
46
+ ],
32
47
  },
33
48
  lastError: { type: String, default: null },
34
49
  },
@@ -114,9 +114,12 @@ const quickBooksPaymentMappingSchema = new mongoose.Schema(
114
114
  { timestamps: true },
115
115
  );
116
116
 
117
+ // sparse is a no-op on a compound index once facilityId/qbConfigId are
118
+ // always present - see quickbooks_invoice_mapping.js for the full
119
+ // explanation. partialFilterExpression is the correct null-safe fix.
117
120
  quickBooksPaymentMappingSchema.index(
118
121
  { facilityId: 1, qbConfigId: 1, qbPaymentId: 1 },
119
- { unique: true, sparse: true },
122
+ { unique: true, partialFilterExpression: { qbPaymentId: { $type: "string" } } },
120
123
  );
121
124
 
122
125
  module.exports = { schema: quickBooksPaymentMappingSchema };
@@ -71,9 +71,12 @@ quickBooksVendorMappingSchema.index(
71
71
  { facilityId: 1, qbConfigId: 1, payserveSupplierId: 1 },
72
72
  { unique: true, partialFilterExpression: { payserveSupplierId: { $exists: true } } },
73
73
  );
74
+ // sparse is a no-op on a compound index once facilityId/qbConfigId are
75
+ // always present - see quickbooks_invoice_mapping.js for the full
76
+ // explanation. partialFilterExpression is the correct null-safe fix.
74
77
  quickBooksVendorMappingSchema.index(
75
78
  { facilityId: 1, qbConfigId: 1, qbVendorId: 1 },
76
- { unique: true, sparse: true },
79
+ { unique: true, partialFilterExpression: { qbVendorId: { $type: "string" } } },
77
80
  );
78
81
 
79
82
  module.exports = { schema: quickBooksVendorMappingSchema };
@@ -0,0 +1,33 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ const waterSensorGatewaySchema = new mongoose.Schema({
4
+ gatewayId: {
5
+ type: String,
6
+ required: true,
7
+ trim: true,
8
+ unique: true
9
+ },
10
+ facilityId: {
11
+ type: mongoose.Schema.Types.ObjectId,
12
+ ref: 'Facility',
13
+ required: true,
14
+ index: true
15
+ },
16
+ name: {
17
+ type: String,
18
+ trim: true,
19
+ default: ''
20
+ },
21
+ assignedBy: {
22
+ type: mongoose.Schema.Types.ObjectId,
23
+ ref: 'User',
24
+ default: null
25
+ }
26
+ }, {
27
+ timestamps: true,
28
+ collection: 'water_sensor_gateways'
29
+ });
30
+
31
+ const WaterSensorGateway = mongoose.model('WaterSensorGateway', waterSensorGatewaySchema);
32
+
33
+ module.exports = WaterSensorGateway;