payservedb 5.6.5 → 5.6.7
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 +169 -167
- package/package.json +1 -1
- package/src/models/notification.js +28 -20
package/index.js
CHANGED
|
@@ -1,191 +1,193 @@
|
|
|
1
|
-
const mongoose = require(
|
|
2
|
-
require(
|
|
3
|
-
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
require("dotenv").config();
|
|
4
3
|
|
|
5
4
|
// Maintain a record of open connections for each database
|
|
6
5
|
const connections = {};
|
|
7
6
|
|
|
8
|
-
|
|
9
7
|
// Utility function to connect to MongoDB
|
|
10
|
-
async function connectToMongoDB(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
8
|
+
async function connectToMongoDB(
|
|
9
|
+
dbName,
|
|
10
|
+
secured,
|
|
11
|
+
username,
|
|
12
|
+
password,
|
|
13
|
+
url,
|
|
14
|
+
port,
|
|
15
|
+
) {
|
|
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");
|
|
33
32
|
}
|
|
33
|
+
} catch (err) {
|
|
34
|
+
console.error("Error connecting to MongoDB:", err);
|
|
35
|
+
throw err;
|
|
36
|
+
}
|
|
34
37
|
}
|
|
35
38
|
|
|
36
|
-
|
|
37
39
|
// Function to switch databases dynamically
|
|
38
40
|
async function switchDB(dbName) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
// Check if there's already a connection to the desired database
|
|
42
|
+
if (connections[dbName]) {
|
|
43
|
+
return connections[dbName]; // Return existing connection
|
|
44
|
+
}
|
|
43
45
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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";
|
|
51
53
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
const connectionString = `mongodb://${username}:${password}@${url}:${port}/${dbName}${source}`;
|
|
55
|
+
const dbConnection = await mongoose.createConnection(connectionString, {
|
|
56
|
+
useNewUrlParser: true,
|
|
57
|
+
});
|
|
56
58
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
+
}
|
|
64
66
|
}
|
|
65
67
|
|
|
66
|
-
|
|
67
68
|
// Importing all model files (Note: models may need to be re-registered for different connections)
|
|
68
69
|
const models = {
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
70
|
+
User: require("./src/models/user"),
|
|
71
|
+
AuditLog: require("./src/models/auditlog"),
|
|
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
|
+
ArchivedAuditLog: require("./src/models/archivedauditlog"),
|
|
81
|
+
FacilityAsset: require("./src/models/facilityasset"),
|
|
82
|
+
Unit: require("./src/models/units"),
|
|
83
|
+
FAQ: require("./src/models/faq"),
|
|
84
|
+
UnitAsset: require("./src/models/unitasset"),
|
|
85
|
+
CombinedUnit: require("./src/models/combinedUnits"),
|
|
86
|
+
Message: require("./src/models/message"),
|
|
87
|
+
SMSAfricastalking: require("./src/models/sms_africastalking"),
|
|
88
|
+
SMSMeliora: require("./src/models/sms_meliora"),
|
|
89
|
+
EntryExit: require("./src/models/entry_exit"),
|
|
90
|
+
Guard: require("./src/models/guard"),
|
|
91
|
+
Visitor: require("./src/models/visitor"),
|
|
92
|
+
VisitLog: require("./src/models/visitLog"),
|
|
93
|
+
Settings: require("./src/models/settings"),
|
|
94
|
+
Levy: require("./src/models/levy"),
|
|
95
|
+
LevyType: require("./src/models/levytype"),
|
|
96
|
+
LevyContract: require("./src/models/levycontract"),
|
|
97
|
+
Invoice: require("./src/models/invoice"),
|
|
98
|
+
Reminder: require("./src/models/reminder"),
|
|
99
|
+
Penalty: require("./src/models/penalty"),
|
|
100
|
+
Notifiaction: require("./src/models/notification"),
|
|
101
|
+
Resident: require("./src/models/resident"),
|
|
102
|
+
Asset: require("./src/models/asset"),
|
|
103
|
+
DutyRoster: require("./src/models/dutyroster"),
|
|
104
|
+
LeaseTemplate: require("./src/models/leasetemplate"),
|
|
105
|
+
Report: require("./src/models/report"),
|
|
106
|
+
Ticket: require("./src/models/tickets"),
|
|
107
|
+
Stocksandspare: require("./src/models/stocksandspare"),
|
|
108
|
+
ServiceVendor: require("./src/models/maintenance_service_vendor"),
|
|
109
|
+
MaintenanceServices: require("./src/models/maintenance_services"),
|
|
110
|
+
StockRequisition: require("./src/models/maintenancerequisition"),
|
|
111
|
+
LeaseAgreement: require("./src/models/leaseagreement"),
|
|
112
|
+
WorkOrder: require("./src/models/workorder"),
|
|
113
|
+
ValueAddedService: require("./src/models/valueaddedservices"),
|
|
114
|
+
VasInvoice: require("./src/models/vasinvoice"),
|
|
115
|
+
VasVendor: require("./src/models/vasvendor"),
|
|
116
|
+
Staff: require("./src/models/staff"),
|
|
117
|
+
ServiceRequest: require("./src/models/servicerequest"),
|
|
118
|
+
CountryTaxRate: require("./src/models/country_tax"),
|
|
119
|
+
WaterMeter: require("./src/models/water_meters"),
|
|
120
|
+
DailyConsumption: require("./src/models/smart_meter_daily_consumption"),
|
|
121
|
+
WaterMeterSettings: require("./src/models/water_meter_settings"),
|
|
122
|
+
AnalogBilling: require("./src/models/water_meter_billing"),
|
|
123
|
+
MeterSize: require("./src/models/water_meter_size"),
|
|
124
|
+
WaterInvoice: require("./src/models/water_invoice"),
|
|
125
|
+
MeterProtocol: require("./src/models/water_meter_communication"),
|
|
126
|
+
MeterManufacturer: require("./src/models/water_meter_manufacturer"),
|
|
127
|
+
MeterIotCard: require("./src/models/water_meter_iot_cards"),
|
|
128
|
+
MetersDelivery: require("./src/models/water_meters_delivery"),
|
|
129
|
+
Notification: require("./src/models/notification"),
|
|
130
|
+
Concentrator: require("./src/models/water_meter_concentrator"),
|
|
131
|
+
Handover: require("./src/models/handover"),
|
|
132
|
+
Budget: require("./src/models/budget"),
|
|
133
|
+
BudgetCategory: require("./src/models/budgetCategory"),
|
|
134
|
+
Expense: require("./src/models/expense"),
|
|
135
|
+
ExpenseCategory: require("./src/models/expense_category"),
|
|
136
|
+
InvoiceSettings: require("./src/models/levy_invoice_settings"),
|
|
137
|
+
Account: require("./src/models/account"),
|
|
138
|
+
FacilityPaymentDetails: require("./src/models/facility_payment_details"),
|
|
139
|
+
DefaultPaymentDetails: require("./src/models/default_payment_details"),
|
|
140
|
+
Currency: require("./src/models/currency_settings"),
|
|
141
|
+
WaterMeterAccount: require("./src/models/water_meter_account"),
|
|
142
|
+
SingleDayWaterMeterHistory: require("./src/models/water_meter_single_day_history"),
|
|
143
|
+
DailyWaterMeterHistory: require("./src/models/water_meter_daily_history"),
|
|
144
|
+
MonthlyWaterMeterHistory: require("./src/models/water_meter_monthly_history"),
|
|
145
|
+
WaterPrepaidCredit: require("./src/models/water_prepaid_credit"),
|
|
146
|
+
WaterPrepaidDebit: require("./src/models/water_prepaid_debit"),
|
|
147
|
+
MeterLog: require("./src/models/water_meter_communication_logs"),
|
|
148
|
+
CashPayment: require("./src/models/cashpayment"),
|
|
149
|
+
VasPayment: require("./src/models/vas_payments"),
|
|
150
|
+
VasInvoicesQuickBooks: require("./src/models/vas_invoices_upload"),
|
|
151
|
+
ServiceChargePayment: require("./src/models/service_charge_payments"),
|
|
152
|
+
ServiceChargeInvoiceUpload: require("./src/models/service_charge_invoice_upload"),
|
|
153
|
+
Campaign: require("./src/models/campaigns"),
|
|
154
|
+
InspectionItem: require("./src/models/item_inspection"),
|
|
155
|
+
Supplier: require("./src/models/suppliers"),
|
|
156
|
+
PurchaseRequest: require("./src/models/purchase_request"),
|
|
157
|
+
PurchaseOrder: require("./src/models/purchase_order"),
|
|
158
|
+
RFQDetails: require("./src/models/rfq_details"),
|
|
159
|
+
RFQResponse: require("./src/models/rfq_response"),
|
|
160
|
+
ApprovalWorkflow: require("./src/models/approvalsWorkflows"),
|
|
161
|
+
CommonAreaElectricityReading: require("./src/models/common_area_electricity"),
|
|
162
|
+
CommonAreaWaterReading: require("./src/models/common_area_water"),
|
|
163
|
+
CommonAreaGeneratorReading: require("./src/models/common_area_generator"),
|
|
164
|
+
CommonAreaUtilityAlert: require("./src/models/common_area_utility_alert"),
|
|
165
|
+
BookingProperty: require("./src/models/bookingproperty"),
|
|
166
|
+
BookingReservation: require("./src/models/bookingreservation"),
|
|
167
|
+
BookingConfig: require("./src/models/bookingconfig"),
|
|
168
|
+
BookingAnalytics: require("./src/models/bookinganalytics"),
|
|
169
|
+
BookingInvoice: require("./src/models/booking_invoice"),
|
|
170
|
+
RevenueRecord: require("./src/models/bookingrevenuerecord"),
|
|
171
|
+
GLAccount: require("./src/models/gl_accounts"),
|
|
172
|
+
GLEntry: require("./src/models/gl_entries"),
|
|
173
|
+
GLAccountDoubleEntries: require("./src/models/gl_account_double_entries"),
|
|
174
|
+
PendingCredential: require("./src/models/pendingCredentials"),
|
|
175
|
+
UnitManagementTemplate: require("./src/models/unitManagementTemplate"),
|
|
176
|
+
PropertyManagerRevenue: require("./src/models/propertyManagerRevenue"),
|
|
177
|
+
PropertyManagerContract: require("./src/models/propertyManagerContract"),
|
|
176
178
|
};
|
|
177
179
|
|
|
178
180
|
// Function to get models dynamically from a specific database connection
|
|
179
181
|
async function getModelFromDB(dbConnection, modelName, schema) {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
182
|
+
if (!dbConnection.models[modelName]) {
|
|
183
|
+
return dbConnection.model(modelName, schema); // Register the model in the db connection
|
|
184
|
+
}
|
|
185
|
+
return dbConnection.models[modelName]; // Return existing model if already registered
|
|
184
186
|
}
|
|
185
187
|
|
|
186
188
|
module.exports = {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
}
|
|
189
|
+
connectToMongoDB,
|
|
190
|
+
switchDB,
|
|
191
|
+
getModelFromDB,
|
|
192
|
+
...models, // Spread operator to export all models
|
|
193
|
+
};
|
package/package.json
CHANGED
|
@@ -1,36 +1,44 @@
|
|
|
1
|
-
const mongoose = require(
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
2
|
|
|
3
3
|
// Define the schema for Notifications
|
|
4
|
-
const notificationSchema = new mongoose.Schema(
|
|
4
|
+
const notificationSchema = new mongoose.Schema(
|
|
5
|
+
{
|
|
5
6
|
userId: {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
8
|
+
ref: "User",
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
facilityId: {
|
|
12
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
13
|
+
ref: "Facility",
|
|
14
|
+
required: true,
|
|
9
15
|
},
|
|
10
16
|
message: {
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
type: String,
|
|
18
|
+
required: true,
|
|
13
19
|
},
|
|
14
20
|
read: {
|
|
15
|
-
|
|
16
|
-
|
|
21
|
+
type: Boolean,
|
|
22
|
+
default: false,
|
|
17
23
|
},
|
|
18
24
|
dateRead: {
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
type: Date,
|
|
26
|
+
default: null,
|
|
21
27
|
},
|
|
22
28
|
dateUpdated: {
|
|
23
|
-
|
|
24
|
-
|
|
29
|
+
type: Date,
|
|
30
|
+
default: null,
|
|
25
31
|
},
|
|
26
32
|
dateSent: {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
|
|
32
|
-
|
|
33
|
+
type: Date,
|
|
34
|
+
required: true,
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
timestamps: true,
|
|
39
|
+
},
|
|
40
|
+
);
|
|
33
41
|
|
|
34
|
-
const Notification = mongoose.model(
|
|
42
|
+
const Notification = mongoose.model("Notification", notificationSchema);
|
|
35
43
|
|
|
36
44
|
module.exports = Notification;
|