payservedb 9.9.2 → 9.9.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.
Files changed (235) hide show
  1. package/.env +2 -2
  2. package/ZOHO_INTEGRATION_SCHEMA.md +644 -644
  3. package/index.js +421 -420
  4. package/package.json +17 -17
  5. package/src/models/InvoiceWithholdingTax.js +67 -67
  6. package/src/models/account.js +59 -59
  7. package/src/models/agent_departments.js +59 -59
  8. package/src/models/agent_notifications.js +53 -53
  9. package/src/models/agent_performance.js +127 -127
  10. package/src/models/agent_roles.js +77 -77
  11. package/src/models/agents.js +154 -154
  12. package/src/models/apilog.js +18 -18
  13. package/src/models/approvalsWorkflows.js +49 -49
  14. package/src/models/archivedapilog.js +18 -18
  15. package/src/models/asset.js +92 -92
  16. package/src/models/assetsAssignment.js +64 -64
  17. package/src/models/auditTrail.js +346 -346
  18. package/src/models/auto_reply_rule.js +68 -68
  19. package/src/models/bankdetails.js +47 -47
  20. package/src/models/billerAddress.js +124 -124
  21. package/src/models/booking_invoice.js +191 -191
  22. package/src/models/booking_voucher.js +131 -131
  23. package/src/models/booking_voucher_config.js +56 -56
  24. package/src/models/bookinganalytics.js +63 -63
  25. package/src/models/bookingconfig.js +74 -74
  26. package/src/models/bookingproperty.js +211 -211
  27. package/src/models/bookingreservation.js +330 -330
  28. package/src/models/bookingrevenuerecord.js +99 -99
  29. package/src/models/budget.js +95 -95
  30. package/src/models/budgetCategory.js +19 -19
  31. package/src/models/campaigns.js +108 -108
  32. package/src/models/cancellation_policy.js +56 -56
  33. package/src/models/cashpayment.js +289 -289
  34. package/src/models/combinedUnits.js +62 -62
  35. package/src/models/combined_invoice.js +424 -424
  36. package/src/models/common_area_electricity.js +38 -38
  37. package/src/models/common_area_generator.js +41 -41
  38. package/src/models/common_area_utility_alert.js +37 -37
  39. package/src/models/common_area_water.js +39 -39
  40. package/src/models/communication_status.js +33 -33
  41. package/src/models/communication_user_opt.js +32 -32
  42. package/src/models/community_guidelines.js +35 -35
  43. package/src/models/company.js +53 -53
  44. package/src/models/coreBaseSettings.js +16 -16
  45. package/src/models/coreInvoiceSettings.js +100 -100
  46. package/src/models/counter_schema.js +21 -21
  47. package/src/models/country_tax.js +42 -42
  48. package/src/models/currency_settings.js +39 -39
  49. package/src/models/customer.js +267 -267
  50. package/src/models/customer_preference.js +52 -52
  51. package/src/models/customer_satisfaction_survey.js +297 -297
  52. package/src/models/customer_surveys.js +139 -139
  53. package/src/models/customer_tickets.js +237 -237
  54. package/src/models/dailyChecklist.js +312 -312
  55. package/src/models/default_payment_details.js +17 -17
  56. package/src/models/deliveryTimeMarks.js +18 -18
  57. package/src/models/document_type.js +19 -19
  58. package/src/models/dutyRosterChecklist.js +250 -250
  59. package/src/models/dutyroster.js +136 -136
  60. package/src/models/email.js +37 -37
  61. package/src/models/email_cc_config.js +48 -48
  62. package/src/models/email_sms_queue.js +61 -61
  63. package/src/models/email_thread.js +35 -35
  64. package/src/models/entry_exit.js +53 -53
  65. package/src/models/expense.js +99 -99
  66. package/src/models/expense_category.js +45 -45
  67. package/src/models/facility.js +131 -131
  68. package/src/models/facilityBillingPrices.js +29 -29
  69. package/src/models/facilityInvoice.js +240 -240
  70. package/src/models/facilityInvoicePayment.js +52 -52
  71. package/src/models/facilityInvoiceRecipient.js +32 -32
  72. package/src/models/facilityWalletTransactionsMetadata.js +236 -236
  73. package/src/models/facility_departements.js +20 -20
  74. package/src/models/facility_etims_config.js +116 -116
  75. package/src/models/facility_payment_details.js +20 -20
  76. package/src/models/facility_rating.js +78 -78
  77. package/src/models/facilityasset.js +25 -25
  78. package/src/models/faq.js +15 -15
  79. package/src/models/gl_account_double_entries.js +25 -25
  80. package/src/models/gl_accounts.js +56 -56
  81. package/src/models/gl_entries.js +49 -49
  82. package/src/models/goodsReceivedNotes.js +115 -115
  83. package/src/models/guard.js +47 -47
  84. package/src/models/handover.js +258 -258
  85. package/src/models/inspection_category.js +38 -38
  86. package/src/models/invoice.js +715 -715
  87. package/src/models/invoiceCreditAdjustment.js +45 -45
  88. package/src/models/invoice_edit_log.js +81 -81
  89. package/src/models/invoice_generation_approval.js +86 -86
  90. package/src/models/invoicing_schedule.js +40 -40
  91. package/src/models/item_inspection.js +96 -96
  92. package/src/models/knowledge_base.js +109 -109
  93. package/src/models/knowledge_base_rating.js +44 -44
  94. package/src/models/leaseagreement.js +270 -270
  95. package/src/models/leasetemplate.js +17 -17
  96. package/src/models/levy.js +235 -235
  97. package/src/models/levy_deposits.js +145 -145
  98. package/src/models/levy_invoice_settings.js +26 -26
  99. package/src/models/levy_payment_receipt.js +158 -158
  100. package/src/models/levycontract.js +250 -250
  101. package/src/models/levytype.js +23 -23
  102. package/src/models/maintenance_service_vendor.js +38 -38
  103. package/src/models/maintenance_services.js +17 -17
  104. package/src/models/maintenancerequisition.js +31 -31
  105. package/src/models/master_workplan.js +32 -32
  106. package/src/models/master_workplan_child.js +34 -34
  107. package/src/models/message.js +38 -38
  108. package/src/models/module.js +21 -21
  109. package/src/models/movein_amenity.js +13 -13
  110. package/src/models/movein_application.js +28 -28
  111. package/src/models/movein_audit_log.js +21 -21
  112. package/src/models/movein_booking.js +33 -33
  113. package/src/models/movein_commission.js +46 -46
  114. package/src/models/movein_conversation.js +25 -25
  115. package/src/models/movein_deal.js +79 -79
  116. package/src/models/movein_disbursement.js +36 -36
  117. package/src/models/movein_email_thread.js +19 -19
  118. package/src/models/movein_enquiry.js +16 -16
  119. package/src/models/movein_featured_package.js +16 -16
  120. package/src/models/movein_handoff_token.js +16 -16
  121. package/src/models/movein_invoice.js +24 -24
  122. package/src/models/movein_landlord.js +18 -18
  123. package/src/models/movein_landlord_user.js +20 -20
  124. package/src/models/movein_lease.js +37 -37
  125. package/src/models/movein_message.js +27 -27
  126. package/src/models/movein_notification.js +27 -27
  127. package/src/models/movein_otp.js +14 -14
  128. package/src/models/movein_payment.js +46 -46
  129. package/src/models/movein_reminder.js +77 -77
  130. package/src/models/movein_reservation.js +31 -31
  131. package/src/models/movein_settings.js +25 -25
  132. package/src/models/movein_tenancy.js +55 -55
  133. package/src/models/movein_unit.js +59 -59
  134. package/src/models/movein_user.js +15 -15
  135. package/src/models/movein_viewing_slot.js +21 -21
  136. package/src/models/movein_want_unit.js +20 -20
  137. package/src/models/notification.js +44 -44
  138. package/src/models/paymentTermsMarks.js +19 -19
  139. package/src/models/penalty.js +76 -76
  140. package/src/models/pendingCredentials.js +32 -32
  141. package/src/models/powerMeterCommunicationProtocol.js +17 -17
  142. package/src/models/powerMeterCustomerAccount.js +78 -78
  143. package/src/models/powerMeterCustomerBand.js +14 -14
  144. package/src/models/powerMeterDailyReading.js +30 -30
  145. package/src/models/powerMeterGateways.js +40 -40
  146. package/src/models/powerMeterMonthlyReading.js +34 -34
  147. package/src/models/powerMeterPowerCharges.js +85 -85
  148. package/src/models/powerMeterSettings.js +211 -211
  149. package/src/models/powerMeterSingleDayReading.js +32 -32
  150. package/src/models/powerMeters.js +154 -154
  151. package/src/models/powerMetersManufacturer.js +14 -14
  152. package/src/models/power_invoice.js +383 -383
  153. package/src/models/power_meter_account.js +81 -81
  154. package/src/models/power_meter_command_logs.js +30 -30
  155. package/src/models/power_meter_command_queue.js +33 -33
  156. package/src/models/power_meter_negative_balance.js +44 -44
  157. package/src/models/power_prepaid_credits.js +47 -47
  158. package/src/models/power_prepaid_debits.js +53 -53
  159. package/src/models/power_prepaid_orders.js +78 -78
  160. package/src/models/power_sms_notification.js +26 -26
  161. package/src/models/privacy_policy.js +19 -19
  162. package/src/models/propertyManagementSettings.js +55 -55
  163. package/src/models/propertyManagerContract.js +663 -663
  164. package/src/models/propertyManagerRevenue.js +195 -195
  165. package/src/models/propertyManagerRevenueEntry.js +118 -118
  166. package/src/models/purchaseOrderInvoice.js +74 -74
  167. package/src/models/purchase_order.js +213 -213
  168. package/src/models/purchase_request.js +110 -110
  169. package/src/models/quickbooks_config.js +52 -52
  170. package/src/models/reception.js +33 -0
  171. package/src/models/recipient_group.js +61 -61
  172. package/src/models/recipient_group_member.js +62 -62
  173. package/src/models/refresh_token.js +23 -23
  174. package/src/models/reminder.js +197 -197
  175. package/src/models/report.js +13 -13
  176. package/src/models/resident.js +121 -121
  177. package/src/models/rfq_details.js +131 -131
  178. package/src/models/rfq_response.js +153 -153
  179. package/src/models/service_charge_invoice_upload.js +42 -42
  180. package/src/models/service_charge_payments.js +27 -27
  181. package/src/models/servicerequest.js +55 -55
  182. package/src/models/settings.js +62 -62
  183. package/src/models/short_urls.js +21 -21
  184. package/src/models/smart_meter_daily_consumption.js +44 -44
  185. package/src/models/sms_africastalking.js +20 -20
  186. package/src/models/sms_balance_notification.js +26 -26
  187. package/src/models/sms_meliora.js +20 -20
  188. package/src/models/staff.js +36 -36
  189. package/src/models/stocksandspare.js +161 -161
  190. package/src/models/suppliers.js +79 -79
  191. package/src/models/terms_and_conditions.js +19 -19
  192. package/src/models/tickets.js +186 -186
  193. package/src/models/tickets_category.js +72 -72
  194. package/src/models/unitManagementTemplate.js +44 -44
  195. package/src/models/unitasset.js +25 -25
  196. package/src/models/units.js +148 -148
  197. package/src/models/user.js +191 -186
  198. package/src/models/valueaddedservices.js +50 -50
  199. package/src/models/vas_invoices_upload.js +50 -50
  200. package/src/models/vas_payments.js +24 -24
  201. package/src/models/vasinvoice.js +196 -196
  202. package/src/models/vasvendor.js +52 -52
  203. package/src/models/visitLog.js +120 -120
  204. package/src/models/visitor.js +75 -75
  205. package/src/models/waitlist.js +45 -45
  206. package/src/models/wallet.js +44 -44
  207. package/src/models/wallet_transaction.js +67 -67
  208. package/src/models/wallet_transactions.js +72 -72
  209. package/src/models/water_invoice.js +362 -362
  210. package/src/models/water_meter_Command_Queue.js +33 -33
  211. package/src/models/water_meter_account.js +94 -94
  212. package/src/models/water_meter_billing.js +58 -58
  213. package/src/models/water_meter_combined_accounts.js +92 -92
  214. package/src/models/water_meter_communication.js +17 -17
  215. package/src/models/water_meter_communication_logs.js +39 -39
  216. package/src/models/water_meter_concentrator.js +77 -77
  217. package/src/models/water_meter_daily_history.js +32 -32
  218. package/src/models/water_meter_high_risk.js +36 -36
  219. package/src/models/water_meter_iot_cards.js +34 -34
  220. package/src/models/water_meter_loan_deduction.js +134 -134
  221. package/src/models/water_meter_manufacturer.js +35 -35
  222. package/src/models/water_meter_monthly_history.js +36 -36
  223. package/src/models/water_meter_negative_amounts.js +44 -44
  224. package/src/models/water_meter_settings.js +348 -348
  225. package/src/models/water_meter_single_day_history.js +34 -34
  226. package/src/models/water_meter_size.js +15 -15
  227. package/src/models/water_meters.js +176 -176
  228. package/src/models/water_meters_delivery.js +76 -76
  229. package/src/models/water_prepaid_credit.js +47 -47
  230. package/src/models/water_prepaid_debit.js +50 -50
  231. package/src/models/whatsapp_conversation.js +23 -23
  232. package/src/models/workorder.js +49 -49
  233. package/src/models/zohoAccount.js +453 -453
  234. package/src/models/zohoIntegration.js +262 -262
  235. package/src/models/zohoItem.js +504 -504
