payservedb 7.9.2 → 7.9.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 +249 -248
- package/package.json +1 -1
- package/src/models/facilityInvoicePayment.js +47 -0
package/index.js
CHANGED
|
@@ -6,283 +6,284 @@ const connections = {};
|
|
|
6
6
|
|
|
7
7
|
// Utility function to connect to MongoDB
|
|
8
8
|
async function connectToMongoDB(
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
dbName,
|
|
10
|
+
secured,
|
|
11
|
+
username,
|
|
12
|
+
password,
|
|
13
|
+
url,
|
|
14
|
+
port,
|
|
15
15
|
) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
} catch (err) {
|
|
34
|
-
console.error("Error connecting to MongoDB:", err);
|
|
35
|
-
throw err;
|
|
16
|
+
try {
|
|
17
|
+
if (secured === false) {
|
|
18
|
+
const url_ = url + ":" + port;
|
|
19
|
+
const connectionString = `mongodb://${url_}/${dbName}`;
|
|
20
|
+
await mongoose.connect(connectionString, {
|
|
21
|
+
useNewUrlParser: true,
|
|
22
|
+
});
|
|
23
|
+
console.log("Connected to MongoDB");
|
|
24
|
+
} else {
|
|
25
|
+
const url_ = `${username}:${password}@${url}:${port}`;
|
|
26
|
+
const source = "?authSource=admin";
|
|
27
|
+
const connectionString = `mongodb://${url_}/${dbName}${source}`;
|
|
28
|
+
await mongoose.connect(connectionString, {
|
|
29
|
+
useNewUrlParser: true,
|
|
30
|
+
});
|
|
31
|
+
console.log("Connected to MongoDB");
|
|
36
32
|
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error("Error connecting to MongoDB:", err);
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
// Function to switch databases dynamically
|
|
40
40
|
async function switchDB(dbName) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
41
|
+
// Check if there's already a connection to the desired database
|
|
42
|
+
if (connections[dbName]) {
|
|
43
|
+
return connections[dbName]; // Return existing connection
|
|
44
|
+
}
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
46
|
+
try {
|
|
47
|
+
// Use environment variables for connection parameters - same as in connectToMongoDB
|
|
48
|
+
const username = process.env.MONGODB_USER;
|
|
49
|
+
const password = process.env.MONGODB_PASSWORD;
|
|
50
|
+
const url = process.env.MONGODB_HOST;
|
|
51
|
+
const port = process.env.MONGODB_PORT;
|
|
52
|
+
const source = "?authSource=admin";
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
54
|
+
const connectionString = `mongodb://${username}:${password}@${url}:${port}/${dbName}${source}`;
|
|
55
|
+
const dbConnection = await mongoose.createConnection(connectionString, {
|
|
56
|
+
useNewUrlParser: true,
|
|
57
|
+
});
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
59
|
+
connections[dbName] = dbConnection; // Store the connection for reuse
|
|
60
|
+
console.log(`Switched to database: ${dbName}`);
|
|
61
|
+
return dbConnection;
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error(`Error switching to database: ${dbName}`, err);
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
// Importing all model files (Note: models may need to be re-registered for different connections)
|
|
69
69
|
// This maintains backward compatibility for existing services
|
|
70
70
|
const models = {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
71
|
+
User: require("./src/models/user"),
|
|
72
|
+
Company: require("./src/models/company"),
|
|
73
|
+
Customer: require("./src/models/customer"),
|
|
74
|
+
FacilityEmailDetails: require("./src/models/email"),
|
|
75
|
+
Module: require("./src/models/module"),
|
|
76
|
+
Facility: require("./src/models/facility"),
|
|
77
|
+
RefreshToken: require("./src/models/refresh_token"),
|
|
78
|
+
ApiLog: require("./src/models/apilog"),
|
|
79
|
+
ArchivedApiLog: require("./src/models/archivedapilog"),
|
|
80
|
+
FacilityAsset: require("./src/models/facilityasset"),
|
|
81
|
+
Unit: require("./src/models/units"),
|
|
82
|
+
FAQ: require("./src/models/faq"),
|
|
83
|
+
UnitAsset: require("./src/models/unitasset"),
|
|
84
|
+
CombinedUnit: require("./src/models/combinedUnits"),
|
|
85
|
+
Message: require("./src/models/message"),
|
|
86
|
+
SMSAfricastalking: require("./src/models/sms_africastalking"),
|
|
87
|
+
SMSMeliora: require("./src/models/sms_meliora"),
|
|
88
|
+
EntryExit: require("./src/models/entry_exit"),
|
|
89
|
+
Guard: require("./src/models/guard"),
|
|
90
|
+
Visitor: require("./src/models/visitor"),
|
|
91
|
+
VisitLog: require("./src/models/visitLog"),
|
|
92
|
+
Settings: require("./src/models/settings"),
|
|
93
|
+
Levy: require("./src/models/levy"),
|
|
94
|
+
LevyType: require("./src/models/levytype"),
|
|
95
|
+
LevyContract: require("./src/models/levycontract"),
|
|
96
|
+
Invoice: require("./src/models/invoice"),
|
|
97
|
+
Reminder: require("./src/models/reminder"),
|
|
98
|
+
Penalty: require("./src/models/penalty"),
|
|
99
|
+
Notifiaction: require("./src/models/notification"),
|
|
100
|
+
Resident: require("./src/models/resident"),
|
|
101
|
+
Asset: require("./src/models/asset"),
|
|
102
|
+
DutyRoster: require("./src/models/dutyroster"),
|
|
103
|
+
LeaseTemplate: require("./src/models/leasetemplate"),
|
|
104
|
+
Report: require("./src/models/report"),
|
|
105
|
+
Ticket: require("./src/models/tickets"),
|
|
106
|
+
Stocksandspare: require("./src/models/stocksandspare"),
|
|
107
|
+
ServiceVendor: require("./src/models/maintenance_service_vendor"),
|
|
108
|
+
MaintenanceServices: require("./src/models/maintenance_services"),
|
|
109
|
+
StockRequisition: require("./src/models/maintenancerequisition"),
|
|
110
|
+
LeaseAgreement: require("./src/models/leaseagreement"),
|
|
111
|
+
WorkOrder: require("./src/models/workorder"),
|
|
112
|
+
ValueAddedService: require("./src/models/valueaddedservices"),
|
|
113
|
+
VasInvoice: require("./src/models/vasinvoice"),
|
|
114
|
+
VasVendor: require("./src/models/vasvendor"),
|
|
115
|
+
Staff: require("./src/models/staff"),
|
|
116
|
+
ServiceRequest: require("./src/models/servicerequest"),
|
|
117
|
+
CountryTaxRate: require("./src/models/country_tax"),
|
|
118
|
+
WaterMeter: require("./src/models/water_meters"),
|
|
119
|
+
DailyConsumption: require("./src/models/smart_meter_daily_consumption"),
|
|
120
|
+
WaterMeterSettings: require("./src/models/water_meter_settings"),
|
|
121
|
+
AnalogBilling: require("./src/models/water_meter_billing"),
|
|
122
|
+
MeterSize: require("./src/models/water_meter_size"),
|
|
123
|
+
WaterInvoice: require("./src/models/water_invoice"),
|
|
124
|
+
MeterProtocol: require("./src/models/water_meter_communication"),
|
|
125
|
+
MeterManufacturer: require("./src/models/water_meter_manufacturer"),
|
|
126
|
+
MeterIotCard: require("./src/models/water_meter_iot_cards"),
|
|
127
|
+
MetersDelivery: require("./src/models/water_meters_delivery"),
|
|
128
|
+
Notification: require("./src/models/notification"),
|
|
129
|
+
Concentrator: require("./src/models/water_meter_concentrator"),
|
|
130
|
+
Handover: require("./src/models/handover"),
|
|
131
|
+
Budget: require("./src/models/budget"),
|
|
132
|
+
BudgetCategory: require("./src/models/budgetCategory"),
|
|
133
|
+
Expense: require("./src/models/expense"),
|
|
134
|
+
ExpenseCategory: require("./src/models/expense_category"),
|
|
135
|
+
InvoiceSettings: require("./src/models/levy_invoice_settings"),
|
|
136
|
+
Account: require("./src/models/account"),
|
|
137
|
+
FacilityPaymentDetails: require("./src/models/facility_payment_details"),
|
|
138
|
+
DefaultPaymentDetails: require("./src/models/default_payment_details"),
|
|
139
|
+
Currency: require("./src/models/currency_settings"),
|
|
140
|
+
WaterMeterAccount: require("./src/models/water_meter_account"),
|
|
141
|
+
SingleDayWaterMeterHistory: require("./src/models/water_meter_single_day_history"),
|
|
142
|
+
DailyWaterMeterHistory: require("./src/models/water_meter_daily_history"),
|
|
143
|
+
MonthlyWaterMeterHistory: require("./src/models/water_meter_monthly_history"),
|
|
144
|
+
WaterPrepaidCredit: require("./src/models/water_prepaid_credit"),
|
|
145
|
+
WaterPrepaidDebit: require("./src/models/water_prepaid_debit"),
|
|
146
|
+
MeterLog: require("./src/models/water_meter_communication_logs"),
|
|
147
|
+
CashPayment: require("./src/models/cashpayment"),
|
|
148
|
+
VasPayment: require("./src/models/vas_payments"),
|
|
149
|
+
VasInvoicesQuickBooks: require("./src/models/vas_invoices_upload"),
|
|
150
|
+
ServiceChargePayment: require("./src/models/service_charge_payments"),
|
|
151
|
+
ServiceChargeInvoiceUpload: require("./src/models/service_charge_invoice_upload"),
|
|
152
|
+
Campaign: require("./src/models/campaigns"),
|
|
153
|
+
InspectionItem: require("./src/models/item_inspection"),
|
|
154
|
+
Supplier: require("./src/models/suppliers"),
|
|
155
|
+
PurchaseRequest: require("./src/models/purchase_request"),
|
|
156
|
+
PurchaseOrder: require("./src/models/purchase_order"),
|
|
157
|
+
PaymentTermMark: require("./src/models/paymentTermsMarks"),
|
|
158
|
+
DeliveryTimeMark: require("./src/models/deliveryTimeMarks"),
|
|
159
|
+
RFQDetails: require("./src/models/rfq_details"),
|
|
160
|
+
RFQResponse: require("./src/models/rfq_response"),
|
|
161
|
+
ApprovalWorkflow: require("./src/models/approvalsWorkflows"),
|
|
162
|
+
CommonAreaElectricityReading: require("./src/models/common_area_electricity"),
|
|
163
|
+
CommonAreaWaterReading: require("./src/models/common_area_water"),
|
|
164
|
+
CommonAreaGeneratorReading: require("./src/models/common_area_generator"),
|
|
165
|
+
CommonAreaUtilityAlert: require("./src/models/common_area_utility_alert"),
|
|
166
|
+
BookingProperty: require("./src/models/bookingproperty"),
|
|
167
|
+
BookingReservation: require("./src/models/bookingreservation"),
|
|
168
|
+
BookingConfig: require("./src/models/bookingconfig"),
|
|
169
|
+
BookingAnalytics: require("./src/models/bookinganalytics"),
|
|
170
|
+
BookingInvoice: require("./src/models/booking_invoice"),
|
|
171
|
+
BankDetails: require("./src/models/bankdetails"),
|
|
172
|
+
RevenueRecord: require("./src/models/bookingrevenuerecord"),
|
|
173
|
+
GLAccount: require("./src/models/gl_accounts"),
|
|
174
|
+
GLEntry: require("./src/models/gl_entries"),
|
|
175
|
+
GLAccountDoubleEntries: require("./src/models/gl_account_double_entries"),
|
|
176
|
+
PendingCredential: require("./src/models/pendingCredentials"),
|
|
177
|
+
UnitManagementTemplate: require("./src/models/unitManagementTemplate"),
|
|
178
|
+
PropertyManagerRevenue: require("./src/models/propertyManagerRevenue"),
|
|
179
|
+
PropertyManagerContract: require("./src/models/propertyManagerContract"),
|
|
180
|
+
BillerAddress: require("./src/models/billerAddress"),
|
|
181
|
+
AssetAssignment: require("./src/models/assetsAssignment"),
|
|
182
|
+
Wallet: require("./src/models/wallet"),
|
|
183
|
+
WalletTransaction: require("./src/models/wallet_transactions"),
|
|
184
|
+
GoodsReceivedNote: require("./src/models/goodsReceivedNotes"),
|
|
185
|
+
CommunicationStatus: require("./src/models/communication_status"),
|
|
186
|
+
MeterCommandQueue: require("./src/models/water_meter_Command_Queue"),
|
|
187
|
+
FacilityDepartment: require("./src/models/facility_departements"),
|
|
188
|
+
EmailSmsQueue: require("./src/models/email_sms_queue"),
|
|
189
|
+
PurchaseOrderInvoice: require("./src/models/purchaseOrderInvoice"),
|
|
190
|
+
PowerMeterCustomerBand: require("./src/models/powerMeterCustomerBand"),
|
|
191
|
+
PowerMeterCommunicationProtocol: require("./src/models/powerMeterCommunicationProtocol"),
|
|
192
|
+
PowerMeterDailyReading: require("./src/models/powerMeterDailyReading"),
|
|
193
|
+
PowerMeterPowerCharge: require("./src/models/powerMeterPowerCharges"),
|
|
194
|
+
PowerMeterGateway: require("./src/models/powerMeterGateways"),
|
|
195
|
+
PowerMeters: require("./src/models/powerMeters"),
|
|
196
|
+
PowerMeterSingleDayReading: require("./src/models/powerMeterSingleDayReading"),
|
|
197
|
+
PowerMeterAccount: require("./src/models/power_meter_account"),
|
|
198
|
+
PowerMeterLog: require("./src/models/power_meter_command_logs"),
|
|
199
|
+
PowerMeterManufacturer: require("./src/models/powerMetersManufacturer"),
|
|
200
|
+
PowerMeterMonthlyReading: require("./src/models/powerMeterMonthlyReading"),
|
|
201
|
+
PowerMeterSettings: require("./src/models/powerMeterSettings"),
|
|
202
|
+
PowerPrepaidDebit: require("./src/models/power_prepaid_debits"),
|
|
203
|
+
PowerPrepaidCredit: require("./src/models/power_prepaid_credits"),
|
|
204
|
+
PowerNegativeBalance: require("./src/models/power_meter_negative_balance"),
|
|
205
|
+
PowerCommandQueue: require("./src/models/power_meter_command_queue"),
|
|
206
|
+
PowerNotification: require("./src/models/power_sms_notification"),
|
|
207
|
+
PowerPrepaidOrder: require("./src/models/power_prepaid_orders"),
|
|
208
|
+
FacilityWalletTransactionsMetadata: require("./src/models/facilityWalletTransactionsMetadata"),
|
|
209
|
+
NegativeBalance: require("./src/models/water_meter_negative_amounts"),
|
|
210
|
+
MasterWorkplan: require("./src/models/master_workplan"),
|
|
211
|
+
MasterWorkplanChild: require("./src/models/master_workplan_child"),
|
|
212
|
+
DutyRosterChecklist: require("./src/models/dutyRosterChecklist"),
|
|
213
|
+
AuditTrail: require("./src/models/auditTrail"),
|
|
214
|
+
DailyChecklist: require("./src/models/dailyChecklist"),
|
|
215
|
+
CoreInvoiceSettings: require("./src/models/coreInvoiceSettings"),
|
|
216
|
+
FacilityInvoice: require("./src/models/facilityInvoice"),
|
|
217
|
+
CoreBaseSettings: require("./src/models/coreBaseSettings"),
|
|
218
|
+
Recipient: require("./src/models/facilityInvoiceRecipient"),
|
|
219
|
+
FacilityBillingPrice: require("./src/models/facilityBillingPrices"),
|
|
220
|
+
FacilityInvoicePayment: require("./src/models/facilityInvoicePayment"),
|
|
220
221
|
};
|
|
221
222
|
|
|
222
223
|
// Function to get models dynamically from a specific database connection
|
|
223
224
|
async function getModelFromDB(dbConnection, modelName, schema) {
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
225
|
+
if (!dbConnection.models[modelName]) {
|
|
226
|
+
return dbConnection.model(modelName, schema); // Register the model in the db connection
|
|
227
|
+
}
|
|
228
|
+
return dbConnection.models[modelName]; // Return existing model if already registered
|
|
228
229
|
}
|
|
229
230
|
|
|
230
231
|
// Function to initialize service with specific models - NEW FEATURE
|
|
231
232
|
function initializeService(modelNames = []) {
|
|
232
|
-
|
|
233
|
+
let currentConnection = null;
|
|
233
234
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
235
|
+
// Enhanced connect function that only registers specified models
|
|
236
|
+
async function connectWithModels(
|
|
237
|
+
dbName,
|
|
238
|
+
secured,
|
|
239
|
+
username,
|
|
240
|
+
password,
|
|
241
|
+
url,
|
|
242
|
+
port,
|
|
243
|
+
) {
|
|
244
|
+
await connectToMongoDB(dbName, secured, username, password, url, port);
|
|
245
|
+
currentConnection = mongoose.connection;
|
|
245
246
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
247
|
+
// Only register the models specified in modelNames
|
|
248
|
+
modelNames.forEach((modelName) => {
|
|
249
|
+
if (models[modelName]) {
|
|
250
|
+
let schema;
|
|
250
251
|
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
252
|
+
// Extract schema from the imported model
|
|
253
|
+
if (models[modelName].schema) {
|
|
254
|
+
schema = models[modelName].schema;
|
|
255
|
+
} else {
|
|
256
|
+
console.warn(`Unable to extract schema from model ${modelName}`);
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
258
259
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
260
|
+
if (!currentConnection.models[modelName]) {
|
|
261
|
+
const modelInstance = currentConnection.model(modelName, schema);
|
|
262
|
+
// Make model globally accessible through payservedb
|
|
263
|
+
module.exports[modelName] = modelInstance;
|
|
264
|
+
} else {
|
|
265
|
+
module.exports[modelName] = currentConnection.models[modelName];
|
|
266
|
+
}
|
|
267
|
+
} else {
|
|
268
|
+
console.warn(`Model ${modelName} not found in models registry`);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
270
271
|
|
|
271
|
-
|
|
272
|
-
|
|
272
|
+
return module.exports;
|
|
273
|
+
}
|
|
273
274
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
275
|
+
return {
|
|
276
|
+
connectToMongoDB: connectWithModels,
|
|
277
|
+
switchDB,
|
|
278
|
+
getModelFromDB,
|
|
279
|
+
getCurrentConnection: () => currentConnection,
|
|
280
|
+
};
|
|
280
281
|
}
|
|
281
282
|
|
|
282
283
|
module.exports = {
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
284
|
+
connectToMongoDB,
|
|
285
|
+
switchDB,
|
|
286
|
+
getModelFromDB,
|
|
287
|
+
initializeService,
|
|
288
|
+
...models,
|
|
288
289
|
};
|
package/package.json
CHANGED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
const FacilityInvoicePaymentSchema = new mongoose.Schema({
|
|
4
|
+
facilityId: {
|
|
5
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
6
|
+
ref: "Facility",
|
|
7
|
+
required: true,
|
|
8
|
+
},
|
|
9
|
+
invoiceId: {
|
|
10
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
11
|
+
ref: "Invoice",
|
|
12
|
+
required: true,
|
|
13
|
+
},
|
|
14
|
+
paymentDate: {
|
|
15
|
+
type: Date,
|
|
16
|
+
required: true,
|
|
17
|
+
},
|
|
18
|
+
amountPaid: {
|
|
19
|
+
type: Number,
|
|
20
|
+
required: true,
|
|
21
|
+
},
|
|
22
|
+
comments: {
|
|
23
|
+
type: String,
|
|
24
|
+
required: false,
|
|
25
|
+
},
|
|
26
|
+
status: {
|
|
27
|
+
type: String,
|
|
28
|
+
enum: ["pending", "paid", "overpaid", "rejected"],
|
|
29
|
+
default: "pending",
|
|
30
|
+
},
|
|
31
|
+
paymentMethod: {
|
|
32
|
+
type: String,
|
|
33
|
+
enum: ["cash", "credit", "debit"],
|
|
34
|
+
default: "cash",
|
|
35
|
+
},
|
|
36
|
+
rejectedReason: {
|
|
37
|
+
type: String,
|
|
38
|
+
required: false,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
const FacilityInvoicePayment = mongoose.model(
|
|
43
|
+
"FacilityInvoicePayment",
|
|
44
|
+
FacilityInvoicePaymentSchema,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
module.exports = FacilityInvoicePayment;
|