payservedb 8.9.0 → 8.9.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.
Files changed (193) hide show
  1. package/.env +2 -2
  2. package/ZOHO_INTEGRATION_SCHEMA.md +644 -644
  3. package/index.js +327 -326
  4. package/package.json +17 -17
  5. package/src/models/account.js +52 -52
  6. package/src/models/agent_departments.js +59 -59
  7. package/src/models/agent_notifications.js +53 -53
  8. package/src/models/agent_performance.js +127 -127
  9. package/src/models/agent_roles.js +77 -77
  10. package/src/models/agents.js +154 -154
  11. package/src/models/apilog.js +18 -18
  12. package/src/models/approvalsWorkflows.js +49 -49
  13. package/src/models/archivedapilog.js +18 -18
  14. package/src/models/asset.js +92 -92
  15. package/src/models/assetsAssignment.js +64 -64
  16. package/src/models/auditTrail.js +346 -346
  17. package/src/models/bankdetails.js +47 -47
  18. package/src/models/billerAddress.js +124 -124
  19. package/src/models/booking_invoice.js +165 -165
  20. package/src/models/bookinganalytics.js +63 -63
  21. package/src/models/bookingconfig.js +45 -45
  22. package/src/models/bookingproperty.js +179 -179
  23. package/src/models/bookingreservation.js +239 -239
  24. package/src/models/bookingrevenuerecord.js +84 -84
  25. package/src/models/budget.js +95 -95
  26. package/src/models/budgetCategory.js +19 -19
  27. package/src/models/campaigns.js +108 -108
  28. package/src/models/cashpayment.js +290 -290
  29. package/src/models/combinedUnits.js +62 -62
  30. package/src/models/combined_invoice.js +424 -424
  31. package/src/models/common_area_electricity.js +38 -38
  32. package/src/models/common_area_generator.js +41 -41
  33. package/src/models/common_area_utility_alert.js +37 -37
  34. package/src/models/common_area_water.js +39 -39
  35. package/src/models/communication_status.js +33 -33
  36. package/src/models/communication_user_opt.js +32 -32
  37. package/src/models/community_guidelines.js +35 -35
  38. package/src/models/company.js +53 -53
  39. package/src/models/coreBaseSettings.js +16 -16
  40. package/src/models/coreInvoiceSettings.js +100 -100
  41. package/src/models/counter_schema.js +21 -21
  42. package/src/models/country_tax.js +42 -42
  43. package/src/models/currency_settings.js +39 -39
  44. package/src/models/customer.js +214 -214
  45. package/src/models/customer_preference.js +52 -52
  46. package/src/models/customer_satisfaction_survey.js +297 -297
  47. package/src/models/customer_surveys.js +139 -139
  48. package/src/models/customer_tickets.js +237 -237
  49. package/src/models/dailyChecklist.js +312 -312
  50. package/src/models/default_payment_details.js +17 -17
  51. package/src/models/deliveryTimeMarks.js +18 -18
  52. package/src/models/document_type.js +19 -19
  53. package/src/models/dutyRosterChecklist.js +250 -250
  54. package/src/models/dutyroster.js +136 -136
  55. package/src/models/email.js +37 -37
  56. package/src/models/email_sms_queue.js +61 -61
  57. package/src/models/email_thread.js +35 -35
  58. package/src/models/entry_exit.js +53 -53
  59. package/src/models/expense.js +99 -99
  60. package/src/models/expense_category.js +45 -45
  61. package/src/models/facility.js +76 -76
  62. package/src/models/facilityBillingPrices.js +29 -29
  63. package/src/models/facilityInvoice.js +240 -240
  64. package/src/models/facilityInvoicePayment.js +52 -52
  65. package/src/models/facilityInvoiceRecipient.js +32 -32
  66. package/src/models/facilityWalletTransactionsMetadata.js +236 -236
  67. package/src/models/facility_departements.js +20 -20
  68. package/src/models/facility_payment_details.js +20 -20
  69. package/src/models/facility_rating.js +78 -78
  70. package/src/models/facilityasset.js +25 -25
  71. package/src/models/faq.js +14 -14
  72. package/src/models/gl_account_double_entries.js +25 -25
  73. package/src/models/gl_accounts.js +56 -56
  74. package/src/models/gl_entries.js +49 -49
  75. package/src/models/goodsReceivedNotes.js +115 -115
  76. package/src/models/guard.js +47 -47
  77. package/src/models/handover.js +258 -258
  78. package/src/models/inspection_category.js +38 -38
  79. package/src/models/invoice.js +484 -480
  80. package/src/models/invoice_generation_approval.js +86 -86
  81. package/src/models/invoicing_schedule.js +40 -40
  82. package/src/models/item_inspection.js +96 -96
  83. package/src/models/knowledge_base.js +109 -109
  84. package/src/models/knowledge_base_rating.js +44 -44
  85. package/src/models/leaseagreement.js +243 -243
  86. package/src/models/leasetemplate.js +17 -17
  87. package/src/models/levy.js +223 -223
  88. package/src/models/levy_invoice_settings.js +26 -26
  89. package/src/models/levycontract.js +216 -216
  90. package/src/models/levytype.js +23 -23
  91. package/src/models/maintenance_service_vendor.js +38 -38
  92. package/src/models/maintenance_services.js +17 -17
  93. package/src/models/maintenancerequisition.js +31 -31
  94. package/src/models/master_workplan.js +32 -32
  95. package/src/models/master_workplan_child.js +34 -34
  96. package/src/models/message.js +38 -38
  97. package/src/models/module.js +21 -21
  98. package/src/models/movein_application.js +29 -29
  99. package/src/models/movein_landlord.js +18 -18
  100. package/src/models/movein_user.js +15 -15
  101. package/src/models/notification.js +44 -44
  102. package/src/models/paymentTermsMarks.js +19 -19
  103. package/src/models/penalty.js +76 -76
  104. package/src/models/pendingCredentials.js +32 -32
  105. package/src/models/powerMeterCommunicationProtocol.js +17 -17
  106. package/src/models/powerMeterCustomerAccount.js +78 -78
  107. package/src/models/powerMeterCustomerBand.js +14 -14
  108. package/src/models/powerMeterDailyReading.js +30 -30
  109. package/src/models/powerMeterGateways.js +40 -40
  110. package/src/models/powerMeterMonthlyReading.js +34 -34
  111. package/src/models/powerMeterPowerCharges.js +85 -85
  112. package/src/models/powerMeterSettings.js +159 -159
  113. package/src/models/powerMeterSingleDayReading.js +32 -32
  114. package/src/models/powerMeters.js +116 -116
  115. package/src/models/powerMetersManufacturer.js +14 -14
  116. package/src/models/power_invoice.js +471 -0
  117. package/src/models/power_meter_account.js +81 -81
  118. package/src/models/power_meter_command_logs.js +30 -30
  119. package/src/models/power_meter_command_queue.js +33 -33
  120. package/src/models/power_meter_negative_balance.js +44 -44
  121. package/src/models/power_prepaid_credits.js +47 -47
  122. package/src/models/power_prepaid_debits.js +53 -53
  123. package/src/models/power_prepaid_orders.js +78 -78
  124. package/src/models/power_sms_notification.js +26 -26
  125. package/src/models/privacy_policy.js +19 -19
  126. package/src/models/propertyManagerContract.js +556 -556
  127. package/src/models/propertyManagerRevenue.js +195 -195
  128. package/src/models/purchaseOrderInvoice.js +74 -74
  129. package/src/models/purchase_order.js +213 -213
  130. package/src/models/purchase_request.js +110 -110
  131. package/src/models/quickbooks_config.js +52 -52
  132. package/src/models/refresh_token.js +23 -23
  133. package/src/models/reminder.js +197 -197
  134. package/src/models/report.js +13 -13
  135. package/src/models/resident.js +121 -121
  136. package/src/models/rfq_details.js +131 -131
  137. package/src/models/rfq_response.js +153 -153
  138. package/src/models/service_charge_invoice_upload.js +42 -42
  139. package/src/models/service_charge_payments.js +27 -27
  140. package/src/models/servicerequest.js +55 -55
  141. package/src/models/settings.js +62 -62
  142. package/src/models/short_urls.js +21 -21
  143. package/src/models/smart_meter_daily_consumption.js +44 -44
  144. package/src/models/sms_africastalking.js +20 -20
  145. package/src/models/sms_balance_notification.js +26 -26
  146. package/src/models/sms_meliora.js +20 -20
  147. package/src/models/staff.js +36 -36
  148. package/src/models/stocksandspare.js +161 -161
  149. package/src/models/suppliers.js +74 -74
  150. package/src/models/terms_and_conditions.js +19 -19
  151. package/src/models/tickets.js +186 -186
  152. package/src/models/tickets_category.js +72 -72
  153. package/src/models/unitManagementTemplate.js +44 -44
  154. package/src/models/unitasset.js +25 -25
  155. package/src/models/units.js +130 -130
  156. package/src/models/user.js +186 -186
  157. package/src/models/valueaddedservices.js +21 -21
  158. package/src/models/vas_invoices_upload.js +50 -50
  159. package/src/models/vas_payments.js +24 -24
  160. package/src/models/vasinvoice.js +192 -192
  161. package/src/models/vasvendor.js +52 -52
  162. package/src/models/visitLog.js +95 -95
  163. package/src/models/visitor.js +67 -67
  164. package/src/models/waitlist.js +45 -45
  165. package/src/models/wallet.js +44 -44
  166. package/src/models/wallet_transactions.js +50 -50
  167. package/src/models/water_invoice.js +351 -351
  168. package/src/models/water_meter_Command_Queue.js +33 -33
  169. package/src/models/water_meter_account.js +86 -86
  170. package/src/models/water_meter_billing.js +58 -58
  171. package/src/models/water_meter_combined_accounts.js +92 -92
  172. package/src/models/water_meter_communication.js +17 -17
  173. package/src/models/water_meter_communication_logs.js +39 -39
  174. package/src/models/water_meter_concentrator.js +70 -70
  175. package/src/models/water_meter_daily_history.js +32 -32
  176. package/src/models/water_meter_high_risk.js +36 -36
  177. package/src/models/water_meter_iot_cards.js +34 -34
  178. package/src/models/water_meter_loan_deduction.js +134 -134
  179. package/src/models/water_meter_manufacturer.js +35 -35
  180. package/src/models/water_meter_monthly_history.js +36 -36
  181. package/src/models/water_meter_negative_amounts.js +44 -44
  182. package/src/models/water_meter_settings.js +290 -290
  183. package/src/models/water_meter_single_day_history.js +34 -34
  184. package/src/models/water_meter_size.js +15 -15
  185. package/src/models/water_meters.js +176 -176
  186. package/src/models/water_meters_delivery.js +76 -76
  187. package/src/models/water_prepaid_credit.js +47 -47
  188. package/src/models/water_prepaid_debit.js +50 -50
  189. package/src/models/whatsapp_conversation.js +23 -23
  190. package/src/models/workorder.js +49 -49
  191. package/src/models/zohoAccount.js +453 -453
  192. package/src/models/zohoIntegration.js +262 -262
  193. package/src/models/zohoItem.js +504 -504