@@ -1,117 +1,117 @@
1
- const mongoose = require("mongoose");
2
-
3
- const FacilityEtimsConfigSchema = new mongoose.Schema(
4
- {
5
- facilityId: {
6
- type: mongoose.Schema.Types.ObjectId,
7
- ref: "Facility",
8
- required: true,
9
- unique: true,
10
- index: true,
11
- },
12
-
13
- // ── KRA Organisation Details ─────────────────────────────────────────────
14
- tin: {
15
- type: String,
16
- required: true,
17
- trim: true,
18
- // Kenya TIN format e.g. P051201909L
19
- },
20
-
21
- branchId: {
22
- type: String,
23
- required: true,
24
- trim: true,
25
- default: "00", // "00" = headquarters
26
- },
27
-
28
- // ── Master Enable/Disable for this facility ───────────────────────────────
29
- enabled: {
30
- type: Boolean,
31
- default: true,
32
- },
33
-
34
- // ── Optional per-facility overrides (fall back to .env if absent) ─────────
35
- // Leave null to use the system-wide .env values
36
- baseUrl: {
37
- type: String,
38
- trim: true,
39
- default: null,
40
- },
41
-
42
- username: {
43
- type: String,
44
- trim: true,
45
- default: null,
46
- },
47
-
48
- // Store hashed or as-is depending on your security posture.
49
- // Recommend encrypting at rest; kept as String here to match
50
- // the pattern used by ZohoConfig in the same codebase.
51
- password: {
52
- type: String,
53
- default: null,
54
- },
55
-
56
- // ── Audit / Meta ──────────────────────────────────────────────────────────
57
- configuredBy: {
58
- type: String, // user email or ID who last saved
59
- default: null,
60
- },
61
-
62
- lastUpdatedAt: {
63
- type: Date,
64
- default: null,
65
- },
66
-
67
- // Lightweight sync stats (updated by the etims service)
68
- syncStats: {
69
- totalSynced: { type: Number, default: 0 },
70
- lastSyncAt: { type: Date, default: null },
71
- lastSyncStatus: {
72
- type: String,
73
- enum: ["success", "failed", null],
74
- default: null,
75
- },
76
- },
77
- },
78
- {
79
- timestamps: true, // createdAt + updatedAt
80
- collection: "facilityetimsconfigs",
81
- }
82
- );
83
-
84
- // ── Instance helper ───────────────────────────────────────────────────────────
85
- /**
86
- * Returns the effective config object ready for use in the etims service.
87
- * Falls back to .env values for credentials not stored per-facility.
88
- */
89
- FacilityEtimsConfigSchema.methods.toEtimsConfig = function () {
90
- return {
91
- enabled: this.enabled,
92
- tin: this.tin,
93
- branchId: this.branchId,
94
- baseUrl:
95
- this.baseUrl ||
96
- process.env.ETIMS_BASE_URL ||
97
- "http://102.217.144.50:8888/api/v1/",
98
- username: this.username || process.env.ETIMS_USERNAME || "admin",
99
- password: this.password || process.env.ETIMS_PASSWORD || "admin",
100
- };
101
- };
102
-
103
- // ── Static helper ────────────────────────────────────────────────────────────
104
- /**
105
- * Load config for a facility. Returns null if not found.
106
- * @param {string|ObjectId} facilityId
107
- */
108
- FacilityEtimsConfigSchema.statics.getForFacility = async function (facilityId) {
109
- return this.findOne({ facilityId }).lean();
110
- };
111
-
112
- const FacilityEtimsConfig = mongoose.model(
113
- "FacilityEtimsConfig",
114
- FacilityEtimsConfigSchema
115
- );
116
-
1
+ const mongoose = require("mongoose");
2
+
3
+ const FacilityEtimsConfigSchema = new mongoose.Schema(
4
+ {
5
+ facilityId: {
6
+ type: mongoose.Schema.Types.ObjectId,
7
+ ref: "Facility",
8
+ required: true,
9
+ unique: true,
10
+ index: true,
11
+ },
12
+
13
+ // ── KRA Organisation Details ─────────────────────────────────────────────
14
+ tin: {
15
+ type: String,
16
+ required: true,
17
+ trim: true,
18
+ // Kenya TIN format e.g. P051201909L
19
+ },
20
+
21
+ branchId: {
22
+ type: String,
23
+ required: true,
24
+ trim: true,
25
+ default: "00", // "00" = headquarters
26
+ },
27
+
28
+ // ── Master Enable/Disable for this facility ───────────────────────────────
29
+ enabled: {
30
+ type: Boolean,
31
+ default: true,
32
+ },
33
+
34
+ // ── Optional per-facility overrides (fall back to .env if absent) ─────────
35
+ // Leave null to use the system-wide .env values
36
+ baseUrl: {
37
+ type: String,
38
+ trim: true,
39
+ default: null,
40
+ },
41
+
42
+ username: {
43
+ type: String,
44
+ trim: true,
45
+ default: null,
46
+ },
47
+
48
+ // Store hashed or as-is depending on your security posture.
49
+ // Recommend encrypting at rest; kept as String here to match
50
+ // the pattern used by ZohoConfig in the same codebase.
51
+ password: {
52
+ type: String,
53
+ default: null,
54
+ },
55
+
56
+ // ── Audit / Meta ──────────────────────────────────────────────────────────
57
+ configuredBy: {
58
+ type: String, // user email or ID who last saved
59
+ default: null,
60
+ },
61
+
62
+ lastUpdatedAt: {
63
+ type: Date,
64
+ default: null,
65
+ },
66
+
67
+ // Lightweight sync stats (updated by the etims service)
68
+ syncStats: {
69
+ totalSynced: { type: Number, default: 0 },
70
+ lastSyncAt: { type: Date, default: null },
71
+ lastSyncStatus: {
72
+ type: String,
73
+ enum: ["success", "failed", null],
74
+ default: null,
75
+ },
76
+ },
77
+ },
78
+ {
79
+ timestamps: true, // createdAt + updatedAt
80
+ collection: "facilityetimsconfigs",
81
+ }
82
+ );
83
+
84
+ // ── Instance helper ───────────────────────────────────────────────────────────
85
+ /**
86
+ * Returns the effective config object ready for use in the etims service.
87
+ * Falls back to .env values for credentials not stored per-facility.
88
+ */
89
+ FacilityEtimsConfigSchema.methods.toEtimsConfig = function () {
90
+ return {
91
+ enabled: this.enabled,
92
+ tin: this.tin,
93
+ branchId: this.branchId,
94
+ baseUrl:
95
+ this.baseUrl ||
96
+ process.env.ETIMS_BASE_URL ||
97
+ "http://102.217.144.50:8888/api/v1/",
98
+ username: this.username || process.env.ETIMS_USERNAME || "admin",
99
+ password: this.password || process.env.ETIMS_PASSWORD || "admin",
100
+ };
101
+ };
102
+
103
+ // ── Static helper ────────────────────────────────────────────────────────────
104
+ /**
105
+ * Load config for a facility. Returns null if not found.
106
+ * @param {string|ObjectId} facilityId
107
+ */
108
+ FacilityEtimsConfigSchema.statics.getForFacility = async function (facilityId) {
109
+ return this.findOne({ facilityId }).lean();
110
+ };
111
+
112
+ const FacilityEtimsConfig = mongoose.model(
113
+ "FacilityEtimsConfig",
114
+ FacilityEtimsConfigSchema
115
+ );
116
+
117
117
  module.exports = FacilityEtimsConfig;
