@7365admin1/core 2.37.0 → 2.39.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 +168 -102
- package/dist/index.js +1157 -799
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +965 -614
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
// src/models/base.model.ts
|
|
2
|
+
var AppServiceType = /* @__PURE__ */ ((AppServiceType2) => {
|
|
3
|
+
AppServiceType2["REAL_ESTATE_DEVELOPER"] = "real_estate_developer";
|
|
4
|
+
AppServiceType2["PROPERTY_MANAGEMENT_AGENCY"] = "property_management_agency";
|
|
5
|
+
AppServiceType2["SECURITY_AGENCY"] = "security_agency";
|
|
6
|
+
AppServiceType2["CLEANING_SERVICES"] = "cleaning_services";
|
|
7
|
+
AppServiceType2["MECHANICAL_ELECTRICAL_SERVICES"] = "mechanical_electrical_services";
|
|
8
|
+
AppServiceType2["LANDSCAPING_SERVICES"] = "landscaping_services";
|
|
9
|
+
AppServiceType2["PEST_CONTROL_SERVICES"] = "pest_control_services";
|
|
10
|
+
AppServiceType2["POOL_MAINTENANCE_SERVICES"] = "pool_maintenance_services";
|
|
11
|
+
return AppServiceType2;
|
|
12
|
+
})(AppServiceType || {});
|
|
13
|
+
|
|
1
14
|
// src/models/session.model.ts
|
|
2
15
|
import { BadRequestError } from "@7365admin1/node-server-utils";
|
|
3
16
|
import Joi from "joi";
|
|
@@ -4842,6 +4855,7 @@ function useSiteRepo() {
|
|
|
4842
4855
|
|
|
4843
4856
|
// src/services/verification.service.ts
|
|
4844
4857
|
import Joi11 from "joi";
|
|
4858
|
+
import path from "path";
|
|
4845
4859
|
function useVerificationService() {
|
|
4846
4860
|
const MailerConfig = {
|
|
4847
4861
|
host: MAILER_TRANSPORT_HOST,
|
|
@@ -4872,7 +4886,6 @@ function useVerificationService() {
|
|
|
4872
4886
|
expireAt: new Date(
|
|
4873
4887
|
(/* @__PURE__ */ new Date()).getTime() + 72 * 60 * 60 * 1e3
|
|
4874
4888
|
).toISOString(),
|
|
4875
|
-
// 72 hours (3 days) from now
|
|
4876
4889
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4877
4890
|
};
|
|
4878
4891
|
if (value.metadata?.org)
|
|
@@ -4960,8 +4973,11 @@ function useVerificationService() {
|
|
|
4960
4973
|
subject = "Service Provider Organization Invite";
|
|
4961
4974
|
}
|
|
4962
4975
|
const res = await add(value);
|
|
4963
|
-
const
|
|
4964
|
-
|
|
4976
|
+
const filePath = path.resolve(
|
|
4977
|
+
__dirname,
|
|
4978
|
+
"../public/handlebars",
|
|
4979
|
+
value.type
|
|
4980
|
+
);
|
|
4965
4981
|
const link = org ? `${APP_MAIN}/verify/${value.type}/${res}` : `${APP_ORG}/organizations/create?email=${email}`;
|
|
4966
4982
|
const emailContent = compileHandlebar({
|
|
4967
4983
|
context: {
|
|
@@ -4997,6 +5013,9 @@ function useVerificationService() {
|
|
|
4997
5013
|
};
|
|
4998
5014
|
try {
|
|
4999
5015
|
const user = await getUserByEmail(email);
|
|
5016
|
+
if (!user) {
|
|
5017
|
+
throw new NotFoundError9("Email not found");
|
|
5018
|
+
}
|
|
5000
5019
|
const res = await add(value);
|
|
5001
5020
|
const dir = __dirname;
|
|
5002
5021
|
const filePath = getDirectory(dir, "./public/handlebars/forget-password");
|
|
@@ -13197,7 +13216,7 @@ var schemaVisitorTransaction = Joi36.object({
|
|
|
13197
13216
|
checkOutRemarks: Joi36.string().optional().allow("", null),
|
|
13198
13217
|
expectedCheckIn: Joi36.string().isoDate().optional(),
|
|
13199
13218
|
purpose: Joi36.string().optional().allow(null, ""),
|
|
13200
|
-
|
|
13219
|
+
inviterId: Joi36.any().optional().allow(null, "")
|
|
13201
13220
|
});
|
|
13202
13221
|
var schemaUpdateVisTrans = Joi36.object({
|
|
13203
13222
|
_id: Joi36.string().hex().length(24).required(),
|
|
@@ -13306,11 +13325,11 @@ function MVisitorTransaction(value) {
|
|
|
13306
13325
|
return p;
|
|
13307
13326
|
});
|
|
13308
13327
|
}
|
|
13309
|
-
if (value.
|
|
13328
|
+
if (value.inviterId && typeof value.inviterId === "string") {
|
|
13310
13329
|
try {
|
|
13311
|
-
value.
|
|
13330
|
+
value.inviterId = new ObjectId39(value.inviterId);
|
|
13312
13331
|
} catch (error2) {
|
|
13313
|
-
throw new Error("Invalid
|
|
13332
|
+
throw new Error("Invalid inviter ID.");
|
|
13314
13333
|
}
|
|
13315
13334
|
}
|
|
13316
13335
|
const newDate = /* @__PURE__ */ new Date();
|
|
@@ -13353,11 +13372,11 @@ function MVisitorTransaction(value) {
|
|
|
13353
13372
|
numberOfPassengers: value.numberOfPassengers ?? null,
|
|
13354
13373
|
email: value.email,
|
|
13355
13374
|
isOvernightParking: value.isOvernightParking ?? false,
|
|
13356
|
-
|
|
13375
|
+
inviterId: value.inviterId ?? "",
|
|
13357
13376
|
overnightParking: value.isOvernightParking == true ? {
|
|
13358
13377
|
status: "pending approval",
|
|
13359
13378
|
remarks: "",
|
|
13360
|
-
updatedBy: value.
|
|
13379
|
+
updatedBy: value.inviterId ?? ""
|
|
13361
13380
|
} : null,
|
|
13362
13381
|
arrivalTime: value.arrivalTime,
|
|
13363
13382
|
duration: value.duration
|
|
@@ -13408,14 +13427,15 @@ function useVisitorTransactionRepo() {
|
|
|
13408
13427
|
page = 1,
|
|
13409
13428
|
limit = 10,
|
|
13410
13429
|
sort = {},
|
|
13411
|
-
status
|
|
13430
|
+
status,
|
|
13412
13431
|
org = "",
|
|
13413
13432
|
site = "",
|
|
13414
13433
|
dateTo = "",
|
|
13415
13434
|
dateFrom = "",
|
|
13416
13435
|
type = "",
|
|
13417
13436
|
checkedOut,
|
|
13418
|
-
plateNumber = ""
|
|
13437
|
+
plateNumber = "",
|
|
13438
|
+
tab = ""
|
|
13419
13439
|
}) {
|
|
13420
13440
|
page = page > 0 ? page - 1 : 0;
|
|
13421
13441
|
const skip = page * limit;
|
|
@@ -13433,7 +13453,6 @@ function useVisitorTransactionRepo() {
|
|
|
13433
13453
|
expectedCheckInFilter.$lte = new Date(dateTo);
|
|
13434
13454
|
}
|
|
13435
13455
|
const query = {
|
|
13436
|
-
status,
|
|
13437
13456
|
...ObjectId40.isValid(org) && { org: new ObjectId40(org) },
|
|
13438
13457
|
...ObjectId40.isValid(site) && { site: new ObjectId40(site) },
|
|
13439
13458
|
...Object.keys(checkInFilter).length > 0 && { checkIn: checkInFilter },
|
|
@@ -13441,7 +13460,9 @@ function useVisitorTransactionRepo() {
|
|
|
13441
13460
|
...Array.isArray(type) ? { type: { $in: type } } : type ? { type } : {},
|
|
13442
13461
|
...checkedOut == false && { checkOut: { $eq: null } },
|
|
13443
13462
|
...search && { $text: { $search: search } },
|
|
13444
|
-
...plateNumber && { plateNumber }
|
|
13463
|
+
...plateNumber && { plateNumber },
|
|
13464
|
+
...status && { status },
|
|
13465
|
+
...tab == "Overnight Parking" && { isOvernightParking: true }
|
|
13445
13466
|
};
|
|
13446
13467
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
13447
13468
|
try {
|
|
@@ -13587,7 +13608,31 @@ function useVisitorTransactionRepo() {
|
|
|
13587
13608
|
},
|
|
13588
13609
|
{ $sort: sort },
|
|
13589
13610
|
{ $skip: skip },
|
|
13590
|
-
{ $limit: limit }
|
|
13611
|
+
{ $limit: limit },
|
|
13612
|
+
{
|
|
13613
|
+
$lookup: {
|
|
13614
|
+
from: "users",
|
|
13615
|
+
localField: "inviterId",
|
|
13616
|
+
foreignField: "_id",
|
|
13617
|
+
as: "inviterData"
|
|
13618
|
+
}
|
|
13619
|
+
},
|
|
13620
|
+
{
|
|
13621
|
+
$unwind: {
|
|
13622
|
+
path: "$inviterData",
|
|
13623
|
+
preserveNullAndEmptyArrays: true
|
|
13624
|
+
}
|
|
13625
|
+
},
|
|
13626
|
+
{
|
|
13627
|
+
$addFields: {
|
|
13628
|
+
inviterName: "$inviterData.name"
|
|
13629
|
+
}
|
|
13630
|
+
},
|
|
13631
|
+
{
|
|
13632
|
+
$project: {
|
|
13633
|
+
inviterData: 0
|
|
13634
|
+
}
|
|
13635
|
+
}
|
|
13591
13636
|
]).toArray(),
|
|
13592
13637
|
collection.aggregate([...basePipeline, { $count: "total" }]).toArray()
|
|
13593
13638
|
]);
|
|
@@ -13903,7 +13948,7 @@ function MVehicle(value) {
|
|
|
13903
13948
|
block: value.block ?? 0,
|
|
13904
13949
|
level: value.level ?? "",
|
|
13905
13950
|
unit: value.unit ?? "",
|
|
13906
|
-
nric: value.nric,
|
|
13951
|
+
nric: value.nric ?? "",
|
|
13907
13952
|
remarks: value.remarks ?? "",
|
|
13908
13953
|
seasonPassType: value.seasonPassType ?? "",
|
|
13909
13954
|
start: value.start ?? createdAt,
|
|
@@ -13963,7 +14008,7 @@ function MVehicleTransaction(value) {
|
|
|
13963
14008
|
import { BadRequestError as BadRequestError71, logger as logger52 } from "@7365admin1/node-server-utils";
|
|
13964
14009
|
import { promises as fsAsync } from "fs";
|
|
13965
14010
|
import Joi39 from "joi";
|
|
13966
|
-
import * as
|
|
14011
|
+
import * as path2 from "path";
|
|
13967
14012
|
import { request } from "urllib";
|
|
13968
14013
|
|
|
13969
14014
|
// src/repositories/vehicle.repo.ts
|
|
@@ -14607,6 +14652,66 @@ function useVehicleRepo() {
|
|
|
14607
14652
|
throw error;
|
|
14608
14653
|
}
|
|
14609
14654
|
}
|
|
14655
|
+
async function bulkUpsertVehicles(values, session) {
|
|
14656
|
+
try {
|
|
14657
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
14658
|
+
return {
|
|
14659
|
+
matchedCount: 0,
|
|
14660
|
+
modifiedCount: 0,
|
|
14661
|
+
upsertedCount: 0
|
|
14662
|
+
};
|
|
14663
|
+
}
|
|
14664
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
14665
|
+
const operations = values.map((item) => {
|
|
14666
|
+
const vehicle = MVehicle(item);
|
|
14667
|
+
const plateNumber = Array.isArray(vehicle.plateNumber) ? vehicle.plateNumber[0] : vehicle.plateNumber;
|
|
14668
|
+
const { createdAt, ...rest } = vehicle;
|
|
14669
|
+
return {
|
|
14670
|
+
updateOne: {
|
|
14671
|
+
filter: {
|
|
14672
|
+
site: vehicle.site,
|
|
14673
|
+
plateNumber,
|
|
14674
|
+
$or: [
|
|
14675
|
+
{ deletedAt: "" },
|
|
14676
|
+
{ deletedAt: null },
|
|
14677
|
+
{ deletedAt: { $exists: false } }
|
|
14678
|
+
]
|
|
14679
|
+
},
|
|
14680
|
+
update: {
|
|
14681
|
+
$set: {
|
|
14682
|
+
...rest,
|
|
14683
|
+
plateNumber,
|
|
14684
|
+
updatedAt: now
|
|
14685
|
+
},
|
|
14686
|
+
$setOnInsert: {
|
|
14687
|
+
createdAt: vehicle.createdAt || now
|
|
14688
|
+
}
|
|
14689
|
+
},
|
|
14690
|
+
upsert: true
|
|
14691
|
+
}
|
|
14692
|
+
};
|
|
14693
|
+
});
|
|
14694
|
+
const res = await collection.bulkWrite(operations, {
|
|
14695
|
+
ordered: false,
|
|
14696
|
+
session
|
|
14697
|
+
});
|
|
14698
|
+
return {
|
|
14699
|
+
matchedCount: res.matchedCount,
|
|
14700
|
+
modifiedCount: res.modifiedCount,
|
|
14701
|
+
upsertedCount: res.upsertedCount,
|
|
14702
|
+
upsertedIds: res.upsertedIds
|
|
14703
|
+
};
|
|
14704
|
+
} catch (error) {
|
|
14705
|
+
logger49.log({
|
|
14706
|
+
level: "error",
|
|
14707
|
+
message: error.message
|
|
14708
|
+
});
|
|
14709
|
+
if (error instanceof AppError9) {
|
|
14710
|
+
throw error;
|
|
14711
|
+
}
|
|
14712
|
+
throw new Error("Failed to bulk upsert vehicles.");
|
|
14713
|
+
}
|
|
14714
|
+
}
|
|
14610
14715
|
return {
|
|
14611
14716
|
createIndex,
|
|
14612
14717
|
createTextIndex,
|
|
@@ -14621,7 +14726,8 @@ function useVehicleRepo() {
|
|
|
14621
14726
|
getVehiclesByNRIC,
|
|
14622
14727
|
deleteExpiredVehicles,
|
|
14623
14728
|
getAllVehiclesByUnitId,
|
|
14624
|
-
getAllExpiredVehicles
|
|
14729
|
+
getAllExpiredVehicles,
|
|
14730
|
+
bulkUpsertVehicles
|
|
14625
14731
|
};
|
|
14626
14732
|
}
|
|
14627
14733
|
|
|
@@ -15267,7 +15373,8 @@ function useVehicleService() {
|
|
|
15267
15373
|
getVehicleById: _getVehicleById,
|
|
15268
15374
|
deleteExpiredVehicles: _deleteExpiredVehicles,
|
|
15269
15375
|
getVehicleByPlateNumber: _getVehicleByPlateNumber,
|
|
15270
|
-
getAllExpiredVehicles: _getAllExpiredVehicles
|
|
15376
|
+
getAllExpiredVehicles: _getAllExpiredVehicles,
|
|
15377
|
+
bulkUpsertVehicles: _bulkUpsertVehicles
|
|
15271
15378
|
} = useVehicleRepo();
|
|
15272
15379
|
const {
|
|
15273
15380
|
addPlateNumber: _addPlateNumber,
|
|
@@ -15884,13 +15991,38 @@ function useVehicleService() {
|
|
|
15884
15991
|
session.endSession();
|
|
15885
15992
|
}
|
|
15886
15993
|
}
|
|
15994
|
+
async function bulkUpsertVehicles(values) {
|
|
15995
|
+
const session = useAtlas33.getClient()?.startSession();
|
|
15996
|
+
if (!session) {
|
|
15997
|
+
throw new Error("Unable to start session for vehicle service.");
|
|
15998
|
+
}
|
|
15999
|
+
try {
|
|
16000
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
16001
|
+
throw new Error("Vehicle list is required.");
|
|
16002
|
+
}
|
|
16003
|
+
const sanitizedValues = values.map((item) => {
|
|
16004
|
+
const plateNumber = Array.isArray(item.plateNumber) ? item.plateNumber[0] : item.plateNumber;
|
|
16005
|
+
return {
|
|
16006
|
+
...item,
|
|
16007
|
+
plateNumber: typeof plateNumber === "string" ? plateNumber.trim() : plateNumber
|
|
16008
|
+
};
|
|
16009
|
+
}).filter((item) => item.site && item.plateNumber);
|
|
16010
|
+
if (sanitizedValues.length === 0) {
|
|
16011
|
+
throw new Error("No valid vehicle plate numbers found.");
|
|
16012
|
+
}
|
|
16013
|
+
return await _bulkUpsertVehicles(sanitizedValues, session);
|
|
16014
|
+
} catch (error) {
|
|
16015
|
+
throw error;
|
|
16016
|
+
}
|
|
16017
|
+
}
|
|
15887
16018
|
return {
|
|
15888
16019
|
add,
|
|
15889
16020
|
deleteVehicle,
|
|
15890
16021
|
approveVehicleById,
|
|
15891
16022
|
processDeletingExpiredVehicles,
|
|
15892
16023
|
reactivateVehicleById,
|
|
15893
|
-
updateVehicleById
|
|
16024
|
+
updateVehicleById,
|
|
16025
|
+
bulkUpsertVehicles
|
|
15894
16026
|
};
|
|
15895
16027
|
}
|
|
15896
16028
|
|
|
@@ -16164,8 +16296,8 @@ function useDahuaService() {
|
|
|
16164
16296
|
const utcMs = Number(UTCMs) || Date.now() % 1e3;
|
|
16165
16297
|
const timeData = createFileNameFromEvent(utcSec, utcMs);
|
|
16166
16298
|
const filename = plateNumber ? `${gate}-${timeData}-${plateNumber}.jpeg` : `${gate}-${timeData}.jpeg`;
|
|
16167
|
-
const snapFolder =
|
|
16168
|
-
const dir =
|
|
16299
|
+
const snapFolder = path2.join(__dirname, `../snap/${site}/${filename}`);
|
|
16300
|
+
const dir = path2.dirname(snapFolder);
|
|
16169
16301
|
try {
|
|
16170
16302
|
await fsAsync.mkdir(dir, { recursive: true });
|
|
16171
16303
|
await fsAsync.writeFile(snapFolder, accumulatedImageBuffer);
|
|
@@ -16437,13 +16569,53 @@ function useDahuaService() {
|
|
|
16437
16569
|
throw error2;
|
|
16438
16570
|
}
|
|
16439
16571
|
}
|
|
16572
|
+
async function bulkInsertPlateNumber(value) {
|
|
16573
|
+
const validation = Joi39.object({
|
|
16574
|
+
host: Joi39.string().required(),
|
|
16575
|
+
username: Joi39.string().required(),
|
|
16576
|
+
password: Joi39.string().required(),
|
|
16577
|
+
plateNumber: Joi39.string().required(),
|
|
16578
|
+
mode: Joi39.string().valid(...Object.values(ANPRMode)).required(),
|
|
16579
|
+
start: Joi39.string().isoDate().optional().allow("", null),
|
|
16580
|
+
end: Joi39.string().isoDate().optional().allow("", null),
|
|
16581
|
+
owner: Joi39.string().optional().allow("", null),
|
|
16582
|
+
isOpenGate: Joi39.boolean().optional().allow(null),
|
|
16583
|
+
vehicleType: Joi39.string().optional().allow("", null),
|
|
16584
|
+
vehicleColor: Joi39.string().optional().allow("", null)
|
|
16585
|
+
});
|
|
16586
|
+
const { error } = validation.validate(value);
|
|
16587
|
+
if (error) {
|
|
16588
|
+
throw new BadRequestError71(`Validation error: ${error.message}`);
|
|
16589
|
+
}
|
|
16590
|
+
value.owner = String(value.owner ?? "").substring(0, 15) || "unknown";
|
|
16591
|
+
value.vehicleType = String(value.vehicleType ?? "").substring(0, 31) || "unknown";
|
|
16592
|
+
value.vehicleColor = String(value.vehicleColor ?? "").substring(0, 31) || "unknown";
|
|
16593
|
+
const _openGate = String(value.isOpenGate);
|
|
16594
|
+
const isOpenGateString = _openGate && _openGate !== "undefined" ? _openGate : "true";
|
|
16595
|
+
const endpoint = `/cgi-bin/recordUpdater.cgi?action=insert&name=${value.mode}&PlateNumber=${value.plateNumber}&VehicleType=${value.vehicleType}&VehicleColor=${value.vehicleColor}&BeginTime=${value.start}&CancelTime=${value.end}&+OpenGate=${isOpenGateString}&MasterOfCar=${value.owner}`;
|
|
16596
|
+
try {
|
|
16597
|
+
const response = await useDahuaDigest({
|
|
16598
|
+
host: value.host,
|
|
16599
|
+
username: value.username,
|
|
16600
|
+
password: value.password,
|
|
16601
|
+
endpoint
|
|
16602
|
+
});
|
|
16603
|
+
return response;
|
|
16604
|
+
} catch (error2) {
|
|
16605
|
+
logger52.error(`[${value.host}] Error bulk add plate number:`, error2);
|
|
16606
|
+
throw new BadRequestError71(
|
|
16607
|
+
`Failed bulk adding plate number: ${error2.message}`
|
|
16608
|
+
);
|
|
16609
|
+
}
|
|
16610
|
+
}
|
|
16440
16611
|
return {
|
|
16441
16612
|
getSnapshot,
|
|
16442
16613
|
getTrafficJunction,
|
|
16443
16614
|
addPlateNumber,
|
|
16444
16615
|
removePlateNumber,
|
|
16445
16616
|
updatePlateNumber,
|
|
16446
|
-
getPlateNumber
|
|
16617
|
+
getPlateNumber,
|
|
16618
|
+
bulkInsertPlateNumber
|
|
16447
16619
|
};
|
|
16448
16620
|
}
|
|
16449
16621
|
|
|
@@ -18600,13 +18772,18 @@ function useBuildingUnitController() {
|
|
|
18600
18772
|
// src/controllers/vehicle.controller.ts
|
|
18601
18773
|
import { BadRequestError as BadRequestError83, logger as logger65 } from "@7365admin1/node-server-utils";
|
|
18602
18774
|
import Joi46 from "joi";
|
|
18775
|
+
import ExcelJS from "exceljs";
|
|
18776
|
+
import { Readable } from "stream";
|
|
18777
|
+
import csv from "csv-parser";
|
|
18778
|
+
import fs from "fs";
|
|
18603
18779
|
function useVehicleController() {
|
|
18604
18780
|
const {
|
|
18605
18781
|
add: _add,
|
|
18606
18782
|
deleteVehicle: _deleteVehicle,
|
|
18607
18783
|
approveVehicleById: _approveVehicleById,
|
|
18608
18784
|
reactivateVehicleById: _reactivateVehicleById,
|
|
18609
|
-
updateVehicleById: _updateVehicleById
|
|
18785
|
+
updateVehicleById: _updateVehicleById,
|
|
18786
|
+
bulkUpsertVehicles: _bulkUpsertVehicles
|
|
18610
18787
|
} = useVehicleService();
|
|
18611
18788
|
const {
|
|
18612
18789
|
getSeasonPassTypes: _getSeasonPassTypes,
|
|
@@ -18615,6 +18792,183 @@ function useVehicleController() {
|
|
|
18615
18792
|
getVehiclesByNRIC: _getVehiclesByNRIC,
|
|
18616
18793
|
getAllVehiclesByUnitId: _getAllVehiclesByUnitId
|
|
18617
18794
|
} = useVehicleRepo();
|
|
18795
|
+
function normalizeRow(row) {
|
|
18796
|
+
return Object.fromEntries(
|
|
18797
|
+
Object.entries(row).map(([key, value]) => [
|
|
18798
|
+
key,
|
|
18799
|
+
typeof value === "string" ? value.trim() : value
|
|
18800
|
+
])
|
|
18801
|
+
);
|
|
18802
|
+
}
|
|
18803
|
+
function mapRowToVehicle(row) {
|
|
18804
|
+
const cleanRow = normalizeRow(row);
|
|
18805
|
+
return {
|
|
18806
|
+
name: cleanRow.fullName,
|
|
18807
|
+
category: cleanRow.userType,
|
|
18808
|
+
type: cleanRow.recordType,
|
|
18809
|
+
phoneNumber: cleanRow.phoneNumber || "",
|
|
18810
|
+
block: Number(cleanRow.block),
|
|
18811
|
+
level: String(cleanRow.level || ""),
|
|
18812
|
+
unitName: String(cleanRow.unit || ""),
|
|
18813
|
+
plateNumber: String(cleanRow.plateNumber || "").toUpperCase(),
|
|
18814
|
+
remarks: `Model: ${cleanRow.vehicleModel || ""}, Color: ${cleanRow.vehicleColor || ""}`,
|
|
18815
|
+
org: cleanRow.org,
|
|
18816
|
+
site: cleanRow.site,
|
|
18817
|
+
end: parseExpiryDate(cleanRow.subscriptionExpiry)
|
|
18818
|
+
};
|
|
18819
|
+
}
|
|
18820
|
+
function parseExpiryDate(value) {
|
|
18821
|
+
if (!value)
|
|
18822
|
+
return void 0;
|
|
18823
|
+
const [day, monthStr, yearShort] = value.split("-");
|
|
18824
|
+
const months = {
|
|
18825
|
+
Jan: 0,
|
|
18826
|
+
Feb: 1,
|
|
18827
|
+
Mar: 2,
|
|
18828
|
+
Apr: 3,
|
|
18829
|
+
May: 4,
|
|
18830
|
+
Jun: 5,
|
|
18831
|
+
Jul: 6,
|
|
18832
|
+
Aug: 7,
|
|
18833
|
+
Sep: 8,
|
|
18834
|
+
Oct: 9,
|
|
18835
|
+
Nov: 10,
|
|
18836
|
+
Dec: 11
|
|
18837
|
+
};
|
|
18838
|
+
const month = months[monthStr];
|
|
18839
|
+
if (month === void 0)
|
|
18840
|
+
return void 0;
|
|
18841
|
+
const year = 2e3 + Number(yearShort);
|
|
18842
|
+
const date = new Date(year, month, Number(day));
|
|
18843
|
+
return isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
18844
|
+
}
|
|
18845
|
+
async function uploadCsvVehicles(req, res, next) {
|
|
18846
|
+
try {
|
|
18847
|
+
if (!req.file) {
|
|
18848
|
+
next(new BadRequestError83("CSV file is required."));
|
|
18849
|
+
return;
|
|
18850
|
+
}
|
|
18851
|
+
if (!req.file.originalname.toLowerCase().endsWith(".csv")) {
|
|
18852
|
+
next(new BadRequestError83("Only .csv files are allowed."));
|
|
18853
|
+
return;
|
|
18854
|
+
}
|
|
18855
|
+
const rows = [];
|
|
18856
|
+
const stream = Readable.from(req.file.buffer);
|
|
18857
|
+
stream.pipe(csv()).on("data", (row) => {
|
|
18858
|
+
rows.push(row);
|
|
18859
|
+
}).on("end", async () => {
|
|
18860
|
+
try {
|
|
18861
|
+
const vehicles = rows.map(mapRowToVehicle);
|
|
18862
|
+
const data = await _bulkUpsertVehicles(vehicles);
|
|
18863
|
+
res.status(200).json({
|
|
18864
|
+
message: "CSV import completed.",
|
|
18865
|
+
count: rows.length,
|
|
18866
|
+
data
|
|
18867
|
+
});
|
|
18868
|
+
} catch (error) {
|
|
18869
|
+
logger65.log({ level: "error", message: error.message });
|
|
18870
|
+
next(error);
|
|
18871
|
+
}
|
|
18872
|
+
}).on("error", (error) => {
|
|
18873
|
+
logger65.log({ level: "error", message: error.message });
|
|
18874
|
+
next(error);
|
|
18875
|
+
});
|
|
18876
|
+
} catch (error) {
|
|
18877
|
+
logger65.log({ level: "error", message: error.message });
|
|
18878
|
+
next(error);
|
|
18879
|
+
}
|
|
18880
|
+
}
|
|
18881
|
+
async function uploadExcelVehicles(req, res, next) {
|
|
18882
|
+
try {
|
|
18883
|
+
if (!req.file) {
|
|
18884
|
+
next(new BadRequestError83("Excel file is required."));
|
|
18885
|
+
return;
|
|
18886
|
+
}
|
|
18887
|
+
if (!req.file.originalname.toLowerCase().endsWith(".xlsx")) {
|
|
18888
|
+
next(new BadRequestError83("Only .xlsx files are allowed."));
|
|
18889
|
+
return;
|
|
18890
|
+
}
|
|
18891
|
+
const schema2 = Joi46.object({
|
|
18892
|
+
fullName: Joi46.string().trim().required(),
|
|
18893
|
+
userType: Joi46.string().trim().required(),
|
|
18894
|
+
recordType: Joi46.string().trim().required(),
|
|
18895
|
+
phoneNumber: Joi46.string().trim().allow("", null).optional(),
|
|
18896
|
+
block: Joi46.number().required(),
|
|
18897
|
+
level: Joi46.number().integer().min(1).required(),
|
|
18898
|
+
unit: Joi46.number().integer().min(1).required(),
|
|
18899
|
+
plateNumber: Joi46.string().trim().uppercase().required(),
|
|
18900
|
+
vehicleModel: Joi46.string().trim().allow("", null).optional(),
|
|
18901
|
+
vehicleColor: Joi46.string().trim().allow("", null).optional(),
|
|
18902
|
+
subscriptionExpiry: Joi46.string().trim().allow("", null).optional(),
|
|
18903
|
+
site: Joi46.string().hex().length(24).required(),
|
|
18904
|
+
org: Joi46.string().hex().length(24).required()
|
|
18905
|
+
});
|
|
18906
|
+
const workbook = new ExcelJS.Workbook();
|
|
18907
|
+
await workbook.xlsx.readFile(req.file.path);
|
|
18908
|
+
const worksheet = workbook.worksheets[0];
|
|
18909
|
+
if (!worksheet) {
|
|
18910
|
+
next(new BadRequestError83("No worksheet found in uploaded Excel file."));
|
|
18911
|
+
return;
|
|
18912
|
+
}
|
|
18913
|
+
const rows = [];
|
|
18914
|
+
const headerRow = worksheet.getRow(1);
|
|
18915
|
+
const headers = (headerRow.values || []).slice(1).map((header) => String(header ?? "").trim());
|
|
18916
|
+
worksheet.eachRow((row, rowNumber) => {
|
|
18917
|
+
if (rowNumber === 1)
|
|
18918
|
+
return;
|
|
18919
|
+
const rowData = {};
|
|
18920
|
+
headers.forEach((header, index) => {
|
|
18921
|
+
rowData[header] = row.getCell(index + 1).value ?? "";
|
|
18922
|
+
});
|
|
18923
|
+
const hasValue = Object.values(rowData).some(
|
|
18924
|
+
(value) => value !== null && value !== void 0 && value !== ""
|
|
18925
|
+
);
|
|
18926
|
+
if (hasValue) {
|
|
18927
|
+
rows.push(rowData);
|
|
18928
|
+
}
|
|
18929
|
+
});
|
|
18930
|
+
const validRows = [];
|
|
18931
|
+
const invalidRows = [];
|
|
18932
|
+
rows.forEach((row, index) => {
|
|
18933
|
+
const { error, value } = schema2.validate(row, {
|
|
18934
|
+
abortEarly: false,
|
|
18935
|
+
convert: true
|
|
18936
|
+
});
|
|
18937
|
+
if (error) {
|
|
18938
|
+
invalidRows.push({
|
|
18939
|
+
row: index + 2,
|
|
18940
|
+
data: row,
|
|
18941
|
+
errors: error.details.map((d) => d.message)
|
|
18942
|
+
});
|
|
18943
|
+
return;
|
|
18944
|
+
}
|
|
18945
|
+
validRows.push(value);
|
|
18946
|
+
});
|
|
18947
|
+
const vehicles = validRows.map(mapRowToVehicle);
|
|
18948
|
+
let data = {
|
|
18949
|
+
matchedCount: 0,
|
|
18950
|
+
modifiedCount: 0,
|
|
18951
|
+
upsertedCount: 0
|
|
18952
|
+
};
|
|
18953
|
+
if (vehicles.length > 0) {
|
|
18954
|
+
data = await _bulkUpsertVehicles(vehicles);
|
|
18955
|
+
}
|
|
18956
|
+
res.status(200).json({
|
|
18957
|
+
message: "Excel import completed.",
|
|
18958
|
+
sheetName: worksheet.name,
|
|
18959
|
+
totalRows: rows.length,
|
|
18960
|
+
validRows: validRows.length,
|
|
18961
|
+
invalidRows: invalidRows.length,
|
|
18962
|
+
validationErrors: invalidRows,
|
|
18963
|
+
data
|
|
18964
|
+
});
|
|
18965
|
+
fs.unlink(req.file.path, () => {
|
|
18966
|
+
});
|
|
18967
|
+
} catch (error) {
|
|
18968
|
+
logger65.log({ level: "error", message: error.message });
|
|
18969
|
+
next(error);
|
|
18970
|
+
}
|
|
18971
|
+
}
|
|
18618
18972
|
async function add(req, res, next) {
|
|
18619
18973
|
const { error, value } = vehicleSchema.validate(req.body, {
|
|
18620
18974
|
abortEarly: false
|
|
@@ -18949,7 +19303,9 @@ function useVehicleController() {
|
|
|
18949
19303
|
approveVehicleById,
|
|
18950
19304
|
getVehiclesByNRIC,
|
|
18951
19305
|
reactivateVehicleById,
|
|
18952
|
-
getAllVehiclesByUnitId
|
|
19306
|
+
getAllVehiclesByUnitId,
|
|
19307
|
+
uploadCsvVehicles,
|
|
19308
|
+
uploadExcelVehicles
|
|
18953
19309
|
};
|
|
18954
19310
|
}
|
|
18955
19311
|
|
|
@@ -19722,21 +20078,6 @@ function useCustomerSiteController() {
|
|
|
19722
20078
|
import { BadRequestError as BadRequestError89, logger as logger69 } from "@7365admin1/node-server-utils";
|
|
19723
20079
|
import Joi51 from "joi";
|
|
19724
20080
|
import { ObjectId as ObjectId51 } from "mongodb";
|
|
19725
|
-
|
|
19726
|
-
// src/models/base.model.ts
|
|
19727
|
-
var AppServiceType = /* @__PURE__ */ ((AppServiceType2) => {
|
|
19728
|
-
AppServiceType2["REAL_ESTATE_DEVELOPER"] = "real_estate_developer";
|
|
19729
|
-
AppServiceType2["PROPERTY_MANAGEMENT_AGENCY"] = "property_management_agency";
|
|
19730
|
-
AppServiceType2["SECURITY_AGENCY"] = "security_agency";
|
|
19731
|
-
AppServiceType2["CLEANING_SERVICES"] = "cleaning_services";
|
|
19732
|
-
AppServiceType2["MECHANICAL_ELECTRICAL_SERVICES"] = "mechanical_electrical_services";
|
|
19733
|
-
AppServiceType2["LANDSCAPING_SERVICES"] = "landscaping_services";
|
|
19734
|
-
AppServiceType2["PEST_CONTROL_SERVICES"] = "pest_control_services";
|
|
19735
|
-
AppServiceType2["POOL_MAINTENANCE_SERVICES"] = "pool_maintenance_services";
|
|
19736
|
-
return AppServiceType2;
|
|
19737
|
-
})(AppServiceType || {});
|
|
19738
|
-
|
|
19739
|
-
// src/models/attendance-settings.model.ts
|
|
19740
20081
|
var attendanceSettingsSchema = Joi51.object({
|
|
19741
20082
|
site: Joi51.string().hex().required(),
|
|
19742
20083
|
serviceType: Joi51.string().valid(...Object.values(AppServiceType)).required(),
|
|
@@ -22198,7 +22539,7 @@ function useVisitorTransactionService() {
|
|
|
22198
22539
|
org: inviter?.org.toString(),
|
|
22199
22540
|
site: inviter?.site.toString(),
|
|
22200
22541
|
status: "approved" /* APPROVED */,
|
|
22201
|
-
|
|
22542
|
+
inviterId: userId
|
|
22202
22543
|
};
|
|
22203
22544
|
const result = await _add(payload);
|
|
22204
22545
|
const emailContent = compileHandlebar2({
|
|
@@ -22349,7 +22690,8 @@ function useVisitorTransactionController() {
|
|
|
22349
22690
|
}).optional().allow(null, ""),
|
|
22350
22691
|
checkedOut: Joi55.boolean().allow(null, ""),
|
|
22351
22692
|
plateNumber: Joi55.string().optional().allow(null, ""),
|
|
22352
|
-
order: Joi55.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */)
|
|
22693
|
+
order: Joi55.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */),
|
|
22694
|
+
tab: Joi55.string().optional().allow(null, "")
|
|
22353
22695
|
});
|
|
22354
22696
|
const { error, value } = validation.validate(req.query, {
|
|
22355
22697
|
abortEarly: false
|
|
@@ -22373,7 +22715,8 @@ function useVisitorTransactionController() {
|
|
|
22373
22715
|
checkedOut,
|
|
22374
22716
|
sort,
|
|
22375
22717
|
order,
|
|
22376
|
-
plateNumber
|
|
22718
|
+
plateNumber,
|
|
22719
|
+
tab
|
|
22377
22720
|
} = value;
|
|
22378
22721
|
const sortObj = {
|
|
22379
22722
|
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
@@ -22390,7 +22733,8 @@ function useVisitorTransactionController() {
|
|
|
22390
22733
|
dateFrom,
|
|
22391
22734
|
type,
|
|
22392
22735
|
checkedOut,
|
|
22393
|
-
plateNumber
|
|
22736
|
+
plateNumber,
|
|
22737
|
+
tab
|
|
22394
22738
|
});
|
|
22395
22739
|
res.status(200).json(data);
|
|
22396
22740
|
return;
|
|
@@ -29729,7 +30073,7 @@ function useSiteBillingItemService() {
|
|
|
29729
30073
|
}
|
|
29730
30074
|
try {
|
|
29731
30075
|
await session.startTransaction();
|
|
29732
|
-
const billing_item = await _getBillingItemById(id
|
|
30076
|
+
const billing_item = await _getBillingItemById(id);
|
|
29733
30077
|
if (!billing_item) {
|
|
29734
30078
|
throw new BadRequestError131("Billing item not found.");
|
|
29735
30079
|
}
|
|
@@ -30749,10 +31093,32 @@ function useEventManagementController() {
|
|
|
30749
31093
|
import { BadRequestError as BadRequestError137, logger as logger116 } from "@7365admin1/node-server-utils";
|
|
30750
31094
|
import { ObjectId as ObjectId85 } from "mongodb";
|
|
30751
31095
|
import Joi83 from "joi";
|
|
31096
|
+
var Status = /* @__PURE__ */ ((Status3) => {
|
|
31097
|
+
Status3["PENDING"] = "pending";
|
|
31098
|
+
Status3["COMPLETED"] = "completed";
|
|
31099
|
+
Status3["APPROVED"] = "approved";
|
|
31100
|
+
Status3["REJECTED"] = "rejected";
|
|
31101
|
+
Status3["CANCELLED"] = "cancelled";
|
|
31102
|
+
Status3["RECURRING"] = "recurring";
|
|
31103
|
+
Status3["NONRECURRING"] = "non-recurring";
|
|
31104
|
+
Status3["ACTIVE"] = "active";
|
|
31105
|
+
Status3["INACTIVE"] = "inactive";
|
|
31106
|
+
return Status3;
|
|
31107
|
+
})(Status || {});
|
|
31108
|
+
var PStatus = /* @__PURE__ */ ((PStatus2) => {
|
|
31109
|
+
PStatus2["PROCESSING"] = "processing";
|
|
31110
|
+
PStatus2["UNPAID"] = "unpaid";
|
|
31111
|
+
PStatus2["PAID"] = "paid";
|
|
31112
|
+
PStatus2["OVERDUE"] = "overdue";
|
|
31113
|
+
PStatus2["PARTIAL"] = "partial-payment";
|
|
31114
|
+
PStatus2["AWAITING_PAYMENT"] = "awaiting-payment";
|
|
31115
|
+
PStatus2["FAILED"] = "failed";
|
|
31116
|
+
return PStatus2;
|
|
31117
|
+
})(PStatus || {});
|
|
30752
31118
|
var schemaUnitBilling = Joi83.object({
|
|
30753
31119
|
_id: Joi83.string().hex().optional(),
|
|
30754
|
-
site: Joi83.string().hex().
|
|
30755
|
-
org: Joi83.string().hex().
|
|
31120
|
+
site: Joi83.string().hex().optional().allow(null, ""),
|
|
31121
|
+
org: Joi83.string().hex().optional().allow(null, ""),
|
|
30756
31122
|
billItem: Joi83.string().hex().optional().allow(null, ""),
|
|
30757
31123
|
billName: Joi83.string().optional().allow(null, ""),
|
|
30758
31124
|
unitId: Joi83.string().hex().optional().allow(null, ""),
|
|
@@ -30772,6 +31138,7 @@ var schemaUnitBilling = Joi83.object({
|
|
|
30772
31138
|
paymentStatus: Joi83.string().optional().allow(null, ""),
|
|
30773
31139
|
status: Joi83.string().optional().allow(null, ""),
|
|
30774
31140
|
amountPaid: Joi83.number().optional().allow(null, ""),
|
|
31141
|
+
balanceAmount: Joi83.number().optional().allow(null, ""),
|
|
30775
31142
|
paidBy: Joi83.string().hex().optional().allow(null, ""),
|
|
30776
31143
|
datePaid: Joi83.date().optional().allow(null, ""),
|
|
30777
31144
|
transaction_id: Joi83.string().optional().allow(null, ""),
|
|
@@ -30795,6 +31162,7 @@ var schemaUpdateSiteUnitBilling = Joi83.object({
|
|
|
30795
31162
|
category: Joi83.string().optional().allow(null, ""),
|
|
30796
31163
|
frequency: Joi83.string().optional().allow(null, ""),
|
|
30797
31164
|
totalAmount: Joi83.number().optional().allow(null, ""),
|
|
31165
|
+
balanceAmount: Joi83.number().optional().allow(null, ""),
|
|
30798
31166
|
taxPercentage: Joi83.number().optional().allow(null, ""),
|
|
30799
31167
|
taxAmount: Joi83.number().optional().allow(null, ""),
|
|
30800
31168
|
amount: Joi83.number().optional().allow(null, ""),
|
|
@@ -30860,8 +31228,8 @@ function MUnitBilling(value) {
|
|
|
30860
31228
|
}
|
|
30861
31229
|
return {
|
|
30862
31230
|
_id: value._id ?? new ObjectId85(),
|
|
30863
|
-
site: value.site,
|
|
30864
|
-
org: value.org,
|
|
31231
|
+
site: value.site ?? "",
|
|
31232
|
+
org: value.org ?? "",
|
|
30865
31233
|
billItem: value.billItem ?? "",
|
|
30866
31234
|
billName: value.billName ?? "",
|
|
30867
31235
|
unitId: value.unitId ?? "",
|
|
@@ -30881,6 +31249,7 @@ function MUnitBilling(value) {
|
|
|
30881
31249
|
paymentStatus: value.paymentStatus ?? "",
|
|
30882
31250
|
status: value.status ?? "active",
|
|
30883
31251
|
amountPaid: value.amountPaid ?? 0,
|
|
31252
|
+
balanceAmount: value.balanceAmount ?? 0,
|
|
30884
31253
|
paidBy: value.paidBy ?? "",
|
|
30885
31254
|
datePaid: value.datePaid ?? "",
|
|
30886
31255
|
transaction_id: value.transaction_id ?? "",
|
|
@@ -30933,7 +31302,7 @@ function useSiteUnitBillingRepo() {
|
|
|
30933
31302
|
value = MUnitBilling(value);
|
|
30934
31303
|
const res = await collection.insertOne(value, { session });
|
|
30935
31304
|
const acronym = createAcronym(value.billName || "NA");
|
|
30936
|
-
const dateFormatted =
|
|
31305
|
+
const dateFormatted = formatDateString(/* @__PURE__ */ new Date());
|
|
30937
31306
|
const newId = new ObjectId86(res.insertedId).toString().slice(-6);
|
|
30938
31307
|
const referenceNumber = `${acronym}${newId}${dateFormatted}`;
|
|
30939
31308
|
await collection.updateOne(
|
|
@@ -31343,6 +31712,95 @@ function useSiteUnitBillingRepo() {
|
|
|
31343
31712
|
throw error;
|
|
31344
31713
|
}
|
|
31345
31714
|
}
|
|
31715
|
+
async function getResidentUserUnsettledBilling({
|
|
31716
|
+
search = "",
|
|
31717
|
+
page = 1,
|
|
31718
|
+
limit = 10,
|
|
31719
|
+
sort = {},
|
|
31720
|
+
status = "active",
|
|
31721
|
+
site = "",
|
|
31722
|
+
paymentStatus = "all",
|
|
31723
|
+
month,
|
|
31724
|
+
year,
|
|
31725
|
+
unitId
|
|
31726
|
+
}, session) {
|
|
31727
|
+
page = page > 0 ? page - 1 : 0;
|
|
31728
|
+
let dateExpr = {};
|
|
31729
|
+
if (month && year) {
|
|
31730
|
+
const monthNum = parseInt(month, 10);
|
|
31731
|
+
const yearNum = parseInt(year, 10);
|
|
31732
|
+
const startDate = new Date(yearNum, monthNum - 1, 1);
|
|
31733
|
+
const endDate = new Date(yearNum, monthNum, 1);
|
|
31734
|
+
dateExpr.createdAt = {
|
|
31735
|
+
$gte: startDate,
|
|
31736
|
+
$lt: endDate
|
|
31737
|
+
};
|
|
31738
|
+
}
|
|
31739
|
+
const unitSearchRegex = search ? search.trim().replace(/\s+/g, "").replace(/\//g, "\\s*/\\s*") : null;
|
|
31740
|
+
const query = {
|
|
31741
|
+
...paymentStatus === "all" ? { paymentStatus: { $in: ["failed", "overdue"] } } : { paymentStatus },
|
|
31742
|
+
status,
|
|
31743
|
+
...search && {
|
|
31744
|
+
$or: [
|
|
31745
|
+
{ unitOwner: { $regex: search, $options: "i" } },
|
|
31746
|
+
{ billName: { $regex: search, $options: "i" } },
|
|
31747
|
+
{ unit: { $regex: unitSearchRegex, $options: "i" } },
|
|
31748
|
+
{
|
|
31749
|
+
$expr: {
|
|
31750
|
+
$regexMatch: {
|
|
31751
|
+
input: { $toString: "$amountPaid" },
|
|
31752
|
+
regex: search,
|
|
31753
|
+
options: "i"
|
|
31754
|
+
}
|
|
31755
|
+
}
|
|
31756
|
+
}
|
|
31757
|
+
]
|
|
31758
|
+
},
|
|
31759
|
+
...ObjectId86.isValid(site) && { site: new ObjectId86(site) },
|
|
31760
|
+
...dateExpr,
|
|
31761
|
+
...ObjectId86.isValid(unitId) && { unitId: new ObjectId86(unitId) }
|
|
31762
|
+
};
|
|
31763
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
31764
|
+
try {
|
|
31765
|
+
const basePipeline = [
|
|
31766
|
+
{ $match: query },
|
|
31767
|
+
{ $sort: sort },
|
|
31768
|
+
{ $skip: page * limit },
|
|
31769
|
+
{ $limit: limit },
|
|
31770
|
+
{
|
|
31771
|
+
$lookup: {
|
|
31772
|
+
from: "site.billing.items",
|
|
31773
|
+
localField: "billItem",
|
|
31774
|
+
foreignField: "_id",
|
|
31775
|
+
pipeline: [
|
|
31776
|
+
{
|
|
31777
|
+
$project: {
|
|
31778
|
+
_id: 1,
|
|
31779
|
+
totalAmount: 1
|
|
31780
|
+
}
|
|
31781
|
+
}
|
|
31782
|
+
],
|
|
31783
|
+
as: "billDetails"
|
|
31784
|
+
}
|
|
31785
|
+
},
|
|
31786
|
+
{
|
|
31787
|
+
$unwind: {
|
|
31788
|
+
path: "$billDetails",
|
|
31789
|
+
preserveNullAndEmptyArrays: true
|
|
31790
|
+
}
|
|
31791
|
+
}
|
|
31792
|
+
];
|
|
31793
|
+
const [items, countResult] = await Promise.all([
|
|
31794
|
+
collection.aggregate(basePipeline, { session }).toArray(),
|
|
31795
|
+
collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
31796
|
+
]);
|
|
31797
|
+
const totalCount = countResult[0]?.total || 0;
|
|
31798
|
+
const data = paginate37(items, page, limit, totalCount);
|
|
31799
|
+
return data;
|
|
31800
|
+
} catch (error) {
|
|
31801
|
+
throw error;
|
|
31802
|
+
}
|
|
31803
|
+
}
|
|
31346
31804
|
function delCachedData() {
|
|
31347
31805
|
delNamespace().then(() => {
|
|
31348
31806
|
logger117.log({
|
|
@@ -31359,7 +31817,7 @@ function useSiteUnitBillingRepo() {
|
|
|
31359
31817
|
function createAcronym(billName) {
|
|
31360
31818
|
return billName.split(" ").map((word) => word.charAt(0).toUpperCase()).join("");
|
|
31361
31819
|
}
|
|
31362
|
-
function
|
|
31820
|
+
function formatDateString(today) {
|
|
31363
31821
|
today = typeof today === "string" ? new Date(today) : today;
|
|
31364
31822
|
let month = today.getMonth() + 1;
|
|
31365
31823
|
let day = today.getDate();
|
|
@@ -31375,7 +31833,8 @@ function useSiteUnitBillingRepo() {
|
|
|
31375
31833
|
updateById,
|
|
31376
31834
|
deleteById,
|
|
31377
31835
|
getUnitBillingBySite,
|
|
31378
|
-
getResidentUserBilling
|
|
31836
|
+
getResidentUserBilling,
|
|
31837
|
+
getResidentUserUnsettledBilling
|
|
31379
31838
|
};
|
|
31380
31839
|
}
|
|
31381
31840
|
|
|
@@ -31567,7 +32026,8 @@ function useSiteUnitBillingController() {
|
|
|
31567
32026
|
updateById: _updateById,
|
|
31568
32027
|
deleteById: _deleteById,
|
|
31569
32028
|
getById: _getById,
|
|
31570
|
-
getResidentUserBilling: _getResidentUserBilling
|
|
32029
|
+
getResidentUserBilling: _getResidentUserBilling,
|
|
32030
|
+
getResidentUserUnsettledBilling: _getResidentUserUnsettledBilling
|
|
31571
32031
|
} = useSiteUnitBillingRepo();
|
|
31572
32032
|
async function add(req, res, next) {
|
|
31573
32033
|
const data = { ...req.body };
|
|
@@ -31759,13 +32219,65 @@ function useSiteUnitBillingController() {
|
|
|
31759
32219
|
return;
|
|
31760
32220
|
}
|
|
31761
32221
|
}
|
|
32222
|
+
async function getResidentUserUnsettledBilling(req, res, next) {
|
|
32223
|
+
const validation = Joi84.object({
|
|
32224
|
+
page: Joi84.number().integer().min(1).allow("", null).default(1),
|
|
32225
|
+
limit: Joi84.number().integer().min(1).max(100).allow("", null).default(10),
|
|
32226
|
+
status: Joi84.string().optional().allow(null, ""),
|
|
32227
|
+
search: Joi84.string().optional().allow(null, ""),
|
|
32228
|
+
site: Joi84.string().required(),
|
|
32229
|
+
paymentStatus: Joi84.string().optional().allow(null, ""),
|
|
32230
|
+
month: Joi84.string().optional().allow(null, ""),
|
|
32231
|
+
year: Joi84.string().optional().allow(null, ""),
|
|
32232
|
+
unitId: Joi84.string().optional().allow(null, "")
|
|
32233
|
+
});
|
|
32234
|
+
const query = { ...req.query };
|
|
32235
|
+
const { error } = validation.validate(query, {
|
|
32236
|
+
abortEarly: false
|
|
32237
|
+
});
|
|
32238
|
+
if (error) {
|
|
32239
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
32240
|
+
logger119.log({ level: "error", message: messages });
|
|
32241
|
+
next(new BadRequestError140(messages));
|
|
32242
|
+
return;
|
|
32243
|
+
}
|
|
32244
|
+
const search = req.query.search ?? "";
|
|
32245
|
+
const page = parseInt(req.query.page ?? "1");
|
|
32246
|
+
const limit = parseInt(req.query.limit ?? "10");
|
|
32247
|
+
const status = req.query.status ?? "active";
|
|
32248
|
+
const site = req.query.site;
|
|
32249
|
+
const paymentStatus = req.query.paymentStatus ?? "awaiting_payment";
|
|
32250
|
+
const month = req.query.month ?? "";
|
|
32251
|
+
const year = req.query.year ?? "";
|
|
32252
|
+
const unitId = req.query.unitId ?? "";
|
|
32253
|
+
try {
|
|
32254
|
+
const data = await _getResidentUserUnsettledBilling({
|
|
32255
|
+
search,
|
|
32256
|
+
page,
|
|
32257
|
+
limit,
|
|
32258
|
+
status,
|
|
32259
|
+
site,
|
|
32260
|
+
paymentStatus,
|
|
32261
|
+
month,
|
|
32262
|
+
year,
|
|
32263
|
+
unitId
|
|
32264
|
+
});
|
|
32265
|
+
res.status(200).json(data);
|
|
32266
|
+
return;
|
|
32267
|
+
} catch (error2) {
|
|
32268
|
+
logger119.log({ level: "error", message: error2.message });
|
|
32269
|
+
next(error2);
|
|
32270
|
+
return;
|
|
32271
|
+
}
|
|
32272
|
+
}
|
|
31762
32273
|
return {
|
|
31763
32274
|
add,
|
|
31764
32275
|
getAll,
|
|
31765
32276
|
getById,
|
|
31766
32277
|
updateById,
|
|
31767
32278
|
deleteById,
|
|
31768
|
-
getResidentUserBilling
|
|
32279
|
+
getResidentUserBilling,
|
|
32280
|
+
getResidentUserUnsettledBilling
|
|
31769
32281
|
};
|
|
31770
32282
|
}
|
|
31771
32283
|
|
|
@@ -31884,8 +32396,8 @@ import {
|
|
|
31884
32396
|
import { ObjectId as ObjectId89 } from "mongodb";
|
|
31885
32397
|
|
|
31886
32398
|
// src/utils/access-management.ts
|
|
31887
|
-
import
|
|
31888
|
-
import
|
|
32399
|
+
import fs2 from "fs";
|
|
32400
|
+
import path3 from "path";
|
|
31889
32401
|
import axios from "axios";
|
|
31890
32402
|
import { parseStringPromise } from "xml2js";
|
|
31891
32403
|
import crypto from "crypto";
|
|
@@ -31914,8 +32426,8 @@ var minifyXml = (xml) => {
|
|
|
31914
32426
|
return xml.replace(/>\s+</g, "><").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").trim();
|
|
31915
32427
|
};
|
|
31916
32428
|
var readTemplate = (name, params) => {
|
|
31917
|
-
const template =
|
|
31918
|
-
|
|
32429
|
+
const template = fs2.readFileSync(
|
|
32430
|
+
path3.join(__dirname, `../src/public/xml-templates/${name}.xml`),
|
|
31919
32431
|
"utf-8"
|
|
31920
32432
|
);
|
|
31921
32433
|
if (!params)
|
|
@@ -32024,14 +32536,14 @@ import { parseStringPromise as parseStringPromise2 } from "xml2js";
|
|
|
32024
32536
|
|
|
32025
32537
|
// src/utils/rsa-encryption.ts
|
|
32026
32538
|
import * as crypto2 from "crypto";
|
|
32027
|
-
import
|
|
32028
|
-
import
|
|
32029
|
-
var pub =
|
|
32030
|
-
var priv =
|
|
32539
|
+
import fs3 from "fs";
|
|
32540
|
+
import path4 from "path";
|
|
32541
|
+
var pub = path4.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_pub.pem");
|
|
32542
|
+
var priv = path4.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_priv.pem");
|
|
32031
32543
|
var EncryptionCredentials = class {
|
|
32032
32544
|
};
|
|
32033
|
-
EncryptionCredentials.RAW_PUBLIC_KEY =
|
|
32034
|
-
EncryptionCredentials.RAW_PRIVATE_KEY =
|
|
32545
|
+
EncryptionCredentials.RAW_PUBLIC_KEY = fs3.readFileSync(pub, "utf8");
|
|
32546
|
+
EncryptionCredentials.RAW_PRIVATE_KEY = fs3.readFileSync(priv, "utf8");
|
|
32035
32547
|
var EntrypassRSAEncryption = class extends EncryptionCredentials {
|
|
32036
32548
|
static hexToCardNumber(hex) {
|
|
32037
32549
|
if (!/^[0-9A-Fa-f]{8}$/.test(hex)) {
|
|
@@ -33949,6 +34461,61 @@ function UseAccessManagementRepo() {
|
|
|
33949
34461
|
await session?.endSession();
|
|
33950
34462
|
}
|
|
33951
34463
|
}
|
|
34464
|
+
async function getBlockLevelAndUnitListRepo(params) {
|
|
34465
|
+
const site = new ObjectId89(params.site);
|
|
34466
|
+
try {
|
|
34467
|
+
const blocks = await collectionName("buildings").aggregate([
|
|
34468
|
+
{
|
|
34469
|
+
$match: {
|
|
34470
|
+
site,
|
|
34471
|
+
status: { $eq: "active" }
|
|
34472
|
+
}
|
|
34473
|
+
},
|
|
34474
|
+
{
|
|
34475
|
+
$project: {
|
|
34476
|
+
_id: 1,
|
|
34477
|
+
name: 1,
|
|
34478
|
+
block: 1
|
|
34479
|
+
}
|
|
34480
|
+
},
|
|
34481
|
+
{
|
|
34482
|
+
$lookup: {
|
|
34483
|
+
from: "building-levels",
|
|
34484
|
+
localField: "_id",
|
|
34485
|
+
foreignField: "block",
|
|
34486
|
+
as: "levels",
|
|
34487
|
+
pipeline: [
|
|
34488
|
+
{
|
|
34489
|
+
$match: { status: { $ne: "deleted" } }
|
|
34490
|
+
},
|
|
34491
|
+
{
|
|
34492
|
+
$lookup: {
|
|
34493
|
+
from: "building-units",
|
|
34494
|
+
localField: "_id",
|
|
34495
|
+
foreignField: "level",
|
|
34496
|
+
pipeline: [
|
|
34497
|
+
{ $match: { status: { $ne: "deleted" } } },
|
|
34498
|
+
{ $project: { _id: 1, name: 1, buildingName: 1, level: 1, block: 1 } }
|
|
34499
|
+
],
|
|
34500
|
+
as: "units"
|
|
34501
|
+
}
|
|
34502
|
+
},
|
|
34503
|
+
{
|
|
34504
|
+
$match: { "units.0": { $exists: true } }
|
|
34505
|
+
}
|
|
34506
|
+
]
|
|
34507
|
+
}
|
|
34508
|
+
},
|
|
34509
|
+
// ✅ Filter out buildings with no levels early
|
|
34510
|
+
{
|
|
34511
|
+
$match: { "levels.0": { $exists: true } }
|
|
34512
|
+
}
|
|
34513
|
+
]).toArray();
|
|
34514
|
+
return blocks;
|
|
34515
|
+
} catch (error) {
|
|
34516
|
+
throw new Error(error.message);
|
|
34517
|
+
}
|
|
34518
|
+
}
|
|
33952
34519
|
return {
|
|
33953
34520
|
createIndexes,
|
|
33954
34521
|
createIndexForEntrypass,
|
|
@@ -33978,7 +34545,8 @@ function UseAccessManagementRepo() {
|
|
|
33978
34545
|
vmsgenerateQrCodesRepo,
|
|
33979
34546
|
addVisitorAccessCardRepo,
|
|
33980
34547
|
signQrCodeRepo,
|
|
33981
|
-
checkoutVisitorRepo
|
|
34548
|
+
checkoutVisitorRepo,
|
|
34549
|
+
getBlockLevelAndUnitListRepo
|
|
33982
34550
|
};
|
|
33983
34551
|
}
|
|
33984
34552
|
|
|
@@ -33987,7 +34555,7 @@ import Joi85 from "joi";
|
|
|
33987
34555
|
|
|
33988
34556
|
// src/services/access-management.service.ts
|
|
33989
34557
|
import { parseStringPromise as parseStringPromise3 } from "xml2js";
|
|
33990
|
-
import { Readable } from "stream";
|
|
34558
|
+
import { Readable as Readable2 } from "stream";
|
|
33991
34559
|
import * as xlsx from "xlsx";
|
|
33992
34560
|
function useAccessManagementSvc() {
|
|
33993
34561
|
const {
|
|
@@ -34017,7 +34585,8 @@ function useAccessManagementSvc() {
|
|
|
34017
34585
|
vmsgenerateQrCodesRepo,
|
|
34018
34586
|
addVisitorAccessCardRepo,
|
|
34019
34587
|
signQrCodeRepo,
|
|
34020
|
-
checkoutVisitorRepo
|
|
34588
|
+
checkoutVisitorRepo,
|
|
34589
|
+
getBlockLevelAndUnitListRepo
|
|
34021
34590
|
} = UseAccessManagementRepo();
|
|
34022
34591
|
const addPhysicalCardSvc = async (payload) => {
|
|
34023
34592
|
try {
|
|
@@ -34192,7 +34761,7 @@ function useAccessManagementSvc() {
|
|
|
34192
34761
|
};
|
|
34193
34762
|
const convertBufferFile = async (bufferFile) => {
|
|
34194
34763
|
return new Promise((resolve, reject) => {
|
|
34195
|
-
const fileStream =
|
|
34764
|
+
const fileStream = Readable2.from(bufferFile);
|
|
34196
34765
|
let fileBuffer = Buffer.alloc(0);
|
|
34197
34766
|
fileStream.on("data", (chunk) => {
|
|
34198
34767
|
fileBuffer = Buffer.concat([fileBuffer, chunk]);
|
|
@@ -34301,6 +34870,14 @@ function useAccessManagementSvc() {
|
|
|
34301
34870
|
throw new Error(err.message);
|
|
34302
34871
|
}
|
|
34303
34872
|
};
|
|
34873
|
+
const getBlockLevelAndUnitListSvc = async (params) => {
|
|
34874
|
+
try {
|
|
34875
|
+
const response = await getBlockLevelAndUnitListRepo({ ...params });
|
|
34876
|
+
return response;
|
|
34877
|
+
} catch (err) {
|
|
34878
|
+
throw new Error(err.message);
|
|
34879
|
+
}
|
|
34880
|
+
};
|
|
34304
34881
|
return {
|
|
34305
34882
|
addPhysicalCardSvc,
|
|
34306
34883
|
addNonPhysicalCardSvc,
|
|
@@ -34334,7 +34911,8 @@ function useAccessManagementSvc() {
|
|
|
34334
34911
|
vmsgenerateQrCodesSvc,
|
|
34335
34912
|
addVisitorAccessCardSvc,
|
|
34336
34913
|
signQrCodeSvc,
|
|
34337
|
-
checkoutVisitorSvc
|
|
34914
|
+
checkoutVisitorSvc,
|
|
34915
|
+
getBlockLevelAndUnitListSvc
|
|
34338
34916
|
};
|
|
34339
34917
|
}
|
|
34340
34918
|
|
|
@@ -34373,7 +34951,8 @@ function useAccessManagementController() {
|
|
|
34373
34951
|
vmsgenerateQrCodesSvc,
|
|
34374
34952
|
addVisitorAccessCardSvc,
|
|
34375
34953
|
signQrCodeSvc,
|
|
34376
|
-
checkoutVisitorSvc
|
|
34954
|
+
checkoutVisitorSvc,
|
|
34955
|
+
getBlockLevelAndUnitListSvc
|
|
34377
34956
|
} = useAccessManagementSvc();
|
|
34378
34957
|
const addPhysicalCard = async (req, res) => {
|
|
34379
34958
|
try {
|
|
@@ -35120,6 +35699,21 @@ function useAccessManagementController() {
|
|
|
35120
35699
|
const removeAccessCard = async ({ cardNo, staffNo, url }) => {
|
|
35121
35700
|
return removeAccessGroup({ cardNo, staffNo, url });
|
|
35122
35701
|
};
|
|
35702
|
+
const getBlockLevelAndUnitList = async (req, res) => {
|
|
35703
|
+
try {
|
|
35704
|
+
const { site } = req.query;
|
|
35705
|
+
if (!site || typeof site !== "string") {
|
|
35706
|
+
throw new Error("Site is required");
|
|
35707
|
+
}
|
|
35708
|
+
const result = await getBlockLevelAndUnitListSvc({ site });
|
|
35709
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
35710
|
+
} catch (error) {
|
|
35711
|
+
return res.status(400).json({
|
|
35712
|
+
data: null,
|
|
35713
|
+
message: error.message
|
|
35714
|
+
});
|
|
35715
|
+
}
|
|
35716
|
+
};
|
|
35123
35717
|
return {
|
|
35124
35718
|
addPhysicalCard,
|
|
35125
35719
|
addNonPhysicalCard,
|
|
@@ -35151,7 +35745,8 @@ function useAccessManagementController() {
|
|
|
35151
35745
|
addVisitorAccessCard,
|
|
35152
35746
|
signQrCode,
|
|
35153
35747
|
checkoutVisitor,
|
|
35154
|
-
removeAccessCard
|
|
35748
|
+
removeAccessCard,
|
|
35749
|
+
getBlockLevelAndUnitList
|
|
35155
35750
|
};
|
|
35156
35751
|
}
|
|
35157
35752
|
|
|
@@ -46614,121 +47209,8 @@ function genericSignature(params, secretKey) {
|
|
|
46614
47209
|
}
|
|
46615
47210
|
|
|
46616
47211
|
// src/repositories/reddot-payment.repository.ts
|
|
46617
|
-
import {
|
|
46618
|
-
|
|
46619
|
-
// src/utils/date-format.util.ts
|
|
46620
|
-
import moment6 from "moment-timezone";
|
|
46621
|
-
function formatDateString(today, format, dateRange) {
|
|
46622
|
-
today = typeof today === "string" ? new Date(today) : today;
|
|
46623
|
-
let month = today.getMonth() + 1;
|
|
46624
|
-
let day = today.getDate();
|
|
46625
|
-
let year = today.getFullYear();
|
|
46626
|
-
let formattedDate;
|
|
46627
|
-
if (format === "mm-dd-yyyy") {
|
|
46628
|
-
formattedDate = `${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}-${year}`;
|
|
46629
|
-
} else if (format === "dd-mm-yyyy") {
|
|
46630
|
-
formattedDate = `${day.toString().padStart(2, "0")}-${month.toString().padStart(2, "0")}-${year}`;
|
|
46631
|
-
} else if (format === "for-ref") {
|
|
46632
|
-
formattedDate = `${month.toString().padStart(2, "0")}${day.toString().padStart(2, "0")}${year}`;
|
|
46633
|
-
} else if (format === "mm/dd/yyyy") {
|
|
46634
|
-
formattedDate = `${month.toString().padStart(2, "0")}/${day.toString().padStart(2, "0")}/${year}`;
|
|
46635
|
-
} else {
|
|
46636
|
-
formattedDate = `${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}`;
|
|
46637
|
-
}
|
|
46638
|
-
return formattedDate;
|
|
46639
|
-
}
|
|
46640
|
-
|
|
46641
|
-
// src/models/credit-card.model.ts
|
|
46642
|
-
import { ObjectId as ObjectId124 } from "mongodb";
|
|
46643
|
-
var MCardInfo = class {
|
|
46644
|
-
// this is coming from RDP transaction
|
|
46645
|
-
constructor({
|
|
46646
|
-
_id = new ObjectId124(),
|
|
46647
|
-
userId,
|
|
46648
|
-
cardType,
|
|
46649
|
-
cardNumber,
|
|
46650
|
-
cardId,
|
|
46651
|
-
fullName,
|
|
46652
|
-
expiryDate,
|
|
46653
|
-
cvv,
|
|
46654
|
-
site,
|
|
46655
|
-
siteName,
|
|
46656
|
-
organization,
|
|
46657
|
-
createdBy,
|
|
46658
|
-
createdAt,
|
|
46659
|
-
updatedAt,
|
|
46660
|
-
transaction_id
|
|
46661
|
-
} = {}) {
|
|
46662
|
-
this._id = _id;
|
|
46663
|
-
this.userId = userId;
|
|
46664
|
-
this.cardType = cardType;
|
|
46665
|
-
this.cardNumber = cardNumber;
|
|
46666
|
-
this.cardId = cardId;
|
|
46667
|
-
this.fullName = fullName;
|
|
46668
|
-
this.expiryDate = expiryDate;
|
|
46669
|
-
this.cvv = cvv;
|
|
46670
|
-
this.site = site;
|
|
46671
|
-
this.siteName = siteName;
|
|
46672
|
-
this.organization = organization;
|
|
46673
|
-
this.createdBy = createdBy;
|
|
46674
|
-
this.createdAt = createdAt;
|
|
46675
|
-
this.updatedAt = updatedAt;
|
|
46676
|
-
this.transaction_id = transaction_id;
|
|
46677
|
-
}
|
|
46678
|
-
};
|
|
46679
|
-
|
|
46680
|
-
// src/models/cart.model.ts
|
|
46681
|
-
import { ObjectId as ObjectId125 } from "mongodb";
|
|
46682
|
-
var MUnitBillings = class {
|
|
46683
|
-
// transaction response messages
|
|
46684
|
-
constructor({
|
|
46685
|
-
_id = new ObjectId125(),
|
|
46686
|
-
unit,
|
|
46687
|
-
unitId,
|
|
46688
|
-
unitBill,
|
|
46689
|
-
paymentStatus = "Processing" /* processing */,
|
|
46690
|
-
referenceNumber,
|
|
46691
|
-
amountPaid,
|
|
46692
|
-
paidBy,
|
|
46693
|
-
datePaid,
|
|
46694
|
-
billCategory,
|
|
46695
|
-
billFrom,
|
|
46696
|
-
billTo,
|
|
46697
|
-
site,
|
|
46698
|
-
organization,
|
|
46699
|
-
createdBy,
|
|
46700
|
-
createdAt,
|
|
46701
|
-
updatedAt,
|
|
46702
|
-
message
|
|
46703
|
-
} = {}) {
|
|
46704
|
-
this._id = _id;
|
|
46705
|
-
this.unit = unit;
|
|
46706
|
-
this.unitId = unitId;
|
|
46707
|
-
this.referenceNumber = referenceNumber;
|
|
46708
|
-
this.unitBill = unitBill;
|
|
46709
|
-
this.paymentStatus = paymentStatus;
|
|
46710
|
-
this.amountPaid = amountPaid;
|
|
46711
|
-
this.site = site;
|
|
46712
|
-
this.organization = organization;
|
|
46713
|
-
this.paidBy = paidBy;
|
|
46714
|
-
this.datePaid = datePaid;
|
|
46715
|
-
this.billCategory = billCategory;
|
|
46716
|
-
this.billFrom = billFrom;
|
|
46717
|
-
this.billTo = billTo;
|
|
46718
|
-
this.createdBy = createdBy;
|
|
46719
|
-
this.createdAt = createdAt;
|
|
46720
|
-
this.updatedAt = updatedAt;
|
|
46721
|
-
this.message = message;
|
|
46722
|
-
}
|
|
46723
|
-
};
|
|
46724
|
-
|
|
46725
|
-
// src/repositories/payment.repository.ts
|
|
46726
|
-
import { ObjectId as ObjectId126 } from "mongodb";
|
|
46727
|
-
import {
|
|
46728
|
-
InternalServerError as InternalServerError66,
|
|
46729
|
-
useAtlas as useAtlas110
|
|
46730
|
-
} from "@7365admin1/node-server-utils";
|
|
46731
|
-
var PaymentBillRepo = () => {
|
|
47212
|
+
import { InternalServerError as InternalServerError66, useAtlas as useAtlas110 } from "@7365admin1/node-server-utils";
|
|
47213
|
+
var useRedDotPaymentRepo = () => {
|
|
46732
47214
|
const getDB2 = () => {
|
|
46733
47215
|
const db = useAtlas110.getDb();
|
|
46734
47216
|
if (!db) {
|
|
@@ -46736,350 +47218,75 @@ var PaymentBillRepo = () => {
|
|
|
46736
47218
|
}
|
|
46737
47219
|
return db;
|
|
46738
47220
|
};
|
|
46739
|
-
const
|
|
46740
|
-
return getDB2().collection("
|
|
47221
|
+
const paymentCollection = () => {
|
|
47222
|
+
return getDB2().collection("payments");
|
|
46741
47223
|
};
|
|
46742
|
-
const
|
|
46743
|
-
return getDB2().collection("
|
|
47224
|
+
const unitBillingCollection = () => {
|
|
47225
|
+
return getDB2().collection("site.unit.billing");
|
|
46744
47226
|
};
|
|
46745
|
-
const
|
|
46746
|
-
return getDB2().collection("
|
|
47227
|
+
const orgCollection = () => {
|
|
47228
|
+
return getDB2().collection("organizations");
|
|
46747
47229
|
};
|
|
46748
|
-
const
|
|
46749
|
-
return getDB2().collection("
|
|
47230
|
+
const redDotMerchantCollection = () => {
|
|
47231
|
+
return getDB2().collection("payment-gateways");
|
|
46750
47232
|
};
|
|
46751
|
-
|
|
47233
|
+
async function paySingleUnitBill(refId, payload) {
|
|
46752
47234
|
try {
|
|
46753
47235
|
if (refId)
|
|
46754
47236
|
refId = refId.toString();
|
|
46755
|
-
const unitBillInfo = await
|
|
46756
|
-
|
|
47237
|
+
const unitBillInfo = await unitBillingCollection().findOne({
|
|
47238
|
+
referenceNumber: refId
|
|
47239
|
+
});
|
|
46757
47240
|
if (!unitBillInfo) {
|
|
46758
47241
|
throw new Error("Unit bill info not found");
|
|
46759
47242
|
}
|
|
46760
|
-
if (unitBillInfo?.status === "
|
|
47243
|
+
if (unitBillInfo?.status === "inactive" /* INACTIVE */) {
|
|
46761
47244
|
throw new Error("This Bill is Inactive!");
|
|
46762
47245
|
}
|
|
46763
|
-
|
|
46764
|
-
|
|
46765
|
-
|
|
46766
|
-
|
|
46767
|
-
|
|
46768
|
-
|
|
46769
|
-
|
|
46770
|
-
const amount = payload.amountPaid;
|
|
46771
|
-
const numericPrice = typeof price === "string" ? parseInt(price) : price;
|
|
46772
|
-
const numericAmount = typeof amount === "string" ? parseInt(amount) : amount;
|
|
46773
|
-
if (typeof amount !== "number") {
|
|
46774
|
-
throw new Error("Amount is not a valid number");
|
|
46775
|
-
} else if (typeof price !== "number") {
|
|
46776
|
-
throw new Error("Price s not a valid number");
|
|
47246
|
+
if (payload.paymentStatus === "partial-payment" /* PARTIAL */ && payload.amountPaid) {
|
|
47247
|
+
const totalAmount = parseInt(unitBillInfo.totalAmount);
|
|
47248
|
+
const amountPaid = payload.amountPaid;
|
|
47249
|
+
if (typeof totalAmount !== "number") {
|
|
47250
|
+
throw new Error("Total Amount is not a valid number");
|
|
47251
|
+
} else if (typeof amountPaid !== "number") {
|
|
47252
|
+
throw new Error("Amount Paid is not a valid number");
|
|
46777
47253
|
}
|
|
46778
|
-
payload.
|
|
46779
|
-
} else if (payload.paymentStatus === "
|
|
47254
|
+
payload.balanceAmount = totalAmount - amountPaid;
|
|
47255
|
+
} else if (payload.paymentStatus === "paid" /* PAID */ && payload.amountPaid) {
|
|
46780
47256
|
payload.datePaid = /* @__PURE__ */ new Date();
|
|
46781
|
-
payload.paymentStatus = "
|
|
47257
|
+
payload.paymentStatus = "paid" /* PAID */;
|
|
46782
47258
|
payload.amountPaid;
|
|
46783
47259
|
payload.transaction_id;
|
|
46784
|
-
} else if (payload.paymentStatus === "
|
|
47260
|
+
} else if (payload.paymentStatus === "failed" /* FAILED */) {
|
|
46785
47261
|
payload.amountPaid = 0;
|
|
46786
|
-
payload.
|
|
46787
|
-
payload.datePaid = "";
|
|
46788
|
-
payload.paymentStatus = "Failed" /* failed */;
|
|
47262
|
+
payload.paymentStatus = "failed" /* FAILED */;
|
|
46789
47263
|
payload.transaction_id;
|
|
46790
47264
|
}
|
|
46791
|
-
|
|
46792
|
-
|
|
46793
|
-
|
|
46794
|
-
|
|
46795
|
-
|
|
46796
|
-
|
|
46797
|
-
}
|
|
46798
|
-
};
|
|
46799
|
-
const saveCreditCardInfo = async (payload) => {
|
|
46800
|
-
try {
|
|
46801
|
-
if (payload.userId)
|
|
46802
|
-
payload.userId = new ObjectId126(payload.userId);
|
|
46803
|
-
if (payload.site)
|
|
46804
|
-
payload.site = new ObjectId126(payload.site);
|
|
46805
|
-
if (payload.organization)
|
|
46806
|
-
payload.organization = new ObjectId126(payload.organization);
|
|
46807
|
-
if (payload.createdBy)
|
|
46808
|
-
payload.createdBy = new ObjectId126(payload.createdBy);
|
|
46809
|
-
const createdAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
46810
|
-
payload.createdAt = createdAt;
|
|
46811
|
-
const result = await creditCollection().insertOne(new MCardInfo(payload));
|
|
46812
|
-
return result;
|
|
46813
|
-
} catch (error) {
|
|
46814
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46815
|
-
}
|
|
46816
|
-
};
|
|
46817
|
-
const checkOutUnitBills = async (payload) => {
|
|
46818
|
-
try {
|
|
46819
|
-
if (payload.unitId)
|
|
46820
|
-
payload.unitId = new ObjectId126(payload.unitId);
|
|
46821
|
-
if (payload.site)
|
|
46822
|
-
payload.site = new ObjectId126(payload.site);
|
|
46823
|
-
if (payload.organization)
|
|
46824
|
-
payload.organization = new ObjectId126(payload.organization);
|
|
46825
|
-
payload.createdAt = await formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
46826
|
-
const addToCart = await cartCollection().insertOne(new MUnitBillings(payload));
|
|
46827
|
-
const unitId = payload.unitId;
|
|
46828
|
-
const dateFormatted = formatDateString(/* @__PURE__ */ new Date(), "for-ref");
|
|
46829
|
-
const unit = unitId?.toString().slice(-4);
|
|
46830
|
-
const newId = new ObjectId126(addToCart?.insertedId).toString().slice(-4);
|
|
46831
|
-
const referenceNumber = `CRT${unit}${newId}${dateFormatted}`;
|
|
46832
|
-
const result = await cartCollection().findOneAndUpdate({ _id: new ObjectId126(addToCart.insertedId) }, { $set: { referenceNumber } }, { returnDocument: "after" });
|
|
46833
|
-
return result;
|
|
46834
|
-
} catch (error) {
|
|
46835
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46836
|
-
}
|
|
46837
|
-
};
|
|
46838
|
-
const payUnitCart = async (refId, payload) => {
|
|
46839
|
-
try {
|
|
46840
|
-
if (refId)
|
|
46841
|
-
refId = refId.toString();
|
|
46842
|
-
const updatedAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
46843
|
-
const cartInfo = await cartCollection().findOne({ referenceNumber: refId });
|
|
46844
|
-
const refNumber = cartInfo?.unitBill;
|
|
46845
|
-
if (payload.paymentStatus === "Paid" /* paid */ && payload.amountPaid) {
|
|
46846
|
-
payload.datePaid = /* @__PURE__ */ new Date();
|
|
46847
|
-
payload.paymentStatus = "Paid" /* paid */;
|
|
46848
|
-
payload.amountPaid;
|
|
46849
|
-
} else if (payload.paymentStatus === "Failed" /* failed */) {
|
|
46850
|
-
payload.amountPaid = 0;
|
|
46851
|
-
payload.paidBy = "";
|
|
46852
|
-
payload.datePaid = "";
|
|
46853
|
-
payload.paymentStatus = "Failed" /* failed */;
|
|
46854
|
-
}
|
|
46855
|
-
payload.updatedAt = updatedAt;
|
|
46856
|
-
const result = await cartCollection().findOneAndUpdate({ referenceNumber: refId }, { $set: payload }, { returnDocument: "after" });
|
|
46857
|
-
if (!result) {
|
|
46858
|
-
throw new Error("Failed to Process Transaction. Please Try Again Later");
|
|
46859
|
-
} else {
|
|
46860
|
-
for (const ref of refNumber) {
|
|
46861
|
-
const unitBillInfo = await collection().findOne({ referenceNumber: ref });
|
|
46862
|
-
const billId = unitBillInfo?.billId;
|
|
46863
|
-
const billInfo = await billCollection().findOne({ _id: new ObjectId126(billId) });
|
|
46864
|
-
const billAmount = billInfo?.price;
|
|
46865
|
-
payload.updatedAt = updatedAt;
|
|
46866
|
-
payload.amountPaid = billAmount;
|
|
46867
|
-
const eachRef = await payUnitBill(ref, payload);
|
|
46868
|
-
}
|
|
46869
|
-
if (!cartInfo) {
|
|
46870
|
-
throw new Error("Cart info not found");
|
|
46871
|
-
}
|
|
46872
|
-
}
|
|
47265
|
+
payload.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
47266
|
+
const result = await unitBillingCollection().findOneAndUpdate(
|
|
47267
|
+
{ _id: unitBillInfo._id },
|
|
47268
|
+
{ $set: payload },
|
|
47269
|
+
{ returnDocument: "after" }
|
|
47270
|
+
);
|
|
46873
47271
|
return result;
|
|
46874
47272
|
} catch (error) {
|
|
46875
47273
|
throw new Error(error.message || error || "Server Internal Error");
|
|
46876
47274
|
}
|
|
46877
|
-
}
|
|
46878
|
-
|
|
46879
|
-
try {
|
|
46880
|
-
if (refId)
|
|
46881
|
-
refId = refId.toString();
|
|
46882
|
-
const result = await cartCollection().aggregate([
|
|
46883
|
-
{ $match: { referenceNumber: refId } },
|
|
46884
|
-
{
|
|
46885
|
-
$lookup: {
|
|
46886
|
-
from: "unit-bill",
|
|
46887
|
-
localField: "unitBill",
|
|
46888
|
-
foreignField: "referenceNumber",
|
|
46889
|
-
as: "unitBill"
|
|
46890
|
-
}
|
|
46891
|
-
},
|
|
46892
|
-
{
|
|
46893
|
-
$unwind: "$unitBill"
|
|
46894
|
-
},
|
|
46895
|
-
{
|
|
46896
|
-
$lookup: {
|
|
46897
|
-
from: "bill-records",
|
|
46898
|
-
localField: "unitBill.billId",
|
|
46899
|
-
foreignField: "_id",
|
|
46900
|
-
as: "billDetails"
|
|
46901
|
-
}
|
|
46902
|
-
},
|
|
46903
|
-
{
|
|
46904
|
-
$unwind: {
|
|
46905
|
-
path: "$billDetails",
|
|
46906
|
-
preserveNullAndEmptyArrays: true
|
|
46907
|
-
}
|
|
46908
|
-
},
|
|
46909
|
-
{
|
|
46910
|
-
$addFields: {
|
|
46911
|
-
"unitBill.billItemName": "$billDetails.billItem"
|
|
46912
|
-
}
|
|
46913
|
-
},
|
|
46914
|
-
{
|
|
46915
|
-
$project: {
|
|
46916
|
-
"unitBill.paidBy": 0,
|
|
46917
|
-
"unitBill.preDueDateAlert": 0,
|
|
46918
|
-
"unitBill.category": 0,
|
|
46919
|
-
"unitBill.contactNumber": 0,
|
|
46920
|
-
"unitBill.email": 0,
|
|
46921
|
-
"unitBill.site": 0,
|
|
46922
|
-
"unitBill.siteName": 0,
|
|
46923
|
-
"unitBill.organization": 0,
|
|
46924
|
-
"unitBill.billStatus": 0,
|
|
46925
|
-
"unitBill.createdBy": 0,
|
|
46926
|
-
"unitBill.createdAt": 0,
|
|
46927
|
-
"unitBill.updatedAt": 0,
|
|
46928
|
-
"billDetails": 0
|
|
46929
|
-
// Exclude the full billDetails as it's no longer needed
|
|
46930
|
-
}
|
|
46931
|
-
},
|
|
46932
|
-
{
|
|
46933
|
-
$group: {
|
|
46934
|
-
_id: "$_id",
|
|
46935
|
-
unitId: { $first: "$unitId" },
|
|
46936
|
-
referenceNumber: { $first: "$referenceNumber" },
|
|
46937
|
-
unitBill: { $push: "$unitBill" },
|
|
46938
|
-
paymentStatus: { $first: "$paymentStatus" },
|
|
46939
|
-
amountPaid: { $first: "$amountPaid" },
|
|
46940
|
-
site: { $first: "$site" },
|
|
46941
|
-
organization: { $first: "$organization" },
|
|
46942
|
-
paidBy: { $first: "$paidBy" },
|
|
46943
|
-
datePaid: { $first: "$referenceNumber" },
|
|
46944
|
-
billCategory: { $first: "$billCategory" },
|
|
46945
|
-
billFrom: { $first: "$billFrom" },
|
|
46946
|
-
billTo: { $first: "$billTo" },
|
|
46947
|
-
createdBy: { $first: "$createdBy" },
|
|
46948
|
-
createdAt: { $first: "$createdAt" },
|
|
46949
|
-
updatedAt: { $first: "$updatedAt" },
|
|
46950
|
-
transaction_id: { $first: "$transaction_id" }
|
|
46951
|
-
}
|
|
46952
|
-
}
|
|
46953
|
-
]).toArray();
|
|
46954
|
-
if (!result || result.length === 0) {
|
|
46955
|
-
return { success: false, message: "Cart Info Not Found" };
|
|
46956
|
-
}
|
|
46957
|
-
return result[0];
|
|
46958
|
-
} catch (error) {
|
|
46959
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46960
|
-
}
|
|
46961
|
-
};
|
|
46962
|
-
const cancelCheckedOutBillings = async (refId) => {
|
|
46963
|
-
try {
|
|
46964
|
-
if (refId)
|
|
46965
|
-
refId = refId.toString();
|
|
46966
|
-
const result = await cartCollection().findOneAndDelete({ referenceNumber: refId });
|
|
46967
|
-
if (!result) {
|
|
46968
|
-
return { success: false, message: "Cart Info Not Found" };
|
|
46969
|
-
}
|
|
46970
|
-
return { success: true, message: "Cart Deleted Successfully!", referenceNumber: result?.referenceNumber };
|
|
46971
|
-
} catch (error) {
|
|
46972
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46973
|
-
}
|
|
46974
|
-
};
|
|
46975
|
-
return {
|
|
46976
|
-
saveCreditCardInfo,
|
|
46977
|
-
checkOutUnitBills,
|
|
46978
|
-
payUnitBill,
|
|
46979
|
-
payUnitCart,
|
|
46980
|
-
getCheckedOutBillings,
|
|
46981
|
-
cancelCheckedOutBillings
|
|
46982
|
-
};
|
|
46983
|
-
};
|
|
46984
|
-
|
|
46985
|
-
// src/repositories/reddot-payment.repository.ts
|
|
46986
|
-
import {
|
|
46987
|
-
InternalServerError as InternalServerError67,
|
|
46988
|
-
useAtlas as useAtlas111
|
|
46989
|
-
} from "@7365admin1/node-server-utils";
|
|
46990
|
-
var useRedDotPaymentRepo = () => {
|
|
46991
|
-
const getDB2 = () => {
|
|
46992
|
-
const db = useAtlas111.getDb();
|
|
46993
|
-
if (!db) {
|
|
46994
|
-
throw new InternalServerError67("Unable to connect to server.");
|
|
46995
|
-
}
|
|
46996
|
-
return db;
|
|
46997
|
-
};
|
|
46998
|
-
const collection = () => {
|
|
46999
|
-
return getDB2().collection("unit-bill");
|
|
47000
|
-
};
|
|
47001
|
-
const orgCollection = () => {
|
|
47002
|
-
return getDB2().collection("organizations");
|
|
47003
|
-
};
|
|
47004
|
-
const cartCollection = () => {
|
|
47005
|
-
return getDB2().collection("checkout-cart");
|
|
47006
|
-
};
|
|
47007
|
-
const redDotMerchantCollection = () => {
|
|
47008
|
-
return getDB2().collection("reddot-merchant");
|
|
47009
|
-
};
|
|
47010
|
-
const createRedDotAccount = async (_id, payload) => {
|
|
47011
|
-
try {
|
|
47012
|
-
const merchant = await redDotMerchantCollection().insertOne(payload);
|
|
47013
|
-
if (!merchant) {
|
|
47014
|
-
throw new Error("Failed to Add Merchant Details");
|
|
47015
|
-
}
|
|
47016
|
-
const merchantId = merchant?.insertedId;
|
|
47017
|
-
const orgId = new ObjectId127(_id);
|
|
47018
|
-
const result = await orgCollection().findOneAndUpdate({ _id: orgId }, { $push: { merchant: merchantId } }, {
|
|
47019
|
-
returnDocument: "after"
|
|
47020
|
-
});
|
|
47021
|
-
if (!result) {
|
|
47022
|
-
throw new Error("Organization not found");
|
|
47023
|
-
}
|
|
47024
|
-
return {
|
|
47025
|
-
success: true,
|
|
47026
|
-
message: "Merchant Details successfully added."
|
|
47027
|
-
};
|
|
47028
|
-
} catch (error) {
|
|
47029
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
47030
|
-
}
|
|
47031
|
-
};
|
|
47032
|
-
const payUnitBillings = async (refId, payload) => {
|
|
47033
|
-
const checkCart = await cartCollection().findOne({ referenceNumber: refId });
|
|
47034
|
-
if (checkCart) {
|
|
47035
|
-
const multiple = await PaymentBillRepo().payUnitCart(refId, payload);
|
|
47036
|
-
if (multiple) {
|
|
47037
|
-
return await PaymentBillRepo().getCheckedOutBillings(refId);
|
|
47038
|
-
}
|
|
47039
|
-
}
|
|
47040
|
-
const single = await PaymentBillRepo().payUnitBill(refId, payload);
|
|
47041
|
-
return single;
|
|
47042
|
-
};
|
|
47043
|
-
const getMerchantDetailsById = async (_id) => {
|
|
47044
|
-
try {
|
|
47045
|
-
if (_id)
|
|
47046
|
-
_id = new ObjectId127(_id);
|
|
47047
|
-
const result = await redDotMerchantCollection().aggregate([
|
|
47048
|
-
{
|
|
47049
|
-
$match: {
|
|
47050
|
-
_id
|
|
47051
|
-
}
|
|
47052
|
-
},
|
|
47053
|
-
{
|
|
47054
|
-
$facet: {
|
|
47055
|
-
totalCount: [{ $count: "count" }],
|
|
47056
|
-
items: [{ $sort: { _id: -1 } }]
|
|
47057
|
-
}
|
|
47058
|
-
}
|
|
47059
|
-
]).toArray();
|
|
47060
|
-
const items = result[0].items;
|
|
47061
|
-
return items;
|
|
47062
|
-
} catch (error) {
|
|
47063
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
47064
|
-
}
|
|
47065
|
-
};
|
|
47066
|
-
return {
|
|
47067
|
-
createRedDotAccount,
|
|
47068
|
-
payUnitBillings,
|
|
47069
|
-
getMerchantDetailsById
|
|
47070
|
-
};
|
|
47275
|
+
}
|
|
47276
|
+
return { paySingleUnitBill };
|
|
47071
47277
|
};
|
|
47072
47278
|
|
|
47073
47279
|
// src/services/reddot-payment.service.ts
|
|
47074
47280
|
var useRedDotPaymentSvc = () => {
|
|
47075
|
-
const
|
|
47076
|
-
return useRedDotPaymentRepo().createRedDotAccount(_id, payload);
|
|
47077
|
-
};
|
|
47281
|
+
const { paySingleUnitBill } = useRedDotPaymentRepo();
|
|
47078
47282
|
const redirectPaymentTransaction = async (payload) => {
|
|
47079
47283
|
try {
|
|
47080
47284
|
const SECRET_KEY2 = payload.merchant_key;
|
|
47081
47285
|
if (!payload.mid && !payload.merchant_key) {
|
|
47082
|
-
return {
|
|
47286
|
+
return {
|
|
47287
|
+
success: false,
|
|
47288
|
+
message: "RDP Not Available on this account. Please Contact Management"
|
|
47289
|
+
};
|
|
47083
47290
|
}
|
|
47084
47291
|
const data = {
|
|
47085
47292
|
mid: payload.mid,
|
|
@@ -47102,7 +47309,9 @@ var useRedDotPaymentSvc = () => {
|
|
|
47102
47309
|
"Content-Length": String(dataString.length)
|
|
47103
47310
|
};
|
|
47104
47311
|
if (!process.env.MERCHANT_PAYMENT) {
|
|
47105
|
-
throw new Error(
|
|
47312
|
+
throw new Error(
|
|
47313
|
+
"MERCHANT_PAYMENT environment variable is not defined."
|
|
47314
|
+
);
|
|
47106
47315
|
}
|
|
47107
47316
|
const url = process.env.MERCHANT_PAYMENT;
|
|
47108
47317
|
const response = await axios3.post(url, dataString, { headers });
|
|
@@ -47116,7 +47325,10 @@ var useRedDotPaymentSvc = () => {
|
|
|
47116
47325
|
try {
|
|
47117
47326
|
const SECRET_KEY2 = payload.merchant_key;
|
|
47118
47327
|
if (!payload.request_mid && !payload.merchant_key) {
|
|
47119
|
-
return {
|
|
47328
|
+
return {
|
|
47329
|
+
success: false,
|
|
47330
|
+
message: "RDP Not Available on this account. Please Contact Management"
|
|
47331
|
+
};
|
|
47120
47332
|
}
|
|
47121
47333
|
const data = {
|
|
47122
47334
|
request_mid: payload.request_mid,
|
|
@@ -47131,7 +47343,9 @@ var useRedDotPaymentSvc = () => {
|
|
|
47131
47343
|
"Content-Type": "application/json"
|
|
47132
47344
|
};
|
|
47133
47345
|
if (!process.env.MERCHANT_ENQUIRY) {
|
|
47134
|
-
throw new Error(
|
|
47346
|
+
throw new Error(
|
|
47347
|
+
"MERCHANT_PAYMENT environment variable is not defined."
|
|
47348
|
+
);
|
|
47135
47349
|
}
|
|
47136
47350
|
const url = process.env.MERCHANT_ENQUIRY;
|
|
47137
47351
|
const response = await axios3.post(url, dataString, { headers });
|
|
@@ -47145,25 +47359,24 @@ var useRedDotPaymentSvc = () => {
|
|
|
47145
47359
|
if (result.response_code === "0") {
|
|
47146
47360
|
const success = {
|
|
47147
47361
|
method: payload.method,
|
|
47148
|
-
paymentStatus: "
|
|
47149
|
-
amountPaid: amount,
|
|
47150
|
-
paidBy: payer,
|
|
47362
|
+
paymentStatus: "paid" /* PAID */,
|
|
47363
|
+
amountPaid: parseInt(amount),
|
|
47151
47364
|
updatedAt: invoiceDate,
|
|
47152
47365
|
transaction_id: transactionId,
|
|
47153
47366
|
message
|
|
47154
47367
|
};
|
|
47155
|
-
await
|
|
47368
|
+
await paySingleUnitBill(refId, success);
|
|
47156
47369
|
} else if (result.response_code !== "0") {
|
|
47157
47370
|
const fail = {
|
|
47158
47371
|
method: payload.method,
|
|
47159
|
-
paymentStatus: "
|
|
47372
|
+
paymentStatus: "failed" /* FAILED */,
|
|
47160
47373
|
updatedAt: invoiceDate,
|
|
47161
47374
|
paidBy: "",
|
|
47162
|
-
amountPaid:
|
|
47375
|
+
amountPaid: 0,
|
|
47163
47376
|
transaction_id: transactionId,
|
|
47164
47377
|
message
|
|
47165
47378
|
};
|
|
47166
|
-
await
|
|
47379
|
+
await paySingleUnitBill(refId, fail);
|
|
47167
47380
|
}
|
|
47168
47381
|
return result;
|
|
47169
47382
|
} catch (error) {
|
|
@@ -47183,7 +47396,9 @@ var useRedDotPaymentSvc = () => {
|
|
|
47183
47396
|
"Content-Length": String(dataString.length)
|
|
47184
47397
|
};
|
|
47185
47398
|
if (!process.env.MERCHANT_PAYMENT) {
|
|
47186
|
-
throw new Error(
|
|
47399
|
+
throw new Error(
|
|
47400
|
+
"MERCHANT_PAYMENT environment variable is not defined."
|
|
47401
|
+
);
|
|
47187
47402
|
}
|
|
47188
47403
|
const url = process.env.MERCHANT_PAYMENT;
|
|
47189
47404
|
const response = await axios3.post(url, dataString, { headers });
|
|
@@ -47192,45 +47407,16 @@ var useRedDotPaymentSvc = () => {
|
|
|
47192
47407
|
return Promise.reject(error || error.message || "Server Internal Error!");
|
|
47193
47408
|
}
|
|
47194
47409
|
};
|
|
47195
|
-
const getMerchantDetailsById = async (_id) => {
|
|
47196
|
-
return useRedDotPaymentRepo().getMerchantDetailsById(_id);
|
|
47197
|
-
};
|
|
47198
47410
|
return {
|
|
47199
|
-
createRedDotAccount,
|
|
47200
47411
|
redirectPaymentTransaction,
|
|
47201
47412
|
enquirePaymentTransaction,
|
|
47202
|
-
payInvoice
|
|
47203
|
-
getMerchantDetailsById
|
|
47413
|
+
payInvoice
|
|
47204
47414
|
};
|
|
47205
47415
|
};
|
|
47206
47416
|
|
|
47207
47417
|
// src/controllers/reddot-payment.controller.ts
|
|
47208
47418
|
import Joi124 from "joi";
|
|
47209
47419
|
function useRedDotPaymentController() {
|
|
47210
|
-
const createRedDotAccount = async (req, res) => {
|
|
47211
|
-
try {
|
|
47212
|
-
const data = req.body;
|
|
47213
|
-
const id = req.params.id;
|
|
47214
|
-
const schema2 = Joi124.object({
|
|
47215
|
-
id: Joi124.string().hex().required(),
|
|
47216
|
-
// organization id
|
|
47217
|
-
paymentMethod: Joi124.string().required(),
|
|
47218
|
-
// payment method (e.g. "Visa / Mastercard / PayNow QR Code")
|
|
47219
|
-
merchant_id: Joi124.string().required(),
|
|
47220
|
-
// merchant id
|
|
47221
|
-
merchant_key: Joi124.string().required()
|
|
47222
|
-
// secret key
|
|
47223
|
-
});
|
|
47224
|
-
const { error } = schema2.validate({ id, ...data });
|
|
47225
|
-
if (error) {
|
|
47226
|
-
return res.status(400).json({ data: null, message: error.message });
|
|
47227
|
-
}
|
|
47228
|
-
const result = await useRedDotPaymentSvc().createRedDotAccount(id, data);
|
|
47229
|
-
return res.json(result);
|
|
47230
|
-
} catch (error) {
|
|
47231
|
-
return res.status(500).json({ message: error.message || error });
|
|
47232
|
-
}
|
|
47233
|
-
};
|
|
47234
47420
|
const redirectPaymentTransaction = async (req, res) => {
|
|
47235
47421
|
try {
|
|
47236
47422
|
const data = req.body;
|
|
@@ -47247,7 +47433,9 @@ function useRedDotPaymentController() {
|
|
|
47247
47433
|
if (error) {
|
|
47248
47434
|
return res.status(400).json({ data: null, message: error.message });
|
|
47249
47435
|
}
|
|
47250
|
-
const result = await useRedDotPaymentSvc().redirectPaymentTransaction(
|
|
47436
|
+
const result = await useRedDotPaymentSvc().redirectPaymentTransaction(
|
|
47437
|
+
data
|
|
47438
|
+
);
|
|
47251
47439
|
return res.json(result);
|
|
47252
47440
|
} catch (error) {
|
|
47253
47441
|
return res.status(500).json({ message: error.message || error });
|
|
@@ -47266,52 +47454,36 @@ function useRedDotPaymentController() {
|
|
|
47266
47454
|
if (error) {
|
|
47267
47455
|
return res.status(400).json({ data: null, message: error.message });
|
|
47268
47456
|
}
|
|
47269
|
-
const result = await useRedDotPaymentSvc().enquirePaymentTransaction(
|
|
47457
|
+
const result = await useRedDotPaymentSvc().enquirePaymentTransaction(
|
|
47458
|
+
data
|
|
47459
|
+
);
|
|
47270
47460
|
return res.json(result);
|
|
47271
47461
|
} catch (error) {
|
|
47272
47462
|
return res.status(500).json({ message: error.message || error });
|
|
47273
47463
|
}
|
|
47274
47464
|
};
|
|
47275
|
-
const getMerchantDetailsById = async (req, res, next) => {
|
|
47276
|
-
try {
|
|
47277
|
-
const _id = req.params.id;
|
|
47278
|
-
const schema2 = Joi124.object({
|
|
47279
|
-
_id: Joi124.string().hex().required()
|
|
47280
|
-
});
|
|
47281
|
-
const { error } = schema2.validate({ _id });
|
|
47282
|
-
if (error) {
|
|
47283
|
-
return res.status(400).json({ data: null, message: error.message });
|
|
47284
|
-
}
|
|
47285
|
-
const result = await useRedDotPaymentSvc().getMerchantDetailsById(_id);
|
|
47286
|
-
return res.json(result);
|
|
47287
|
-
} catch (error) {
|
|
47288
|
-
next(error);
|
|
47289
|
-
}
|
|
47290
|
-
};
|
|
47291
47465
|
return {
|
|
47292
|
-
createRedDotAccount,
|
|
47293
47466
|
redirectPaymentTransaction,
|
|
47294
|
-
enquirePaymentTransaction
|
|
47295
|
-
getMerchantDetailsById
|
|
47467
|
+
enquirePaymentTransaction
|
|
47296
47468
|
};
|
|
47297
47469
|
}
|
|
47298
47470
|
|
|
47299
47471
|
// src/repositories/verification-v2.repo.ts
|
|
47300
47472
|
import {
|
|
47301
47473
|
BadRequestError as BadRequestError195,
|
|
47302
|
-
InternalServerError as
|
|
47474
|
+
InternalServerError as InternalServerError67,
|
|
47303
47475
|
logger as logger175,
|
|
47304
47476
|
makeCacheKey as makeCacheKey64,
|
|
47305
47477
|
paginate as paginate57,
|
|
47306
47478
|
toObjectId as toObjectId18,
|
|
47307
|
-
useAtlas as
|
|
47479
|
+
useAtlas as useAtlas111,
|
|
47308
47480
|
useCache as useCache66
|
|
47309
47481
|
} from "@7365admin1/node-server-utils";
|
|
47310
|
-
import { ObjectId as
|
|
47482
|
+
import { ObjectId as ObjectId124 } from "mongodb";
|
|
47311
47483
|
function useVerificationRepoV2() {
|
|
47312
|
-
const db =
|
|
47484
|
+
const db = useAtlas111.getDb();
|
|
47313
47485
|
if (!db) {
|
|
47314
|
-
throw new
|
|
47486
|
+
throw new InternalServerError67("Unable to connect to server.");
|
|
47315
47487
|
}
|
|
47316
47488
|
const namespace_collection = "verifications";
|
|
47317
47489
|
const collection = db.collection(namespace_collection);
|
|
@@ -47324,7 +47496,7 @@ function useVerificationRepoV2() {
|
|
|
47324
47496
|
{ "metadata.org": 1 }
|
|
47325
47497
|
]);
|
|
47326
47498
|
} catch (error) {
|
|
47327
|
-
throw new
|
|
47499
|
+
throw new InternalServerError67("Failed to create index.");
|
|
47328
47500
|
}
|
|
47329
47501
|
}
|
|
47330
47502
|
async function createTextIndex() {
|
|
@@ -47333,7 +47505,7 @@ function useVerificationRepoV2() {
|
|
|
47333
47505
|
email: "text"
|
|
47334
47506
|
});
|
|
47335
47507
|
} catch (error) {
|
|
47336
|
-
throw new
|
|
47508
|
+
throw new InternalServerError67("Failed to create text index on email.");
|
|
47337
47509
|
}
|
|
47338
47510
|
}
|
|
47339
47511
|
const { delNamespace, setCache, getCache, delCache } = useCache66(namespace_collection);
|
|
@@ -47355,12 +47527,12 @@ function useVerificationRepoV2() {
|
|
|
47355
47527
|
level: "info",
|
|
47356
47528
|
message: String(error)
|
|
47357
47529
|
});
|
|
47358
|
-
throw new
|
|
47530
|
+
throw new InternalServerError67("Server internal error.");
|
|
47359
47531
|
}
|
|
47360
47532
|
}
|
|
47361
47533
|
async function updateVerificationStatusById(_id, status, session) {
|
|
47362
47534
|
try {
|
|
47363
|
-
_id = new
|
|
47535
|
+
_id = new ObjectId124(_id);
|
|
47364
47536
|
} catch (error) {
|
|
47365
47537
|
throw new BadRequestError195("Invalid verification ID format.");
|
|
47366
47538
|
}
|
|
@@ -47380,7 +47552,7 @@ function useVerificationRepoV2() {
|
|
|
47380
47552
|
});
|
|
47381
47553
|
return result;
|
|
47382
47554
|
} catch (error) {
|
|
47383
|
-
throw new
|
|
47555
|
+
throw new InternalServerError67("Error updating verification status.");
|
|
47384
47556
|
}
|
|
47385
47557
|
}
|
|
47386
47558
|
async function getByVerificationCode(verificationCode) {
|
|
@@ -47403,7 +47575,7 @@ function useVerificationRepoV2() {
|
|
|
47403
47575
|
});
|
|
47404
47576
|
return data;
|
|
47405
47577
|
} catch (error) {
|
|
47406
|
-
throw new
|
|
47578
|
+
throw new InternalServerError67(
|
|
47407
47579
|
"Internal server error, failed to retrieve verification."
|
|
47408
47580
|
);
|
|
47409
47581
|
}
|
|
@@ -47425,7 +47597,7 @@ function useVerificationRepoV2() {
|
|
|
47425
47597
|
});
|
|
47426
47598
|
return data;
|
|
47427
47599
|
} catch (error) {
|
|
47428
|
-
throw new
|
|
47600
|
+
throw new InternalServerError67(
|
|
47429
47601
|
"Internal server error, failed to retrieve verification."
|
|
47430
47602
|
);
|
|
47431
47603
|
}
|
|
@@ -47503,7 +47675,7 @@ function useVerificationRepoV2() {
|
|
|
47503
47675
|
}
|
|
47504
47676
|
async function updateStatusById(_id, status, session) {
|
|
47505
47677
|
try {
|
|
47506
|
-
_id = new
|
|
47678
|
+
_id = new ObjectId124(_id);
|
|
47507
47679
|
} catch (error) {
|
|
47508
47680
|
throw new BadRequestError195("Invalid verification ID format.");
|
|
47509
47681
|
}
|
|
@@ -47529,7 +47701,7 @@ function useVerificationRepoV2() {
|
|
|
47529
47701
|
});
|
|
47530
47702
|
return result;
|
|
47531
47703
|
} catch (error) {
|
|
47532
|
-
throw new
|
|
47704
|
+
throw new InternalServerError67("Error updating verification status.");
|
|
47533
47705
|
}
|
|
47534
47706
|
}
|
|
47535
47707
|
return {
|
|
@@ -47552,8 +47724,8 @@ import {
|
|
|
47552
47724
|
getDirectory as getDirectory4,
|
|
47553
47725
|
BadRequestError as BadRequestError196,
|
|
47554
47726
|
NotFoundError as NotFoundError51,
|
|
47555
|
-
InternalServerError as
|
|
47556
|
-
useAtlas as
|
|
47727
|
+
InternalServerError as InternalServerError68,
|
|
47728
|
+
useAtlas as useAtlas112,
|
|
47557
47729
|
hashPassword as hashPassword4
|
|
47558
47730
|
} from "@7365admin1/node-server-utils";
|
|
47559
47731
|
import crypto4 from "crypto";
|
|
@@ -47620,7 +47792,7 @@ function useVerificationServiceV2() {
|
|
|
47620
47792
|
email,
|
|
47621
47793
|
metadata
|
|
47622
47794
|
}) {
|
|
47623
|
-
const session =
|
|
47795
|
+
const session = useAtlas112.getClient()?.startSession();
|
|
47624
47796
|
try {
|
|
47625
47797
|
session?.startTransaction();
|
|
47626
47798
|
const user = await _getUserByEmailStatus(email);
|
|
@@ -47672,7 +47844,7 @@ function useVerificationServiceV2() {
|
|
|
47672
47844
|
}
|
|
47673
47845
|
}
|
|
47674
47846
|
async function verify(verificationCode) {
|
|
47675
|
-
const session =
|
|
47847
|
+
const session = useAtlas112.getClient()?.startSession();
|
|
47676
47848
|
try {
|
|
47677
47849
|
session?.startTransaction();
|
|
47678
47850
|
const item = await _getByVerificationCode(verificationCode);
|
|
@@ -47873,14 +48045,14 @@ function useVerificationServiceV2() {
|
|
|
47873
48045
|
});
|
|
47874
48046
|
return "Successfully created a link to reset password. Please check your email.";
|
|
47875
48047
|
} catch (error) {
|
|
47876
|
-
throw new
|
|
48048
|
+
throw new InternalServerError68("Failed to create forget password link.");
|
|
47877
48049
|
}
|
|
47878
48050
|
}
|
|
47879
48051
|
async function cancelUserInvitation(id) {
|
|
47880
48052
|
try {
|
|
47881
48053
|
await _updateStatusById(id, "cancelled");
|
|
47882
48054
|
} catch (error) {
|
|
47883
|
-
throw new
|
|
48055
|
+
throw new InternalServerError68(
|
|
47884
48056
|
`Error cancelling user invitation: ${error}`
|
|
47885
48057
|
);
|
|
47886
48058
|
}
|
|
@@ -48098,17 +48270,17 @@ import { BadRequestError as BadRequestError201, logger as logger180 } from "@736
|
|
|
48098
48270
|
import {
|
|
48099
48271
|
BadRequestError as BadRequestError199,
|
|
48100
48272
|
comparePassword as comparePassword3,
|
|
48101
|
-
InternalServerError as
|
|
48273
|
+
InternalServerError as InternalServerError70,
|
|
48102
48274
|
NotFoundError as NotFoundError53,
|
|
48103
48275
|
useCache as useCache68
|
|
48104
48276
|
} from "@7365admin1/node-server-utils";
|
|
48105
48277
|
import { v4 as uuidv42 } from "uuid";
|
|
48106
48278
|
|
|
48107
48279
|
// src/repositories/user-v2.repo.ts
|
|
48108
|
-
import { ObjectId as
|
|
48280
|
+
import { ObjectId as ObjectId125 } from "mongodb";
|
|
48109
48281
|
import {
|
|
48110
|
-
useAtlas as
|
|
48111
|
-
InternalServerError as
|
|
48282
|
+
useAtlas as useAtlas113,
|
|
48283
|
+
InternalServerError as InternalServerError69,
|
|
48112
48284
|
logger as logger178,
|
|
48113
48285
|
BadRequestError as BadRequestError198,
|
|
48114
48286
|
paginate as paginate58,
|
|
@@ -48122,9 +48294,9 @@ function useUserRepoV2() {
|
|
|
48122
48294
|
const { updateFeedbackCreatedByName } = useFeedbackRepo();
|
|
48123
48295
|
const { updateWorkOrderCreatedByName } = useWorkOrderRepo();
|
|
48124
48296
|
const { updateUserNameBySignatureId } = useOccurrenceEntryRepo();
|
|
48125
|
-
const db =
|
|
48297
|
+
const db = useAtlas113.getDb();
|
|
48126
48298
|
if (!db) {
|
|
48127
|
-
throw new
|
|
48299
|
+
throw new InternalServerError69("Unable to connect to server.");
|
|
48128
48300
|
}
|
|
48129
48301
|
const namespace_collection = "users";
|
|
48130
48302
|
const collection = db.collection(namespace_collection);
|
|
@@ -48133,14 +48305,14 @@ function useUserRepoV2() {
|
|
|
48133
48305
|
try {
|
|
48134
48306
|
await collection.createIndexes([{ key: { email: 1 } }]);
|
|
48135
48307
|
} catch (error) {
|
|
48136
|
-
throw new
|
|
48308
|
+
throw new InternalServerError69("Failed to create text index on user.");
|
|
48137
48309
|
}
|
|
48138
48310
|
}
|
|
48139
48311
|
async function createTextIndex() {
|
|
48140
48312
|
try {
|
|
48141
48313
|
await collection.createIndex({ name: "text", email: "text" });
|
|
48142
48314
|
} catch (error) {
|
|
48143
|
-
throw new
|
|
48315
|
+
throw new InternalServerError69("Failed to create text index on user.");
|
|
48144
48316
|
}
|
|
48145
48317
|
}
|
|
48146
48318
|
async function createUniqueIndex() {
|
|
@@ -48150,7 +48322,7 @@ function useUserRepoV2() {
|
|
|
48150
48322
|
{ unique: true }
|
|
48151
48323
|
);
|
|
48152
48324
|
} catch (error) {
|
|
48153
|
-
throw new
|
|
48325
|
+
throw new InternalServerError69("Failed to create unique index on user.");
|
|
48154
48326
|
}
|
|
48155
48327
|
}
|
|
48156
48328
|
async function createUser(value, session) {
|
|
@@ -48190,7 +48362,7 @@ function useUserRepoV2() {
|
|
|
48190
48362
|
);
|
|
48191
48363
|
return data;
|
|
48192
48364
|
} catch (error) {
|
|
48193
|
-
throw new
|
|
48365
|
+
throw new InternalServerError69("Failed to get user by email.");
|
|
48194
48366
|
}
|
|
48195
48367
|
}
|
|
48196
48368
|
async function getUserByEmailStatus(email) {
|
|
@@ -48213,7 +48385,7 @@ function useUserRepoV2() {
|
|
|
48213
48385
|
);
|
|
48214
48386
|
return data;
|
|
48215
48387
|
} catch (error) {
|
|
48216
|
-
throw new
|
|
48388
|
+
throw new InternalServerError69("Failed to get user by email.");
|
|
48217
48389
|
}
|
|
48218
48390
|
}
|
|
48219
48391
|
async function getUserById(id) {
|
|
@@ -48253,7 +48425,7 @@ function useUserRepoV2() {
|
|
|
48253
48425
|
} catch (error) {
|
|
48254
48426
|
if (error instanceof AppError27)
|
|
48255
48427
|
throw error;
|
|
48256
|
-
throw new
|
|
48428
|
+
throw new InternalServerError69("Failed to get user by id.");
|
|
48257
48429
|
}
|
|
48258
48430
|
}
|
|
48259
48431
|
async function getUserByReferralCode(referralCode) {
|
|
@@ -48270,7 +48442,7 @@ function useUserRepoV2() {
|
|
|
48270
48442
|
);
|
|
48271
48443
|
return data;
|
|
48272
48444
|
} catch (error) {
|
|
48273
|
-
throw new
|
|
48445
|
+
throw new InternalServerError69("Failed to get user by referral code.");
|
|
48274
48446
|
}
|
|
48275
48447
|
}
|
|
48276
48448
|
async function getByEmailApp(email, app) {
|
|
@@ -48290,7 +48462,7 @@ function useUserRepoV2() {
|
|
|
48290
48462
|
);
|
|
48291
48463
|
return data;
|
|
48292
48464
|
} catch (error) {
|
|
48293
|
-
throw new
|
|
48465
|
+
throw new InternalServerError69("Failed to get user by email and app.");
|
|
48294
48466
|
}
|
|
48295
48467
|
}
|
|
48296
48468
|
async function getUsersByOrgId({
|
|
@@ -48317,7 +48489,7 @@ function useUserRepoV2() {
|
|
|
48317
48489
|
}
|
|
48318
48490
|
if (organization) {
|
|
48319
48491
|
try {
|
|
48320
|
-
query.defaultOrg = new
|
|
48492
|
+
query.defaultOrg = new ObjectId125(organization);
|
|
48321
48493
|
cacheOptions.organization = organization.toString();
|
|
48322
48494
|
} catch (error) {
|
|
48323
48495
|
throw new BadRequestError198("Invalid organization ID format.");
|
|
@@ -48436,7 +48608,7 @@ function useUserRepoV2() {
|
|
|
48436
48608
|
});
|
|
48437
48609
|
return result;
|
|
48438
48610
|
} catch (error) {
|
|
48439
|
-
throw new
|
|
48611
|
+
throw new InternalServerError69("Failed to update user password.");
|
|
48440
48612
|
}
|
|
48441
48613
|
}
|
|
48442
48614
|
async function updateUserFieldById({ _id, field, value } = {}, session) {
|
|
@@ -48456,13 +48628,13 @@ function useUserRepoV2() {
|
|
|
48456
48628
|
);
|
|
48457
48629
|
}
|
|
48458
48630
|
try {
|
|
48459
|
-
_id = new
|
|
48631
|
+
_id = new ObjectId125(_id);
|
|
48460
48632
|
} catch (error) {
|
|
48461
48633
|
throw new BadRequestError198("Invalid ID.");
|
|
48462
48634
|
}
|
|
48463
48635
|
if (field === "defaultOrg") {
|
|
48464
48636
|
try {
|
|
48465
|
-
value = new
|
|
48637
|
+
value = new ObjectId125(value);
|
|
48466
48638
|
} catch (error) {
|
|
48467
48639
|
throw new BadRequestError198("Invalid organization ID.");
|
|
48468
48640
|
}
|
|
@@ -48493,7 +48665,7 @@ function useUserRepoV2() {
|
|
|
48493
48665
|
});
|
|
48494
48666
|
return `Successfully updated user ${field}.`;
|
|
48495
48667
|
} catch (error) {
|
|
48496
|
-
throw new
|
|
48668
|
+
throw new InternalServerError69(`Failed to update user ${field}.`);
|
|
48497
48669
|
}
|
|
48498
48670
|
}
|
|
48499
48671
|
async function updateBirthday({
|
|
@@ -48503,7 +48675,7 @@ function useUserRepoV2() {
|
|
|
48503
48675
|
year
|
|
48504
48676
|
}, session) {
|
|
48505
48677
|
try {
|
|
48506
|
-
_id = new
|
|
48678
|
+
_id = new ObjectId125(_id);
|
|
48507
48679
|
} catch (error) {
|
|
48508
48680
|
throw new BadRequestError198("Invalid user ID format.");
|
|
48509
48681
|
}
|
|
@@ -48528,12 +48700,12 @@ function useUserRepoV2() {
|
|
|
48528
48700
|
});
|
|
48529
48701
|
return "Successfully updated user birthday.";
|
|
48530
48702
|
} catch (error) {
|
|
48531
|
-
throw new
|
|
48703
|
+
throw new InternalServerError69("Failed to update user birthday.");
|
|
48532
48704
|
}
|
|
48533
48705
|
}
|
|
48534
48706
|
async function updatePassword({ _id, password }, session) {
|
|
48535
48707
|
try {
|
|
48536
|
-
_id = new
|
|
48708
|
+
_id = new ObjectId125(_id);
|
|
48537
48709
|
} catch (error) {
|
|
48538
48710
|
throw new BadRequestError198("Invalid user ID format.");
|
|
48539
48711
|
}
|
|
@@ -48551,7 +48723,7 @@ function useUserRepoV2() {
|
|
|
48551
48723
|
});
|
|
48552
48724
|
return result;
|
|
48553
48725
|
} catch (error) {
|
|
48554
|
-
throw new
|
|
48726
|
+
throw new InternalServerError69("Failed to update user password.");
|
|
48555
48727
|
}
|
|
48556
48728
|
}
|
|
48557
48729
|
return {
|
|
@@ -48591,7 +48763,7 @@ function useAuthServiceV2() {
|
|
|
48591
48763
|
);
|
|
48592
48764
|
}
|
|
48593
48765
|
if (!user._id) {
|
|
48594
|
-
throw new
|
|
48766
|
+
throw new InternalServerError70("Valid user ID.");
|
|
48595
48767
|
}
|
|
48596
48768
|
if (user.status === "suspended") {
|
|
48597
48769
|
throw new BadRequestError199(
|
|
@@ -48625,7 +48797,7 @@ function useAuthServiceV2() {
|
|
|
48625
48797
|
await delCache(`sid:${sid}`);
|
|
48626
48798
|
return "Session deleted successfully";
|
|
48627
48799
|
} catch (error) {
|
|
48628
|
-
throw new
|
|
48800
|
+
throw new InternalServerError70("Error deleting token");
|
|
48629
48801
|
}
|
|
48630
48802
|
}
|
|
48631
48803
|
async function verifyPassword(_id, password) {
|
|
@@ -48640,7 +48812,7 @@ function useAuthServiceV2() {
|
|
|
48640
48812
|
if (error instanceof BadRequestError199) {
|
|
48641
48813
|
throw error;
|
|
48642
48814
|
}
|
|
48643
|
-
throw new
|
|
48815
|
+
throw new InternalServerError70("Error during password verification");
|
|
48644
48816
|
}
|
|
48645
48817
|
}
|
|
48646
48818
|
return {
|
|
@@ -48655,9 +48827,9 @@ import {
|
|
|
48655
48827
|
BadRequestError as BadRequestError200,
|
|
48656
48828
|
comparePassword as comparePassword4,
|
|
48657
48829
|
hashPassword as hashPassword5,
|
|
48658
|
-
InternalServerError as
|
|
48830
|
+
InternalServerError as InternalServerError71,
|
|
48659
48831
|
NotFoundError as NotFoundError54,
|
|
48660
|
-
useAtlas as
|
|
48832
|
+
useAtlas as useAtlas114,
|
|
48661
48833
|
useS3 as useS33
|
|
48662
48834
|
} from "@7365admin1/node-server-utils";
|
|
48663
48835
|
import "multer";
|
|
@@ -48684,7 +48856,7 @@ function useUserServiceV2() {
|
|
|
48684
48856
|
id = "",
|
|
48685
48857
|
name = ""
|
|
48686
48858
|
}) {
|
|
48687
|
-
const session =
|
|
48859
|
+
const session = useAtlas114.getClient()?.startSession();
|
|
48688
48860
|
session?.startTransaction();
|
|
48689
48861
|
try {
|
|
48690
48862
|
const signUp = await _getVerificationById(id);
|
|
@@ -48750,12 +48922,12 @@ function useUserServiceV2() {
|
|
|
48750
48922
|
throw new BadRequestError200("Passwords do not match.");
|
|
48751
48923
|
}
|
|
48752
48924
|
let hashedPassword;
|
|
48753
|
-
const session =
|
|
48925
|
+
const session = useAtlas114.getClient()?.startSession();
|
|
48754
48926
|
session?.startTransaction();
|
|
48755
48927
|
try {
|
|
48756
48928
|
hashedPassword = await hashPassword5(newPassword);
|
|
48757
48929
|
} catch (error) {
|
|
48758
|
-
throw new
|
|
48930
|
+
throw new InternalServerError71(`Error hashing password: ${error}`);
|
|
48759
48931
|
}
|
|
48760
48932
|
try {
|
|
48761
48933
|
const otpDoc = await _getVerificationById(id);
|
|
@@ -48770,7 +48942,7 @@ function useUserServiceV2() {
|
|
|
48770
48942
|
throw new NotFoundError54("User not found.");
|
|
48771
48943
|
}
|
|
48772
48944
|
if (!user._id) {
|
|
48773
|
-
throw new
|
|
48945
|
+
throw new InternalServerError71("Invalid user ID.");
|
|
48774
48946
|
}
|
|
48775
48947
|
await Promise.all([
|
|
48776
48948
|
_updateVerificationStatusById(id, "complete" /* COMPLETE */, session),
|
|
@@ -48801,7 +48973,7 @@ function useUserServiceV2() {
|
|
|
48801
48973
|
user,
|
|
48802
48974
|
previousProfile
|
|
48803
48975
|
}) {
|
|
48804
|
-
const session =
|
|
48976
|
+
const session = useAtlas114.getClient()?.startSession();
|
|
48805
48977
|
session?.startTransaction();
|
|
48806
48978
|
const _file = {
|
|
48807
48979
|
name: file.originalname,
|
|
@@ -48845,7 +49017,7 @@ function useUserServiceV2() {
|
|
|
48845
49017
|
try {
|
|
48846
49018
|
hashedPassword = await hashPassword5(newPassword);
|
|
48847
49019
|
if (!hashedPassword)
|
|
48848
|
-
throw new
|
|
49020
|
+
throw new InternalServerError71("Error hashing password.");
|
|
48849
49021
|
return await updatePassword({ _id: id, password: hashedPassword });
|
|
48850
49022
|
} catch (error) {
|
|
48851
49023
|
throw error;
|
|
@@ -49288,9 +49460,182 @@ function useUserControllerV2() {
|
|
|
49288
49460
|
updatePasswordById
|
|
49289
49461
|
};
|
|
49290
49462
|
}
|
|
49463
|
+
|
|
49464
|
+
// src/models/role-v2.model.ts
|
|
49465
|
+
import { BadRequestError as BadRequestError203 } from "@7365admin1/node-server-utils";
|
|
49466
|
+
import { ObjectId as ObjectId126 } from "mongodb";
|
|
49467
|
+
var MRoleV2 = class {
|
|
49468
|
+
constructor(value) {
|
|
49469
|
+
if (typeof value._id === "string") {
|
|
49470
|
+
try {
|
|
49471
|
+
value._id = new ObjectId126(value._id);
|
|
49472
|
+
} catch (error) {
|
|
49473
|
+
throw new BadRequestError203("Invalid role-v2 ID format.");
|
|
49474
|
+
}
|
|
49475
|
+
}
|
|
49476
|
+
if (typeof value.site === "string" && value.site.length === 24) {
|
|
49477
|
+
try {
|
|
49478
|
+
value.site = new ObjectId126(value.site);
|
|
49479
|
+
} catch (error) {
|
|
49480
|
+
throw new BadRequestError203("Invalid site ID format.");
|
|
49481
|
+
}
|
|
49482
|
+
}
|
|
49483
|
+
if (typeof value.org === "string" && value.org.length === 24) {
|
|
49484
|
+
try {
|
|
49485
|
+
value.org = new ObjectId126(value.org);
|
|
49486
|
+
} catch (error) {
|
|
49487
|
+
throw new BadRequestError203("Invalid org ID format.");
|
|
49488
|
+
}
|
|
49489
|
+
}
|
|
49490
|
+
if (value.createdBy) {
|
|
49491
|
+
try {
|
|
49492
|
+
value.createdBy = new ObjectId126(value.createdBy);
|
|
49493
|
+
} catch (error) {
|
|
49494
|
+
throw new BadRequestError203("Invalid created by ID format.");
|
|
49495
|
+
}
|
|
49496
|
+
}
|
|
49497
|
+
this._id = value._id ?? new ObjectId126();
|
|
49498
|
+
this.name = value.name ?? "";
|
|
49499
|
+
this.permissions = value.permissions ?? [];
|
|
49500
|
+
this.site = value.site ?? "";
|
|
49501
|
+
this.platform = value.platform ?? "";
|
|
49502
|
+
this.type = value.type ?? "account";
|
|
49503
|
+
this.org = value.org ?? "";
|
|
49504
|
+
this.status = value.status ?? "active";
|
|
49505
|
+
this.createdBy = value.createdBy ?? "";
|
|
49506
|
+
this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
49507
|
+
this.updatedAt = value.updatedAt ?? "";
|
|
49508
|
+
this.deletedAt = value.deletedAt ?? "";
|
|
49509
|
+
}
|
|
49510
|
+
};
|
|
49511
|
+
|
|
49512
|
+
// src/repositories/role-v2.repo.ts
|
|
49513
|
+
import {
|
|
49514
|
+
BadRequestError as BadRequestError204,
|
|
49515
|
+
InternalServerError as InternalServerError72,
|
|
49516
|
+
useAtlas as useAtlas115,
|
|
49517
|
+
logger as logger182,
|
|
49518
|
+
useCache as useCache69
|
|
49519
|
+
} from "@7365admin1/node-server-utils";
|
|
49520
|
+
function useRoleRepoV2() {
|
|
49521
|
+
const db = useAtlas115.getDb();
|
|
49522
|
+
if (!db) {
|
|
49523
|
+
throw new InternalServerError72("Unable to connect to server.");
|
|
49524
|
+
}
|
|
49525
|
+
const namespace_collection = "roles.v2";
|
|
49526
|
+
const collection = db.collection(namespace_collection);
|
|
49527
|
+
async function createIndex() {
|
|
49528
|
+
try {
|
|
49529
|
+
await collection.createIndexes([
|
|
49530
|
+
{ key: { name: 1 } },
|
|
49531
|
+
{ key: { type: 1 } },
|
|
49532
|
+
{ key: { status: 1 } }
|
|
49533
|
+
]);
|
|
49534
|
+
} catch (error) {
|
|
49535
|
+
throw new InternalServerError72("Failed to create index on role.");
|
|
49536
|
+
}
|
|
49537
|
+
}
|
|
49538
|
+
async function createTextIndex() {
|
|
49539
|
+
try {
|
|
49540
|
+
await collection.createIndex({ name: "text" });
|
|
49541
|
+
} catch (error) {
|
|
49542
|
+
throw new InternalServerError72("Failed to create text index on role.");
|
|
49543
|
+
}
|
|
49544
|
+
}
|
|
49545
|
+
async function createUniqueIndex() {
|
|
49546
|
+
try {
|
|
49547
|
+
await collection.createIndex(
|
|
49548
|
+
{ name: 1, site: 1, platform: 1, type: 1, org: 1, deletedAt: 1 },
|
|
49549
|
+
{ unique: true }
|
|
49550
|
+
);
|
|
49551
|
+
} catch (error) {
|
|
49552
|
+
throw new InternalServerError72("Failed to create unique index on role.");
|
|
49553
|
+
}
|
|
49554
|
+
}
|
|
49555
|
+
const { delNamespace } = useCache69(namespace_collection);
|
|
49556
|
+
async function addRole(value, session) {
|
|
49557
|
+
value = new MRoleV2(value);
|
|
49558
|
+
try {
|
|
49559
|
+
const res = await collection.insertOne(value, { session });
|
|
49560
|
+
delNamespace().then(() => {
|
|
49561
|
+
logger182.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
49562
|
+
}).catch((err) => {
|
|
49563
|
+
logger182.error(
|
|
49564
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
49565
|
+
err
|
|
49566
|
+
);
|
|
49567
|
+
});
|
|
49568
|
+
return res.insertedId;
|
|
49569
|
+
} catch (error) {
|
|
49570
|
+
logger182.log({ level: "error", message: `${error}` });
|
|
49571
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
49572
|
+
if (isDuplicated) {
|
|
49573
|
+
throw new BadRequestError204("Role already exists.");
|
|
49574
|
+
}
|
|
49575
|
+
throw new InternalServerError72("Failed to create role.");
|
|
49576
|
+
}
|
|
49577
|
+
}
|
|
49578
|
+
return {
|
|
49579
|
+
createIndex,
|
|
49580
|
+
createTextIndex,
|
|
49581
|
+
createUniqueIndex,
|
|
49582
|
+
addRole
|
|
49583
|
+
};
|
|
49584
|
+
}
|
|
49585
|
+
|
|
49586
|
+
// src/services/role-v2.service.ts
|
|
49587
|
+
function useRoleServiceV2() {
|
|
49588
|
+
const { addRole: _addRole } = useRoleRepoV2();
|
|
49589
|
+
async function createRole(value) {
|
|
49590
|
+
try {
|
|
49591
|
+
return await _addRole(value);
|
|
49592
|
+
} catch (error) {
|
|
49593
|
+
throw error;
|
|
49594
|
+
}
|
|
49595
|
+
}
|
|
49596
|
+
return { createRole };
|
|
49597
|
+
}
|
|
49598
|
+
|
|
49599
|
+
// src/controllers/role-v2.controller.ts
|
|
49600
|
+
import Joi129 from "joi";
|
|
49601
|
+
import { BadRequestError as BadRequestError205, logger as logger183 } from "@7365admin1/node-server-utils";
|
|
49602
|
+
function useRoleControllerV2() {
|
|
49603
|
+
const { createRole: _createRole } = useRoleServiceV2();
|
|
49604
|
+
async function createRole(req, res, next) {
|
|
49605
|
+
const validation = Joi129.object({
|
|
49606
|
+
name: Joi129.string().required(),
|
|
49607
|
+
site: Joi129.string().hex().required(),
|
|
49608
|
+
platform: Joi129.string().required(),
|
|
49609
|
+
permissions: Joi129.array().items(Joi129.string()).required(),
|
|
49610
|
+
type: Joi129.string().optional().allow("", null),
|
|
49611
|
+
org: Joi129.string().hex().optional().allow("", null)
|
|
49612
|
+
});
|
|
49613
|
+
const payload = { ...req.body };
|
|
49614
|
+
const { error, value } = validation.validate(payload, { abortEarly: false });
|
|
49615
|
+
if (error) {
|
|
49616
|
+
const message = error.details.map((item) => item.message).join(", ");
|
|
49617
|
+
logger183.log({ level: "error", message });
|
|
49618
|
+
next(new BadRequestError205(message));
|
|
49619
|
+
return;
|
|
49620
|
+
}
|
|
49621
|
+
try {
|
|
49622
|
+
const role = await _createRole(value);
|
|
49623
|
+
res.status(201).json({ message: "Successfully created role.", data: { role } });
|
|
49624
|
+
return;
|
|
49625
|
+
} catch (error2) {
|
|
49626
|
+
logger183.log({ level: "error", message: error2.message });
|
|
49627
|
+
next(error2);
|
|
49628
|
+
return;
|
|
49629
|
+
}
|
|
49630
|
+
}
|
|
49631
|
+
return {
|
|
49632
|
+
createRole
|
|
49633
|
+
};
|
|
49634
|
+
}
|
|
49291
49635
|
export {
|
|
49292
49636
|
ANPRMode,
|
|
49293
49637
|
AccessTypeProps,
|
|
49638
|
+
AppServiceType,
|
|
49294
49639
|
BuildingStatus,
|
|
49295
49640
|
BulletinRecipient,
|
|
49296
49641
|
BulletinSort,
|
|
@@ -49351,6 +49696,7 @@ export {
|
|
|
49351
49696
|
MPromoCode,
|
|
49352
49697
|
MRobot,
|
|
49353
49698
|
MRole,
|
|
49699
|
+
MRoleV2,
|
|
49354
49700
|
MServiceProvider,
|
|
49355
49701
|
MServiceProviderBilling,
|
|
49356
49702
|
MSession,
|
|
@@ -49373,6 +49719,7 @@ export {
|
|
|
49373
49719
|
OvernightParkingRequestStatus,
|
|
49374
49720
|
PERSON_TYPES,
|
|
49375
49721
|
PMDashboardCollection,
|
|
49722
|
+
PStatus,
|
|
49376
49723
|
Period,
|
|
49377
49724
|
PersonStatus,
|
|
49378
49725
|
PersonTypes,
|
|
@@ -49380,6 +49727,7 @@ export {
|
|
|
49380
49727
|
SiteStatus,
|
|
49381
49728
|
SortFields,
|
|
49382
49729
|
SortOrder,
|
|
49730
|
+
Status,
|
|
49383
49731
|
SubscriptionType,
|
|
49384
49732
|
UseAccessManagementRepo,
|
|
49385
49733
|
UserStatus,
|
|
@@ -49634,7 +49982,10 @@ export {
|
|
|
49634
49982
|
useRobotRepo,
|
|
49635
49983
|
useRobotService,
|
|
49636
49984
|
useRoleController,
|
|
49985
|
+
useRoleControllerV2,
|
|
49637
49986
|
useRoleRepo,
|
|
49987
|
+
useRoleRepoV2,
|
|
49988
|
+
useRoleServiceV2,
|
|
49638
49989
|
useServiceProviderBillingController,
|
|
49639
49990
|
useServiceProviderBillingRepo,
|
|
49640
49991
|
useServiceProviderBillingService,
|