@@ -1,236 +1,236 @@
1
- const mongoose = require("mongoose");
2
-
3
- const facilityWalletTransactionsMetadataSchema = new mongoose.Schema(
4
- {
5
- invoiceId: {
6
- type: mongoose.Schema.Types.ObjectId,
7
- ref: "Invoice",
8
- required: true,
9
- },
10
- invoiceNumber: {
11
- type: String,
12
- required: true,
13
- },
14
- amount: {
15
- type: Number,
16
- required: true,
17
- min: 0.01,
18
- },
19
- walletId: {
20
- type: mongoose.Schema.Types.ObjectId,
21
- ref: "Wallet",
22
- required: true,
23
- },
24
- // Updated status enum to include pending, approved, and rejected
25
- status: {
26
- type: String,
27
- enum: ["pending", "partial", "paid", "approved", "rejected", "cancelled"],
28
- required: true,
29
- default: "pending",
30
- },
31
- amountToLandlord: {
32
- type: Number,
33
- default: 0,
34
- min: 0,
35
- },
36
- amountToPropertyManager: {
37
- type: Number,
38
- default: 0,
39
- min: 0,
40
- },
41
- paidToLandlord: {
42
- type: Boolean,
43
- default: false,
44
- },
45
- paidToPropertyManager: {
46
- type: Boolean,
47
- default: false,
48
- },
49
- propertyManager: {
50
- type: mongoose.Schema.Types.ObjectId,
51
- ref: "User",
52
- required: true,
53
- },
54
- landlord: {
55
- type: mongoose.Schema.Types.ObjectId,
56
- ref: "Customer",
57
- required: true,
58
- },
59
- facility: {
60
- type: mongoose.Schema.Types.ObjectId,
61
- ref: "Facility",
62
- required: true,
63
- },
64
- // New approval tracking fields
65
- approvedBy: {
66
- type: mongoose.Schema.Types.ObjectId,
67
- ref: "User",
68
- default: null,
69
- },
70
- approvedAt: {
71
- type: Date,
72
- default: null,
73
- },
74
- approvalNotes: {
75
- type: String,
76
- maxlength: 500,
77
- default: null,
78
- },
79
- // New rejection tracking fields
80
- rejectedBy: {
81
- type: mongoose.Schema.Types.ObjectId,
82
- ref: "User",
83
- default: null,
84
- },
85
- rejectedAt: {
86
- type: Date,
87
- default: null,
88
- },
89
- rejectionReason: {
90
- type: String,
91
- maxlength: 500,
92
- default: null,
93
- },
94
- // Link to created transaction when approved
95
- transactionId: {
96
- type: mongoose.Schema.Types.ObjectId,
97
- ref: "WalletTransaction",
98
- default: null,
99
- },
100
- // Additional metadata fields
101
- createdBy: {
102
- type: mongoose.Schema.Types.ObjectId,
103
- ref: "User",
104
- required: false,
105
- },
106
- updatedBy: {
107
- type: mongoose.Schema.Types.ObjectId,
108
- ref: "User",
109
- required: false,
110
- },
111
- },
112
- {
113
- timestamps: true, // Adds createdAt and updatedAt automatically
114
- },
115
- );
116
-
117
- // Indexes for better query performance
118
- facilityWalletTransactionsMetadataSchema.index({ facility: 1, status: 1 });
119
- facilityWalletTransactionsMetadataSchema.index({ walletId: 1, status: 1 });
120
- facilityWalletTransactionsMetadataSchema.index({ status: 1, createdAt: -1 });
121
- facilityWalletTransactionsMetadataSchema.index({ approvedBy: 1 });
122
- facilityWalletTransactionsMetadataSchema.index({ rejectedBy: 1 });
123
-
124
- // Virtual for checking if metadata is approvable
125
- facilityWalletTransactionsMetadataSchema
126
- .virtual("isApprovable")
127
- .get(function () {
128
- return this.status === "pending";
129
- });
130
-
131
- // Virtual for checking if metadata has been processed
132
- facilityWalletTransactionsMetadataSchema
133
- .virtual("isProcessed")
134
- .get(function () {
135
- return ["approved", "rejected", "cancelled"].includes(this.status);
136
- });
137
-
138
- // Simple pre-save middleware to set timestamps
139
- facilityWalletTransactionsMetadataSchema.pre("save", function (next) {
140
- // Set approval/rejection timestamps when status changes
141
- if (this.isModified("status")) {
142
- if (this.status === "approved" && !this.approvedAt) {
143
- this.approvedAt = new Date();
144
- }
145
- if (this.status === "rejected" && !this.rejectedAt) {
146
- this.rejectedAt = new Date();
147
- }
148
- }
149
- next();
150
- });
151
-
152
- // Static method to find pending metadata
153
- facilityWalletTransactionsMetadataSchema.statics.findPending = function (
154
- facilityId,
155
- options = {},
156
- ) {
157
- const query = { facility: facilityId, status: "pending" };
158
-
159
- if (options.walletId) {
160
- query.walletId = options.walletId;
161
- }
162
-
163
- return this.find(query).sort({ createdAt: -1 });
164
- };
165
-
166
- // Static method to get summary stats
167
- facilityWalletTransactionsMetadataSchema.statics.getSummaryStats = function (
168
- facilityId,
169
- ) {
170
- return this.aggregate([
171
- { $match: { facility: new mongoose.Types.ObjectId(facilityId) } },
172
- {
173
- $group: {
174
- _id: "$status",
175
- count: { $sum: 1 },
176
- totalAmount: { $sum: "$amount" },
177
- },
178
- },
179
- ]);
180
- };
181
-
182
- // Instance method to approve metadata (with validation)
183
- facilityWalletTransactionsMetadataSchema.methods.approve = function (
184
- approvedBy,
185
- notes,
186
- ) {
187
- if (this.status !== "pending") {
188
- throw new Error(`Cannot approve metadata with status: ${this.status}`);
189
- }
190
-
191
- this.status = "approved";
192
- this.approvedBy = approvedBy;
193
- this.approvedAt = new Date();
194
- if (notes) this.approvalNotes = notes;
195
-
196
- return this.save();
197
- };
198
-
199
- // Instance method to reject metadata (with validation)
200
- facilityWalletTransactionsMetadataSchema.methods.reject = function (
201
- rejectedBy,
202
- reason,
203
- ) {
204
- if (this.status !== "pending") {
205
- throw new Error(`Cannot reject metadata with status: ${this.status}`);
206
- }
207
-
208
- this.status = "rejected";
209
- this.rejectedBy = rejectedBy;
210
- this.rejectedAt = new Date();
211
- this.rejectionReason = reason;
212
-
213
- return this.save();
214
- };
215
-
216
- // Static method to validate status transitions (call manually if needed)
217
- facilityWalletTransactionsMetadataSchema.statics.isValidStatusTransition =
218
- function (fromStatus, toStatus) {
219
- const validTransitions = {
220
- pending: ["approved", "rejected", "cancelled"],
221
- partial: ["paid", "cancelled"],
222
- approved: ["paid", "cancelled"],
223
- rejected: ["pending"], // Allow resubmission
224
- paid: [], // Terminal state
225
- cancelled: ["pending"], // Allow reactivation
226
- };
227
-
228
- return validTransitions[fromStatus]?.includes(toStatus) || false;
229
- };
230
-
231
- const FacilityWalletTransactionsMetadata = mongoose.model(
232
- "FacilityWalletTransactionsMetadata",
233
- facilityWalletTransactionsMetadataSchema,
234
- );
235
-
236
- module.exports = FacilityWalletTransactionsMetadata;
1
+ const mongoose = require("mongoose");
2
+
3
+ const facilityWalletTransactionsMetadataSchema = new mongoose.Schema(
4
+ {
5
+ invoiceId: {
6
+ type: mongoose.Schema.Types.ObjectId,
7
+ ref: "Invoice",
8
+ required: true,
9
+ },
10
+ invoiceNumber: {
11
+ type: String,
12
+ required: true,
13
+ },
14
+ amount: {
15
+ type: Number,
16
+ required: true,
17
+ min: 0.01,
18
+ },
19
+ walletId: {
20
+ type: mongoose.Schema.Types.ObjectId,
21
+ ref: "Wallet",
22
+ required: true,
23
+ },
24
+ // Updated status enum to include pending, approved, and rejected
25
+ status: {
26
+ type: String,
27
+ enum: ["pending", "partial", "paid", "approved", "rejected", "cancelled"],
28
+ required: true,
29
+ default: "pending",
30
+ },
31
+ amountToLandlord: {
32
+ type: Number,
33
+ default: 0,
34
+ min: 0,
35
+ },
36
+ amountToPropertyManager: {
37
+ type: Number,
38
+ default: 0,
39
+ min: 0,
40
+ },
41
+ paidToLandlord: {
42
+ type: Boolean,
43
+ default: false,
44
+ },
45
+ paidToPropertyManager: {
46
+ type: Boolean,
47
+ default: false,
48
+ },
49
+ propertyManager: {
50
+ type: mongoose.Schema.Types.ObjectId,
51
+ ref: "User",
52
+ required: true,
53
+ },
54
+ landlord: {
55
+ type: mongoose.Schema.Types.ObjectId,
56
+ ref: "Customer",
57
+ required: true,
58
+ },
59
+ facility: {
60
+ type: mongoose.Schema.Types.ObjectId,
61
+ ref: "Facility",
62
+ required: true,
63
+ },
64
+ // New approval tracking fields
65
+ approvedBy: {
66
+ type: mongoose.Schema.Types.ObjectId,
67
+ ref: "User",
68
+ default: null,
69
+ },
70
+ approvedAt: {
71
+ type: Date,
72
+ default: null,
73
+ },
74
+ approvalNotes: {
75
+ type: String,
76
+ maxlength: 500,
77
+ default: null,
78
+ },
79
+ // New rejection tracking fields
80
+ rejectedBy: {
81
+ type: mongoose.Schema.Types.ObjectId,
82
+ ref: "User",
83
+ default: null,
84
+ },
85
+ rejectedAt: {
86
+ type: Date,
87
+ default: null,
88
+ },
89
+ rejectionReason: {
90
+ type: String,
91
+ maxlength: 500,
92
+ default: null,
93
+ },
94
+ // Link to created transaction when approved
95
+ transactionId: {
96
+ type: mongoose.Schema.Types.ObjectId,
97
+ ref: "WalletTransaction",
98
+ default: null,
99
+ },
100
+ // Additional metadata fields
101
+ createdBy: {
102
+ type: mongoose.Schema.Types.ObjectId,
103
+ ref: "User",
104
+ required: false,
105
+ },
106
+ updatedBy: {
107
+ type: mongoose.Schema.Types.ObjectId,
108
+ ref: "User",
109
+ required: false,
110
+ },
111
+ },
112
+ {
113
+ timestamps: true, // Adds createdAt and updatedAt automatically
114
+ },
115
+ );
116
+
117
+ // Indexes for better query performance
118
+ facilityWalletTransactionsMetadataSchema.index({ facility: 1, status: 1 });
119
+ facilityWalletTransactionsMetadataSchema.index({ walletId: 1, status: 1 });
120
+ facilityWalletTransactionsMetadataSchema.index({ status: 1, createdAt: -1 });
121
+ facilityWalletTransactionsMetadataSchema.index({ approvedBy: 1 });
122
+ facilityWalletTransactionsMetadataSchema.index({ rejectedBy: 1 });
123
+
124
+ // Virtual for checking if metadata is approvable
125
+ facilityWalletTransactionsMetadataSchema
126
+ .virtual("isApprovable")
127
+ .get(function () {
128
+ return this.status === "pending";
129
+ });
130
+
131
+ // Virtual for checking if metadata has been processed
132
+ facilityWalletTransactionsMetadataSchema
133
+ .virtual("isProcessed")
134
+ .get(function () {
135
+ return ["approved", "rejected", "cancelled"].includes(this.status);
136
+ });
137
+
138
+ // Simple pre-save middleware to set timestamps
139
+ facilityWalletTransactionsMetadataSchema.pre("save", function (next) {
140
+ // Set approval/rejection timestamps when status changes
141
+ if (this.isModified("status")) {
142
+ if (this.status === "approved" && !this.approvedAt) {
143
+ this.approvedAt = new Date();
144
+ }
145
+ if (this.status === "rejected" && !this.rejectedAt) {
146
+ this.rejectedAt = new Date();
147
+ }
148
+ }
149
+ next();
150
+ });
151
+
152
+ // Static method to find pending metadata
153
+ facilityWalletTransactionsMetadataSchema.statics.findPending = function (
154
+ facilityId,
155
+ options = {},
156
+ ) {
157
+ const query = { facility: facilityId, status: "pending" };
158
+
159
+ if (options.walletId) {
160
+ query.walletId = options.walletId;
161
+ }
162
+
163
+ return this.find(query).sort({ createdAt: -1 });
164
+ };
165
+
166
+ // Static method to get summary stats
167
+ facilityWalletTransactionsMetadataSchema.statics.getSummaryStats = function (
168
+ facilityId,
169
+ ) {
170
+ return this.aggregate([
171
+ { $match: { facility: new mongoose.Types.ObjectId(facilityId) } },
172
+ {
173
+ $group: {
174
+ _id: "$status",
175
+ count: { $sum: 1 },
176
+ totalAmount: { $sum: "$amount" },
177
+ },
178
+ },
179
+ ]);
180
+ };
181
+
182
+ // Instance method to approve metadata (with validation)
183
+ facilityWalletTransactionsMetadataSchema.methods.approve = function (
184
+ approvedBy,
185
+ notes,
186
+ ) {
187
+ if (this.status !== "pending") {
188
+ throw new Error(`Cannot approve metadata with status: ${this.status}`);
189
+ }
190
+
191
+ this.status = "approved";
192
+ this.approvedBy = approvedBy;
193
+ this.approvedAt = new Date();
194
+ if (notes) this.approvalNotes = notes;
195
+
196
+ return this.save();
197
+ };
198
+
199
+ // Instance method to reject metadata (with validation)
200
+ facilityWalletTransactionsMetadataSchema.methods.reject = function (
201
+ rejectedBy,
202
+ reason,
203
+ ) {
204
+ if (this.status !== "pending") {
205
+ throw new Error(`Cannot reject metadata with status: ${this.status}`);
206
+ }
207
+
208
+ this.status = "rejected";
209
+ this.rejectedBy = rejectedBy;
210
+ this.rejectedAt = new Date();
211
+ this.rejectionReason = reason;
212
+
213
+ return this.save();
214
+ };
215
+
216
+ // Static method to validate status transitions (call manually if needed)
217
+ facilityWalletTransactionsMetadataSchema.statics.isValidStatusTransition =
218
+ function (fromStatus, toStatus) {
219
+ const validTransitions = {
220
+ pending: ["approved", "rejected", "cancelled"],
221
+ partial: ["paid", "cancelled"],
222
+ approved: ["paid", "cancelled"],
223
+ rejected: ["pending"], // Allow resubmission
224
+ paid: [], // Terminal state
225
+ cancelled: ["pending"], // Allow reactivation
226
+ };
227
+
228
+ return validTransitions[fromStatus]?.includes(toStatus) || false;
229
+ };
230
+
231
+ const FacilityWalletTransactionsMetadata = mongoose.model(
232
+ "FacilityWalletTransactionsMetadata",
233
+ facilityWalletTransactionsMetadataSchema,
234
+ );
235
+
236
+ module.exports = FacilityWalletTransactionsMetadata;
@@ -1,20 +1,20 @@
1
- const mongoose = require('mongoose');
2
-
3
- const facilityDepartmentSchema = new mongoose.Schema({
4
- facilityId: {
5
- type: mongoose.Schema.Types.ObjectId,
6
- ref: 'Facility',
7
- required: true
8
- },
9
- name: {
10
- type: String,
11
- required: true,
12
- trim: true
13
- }
14
- }, {
15
- timestamps: true
16
- });
17
-
18
- const FacilityDepartment = mongoose.model('FacilityDepartment', facilityDepartmentSchema);
19
-
20
- module.exports = FacilityDepartment;
1
+ const mongoose = require('mongoose');
2
+
3
+ const facilityDepartmentSchema = new mongoose.Schema({
4
+ facilityId: {
5
+ type: mongoose.Schema.Types.ObjectId,
6
+ ref: 'Facility',
7
+ required: true
8
+ },
9
+ name: {
10
+ type: String,
11
+ required: true,
12
+ trim: true
13
+ }
14
+ }, {
15
+ timestamps: true
16
+ });
17
+
18
+ const FacilityDepartment = mongoose.model('FacilityDepartment', facilityDepartmentSchema);
19
+
20
+ module.exports = FacilityDepartment;
@@ -1,21 +1,21 @@
1
- const mongoose = require("mongoose");
2
-
3
- const facilityPaymentDetailsSchema = new mongoose.Schema({
4
- facility: {
5
- type: mongoose.Schema.Types.ObjectId,
6
- },
7
- shortCode: { type: String },
8
- passkey: { type: String },
9
- authorizationKey: {
10
- type: String,
11
- },
12
- module: {
13
- type: String,
14
- enum: ["All", "Water", "Electricity", "Levy","Lease","Booking"],
15
- default: "All"
16
- },
17
- });
18
-
19
- const FacilityPaymentDetails = mongoose.model('FacilityPaymentDetails', facilityPaymentDetailsSchema);
20
-
1
+ const mongoose = require("mongoose");
2
+
3
+ const facilityPaymentDetailsSchema = new mongoose.Schema({
4
+ facility: {
5
+ type: mongoose.Schema.Types.ObjectId,
6
+ },
7
+ shortCode: { type: String },
8
+ passkey: { type: String },
9
+ authorizationKey: {
10
+ type: String,
11
+ },
12
+ module: {
13
+ type: String,
14
+ enum: ["All", "Water", "Electricity", "Levy","Lease","Booking"],
15
+ default: "All"
16
+ },
17
+ });
18
+
19
+ const FacilityPaymentDetails = mongoose.model('FacilityPaymentDetails', facilityPaymentDetailsSchema);
20
+
21
21
  module.exports = FacilityPaymentDetails;