@7365admin1/core 2.22.0 → 2.24.0
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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +197 -4
- package/dist/index.js +1728 -120
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1945 -331
- package/dist/index.mjs.map +1 -1
- package/dist/public/handlebars/alert-email.hbs +43 -0
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -69,6 +69,7 @@ __export(src_exports, {
|
|
|
69
69
|
MManpowerDesignations: () => MManpowerDesignations,
|
|
70
70
|
MManpowerMonitoring: () => MManpowerMonitoring,
|
|
71
71
|
MManpowerRemarks: () => MManpowerRemarks,
|
|
72
|
+
MManpowerSites: () => MManpowerSites,
|
|
72
73
|
MMember: () => MMember,
|
|
73
74
|
MNfcPatrolLog: () => MNfcPatrolLog,
|
|
74
75
|
MNfcPatrolRoute: () => MNfcPatrolRoute,
|
|
@@ -134,6 +135,7 @@ __export(src_exports, {
|
|
|
134
135
|
bulletin_boards_namespace_collection: () => bulletin_boards_namespace_collection,
|
|
135
136
|
calculatePercentage: () => calculatePercentage,
|
|
136
137
|
chatSchema: () => chatSchema,
|
|
138
|
+
createManpowerRemarksDaily: () => createManpowerRemarksDaily,
|
|
137
139
|
customerSchema: () => customerSchema,
|
|
138
140
|
designationsSchema: () => designationsSchema,
|
|
139
141
|
events_namespace_collection: () => events_namespace_collection,
|
|
@@ -148,10 +150,13 @@ __export(src_exports, {
|
|
|
148
150
|
landscapeDashboardCollection: () => landscapeDashboardCollection,
|
|
149
151
|
mAndEDashboardCollection: () => mAndEDashboardCollection,
|
|
150
152
|
manpowerDesignationsSchema: () => manpowerDesignationsSchema,
|
|
153
|
+
manpowerEvents: () => manpowerEvents,
|
|
151
154
|
manpowerMonitoringSchema: () => manpowerMonitoringSchema,
|
|
152
155
|
manpowerRemarksSchema: () => manpowerRemarksSchema,
|
|
156
|
+
manpowerSitesSchema: () => manpowerSitesSchema,
|
|
153
157
|
nfcPatrolSettingsSchema: () => nfcPatrolSettingsSchema,
|
|
154
158
|
nfcPatrolSettingsSchemaUpdate: () => nfcPatrolSettingsSchemaUpdate,
|
|
159
|
+
occurrence_book_namespace_collection: () => occurrence_book_namespace_collection,
|
|
155
160
|
orgSchema: () => orgSchema,
|
|
156
161
|
overnight_parking_requests_namespace_collection: () => overnight_parking_requests_namespace_collection,
|
|
157
162
|
pestDashboardCollection: () => pestDashboardCollection,
|
|
@@ -232,6 +237,8 @@ __export(src_exports, {
|
|
|
232
237
|
siteSchema: () => siteSchema,
|
|
233
238
|
site_people_namespace_collection: () => site_people_namespace_collection,
|
|
234
239
|
tokenSchema: () => tokenSchema,
|
|
240
|
+
updateRemarksStatusEod: () => updateRemarksStatusEod,
|
|
241
|
+
updateRemarksisAcknowledged: () => updateRemarksisAcknowledged,
|
|
235
242
|
updateSiteSchema: () => updateSiteSchema,
|
|
236
243
|
useAccessManagementController: () => useAccessManagementController,
|
|
237
244
|
useAddressRepo: () => useAddressRepo,
|
|
@@ -298,6 +305,9 @@ __export(src_exports, {
|
|
|
298
305
|
useManpowerMonitoringSrvc: () => useManpowerMonitoringSrvc,
|
|
299
306
|
useManpowerRemarkCtrl: () => useManpowerRemarkCtrl,
|
|
300
307
|
useManpowerRemarksRepo: () => useManpowerRemarksRepo,
|
|
308
|
+
useManpowerSitesCtrl: () => useManpowerSitesCtrl,
|
|
309
|
+
useManpowerSitesRepo: () => useManpowerSitesRepo,
|
|
310
|
+
useManpowerSitesSrvc: () => useManpowerSitesSrvc,
|
|
301
311
|
useMemberController: () => useMemberController,
|
|
302
312
|
useMemberRepo: () => useMemberRepo,
|
|
303
313
|
useNewDashboardController: () => useNewDashboardController,
|
|
@@ -345,6 +355,9 @@ __export(src_exports, {
|
|
|
345
355
|
usePriceRepo: () => usePriceRepo,
|
|
346
356
|
usePromoCodeController: () => usePromoCodeController,
|
|
347
357
|
usePromoCodeRepo: () => usePromoCodeRepo,
|
|
358
|
+
useRedDotPaymentController: () => useRedDotPaymentController,
|
|
359
|
+
useRedDotPaymentRepo: () => useRedDotPaymentRepo,
|
|
360
|
+
useRedDotPaymentSvc: () => useRedDotPaymentSvc,
|
|
348
361
|
useRobotController: () => useRobotController,
|
|
349
362
|
useRobotRepo: () => useRobotRepo,
|
|
350
363
|
useRobotService: () => useRobotService,
|
|
@@ -12990,7 +13003,8 @@ var schemaPerson = import_joi35.default.object({
|
|
|
12990
13003
|
companyName: import_joi35.default.array().items(import_joi35.default.string()).optional(),
|
|
12991
13004
|
plates: import_joi35.default.array().items(schemaPlate).optional().allow(null),
|
|
12992
13005
|
isOwner: import_joi35.default.boolean().required(),
|
|
12993
|
-
files: import_joi35.default.array().items(schemaFiles).optional().allow(null)
|
|
13006
|
+
files: import_joi35.default.array().items(schemaFiles).optional().allow(null),
|
|
13007
|
+
password: import_joi35.default.string().optional().allow(null, "")
|
|
12994
13008
|
});
|
|
12995
13009
|
var schemaUpdatePerson = import_joi35.default.object({
|
|
12996
13010
|
_id: import_joi35.default.string().hex().required(),
|
|
@@ -13009,7 +13023,8 @@ var schemaUpdatePerson = import_joi35.default.object({
|
|
|
13009
13023
|
companyName: import_joi35.default.array().items(import_joi35.default.string()).optional().allow(null, ""),
|
|
13010
13024
|
plates: import_joi35.default.array().items(schemaFiles).optional().allow(null, ""),
|
|
13011
13025
|
isOwner: import_joi35.default.boolean().optional().allow(null, ""),
|
|
13012
|
-
files: import_joi35.default.array().items(schemaFiles).optional().allow(null)
|
|
13026
|
+
files: import_joi35.default.array().items(schemaFiles).optional().allow(null),
|
|
13027
|
+
password: import_joi35.default.string().optional().allow(null, "")
|
|
13013
13028
|
});
|
|
13014
13029
|
function MPerson(value) {
|
|
13015
13030
|
const { error } = schemaPerson.validate(value);
|
|
@@ -13060,6 +13075,7 @@ function MPerson(value) {
|
|
|
13060
13075
|
end: value.end,
|
|
13061
13076
|
type: value.type,
|
|
13062
13077
|
email: value.email,
|
|
13078
|
+
password: value.password ?? "",
|
|
13063
13079
|
status: value.status ?? "active",
|
|
13064
13080
|
nric: value.nric,
|
|
13065
13081
|
remarks: value.remarks,
|
|
@@ -13609,6 +13625,8 @@ var VehicleSort = /* @__PURE__ */ ((VehicleSort2) => {
|
|
|
13609
13625
|
VehicleSort2["CREATED_AT"] = "createdAt";
|
|
13610
13626
|
VehicleSort2["ID"] = "_id";
|
|
13611
13627
|
VehicleSort2["NAME"] = "name";
|
|
13628
|
+
VehicleSort2["START"] = "start";
|
|
13629
|
+
VehicleSort2["END"] = "end";
|
|
13612
13630
|
return VehicleSort2;
|
|
13613
13631
|
})(VehicleSort || {});
|
|
13614
13632
|
var OrgNature = /* @__PURE__ */ ((OrgNature2) => {
|
|
@@ -13761,6 +13779,7 @@ var import_mongodb41 = require("mongodb");
|
|
|
13761
13779
|
var import_joi38 = __toESM(require("joi"));
|
|
13762
13780
|
var vehicles_namespace_collection = "vehicles";
|
|
13763
13781
|
function useVehicleRepo() {
|
|
13782
|
+
vehicles_namespace_collection;
|
|
13764
13783
|
const db = import_node_server_utils69.useAtlas.getDb();
|
|
13765
13784
|
if (!db) {
|
|
13766
13785
|
throw new import_node_server_utils69.InternalServerError("Unable to connect to server.");
|
|
@@ -18238,11 +18257,13 @@ function useVehicleController() {
|
|
|
18238
18257
|
getAllVehiclesByUnitId: _getAllVehiclesByUnitId
|
|
18239
18258
|
} = useVehicleRepo();
|
|
18240
18259
|
async function add(req, res, next) {
|
|
18241
|
-
const
|
|
18242
|
-
|
|
18260
|
+
const { error, value } = vehicleSchema.validate(req.body, {
|
|
18261
|
+
abortEarly: false
|
|
18262
|
+
});
|
|
18243
18263
|
if (error) {
|
|
18244
|
-
|
|
18245
|
-
|
|
18264
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
18265
|
+
import_node_server_utils85.logger.log({ level: "error", message: messages });
|
|
18266
|
+
next(new import_node_server_utils85.BadRequestError(messages));
|
|
18246
18267
|
return;
|
|
18247
18268
|
}
|
|
18248
18269
|
try {
|
|
@@ -18258,40 +18279,29 @@ function useVehicleController() {
|
|
|
18258
18279
|
}
|
|
18259
18280
|
}
|
|
18260
18281
|
async function getVehicles(req, res, next) {
|
|
18261
|
-
const
|
|
18262
|
-
const allowedOrder = ["asc", "desc"];
|
|
18263
|
-
const validation = import_joi46.default.object({
|
|
18282
|
+
const schema2 = import_joi46.default.object({
|
|
18264
18283
|
search: import_joi46.default.string().optional().allow("", null),
|
|
18265
|
-
page: import_joi46.default.number().integer().min(1).
|
|
18266
|
-
limit: import_joi46.default.number().integer().min(1).max(100).
|
|
18267
|
-
sort: import_joi46.default.string().
|
|
18268
|
-
order: import_joi46.default.string().
|
|
18284
|
+
page: import_joi46.default.number().integer().min(1).optional().default(1),
|
|
18285
|
+
limit: import_joi46.default.number().integer().min(1).max(100).optional().default(10),
|
|
18286
|
+
sort: import_joi46.default.string().optional().valid(...Object.values(VehicleSort)),
|
|
18287
|
+
order: import_joi46.default.string().optional().valid(...Object.values(SortOrder)),
|
|
18269
18288
|
type: import_joi46.default.string().optional().valid(...Object.values(VehicleType)).allow(null, ""),
|
|
18270
18289
|
category: import_joi46.default.string().optional().valid(...Object.values(VehicleCategory)).allow(null, ""),
|
|
18271
18290
|
status: import_joi46.default.string().optional().valid(...Object.values(VehicleStatus)).allow(null, "")
|
|
18272
18291
|
});
|
|
18273
|
-
const
|
|
18274
|
-
|
|
18292
|
+
const { error, value } = schema2.validate(req.query, {
|
|
18293
|
+
abortEarly: false
|
|
18294
|
+
});
|
|
18275
18295
|
if (error) {
|
|
18276
|
-
|
|
18277
|
-
|
|
18296
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
18297
|
+
import_node_server_utils85.logger.log({ level: "error", message: messages });
|
|
18298
|
+
next(new import_node_server_utils85.BadRequestError(messages));
|
|
18278
18299
|
return;
|
|
18279
18300
|
}
|
|
18280
|
-
const search
|
|
18281
|
-
const
|
|
18282
|
-
|
|
18283
|
-
|
|
18284
|
-
const category = req.query.category ?? "";
|
|
18285
|
-
const status = req.query.status ?? "";
|
|
18286
|
-
const sortObj = {};
|
|
18287
|
-
const sortFields = String(req.query.sort).split(",");
|
|
18288
|
-
const sortOrders = String(req.query.order).split(",");
|
|
18289
|
-
sortFields.forEach((field, index) => {
|
|
18290
|
-
if (allowedFields.includes(field)) {
|
|
18291
|
-
const order = sortOrders[index] === "asc" ? 1 : -1;
|
|
18292
|
-
sortObj[field] = order;
|
|
18293
|
-
}
|
|
18294
|
-
});
|
|
18301
|
+
const { search, page, limit, type, category, status, sort, order } = value;
|
|
18302
|
+
const sortObj = {
|
|
18303
|
+
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
18304
|
+
};
|
|
18295
18305
|
try {
|
|
18296
18306
|
const data = await _getVehicles({
|
|
18297
18307
|
search,
|
|
@@ -18311,14 +18321,20 @@ function useVehicleController() {
|
|
|
18311
18321
|
}
|
|
18312
18322
|
}
|
|
18313
18323
|
async function getSeasonPassTypes(req, res, next) {
|
|
18314
|
-
const
|
|
18315
|
-
|
|
18316
|
-
|
|
18324
|
+
const schema2 = import_joi46.default.object({
|
|
18325
|
+
site: import_joi46.default.string().hex().length(24).required()
|
|
18326
|
+
});
|
|
18327
|
+
const { error, value } = schema2.validate(
|
|
18328
|
+
{ site: req.params.site },
|
|
18329
|
+
{ abortEarly: false }
|
|
18330
|
+
);
|
|
18317
18331
|
if (error) {
|
|
18318
|
-
|
|
18319
|
-
|
|
18332
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
18333
|
+
import_node_server_utils85.logger.log({ level: "error", message: messages });
|
|
18334
|
+
next(new import_node_server_utils85.BadRequestError(messages));
|
|
18320
18335
|
return;
|
|
18321
18336
|
}
|
|
18337
|
+
const { site } = value;
|
|
18322
18338
|
try {
|
|
18323
18339
|
const data = await _getSeasonPassTypes(site);
|
|
18324
18340
|
res.json(data);
|
|
@@ -18330,14 +18346,20 @@ function useVehicleController() {
|
|
|
18330
18346
|
}
|
|
18331
18347
|
}
|
|
18332
18348
|
async function getVehicleById(req, res, next) {
|
|
18333
|
-
const
|
|
18334
|
-
|
|
18335
|
-
|
|
18349
|
+
const schema2 = import_joi46.default.object({
|
|
18350
|
+
_id: import_joi46.default.string().hex().length(24).required()
|
|
18351
|
+
});
|
|
18352
|
+
const { error, value } = schema2.validate(
|
|
18353
|
+
{ _id: req.params.id },
|
|
18354
|
+
{ abortEarly: false }
|
|
18355
|
+
);
|
|
18336
18356
|
if (error) {
|
|
18337
|
-
|
|
18338
|
-
|
|
18357
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
18358
|
+
import_node_server_utils85.logger.log({ level: "error", message: messages });
|
|
18359
|
+
next(new import_node_server_utils85.BadRequestError(messages));
|
|
18339
18360
|
return;
|
|
18340
18361
|
}
|
|
18362
|
+
const { _id } = value;
|
|
18341
18363
|
try {
|
|
18342
18364
|
const site = await _getVehicleById(_id);
|
|
18343
18365
|
res.json(site);
|
|
@@ -18350,7 +18372,7 @@ function useVehicleController() {
|
|
|
18350
18372
|
}
|
|
18351
18373
|
async function updateVehicleById(req, res, next) {
|
|
18352
18374
|
try {
|
|
18353
|
-
const
|
|
18375
|
+
const schema2 = import_joi46.default.object({
|
|
18354
18376
|
_id: import_joi46.default.string().hex().length(24).required(),
|
|
18355
18377
|
site: import_joi46.default.string().hex().length(24).required(),
|
|
18356
18378
|
name: import_joi46.default.string().optional().allow("", null),
|
|
@@ -18365,13 +18387,17 @@ function useVehicleController() {
|
|
|
18365
18387
|
recNo: import_joi46.default.string().optional().allow(null, ""),
|
|
18366
18388
|
type: import_joi46.default.string().optional().valid(...Object.values(VehicleType)).allow(null, "")
|
|
18367
18389
|
});
|
|
18368
|
-
const { error, value } =
|
|
18369
|
-
|
|
18370
|
-
|
|
18371
|
-
|
|
18390
|
+
const { error, value } = schema2.validate(
|
|
18391
|
+
{
|
|
18392
|
+
_id: req.params.id,
|
|
18393
|
+
...req.body
|
|
18394
|
+
},
|
|
18395
|
+
{ abortEarly: false }
|
|
18396
|
+
);
|
|
18372
18397
|
if (error) {
|
|
18373
|
-
|
|
18374
|
-
|
|
18398
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
18399
|
+
import_node_server_utils85.logger.log({ level: "error", message: messages });
|
|
18400
|
+
next(new import_node_server_utils85.BadRequestError(messages));
|
|
18375
18401
|
return;
|
|
18376
18402
|
}
|
|
18377
18403
|
const { _id, ...rest } = value;
|
|
@@ -18385,21 +18411,24 @@ function useVehicleController() {
|
|
|
18385
18411
|
}
|
|
18386
18412
|
}
|
|
18387
18413
|
async function deleteVehicle(req, res, next) {
|
|
18388
|
-
const _id = req.params.id;
|
|
18389
18414
|
const deleteVehicleSchema = import_joi46.default.object({
|
|
18390
18415
|
_id: import_joi46.default.string().hex().length(24).required(),
|
|
18391
18416
|
recno: import_joi46.default.string().required(),
|
|
18392
18417
|
site: import_joi46.default.string().hex().length(24).required(),
|
|
18393
|
-
type: import_joi46.default.string().valid(
|
|
18418
|
+
type: import_joi46.default.string().valid(...Object.values(VehicleType)).required(),
|
|
18394
18419
|
bypass: import_joi46.default.boolean().optional().default(true)
|
|
18395
18420
|
});
|
|
18396
|
-
const { error, value } = deleteVehicleSchema.validate({
|
|
18421
|
+
const { error, value } = deleteVehicleSchema.validate({
|
|
18422
|
+
_id: req.params.id,
|
|
18423
|
+
...req.body
|
|
18424
|
+
});
|
|
18397
18425
|
if (error) {
|
|
18398
|
-
|
|
18399
|
-
|
|
18426
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
18427
|
+
import_node_server_utils85.logger.log({ level: "error", message: messages });
|
|
18428
|
+
next(new import_node_server_utils85.BadRequestError(messages));
|
|
18400
18429
|
return;
|
|
18401
18430
|
}
|
|
18402
|
-
const { recno, site, type, bypass } = value;
|
|
18431
|
+
const { recno, site, type, bypass, _id } = value;
|
|
18403
18432
|
try {
|
|
18404
18433
|
const data = await _deleteVehicle(_id, recno, site, type, bypass);
|
|
18405
18434
|
res.json({
|
|
@@ -21173,9 +21202,19 @@ function usePersonService() {
|
|
|
21173
21202
|
updateById: _updateById
|
|
21174
21203
|
} = usePersonRepo();
|
|
21175
21204
|
const { addPlateNumber: _addPlateNumber } = useDahuaService();
|
|
21205
|
+
const {
|
|
21206
|
+
createUser: addUser,
|
|
21207
|
+
getUserById,
|
|
21208
|
+
getUserByEmail,
|
|
21209
|
+
updatePassword,
|
|
21210
|
+
updateUserFieldById: _updateUserFieldById
|
|
21211
|
+
} = useUserRepo();
|
|
21212
|
+
const { add: addMember } = useMemberRepo();
|
|
21176
21213
|
const { getById: _getUnitById, updateById: updateUnitById } = useBuildingUnitRepo();
|
|
21177
21214
|
const { getAllCameraWithPassword: _getAllSiteCameras } = useSiteCameraRepo();
|
|
21178
21215
|
const { updateStatusById } = useFileRepo();
|
|
21216
|
+
const { getById: getOrgById } = useOrgRepo();
|
|
21217
|
+
const { getSiteById } = useSiteRepo();
|
|
21179
21218
|
async function add(value) {
|
|
21180
21219
|
const session = import_node_server_utils104.useAtlas.getClient()?.startSession();
|
|
21181
21220
|
if (!session) {
|
|
@@ -21196,6 +21235,49 @@ function usePersonService() {
|
|
|
21196
21235
|
}
|
|
21197
21236
|
}
|
|
21198
21237
|
}
|
|
21238
|
+
const isValidType = ["resident" /* RESIDENT */, "tenant" /* TENANT */].includes(
|
|
21239
|
+
value?.type
|
|
21240
|
+
);
|
|
21241
|
+
if (value.email && value.password && value.name && isValidType) {
|
|
21242
|
+
const _user = await getUserByEmail(value.email);
|
|
21243
|
+
if (_user) {
|
|
21244
|
+
throw new import_node_server_utils104.BadRequestError(`User already exists: ${value.email}.`);
|
|
21245
|
+
}
|
|
21246
|
+
const hashedPassword = await (0, import_node_server_utils104.hashPassword)(value.password);
|
|
21247
|
+
const user = {
|
|
21248
|
+
email: value.email,
|
|
21249
|
+
password: hashedPassword,
|
|
21250
|
+
name: value.name,
|
|
21251
|
+
defaultOrg: value.org?.toString() || ""
|
|
21252
|
+
};
|
|
21253
|
+
const userId = await addUser(user, session);
|
|
21254
|
+
let org = null;
|
|
21255
|
+
if (userId) {
|
|
21256
|
+
if (value?.org) {
|
|
21257
|
+
org = await getOrgById(value.org);
|
|
21258
|
+
if (!org) {
|
|
21259
|
+
value.org = "";
|
|
21260
|
+
}
|
|
21261
|
+
}
|
|
21262
|
+
let site;
|
|
21263
|
+
if (value.site) {
|
|
21264
|
+
site = await getSiteById(value.site);
|
|
21265
|
+
}
|
|
21266
|
+
await addMember(
|
|
21267
|
+
{
|
|
21268
|
+
org: value.org?.toString() || "",
|
|
21269
|
+
orgName: org?.name || "",
|
|
21270
|
+
user: userId.toString(),
|
|
21271
|
+
name: value.name,
|
|
21272
|
+
role: "",
|
|
21273
|
+
type: "resident",
|
|
21274
|
+
siteId: value.site?.toString() || "",
|
|
21275
|
+
siteName: site?.name || ""
|
|
21276
|
+
},
|
|
21277
|
+
session
|
|
21278
|
+
);
|
|
21279
|
+
}
|
|
21280
|
+
}
|
|
21199
21281
|
await _add(value, session);
|
|
21200
21282
|
await session.commitTransaction();
|
|
21201
21283
|
return "People added successfully.";
|
|
@@ -25566,14 +25648,17 @@ function useSiteFacilityBookingController() {
|
|
|
25566
25648
|
}
|
|
25567
25649
|
}
|
|
25568
25650
|
async function deleteSiteFacilityBookingById(req, res, next) {
|
|
25569
|
-
const
|
|
25570
|
-
|
|
25571
|
-
|
|
25651
|
+
const schema2 = import_joi72.default.object({
|
|
25652
|
+
_id: import_joi72.default.string().hex().length(24).required()
|
|
25653
|
+
});
|
|
25654
|
+
const { error, value } = schema2.validate({ _id: req.params.id });
|
|
25572
25655
|
if (error) {
|
|
25573
|
-
|
|
25574
|
-
|
|
25656
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
25657
|
+
import_node_server_utils128.logger.log({ level: "error", message: messages });
|
|
25658
|
+
next(new import_node_server_utils128.BadRequestError(messages));
|
|
25575
25659
|
return;
|
|
25576
25660
|
}
|
|
25661
|
+
const { _id } = value;
|
|
25577
25662
|
try {
|
|
25578
25663
|
await _deleteSiteFacilityBookingById(_id);
|
|
25579
25664
|
res.status(200).json({ message: "Successfully deleted site facility booking." });
|
|
@@ -28777,7 +28862,7 @@ function useSiteUnitBillingRepo() {
|
|
|
28777
28862
|
value = MUnitBilling(value);
|
|
28778
28863
|
const res = await collection.insertOne(value, { session });
|
|
28779
28864
|
const acronym = createAcronym(value.billName || "NA");
|
|
28780
|
-
const dateFormatted =
|
|
28865
|
+
const dateFormatted = formatDateString2(/* @__PURE__ */ new Date());
|
|
28781
28866
|
const newId = new import_mongodb81.ObjectId(res.insertedId).toString().slice(-6);
|
|
28782
28867
|
const referenceNumber = `${acronym}${newId}${dateFormatted}`;
|
|
28783
28868
|
await collection.updateOne(
|
|
@@ -29116,7 +29201,7 @@ function useSiteUnitBillingRepo() {
|
|
|
29116
29201
|
function createAcronym(billName) {
|
|
29117
29202
|
return billName.split(" ").map((word) => word.charAt(0).toUpperCase()).join("");
|
|
29118
29203
|
}
|
|
29119
|
-
function
|
|
29204
|
+
function formatDateString2(today) {
|
|
29120
29205
|
today = typeof today === "string" ? new Date(today) : today;
|
|
29121
29206
|
let month = today.getMonth() + 1;
|
|
29122
29207
|
let day = today.getDate();
|
|
@@ -29582,6 +29667,7 @@ var import_mongodb84 = require("mongodb");
|
|
|
29582
29667
|
var import_fs2 = __toESM(require("fs"));
|
|
29583
29668
|
var import_path = __toESM(require("path"));
|
|
29584
29669
|
var import_axios = __toESM(require("axios"));
|
|
29670
|
+
var import_xml2js = require("xml2js");
|
|
29585
29671
|
var import_crypto = __toESM(require("crypto"));
|
|
29586
29672
|
var ALGORITHM = "aes-256-gcm";
|
|
29587
29673
|
var SECRET_KEY = import_crypto.default.createSecretKey(
|
|
@@ -29682,9 +29768,39 @@ var formatEntryPassDate = (date) => {
|
|
|
29682
29768
|
const day = String(newDate.getDate()).padStart(2, "0");
|
|
29683
29769
|
return `${year}${month}${day}`;
|
|
29684
29770
|
};
|
|
29771
|
+
async function removeAccessGroup({ cardNo, staffNo, url }) {
|
|
29772
|
+
try {
|
|
29773
|
+
const commands = readTemplate("delete-qr-card", {
|
|
29774
|
+
staffNo,
|
|
29775
|
+
// dateOfJoin: formatEntryPassDate(cardDetails.startDate),
|
|
29776
|
+
// accessLevel: cardDetails.accessLevel,
|
|
29777
|
+
cardNo
|
|
29778
|
+
// pin: cardDetails.pin,
|
|
29779
|
+
// startDate: formatEntryPassDate(cardDetails.startDate),
|
|
29780
|
+
// endDate: formatEntryPassDate(cardDetails.endDate),
|
|
29781
|
+
// cardType: 0,
|
|
29782
|
+
// isActivated: cardDetails.isActivated ? 1 : 0,
|
|
29783
|
+
// isAntiPassBack: cardDetails.isAntiPassBack ? 1 : 0,
|
|
29784
|
+
// isLiftCard: cardDetails.isLiftCard ? 1 : 0,
|
|
29785
|
+
// isLiftActivate: cardDetails.isLiftCard ? 1 : 0,
|
|
29786
|
+
// liftAccessLevel: cardDetails.liftAccessLevel || 1,
|
|
29787
|
+
// liftAccessStartDate: formatEntryPassDate(cardDetails.liftAccessStartDate) || "19770510",
|
|
29788
|
+
// liftAccessEndDate: formatEntryPassDate(cardDetails.liftAccessEndDate) || "19770510",
|
|
29789
|
+
});
|
|
29790
|
+
const response = await sendCommand(commands, url);
|
|
29791
|
+
const result = await (0, import_xml2js.parseStringPromise)(response, { explicitArray: false });
|
|
29792
|
+
console.log(result.RESULT.$.STCODE);
|
|
29793
|
+
console.log(commands);
|
|
29794
|
+
if (result && result.RESULT.$.STCODE !== "0") {
|
|
29795
|
+
throw new Error("Command failed, server error.");
|
|
29796
|
+
}
|
|
29797
|
+
} catch (error) {
|
|
29798
|
+
console.log(error);
|
|
29799
|
+
}
|
|
29800
|
+
}
|
|
29685
29801
|
|
|
29686
29802
|
// src/repositories/access-management.repo.ts
|
|
29687
|
-
var
|
|
29803
|
+
var import_xml2js2 = require("xml2js");
|
|
29688
29804
|
|
|
29689
29805
|
// src/utils/rsa-encryption.ts
|
|
29690
29806
|
var crypto2 = __toESM(require("crypto"));
|
|
@@ -30693,7 +30809,7 @@ function UseAccessManagementRepo() {
|
|
|
30693
30809
|
return readTemplate(`${item.accessLevel !== null ? "add-card" : "add-card-lift"}`, { ...command });
|
|
30694
30810
|
}).flat();
|
|
30695
30811
|
const response = await sendCommand(commands.join("").toString(), params.acm_url);
|
|
30696
|
-
const result = await (0,
|
|
30812
|
+
const result = await (0, import_xml2js2.parseStringPromise)(response, { explicitArray: false });
|
|
30697
30813
|
if (result && result.RESULT.$.STCODE !== "0") {
|
|
30698
30814
|
throw new Error("Command failed, server error.");
|
|
30699
30815
|
}
|
|
@@ -31554,7 +31670,7 @@ function UseAccessManagementRepo() {
|
|
|
31554
31670
|
return readTemplate(`${item.accessLevel !== null ? "add-card" : "add-card-lift"}`, { ...command });
|
|
31555
31671
|
}).flat();
|
|
31556
31672
|
const response = await sendCommand(commands.join("").toString(), acm_url);
|
|
31557
|
-
serverResult = await (0,
|
|
31673
|
+
serverResult = await (0, import_xml2js2.parseStringPromise)(response, { explicitArray: false });
|
|
31558
31674
|
if (result && serverResult.RESULT.$.STCODE !== "0") {
|
|
31559
31675
|
throw new Error("Command failed, server error.");
|
|
31560
31676
|
}
|
|
@@ -31650,7 +31766,7 @@ function UseAccessManagementRepo() {
|
|
|
31650
31766
|
var import_joi85 = __toESM(require("joi"));
|
|
31651
31767
|
|
|
31652
31768
|
// src/services/access-management.service.ts
|
|
31653
|
-
var
|
|
31769
|
+
var import_xml2js3 = require("xml2js");
|
|
31654
31770
|
var import_stream = require("stream");
|
|
31655
31771
|
var xlsx = __toESM(require("xlsx"));
|
|
31656
31772
|
function useAccessManagementSvc() {
|
|
@@ -31713,7 +31829,7 @@ function useAccessManagementSvc() {
|
|
|
31713
31829
|
try {
|
|
31714
31830
|
const command = readTemplate("door-levels");
|
|
31715
31831
|
const response = await sendCommand(command, params.acm_url);
|
|
31716
|
-
const res = await (0,
|
|
31832
|
+
const res = await (0, import_xml2js3.parseStringPromise)(response, { explicitArray: false });
|
|
31717
31833
|
const format = await formatDoorAccessLevels(res);
|
|
31718
31834
|
return format;
|
|
31719
31835
|
} catch (err) {
|
|
@@ -31724,7 +31840,7 @@ function useAccessManagementSvc() {
|
|
|
31724
31840
|
try {
|
|
31725
31841
|
const command = readTemplate("lift-levels");
|
|
31726
31842
|
const response = await sendCommand(command, params.acm_url);
|
|
31727
|
-
const res = await (0,
|
|
31843
|
+
const res = await (0, import_xml2js3.parseStringPromise)(response, { explicitArray: false });
|
|
31728
31844
|
const format = await formatLiftAccessLevels(res);
|
|
31729
31845
|
return format;
|
|
31730
31846
|
} catch (error) {
|
|
@@ -31735,7 +31851,7 @@ function useAccessManagementSvc() {
|
|
|
31735
31851
|
try {
|
|
31736
31852
|
const command = readTemplate("access-group");
|
|
31737
31853
|
const response = await sendCommand(command, params.acm_url);
|
|
31738
|
-
const res = await (0,
|
|
31854
|
+
const res = await (0, import_xml2js3.parseStringPromise)(response, { explicitArray: false });
|
|
31739
31855
|
const format = await formatAccessGroup(res);
|
|
31740
31856
|
return format;
|
|
31741
31857
|
} catch (err) {
|
|
@@ -32781,6 +32897,9 @@ function useAccessManagementController() {
|
|
|
32781
32897
|
});
|
|
32782
32898
|
}
|
|
32783
32899
|
};
|
|
32900
|
+
const removeAccessCard = async ({ cardNo, staffNo, url }) => {
|
|
32901
|
+
return removeAccessGroup({ cardNo, staffNo, url });
|
|
32902
|
+
};
|
|
32784
32903
|
return {
|
|
32785
32904
|
addPhysicalCard,
|
|
32786
32905
|
addNonPhysicalCard,
|
|
@@ -32811,7 +32930,8 @@ function useAccessManagementController() {
|
|
|
32811
32930
|
vmsgenerateQrCodes,
|
|
32812
32931
|
addVisitorAccessCard,
|
|
32813
32932
|
signQrCode,
|
|
32814
|
-
checkoutVisitor
|
|
32933
|
+
checkoutVisitor,
|
|
32934
|
+
removeAccessCard
|
|
32815
32935
|
};
|
|
32816
32936
|
}
|
|
32817
32937
|
|
|
@@ -33326,6 +33446,7 @@ function MOccurrenceBook(value) {
|
|
|
33326
33446
|
// src/repositories/occurrence-book.repo.ts
|
|
33327
33447
|
var import_node_server_utils155 = require("@7365admin1/node-server-utils");
|
|
33328
33448
|
var import_mongodb88 = require("mongodb");
|
|
33449
|
+
var occurrence_book_namespace_collection = "occurrence-books";
|
|
33329
33450
|
function useOccurrenceBookRepo() {
|
|
33330
33451
|
const db = import_node_server_utils155.useAtlas.getDb();
|
|
33331
33452
|
if (!db) {
|
|
@@ -33353,18 +33474,21 @@ function useOccurrenceBookRepo() {
|
|
|
33353
33474
|
);
|
|
33354
33475
|
}
|
|
33355
33476
|
}
|
|
33356
|
-
const
|
|
33357
|
-
const
|
|
33358
|
-
|
|
33477
|
+
const collection = db.collection(occurrence_book_namespace_collection);
|
|
33478
|
+
const { delNamespace, getCache, setCache } = (0, import_node_server_utils155.useCache)(
|
|
33479
|
+
occurrence_book_namespace_collection
|
|
33480
|
+
);
|
|
33359
33481
|
async function add(value, session) {
|
|
33360
33482
|
try {
|
|
33361
33483
|
value = MOccurrenceBook(value);
|
|
33362
33484
|
const res = await collection.insertOne(value, { session });
|
|
33363
33485
|
delNamespace().then(() => {
|
|
33364
|
-
import_node_server_utils155.logger.info(
|
|
33486
|
+
import_node_server_utils155.logger.info(
|
|
33487
|
+
`Cache cleared for namespace: ${occurrence_book_namespace_collection}`
|
|
33488
|
+
);
|
|
33365
33489
|
}).catch((err) => {
|
|
33366
33490
|
import_node_server_utils155.logger.error(
|
|
33367
|
-
`Failed to clear cache for namespace: ${
|
|
33491
|
+
`Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
|
|
33368
33492
|
err
|
|
33369
33493
|
);
|
|
33370
33494
|
});
|
|
@@ -33447,7 +33571,10 @@ function useOccurrenceBookRepo() {
|
|
|
33447
33571
|
query.$text = { $search: search };
|
|
33448
33572
|
cacheOptions.search = search;
|
|
33449
33573
|
}
|
|
33450
|
-
const cacheKey = (0, import_node_server_utils155.makeCacheKey)(
|
|
33574
|
+
const cacheKey = (0, import_node_server_utils155.makeCacheKey)(
|
|
33575
|
+
occurrence_book_namespace_collection,
|
|
33576
|
+
cacheOptions
|
|
33577
|
+
);
|
|
33451
33578
|
const cachedData = await getCache(cacheKey);
|
|
33452
33579
|
if (cachedData) {
|
|
33453
33580
|
import_node_server_utils155.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
@@ -33481,7 +33608,9 @@ function useOccurrenceBookRepo() {
|
|
|
33481
33608
|
} catch (error) {
|
|
33482
33609
|
throw new import_node_server_utils155.BadRequestError("Invalid occurrence book ID format.");
|
|
33483
33610
|
}
|
|
33484
|
-
const cacheKey = (0, import_node_server_utils155.makeCacheKey)(
|
|
33611
|
+
const cacheKey = (0, import_node_server_utils155.makeCacheKey)(occurrence_book_namespace_collection, {
|
|
33612
|
+
_id
|
|
33613
|
+
});
|
|
33485
33614
|
const cachedData = await getCache(cacheKey);
|
|
33486
33615
|
if (cachedData) {
|
|
33487
33616
|
import_node_server_utils155.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
@@ -33521,10 +33650,12 @@ function useOccurrenceBookRepo() {
|
|
|
33521
33650
|
);
|
|
33522
33651
|
}
|
|
33523
33652
|
delNamespace().then(() => {
|
|
33524
|
-
import_node_server_utils155.logger.info(
|
|
33653
|
+
import_node_server_utils155.logger.info(
|
|
33654
|
+
`Cache cleared for namespace: ${occurrence_book_namespace_collection}`
|
|
33655
|
+
);
|
|
33525
33656
|
}).catch((err) => {
|
|
33526
33657
|
import_node_server_utils155.logger.error(
|
|
33527
|
-
`Failed to clear cache for namespace: ${
|
|
33658
|
+
`Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
|
|
33528
33659
|
err
|
|
33529
33660
|
);
|
|
33530
33661
|
});
|
|
@@ -33550,10 +33681,12 @@ function useOccurrenceBookRepo() {
|
|
|
33550
33681
|
throw new import_node_server_utils155.InternalServerError("Unable to delete occurrence book.");
|
|
33551
33682
|
}
|
|
33552
33683
|
delNamespace().then(() => {
|
|
33553
|
-
import_node_server_utils155.logger.info(
|
|
33684
|
+
import_node_server_utils155.logger.info(
|
|
33685
|
+
`Cache cleared for namespace: ${occurrence_book_namespace_collection}`
|
|
33686
|
+
);
|
|
33554
33687
|
}).catch((err) => {
|
|
33555
33688
|
import_node_server_utils155.logger.error(
|
|
33556
|
-
`Failed to clear cache for namespace: ${
|
|
33689
|
+
`Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
|
|
33557
33690
|
err
|
|
33558
33691
|
);
|
|
33559
33692
|
});
|
|
@@ -33575,10 +33708,12 @@ function useOccurrenceBookRepo() {
|
|
|
33575
33708
|
throw new import_node_server_utils155.InternalServerError("Unable to close daily occurrence book.");
|
|
33576
33709
|
}
|
|
33577
33710
|
delNamespace().then(() => {
|
|
33578
|
-
import_node_server_utils155.logger.info(
|
|
33711
|
+
import_node_server_utils155.logger.info(
|
|
33712
|
+
`Cache cleared for namespace: ${occurrence_book_namespace_collection}`
|
|
33713
|
+
);
|
|
33579
33714
|
}).catch((err) => {
|
|
33580
33715
|
import_node_server_utils155.logger.error(
|
|
33581
|
-
`Failed to clear cache for namespace: ${
|
|
33716
|
+
`Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
|
|
33582
33717
|
err
|
|
33583
33718
|
);
|
|
33584
33719
|
});
|
|
@@ -33587,6 +33722,47 @@ function useOccurrenceBookRepo() {
|
|
|
33587
33722
|
throw error;
|
|
33588
33723
|
}
|
|
33589
33724
|
}
|
|
33725
|
+
async function bulkCreate(payloads, session) {
|
|
33726
|
+
try {
|
|
33727
|
+
if (!payloads.length) {
|
|
33728
|
+
return { insertedCount: 0 };
|
|
33729
|
+
}
|
|
33730
|
+
const chunkSize = 500;
|
|
33731
|
+
let totalInserted = 0;
|
|
33732
|
+
for (let i = 0; i < payloads.length; i += chunkSize) {
|
|
33733
|
+
const chunk = payloads.slice(i, i + chunkSize);
|
|
33734
|
+
const operations = chunk.map((item) => ({
|
|
33735
|
+
insertOne: {
|
|
33736
|
+
document: {
|
|
33737
|
+
...item,
|
|
33738
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
33739
|
+
updatedAt: "",
|
|
33740
|
+
deletedAt: ""
|
|
33741
|
+
}
|
|
33742
|
+
}
|
|
33743
|
+
}));
|
|
33744
|
+
const result = await collection.bulkWrite(operations, { session });
|
|
33745
|
+
totalInserted += result.insertedCount || 0;
|
|
33746
|
+
}
|
|
33747
|
+
import_node_server_utils155.logger.info(
|
|
33748
|
+
`Bulk insert successful: ${totalInserted} occurrence books created.`
|
|
33749
|
+
);
|
|
33750
|
+
delNamespace().then(() => {
|
|
33751
|
+
import_node_server_utils155.logger.info(
|
|
33752
|
+
`Cache cleared for namespace: ${occurrence_book_namespace_collection}`
|
|
33753
|
+
);
|
|
33754
|
+
}).catch((err) => {
|
|
33755
|
+
import_node_server_utils155.logger.error(
|
|
33756
|
+
`Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
|
|
33757
|
+
err
|
|
33758
|
+
);
|
|
33759
|
+
});
|
|
33760
|
+
return { insertedCount: totalInserted };
|
|
33761
|
+
} catch (error) {
|
|
33762
|
+
import_node_server_utils155.logger.error("Bulk insert failed for occurrence books", error);
|
|
33763
|
+
throw error;
|
|
33764
|
+
}
|
|
33765
|
+
}
|
|
33590
33766
|
return {
|
|
33591
33767
|
add,
|
|
33592
33768
|
getAll,
|
|
@@ -33595,7 +33771,8 @@ function useOccurrenceBookRepo() {
|
|
|
33595
33771
|
deleteOccurrenceBookById,
|
|
33596
33772
|
closeOccurrenceBooks,
|
|
33597
33773
|
createIndexes,
|
|
33598
|
-
createTextIndex
|
|
33774
|
+
createTextIndex,
|
|
33775
|
+
bulkCreate
|
|
33599
33776
|
};
|
|
33600
33777
|
}
|
|
33601
33778
|
|
|
@@ -33605,14 +33782,18 @@ function useOccurrenceBookService() {
|
|
|
33605
33782
|
const {
|
|
33606
33783
|
add: _add,
|
|
33607
33784
|
updateOccurrenceBookById: _updateOccurrenceBookById,
|
|
33608
|
-
closeOccurrenceBooks: _closeOccurrenceBooks
|
|
33785
|
+
closeOccurrenceBooks: _closeOccurrenceBooks,
|
|
33786
|
+
bulkCreate: _bulkCreate
|
|
33609
33787
|
} = useOccurrenceBookRepo();
|
|
33610
33788
|
const {
|
|
33611
33789
|
add: _addOccurrenceCounter,
|
|
33612
33790
|
incrementByType: _incrementByType,
|
|
33613
33791
|
getByType: _getByType
|
|
33614
33792
|
} = useCounterRepo();
|
|
33615
|
-
const {
|
|
33793
|
+
const {
|
|
33794
|
+
getAllSites: _getAllSites,
|
|
33795
|
+
getAllSitesUnpaginated: _getAllSitesUnpaginated
|
|
33796
|
+
} = useSiteRepo();
|
|
33616
33797
|
async function add(value) {
|
|
33617
33798
|
const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
|
|
33618
33799
|
session?.startTransaction();
|
|
@@ -33650,39 +33831,31 @@ function useOccurrenceBookService() {
|
|
|
33650
33831
|
}
|
|
33651
33832
|
}
|
|
33652
33833
|
async function processCreateDOB() {
|
|
33653
|
-
const limit = 100;
|
|
33654
33834
|
const counterName = "occurrence-book";
|
|
33655
|
-
let page = 1;
|
|
33656
33835
|
let entryCounter = 0;
|
|
33657
33836
|
const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
|
|
33658
|
-
session?.startTransaction();
|
|
33659
|
-
const existingCounter = await _getByType(counterName);
|
|
33660
|
-
if (!existingCounter) {
|
|
33661
|
-
await _addOccurrenceCounter(counterName);
|
|
33662
|
-
} else {
|
|
33663
|
-
await _incrementByType(counterName, session);
|
|
33664
|
-
entryCounter = existingCounter.count + 1;
|
|
33665
|
-
}
|
|
33666
|
-
const baseDate = /* @__PURE__ */ new Date();
|
|
33667
|
-
baseDate.setUTCMinutes(0, 0, 0);
|
|
33668
|
-
const closedAt = new Date(baseDate);
|
|
33669
|
-
closedAt.setUTCDate(closedAt.getUTCDate() + 3);
|
|
33670
33837
|
try {
|
|
33671
|
-
|
|
33672
|
-
|
|
33673
|
-
|
|
33674
|
-
|
|
33675
|
-
|
|
33676
|
-
|
|
33677
|
-
|
|
33678
|
-
|
|
33679
|
-
|
|
33680
|
-
|
|
33681
|
-
|
|
33682
|
-
|
|
33683
|
-
|
|
33684
|
-
|
|
33685
|
-
|
|
33838
|
+
session?.startTransaction();
|
|
33839
|
+
const existingCounter = await _getByType(counterName);
|
|
33840
|
+
if (!existingCounter) {
|
|
33841
|
+
await _addOccurrenceCounter(counterName);
|
|
33842
|
+
entryCounter = 1;
|
|
33843
|
+
} else {
|
|
33844
|
+
entryCounter = existingCounter.count + 1;
|
|
33845
|
+
await _incrementByType(counterName);
|
|
33846
|
+
}
|
|
33847
|
+
const baseDate = /* @__PURE__ */ new Date();
|
|
33848
|
+
baseDate.setUTCMinutes(0, 0, 0);
|
|
33849
|
+
const closedAt = new Date(baseDate);
|
|
33850
|
+
closedAt.setUTCDate(closedAt.getUTCDate() + 3);
|
|
33851
|
+
const sites = await _getAllSitesUnpaginated();
|
|
33852
|
+
const payloads = sites.map((site) => ({
|
|
33853
|
+
site: site._id,
|
|
33854
|
+
date: baseDate.toISOString(),
|
|
33855
|
+
closedAt: closedAt.toISOString(),
|
|
33856
|
+
entryCounter
|
|
33857
|
+
}));
|
|
33858
|
+
await _bulkCreate(payloads, session);
|
|
33686
33859
|
await session?.commitTransaction();
|
|
33687
33860
|
} catch (err) {
|
|
33688
33861
|
await session?.abortTransaction();
|
|
@@ -40658,7 +40831,7 @@ function useManpowerMonitoringRepo() {
|
|
|
40658
40831
|
if (!db) {
|
|
40659
40832
|
throw new Error("Unable to connect to server.");
|
|
40660
40833
|
}
|
|
40661
|
-
const namespace_collection = "manpower-
|
|
40834
|
+
const namespace_collection = "manpower-settings";
|
|
40662
40835
|
const collection = db.collection(namespace_collection);
|
|
40663
40836
|
const serviceProviderCollection = db.collection("site.service-providers");
|
|
40664
40837
|
async function createManpowerMonitoringSettings(value, session) {
|
|
@@ -41601,7 +41774,7 @@ function useOvernightParkingRepo() {
|
|
|
41601
41774
|
try {
|
|
41602
41775
|
const data = await collection.findOne({
|
|
41603
41776
|
site: siteId,
|
|
41604
|
-
deletedAt: null
|
|
41777
|
+
deletedAt: { $nin: ["", null] }
|
|
41605
41778
|
});
|
|
41606
41779
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
41607
41780
|
import_node_server_utils200.logger.info(`Cache set for key: ${cacheKey}`);
|
|
@@ -41709,12 +41882,12 @@ var schemaOvernightParkingRequest = import_joi118.default.object({
|
|
|
41709
41882
|
numberOfPassengers: import_joi118.default.number().integer().min(0).optional().default(0),
|
|
41710
41883
|
purposeOfVisit: import_joi118.default.string().optional().allow("", null),
|
|
41711
41884
|
status: import_joi118.default.string().valid(...Object.values(OvernightParkingRequestStatus)).optional().allow(null, "").default("pending" /* PENDING */),
|
|
41712
|
-
|
|
41885
|
+
remarks: import_joi118.default.string().optional().allow(null, "")
|
|
41713
41886
|
});
|
|
41714
41887
|
var schemaUpdateOvernightParkingRequest = import_joi118.default.object({
|
|
41715
41888
|
_id: import_joi118.default.string().hex().length(24).required(),
|
|
41716
41889
|
status: import_joi118.default.string().valid(...Object.values(OvernightParkingRequestStatus)).required(),
|
|
41717
|
-
|
|
41890
|
+
remarks: import_joi118.default.string().optional().allow(null, "")
|
|
41718
41891
|
});
|
|
41719
41892
|
function MOvernightParkingRequest(value) {
|
|
41720
41893
|
const { error } = schemaOvernightParkingRequest.validate(value);
|
|
@@ -41746,6 +41919,30 @@ function useOvernightParkingRequestRepo() {
|
|
|
41746
41919
|
const { delNamespace, getCache, setCache } = (0, import_node_server_utils203.useCache)(
|
|
41747
41920
|
overnight_parking_requests_namespace_collection
|
|
41748
41921
|
);
|
|
41922
|
+
async function createIndexes() {
|
|
41923
|
+
try {
|
|
41924
|
+
const existingIndexes = await collection.indexes();
|
|
41925
|
+
const existingNames = new Set(existingIndexes.map((i) => i.name));
|
|
41926
|
+
const indexesToEnsure = [
|
|
41927
|
+
{
|
|
41928
|
+
key: { site: 1 },
|
|
41929
|
+
name: "site-index"
|
|
41930
|
+
},
|
|
41931
|
+
{
|
|
41932
|
+
key: { status: 1 },
|
|
41933
|
+
name: "status-index"
|
|
41934
|
+
}
|
|
41935
|
+
];
|
|
41936
|
+
const indexesToCreate = indexesToEnsure.filter(
|
|
41937
|
+
(index) => index.name && !existingNames.has(index.name)
|
|
41938
|
+
);
|
|
41939
|
+
if (indexesToCreate.length > 0) {
|
|
41940
|
+
await collection.createIndexes(indexesToCreate);
|
|
41941
|
+
}
|
|
41942
|
+
} catch (error) {
|
|
41943
|
+
throw new import_node_server_utils203.InternalServerError("Failed to create collection indexes.");
|
|
41944
|
+
}
|
|
41945
|
+
}
|
|
41749
41946
|
async function add(value, session) {
|
|
41750
41947
|
try {
|
|
41751
41948
|
value = MOvernightParkingRequest(value);
|
|
@@ -41931,7 +42128,8 @@ function useOvernightParkingRequestRepo() {
|
|
|
41931
42128
|
getOvernightParkingRequestById,
|
|
41932
42129
|
updateOvernightParkingRequestById,
|
|
41933
42130
|
deleteOvernightParkingRequestById,
|
|
41934
|
-
updateExpiredRequests
|
|
42131
|
+
updateExpiredRequests,
|
|
42132
|
+
createIndexes
|
|
41935
42133
|
};
|
|
41936
42134
|
}
|
|
41937
42135
|
|
|
@@ -43068,6 +43266,1403 @@ function useManpowerRemarkCtrl() {
|
|
|
43068
43266
|
updateRemarksStatus
|
|
43069
43267
|
};
|
|
43070
43268
|
}
|
|
43269
|
+
|
|
43270
|
+
// src/models/manpower-sites.model.ts
|
|
43271
|
+
var import_joi122 = __toESM(require("joi"));
|
|
43272
|
+
var import_mongodb114 = require("mongodb");
|
|
43273
|
+
var manpowerSitesSchema = import_joi122.default.object({
|
|
43274
|
+
id: import_joi122.default.string().hex().required(),
|
|
43275
|
+
text: import_joi122.default.string().hex().optional().allow("", null),
|
|
43276
|
+
contractID: import_joi122.default.string().optional().allow("", null),
|
|
43277
|
+
contractName: import_joi122.default.string().optional().allow("", null),
|
|
43278
|
+
type: import_joi122.default.string().optional().allow("", null),
|
|
43279
|
+
status: import_joi122.default.number().optional().allow("", null)
|
|
43280
|
+
});
|
|
43281
|
+
var MManpowerSites = class {
|
|
43282
|
+
constructor(data) {
|
|
43283
|
+
this._id = new import_mongodb114.ObjectId();
|
|
43284
|
+
this.id = data.id || "";
|
|
43285
|
+
this.text = data.text || "";
|
|
43286
|
+
this.contractID = data.contractID || "";
|
|
43287
|
+
this.contractName = data.contractName || "";
|
|
43288
|
+
this.type = data.type || "";
|
|
43289
|
+
this.status = data.status || "";
|
|
43290
|
+
}
|
|
43291
|
+
};
|
|
43292
|
+
|
|
43293
|
+
// src/repositories/manpower-sites.repo.ts
|
|
43294
|
+
var import_node_server_utils209 = require("@7365admin1/node-server-utils");
|
|
43295
|
+
function useManpowerSitesRepo() {
|
|
43296
|
+
const db = import_node_server_utils209.useAtlas.getDb();
|
|
43297
|
+
if (!db) {
|
|
43298
|
+
throw new Error("Unable to connect to server.");
|
|
43299
|
+
}
|
|
43300
|
+
const namespace_collection = "manpower-sites";
|
|
43301
|
+
const collection = db.collection(namespace_collection);
|
|
43302
|
+
async function createManpowerSites(value) {
|
|
43303
|
+
try {
|
|
43304
|
+
value = new MManpowerSites(value);
|
|
43305
|
+
const result = await collection.insertOne(value);
|
|
43306
|
+
return result;
|
|
43307
|
+
} catch (error) {
|
|
43308
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
43309
|
+
}
|
|
43310
|
+
}
|
|
43311
|
+
async function getAllManpowerSites({
|
|
43312
|
+
page = 1,
|
|
43313
|
+
limit = 10,
|
|
43314
|
+
search = ""
|
|
43315
|
+
}) {
|
|
43316
|
+
try {
|
|
43317
|
+
page = page ? page - 1 : 0;
|
|
43318
|
+
limit = limit || 10;
|
|
43319
|
+
const searchQuery = {};
|
|
43320
|
+
if (search) {
|
|
43321
|
+
searchQuery.siteName = { $regex: search, $options: "i" };
|
|
43322
|
+
}
|
|
43323
|
+
const result = await collection.aggregate([
|
|
43324
|
+
{ $match: searchQuery },
|
|
43325
|
+
{
|
|
43326
|
+
$facet: {
|
|
43327
|
+
totalCount: [{ $count: "count" }],
|
|
43328
|
+
items: [
|
|
43329
|
+
{ $sort: { _id: 1 } },
|
|
43330
|
+
{
|
|
43331
|
+
$project: {
|
|
43332
|
+
_id: 0
|
|
43333
|
+
}
|
|
43334
|
+
},
|
|
43335
|
+
{ $skip: page * limit },
|
|
43336
|
+
{ $limit: limit }
|
|
43337
|
+
]
|
|
43338
|
+
}
|
|
43339
|
+
}
|
|
43340
|
+
]).toArray();
|
|
43341
|
+
const items = result[0].items;
|
|
43342
|
+
return items;
|
|
43343
|
+
} catch (error) {
|
|
43344
|
+
throw new Error(error.message || "Server Internal Error");
|
|
43345
|
+
}
|
|
43346
|
+
}
|
|
43347
|
+
async function deleteManpowerSites(siteId) {
|
|
43348
|
+
try {
|
|
43349
|
+
const result = await collection.deleteOne({
|
|
43350
|
+
id: siteId.toString()
|
|
43351
|
+
});
|
|
43352
|
+
return result;
|
|
43353
|
+
} catch (error) {
|
|
43354
|
+
throw new Error(error.message || "Server Internal Error");
|
|
43355
|
+
}
|
|
43356
|
+
}
|
|
43357
|
+
return {
|
|
43358
|
+
createManpowerSites,
|
|
43359
|
+
getAllManpowerSites,
|
|
43360
|
+
deleteManpowerSites
|
|
43361
|
+
};
|
|
43362
|
+
}
|
|
43363
|
+
|
|
43364
|
+
// src/services/manpower-sites.service.ts
|
|
43365
|
+
var import_node_server_utils210 = require("@7365admin1/node-server-utils");
|
|
43366
|
+
function useManpowerSitesSrvc() {
|
|
43367
|
+
const manpowerSitesRepo = useManpowerSitesRepo();
|
|
43368
|
+
const manpowerMonitoringRepo = useManpowerMonitoringRepo();
|
|
43369
|
+
async function createManpowerSites(payload) {
|
|
43370
|
+
const session = import_node_server_utils210.useAtlas.getClient()?.startSession();
|
|
43371
|
+
if (!session) {
|
|
43372
|
+
throw new import_node_server_utils210.BadRequestError("Database session not available.");
|
|
43373
|
+
}
|
|
43374
|
+
await session.startTransaction();
|
|
43375
|
+
try {
|
|
43376
|
+
const manpowerSites = await manpowerMonitoringRepo.getAllSites(payload);
|
|
43377
|
+
for (const site of manpowerSites) {
|
|
43378
|
+
await manpowerSitesRepo.createManpowerSites(site);
|
|
43379
|
+
}
|
|
43380
|
+
await session.commitTransaction();
|
|
43381
|
+
return "Created Succesfully";
|
|
43382
|
+
} catch (error) {
|
|
43383
|
+
await session.abortTransaction();
|
|
43384
|
+
import_node_server_utils210.logger.error(error.message || error);
|
|
43385
|
+
console.error("Error creating monitoring settings:", error);
|
|
43386
|
+
throw new Error(error?.message || "Internal Server Error!");
|
|
43387
|
+
} finally {
|
|
43388
|
+
session.endSession();
|
|
43389
|
+
}
|
|
43390
|
+
}
|
|
43391
|
+
async function checkManpowerSites() {
|
|
43392
|
+
try {
|
|
43393
|
+
const serviceProviderId = "69bb9dbff572cf9d260d7ce3";
|
|
43394
|
+
const hrmLabsSites = await manpowerMonitoringRepo.getAllSites(
|
|
43395
|
+
serviceProviderId
|
|
43396
|
+
);
|
|
43397
|
+
const manpowerSites = await manpowerSitesRepo.getAllManpowerSites({
|
|
43398
|
+
page: 1,
|
|
43399
|
+
limit: 1e3,
|
|
43400
|
+
search: ""
|
|
43401
|
+
});
|
|
43402
|
+
const added = hrmLabsSites.filter(
|
|
43403
|
+
(hrmSite) => !manpowerSites.some((mpSite) => mpSite.id === hrmSite.id)
|
|
43404
|
+
);
|
|
43405
|
+
const deleted = manpowerSites.filter(
|
|
43406
|
+
(mpSite) => !hrmLabsSites.some((hrmSite) => hrmSite.id === mpSite.id)
|
|
43407
|
+
);
|
|
43408
|
+
if (added.length > 0) {
|
|
43409
|
+
await Promise.all(
|
|
43410
|
+
added.map((site) => manpowerSitesRepo.createManpowerSites(site))
|
|
43411
|
+
);
|
|
43412
|
+
}
|
|
43413
|
+
if (deleted.length > 0) {
|
|
43414
|
+
await Promise.all(
|
|
43415
|
+
deleted.map(
|
|
43416
|
+
(site) => manpowerSitesRepo.deleteManpowerSites(site.id)
|
|
43417
|
+
)
|
|
43418
|
+
);
|
|
43419
|
+
}
|
|
43420
|
+
return "Manpower Sites Updated Successfully";
|
|
43421
|
+
} catch (error) {
|
|
43422
|
+
import_node_server_utils210.logger.error(error.message || error);
|
|
43423
|
+
console.error("Error checking manpower sites:", error);
|
|
43424
|
+
throw new Error(error?.message || "Internal Server Error!");
|
|
43425
|
+
}
|
|
43426
|
+
}
|
|
43427
|
+
return {
|
|
43428
|
+
createManpowerSites,
|
|
43429
|
+
checkManpowerSites
|
|
43430
|
+
};
|
|
43431
|
+
}
|
|
43432
|
+
|
|
43433
|
+
// src/controllers/manpower-sites.controller.ts
|
|
43434
|
+
var import_node_server_utils211 = require("@7365admin1/node-server-utils");
|
|
43435
|
+
var import_joi123 = __toESM(require("joi"));
|
|
43436
|
+
function useManpowerSitesCtrl() {
|
|
43437
|
+
const { createManpowerSites: _createManpowerSites } = useManpowerSitesSrvc();
|
|
43438
|
+
const { getAllManpowerSites: _getAllManpowerSites } = useManpowerSitesRepo();
|
|
43439
|
+
async function createManpowerSites(req, res, next) {
|
|
43440
|
+
try {
|
|
43441
|
+
const payload = req.query.serviceProviderId;
|
|
43442
|
+
const schema2 = import_joi123.default.object({
|
|
43443
|
+
serviceProviderId: import_joi123.default.string().hex().required()
|
|
43444
|
+
});
|
|
43445
|
+
const { error } = schema2.validate({
|
|
43446
|
+
serviceProviderId: payload
|
|
43447
|
+
});
|
|
43448
|
+
if (error) {
|
|
43449
|
+
next(new import_node_server_utils211.BadRequestError(error.message));
|
|
43450
|
+
return;
|
|
43451
|
+
}
|
|
43452
|
+
const result = await _createManpowerSites(payload);
|
|
43453
|
+
return res.json(result);
|
|
43454
|
+
} catch (error) {
|
|
43455
|
+
import_node_server_utils211.logger.log({ level: "error", message: error.message });
|
|
43456
|
+
next(error);
|
|
43457
|
+
return;
|
|
43458
|
+
}
|
|
43459
|
+
}
|
|
43460
|
+
async function getAllManpowerSites(req, res, next) {
|
|
43461
|
+
try {
|
|
43462
|
+
const { page, search, limit } = req.query;
|
|
43463
|
+
const schema2 = import_joi123.default.object({
|
|
43464
|
+
page: import_joi123.default.number().optional().allow("", null),
|
|
43465
|
+
limit: import_joi123.default.number().optional().allow("", null),
|
|
43466
|
+
search: import_joi123.default.string().optional().allow("", null)
|
|
43467
|
+
});
|
|
43468
|
+
const { error } = schema2.validate({ page, search, limit });
|
|
43469
|
+
if (error) {
|
|
43470
|
+
next(new import_node_server_utils211.BadRequestError(error.message));
|
|
43471
|
+
return;
|
|
43472
|
+
}
|
|
43473
|
+
const result = await _getAllManpowerSites({
|
|
43474
|
+
page: Number(page),
|
|
43475
|
+
limit: Number(limit),
|
|
43476
|
+
search
|
|
43477
|
+
});
|
|
43478
|
+
return res.json(result);
|
|
43479
|
+
} catch (error) {
|
|
43480
|
+
import_node_server_utils211.logger.log({ level: "error", message: error.message });
|
|
43481
|
+
next(error);
|
|
43482
|
+
return;
|
|
43483
|
+
}
|
|
43484
|
+
}
|
|
43485
|
+
return {
|
|
43486
|
+
createManpowerSites,
|
|
43487
|
+
getAllManpowerSites
|
|
43488
|
+
};
|
|
43489
|
+
}
|
|
43490
|
+
|
|
43491
|
+
// src/utils/cron.util.ts
|
|
43492
|
+
var import_node_server_utils212 = require("@7365admin1/node-server-utils");
|
|
43493
|
+
var import_mongodb115 = require("mongodb");
|
|
43494
|
+
var import_moment_timezone4 = __toESM(require("moment-timezone"));
|
|
43495
|
+
var createManpowerRemarksDaily = async () => {
|
|
43496
|
+
const db = import_node_server_utils212.useAtlas.getDb();
|
|
43497
|
+
if (!db) {
|
|
43498
|
+
throw new Error("Unable to connect to server.");
|
|
43499
|
+
}
|
|
43500
|
+
const namespace_collection = "manpower-settings";
|
|
43501
|
+
const settings = db.collection(namespace_collection);
|
|
43502
|
+
const remarks = db.collection("manpower-remarks");
|
|
43503
|
+
const serviceProviders = db.collection("site.service-providers");
|
|
43504
|
+
const items = [];
|
|
43505
|
+
const yesterday = (0, import_moment_timezone4.default)().tz("Asia/Singapore").subtract(1, "days").format("DD-MM-YYYY");
|
|
43506
|
+
try {
|
|
43507
|
+
const nowSGT = (0, import_moment_timezone4.default)().tz("Asia/Singapore");
|
|
43508
|
+
const servideProvider = await serviceProviders.findOne({
|
|
43509
|
+
name: { $regex: process.env.HRMLABS_DOMAIN, $options: "i" }
|
|
43510
|
+
});
|
|
43511
|
+
if (!servideProvider) {
|
|
43512
|
+
throw new Error("Servide Provider not found.");
|
|
43513
|
+
}
|
|
43514
|
+
const remark = await remarks.find({
|
|
43515
|
+
createdAtSGT: yesterday,
|
|
43516
|
+
serviceProviderId: servideProvider._id,
|
|
43517
|
+
status: "active"
|
|
43518
|
+
}).toArray();
|
|
43519
|
+
for (const site of remark) {
|
|
43520
|
+
const existingRemark = await settings.findOne({
|
|
43521
|
+
siteId: site.siteId,
|
|
43522
|
+
enabled: true
|
|
43523
|
+
});
|
|
43524
|
+
if (existingRemark) {
|
|
43525
|
+
const setting = await settings.findOne({
|
|
43526
|
+
siteId: site.siteId,
|
|
43527
|
+
enabled: true
|
|
43528
|
+
});
|
|
43529
|
+
const shiftType = setting?.shiftType;
|
|
43530
|
+
const morningCheckInTime = setting?.shifts?.[shiftType][0]?.checkIn;
|
|
43531
|
+
const afternoonCheckInTime = shiftType == "3-shifts" ? setting?.shifts?.[shiftType][1]?.checkIn : null;
|
|
43532
|
+
const nightCheckInTime = shiftType == "3-shifts" ? setting?.shifts?.[shiftType][2]?.checkIn : setting?.shifts?.[shiftType][1]?.checkIn;
|
|
43533
|
+
const morningAlertFrequencyMins = setting?.shifts?.[shiftType][0]?.alertFrequencyMins;
|
|
43534
|
+
const afternoonAlertFrequencyMins = shiftType == "3-shifts" ? setting?.shifts?.[shiftType][1]?.alertFrequencyMins : null;
|
|
43535
|
+
const nightAlertFrequencyMins = shiftType == "3-shifts" ? setting?.shifts?.[shiftType][2]?.alertFrequencyMins : setting?.shifts?.[shiftType][1]?.alertFrequencyMins;
|
|
43536
|
+
const morningAlertTime = import_moment_timezone4.default.tz(morningCheckInTime, "HH:mm", "Asia/Singapore").add(morningAlertFrequencyMins, "minutes").format("HH:mm");
|
|
43537
|
+
const afternoonAlertTime = afternoonCheckInTime ? import_moment_timezone4.default.tz(afternoonCheckInTime, "HH:mm", "Asia/Singapore").add(afternoonAlertFrequencyMins, "minutes").format("HH:mm") : "";
|
|
43538
|
+
const nightAlertTime = import_moment_timezone4.default.tz(nightCheckInTime, "HH:mm", "Asia/Singapore").add(nightAlertFrequencyMins, "minutes").format("HH:mm");
|
|
43539
|
+
const remark2 = {
|
|
43540
|
+
siteId: site.siteId,
|
|
43541
|
+
siteName: site.siteName,
|
|
43542
|
+
serviceProviderId: servideProvider._id,
|
|
43543
|
+
remarks: [
|
|
43544
|
+
{
|
|
43545
|
+
name: "Morning Shift",
|
|
43546
|
+
remark: {
|
|
43547
|
+
isAcknowledged: true,
|
|
43548
|
+
status: "",
|
|
43549
|
+
acknowledgementRemarks: "",
|
|
43550
|
+
acknowledgedAt: ""
|
|
43551
|
+
}
|
|
43552
|
+
},
|
|
43553
|
+
{
|
|
43554
|
+
name: "Afternoon Shift",
|
|
43555
|
+
remark: {
|
|
43556
|
+
isAcknowledged: true,
|
|
43557
|
+
status: "",
|
|
43558
|
+
acknowledgementRemarks: "",
|
|
43559
|
+
acknowledgedAt: ""
|
|
43560
|
+
}
|
|
43561
|
+
},
|
|
43562
|
+
{
|
|
43563
|
+
name: "Night Shift",
|
|
43564
|
+
remark: {
|
|
43565
|
+
isAcknowledged: true,
|
|
43566
|
+
status: "",
|
|
43567
|
+
acknowledgementRemarks: "",
|
|
43568
|
+
acknowledgedAt: ""
|
|
43569
|
+
}
|
|
43570
|
+
}
|
|
43571
|
+
],
|
|
43572
|
+
createdBy: "",
|
|
43573
|
+
createdByName: "",
|
|
43574
|
+
morningAlertTime,
|
|
43575
|
+
afternoonAlertTime,
|
|
43576
|
+
nightAlertTime,
|
|
43577
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
43578
|
+
createdAtSGT: nowSGT.format("DD-MM-YYYY"),
|
|
43579
|
+
updatedAt: "",
|
|
43580
|
+
status: "active"
|
|
43581
|
+
};
|
|
43582
|
+
items.push(remark2);
|
|
43583
|
+
}
|
|
43584
|
+
}
|
|
43585
|
+
if (items.length > 0) {
|
|
43586
|
+
await remarks.insertMany(items);
|
|
43587
|
+
}
|
|
43588
|
+
console.log("Daily manpower remarks created successfully.");
|
|
43589
|
+
} catch (error) {
|
|
43590
|
+
console.error("Error creating daily manpower remarks:", error);
|
|
43591
|
+
}
|
|
43592
|
+
};
|
|
43593
|
+
var updateRemarksisAcknowledged = async () => {
|
|
43594
|
+
const { getAttendanceDataCount: _getAttendanceDataCount } = useHrmLabsAttendanceSrvc();
|
|
43595
|
+
const nowSGT = (0, import_moment_timezone4.default)().tz("Asia/Singapore").format("DD-MM-YYYY");
|
|
43596
|
+
const db = import_node_server_utils212.useAtlas.getDb();
|
|
43597
|
+
if (!db) {
|
|
43598
|
+
throw new Error("Unable to connect to server.");
|
|
43599
|
+
}
|
|
43600
|
+
const namespace_collection = "manpower-remarks";
|
|
43601
|
+
const remarks = db.collection(namespace_collection);
|
|
43602
|
+
const timeNow = (0, import_moment_timezone4.default)().tz("Asia/Singapore").format("HH:mm");
|
|
43603
|
+
const settings = db.collection("manpower-settings");
|
|
43604
|
+
try {
|
|
43605
|
+
const matchingDocs = await remarks.find({
|
|
43606
|
+
createdAtSGT: nowSGT,
|
|
43607
|
+
$or: [
|
|
43608
|
+
{
|
|
43609
|
+
morningAlertTime: timeNow,
|
|
43610
|
+
"remarks.0.remark.isAcknowledged": true
|
|
43611
|
+
},
|
|
43612
|
+
{
|
|
43613
|
+
afternoonAlertTime: timeNow,
|
|
43614
|
+
"remarks.1.remark.isAcknowledged": true
|
|
43615
|
+
},
|
|
43616
|
+
{ nightAlertTime: timeNow, "remarks.2.remark.isAcknowledged": true }
|
|
43617
|
+
]
|
|
43618
|
+
}).project({ _id: 1 }).toArray();
|
|
43619
|
+
if (matchingDocs.length === 0) {
|
|
43620
|
+
return;
|
|
43621
|
+
}
|
|
43622
|
+
const updatedIds = matchingDocs.map((doc) => doc._id);
|
|
43623
|
+
await remarks.updateMany(
|
|
43624
|
+
{
|
|
43625
|
+
_id: { $in: updatedIds },
|
|
43626
|
+
morningAlertTime: timeNow,
|
|
43627
|
+
createdAtSGT: nowSGT,
|
|
43628
|
+
"remarks.0.remark.isAcknowledged": true
|
|
43629
|
+
},
|
|
43630
|
+
{ $set: { "remarks.0.remark.isAcknowledged": false } }
|
|
43631
|
+
);
|
|
43632
|
+
await remarks.updateMany(
|
|
43633
|
+
{
|
|
43634
|
+
_id: { $in: updatedIds },
|
|
43635
|
+
afternoonAlertTime: timeNow,
|
|
43636
|
+
createdAtSGT: nowSGT,
|
|
43637
|
+
"remarks.1.remark.isAcknowledged": true
|
|
43638
|
+
},
|
|
43639
|
+
{ $set: { "remarks.1.remark.isAcknowledged": false } }
|
|
43640
|
+
);
|
|
43641
|
+
await remarks.updateMany(
|
|
43642
|
+
{
|
|
43643
|
+
_id: { $in: updatedIds },
|
|
43644
|
+
nightAlertTime: timeNow,
|
|
43645
|
+
createdAtSGT: nowSGT,
|
|
43646
|
+
"remarks.2.remark.isAcknowledged": true
|
|
43647
|
+
},
|
|
43648
|
+
{ $set: { "remarks.2.remark.isAcknowledged": false } }
|
|
43649
|
+
);
|
|
43650
|
+
for (const id of updatedIds) {
|
|
43651
|
+
const doc = await remarks.findOne({ _id: id });
|
|
43652
|
+
const setting = await settings.findOne(
|
|
43653
|
+
{ siteId: new import_mongodb115.ObjectId(doc?.siteId) },
|
|
43654
|
+
{ projection: { emails: 1 } }
|
|
43655
|
+
);
|
|
43656
|
+
const payload = {
|
|
43657
|
+
startDate: doc?.createdAtSGT,
|
|
43658
|
+
endDate: doc?.createdAtSGT,
|
|
43659
|
+
siteName: doc?.siteName,
|
|
43660
|
+
siteId: doc?.siteId.toString(),
|
|
43661
|
+
serviceProviderId: doc?.serviceProviderId.toString()
|
|
43662
|
+
};
|
|
43663
|
+
const result = await _getAttendanceDataCount(payload);
|
|
43664
|
+
const shifts = [
|
|
43665
|
+
{ key: "dayShift", alertTime: doc?.morningAlertTime },
|
|
43666
|
+
{ key: "afternoonShift", alertTime: doc?.afternoonAlertTime },
|
|
43667
|
+
{ key: "nightShift", alertTime: doc?.nightAlertTime }
|
|
43668
|
+
];
|
|
43669
|
+
let shiftType;
|
|
43670
|
+
let actual = 0;
|
|
43671
|
+
let expected = 0;
|
|
43672
|
+
for (const shift of shifts) {
|
|
43673
|
+
if (shift.alertTime && isWithinHour(shift.alertTime, timeNow)) {
|
|
43674
|
+
shiftType = shift.key;
|
|
43675
|
+
actual = result?.totalCount?.[shift.key]?.actual || 0;
|
|
43676
|
+
expected = result?.totalCount?.[shift.key]?.expected || 0;
|
|
43677
|
+
break;
|
|
43678
|
+
}
|
|
43679
|
+
}
|
|
43680
|
+
let newStatus = "Normal";
|
|
43681
|
+
if (actual > expected)
|
|
43682
|
+
newStatus = "Over";
|
|
43683
|
+
else if (actual < expected)
|
|
43684
|
+
newStatus = "Under";
|
|
43685
|
+
sendEmailWithAttachmentsTo({
|
|
43686
|
+
email: setting?.emails,
|
|
43687
|
+
subject: "Manpower Alert",
|
|
43688
|
+
message: "",
|
|
43689
|
+
siteName: doc?.siteName || "",
|
|
43690
|
+
handlebar: "alert-email",
|
|
43691
|
+
date: nowSGT,
|
|
43692
|
+
actual,
|
|
43693
|
+
expected,
|
|
43694
|
+
status: newStatus
|
|
43695
|
+
});
|
|
43696
|
+
}
|
|
43697
|
+
} catch (error) {
|
|
43698
|
+
console.error("Error updating remarks:", error);
|
|
43699
|
+
}
|
|
43700
|
+
};
|
|
43701
|
+
var updateRemarksStatusEod = async () => {
|
|
43702
|
+
const { getAttendanceDataCount: _getAttendanceDataCount } = useHrmLabsAttendanceSrvc();
|
|
43703
|
+
const db = import_node_server_utils212.useAtlas.getDb();
|
|
43704
|
+
if (!db) {
|
|
43705
|
+
throw new Error("Unable to connect to server.");
|
|
43706
|
+
}
|
|
43707
|
+
const remarks = db.collection("manpower-remarks");
|
|
43708
|
+
const settings = db.collection("manpower-settings");
|
|
43709
|
+
const nowSGT = (0, import_moment_timezone4.default)().tz("Asia/Singapore").format("DD-MM-YYYY");
|
|
43710
|
+
const yesterdaySGT = (0, import_moment_timezone4.default)().tz("Asia/Singapore").subtract(1, "days").format("DD-MM-YYYY");
|
|
43711
|
+
const timeNow = (0, import_moment_timezone4.default)().tz("Asia/Singapore").format("HH:mm");
|
|
43712
|
+
const docs = await remarks.find({
|
|
43713
|
+
$or: [
|
|
43714
|
+
// Morning & Afternoon from today
|
|
43715
|
+
{
|
|
43716
|
+
createdAtSGT: nowSGT,
|
|
43717
|
+
$or: [
|
|
43718
|
+
{
|
|
43719
|
+
"remarks.0.remark.status": "",
|
|
43720
|
+
"remarks.0.remark.isAcknowledged": false
|
|
43721
|
+
},
|
|
43722
|
+
{
|
|
43723
|
+
"remarks.1.remark.status": "",
|
|
43724
|
+
"remarks.1.remark.isAcknowledged": false
|
|
43725
|
+
}
|
|
43726
|
+
]
|
|
43727
|
+
},
|
|
43728
|
+
// Night shift from yesterday
|
|
43729
|
+
{
|
|
43730
|
+
createdAtSGT: yesterdaySGT,
|
|
43731
|
+
"remarks.2.remark.status": "",
|
|
43732
|
+
"remarks.2.remark.isAcknowledged": false
|
|
43733
|
+
}
|
|
43734
|
+
]
|
|
43735
|
+
}).toArray();
|
|
43736
|
+
for (const doc of docs) {
|
|
43737
|
+
let shiftsToCheck = [];
|
|
43738
|
+
const endShiftTime = await settings.findOne(
|
|
43739
|
+
{ siteId: new import_mongodb115.ObjectId(doc.siteId) },
|
|
43740
|
+
{ projection: { shifts: 1, shiftType: 1 } }
|
|
43741
|
+
);
|
|
43742
|
+
if (doc.createdAtSGT === nowSGT) {
|
|
43743
|
+
const shiftType = endShiftTime?.shiftType || "2-shifts";
|
|
43744
|
+
if (timeNow >= endShiftTime?.shifts[shiftType][0]?.checkOut)
|
|
43745
|
+
shiftsToCheck.push({ index: 0, key: "dayShift" });
|
|
43746
|
+
if (shiftType == "3-shifts" && timeNow >= endShiftTime?.shifts[shiftType][1]?.checkOut)
|
|
43747
|
+
shiftsToCheck.push({ index: 1, key: "afternoonShift" });
|
|
43748
|
+
}
|
|
43749
|
+
if (doc.createdAtSGT === yesterdaySGT) {
|
|
43750
|
+
const index = endShiftTime?.shiftType === "2-shifts" ? 1 : 2;
|
|
43751
|
+
if (timeNow >= endShiftTime?.shifts[endShiftTime?.shiftType][index]?.checkOut)
|
|
43752
|
+
shiftsToCheck.push({ index: 2, key: "nightShift" });
|
|
43753
|
+
}
|
|
43754
|
+
if (shiftsToCheck.length === 0)
|
|
43755
|
+
continue;
|
|
43756
|
+
const payload = {
|
|
43757
|
+
startDate: doc.createdAtSGT,
|
|
43758
|
+
endDate: doc.createdAtSGT,
|
|
43759
|
+
siteName: doc.siteName,
|
|
43760
|
+
siteId: doc.siteId.toString(),
|
|
43761
|
+
serviceProviderId: doc.serviceProviderId.toString()
|
|
43762
|
+
};
|
|
43763
|
+
const result = await _getAttendanceDataCount(payload);
|
|
43764
|
+
if (!result?.totalCount) {
|
|
43765
|
+
continue;
|
|
43766
|
+
}
|
|
43767
|
+
for (const shift of shiftsToCheck) {
|
|
43768
|
+
const actual = result?.totalCount[shift?.key]?.actual || 0;
|
|
43769
|
+
const expected = result?.totalCount[shift?.key]?.expected || 0;
|
|
43770
|
+
if (doc.remarks[shift.index].remark.status === "") {
|
|
43771
|
+
let newStatus = "Normal";
|
|
43772
|
+
if (actual > expected)
|
|
43773
|
+
newStatus = "Over";
|
|
43774
|
+
else if (actual < expected)
|
|
43775
|
+
newStatus = "Under";
|
|
43776
|
+
await remarks.updateOne(
|
|
43777
|
+
{ _id: doc._id },
|
|
43778
|
+
{
|
|
43779
|
+
$set: {
|
|
43780
|
+
[`remarks.${shift.index}.remark.status`]: newStatus,
|
|
43781
|
+
[`remarks.${shift.index}.remark.isAcknowledged`]: true,
|
|
43782
|
+
[`remarks.${shift.index}.remark.acknowledgedAt`]: (/* @__PURE__ */ new Date()).toISOString()
|
|
43783
|
+
}
|
|
43784
|
+
}
|
|
43785
|
+
);
|
|
43786
|
+
}
|
|
43787
|
+
}
|
|
43788
|
+
}
|
|
43789
|
+
};
|
|
43790
|
+
function sendEmailWithAttachmentsTo({
|
|
43791
|
+
email = "",
|
|
43792
|
+
subject = "",
|
|
43793
|
+
message = "",
|
|
43794
|
+
siteName = "",
|
|
43795
|
+
handlebar = "",
|
|
43796
|
+
date = "",
|
|
43797
|
+
actual = 0,
|
|
43798
|
+
expected = 0,
|
|
43799
|
+
status = ""
|
|
43800
|
+
}) {
|
|
43801
|
+
const MailerConfig = {
|
|
43802
|
+
host: MAILER_TRANSPORT_HOST,
|
|
43803
|
+
port: MAILER_TRANSPORT_PORT,
|
|
43804
|
+
secure: MAILER_TRANSPORT_SECURE,
|
|
43805
|
+
email: MAILER_EMAIL,
|
|
43806
|
+
password: MAILER_PASSWORD
|
|
43807
|
+
};
|
|
43808
|
+
const mailer = new import_node_server_utils212.useMailer(MailerConfig);
|
|
43809
|
+
const dir = __dirname;
|
|
43810
|
+
const type = "alert-email";
|
|
43811
|
+
const filePath = (0, import_node_server_utils212.getDirectory)(dir, `./public/handlebars/${type}`);
|
|
43812
|
+
const emailContent = (0, import_node_server_utils212.compileHandlebar)({
|
|
43813
|
+
context: {
|
|
43814
|
+
siteName,
|
|
43815
|
+
date,
|
|
43816
|
+
actual,
|
|
43817
|
+
expected,
|
|
43818
|
+
status
|
|
43819
|
+
},
|
|
43820
|
+
filePath
|
|
43821
|
+
});
|
|
43822
|
+
mailer.sendMail({
|
|
43823
|
+
to: email,
|
|
43824
|
+
subject,
|
|
43825
|
+
html: emailContent,
|
|
43826
|
+
sender: "iService365"
|
|
43827
|
+
}).catch((error) => {
|
|
43828
|
+
import_node_server_utils212.logger.log({
|
|
43829
|
+
level: "error",
|
|
43830
|
+
message: `Error sending user ${type} email: ${error}`
|
|
43831
|
+
});
|
|
43832
|
+
});
|
|
43833
|
+
return { message };
|
|
43834
|
+
}
|
|
43835
|
+
var isWithinHour = (alertTime, timeNow) => {
|
|
43836
|
+
const [ah, am] = alertTime.split(":").map(Number);
|
|
43837
|
+
const [nh, nm] = timeNow.split(":").map(Number);
|
|
43838
|
+
const alertMinutes = ah * 60 + am;
|
|
43839
|
+
const nowMinutes = nh * 60 + nm;
|
|
43840
|
+
return nowMinutes >= alertMinutes && nowMinutes <= alertMinutes + 60;
|
|
43841
|
+
};
|
|
43842
|
+
|
|
43843
|
+
// src/events/manpower.event.ts
|
|
43844
|
+
var import_node_server_utils213 = require("@7365admin1/node-server-utils");
|
|
43845
|
+
var import_mongodb116 = require("mongodb");
|
|
43846
|
+
var import_moment_timezone5 = __toESM(require("moment-timezone"));
|
|
43847
|
+
async function manpowerEvents(io) {
|
|
43848
|
+
console.log("Manpower events initialized");
|
|
43849
|
+
let intervalId = null;
|
|
43850
|
+
let activeConnections = 0;
|
|
43851
|
+
const { getAttendanceDataCount: _getAttendanceDataCount } = useHrmLabsAttendanceSrvc();
|
|
43852
|
+
const updateRemarksStatus = async (date) => {
|
|
43853
|
+
const db = import_node_server_utils213.useAtlas.getDb();
|
|
43854
|
+
if (!db) {
|
|
43855
|
+
throw new Error("Unable to connect to server.");
|
|
43856
|
+
}
|
|
43857
|
+
const remarks = db.collection("manpower-remarks");
|
|
43858
|
+
const settings = db.collection("manpower-settings");
|
|
43859
|
+
const selectedDateMoment = import_moment_timezone5.default.tz(date, "DD-MM-YYYY", "Asia/Singapore");
|
|
43860
|
+
const selectedDateSGT = selectedDateMoment.format("DD-MM-YYYY");
|
|
43861
|
+
const currentSGT = (0, import_moment_timezone5.default)().tz("Asia/Singapore");
|
|
43862
|
+
const docs = await remarks.find({
|
|
43863
|
+
createdAtSGT: selectedDateSGT,
|
|
43864
|
+
$or: [
|
|
43865
|
+
{ "remarks.0.remark.status": "" },
|
|
43866
|
+
{ "remarks.1.remark.status": "" },
|
|
43867
|
+
{ "remarks.2.remark.status": "" }
|
|
43868
|
+
]
|
|
43869
|
+
}).toArray();
|
|
43870
|
+
for (const doc of docs) {
|
|
43871
|
+
const siteSettings = await settings.findOne(
|
|
43872
|
+
{ siteId: new import_mongodb116.ObjectId(doc.siteId), enabled: true },
|
|
43873
|
+
{ projection: { shifts: 1, shiftType: 1 } }
|
|
43874
|
+
);
|
|
43875
|
+
const shiftType = siteSettings?.shiftType || "2-shifts";
|
|
43876
|
+
const shiftsToCheck = [];
|
|
43877
|
+
shiftsToCheck.push({ index: 0, key: "dayShift" });
|
|
43878
|
+
if (shiftType === "3-shifts") {
|
|
43879
|
+
shiftsToCheck.push({ index: 1, key: "afternoonShift" });
|
|
43880
|
+
}
|
|
43881
|
+
if (currentSGT.isSame(selectedDateMoment, "day")) {
|
|
43882
|
+
if (currentSGT.isSameOrAfter(
|
|
43883
|
+
import_moment_timezone5.default.tz("19:55", "HH:mm", "Asia/Singapore")
|
|
43884
|
+
)) {
|
|
43885
|
+
shiftsToCheck.push({ index: 2, key: "nightShift" });
|
|
43886
|
+
}
|
|
43887
|
+
} else if (currentSGT.isAfter(selectedDateMoment, "day")) {
|
|
43888
|
+
shiftsToCheck.push({ index: 2, key: "nightShift" });
|
|
43889
|
+
}
|
|
43890
|
+
if (shiftsToCheck.length === 0)
|
|
43891
|
+
continue;
|
|
43892
|
+
const payload = {
|
|
43893
|
+
startDate: doc.createdAtSGT,
|
|
43894
|
+
endDate: doc.createdAtSGT,
|
|
43895
|
+
siteName: doc.siteName,
|
|
43896
|
+
siteId: doc.siteId.toString(),
|
|
43897
|
+
serviceProviderId: doc.serviceProviderId.toString()
|
|
43898
|
+
};
|
|
43899
|
+
const result = await _getAttendanceDataCount(payload);
|
|
43900
|
+
for (const shift of shiftsToCheck) {
|
|
43901
|
+
const actual = result?.totalCount?.[shift.key]?.actual || 0;
|
|
43902
|
+
const expected = result?.totalCount?.[shift.key]?.expected || 0;
|
|
43903
|
+
let newStatus = "Normal";
|
|
43904
|
+
if (actual > expected)
|
|
43905
|
+
newStatus = "Over";
|
|
43906
|
+
else if (actual < expected)
|
|
43907
|
+
newStatus = "Under";
|
|
43908
|
+
const namespace = `/manpower`;
|
|
43909
|
+
io.of(namespace).emit("manpower-status-update", {
|
|
43910
|
+
siteId: doc.siteId,
|
|
43911
|
+
siteName: doc.siteName,
|
|
43912
|
+
shift: shift.key,
|
|
43913
|
+
status: newStatus,
|
|
43914
|
+
actual,
|
|
43915
|
+
expected,
|
|
43916
|
+
selectedDateSGT
|
|
43917
|
+
});
|
|
43918
|
+
}
|
|
43919
|
+
}
|
|
43920
|
+
};
|
|
43921
|
+
const startInterval = (date) => {
|
|
43922
|
+
if (!intervalId) {
|
|
43923
|
+
intervalId = setInterval(
|
|
43924
|
+
() => updateRemarksStatus(date?.toString() || ""),
|
|
43925
|
+
15 * 1e3
|
|
43926
|
+
);
|
|
43927
|
+
console.log(" Interval started.");
|
|
43928
|
+
}
|
|
43929
|
+
};
|
|
43930
|
+
const stopInterval = () => {
|
|
43931
|
+
if (intervalId) {
|
|
43932
|
+
clearInterval(intervalId);
|
|
43933
|
+
intervalId = null;
|
|
43934
|
+
console.log(" Interval stopped.");
|
|
43935
|
+
}
|
|
43936
|
+
};
|
|
43937
|
+
io.of("/manpower").on("connection", (socket) => {
|
|
43938
|
+
activeConnections += 1;
|
|
43939
|
+
const date = socket.handshake.query.date;
|
|
43940
|
+
if (activeConnections === 1) {
|
|
43941
|
+
startInterval(date?.toString() || "");
|
|
43942
|
+
}
|
|
43943
|
+
updateRemarksStatus(date?.toString() || "");
|
|
43944
|
+
socket.on("disconnect", () => {
|
|
43945
|
+
activeConnections -= 1;
|
|
43946
|
+
console.log(`Client disconnected: ${socket.id}`);
|
|
43947
|
+
console.log(`Total active connections: ${activeConnections}`);
|
|
43948
|
+
if (activeConnections === 0) {
|
|
43949
|
+
stopInterval();
|
|
43950
|
+
}
|
|
43951
|
+
});
|
|
43952
|
+
});
|
|
43953
|
+
}
|
|
43954
|
+
|
|
43955
|
+
// src/services/reddot-payment.service.ts
|
|
43956
|
+
var import_axios3 = __toESM(require("axios"));
|
|
43957
|
+
|
|
43958
|
+
// src/utils/payment-signature.util.ts
|
|
43959
|
+
var crypto3 = __toESM(require("crypto"));
|
|
43960
|
+
function paymentSignature(params, secretKey) {
|
|
43961
|
+
const fieldOrder = ["mid", "order_id", "payment_type", "amount", "ccy", "card_no", "exp_date", "cvv2"];
|
|
43962
|
+
let concatenated = "";
|
|
43963
|
+
fieldOrder.forEach((v) => {
|
|
43964
|
+
if (!params.hasOwnProperty(v)) {
|
|
43965
|
+
return;
|
|
43966
|
+
} else if (v === "cvv2") {
|
|
43967
|
+
concatenated += (params[v] ?? "").toString().slice(-1);
|
|
43968
|
+
} else if (v === "card_no") {
|
|
43969
|
+
concatenated += (params[v] ?? "").substring(0, 6) + (params[v] ?? "").slice(-4);
|
|
43970
|
+
} else {
|
|
43971
|
+
concatenated += params[v];
|
|
43972
|
+
}
|
|
43973
|
+
});
|
|
43974
|
+
concatenated += secretKey;
|
|
43975
|
+
const signature = crypto3.createHash("sha512").update(concatenated).digest("hex");
|
|
43976
|
+
return signature;
|
|
43977
|
+
}
|
|
43978
|
+
function genericSignature(params, secretKey) {
|
|
43979
|
+
const paramsCopy = { ...params };
|
|
43980
|
+
delete paramsCopy["signature"];
|
|
43981
|
+
const sortedParams = Object.keys(paramsCopy).sort().reduce((obj, key) => {
|
|
43982
|
+
obj[key] = paramsCopy[key];
|
|
43983
|
+
return obj;
|
|
43984
|
+
}, {});
|
|
43985
|
+
const concatenated = Object.values(sortedParams).join("") + secretKey;
|
|
43986
|
+
const signature = crypto3.createHash("sha512").update(concatenated).digest("hex");
|
|
43987
|
+
return signature;
|
|
43988
|
+
}
|
|
43989
|
+
|
|
43990
|
+
// src/repositories/reddot-payment.repository.ts
|
|
43991
|
+
var import_mongodb120 = require("mongodb");
|
|
43992
|
+
|
|
43993
|
+
// src/utils/date-format.util.ts
|
|
43994
|
+
var import_moment_timezone6 = __toESM(require("moment-timezone"));
|
|
43995
|
+
function formatDateString(today, format, dateRange) {
|
|
43996
|
+
today = typeof today === "string" ? new Date(today) : today;
|
|
43997
|
+
let month = today.getMonth() + 1;
|
|
43998
|
+
let day = today.getDate();
|
|
43999
|
+
let year = today.getFullYear();
|
|
44000
|
+
let formattedDate;
|
|
44001
|
+
if (format === "mm-dd-yyyy") {
|
|
44002
|
+
formattedDate = `${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}-${year}`;
|
|
44003
|
+
} else if (format === "dd-mm-yyyy") {
|
|
44004
|
+
formattedDate = `${day.toString().padStart(2, "0")}-${month.toString().padStart(2, "0")}-${year}`;
|
|
44005
|
+
} else if (format === "for-ref") {
|
|
44006
|
+
formattedDate = `${month.toString().padStart(2, "0")}${day.toString().padStart(2, "0")}${year}`;
|
|
44007
|
+
} else if (format === "mm/dd/yyyy") {
|
|
44008
|
+
formattedDate = `${month.toString().padStart(2, "0")}/${day.toString().padStart(2, "0")}/${year}`;
|
|
44009
|
+
} else {
|
|
44010
|
+
formattedDate = `${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}`;
|
|
44011
|
+
}
|
|
44012
|
+
return formattedDate;
|
|
44013
|
+
}
|
|
44014
|
+
|
|
44015
|
+
// src/models/credit-card.model.ts
|
|
44016
|
+
var import_mongodb117 = require("mongodb");
|
|
44017
|
+
var MCardInfo = class {
|
|
44018
|
+
// this is coming from RDP transaction
|
|
44019
|
+
constructor({
|
|
44020
|
+
_id = new import_mongodb117.ObjectId(),
|
|
44021
|
+
userId,
|
|
44022
|
+
cardType,
|
|
44023
|
+
cardNumber,
|
|
44024
|
+
cardId,
|
|
44025
|
+
fullName,
|
|
44026
|
+
expiryDate,
|
|
44027
|
+
cvv,
|
|
44028
|
+
site,
|
|
44029
|
+
siteName,
|
|
44030
|
+
organization,
|
|
44031
|
+
createdBy,
|
|
44032
|
+
createdAt,
|
|
44033
|
+
updatedAt,
|
|
44034
|
+
transaction_id
|
|
44035
|
+
} = {}) {
|
|
44036
|
+
this._id = _id;
|
|
44037
|
+
this.userId = userId;
|
|
44038
|
+
this.cardType = cardType;
|
|
44039
|
+
this.cardNumber = cardNumber;
|
|
44040
|
+
this.cardId = cardId;
|
|
44041
|
+
this.fullName = fullName;
|
|
44042
|
+
this.expiryDate = expiryDate;
|
|
44043
|
+
this.cvv = cvv;
|
|
44044
|
+
this.site = site;
|
|
44045
|
+
this.siteName = siteName;
|
|
44046
|
+
this.organization = organization;
|
|
44047
|
+
this.createdBy = createdBy;
|
|
44048
|
+
this.createdAt = createdAt;
|
|
44049
|
+
this.updatedAt = updatedAt;
|
|
44050
|
+
this.transaction_id = transaction_id;
|
|
44051
|
+
}
|
|
44052
|
+
};
|
|
44053
|
+
|
|
44054
|
+
// src/models/cart.model.ts
|
|
44055
|
+
var import_mongodb118 = require("mongodb");
|
|
44056
|
+
var MUnitBillings = class {
|
|
44057
|
+
// transaction response messages
|
|
44058
|
+
constructor({
|
|
44059
|
+
_id = new import_mongodb118.ObjectId(),
|
|
44060
|
+
unit,
|
|
44061
|
+
unitId,
|
|
44062
|
+
unitBill,
|
|
44063
|
+
paymentStatus = "Processing" /* processing */,
|
|
44064
|
+
referenceNumber,
|
|
44065
|
+
amountPaid,
|
|
44066
|
+
paidBy,
|
|
44067
|
+
datePaid,
|
|
44068
|
+
billCategory,
|
|
44069
|
+
billFrom,
|
|
44070
|
+
billTo,
|
|
44071
|
+
site,
|
|
44072
|
+
organization,
|
|
44073
|
+
createdBy,
|
|
44074
|
+
createdAt,
|
|
44075
|
+
updatedAt,
|
|
44076
|
+
message
|
|
44077
|
+
} = {}) {
|
|
44078
|
+
this._id = _id;
|
|
44079
|
+
this.unit = unit;
|
|
44080
|
+
this.unitId = unitId;
|
|
44081
|
+
this.referenceNumber = referenceNumber;
|
|
44082
|
+
this.unitBill = unitBill;
|
|
44083
|
+
this.paymentStatus = paymentStatus;
|
|
44084
|
+
this.amountPaid = amountPaid;
|
|
44085
|
+
this.site = site;
|
|
44086
|
+
this.organization = organization;
|
|
44087
|
+
this.paidBy = paidBy;
|
|
44088
|
+
this.datePaid = datePaid;
|
|
44089
|
+
this.billCategory = billCategory;
|
|
44090
|
+
this.billFrom = billFrom;
|
|
44091
|
+
this.billTo = billTo;
|
|
44092
|
+
this.createdBy = createdBy;
|
|
44093
|
+
this.createdAt = createdAt;
|
|
44094
|
+
this.updatedAt = updatedAt;
|
|
44095
|
+
this.message = message;
|
|
44096
|
+
}
|
|
44097
|
+
};
|
|
44098
|
+
|
|
44099
|
+
// src/repositories/payment.repository.ts
|
|
44100
|
+
var import_mongodb119 = require("mongodb");
|
|
44101
|
+
var import_node_server_utils214 = require("@7365admin1/node-server-utils");
|
|
44102
|
+
var PaymentBillRepo = () => {
|
|
44103
|
+
const getDB = () => {
|
|
44104
|
+
const db = import_node_server_utils214.useAtlas.getDb();
|
|
44105
|
+
if (!db) {
|
|
44106
|
+
throw new import_node_server_utils214.InternalServerError("Unable to connect to server.");
|
|
44107
|
+
}
|
|
44108
|
+
return db;
|
|
44109
|
+
};
|
|
44110
|
+
const collection = () => {
|
|
44111
|
+
return getDB().collection("unit-bill");
|
|
44112
|
+
};
|
|
44113
|
+
const billCollection = () => {
|
|
44114
|
+
return getDB().collection("bill-records");
|
|
44115
|
+
};
|
|
44116
|
+
const creditCollection = () => {
|
|
44117
|
+
return getDB().collection("credit-info");
|
|
44118
|
+
};
|
|
44119
|
+
const cartCollection = () => {
|
|
44120
|
+
return getDB().collection("checkout-cart");
|
|
44121
|
+
};
|
|
44122
|
+
const payUnitBill = async (refId, payload) => {
|
|
44123
|
+
try {
|
|
44124
|
+
if (refId)
|
|
44125
|
+
refId = refId.toString();
|
|
44126
|
+
const unitBillInfo = await collection().findOne({ referenceNumber: refId });
|
|
44127
|
+
const unitBillId = unitBillInfo?._id;
|
|
44128
|
+
if (!unitBillInfo) {
|
|
44129
|
+
throw new Error("Unit bill info not found");
|
|
44130
|
+
}
|
|
44131
|
+
if (unitBillInfo?.status === "Inactive" /* inactive */) {
|
|
44132
|
+
throw new Error("This Bill is Inactive!");
|
|
44133
|
+
}
|
|
44134
|
+
const billId = new import_mongodb119.ObjectId(unitBillInfo?.billId);
|
|
44135
|
+
const billInfo = await billCollection().findOne({ _id: billId });
|
|
44136
|
+
if (!billInfo) {
|
|
44137
|
+
throw new Error("Bill info not found");
|
|
44138
|
+
}
|
|
44139
|
+
if (payload.paymentStatus === "Partial Payment" /* partial */ && payload.amountPaid) {
|
|
44140
|
+
const price = parseInt(billInfo?.price);
|
|
44141
|
+
const amount = payload.amountPaid;
|
|
44142
|
+
const numericPrice = typeof price === "string" ? parseInt(price) : price;
|
|
44143
|
+
const numericAmount = typeof amount === "string" ? parseInt(amount) : amount;
|
|
44144
|
+
if (typeof amount !== "number") {
|
|
44145
|
+
throw new Error("Amount is not a valid number");
|
|
44146
|
+
} else if (typeof price !== "number") {
|
|
44147
|
+
throw new Error("Price s not a valid number");
|
|
44148
|
+
}
|
|
44149
|
+
payload.balance = numericPrice - numericAmount;
|
|
44150
|
+
} else if (payload.paymentStatus === "Paid" /* paid */ && payload.amountPaid) {
|
|
44151
|
+
payload.datePaid = /* @__PURE__ */ new Date();
|
|
44152
|
+
payload.paymentStatus = "Paid" /* paid */;
|
|
44153
|
+
payload.amountPaid;
|
|
44154
|
+
payload.transaction_id;
|
|
44155
|
+
} else if (payload.paymentStatus === "Failed" /* failed */) {
|
|
44156
|
+
payload.amountPaid = 0;
|
|
44157
|
+
payload.paidBy = "";
|
|
44158
|
+
payload.datePaid = "";
|
|
44159
|
+
payload.paymentStatus = "Failed" /* failed */;
|
|
44160
|
+
payload.transaction_id;
|
|
44161
|
+
}
|
|
44162
|
+
const updatedAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
44163
|
+
payload.updatedAt = updatedAt;
|
|
44164
|
+
const result = await collection().findOneAndUpdate({ _id: unitBillId }, { $set: payload }, { returnDocument: "after" });
|
|
44165
|
+
return result;
|
|
44166
|
+
} catch (error) {
|
|
44167
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44168
|
+
}
|
|
44169
|
+
};
|
|
44170
|
+
const saveCreditCardInfo = async (payload) => {
|
|
44171
|
+
try {
|
|
44172
|
+
if (payload.userId)
|
|
44173
|
+
payload.userId = new import_mongodb119.ObjectId(payload.userId);
|
|
44174
|
+
if (payload.site)
|
|
44175
|
+
payload.site = new import_mongodb119.ObjectId(payload.site);
|
|
44176
|
+
if (payload.organization)
|
|
44177
|
+
payload.organization = new import_mongodb119.ObjectId(payload.organization);
|
|
44178
|
+
if (payload.createdBy)
|
|
44179
|
+
payload.createdBy = new import_mongodb119.ObjectId(payload.createdBy);
|
|
44180
|
+
const createdAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
44181
|
+
payload.createdAt = createdAt;
|
|
44182
|
+
const result = await creditCollection().insertOne(new MCardInfo(payload));
|
|
44183
|
+
return result;
|
|
44184
|
+
} catch (error) {
|
|
44185
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44186
|
+
}
|
|
44187
|
+
};
|
|
44188
|
+
const checkOutUnitBills = async (payload) => {
|
|
44189
|
+
try {
|
|
44190
|
+
if (payload.unitId)
|
|
44191
|
+
payload.unitId = new import_mongodb119.ObjectId(payload.unitId);
|
|
44192
|
+
if (payload.site)
|
|
44193
|
+
payload.site = new import_mongodb119.ObjectId(payload.site);
|
|
44194
|
+
if (payload.organization)
|
|
44195
|
+
payload.organization = new import_mongodb119.ObjectId(payload.organization);
|
|
44196
|
+
payload.createdAt = await formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
44197
|
+
const addToCart = await cartCollection().insertOne(new MUnitBillings(payload));
|
|
44198
|
+
const unitId = payload.unitId;
|
|
44199
|
+
const dateFormatted = formatDateString(/* @__PURE__ */ new Date(), "for-ref");
|
|
44200
|
+
const unit = unitId?.toString().slice(-4);
|
|
44201
|
+
const newId = new import_mongodb119.ObjectId(addToCart?.insertedId).toString().slice(-4);
|
|
44202
|
+
const referenceNumber = `CRT${unit}${newId}${dateFormatted}`;
|
|
44203
|
+
const result = await cartCollection().findOneAndUpdate({ _id: new import_mongodb119.ObjectId(addToCart.insertedId) }, { $set: { referenceNumber } }, { returnDocument: "after" });
|
|
44204
|
+
return result;
|
|
44205
|
+
} catch (error) {
|
|
44206
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44207
|
+
}
|
|
44208
|
+
};
|
|
44209
|
+
const payUnitCart = async (refId, payload) => {
|
|
44210
|
+
try {
|
|
44211
|
+
if (refId)
|
|
44212
|
+
refId = refId.toString();
|
|
44213
|
+
const updatedAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
44214
|
+
const cartInfo = await cartCollection().findOne({ referenceNumber: refId });
|
|
44215
|
+
const refNumber = cartInfo?.unitBill;
|
|
44216
|
+
if (payload.paymentStatus === "Paid" /* paid */ && payload.amountPaid) {
|
|
44217
|
+
payload.datePaid = /* @__PURE__ */ new Date();
|
|
44218
|
+
payload.paymentStatus = "Paid" /* paid */;
|
|
44219
|
+
payload.amountPaid;
|
|
44220
|
+
} else if (payload.paymentStatus === "Failed" /* failed */) {
|
|
44221
|
+
payload.amountPaid = 0;
|
|
44222
|
+
payload.paidBy = "";
|
|
44223
|
+
payload.datePaid = "";
|
|
44224
|
+
payload.paymentStatus = "Failed" /* failed */;
|
|
44225
|
+
}
|
|
44226
|
+
payload.updatedAt = updatedAt;
|
|
44227
|
+
const result = await cartCollection().findOneAndUpdate({ referenceNumber: refId }, { $set: payload }, { returnDocument: "after" });
|
|
44228
|
+
if (!result) {
|
|
44229
|
+
throw new Error("Failed to Process Transaction. Please Try Again Later");
|
|
44230
|
+
} else {
|
|
44231
|
+
for (const ref of refNumber) {
|
|
44232
|
+
const unitBillInfo = await collection().findOne({ referenceNumber: ref });
|
|
44233
|
+
const billId = unitBillInfo?.billId;
|
|
44234
|
+
const billInfo = await billCollection().findOne({ _id: new import_mongodb119.ObjectId(billId) });
|
|
44235
|
+
const billAmount = billInfo?.price;
|
|
44236
|
+
payload.updatedAt = updatedAt;
|
|
44237
|
+
payload.amountPaid = billAmount;
|
|
44238
|
+
const eachRef = await payUnitBill(ref, payload);
|
|
44239
|
+
}
|
|
44240
|
+
if (!cartInfo) {
|
|
44241
|
+
throw new Error("Cart info not found");
|
|
44242
|
+
}
|
|
44243
|
+
}
|
|
44244
|
+
return result;
|
|
44245
|
+
} catch (error) {
|
|
44246
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44247
|
+
}
|
|
44248
|
+
};
|
|
44249
|
+
const getCheckedOutBillings = async (refId) => {
|
|
44250
|
+
try {
|
|
44251
|
+
if (refId)
|
|
44252
|
+
refId = refId.toString();
|
|
44253
|
+
const result = await cartCollection().aggregate([
|
|
44254
|
+
{ $match: { referenceNumber: refId } },
|
|
44255
|
+
{
|
|
44256
|
+
$lookup: {
|
|
44257
|
+
from: "unit-bill",
|
|
44258
|
+
localField: "unitBill",
|
|
44259
|
+
foreignField: "referenceNumber",
|
|
44260
|
+
as: "unitBill"
|
|
44261
|
+
}
|
|
44262
|
+
},
|
|
44263
|
+
{
|
|
44264
|
+
$unwind: "$unitBill"
|
|
44265
|
+
},
|
|
44266
|
+
{
|
|
44267
|
+
$lookup: {
|
|
44268
|
+
from: "bill-records",
|
|
44269
|
+
localField: "unitBill.billId",
|
|
44270
|
+
foreignField: "_id",
|
|
44271
|
+
as: "billDetails"
|
|
44272
|
+
}
|
|
44273
|
+
},
|
|
44274
|
+
{
|
|
44275
|
+
$unwind: {
|
|
44276
|
+
path: "$billDetails",
|
|
44277
|
+
preserveNullAndEmptyArrays: true
|
|
44278
|
+
}
|
|
44279
|
+
},
|
|
44280
|
+
{
|
|
44281
|
+
$addFields: {
|
|
44282
|
+
"unitBill.billItemName": "$billDetails.billItem"
|
|
44283
|
+
}
|
|
44284
|
+
},
|
|
44285
|
+
{
|
|
44286
|
+
$project: {
|
|
44287
|
+
"unitBill.paidBy": 0,
|
|
44288
|
+
"unitBill.preDueDateAlert": 0,
|
|
44289
|
+
"unitBill.category": 0,
|
|
44290
|
+
"unitBill.contactNumber": 0,
|
|
44291
|
+
"unitBill.email": 0,
|
|
44292
|
+
"unitBill.site": 0,
|
|
44293
|
+
"unitBill.siteName": 0,
|
|
44294
|
+
"unitBill.organization": 0,
|
|
44295
|
+
"unitBill.billStatus": 0,
|
|
44296
|
+
"unitBill.createdBy": 0,
|
|
44297
|
+
"unitBill.createdAt": 0,
|
|
44298
|
+
"unitBill.updatedAt": 0,
|
|
44299
|
+
"billDetails": 0
|
|
44300
|
+
// Exclude the full billDetails as it's no longer needed
|
|
44301
|
+
}
|
|
44302
|
+
},
|
|
44303
|
+
{
|
|
44304
|
+
$group: {
|
|
44305
|
+
_id: "$_id",
|
|
44306
|
+
unitId: { $first: "$unitId" },
|
|
44307
|
+
referenceNumber: { $first: "$referenceNumber" },
|
|
44308
|
+
unitBill: { $push: "$unitBill" },
|
|
44309
|
+
paymentStatus: { $first: "$paymentStatus" },
|
|
44310
|
+
amountPaid: { $first: "$amountPaid" },
|
|
44311
|
+
site: { $first: "$site" },
|
|
44312
|
+
organization: { $first: "$organization" },
|
|
44313
|
+
paidBy: { $first: "$paidBy" },
|
|
44314
|
+
datePaid: { $first: "$referenceNumber" },
|
|
44315
|
+
billCategory: { $first: "$billCategory" },
|
|
44316
|
+
billFrom: { $first: "$billFrom" },
|
|
44317
|
+
billTo: { $first: "$billTo" },
|
|
44318
|
+
createdBy: { $first: "$createdBy" },
|
|
44319
|
+
createdAt: { $first: "$createdAt" },
|
|
44320
|
+
updatedAt: { $first: "$updatedAt" },
|
|
44321
|
+
transaction_id: { $first: "$transaction_id" }
|
|
44322
|
+
}
|
|
44323
|
+
}
|
|
44324
|
+
]).toArray();
|
|
44325
|
+
if (!result || result.length === 0) {
|
|
44326
|
+
return { success: false, message: "Cart Info Not Found" };
|
|
44327
|
+
}
|
|
44328
|
+
return result[0];
|
|
44329
|
+
} catch (error) {
|
|
44330
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44331
|
+
}
|
|
44332
|
+
};
|
|
44333
|
+
const cancelCheckedOutBillings = async (refId) => {
|
|
44334
|
+
try {
|
|
44335
|
+
if (refId)
|
|
44336
|
+
refId = refId.toString();
|
|
44337
|
+
const result = await cartCollection().findOneAndDelete({ referenceNumber: refId });
|
|
44338
|
+
if (!result) {
|
|
44339
|
+
return { success: false, message: "Cart Info Not Found" };
|
|
44340
|
+
}
|
|
44341
|
+
return { success: true, message: "Cart Deleted Successfully!", referenceNumber: result?.referenceNumber };
|
|
44342
|
+
} catch (error) {
|
|
44343
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44344
|
+
}
|
|
44345
|
+
};
|
|
44346
|
+
return {
|
|
44347
|
+
saveCreditCardInfo,
|
|
44348
|
+
checkOutUnitBills,
|
|
44349
|
+
payUnitBill,
|
|
44350
|
+
payUnitCart,
|
|
44351
|
+
getCheckedOutBillings,
|
|
44352
|
+
cancelCheckedOutBillings
|
|
44353
|
+
};
|
|
44354
|
+
};
|
|
44355
|
+
|
|
44356
|
+
// src/repositories/reddot-payment.repository.ts
|
|
44357
|
+
var import_node_server_utils215 = require("@7365admin1/node-server-utils");
|
|
44358
|
+
var useRedDotPaymentRepo = () => {
|
|
44359
|
+
const getDB = () => {
|
|
44360
|
+
const db = import_node_server_utils215.useAtlas.getDb();
|
|
44361
|
+
if (!db) {
|
|
44362
|
+
throw new import_node_server_utils215.InternalServerError("Unable to connect to server.");
|
|
44363
|
+
}
|
|
44364
|
+
return db;
|
|
44365
|
+
};
|
|
44366
|
+
const collection = () => {
|
|
44367
|
+
return getDB().collection("unit-bill");
|
|
44368
|
+
};
|
|
44369
|
+
const orgCollection = () => {
|
|
44370
|
+
return getDB().collection("organizations");
|
|
44371
|
+
};
|
|
44372
|
+
const cartCollection = () => {
|
|
44373
|
+
return getDB().collection("checkout-cart");
|
|
44374
|
+
};
|
|
44375
|
+
const redDotMerchantCollection = () => {
|
|
44376
|
+
return getDB().collection("reddot-merchant");
|
|
44377
|
+
};
|
|
44378
|
+
const createRedDotAccount = async (_id, payload) => {
|
|
44379
|
+
try {
|
|
44380
|
+
const merchant = await redDotMerchantCollection().insertOne(payload);
|
|
44381
|
+
if (!merchant) {
|
|
44382
|
+
throw new Error("Failed to Add Merchant Details");
|
|
44383
|
+
}
|
|
44384
|
+
const merchantId = merchant?.insertedId;
|
|
44385
|
+
const orgId = new import_mongodb120.ObjectId(_id);
|
|
44386
|
+
const result = await orgCollection().findOneAndUpdate({ _id: orgId }, { $push: { merchant: merchantId } }, {
|
|
44387
|
+
returnDocument: "after"
|
|
44388
|
+
});
|
|
44389
|
+
if (!result) {
|
|
44390
|
+
throw new Error("Organization not found");
|
|
44391
|
+
}
|
|
44392
|
+
return {
|
|
44393
|
+
success: true,
|
|
44394
|
+
message: "Merchant Details successfully added."
|
|
44395
|
+
};
|
|
44396
|
+
} catch (error) {
|
|
44397
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44398
|
+
}
|
|
44399
|
+
};
|
|
44400
|
+
const payUnitBillings = async (refId, payload) => {
|
|
44401
|
+
const checkCart = await cartCollection().findOne({ referenceNumber: refId });
|
|
44402
|
+
if (checkCart) {
|
|
44403
|
+
const multiple = await PaymentBillRepo().payUnitCart(refId, payload);
|
|
44404
|
+
if (multiple) {
|
|
44405
|
+
return await PaymentBillRepo().getCheckedOutBillings(refId);
|
|
44406
|
+
}
|
|
44407
|
+
}
|
|
44408
|
+
const single = await PaymentBillRepo().payUnitBill(refId, payload);
|
|
44409
|
+
return single;
|
|
44410
|
+
};
|
|
44411
|
+
const getMerchantDetailsById = async (_id) => {
|
|
44412
|
+
try {
|
|
44413
|
+
if (_id)
|
|
44414
|
+
_id = new import_mongodb120.ObjectId(_id);
|
|
44415
|
+
const result = await redDotMerchantCollection().aggregate([
|
|
44416
|
+
{
|
|
44417
|
+
$match: {
|
|
44418
|
+
_id
|
|
44419
|
+
}
|
|
44420
|
+
},
|
|
44421
|
+
{
|
|
44422
|
+
$facet: {
|
|
44423
|
+
totalCount: [{ $count: "count" }],
|
|
44424
|
+
items: [{ $sort: { _id: -1 } }]
|
|
44425
|
+
}
|
|
44426
|
+
}
|
|
44427
|
+
]).toArray();
|
|
44428
|
+
const items = result[0].items;
|
|
44429
|
+
return items;
|
|
44430
|
+
} catch (error) {
|
|
44431
|
+
throw new Error(error.message || error || "Server Internal Error");
|
|
44432
|
+
}
|
|
44433
|
+
};
|
|
44434
|
+
return {
|
|
44435
|
+
createRedDotAccount,
|
|
44436
|
+
payUnitBillings,
|
|
44437
|
+
getMerchantDetailsById
|
|
44438
|
+
};
|
|
44439
|
+
};
|
|
44440
|
+
|
|
44441
|
+
// src/services/reddot-payment.service.ts
|
|
44442
|
+
var useRedDotPaymentSvc = () => {
|
|
44443
|
+
const createRedDotAccount = async (_id, payload) => {
|
|
44444
|
+
return useRedDotPaymentRepo().createRedDotAccount(_id, payload);
|
|
44445
|
+
};
|
|
44446
|
+
const redirectPaymentTransaction = async (payload) => {
|
|
44447
|
+
try {
|
|
44448
|
+
const SECRET_KEY2 = payload.merchant_key;
|
|
44449
|
+
if (!payload.mid && !payload.merchant_key) {
|
|
44450
|
+
return { success: false, message: "RDP Not Available on this account. Please Contact Management" };
|
|
44451
|
+
}
|
|
44452
|
+
const data = {
|
|
44453
|
+
mid: payload.mid,
|
|
44454
|
+
api_mode: "redirection_hosted",
|
|
44455
|
+
payment_type: "S",
|
|
44456
|
+
order_id: payload.order_id,
|
|
44457
|
+
ccy: "SGD",
|
|
44458
|
+
amount: payload.amount,
|
|
44459
|
+
back_url: payload.back_url,
|
|
44460
|
+
redirect_url: payload.redirect_url,
|
|
44461
|
+
notify_url: payload.notify_url
|
|
44462
|
+
};
|
|
44463
|
+
if (!SECRET_KEY2) {
|
|
44464
|
+
throw new Error("Merchant key is required but was not provided.");
|
|
44465
|
+
}
|
|
44466
|
+
data["signature"] = paymentSignature(data, SECRET_KEY2);
|
|
44467
|
+
const dataString = JSON.stringify(data);
|
|
44468
|
+
const headers = {
|
|
44469
|
+
"Content-Type": "application/json",
|
|
44470
|
+
"Content-Length": String(dataString.length)
|
|
44471
|
+
};
|
|
44472
|
+
if (!process.env.MERCHANT_PAYMENT) {
|
|
44473
|
+
throw new Error("MERCHANT_PAYMENT environment variable is not defined.");
|
|
44474
|
+
}
|
|
44475
|
+
const url = process.env.MERCHANT_PAYMENT;
|
|
44476
|
+
const response = await import_axios3.default.post(url, dataString, { headers });
|
|
44477
|
+
const result = response.data;
|
|
44478
|
+
return result;
|
|
44479
|
+
} catch (error) {
|
|
44480
|
+
return Promise.reject(error || error.message || "Server Internal Error!");
|
|
44481
|
+
}
|
|
44482
|
+
};
|
|
44483
|
+
const enquirePaymentTransaction = async (payload) => {
|
|
44484
|
+
try {
|
|
44485
|
+
const SECRET_KEY2 = payload.merchant_key;
|
|
44486
|
+
if (!payload.request_mid && !payload.merchant_key) {
|
|
44487
|
+
return { success: false, message: "RDP Not Available on this account. Please Contact Management" };
|
|
44488
|
+
}
|
|
44489
|
+
const data = {
|
|
44490
|
+
request_mid: payload.request_mid,
|
|
44491
|
+
transaction_id: payload.transaction_id
|
|
44492
|
+
};
|
|
44493
|
+
if (!SECRET_KEY2) {
|
|
44494
|
+
throw new Error("Merchant key is required but was not provided.");
|
|
44495
|
+
}
|
|
44496
|
+
data["signature"] = genericSignature(data, SECRET_KEY2);
|
|
44497
|
+
const dataString = JSON.stringify(data);
|
|
44498
|
+
const headers = {
|
|
44499
|
+
"Content-Type": "application/json"
|
|
44500
|
+
};
|
|
44501
|
+
if (!process.env.MERCHANT_ENQUIRY) {
|
|
44502
|
+
throw new Error("MERCHANT_PAYMENT environment variable is not defined.");
|
|
44503
|
+
}
|
|
44504
|
+
const url = process.env.MERCHANT_ENQUIRY;
|
|
44505
|
+
const response = await import_axios3.default.post(url, dataString, { headers });
|
|
44506
|
+
const result = response.data;
|
|
44507
|
+
const transactionId = result.transaction_id;
|
|
44508
|
+
const amount = result.request_amount || 0;
|
|
44509
|
+
const payer = result.payer_name || "";
|
|
44510
|
+
const refId = result.order_id;
|
|
44511
|
+
const message = result.response_msg;
|
|
44512
|
+
const invoiceDate = /* @__PURE__ */ new Date();
|
|
44513
|
+
if (result.response_code === "0") {
|
|
44514
|
+
const success = {
|
|
44515
|
+
method: payload.method,
|
|
44516
|
+
paymentStatus: "Paid" /* paid */,
|
|
44517
|
+
amountPaid: amount,
|
|
44518
|
+
paidBy: payer,
|
|
44519
|
+
updatedAt: invoiceDate,
|
|
44520
|
+
transaction_id: transactionId,
|
|
44521
|
+
message
|
|
44522
|
+
};
|
|
44523
|
+
await useRedDotPaymentRepo().payUnitBillings(refId, success);
|
|
44524
|
+
} else if (result.response_code !== "0") {
|
|
44525
|
+
const fail = {
|
|
44526
|
+
method: payload.method,
|
|
44527
|
+
paymentStatus: "Failed" /* failed */,
|
|
44528
|
+
updatedAt: invoiceDate,
|
|
44529
|
+
paidBy: "",
|
|
44530
|
+
amountPaid: "0",
|
|
44531
|
+
transaction_id: transactionId,
|
|
44532
|
+
message
|
|
44533
|
+
};
|
|
44534
|
+
await useRedDotPaymentRepo().payUnitBillings(refId, fail);
|
|
44535
|
+
}
|
|
44536
|
+
return result;
|
|
44537
|
+
} catch (error) {
|
|
44538
|
+
return Promise.reject(error || error.message || "Server Internal Error!");
|
|
44539
|
+
}
|
|
44540
|
+
};
|
|
44541
|
+
const payInvoice = async (payload) => {
|
|
44542
|
+
try {
|
|
44543
|
+
const data = {
|
|
44544
|
+
cardNumber: payload.cardNumber,
|
|
44545
|
+
rdpMid: payload.rdpMid,
|
|
44546
|
+
orderId: payload.orderId
|
|
44547
|
+
};
|
|
44548
|
+
const dataString = JSON.stringify(data);
|
|
44549
|
+
const headers = {
|
|
44550
|
+
"Content-Type": "application/json",
|
|
44551
|
+
"Content-Length": String(dataString.length)
|
|
44552
|
+
};
|
|
44553
|
+
if (!process.env.MERCHANT_PAYMENT) {
|
|
44554
|
+
throw new Error("MERCHANT_PAYMENT environment variable is not defined.");
|
|
44555
|
+
}
|
|
44556
|
+
const url = process.env.MERCHANT_PAYMENT;
|
|
44557
|
+
const response = await import_axios3.default.post(url, dataString, { headers });
|
|
44558
|
+
return response;
|
|
44559
|
+
} catch (error) {
|
|
44560
|
+
return Promise.reject(error || error.message || "Server Internal Error!");
|
|
44561
|
+
}
|
|
44562
|
+
};
|
|
44563
|
+
const getMerchantDetailsById = async (_id) => {
|
|
44564
|
+
return useRedDotPaymentRepo().getMerchantDetailsById(_id);
|
|
44565
|
+
};
|
|
44566
|
+
return {
|
|
44567
|
+
createRedDotAccount,
|
|
44568
|
+
redirectPaymentTransaction,
|
|
44569
|
+
enquirePaymentTransaction,
|
|
44570
|
+
payInvoice,
|
|
44571
|
+
getMerchantDetailsById
|
|
44572
|
+
};
|
|
44573
|
+
};
|
|
44574
|
+
|
|
44575
|
+
// src/controllers/reddot-payment.controller.ts
|
|
44576
|
+
var import_joi124 = __toESM(require("joi"));
|
|
44577
|
+
function useRedDotPaymentController() {
|
|
44578
|
+
const createRedDotAccount = async (req, res) => {
|
|
44579
|
+
try {
|
|
44580
|
+
const data = req.body;
|
|
44581
|
+
const id = req.params.id;
|
|
44582
|
+
const schema2 = import_joi124.default.object({
|
|
44583
|
+
id: import_joi124.default.string().hex().required(),
|
|
44584
|
+
// organization id
|
|
44585
|
+
paymentMethod: import_joi124.default.string().required(),
|
|
44586
|
+
// payment method (e.g. "Visa / Mastercard / PayNow QR Code")
|
|
44587
|
+
merchant_id: import_joi124.default.string().required(),
|
|
44588
|
+
// merchant id
|
|
44589
|
+
merchant_key: import_joi124.default.string().required()
|
|
44590
|
+
// secret key
|
|
44591
|
+
});
|
|
44592
|
+
const { error } = schema2.validate({ id, ...data });
|
|
44593
|
+
if (error) {
|
|
44594
|
+
return res.status(400).json({ data: null, message: error.message });
|
|
44595
|
+
}
|
|
44596
|
+
const result = await useRedDotPaymentSvc().createRedDotAccount(id, data);
|
|
44597
|
+
return res.json(result);
|
|
44598
|
+
} catch (error) {
|
|
44599
|
+
return res.status(500).json({ message: error.message || error });
|
|
44600
|
+
}
|
|
44601
|
+
};
|
|
44602
|
+
const redirectPaymentTransaction = async (req, res) => {
|
|
44603
|
+
try {
|
|
44604
|
+
const data = req.body;
|
|
44605
|
+
const schema2 = import_joi124.default.object({
|
|
44606
|
+
mid: import_joi124.default.string().optional().allow("", null),
|
|
44607
|
+
order_id: import_joi124.default.string().required(),
|
|
44608
|
+
amount: import_joi124.default.number().required(),
|
|
44609
|
+
merchant_key: import_joi124.default.string().required(),
|
|
44610
|
+
back_url: import_joi124.default.string().required(),
|
|
44611
|
+
redirect_url: import_joi124.default.string().required(),
|
|
44612
|
+
notify_url: import_joi124.default.string().required()
|
|
44613
|
+
});
|
|
44614
|
+
const { error } = schema2.validate({ ...data });
|
|
44615
|
+
if (error) {
|
|
44616
|
+
return res.status(400).json({ data: null, message: error.message });
|
|
44617
|
+
}
|
|
44618
|
+
const result = await useRedDotPaymentSvc().redirectPaymentTransaction(data);
|
|
44619
|
+
return res.json(result);
|
|
44620
|
+
} catch (error) {
|
|
44621
|
+
return res.status(500).json({ message: error.message || error });
|
|
44622
|
+
}
|
|
44623
|
+
};
|
|
44624
|
+
const enquirePaymentTransaction = async (req, res) => {
|
|
44625
|
+
try {
|
|
44626
|
+
const data = req.body;
|
|
44627
|
+
const schema2 = import_joi124.default.object({
|
|
44628
|
+
request_mid: import_joi124.default.string().optional().allow("", null),
|
|
44629
|
+
transaction_id: import_joi124.default.string().required(),
|
|
44630
|
+
merchant_key: import_joi124.default.string().optional().allow("", null),
|
|
44631
|
+
method: import_joi124.default.string().optional().allow("", null)
|
|
44632
|
+
});
|
|
44633
|
+
const { error } = schema2.validate({ ...data });
|
|
44634
|
+
if (error) {
|
|
44635
|
+
return res.status(400).json({ data: null, message: error.message });
|
|
44636
|
+
}
|
|
44637
|
+
const result = await useRedDotPaymentSvc().enquirePaymentTransaction(data);
|
|
44638
|
+
return res.json(result);
|
|
44639
|
+
} catch (error) {
|
|
44640
|
+
return res.status(500).json({ message: error.message || error });
|
|
44641
|
+
}
|
|
44642
|
+
};
|
|
44643
|
+
const getMerchantDetailsById = async (req, res, next) => {
|
|
44644
|
+
try {
|
|
44645
|
+
const _id = req.params.id;
|
|
44646
|
+
const schema2 = import_joi124.default.object({
|
|
44647
|
+
_id: import_joi124.default.string().hex().required()
|
|
44648
|
+
});
|
|
44649
|
+
const { error } = schema2.validate({ _id });
|
|
44650
|
+
if (error) {
|
|
44651
|
+
return res.status(400).json({ data: null, message: error.message });
|
|
44652
|
+
}
|
|
44653
|
+
const result = await useRedDotPaymentSvc().getMerchantDetailsById(_id);
|
|
44654
|
+
return res.json(result);
|
|
44655
|
+
} catch (error) {
|
|
44656
|
+
next(error);
|
|
44657
|
+
}
|
|
44658
|
+
};
|
|
44659
|
+
return {
|
|
44660
|
+
createRedDotAccount,
|
|
44661
|
+
redirectPaymentTransaction,
|
|
44662
|
+
enquirePaymentTransaction,
|
|
44663
|
+
getMerchantDetailsById
|
|
44664
|
+
};
|
|
44665
|
+
}
|
|
43071
44666
|
// Annotate the CommonJS export names for ESM import in node:
|
|
43072
44667
|
0 && (module.exports = {
|
|
43073
44668
|
ANPRMode,
|
|
@@ -43109,6 +44704,7 @@ function useManpowerRemarkCtrl() {
|
|
|
43109
44704
|
MManpowerDesignations,
|
|
43110
44705
|
MManpowerMonitoring,
|
|
43111
44706
|
MManpowerRemarks,
|
|
44707
|
+
MManpowerSites,
|
|
43112
44708
|
MMember,
|
|
43113
44709
|
MNfcPatrolLog,
|
|
43114
44710
|
MNfcPatrolRoute,
|
|
@@ -43174,6 +44770,7 @@ function useManpowerRemarkCtrl() {
|
|
|
43174
44770
|
bulletin_boards_namespace_collection,
|
|
43175
44771
|
calculatePercentage,
|
|
43176
44772
|
chatSchema,
|
|
44773
|
+
createManpowerRemarksDaily,
|
|
43177
44774
|
customerSchema,
|
|
43178
44775
|
designationsSchema,
|
|
43179
44776
|
events_namespace_collection,
|
|
@@ -43188,10 +44785,13 @@ function useManpowerRemarkCtrl() {
|
|
|
43188
44785
|
landscapeDashboardCollection,
|
|
43189
44786
|
mAndEDashboardCollection,
|
|
43190
44787
|
manpowerDesignationsSchema,
|
|
44788
|
+
manpowerEvents,
|
|
43191
44789
|
manpowerMonitoringSchema,
|
|
43192
44790
|
manpowerRemarksSchema,
|
|
44791
|
+
manpowerSitesSchema,
|
|
43193
44792
|
nfcPatrolSettingsSchema,
|
|
43194
44793
|
nfcPatrolSettingsSchemaUpdate,
|
|
44794
|
+
occurrence_book_namespace_collection,
|
|
43195
44795
|
orgSchema,
|
|
43196
44796
|
overnight_parking_requests_namespace_collection,
|
|
43197
44797
|
pestDashboardCollection,
|
|
@@ -43272,6 +44872,8 @@ function useManpowerRemarkCtrl() {
|
|
|
43272
44872
|
siteSchema,
|
|
43273
44873
|
site_people_namespace_collection,
|
|
43274
44874
|
tokenSchema,
|
|
44875
|
+
updateRemarksStatusEod,
|
|
44876
|
+
updateRemarksisAcknowledged,
|
|
43275
44877
|
updateSiteSchema,
|
|
43276
44878
|
useAccessManagementController,
|
|
43277
44879
|
useAddressRepo,
|
|
@@ -43338,6 +44940,9 @@ function useManpowerRemarkCtrl() {
|
|
|
43338
44940
|
useManpowerMonitoringSrvc,
|
|
43339
44941
|
useManpowerRemarkCtrl,
|
|
43340
44942
|
useManpowerRemarksRepo,
|
|
44943
|
+
useManpowerSitesCtrl,
|
|
44944
|
+
useManpowerSitesRepo,
|
|
44945
|
+
useManpowerSitesSrvc,
|
|
43341
44946
|
useMemberController,
|
|
43342
44947
|
useMemberRepo,
|
|
43343
44948
|
useNewDashboardController,
|
|
@@ -43385,6 +44990,9 @@ function useManpowerRemarkCtrl() {
|
|
|
43385
44990
|
usePriceRepo,
|
|
43386
44991
|
usePromoCodeController,
|
|
43387
44992
|
usePromoCodeRepo,
|
|
44993
|
+
useRedDotPaymentController,
|
|
44994
|
+
useRedDotPaymentRepo,
|
|
44995
|
+
useRedDotPaymentSvc,
|
|
43388
44996
|
useRobotController,
|
|
43389
44997
|
useRobotRepo,
|
|
43390
44998
|
useRobotService,
|