@@ -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;
@@ -1,79 +1,79 @@
1
- const mongoose = require("mongoose");
2
-
3
- const ratingSchema = new mongoose.Schema(
4
- {
5
- customerId: {
6
- type: mongoose.Schema.Types.ObjectId,
7
- ref: "Customer",
8
- required: true,
9
- index: true,
10
- },
11
- facilityId: {
12
- type: mongoose.Schema.Types.ObjectId,
13
- ref: "Facility",
14
- required: true,
15
- index: true,
16
- },
17
- invoiceId: {
18
- type: mongoose.Schema.Types.ObjectId,
19
- ref: "Invoice",
20
- required: true,
21
- index: true,
22
- },
23
- score: {
24
- type: Number,
25
- required: true,
26
- min: 1,
27
- max: 5,
28
- validate: {
29
- validator: Number.isInteger,
30
- message: "Score must be an integer between 1 and 5",
31
- },
32
- },
33
- },
34
- {
35
- timestamps: true, // Automatically adds createdAt and updatedAt
36
- }
37
- );
38
-
39
- // Compound indexes for common queries
40
- ratingSchema.index({ facilityId: 1, createdAt: -1 });
41
- ratingSchema.index({ customerId: 1, facilityId: 1 });
42
- ratingSchema.index({ invoiceId: 1 }, { unique: true });
43
-
44
- // Static method to calculate average rating for a facility
45
- ratingSchema.statics.getAverageRating = function (facilityId) {
46
- return this.aggregate([
47
- { $match: { facilityId: facilityId } },
48
- {
49
- $group: {
50
- _id: "$facilityId",
51
- averageScore: { $avg: "$score" },
52
- totalRatings: { $sum: 1 },
53
- },
54
- },
55
- ]);
56
- };
57
-
58
- // Static method to get rating distribution for a facility
59
- ratingSchema.statics.getRatingDistribution = function (facilityId) {
60
- return this.aggregate([
61
- { $match: { facilityId: facilityId } },
62
- {
63
- $group: {
64
- _id: "$score",
65
- count: { $sum: 1 },
66
- },
67
- },
68
- { $sort: { _id: -1 } }, // Sort by score descending (5 to 1)
69
- ]);
70
- };
71
-
72
- // Static method to check if customer has already rated an invoice
73
- ratingSchema.statics.hasRated = function (invoiceId) {
74
- return this.findOne({ invoiceId: invoiceId });
75
- };
76
-
77
- const Rating = mongoose.model("Rating", ratingSchema);
78
-
1
+ const mongoose = require("mongoose");
2
+
3
+ const ratingSchema = new mongoose.Schema(
4
+ {
5
+ customerId: {
6
+ type: mongoose.Schema.Types.ObjectId,
7
+ ref: "Customer",
8
+ required: true,
9
+ index: true,
10
+ },
11
+ facilityId: {
12
+ type: mongoose.Schema.Types.ObjectId,
13
+ ref: "Facility",
14
+ required: true,
15
+ index: true,
16
+ },
17
+ invoiceId: {
18
+ type: mongoose.Schema.Types.ObjectId,
19
+ ref: "Invoice",
20
+ required: true,
21
+ index: true,
22
+ },
23
+ score: {
24
+ type: Number,
25
+ required: true,
26
+ min: 1,
27
+ max: 5,
28
+ validate: {
29
+ validator: Number.isInteger,
30
+ message: "Score must be an integer between 1 and 5",
31
+ },
32
+ },
33
+ },
34
+ {
35
+ timestamps: true, // Automatically adds createdAt and updatedAt
36
+ }
37
+ );
38
+
39
+ // Compound indexes for common queries
40
+ ratingSchema.index({ facilityId: 1, createdAt: -1 });
41
+ ratingSchema.index({ customerId: 1, facilityId: 1 });
42
+ ratingSchema.index({ invoiceId: 1 }, { unique: true });
43
+
44
+ // Static method to calculate average rating for a facility
45
+ ratingSchema.statics.getAverageRating = function (facilityId) {
46
+ return this.aggregate([
47
+ { $match: { facilityId: facilityId } },
48
+ {
49
+ $group: {
50
+ _id: "$facilityId",
51
+ averageScore: { $avg: "$score" },
52
+ totalRatings: { $sum: 1 },
53
+ },
54
+ },
55
+ ]);
56
+ };
57
+
58
+ // Static method to get rating distribution for a facility
59
+ ratingSchema.statics.getRatingDistribution = function (facilityId) {
60
+ return this.aggregate([
61
+ { $match: { facilityId: facilityId } },
62
+ {
63
+ $group: {
64
+ _id: "$score",
65
+ count: { $sum: 1 },
66
+ },
67
+ },
68
+ { $sort: { _id: -1 } }, // Sort by score descending (5 to 1)
69
+ ]);
70
+ };
71
+
72
+ // Static method to check if customer has already rated an invoice
73
+ ratingSchema.statics.hasRated = function (invoiceId) {
74
+ return this.findOne({ invoiceId: invoiceId });
75
+ };
76
+
77
+ const Rating = mongoose.model("Rating", ratingSchema);
78
+
79
79
  module.exports = Rating;
