payservedb 10.1.1 → 10.1.2

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
@@ -101,6 +101,7 @@ const models = {
101
101
  Levy: require("./src/models/levy"),
102
102
  LevyType: require("./src/models/levytype"),
103
103
  LevyContract: require("./src/models/levycontract"),
104
+ FacilityAccountSnapshot: require("./src/models/facility_account_snapshot"),
104
105
  ContractPaymentReceipt: require("./src/models/levy_payment_receipt"),
105
106
  DepositSchema: require("./src/models/levy_deposits"),
106
107
  ReceiptCounter: require("./src/models/receipt_counter"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "10.1.1",
3
+ "version": "10.1.2",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,26 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // One row per facility per calendar month. Written by the month-end cron
4
+ // (source "cron") or the historical backfill (source "backfill").
5
+ const facilityAccountSnapshotSchema = new mongoose.Schema({
6
+ facilityId: {
7
+ type: mongoose.Schema.Types.ObjectId,
8
+ ref: 'Facility',
9
+ required: true
10
+ },
11
+ yearMonth: { type: String, required: true }, // "YYYY-MM"
12
+ powerAccounts: { type: Number, default: 0 },
13
+ waterAccounts: { type: Number, default: 0 },
14
+ leaseAccounts: { type: Number, default: 0 },
15
+ levyAccounts: { type: Number, default: 0 },
16
+ source: { type: String, enum: ['cron', 'backfill'], required: true },
17
+ snapshotAt: { type: Date, default: Date.now }
18
+ }, {
19
+ timestamps: true
20
+ });
21
+
22
+ facilityAccountSnapshotSchema.index({ facilityId: 1, yearMonth: 1 }, { unique: true });
23
+
24
+ const FacilityAccountSnapshot = mongoose.model('FacilityAccountSnapshot', facilityAccountSnapshotSchema);
25
+
26
+ module.exports = FacilityAccountSnapshot;