@@ -1,25 +1,25 @@
1
- const mongoose = require('mongoose');
2
-
3
- // Define the schema for companies
4
- const facilityassetSchema = new mongoose.Schema({
5
- name: {
6
- type: String,
7
- required:true
8
- },
9
- facilityId:{
10
- type: mongoose.Schema.Types.ObjectId,
11
- ref: 'Facility',
12
- }
13
-
14
-
15
- }, {
16
- timestamps: true // Automatically add createdAt and updatedAt fields
17
- });
18
-
19
- // Indexes for improved performance
20
- facilityassetSchema.index({ name: 1 });
21
-
22
- // Compile the model from the schema
23
- const FacilityAsset = mongoose.model('FacilityAsset', facilityassetSchema);
24
-
25
- module.exports = FacilityAsset;
1
+ const mongoose = require('mongoose');
2
+
3
+ // Define the schema for companies
4
+ const facilityassetSchema = new mongoose.Schema({
5
+ name: {
6
+ type: String,
7
+ required:true
8
+ },
9
+ facilityId:{
10
+ type: mongoose.Schema.Types.ObjectId,
11
+ ref: 'Facility',
12
+ }
13
+
14
+
15
+ }, {
16
+ timestamps: true // Automatically add createdAt and updatedAt fields
17
+ });
18
+
19
+ // Indexes for improved performance
20
+ facilityassetSchema.index({ name: 1 });
21
+
22
+ // Compile the model from the schema
23
+ const FacilityAsset = mongoose.model('FacilityAsset', facilityassetSchema);
24
+
25
+ module.exports = FacilityAsset;
package/src/models/faq.js CHANGED
@@ -1,15 +1,15 @@
1
- const mongoose = require('mongoose');
2
-
3
- const faqSchema = new mongoose.Schema({
4
- name:{type:String},
5
- question:{type:String,required:true},
6
- answer:{type:String,required:true},
7
- facilityId: {
8
- type: mongoose.Schema.Types.ObjectId,
9
- ref: 'Facility'
10
- },
11
- });
12
-
13
- const FAQ = mongoose.model('FAQ', faqSchema);
14
-
15
- module.exports = FAQ;
1
+ const mongoose = require('mongoose');
2
+
3
+ const faqSchema = new mongoose.Schema({
4
+ name:{type:String},
5
+ question:{type:String,required:true},
6
+ answer:{type:String,required:true},
7
+ facilityId: {
8
+ type: mongoose.Schema.Types.ObjectId,
9
+ ref: 'Facility'
10
+ },
11
+ });
12
+
13
+ const FAQ = mongoose.model('FAQ', faqSchema);
14
+
15
+ module.exports = FAQ;
@@ -1,25 +1,25 @@
1
- const mongoose = require('mongoose');
2
-
3
- const glAccountDoubleEntriesSchema = new mongoose.Schema({
4
- accountdebited: {
5
- type: mongoose.Schema.Types.ObjectId,
6
- ref: 'GLAccount',
7
- required: true,
8
- },
9
- accountcredited: {
10
- type: mongoose.Schema.Types.ObjectId,
11
- ref: 'GLAccount',
12
- required: true,
13
- },
14
- facilityId: {
15
- type: mongoose.Schema.Types.ObjectId,
16
- ref: 'Facility',
17
- required: true,
18
- },
19
- createdAt: {
20
- type: Date,
21
- default: Date.now,
22
- },
23
- });
24
-
25
- module.exports = mongoose.model('GLAccountDoubleEntries', glAccountDoubleEntriesSchema);
1
+ const mongoose = require('mongoose');
2
+
3
+ const glAccountDoubleEntriesSchema = new mongoose.Schema({
4
+ accountdebited: {
5
+ type: mongoose.Schema.Types.ObjectId,
6
+ ref: 'GLAccount',
7
+ required: true,
8
+ },
9
+ accountcredited: {
10
+ type: mongoose.Schema.Types.ObjectId,
11
+ ref: 'GLAccount',
12
+ required: true,
13
+ },
14
+ facilityId: {
15
+ type: mongoose.Schema.Types.ObjectId,
16
+ ref: 'Facility',
17
+ required: true,
18
+ },
19
+ createdAt: {
20
+ type: Date,
21
+ default: Date.now,
22
+ },
23
+ });
24
+
25
+ module.exports = mongoose.model('GLAccountDoubleEntries', glAccountDoubleEntriesSchema);
@@ -1,57 +1,57 @@
1
- const mongoose = require('mongoose');
2
-
3
- const glAccountsSchema = new mongoose.Schema({
4
- accountCode: {
5
- type: String,
6
- required: true,
7
- unique: true,
8
- trim: true,
9
- },
10
- accountName: {
11
- type: String,
12
- required: true,
13
- trim: true,
14
- },
15
- accountType: {
16
- type: String,
17
- required: true,
18
- trim: true,
19
- },
20
- accountBalance: {
21
- type: Number,
22
- default: 0,
23
- },
24
- facilityId: {
25
- type: mongoose.Schema.Types.ObjectId,
26
- ref: 'Facility',
27
- required: true,
28
- },
29
- parentAccountId: {
30
- type: mongoose.Schema.Types.ObjectId,
31
- ref: 'GLAccount',
32
- default: null,
33
- },
34
- accountLevel: {
35
- type: Number,
36
- required: true,
37
- default: 0,
38
- },
39
- isFinal: {
40
- type: Boolean,
41
- default: false,
42
- },
43
- isActive: {
44
- type: Boolean,
45
- default: true,
46
- },
47
- createdAt: {
48
- type: Date,
49
- default: Date.now,
50
- },
51
- updatedAt: {
52
- type: Date,
53
- default: Date.now,
54
- },
55
- });
56
-
1
+ const mongoose = require('mongoose');
2
+
3
+ const glAccountsSchema = new mongoose.Schema({
4
+ accountCode: {
5
+ type: String,
6
+ required: true,
7
+ unique: true,
8
+ trim: true,
9
+ },
10
+ accountName: {
11
+ type: String,
12
+ required: true,
13
+ trim: true,
14
+ },
15
+ accountType: {
16
+ type: String,
17
+ required: true,
18
+ trim: true,
19
+ },
20
+ accountBalance: {
21
+ type: Number,
22
+ default: 0,
23
+ },
24
+ facilityId: {
25
+ type: mongoose.Schema.Types.ObjectId,
26
+ ref: 'Facility',
27
+ required: true,
28
+ },
29
+ parentAccountId: {
30
+ type: mongoose.Schema.Types.ObjectId,
31
+ ref: 'GLAccount',
32
+ default: null,
33
+ },
34
+ accountLevel: {
35
+ type: Number,
36
+ required: true,
37
+ default: 0,
38
+ },
39
+ isFinal: {
40
+ type: Boolean,
41
+ default: false,
42
+ },
43
+ isActive: {
44
+ type: Boolean,
45
+ default: true,
46
+ },
47
+ createdAt: {
48
+ type: Date,
49
+ default: Date.now,
50
+ },
51
+ updatedAt: {
52
+ type: Date,
53
+ default: Date.now,
54
+ },
55
+ });
56
+
57
57
  module.exports = mongoose.model('GLAccount', glAccountsSchema);