@7365admin1/core 2.36.1 → 2.38.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 +118 -77
- package/dist/index.js +943 -822
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +752 -637
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.mjs
CHANGED
|
@@ -4842,6 +4842,7 @@ function useSiteRepo() {
|
|
|
4842
4842
|
|
|
4843
4843
|
// src/services/verification.service.ts
|
|
4844
4844
|
import Joi11 from "joi";
|
|
4845
|
+
import path from "path";
|
|
4845
4846
|
function useVerificationService() {
|
|
4846
4847
|
const MailerConfig = {
|
|
4847
4848
|
host: MAILER_TRANSPORT_HOST,
|
|
@@ -4872,7 +4873,6 @@ function useVerificationService() {
|
|
|
4872
4873
|
expireAt: new Date(
|
|
4873
4874
|
(/* @__PURE__ */ new Date()).getTime() + 72 * 60 * 60 * 1e3
|
|
4874
4875
|
).toISOString(),
|
|
4875
|
-
// 72 hours (3 days) from now
|
|
4876
4876
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4877
4877
|
};
|
|
4878
4878
|
if (value.metadata?.org)
|
|
@@ -4960,8 +4960,11 @@ function useVerificationService() {
|
|
|
4960
4960
|
subject = "Service Provider Organization Invite";
|
|
4961
4961
|
}
|
|
4962
4962
|
const res = await add(value);
|
|
4963
|
-
const
|
|
4964
|
-
|
|
4963
|
+
const filePath = path.resolve(
|
|
4964
|
+
__dirname,
|
|
4965
|
+
"../public/handlebars",
|
|
4966
|
+
value.type
|
|
4967
|
+
);
|
|
4965
4968
|
const link = org ? `${APP_MAIN}/verify/${value.type}/${res}` : `${APP_ORG}/organizations/create?email=${email}`;
|
|
4966
4969
|
const emailContent = compileHandlebar({
|
|
4967
4970
|
context: {
|
|
@@ -4997,6 +5000,9 @@ function useVerificationService() {
|
|
|
4997
5000
|
};
|
|
4998
5001
|
try {
|
|
4999
5002
|
const user = await getUserByEmail(email);
|
|
5003
|
+
if (!user) {
|
|
5004
|
+
throw new NotFoundError9("Email not found");
|
|
5005
|
+
}
|
|
5000
5006
|
const res = await add(value);
|
|
5001
5007
|
const dir = __dirname;
|
|
5002
5008
|
const filePath = getDirectory(dir, "./public/handlebars/forget-password");
|
|
@@ -13185,19 +13191,19 @@ var schemaVisitorTransaction = Joi36.object({
|
|
|
13185
13191
|
numberOfPassengers: Joi36.number().integer().optional().allow(null, ""),
|
|
13186
13192
|
visitorPass: Joi36.array().items(
|
|
13187
13193
|
Joi36.object({
|
|
13188
|
-
keyId: Joi36.string().hex().length(24).
|
|
13194
|
+
keyId: Joi36.string().hex().length(24).allow(null, "")
|
|
13189
13195
|
})
|
|
13190
13196
|
).optional().allow(null),
|
|
13191
13197
|
passKeys: Joi36.array().items(
|
|
13192
13198
|
Joi36.object({
|
|
13193
|
-
keyId: Joi36.string().hex().length(24).
|
|
13199
|
+
keyId: Joi36.string().hex().length(24).allow(null, "")
|
|
13194
13200
|
})
|
|
13195
13201
|
).optional().allow(null),
|
|
13196
13202
|
checkInRemarks: Joi36.string().optional().allow("", null),
|
|
13197
13203
|
checkOutRemarks: Joi36.string().optional().allow("", null),
|
|
13198
13204
|
expectedCheckIn: Joi36.string().isoDate().optional(),
|
|
13199
13205
|
purpose: Joi36.string().optional().allow(null, ""),
|
|
13200
|
-
|
|
13206
|
+
inviterId: Joi36.any().optional().allow(null, "")
|
|
13201
13207
|
});
|
|
13202
13208
|
var schemaUpdateVisTrans = Joi36.object({
|
|
13203
13209
|
_id: Joi36.string().hex().length(24).required(),
|
|
@@ -13306,14 +13312,14 @@ function MVisitorTransaction(value) {
|
|
|
13306
13312
|
return p;
|
|
13307
13313
|
});
|
|
13308
13314
|
}
|
|
13309
|
-
if (value.
|
|
13315
|
+
if (value.inviterId && typeof value.inviterId === "string") {
|
|
13310
13316
|
try {
|
|
13311
|
-
value.
|
|
13317
|
+
value.inviterId = new ObjectId39(value.inviterId);
|
|
13312
13318
|
} catch (error2) {
|
|
13313
|
-
throw new Error("Invalid
|
|
13319
|
+
throw new Error("Invalid inviter ID.");
|
|
13314
13320
|
}
|
|
13315
13321
|
}
|
|
13316
|
-
const newDate =
|
|
13322
|
+
const newDate = /* @__PURE__ */ new Date();
|
|
13317
13323
|
return {
|
|
13318
13324
|
_id: value._id,
|
|
13319
13325
|
name: value.name,
|
|
@@ -13328,7 +13334,7 @@ function MVisitorTransaction(value) {
|
|
|
13328
13334
|
plateNumber: value.plateNumber,
|
|
13329
13335
|
recNo: value.recNo,
|
|
13330
13336
|
checkIn: value.checkIn === void 0 ? newDate : value.checkIn,
|
|
13331
|
-
expectedCheckIn: value.expectedCheckIn,
|
|
13337
|
+
expectedCheckIn: value.expectedCheckIn ? new Date(value.expectedCheckIn) : void 0,
|
|
13332
13338
|
checkOut: value.checkOut,
|
|
13333
13339
|
status: value.status,
|
|
13334
13340
|
remarks: value.remarks,
|
|
@@ -13353,12 +13359,14 @@ function MVisitorTransaction(value) {
|
|
|
13353
13359
|
numberOfPassengers: value.numberOfPassengers ?? null,
|
|
13354
13360
|
email: value.email,
|
|
13355
13361
|
isOvernightParking: value.isOvernightParking ?? false,
|
|
13356
|
-
|
|
13362
|
+
inviterId: value.inviterId ?? "",
|
|
13357
13363
|
overnightParking: value.isOvernightParking == true ? {
|
|
13358
13364
|
status: "pending approval",
|
|
13359
13365
|
remarks: "",
|
|
13360
|
-
updatedBy: value.
|
|
13361
|
-
} : null
|
|
13366
|
+
updatedBy: value.inviterId ?? ""
|
|
13367
|
+
} : null,
|
|
13368
|
+
arrivalTime: value.arrivalTime,
|
|
13369
|
+
duration: value.duration
|
|
13362
13370
|
};
|
|
13363
13371
|
}
|
|
13364
13372
|
|
|
@@ -13406,47 +13414,42 @@ function useVisitorTransactionRepo() {
|
|
|
13406
13414
|
page = 1,
|
|
13407
13415
|
limit = 10,
|
|
13408
13416
|
sort = {},
|
|
13409
|
-
status
|
|
13417
|
+
status,
|
|
13410
13418
|
org = "",
|
|
13411
13419
|
site = "",
|
|
13412
13420
|
dateTo = "",
|
|
13413
13421
|
dateFrom = "",
|
|
13414
13422
|
type = "",
|
|
13415
13423
|
checkedOut,
|
|
13416
|
-
plateNumber = ""
|
|
13424
|
+
plateNumber = "",
|
|
13425
|
+
tab = ""
|
|
13417
13426
|
}) {
|
|
13418
13427
|
page = page > 0 ? page - 1 : 0;
|
|
13419
13428
|
const skip = page * limit;
|
|
13420
|
-
|
|
13421
|
-
const
|
|
13422
|
-
if (
|
|
13423
|
-
|
|
13424
|
-
|
|
13425
|
-
|
|
13426
|
-
|
|
13427
|
-
|
|
13428
|
-
|
|
13429
|
-
|
|
13430
|
-
|
|
13431
|
-
|
|
13432
|
-
};
|
|
13433
|
-
} else if (dateTo) {
|
|
13434
|
-
checkOutFilter = {
|
|
13435
|
-
$or: [
|
|
13436
|
-
{ checkOut: { $lte: new Date(dateTo).toISOString() } },
|
|
13437
|
-
{ checkOut: null }
|
|
13438
|
-
]
|
|
13439
|
-
};
|
|
13429
|
+
const checkInFilter = {};
|
|
13430
|
+
const expectedCheckInFilter = {};
|
|
13431
|
+
if (status != "approved") {
|
|
13432
|
+
if (dateFrom)
|
|
13433
|
+
checkInFilter.$gte = new Date(dateFrom);
|
|
13434
|
+
if (dateTo)
|
|
13435
|
+
checkInFilter.$lte = new Date(dateTo);
|
|
13436
|
+
} else {
|
|
13437
|
+
if (dateFrom)
|
|
13438
|
+
expectedCheckInFilter.$gte = new Date(dateFrom);
|
|
13439
|
+
if (dateTo)
|
|
13440
|
+
expectedCheckInFilter.$lte = new Date(dateTo);
|
|
13440
13441
|
}
|
|
13441
13442
|
const query = {
|
|
13442
|
-
status,
|
|
13443
13443
|
...ObjectId40.isValid(org) && { org: new ObjectId40(org) },
|
|
13444
13444
|
...ObjectId40.isValid(site) && { site: new ObjectId40(site) },
|
|
13445
|
-
...
|
|
13445
|
+
...Object.keys(checkInFilter).length > 0 && { checkIn: checkInFilter },
|
|
13446
|
+
...Object.keys(expectedCheckInFilter).length > 0 && { expectedCheckIn: expectedCheckInFilter },
|
|
13446
13447
|
...Array.isArray(type) ? { type: { $in: type } } : type ? { type } : {},
|
|
13447
|
-
...
|
|
13448
|
+
...checkedOut == false && { checkOut: { $eq: null } },
|
|
13448
13449
|
...search && { $text: { $search: search } },
|
|
13449
|
-
...plateNumber && { plateNumber }
|
|
13450
|
+
...plateNumber && { plateNumber },
|
|
13451
|
+
...status && { status },
|
|
13452
|
+
...tab == "Overnight Parking" && { isOvernightParking: true }
|
|
13450
13453
|
};
|
|
13451
13454
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
13452
13455
|
try {
|
|
@@ -13592,7 +13595,31 @@ function useVisitorTransactionRepo() {
|
|
|
13592
13595
|
},
|
|
13593
13596
|
{ $sort: sort },
|
|
13594
13597
|
{ $skip: skip },
|
|
13595
|
-
{ $limit: limit }
|
|
13598
|
+
{ $limit: limit },
|
|
13599
|
+
{
|
|
13600
|
+
$lookup: {
|
|
13601
|
+
from: "users",
|
|
13602
|
+
localField: "inviterId",
|
|
13603
|
+
foreignField: "_id",
|
|
13604
|
+
as: "inviterData"
|
|
13605
|
+
}
|
|
13606
|
+
},
|
|
13607
|
+
{
|
|
13608
|
+
$unwind: {
|
|
13609
|
+
path: "$inviterData",
|
|
13610
|
+
preserveNullAndEmptyArrays: true
|
|
13611
|
+
}
|
|
13612
|
+
},
|
|
13613
|
+
{
|
|
13614
|
+
$addFields: {
|
|
13615
|
+
inviterName: "$inviterData.name"
|
|
13616
|
+
}
|
|
13617
|
+
},
|
|
13618
|
+
{
|
|
13619
|
+
$project: {
|
|
13620
|
+
inviterData: 0
|
|
13621
|
+
}
|
|
13622
|
+
}
|
|
13596
13623
|
]).toArray(),
|
|
13597
13624
|
collection.aggregate([...basePipeline, { $count: "total" }]).toArray()
|
|
13598
13625
|
]);
|
|
@@ -13667,7 +13694,7 @@ function useVisitorTransactionRepo() {
|
|
|
13667
13694
|
} catch (error) {
|
|
13668
13695
|
throw new BadRequestError66("Invalid visitor transaction ID format.");
|
|
13669
13696
|
}
|
|
13670
|
-
value.updatedAt =
|
|
13697
|
+
value.updatedAt = /* @__PURE__ */ new Date();
|
|
13671
13698
|
if (value.checkOut) {
|
|
13672
13699
|
value.manualCheckout = true;
|
|
13673
13700
|
}
|
|
@@ -13691,8 +13718,8 @@ function useVisitorTransactionRepo() {
|
|
|
13691
13718
|
try {
|
|
13692
13719
|
const updateValue = {
|
|
13693
13720
|
status: "deleted",
|
|
13694
|
-
updatedAt:
|
|
13695
|
-
deletedAt:
|
|
13721
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
13722
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
13696
13723
|
};
|
|
13697
13724
|
const res = await collection.updateOne({ _id }, { $set: updateValue });
|
|
13698
13725
|
if (res.modifiedCount === 0) {
|
|
@@ -13705,7 +13732,7 @@ function useVisitorTransactionRepo() {
|
|
|
13705
13732
|
}
|
|
13706
13733
|
async function getDeliveryPickupTransactions() {
|
|
13707
13734
|
try {
|
|
13708
|
-
const now =
|
|
13735
|
+
const now = /* @__PURE__ */ new Date();
|
|
13709
13736
|
const result = await collection.find(
|
|
13710
13737
|
{
|
|
13711
13738
|
type: {
|
|
@@ -13732,7 +13759,7 @@ function useVisitorTransactionRepo() {
|
|
|
13732
13759
|
async function getExpiredCheckedOutTransactionsBySite(siteId) {
|
|
13733
13760
|
const site = toObjectId7(siteId);
|
|
13734
13761
|
try {
|
|
13735
|
-
const now =
|
|
13762
|
+
const now = /* @__PURE__ */ new Date();
|
|
13736
13763
|
const expiredTransactions = await collection.find({
|
|
13737
13764
|
$or: [
|
|
13738
13765
|
{ expiredAt: { $lte: now } },
|
|
@@ -13758,7 +13785,7 @@ function useVisitorTransactionRepo() {
|
|
|
13758
13785
|
{
|
|
13759
13786
|
$set: {
|
|
13760
13787
|
dahuaSyncStatus,
|
|
13761
|
-
updatedAt:
|
|
13788
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
13762
13789
|
}
|
|
13763
13790
|
},
|
|
13764
13791
|
{ session }
|
|
@@ -13908,7 +13935,7 @@ function MVehicle(value) {
|
|
|
13908
13935
|
block: value.block ?? 0,
|
|
13909
13936
|
level: value.level ?? "",
|
|
13910
13937
|
unit: value.unit ?? "",
|
|
13911
|
-
nric: value.nric,
|
|
13938
|
+
nric: value.nric ?? "",
|
|
13912
13939
|
remarks: value.remarks ?? "",
|
|
13913
13940
|
seasonPassType: value.seasonPassType ?? "",
|
|
13914
13941
|
start: value.start ?? createdAt,
|
|
@@ -13968,7 +13995,7 @@ function MVehicleTransaction(value) {
|
|
|
13968
13995
|
import { BadRequestError as BadRequestError71, logger as logger52 } from "@7365admin1/node-server-utils";
|
|
13969
13996
|
import { promises as fsAsync } from "fs";
|
|
13970
13997
|
import Joi39 from "joi";
|
|
13971
|
-
import * as
|
|
13998
|
+
import * as path2 from "path";
|
|
13972
13999
|
import { request } from "urllib";
|
|
13973
14000
|
|
|
13974
14001
|
// src/repositories/vehicle.repo.ts
|
|
@@ -14612,6 +14639,66 @@ function useVehicleRepo() {
|
|
|
14612
14639
|
throw error;
|
|
14613
14640
|
}
|
|
14614
14641
|
}
|
|
14642
|
+
async function bulkUpsertVehicles(values, session) {
|
|
14643
|
+
try {
|
|
14644
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
14645
|
+
return {
|
|
14646
|
+
matchedCount: 0,
|
|
14647
|
+
modifiedCount: 0,
|
|
14648
|
+
upsertedCount: 0
|
|
14649
|
+
};
|
|
14650
|
+
}
|
|
14651
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
14652
|
+
const operations = values.map((item) => {
|
|
14653
|
+
const vehicle = MVehicle(item);
|
|
14654
|
+
const plateNumber = Array.isArray(vehicle.plateNumber) ? vehicle.plateNumber[0] : vehicle.plateNumber;
|
|
14655
|
+
const { createdAt, ...rest } = vehicle;
|
|
14656
|
+
return {
|
|
14657
|
+
updateOne: {
|
|
14658
|
+
filter: {
|
|
14659
|
+
site: vehicle.site,
|
|
14660
|
+
plateNumber,
|
|
14661
|
+
$or: [
|
|
14662
|
+
{ deletedAt: "" },
|
|
14663
|
+
{ deletedAt: null },
|
|
14664
|
+
{ deletedAt: { $exists: false } }
|
|
14665
|
+
]
|
|
14666
|
+
},
|
|
14667
|
+
update: {
|
|
14668
|
+
$set: {
|
|
14669
|
+
...rest,
|
|
14670
|
+
plateNumber,
|
|
14671
|
+
updatedAt: now
|
|
14672
|
+
},
|
|
14673
|
+
$setOnInsert: {
|
|
14674
|
+
createdAt: vehicle.createdAt || now
|
|
14675
|
+
}
|
|
14676
|
+
},
|
|
14677
|
+
upsert: true
|
|
14678
|
+
}
|
|
14679
|
+
};
|
|
14680
|
+
});
|
|
14681
|
+
const res = await collection.bulkWrite(operations, {
|
|
14682
|
+
ordered: false,
|
|
14683
|
+
session
|
|
14684
|
+
});
|
|
14685
|
+
return {
|
|
14686
|
+
matchedCount: res.matchedCount,
|
|
14687
|
+
modifiedCount: res.modifiedCount,
|
|
14688
|
+
upsertedCount: res.upsertedCount,
|
|
14689
|
+
upsertedIds: res.upsertedIds
|
|
14690
|
+
};
|
|
14691
|
+
} catch (error) {
|
|
14692
|
+
logger49.log({
|
|
14693
|
+
level: "error",
|
|
14694
|
+
message: error.message
|
|
14695
|
+
});
|
|
14696
|
+
if (error instanceof AppError9) {
|
|
14697
|
+
throw error;
|
|
14698
|
+
}
|
|
14699
|
+
throw new Error("Failed to bulk upsert vehicles.");
|
|
14700
|
+
}
|
|
14701
|
+
}
|
|
14615
14702
|
return {
|
|
14616
14703
|
createIndex,
|
|
14617
14704
|
createTextIndex,
|
|
@@ -14626,7 +14713,8 @@ function useVehicleRepo() {
|
|
|
14626
14713
|
getVehiclesByNRIC,
|
|
14627
14714
|
deleteExpiredVehicles,
|
|
14628
14715
|
getAllVehiclesByUnitId,
|
|
14629
|
-
getAllExpiredVehicles
|
|
14716
|
+
getAllExpiredVehicles,
|
|
14717
|
+
bulkUpsertVehicles
|
|
14630
14718
|
};
|
|
14631
14719
|
}
|
|
14632
14720
|
|
|
@@ -15272,7 +15360,8 @@ function useVehicleService() {
|
|
|
15272
15360
|
getVehicleById: _getVehicleById,
|
|
15273
15361
|
deleteExpiredVehicles: _deleteExpiredVehicles,
|
|
15274
15362
|
getVehicleByPlateNumber: _getVehicleByPlateNumber,
|
|
15275
|
-
getAllExpiredVehicles: _getAllExpiredVehicles
|
|
15363
|
+
getAllExpiredVehicles: _getAllExpiredVehicles,
|
|
15364
|
+
bulkUpsertVehicles: _bulkUpsertVehicles
|
|
15276
15365
|
} = useVehicleRepo();
|
|
15277
15366
|
const {
|
|
15278
15367
|
addPlateNumber: _addPlateNumber,
|
|
@@ -15889,13 +15978,38 @@ function useVehicleService() {
|
|
|
15889
15978
|
session.endSession();
|
|
15890
15979
|
}
|
|
15891
15980
|
}
|
|
15981
|
+
async function bulkUpsertVehicles(values) {
|
|
15982
|
+
const session = useAtlas33.getClient()?.startSession();
|
|
15983
|
+
if (!session) {
|
|
15984
|
+
throw new Error("Unable to start session for vehicle service.");
|
|
15985
|
+
}
|
|
15986
|
+
try {
|
|
15987
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
15988
|
+
throw new Error("Vehicle list is required.");
|
|
15989
|
+
}
|
|
15990
|
+
const sanitizedValues = values.map((item) => {
|
|
15991
|
+
const plateNumber = Array.isArray(item.plateNumber) ? item.plateNumber[0] : item.plateNumber;
|
|
15992
|
+
return {
|
|
15993
|
+
...item,
|
|
15994
|
+
plateNumber: typeof plateNumber === "string" ? plateNumber.trim() : plateNumber
|
|
15995
|
+
};
|
|
15996
|
+
}).filter((item) => item.site && item.plateNumber);
|
|
15997
|
+
if (sanitizedValues.length === 0) {
|
|
15998
|
+
throw new Error("No valid vehicle plate numbers found.");
|
|
15999
|
+
}
|
|
16000
|
+
return await _bulkUpsertVehicles(sanitizedValues, session);
|
|
16001
|
+
} catch (error) {
|
|
16002
|
+
throw error;
|
|
16003
|
+
}
|
|
16004
|
+
}
|
|
15892
16005
|
return {
|
|
15893
16006
|
add,
|
|
15894
16007
|
deleteVehicle,
|
|
15895
16008
|
approveVehicleById,
|
|
15896
16009
|
processDeletingExpiredVehicles,
|
|
15897
16010
|
reactivateVehicleById,
|
|
15898
|
-
updateVehicleById
|
|
16011
|
+
updateVehicleById,
|
|
16012
|
+
bulkUpsertVehicles
|
|
15899
16013
|
};
|
|
15900
16014
|
}
|
|
15901
16015
|
|
|
@@ -16169,8 +16283,8 @@ function useDahuaService() {
|
|
|
16169
16283
|
const utcMs = Number(UTCMs) || Date.now() % 1e3;
|
|
16170
16284
|
const timeData = createFileNameFromEvent(utcSec, utcMs);
|
|
16171
16285
|
const filename = plateNumber ? `${gate}-${timeData}-${plateNumber}.jpeg` : `${gate}-${timeData}.jpeg`;
|
|
16172
|
-
const snapFolder =
|
|
16173
|
-
const dir =
|
|
16286
|
+
const snapFolder = path2.join(__dirname, `../snap/${site}/${filename}`);
|
|
16287
|
+
const dir = path2.dirname(snapFolder);
|
|
16174
16288
|
try {
|
|
16175
16289
|
await fsAsync.mkdir(dir, { recursive: true });
|
|
16176
16290
|
await fsAsync.writeFile(snapFolder, accumulatedImageBuffer);
|
|
@@ -16997,13 +17111,15 @@ var schemaBuilding = Joi43.object({
|
|
|
16997
17111
|
updatedAt: Joi43.date().optional().allow("", null),
|
|
16998
17112
|
deletedAt: Joi43.date().optional().allow("", null),
|
|
16999
17113
|
status: Joi43.string().optional().allow("", null),
|
|
17000
|
-
buildingFloorPlan:
|
|
17114
|
+
// buildingFloorPlan: Joi.array().items(Joi.string()).optional(),
|
|
17115
|
+
buildingFiles: Joi43.array().items({ id: Joi43.string().hex().optional().allow("", null), name: Joi43.string().optional().allow("", null) }).optional().allow("", null)
|
|
17001
17116
|
});
|
|
17002
17117
|
var schemaBuildingUpdateOptions = Joi43.object({
|
|
17003
17118
|
name: Joi43.string().optional().allow("", null),
|
|
17004
17119
|
levels: Joi43.array().items(Joi43.string().required()).min(1).required(),
|
|
17005
17120
|
block: Joi43.number().integer().min(1).required(),
|
|
17006
|
-
buildingFloorPlan:
|
|
17121
|
+
// buildingFloorPlan: Joi.array().items(Joi.string()).optional(),
|
|
17122
|
+
buildingFiles: Joi43.array().items({ id: Joi43.string().hex().optional().allow("", null), name: Joi43.string().optional().allow("", null) }).optional().allow("", null)
|
|
17007
17123
|
});
|
|
17008
17124
|
var schemaBilling = Joi43.object({
|
|
17009
17125
|
_id: Joi43.string().hex().optional(),
|
|
@@ -17069,7 +17185,8 @@ function MBuilding(value) {
|
|
|
17069
17185
|
block: value.block ?? 0,
|
|
17070
17186
|
levels: value.levels ?? "",
|
|
17071
17187
|
status: value.status ?? "active",
|
|
17072
|
-
buildingFloorPlan: value.buildingFloorPlan ?? [],
|
|
17188
|
+
// buildingFloorPlan: value.buildingFloorPlan ?? [],
|
|
17189
|
+
buildingFiles: value.buildingFiles ?? [],
|
|
17073
17190
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
17074
17191
|
updatedAt: value.updatedAt ?? "",
|
|
17075
17192
|
deletedAt: value.deletedAt ?? ""
|
|
@@ -17999,11 +18116,11 @@ function useBuildingService() {
|
|
|
17999
18116
|
}
|
|
18000
18117
|
try {
|
|
18001
18118
|
await session.startTransaction();
|
|
18002
|
-
const
|
|
18003
|
-
if (
|
|
18004
|
-
for (const
|
|
18119
|
+
const buildingFiles = value?.buildingFiles ?? [];
|
|
18120
|
+
if (buildingFiles.length > 0) {
|
|
18121
|
+
for (const buildingFile of buildingFiles) {
|
|
18005
18122
|
const file = await updateStatusById(
|
|
18006
|
-
|
|
18123
|
+
buildingFile.id,
|
|
18007
18124
|
{ status: "active" },
|
|
18008
18125
|
session
|
|
18009
18126
|
);
|
|
@@ -18037,12 +18154,12 @@ function useBuildingService() {
|
|
|
18037
18154
|
if (!building) {
|
|
18038
18155
|
throw new NotFoundError18("Building not found.");
|
|
18039
18156
|
}
|
|
18040
|
-
const
|
|
18041
|
-
const
|
|
18157
|
+
const dataFiles = data?.buildingFiles || [];
|
|
18158
|
+
const buildingFiles = building?.buildingFiles || [];
|
|
18042
18159
|
const deletedFiles = [];
|
|
18043
|
-
|
|
18044
|
-
if (!
|
|
18045
|
-
deletedFiles.push(
|
|
18160
|
+
buildingFiles.forEach((file) => {
|
|
18161
|
+
if (!dataFiles.find((f) => f.id === file.id)) {
|
|
18162
|
+
deletedFiles.push(file.id);
|
|
18046
18163
|
}
|
|
18047
18164
|
});
|
|
18048
18165
|
if (deletedFiles.length > 0) {
|
|
@@ -18138,7 +18255,8 @@ function useBuildingController() {
|
|
|
18138
18255
|
levels: Joi44.array().items(Joi44.string().required()).min(1).required(),
|
|
18139
18256
|
serial: Joi44.string().optional().allow("", null),
|
|
18140
18257
|
status: Joi44.string().optional().allow("", null),
|
|
18141
|
-
buildingFloorPlan:
|
|
18258
|
+
// buildingFloorPlan: Joi.array().items(Joi.string()).optional(),
|
|
18259
|
+
buildingFiles: Joi44.array().items({ id: Joi44.string().hex().optional().allow("", null), name: Joi44.string().optional().allow("", null) }).optional().allow("", null)
|
|
18142
18260
|
});
|
|
18143
18261
|
const { error } = validation.validate(value);
|
|
18144
18262
|
if (error) {
|
|
@@ -18601,13 +18719,18 @@ function useBuildingUnitController() {
|
|
|
18601
18719
|
// src/controllers/vehicle.controller.ts
|
|
18602
18720
|
import { BadRequestError as BadRequestError83, logger as logger65 } from "@7365admin1/node-server-utils";
|
|
18603
18721
|
import Joi46 from "joi";
|
|
18722
|
+
import ExcelJS from "exceljs";
|
|
18723
|
+
import { Readable } from "stream";
|
|
18724
|
+
import csv from "csv-parser";
|
|
18725
|
+
import fs from "fs";
|
|
18604
18726
|
function useVehicleController() {
|
|
18605
18727
|
const {
|
|
18606
18728
|
add: _add,
|
|
18607
18729
|
deleteVehicle: _deleteVehicle,
|
|
18608
18730
|
approveVehicleById: _approveVehicleById,
|
|
18609
18731
|
reactivateVehicleById: _reactivateVehicleById,
|
|
18610
|
-
updateVehicleById: _updateVehicleById
|
|
18732
|
+
updateVehicleById: _updateVehicleById,
|
|
18733
|
+
bulkUpsertVehicles: _bulkUpsertVehicles
|
|
18611
18734
|
} = useVehicleService();
|
|
18612
18735
|
const {
|
|
18613
18736
|
getSeasonPassTypes: _getSeasonPassTypes,
|
|
@@ -18616,6 +18739,141 @@ function useVehicleController() {
|
|
|
18616
18739
|
getVehiclesByNRIC: _getVehiclesByNRIC,
|
|
18617
18740
|
getAllVehiclesByUnitId: _getAllVehiclesByUnitId
|
|
18618
18741
|
} = useVehicleRepo();
|
|
18742
|
+
function normalizeRow(row) {
|
|
18743
|
+
return Object.fromEntries(
|
|
18744
|
+
Object.entries(row).map(([key, value]) => [
|
|
18745
|
+
key,
|
|
18746
|
+
typeof value === "string" ? value.trim() : value
|
|
18747
|
+
])
|
|
18748
|
+
);
|
|
18749
|
+
}
|
|
18750
|
+
function mapRowToVehicle(row) {
|
|
18751
|
+
const cleanRow = normalizeRow(row);
|
|
18752
|
+
return {
|
|
18753
|
+
name: cleanRow.fullName,
|
|
18754
|
+
category: cleanRow.userType,
|
|
18755
|
+
type: cleanRow.recordType,
|
|
18756
|
+
phoneNumber: cleanRow.phoneNumber || "",
|
|
18757
|
+
block: Number(cleanRow.block),
|
|
18758
|
+
level: String(cleanRow.level || ""),
|
|
18759
|
+
unitName: String(cleanRow.unit || ""),
|
|
18760
|
+
plateNumber: String(cleanRow.plateNumber || "").toUpperCase(),
|
|
18761
|
+
remarks: `Model: ${cleanRow.vehicleModel || ""}, Color: ${cleanRow.vehicleColor || ""}`,
|
|
18762
|
+
org: cleanRow.org,
|
|
18763
|
+
site: cleanRow.site,
|
|
18764
|
+
end: parseExpiryDate(cleanRow.subscriptionExpiry)
|
|
18765
|
+
};
|
|
18766
|
+
}
|
|
18767
|
+
function parseExpiryDate(value) {
|
|
18768
|
+
if (!value)
|
|
18769
|
+
return void 0;
|
|
18770
|
+
const [day, monthStr, yearShort] = value.split("-");
|
|
18771
|
+
const months = {
|
|
18772
|
+
Jan: 0,
|
|
18773
|
+
Feb: 1,
|
|
18774
|
+
Mar: 2,
|
|
18775
|
+
Apr: 3,
|
|
18776
|
+
May: 4,
|
|
18777
|
+
Jun: 5,
|
|
18778
|
+
Jul: 6,
|
|
18779
|
+
Aug: 7,
|
|
18780
|
+
Sep: 8,
|
|
18781
|
+
Oct: 9,
|
|
18782
|
+
Nov: 10,
|
|
18783
|
+
Dec: 11
|
|
18784
|
+
};
|
|
18785
|
+
const month = months[monthStr];
|
|
18786
|
+
if (month === void 0)
|
|
18787
|
+
return void 0;
|
|
18788
|
+
const year = 2e3 + Number(yearShort);
|
|
18789
|
+
const date = new Date(year, month, Number(day));
|
|
18790
|
+
return isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
18791
|
+
}
|
|
18792
|
+
async function uploadCsvVehicles(req, res, next) {
|
|
18793
|
+
try {
|
|
18794
|
+
if (!req.file) {
|
|
18795
|
+
next(new BadRequestError83("CSV file is required."));
|
|
18796
|
+
return;
|
|
18797
|
+
}
|
|
18798
|
+
if (!req.file.originalname.toLowerCase().endsWith(".csv")) {
|
|
18799
|
+
next(new BadRequestError83("Only .csv files are allowed."));
|
|
18800
|
+
return;
|
|
18801
|
+
}
|
|
18802
|
+
const rows = [];
|
|
18803
|
+
const stream = Readable.from(req.file.buffer);
|
|
18804
|
+
stream.pipe(csv()).on("data", (row) => {
|
|
18805
|
+
rows.push(row);
|
|
18806
|
+
}).on("end", async () => {
|
|
18807
|
+
try {
|
|
18808
|
+
const vehicles = rows.map(mapRowToVehicle);
|
|
18809
|
+
const data = await _bulkUpsertVehicles(vehicles);
|
|
18810
|
+
res.status(200).json({
|
|
18811
|
+
message: "CSV import completed.",
|
|
18812
|
+
count: rows.length,
|
|
18813
|
+
data
|
|
18814
|
+
});
|
|
18815
|
+
} catch (error) {
|
|
18816
|
+
logger65.log({ level: "error", message: error.message });
|
|
18817
|
+
next(error);
|
|
18818
|
+
}
|
|
18819
|
+
}).on("error", (error) => {
|
|
18820
|
+
logger65.log({ level: "error", message: error.message });
|
|
18821
|
+
next(error);
|
|
18822
|
+
});
|
|
18823
|
+
} catch (error) {
|
|
18824
|
+
logger65.log({ level: "error", message: error.message });
|
|
18825
|
+
next(error);
|
|
18826
|
+
}
|
|
18827
|
+
}
|
|
18828
|
+
async function uploadExcelVehicles(req, res, next) {
|
|
18829
|
+
try {
|
|
18830
|
+
if (!req.file) {
|
|
18831
|
+
next(new BadRequestError83("Excel file is required."));
|
|
18832
|
+
return;
|
|
18833
|
+
}
|
|
18834
|
+
if (!req.file.originalname.toLowerCase().endsWith(".xlsx")) {
|
|
18835
|
+
next(new BadRequestError83("Only .xlsx files are allowed."));
|
|
18836
|
+
return;
|
|
18837
|
+
}
|
|
18838
|
+
const workbook = new ExcelJS.Workbook();
|
|
18839
|
+
await workbook.xlsx.readFile(req.file.path);
|
|
18840
|
+
const worksheet = workbook.worksheets[0];
|
|
18841
|
+
if (!worksheet) {
|
|
18842
|
+
next(new BadRequestError83("No worksheet found in uploaded Excel file."));
|
|
18843
|
+
return;
|
|
18844
|
+
}
|
|
18845
|
+
const rows = [];
|
|
18846
|
+
const headerRow = worksheet.getRow(1);
|
|
18847
|
+
const headers = (headerRow.values || []).slice(1).map((header) => String(header ?? "").trim());
|
|
18848
|
+
worksheet.eachRow((row, rowNumber) => {
|
|
18849
|
+
if (rowNumber === 1)
|
|
18850
|
+
return;
|
|
18851
|
+
const rowData = {};
|
|
18852
|
+
headers.forEach((header, index) => {
|
|
18853
|
+
rowData[header] = row.getCell(index + 1).value ?? "";
|
|
18854
|
+
});
|
|
18855
|
+
const hasValue = Object.values(rowData).some(
|
|
18856
|
+
(value) => value !== null && value !== void 0 && value !== ""
|
|
18857
|
+
);
|
|
18858
|
+
if (hasValue) {
|
|
18859
|
+
rows.push(rowData);
|
|
18860
|
+
}
|
|
18861
|
+
});
|
|
18862
|
+
const vehicles = rows.map(mapRowToVehicle);
|
|
18863
|
+
const data = await _bulkUpsertVehicles(vehicles);
|
|
18864
|
+
res.status(200).json({
|
|
18865
|
+
message: "Excel import completed.",
|
|
18866
|
+
sheetName: worksheet.name,
|
|
18867
|
+
count: rows.length,
|
|
18868
|
+
data
|
|
18869
|
+
});
|
|
18870
|
+
fs.unlink(req.file.path, () => {
|
|
18871
|
+
});
|
|
18872
|
+
} catch (error) {
|
|
18873
|
+
logger65.log({ level: "error", message: error.message });
|
|
18874
|
+
next(error);
|
|
18875
|
+
}
|
|
18876
|
+
}
|
|
18619
18877
|
async function add(req, res, next) {
|
|
18620
18878
|
const { error, value } = vehicleSchema.validate(req.body, {
|
|
18621
18879
|
abortEarly: false
|
|
@@ -18940,6 +19198,69 @@ function useVehicleController() {
|
|
|
18940
19198
|
return;
|
|
18941
19199
|
}
|
|
18942
19200
|
}
|
|
19201
|
+
async function bulkUpsertVehicles(req, res, next) {
|
|
19202
|
+
const items = Array.isArray(req.body) ? req.body : req.body?.items;
|
|
19203
|
+
if (!Array.isArray(items) || items.length === 0) {
|
|
19204
|
+
next(new BadRequestError83("A non-empty array of vehicles is required."));
|
|
19205
|
+
return;
|
|
19206
|
+
}
|
|
19207
|
+
const success = [];
|
|
19208
|
+
const failed = [];
|
|
19209
|
+
try {
|
|
19210
|
+
for (let index = 0; index < items.length; index++) {
|
|
19211
|
+
const item = items[index];
|
|
19212
|
+
const schema2 = Joi46.object({
|
|
19213
|
+
fullName: Joi46.string().trim().required(),
|
|
19214
|
+
category: Joi46.string().trim().lowercase().valid(...Object.values(PersonTypes)).required(),
|
|
19215
|
+
type: Joi46.string().trim().lowercase().valid(...Object.values(VehicleType)),
|
|
19216
|
+
phoneNumber: Joi46.string().trim().allow(null, "").optional(),
|
|
19217
|
+
block: Joi46.number().integer().min(1).required(),
|
|
19218
|
+
level: Joi46.string().trim().required(),
|
|
19219
|
+
unit: Joi46.string().trim().required(),
|
|
19220
|
+
plateNumber: Joi46.string().trim().uppercase().required(),
|
|
19221
|
+
vehicleModel: Joi46.string().trim().required(),
|
|
19222
|
+
vehicleColor: Joi46.string().trim().required(),
|
|
19223
|
+
subscriptionExpiry: Joi46.string().trim().allow(null, "").optional()
|
|
19224
|
+
});
|
|
19225
|
+
const { error, value } = schema2.validate(item, {
|
|
19226
|
+
abortEarly: false
|
|
19227
|
+
});
|
|
19228
|
+
if (error) {
|
|
19229
|
+
const message = error.details.map((d) => d.message).join(", ");
|
|
19230
|
+
failed.push({
|
|
19231
|
+
index,
|
|
19232
|
+
item,
|
|
19233
|
+
message
|
|
19234
|
+
});
|
|
19235
|
+
continue;
|
|
19236
|
+
}
|
|
19237
|
+
try {
|
|
19238
|
+
const data = await _bulkUpsertVehicles(value);
|
|
19239
|
+
success.push({
|
|
19240
|
+
index,
|
|
19241
|
+
data
|
|
19242
|
+
});
|
|
19243
|
+
} catch (error2) {
|
|
19244
|
+
failed.push({
|
|
19245
|
+
index,
|
|
19246
|
+
item,
|
|
19247
|
+
message: error2.message
|
|
19248
|
+
});
|
|
19249
|
+
}
|
|
19250
|
+
}
|
|
19251
|
+
res.status(201).json({
|
|
19252
|
+
message: "Bulk vehicle import completed.",
|
|
19253
|
+
successCount: success.length,
|
|
19254
|
+
failedCount: failed.length,
|
|
19255
|
+
success,
|
|
19256
|
+
failed
|
|
19257
|
+
});
|
|
19258
|
+
} catch (error) {
|
|
19259
|
+
logger65.log({ level: "error", message: error.message });
|
|
19260
|
+
next(error);
|
|
19261
|
+
return;
|
|
19262
|
+
}
|
|
19263
|
+
}
|
|
18943
19264
|
return {
|
|
18944
19265
|
add,
|
|
18945
19266
|
getVehicles,
|
|
@@ -18950,7 +19271,10 @@ function useVehicleController() {
|
|
|
18950
19271
|
approveVehicleById,
|
|
18951
19272
|
getVehiclesByNRIC,
|
|
18952
19273
|
reactivateVehicleById,
|
|
18953
|
-
getAllVehiclesByUnitId
|
|
19274
|
+
getAllVehiclesByUnitId,
|
|
19275
|
+
bulkUpsertVehicles,
|
|
19276
|
+
uploadCsvVehicles,
|
|
19277
|
+
uploadExcelVehicles
|
|
18954
19278
|
};
|
|
18955
19279
|
}
|
|
18956
19280
|
|
|
@@ -21874,6 +22198,8 @@ function useVisitorTransactionService() {
|
|
|
21874
22198
|
try {
|
|
21875
22199
|
const updatePayload = { status: "In Use" /* IN_USE */ };
|
|
21876
22200
|
const visitorPassId = typeof vp === "string" || vp instanceof ObjectId58 ? vp : vp.keyId;
|
|
22201
|
+
if (!visitorPassId)
|
|
22202
|
+
value.visitorPass = [];
|
|
21877
22203
|
await KeyRepo.updateKeyById(
|
|
21878
22204
|
visitorPassId,
|
|
21879
22205
|
updatePayload,
|
|
@@ -21889,6 +22215,8 @@ function useVisitorTransactionService() {
|
|
|
21889
22215
|
try {
|
|
21890
22216
|
const updatePayload = { status: "In Use" /* IN_USE */ };
|
|
21891
22217
|
const passKeyId = typeof pk === "string" || pk instanceof ObjectId58 ? pk : pk.keyId;
|
|
22218
|
+
if (!passKeyId)
|
|
22219
|
+
value.passKeys = [];
|
|
21892
22220
|
await KeyRepo.updateKeyById(
|
|
21893
22221
|
passKeyId,
|
|
21894
22222
|
updatePayload,
|
|
@@ -22000,11 +22328,13 @@ function useVisitorTransactionService() {
|
|
|
22000
22328
|
value.recNo = parsed.recNo;
|
|
22001
22329
|
}
|
|
22002
22330
|
}
|
|
22003
|
-
if (value.visitorPass && Array.isArray(value.visitorPass) && value.visitorPass.length > 0) {
|
|
22331
|
+
if (value.visitorPass && Array.isArray(value.visitorPass) && value.visitorPass.length > 0 && value.visitorPass) {
|
|
22004
22332
|
for (const vp of value.visitorPass) {
|
|
22005
22333
|
try {
|
|
22006
22334
|
const updatePayload = { status: "In Use" /* IN_USE */ };
|
|
22007
22335
|
const visitorPassId = typeof vp === "string" || vp instanceof ObjectId58 ? vp : vp.keyId;
|
|
22336
|
+
if (!visitorPassId)
|
|
22337
|
+
value.visitorPass = [];
|
|
22008
22338
|
await KeyRepo.updateKeyById(
|
|
22009
22339
|
visitorPassId,
|
|
22010
22340
|
updatePayload,
|
|
@@ -22020,6 +22350,8 @@ function useVisitorTransactionService() {
|
|
|
22020
22350
|
try {
|
|
22021
22351
|
const updatePayload = { status: "In Use" /* IN_USE */ };
|
|
22022
22352
|
const passKeyId = typeof pk === "string" || pk instanceof ObjectId58 ? pk : pk.keyId;
|
|
22353
|
+
if (!passKeyId)
|
|
22354
|
+
value.passKeys = [];
|
|
22023
22355
|
await KeyRepo.updateKeyById(
|
|
22024
22356
|
passKeyId,
|
|
22025
22357
|
updatePayload,
|
|
@@ -22191,7 +22523,7 @@ function useVisitorTransactionService() {
|
|
|
22191
22523
|
org: inviter?.org.toString(),
|
|
22192
22524
|
site: inviter?.site.toString(),
|
|
22193
22525
|
status: "approved" /* APPROVED */,
|
|
22194
|
-
|
|
22526
|
+
inviterId: userId
|
|
22195
22527
|
};
|
|
22196
22528
|
const result = await _add(payload);
|
|
22197
22529
|
const emailContent = compileHandlebar2({
|
|
@@ -22342,7 +22674,8 @@ function useVisitorTransactionController() {
|
|
|
22342
22674
|
}).optional().allow(null, ""),
|
|
22343
22675
|
checkedOut: Joi55.boolean().allow(null, ""),
|
|
22344
22676
|
plateNumber: Joi55.string().optional().allow(null, ""),
|
|
22345
|
-
order: Joi55.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */)
|
|
22677
|
+
order: Joi55.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */),
|
|
22678
|
+
tab: Joi55.string().optional().allow(null, "")
|
|
22346
22679
|
});
|
|
22347
22680
|
const { error, value } = validation.validate(req.query, {
|
|
22348
22681
|
abortEarly: false
|
|
@@ -22366,7 +22699,8 @@ function useVisitorTransactionController() {
|
|
|
22366
22699
|
checkedOut,
|
|
22367
22700
|
sort,
|
|
22368
22701
|
order,
|
|
22369
|
-
plateNumber
|
|
22702
|
+
plateNumber,
|
|
22703
|
+
tab
|
|
22370
22704
|
} = value;
|
|
22371
22705
|
const sortObj = {
|
|
22372
22706
|
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
@@ -22383,7 +22717,8 @@ function useVisitorTransactionController() {
|
|
|
22383
22717
|
dateFrom,
|
|
22384
22718
|
type,
|
|
22385
22719
|
checkedOut,
|
|
22386
|
-
plateNumber
|
|
22720
|
+
plateNumber,
|
|
22721
|
+
tab
|
|
22387
22722
|
});
|
|
22388
22723
|
res.status(200).json(data);
|
|
22389
22724
|
return;
|
|
@@ -29722,7 +30057,7 @@ function useSiteBillingItemService() {
|
|
|
29722
30057
|
}
|
|
29723
30058
|
try {
|
|
29724
30059
|
await session.startTransaction();
|
|
29725
|
-
const billing_item = await _getBillingItemById(id
|
|
30060
|
+
const billing_item = await _getBillingItemById(id);
|
|
29726
30061
|
if (!billing_item) {
|
|
29727
30062
|
throw new BadRequestError131("Billing item not found.");
|
|
29728
30063
|
}
|
|
@@ -30742,10 +31077,32 @@ function useEventManagementController() {
|
|
|
30742
31077
|
import { BadRequestError as BadRequestError137, logger as logger116 } from "@7365admin1/node-server-utils";
|
|
30743
31078
|
import { ObjectId as ObjectId85 } from "mongodb";
|
|
30744
31079
|
import Joi83 from "joi";
|
|
31080
|
+
var Status = /* @__PURE__ */ ((Status3) => {
|
|
31081
|
+
Status3["PENDING"] = "pending";
|
|
31082
|
+
Status3["COMPLETED"] = "completed";
|
|
31083
|
+
Status3["APPROVED"] = "approved";
|
|
31084
|
+
Status3["REJECTED"] = "rejected";
|
|
31085
|
+
Status3["CANCELLED"] = "cancelled";
|
|
31086
|
+
Status3["RECURRING"] = "recurring";
|
|
31087
|
+
Status3["NONRECURRING"] = "non-recurring";
|
|
31088
|
+
Status3["ACTIVE"] = "active";
|
|
31089
|
+
Status3["INACTIVE"] = "inactive";
|
|
31090
|
+
return Status3;
|
|
31091
|
+
})(Status || {});
|
|
31092
|
+
var PStatus = /* @__PURE__ */ ((PStatus2) => {
|
|
31093
|
+
PStatus2["PROCESSING"] = "processing";
|
|
31094
|
+
PStatus2["UNPAID"] = "unpaid";
|
|
31095
|
+
PStatus2["PAID"] = "paid";
|
|
31096
|
+
PStatus2["OVERDUE"] = "overdue";
|
|
31097
|
+
PStatus2["PARTIAL"] = "partial-payment";
|
|
31098
|
+
PStatus2["AWAITING_PAYMENT"] = "awaiting-payment";
|
|
31099
|
+
PStatus2["FAILED"] = "failed";
|
|
31100
|
+
return PStatus2;
|
|
31101
|
+
})(PStatus || {});
|
|
30745
31102
|
var schemaUnitBilling = Joi83.object({
|
|
30746
31103
|
_id: Joi83.string().hex().optional(),
|
|
30747
|
-
site: Joi83.string().hex().
|
|
30748
|
-
org: Joi83.string().hex().
|
|
31104
|
+
site: Joi83.string().hex().optional().allow(null, ""),
|
|
31105
|
+
org: Joi83.string().hex().optional().allow(null, ""),
|
|
30749
31106
|
billItem: Joi83.string().hex().optional().allow(null, ""),
|
|
30750
31107
|
billName: Joi83.string().optional().allow(null, ""),
|
|
30751
31108
|
unitId: Joi83.string().hex().optional().allow(null, ""),
|
|
@@ -30765,6 +31122,7 @@ var schemaUnitBilling = Joi83.object({
|
|
|
30765
31122
|
paymentStatus: Joi83.string().optional().allow(null, ""),
|
|
30766
31123
|
status: Joi83.string().optional().allow(null, ""),
|
|
30767
31124
|
amountPaid: Joi83.number().optional().allow(null, ""),
|
|
31125
|
+
balanceAmount: Joi83.number().optional().allow(null, ""),
|
|
30768
31126
|
paidBy: Joi83.string().hex().optional().allow(null, ""),
|
|
30769
31127
|
datePaid: Joi83.date().optional().allow(null, ""),
|
|
30770
31128
|
transaction_id: Joi83.string().optional().allow(null, ""),
|
|
@@ -30788,6 +31146,7 @@ var schemaUpdateSiteUnitBilling = Joi83.object({
|
|
|
30788
31146
|
category: Joi83.string().optional().allow(null, ""),
|
|
30789
31147
|
frequency: Joi83.string().optional().allow(null, ""),
|
|
30790
31148
|
totalAmount: Joi83.number().optional().allow(null, ""),
|
|
31149
|
+
balanceAmount: Joi83.number().optional().allow(null, ""),
|
|
30791
31150
|
taxPercentage: Joi83.number().optional().allow(null, ""),
|
|
30792
31151
|
taxAmount: Joi83.number().optional().allow(null, ""),
|
|
30793
31152
|
amount: Joi83.number().optional().allow(null, ""),
|
|
@@ -30853,8 +31212,8 @@ function MUnitBilling(value) {
|
|
|
30853
31212
|
}
|
|
30854
31213
|
return {
|
|
30855
31214
|
_id: value._id ?? new ObjectId85(),
|
|
30856
|
-
site: value.site,
|
|
30857
|
-
org: value.org,
|
|
31215
|
+
site: value.site ?? "",
|
|
31216
|
+
org: value.org ?? "",
|
|
30858
31217
|
billItem: value.billItem ?? "",
|
|
30859
31218
|
billName: value.billName ?? "",
|
|
30860
31219
|
unitId: value.unitId ?? "",
|
|
@@ -30874,6 +31233,7 @@ function MUnitBilling(value) {
|
|
|
30874
31233
|
paymentStatus: value.paymentStatus ?? "",
|
|
30875
31234
|
status: value.status ?? "active",
|
|
30876
31235
|
amountPaid: value.amountPaid ?? 0,
|
|
31236
|
+
balanceAmount: value.balanceAmount ?? 0,
|
|
30877
31237
|
paidBy: value.paidBy ?? "",
|
|
30878
31238
|
datePaid: value.datePaid ?? "",
|
|
30879
31239
|
transaction_id: value.transaction_id ?? "",
|
|
@@ -30926,7 +31286,7 @@ function useSiteUnitBillingRepo() {
|
|
|
30926
31286
|
value = MUnitBilling(value);
|
|
30927
31287
|
const res = await collection.insertOne(value, { session });
|
|
30928
31288
|
const acronym = createAcronym(value.billName || "NA");
|
|
30929
|
-
const dateFormatted =
|
|
31289
|
+
const dateFormatted = formatDateString(/* @__PURE__ */ new Date());
|
|
30930
31290
|
const newId = new ObjectId86(res.insertedId).toString().slice(-6);
|
|
30931
31291
|
const referenceNumber = `${acronym}${newId}${dateFormatted}`;
|
|
30932
31292
|
await collection.updateOne(
|
|
@@ -31352,7 +31712,7 @@ function useSiteUnitBillingRepo() {
|
|
|
31352
31712
|
function createAcronym(billName) {
|
|
31353
31713
|
return billName.split(" ").map((word) => word.charAt(0).toUpperCase()).join("");
|
|
31354
31714
|
}
|
|
31355
|
-
function
|
|
31715
|
+
function formatDateString(today) {
|
|
31356
31716
|
today = typeof today === "string" ? new Date(today) : today;
|
|
31357
31717
|
let month = today.getMonth() + 1;
|
|
31358
31718
|
let day = today.getDate();
|
|
@@ -31877,8 +32237,8 @@ import {
|
|
|
31877
32237
|
import { ObjectId as ObjectId89 } from "mongodb";
|
|
31878
32238
|
|
|
31879
32239
|
// src/utils/access-management.ts
|
|
31880
|
-
import
|
|
31881
|
-
import
|
|
32240
|
+
import fs2 from "fs";
|
|
32241
|
+
import path3 from "path";
|
|
31882
32242
|
import axios from "axios";
|
|
31883
32243
|
import { parseStringPromise } from "xml2js";
|
|
31884
32244
|
import crypto from "crypto";
|
|
@@ -31907,8 +32267,8 @@ var minifyXml = (xml) => {
|
|
|
31907
32267
|
return xml.replace(/>\s+</g, "><").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").trim();
|
|
31908
32268
|
};
|
|
31909
32269
|
var readTemplate = (name, params) => {
|
|
31910
|
-
const template =
|
|
31911
|
-
|
|
32270
|
+
const template = fs2.readFileSync(
|
|
32271
|
+
path3.join(__dirname, `../src/public/xml-templates/${name}.xml`),
|
|
31912
32272
|
"utf-8"
|
|
31913
32273
|
);
|
|
31914
32274
|
if (!params)
|
|
@@ -32017,14 +32377,14 @@ import { parseStringPromise as parseStringPromise2 } from "xml2js";
|
|
|
32017
32377
|
|
|
32018
32378
|
// src/utils/rsa-encryption.ts
|
|
32019
32379
|
import * as crypto2 from "crypto";
|
|
32020
|
-
import
|
|
32021
|
-
import
|
|
32022
|
-
var pub =
|
|
32023
|
-
var priv =
|
|
32380
|
+
import fs3 from "fs";
|
|
32381
|
+
import path4 from "path";
|
|
32382
|
+
var pub = path4.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_pub.pem");
|
|
32383
|
+
var priv = path4.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_priv.pem");
|
|
32024
32384
|
var EncryptionCredentials = class {
|
|
32025
32385
|
};
|
|
32026
|
-
EncryptionCredentials.RAW_PUBLIC_KEY =
|
|
32027
|
-
EncryptionCredentials.RAW_PRIVATE_KEY =
|
|
32386
|
+
EncryptionCredentials.RAW_PUBLIC_KEY = fs3.readFileSync(pub, "utf8");
|
|
32387
|
+
EncryptionCredentials.RAW_PRIVATE_KEY = fs3.readFileSync(priv, "utf8");
|
|
32028
32388
|
var EntrypassRSAEncryption = class extends EncryptionCredentials {
|
|
32029
32389
|
static hexToCardNumber(hex) {
|
|
32030
32390
|
if (!/^[0-9A-Fa-f]{8}$/.test(hex)) {
|
|
@@ -33980,7 +34340,7 @@ import Joi85 from "joi";
|
|
|
33980
34340
|
|
|
33981
34341
|
// src/services/access-management.service.ts
|
|
33982
34342
|
import { parseStringPromise as parseStringPromise3 } from "xml2js";
|
|
33983
|
-
import { Readable } from "stream";
|
|
34343
|
+
import { Readable as Readable2 } from "stream";
|
|
33984
34344
|
import * as xlsx from "xlsx";
|
|
33985
34345
|
function useAccessManagementSvc() {
|
|
33986
34346
|
const {
|
|
@@ -34185,7 +34545,7 @@ function useAccessManagementSvc() {
|
|
|
34185
34545
|
};
|
|
34186
34546
|
const convertBufferFile = async (bufferFile) => {
|
|
34187
34547
|
return new Promise((resolve, reject) => {
|
|
34188
|
-
const fileStream =
|
|
34548
|
+
const fileStream = Readable2.from(bufferFile);
|
|
34189
34549
|
let fileBuffer = Buffer.alloc(0);
|
|
34190
34550
|
fileStream.on("data", (chunk) => {
|
|
34191
34551
|
fileBuffer = Buffer.concat([fileBuffer, chunk]);
|
|
@@ -46607,121 +46967,8 @@ function genericSignature(params, secretKey) {
|
|
|
46607
46967
|
}
|
|
46608
46968
|
|
|
46609
46969
|
// src/repositories/reddot-payment.repository.ts
|
|
46610
|
-
import {
|
|
46611
|
-
|
|
46612
|
-
// src/utils/date-format.util.ts
|
|
46613
|
-
import moment6 from "moment-timezone";
|
|
46614
|
-
function formatDateString(today, format, dateRange) {
|
|
46615
|
-
today = typeof today === "string" ? new Date(today) : today;
|
|
46616
|
-
let month = today.getMonth() + 1;
|
|
46617
|
-
let day = today.getDate();
|
|
46618
|
-
let year = today.getFullYear();
|
|
46619
|
-
let formattedDate;
|
|
46620
|
-
if (format === "mm-dd-yyyy") {
|
|
46621
|
-
formattedDate = `${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}-${year}`;
|
|
46622
|
-
} else if (format === "dd-mm-yyyy") {
|
|
46623
|
-
formattedDate = `${day.toString().padStart(2, "0")}-${month.toString().padStart(2, "0")}-${year}`;
|
|
46624
|
-
} else if (format === "for-ref") {
|
|
46625
|
-
formattedDate = `${month.toString().padStart(2, "0")}${day.toString().padStart(2, "0")}${year}`;
|
|
46626
|
-
} else if (format === "mm/dd/yyyy") {
|
|
46627
|
-
formattedDate = `${month.toString().padStart(2, "0")}/${day.toString().padStart(2, "0")}/${year}`;
|
|
46628
|
-
} else {
|
|
46629
|
-
formattedDate = `${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}`;
|
|
46630
|
-
}
|
|
46631
|
-
return formattedDate;
|
|
46632
|
-
}
|
|
46633
|
-
|
|
46634
|
-
// src/models/credit-card.model.ts
|
|
46635
|
-
import { ObjectId as ObjectId124 } from "mongodb";
|
|
46636
|
-
var MCardInfo = class {
|
|
46637
|
-
// this is coming from RDP transaction
|
|
46638
|
-
constructor({
|
|
46639
|
-
_id = new ObjectId124(),
|
|
46640
|
-
userId,
|
|
46641
|
-
cardType,
|
|
46642
|
-
cardNumber,
|
|
46643
|
-
cardId,
|
|
46644
|
-
fullName,
|
|
46645
|
-
expiryDate,
|
|
46646
|
-
cvv,
|
|
46647
|
-
site,
|
|
46648
|
-
siteName,
|
|
46649
|
-
organization,
|
|
46650
|
-
createdBy,
|
|
46651
|
-
createdAt,
|
|
46652
|
-
updatedAt,
|
|
46653
|
-
transaction_id
|
|
46654
|
-
} = {}) {
|
|
46655
|
-
this._id = _id;
|
|
46656
|
-
this.userId = userId;
|
|
46657
|
-
this.cardType = cardType;
|
|
46658
|
-
this.cardNumber = cardNumber;
|
|
46659
|
-
this.cardId = cardId;
|
|
46660
|
-
this.fullName = fullName;
|
|
46661
|
-
this.expiryDate = expiryDate;
|
|
46662
|
-
this.cvv = cvv;
|
|
46663
|
-
this.site = site;
|
|
46664
|
-
this.siteName = siteName;
|
|
46665
|
-
this.organization = organization;
|
|
46666
|
-
this.createdBy = createdBy;
|
|
46667
|
-
this.createdAt = createdAt;
|
|
46668
|
-
this.updatedAt = updatedAt;
|
|
46669
|
-
this.transaction_id = transaction_id;
|
|
46670
|
-
}
|
|
46671
|
-
};
|
|
46672
|
-
|
|
46673
|
-
// src/models/cart.model.ts
|
|
46674
|
-
import { ObjectId as ObjectId125 } from "mongodb";
|
|
46675
|
-
var MUnitBillings = class {
|
|
46676
|
-
// transaction response messages
|
|
46677
|
-
constructor({
|
|
46678
|
-
_id = new ObjectId125(),
|
|
46679
|
-
unit,
|
|
46680
|
-
unitId,
|
|
46681
|
-
unitBill,
|
|
46682
|
-
paymentStatus = "Processing" /* processing */,
|
|
46683
|
-
referenceNumber,
|
|
46684
|
-
amountPaid,
|
|
46685
|
-
paidBy,
|
|
46686
|
-
datePaid,
|
|
46687
|
-
billCategory,
|
|
46688
|
-
billFrom,
|
|
46689
|
-
billTo,
|
|
46690
|
-
site,
|
|
46691
|
-
organization,
|
|
46692
|
-
createdBy,
|
|
46693
|
-
createdAt,
|
|
46694
|
-
updatedAt,
|
|
46695
|
-
message
|
|
46696
|
-
} = {}) {
|
|
46697
|
-
this._id = _id;
|
|
46698
|
-
this.unit = unit;
|
|
46699
|
-
this.unitId = unitId;
|
|
46700
|
-
this.referenceNumber = referenceNumber;
|
|
46701
|
-
this.unitBill = unitBill;
|
|
46702
|
-
this.paymentStatus = paymentStatus;
|
|
46703
|
-
this.amountPaid = amountPaid;
|
|
46704
|
-
this.site = site;
|
|
46705
|
-
this.organization = organization;
|
|
46706
|
-
this.paidBy = paidBy;
|
|
46707
|
-
this.datePaid = datePaid;
|
|
46708
|
-
this.billCategory = billCategory;
|
|
46709
|
-
this.billFrom = billFrom;
|
|
46710
|
-
this.billTo = billTo;
|
|
46711
|
-
this.createdBy = createdBy;
|
|
46712
|
-
this.createdAt = createdAt;
|
|
46713
|
-
this.updatedAt = updatedAt;
|
|
46714
|
-
this.message = message;
|
|
46715
|
-
}
|
|
46716
|
-
};
|
|
46717
|
-
|
|
46718
|
-
// src/repositories/payment.repository.ts
|
|
46719
|
-
import { ObjectId as ObjectId126 } from "mongodb";
|
|
46720
|
-
import {
|
|
46721
|
-
InternalServerError as InternalServerError66,
|
|
46722
|
-
useAtlas as useAtlas110
|
|
46723
|
-
} from "@7365admin1/node-server-utils";
|
|
46724
|
-
var PaymentBillRepo = () => {
|
|
46970
|
+
import { InternalServerError as InternalServerError66, useAtlas as useAtlas110 } from "@7365admin1/node-server-utils";
|
|
46971
|
+
var useRedDotPaymentRepo = () => {
|
|
46725
46972
|
const getDB2 = () => {
|
|
46726
46973
|
const db = useAtlas110.getDb();
|
|
46727
46974
|
if (!db) {
|
|
@@ -46729,350 +46976,75 @@ var PaymentBillRepo = () => {
|
|
|
46729
46976
|
}
|
|
46730
46977
|
return db;
|
|
46731
46978
|
};
|
|
46732
|
-
const
|
|
46733
|
-
return getDB2().collection("
|
|
46979
|
+
const paymentCollection = () => {
|
|
46980
|
+
return getDB2().collection("payments");
|
|
46734
46981
|
};
|
|
46735
|
-
const
|
|
46736
|
-
return getDB2().collection("
|
|
46982
|
+
const unitBillingCollection = () => {
|
|
46983
|
+
return getDB2().collection("site.unit.billing");
|
|
46737
46984
|
};
|
|
46738
|
-
const
|
|
46739
|
-
return getDB2().collection("
|
|
46985
|
+
const orgCollection = () => {
|
|
46986
|
+
return getDB2().collection("organizations");
|
|
46740
46987
|
};
|
|
46741
|
-
const
|
|
46742
|
-
return getDB2().collection("
|
|
46988
|
+
const redDotMerchantCollection = () => {
|
|
46989
|
+
return getDB2().collection("payment-gateways");
|
|
46743
46990
|
};
|
|
46744
|
-
|
|
46991
|
+
async function paySingleUnitBill(refId, payload) {
|
|
46745
46992
|
try {
|
|
46746
46993
|
if (refId)
|
|
46747
46994
|
refId = refId.toString();
|
|
46748
|
-
const unitBillInfo = await
|
|
46749
|
-
|
|
46995
|
+
const unitBillInfo = await unitBillingCollection().findOne({
|
|
46996
|
+
referenceNumber: refId
|
|
46997
|
+
});
|
|
46750
46998
|
if (!unitBillInfo) {
|
|
46751
46999
|
throw new Error("Unit bill info not found");
|
|
46752
47000
|
}
|
|
46753
|
-
if (unitBillInfo?.status === "
|
|
47001
|
+
if (unitBillInfo?.status === "inactive" /* INACTIVE */) {
|
|
46754
47002
|
throw new Error("This Bill is Inactive!");
|
|
46755
47003
|
}
|
|
46756
|
-
|
|
46757
|
-
|
|
46758
|
-
|
|
46759
|
-
|
|
46760
|
-
|
|
46761
|
-
|
|
46762
|
-
|
|
46763
|
-
const amount = payload.amountPaid;
|
|
46764
|
-
const numericPrice = typeof price === "string" ? parseInt(price) : price;
|
|
46765
|
-
const numericAmount = typeof amount === "string" ? parseInt(amount) : amount;
|
|
46766
|
-
if (typeof amount !== "number") {
|
|
46767
|
-
throw new Error("Amount is not a valid number");
|
|
46768
|
-
} else if (typeof price !== "number") {
|
|
46769
|
-
throw new Error("Price s not a valid number");
|
|
47004
|
+
if (payload.paymentStatus === "partial-payment" /* PARTIAL */ && payload.amountPaid) {
|
|
47005
|
+
const totalAmount = parseInt(unitBillInfo.totalAmount);
|
|
47006
|
+
const amountPaid = payload.amountPaid;
|
|
47007
|
+
if (typeof totalAmount !== "number") {
|
|
47008
|
+
throw new Error("Total Amount is not a valid number");
|
|
47009
|
+
} else if (typeof amountPaid !== "number") {
|
|
47010
|
+
throw new Error("Amount Paid is not a valid number");
|
|
46770
47011
|
}
|
|
46771
|
-
payload.
|
|
46772
|
-
} else if (payload.paymentStatus === "
|
|
47012
|
+
payload.balanceAmount = totalAmount - amountPaid;
|
|
47013
|
+
} else if (payload.paymentStatus === "paid" /* PAID */ && payload.amountPaid) {
|
|
46773
47014
|
payload.datePaid = /* @__PURE__ */ new Date();
|
|
46774
|
-
payload.paymentStatus = "
|
|
47015
|
+
payload.paymentStatus = "paid" /* PAID */;
|
|
46775
47016
|
payload.amountPaid;
|
|
46776
47017
|
payload.transaction_id;
|
|
46777
|
-
} else if (payload.paymentStatus === "
|
|
47018
|
+
} else if (payload.paymentStatus === "failed" /* FAILED */) {
|
|
46778
47019
|
payload.amountPaid = 0;
|
|
46779
|
-
payload.
|
|
46780
|
-
payload.datePaid = "";
|
|
46781
|
-
payload.paymentStatus = "Failed" /* failed */;
|
|
47020
|
+
payload.paymentStatus = "failed" /* FAILED */;
|
|
46782
47021
|
payload.transaction_id;
|
|
46783
47022
|
}
|
|
46784
|
-
|
|
46785
|
-
|
|
46786
|
-
|
|
46787
|
-
|
|
46788
|
-
|
|
46789
|
-
|
|
46790
|
-
}
|
|
46791
|
-
};
|
|
46792
|
-
const saveCreditCardInfo = async (payload) => {
|
|
46793
|
-
try {
|
|
46794
|
-
if (payload.userId)
|
|
46795
|
-
payload.userId = new ObjectId126(payload.userId);
|
|
46796
|
-
if (payload.site)
|
|
46797
|
-
payload.site = new ObjectId126(payload.site);
|
|
46798
|
-
if (payload.organization)
|
|
46799
|
-
payload.organization = new ObjectId126(payload.organization);
|
|
46800
|
-
if (payload.createdBy)
|
|
46801
|
-
payload.createdBy = new ObjectId126(payload.createdBy);
|
|
46802
|
-
const createdAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
46803
|
-
payload.createdAt = createdAt;
|
|
46804
|
-
const result = await creditCollection().insertOne(new MCardInfo(payload));
|
|
46805
|
-
return result;
|
|
46806
|
-
} catch (error) {
|
|
46807
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46808
|
-
}
|
|
46809
|
-
};
|
|
46810
|
-
const checkOutUnitBills = async (payload) => {
|
|
46811
|
-
try {
|
|
46812
|
-
if (payload.unitId)
|
|
46813
|
-
payload.unitId = new ObjectId126(payload.unitId);
|
|
46814
|
-
if (payload.site)
|
|
46815
|
-
payload.site = new ObjectId126(payload.site);
|
|
46816
|
-
if (payload.organization)
|
|
46817
|
-
payload.organization = new ObjectId126(payload.organization);
|
|
46818
|
-
payload.createdAt = await formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
46819
|
-
const addToCart = await cartCollection().insertOne(new MUnitBillings(payload));
|
|
46820
|
-
const unitId = payload.unitId;
|
|
46821
|
-
const dateFormatted = formatDateString(/* @__PURE__ */ new Date(), "for-ref");
|
|
46822
|
-
const unit = unitId?.toString().slice(-4);
|
|
46823
|
-
const newId = new ObjectId126(addToCart?.insertedId).toString().slice(-4);
|
|
46824
|
-
const referenceNumber = `CRT${unit}${newId}${dateFormatted}`;
|
|
46825
|
-
const result = await cartCollection().findOneAndUpdate({ _id: new ObjectId126(addToCart.insertedId) }, { $set: { referenceNumber } }, { returnDocument: "after" });
|
|
46826
|
-
return result;
|
|
46827
|
-
} catch (error) {
|
|
46828
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46829
|
-
}
|
|
46830
|
-
};
|
|
46831
|
-
const payUnitCart = async (refId, payload) => {
|
|
46832
|
-
try {
|
|
46833
|
-
if (refId)
|
|
46834
|
-
refId = refId.toString();
|
|
46835
|
-
const updatedAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
46836
|
-
const cartInfo = await cartCollection().findOne({ referenceNumber: refId });
|
|
46837
|
-
const refNumber = cartInfo?.unitBill;
|
|
46838
|
-
if (payload.paymentStatus === "Paid" /* paid */ && payload.amountPaid) {
|
|
46839
|
-
payload.datePaid = /* @__PURE__ */ new Date();
|
|
46840
|
-
payload.paymentStatus = "Paid" /* paid */;
|
|
46841
|
-
payload.amountPaid;
|
|
46842
|
-
} else if (payload.paymentStatus === "Failed" /* failed */) {
|
|
46843
|
-
payload.amountPaid = 0;
|
|
46844
|
-
payload.paidBy = "";
|
|
46845
|
-
payload.datePaid = "";
|
|
46846
|
-
payload.paymentStatus = "Failed" /* failed */;
|
|
46847
|
-
}
|
|
46848
|
-
payload.updatedAt = updatedAt;
|
|
46849
|
-
const result = await cartCollection().findOneAndUpdate({ referenceNumber: refId }, { $set: payload }, { returnDocument: "after" });
|
|
46850
|
-
if (!result) {
|
|
46851
|
-
throw new Error("Failed to Process Transaction. Please Try Again Later");
|
|
46852
|
-
} else {
|
|
46853
|
-
for (const ref of refNumber) {
|
|
46854
|
-
const unitBillInfo = await collection().findOne({ referenceNumber: ref });
|
|
46855
|
-
const billId = unitBillInfo?.billId;
|
|
46856
|
-
const billInfo = await billCollection().findOne({ _id: new ObjectId126(billId) });
|
|
46857
|
-
const billAmount = billInfo?.price;
|
|
46858
|
-
payload.updatedAt = updatedAt;
|
|
46859
|
-
payload.amountPaid = billAmount;
|
|
46860
|
-
const eachRef = await payUnitBill(ref, payload);
|
|
46861
|
-
}
|
|
46862
|
-
if (!cartInfo) {
|
|
46863
|
-
throw new Error("Cart info not found");
|
|
46864
|
-
}
|
|
46865
|
-
}
|
|
47023
|
+
payload.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
47024
|
+
const result = await unitBillingCollection().findOneAndUpdate(
|
|
47025
|
+
{ _id: unitBillInfo._id },
|
|
47026
|
+
{ $set: payload },
|
|
47027
|
+
{ returnDocument: "after" }
|
|
47028
|
+
);
|
|
46866
47029
|
return result;
|
|
46867
47030
|
} catch (error) {
|
|
46868
47031
|
throw new Error(error.message || error || "Server Internal Error");
|
|
46869
47032
|
}
|
|
46870
|
-
}
|
|
46871
|
-
|
|
46872
|
-
try {
|
|
46873
|
-
if (refId)
|
|
46874
|
-
refId = refId.toString();
|
|
46875
|
-
const result = await cartCollection().aggregate([
|
|
46876
|
-
{ $match: { referenceNumber: refId } },
|
|
46877
|
-
{
|
|
46878
|
-
$lookup: {
|
|
46879
|
-
from: "unit-bill",
|
|
46880
|
-
localField: "unitBill",
|
|
46881
|
-
foreignField: "referenceNumber",
|
|
46882
|
-
as: "unitBill"
|
|
46883
|
-
}
|
|
46884
|
-
},
|
|
46885
|
-
{
|
|
46886
|
-
$unwind: "$unitBill"
|
|
46887
|
-
},
|
|
46888
|
-
{
|
|
46889
|
-
$lookup: {
|
|
46890
|
-
from: "bill-records",
|
|
46891
|
-
localField: "unitBill.billId",
|
|
46892
|
-
foreignField: "_id",
|
|
46893
|
-
as: "billDetails"
|
|
46894
|
-
}
|
|
46895
|
-
},
|
|
46896
|
-
{
|
|
46897
|
-
$unwind: {
|
|
46898
|
-
path: "$billDetails",
|
|
46899
|
-
preserveNullAndEmptyArrays: true
|
|
46900
|
-
}
|
|
46901
|
-
},
|
|
46902
|
-
{
|
|
46903
|
-
$addFields: {
|
|
46904
|
-
"unitBill.billItemName": "$billDetails.billItem"
|
|
46905
|
-
}
|
|
46906
|
-
},
|
|
46907
|
-
{
|
|
46908
|
-
$project: {
|
|
46909
|
-
"unitBill.paidBy": 0,
|
|
46910
|
-
"unitBill.preDueDateAlert": 0,
|
|
46911
|
-
"unitBill.category": 0,
|
|
46912
|
-
"unitBill.contactNumber": 0,
|
|
46913
|
-
"unitBill.email": 0,
|
|
46914
|
-
"unitBill.site": 0,
|
|
46915
|
-
"unitBill.siteName": 0,
|
|
46916
|
-
"unitBill.organization": 0,
|
|
46917
|
-
"unitBill.billStatus": 0,
|
|
46918
|
-
"unitBill.createdBy": 0,
|
|
46919
|
-
"unitBill.createdAt": 0,
|
|
46920
|
-
"unitBill.updatedAt": 0,
|
|
46921
|
-
"billDetails": 0
|
|
46922
|
-
// Exclude the full billDetails as it's no longer needed
|
|
46923
|
-
}
|
|
46924
|
-
},
|
|
46925
|
-
{
|
|
46926
|
-
$group: {
|
|
46927
|
-
_id: "$_id",
|
|
46928
|
-
unitId: { $first: "$unitId" },
|
|
46929
|
-
referenceNumber: { $first: "$referenceNumber" },
|
|
46930
|
-
unitBill: { $push: "$unitBill" },
|
|
46931
|
-
paymentStatus: { $first: "$paymentStatus" },
|
|
46932
|
-
amountPaid: { $first: "$amountPaid" },
|
|
46933
|
-
site: { $first: "$site" },
|
|
46934
|
-
organization: { $first: "$organization" },
|
|
46935
|
-
paidBy: { $first: "$paidBy" },
|
|
46936
|
-
datePaid: { $first: "$referenceNumber" },
|
|
46937
|
-
billCategory: { $first: "$billCategory" },
|
|
46938
|
-
billFrom: { $first: "$billFrom" },
|
|
46939
|
-
billTo: { $first: "$billTo" },
|
|
46940
|
-
createdBy: { $first: "$createdBy" },
|
|
46941
|
-
createdAt: { $first: "$createdAt" },
|
|
46942
|
-
updatedAt: { $first: "$updatedAt" },
|
|
46943
|
-
transaction_id: { $first: "$transaction_id" }
|
|
46944
|
-
}
|
|
46945
|
-
}
|
|
46946
|
-
]).toArray();
|
|
46947
|
-
if (!result || result.length === 0) {
|
|
46948
|
-
return { success: false, message: "Cart Info Not Found" };
|
|
46949
|
-
}
|
|
46950
|
-
return result[0];
|
|
46951
|
-
} catch (error) {
|
|
46952
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46953
|
-
}
|
|
46954
|
-
};
|
|
46955
|
-
const cancelCheckedOutBillings = async (refId) => {
|
|
46956
|
-
try {
|
|
46957
|
-
if (refId)
|
|
46958
|
-
refId = refId.toString();
|
|
46959
|
-
const result = await cartCollection().findOneAndDelete({ referenceNumber: refId });
|
|
46960
|
-
if (!result) {
|
|
46961
|
-
return { success: false, message: "Cart Info Not Found" };
|
|
46962
|
-
}
|
|
46963
|
-
return { success: true, message: "Cart Deleted Successfully!", referenceNumber: result?.referenceNumber };
|
|
46964
|
-
} catch (error) {
|
|
46965
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46966
|
-
}
|
|
46967
|
-
};
|
|
46968
|
-
return {
|
|
46969
|
-
saveCreditCardInfo,
|
|
46970
|
-
checkOutUnitBills,
|
|
46971
|
-
payUnitBill,
|
|
46972
|
-
payUnitCart,
|
|
46973
|
-
getCheckedOutBillings,
|
|
46974
|
-
cancelCheckedOutBillings
|
|
46975
|
-
};
|
|
46976
|
-
};
|
|
46977
|
-
|
|
46978
|
-
// src/repositories/reddot-payment.repository.ts
|
|
46979
|
-
import {
|
|
46980
|
-
InternalServerError as InternalServerError67,
|
|
46981
|
-
useAtlas as useAtlas111
|
|
46982
|
-
} from "@7365admin1/node-server-utils";
|
|
46983
|
-
var useRedDotPaymentRepo = () => {
|
|
46984
|
-
const getDB2 = () => {
|
|
46985
|
-
const db = useAtlas111.getDb();
|
|
46986
|
-
if (!db) {
|
|
46987
|
-
throw new InternalServerError67("Unable to connect to server.");
|
|
46988
|
-
}
|
|
46989
|
-
return db;
|
|
46990
|
-
};
|
|
46991
|
-
const collection = () => {
|
|
46992
|
-
return getDB2().collection("unit-bill");
|
|
46993
|
-
};
|
|
46994
|
-
const orgCollection = () => {
|
|
46995
|
-
return getDB2().collection("organizations");
|
|
46996
|
-
};
|
|
46997
|
-
const cartCollection = () => {
|
|
46998
|
-
return getDB2().collection("checkout-cart");
|
|
46999
|
-
};
|
|
47000
|
-
const redDotMerchantCollection = () => {
|
|
47001
|
-
return getDB2().collection("reddot-merchant");
|
|
47002
|
-
};
|
|
47003
|
-
const createRedDotAccount = async (_id, payload) => {
|
|
47004
|
-
try {
|
|
47005
|
-
const merchant = await redDotMerchantCollection().insertOne(payload);
|
|
47006
|
-
if (!merchant) {
|
|
47007
|
-
throw new Error("Failed to Add Merchant Details");
|
|
47008
|
-
}
|
|
47009
|
-
const merchantId = merchant?.insertedId;
|
|
47010
|
-
const orgId = new ObjectId127(_id);
|
|
47011
|
-
const result = await orgCollection().findOneAndUpdate({ _id: orgId }, { $push: { merchant: merchantId } }, {
|
|
47012
|
-
returnDocument: "after"
|
|
47013
|
-
});
|
|
47014
|
-
if (!result) {
|
|
47015
|
-
throw new Error("Organization not found");
|
|
47016
|
-
}
|
|
47017
|
-
return {
|
|
47018
|
-
success: true,
|
|
47019
|
-
message: "Merchant Details successfully added."
|
|
47020
|
-
};
|
|
47021
|
-
} catch (error) {
|
|
47022
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
47023
|
-
}
|
|
47024
|
-
};
|
|
47025
|
-
const payUnitBillings = async (refId, payload) => {
|
|
47026
|
-
const checkCart = await cartCollection().findOne({ referenceNumber: refId });
|
|
47027
|
-
if (checkCart) {
|
|
47028
|
-
const multiple = await PaymentBillRepo().payUnitCart(refId, payload);
|
|
47029
|
-
if (multiple) {
|
|
47030
|
-
return await PaymentBillRepo().getCheckedOutBillings(refId);
|
|
47031
|
-
}
|
|
47032
|
-
}
|
|
47033
|
-
const single = await PaymentBillRepo().payUnitBill(refId, payload);
|
|
47034
|
-
return single;
|
|
47035
|
-
};
|
|
47036
|
-
const getMerchantDetailsById = async (_id) => {
|
|
47037
|
-
try {
|
|
47038
|
-
if (_id)
|
|
47039
|
-
_id = new ObjectId127(_id);
|
|
47040
|
-
const result = await redDotMerchantCollection().aggregate([
|
|
47041
|
-
{
|
|
47042
|
-
$match: {
|
|
47043
|
-
_id
|
|
47044
|
-
}
|
|
47045
|
-
},
|
|
47046
|
-
{
|
|
47047
|
-
$facet: {
|
|
47048
|
-
totalCount: [{ $count: "count" }],
|
|
47049
|
-
items: [{ $sort: { _id: -1 } }]
|
|
47050
|
-
}
|
|
47051
|
-
}
|
|
47052
|
-
]).toArray();
|
|
47053
|
-
const items = result[0].items;
|
|
47054
|
-
return items;
|
|
47055
|
-
} catch (error) {
|
|
47056
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
47057
|
-
}
|
|
47058
|
-
};
|
|
47059
|
-
return {
|
|
47060
|
-
createRedDotAccount,
|
|
47061
|
-
payUnitBillings,
|
|
47062
|
-
getMerchantDetailsById
|
|
47063
|
-
};
|
|
47033
|
+
}
|
|
47034
|
+
return { paySingleUnitBill };
|
|
47064
47035
|
};
|
|
47065
47036
|
|
|
47066
47037
|
// src/services/reddot-payment.service.ts
|
|
47067
47038
|
var useRedDotPaymentSvc = () => {
|
|
47068
|
-
const
|
|
47069
|
-
return useRedDotPaymentRepo().createRedDotAccount(_id, payload);
|
|
47070
|
-
};
|
|
47039
|
+
const { paySingleUnitBill } = useRedDotPaymentRepo();
|
|
47071
47040
|
const redirectPaymentTransaction = async (payload) => {
|
|
47072
47041
|
try {
|
|
47073
47042
|
const SECRET_KEY2 = payload.merchant_key;
|
|
47074
47043
|
if (!payload.mid && !payload.merchant_key) {
|
|
47075
|
-
return {
|
|
47044
|
+
return {
|
|
47045
|
+
success: false,
|
|
47046
|
+
message: "RDP Not Available on this account. Please Contact Management"
|
|
47047
|
+
};
|
|
47076
47048
|
}
|
|
47077
47049
|
const data = {
|
|
47078
47050
|
mid: payload.mid,
|
|
@@ -47095,7 +47067,9 @@ var useRedDotPaymentSvc = () => {
|
|
|
47095
47067
|
"Content-Length": String(dataString.length)
|
|
47096
47068
|
};
|
|
47097
47069
|
if (!process.env.MERCHANT_PAYMENT) {
|
|
47098
|
-
throw new Error(
|
|
47070
|
+
throw new Error(
|
|
47071
|
+
"MERCHANT_PAYMENT environment variable is not defined."
|
|
47072
|
+
);
|
|
47099
47073
|
}
|
|
47100
47074
|
const url = process.env.MERCHANT_PAYMENT;
|
|
47101
47075
|
const response = await axios3.post(url, dataString, { headers });
|
|
@@ -47109,7 +47083,10 @@ var useRedDotPaymentSvc = () => {
|
|
|
47109
47083
|
try {
|
|
47110
47084
|
const SECRET_KEY2 = payload.merchant_key;
|
|
47111
47085
|
if (!payload.request_mid && !payload.merchant_key) {
|
|
47112
|
-
return {
|
|
47086
|
+
return {
|
|
47087
|
+
success: false,
|
|
47088
|
+
message: "RDP Not Available on this account. Please Contact Management"
|
|
47089
|
+
};
|
|
47113
47090
|
}
|
|
47114
47091
|
const data = {
|
|
47115
47092
|
request_mid: payload.request_mid,
|
|
@@ -47124,7 +47101,9 @@ var useRedDotPaymentSvc = () => {
|
|
|
47124
47101
|
"Content-Type": "application/json"
|
|
47125
47102
|
};
|
|
47126
47103
|
if (!process.env.MERCHANT_ENQUIRY) {
|
|
47127
|
-
throw new Error(
|
|
47104
|
+
throw new Error(
|
|
47105
|
+
"MERCHANT_PAYMENT environment variable is not defined."
|
|
47106
|
+
);
|
|
47128
47107
|
}
|
|
47129
47108
|
const url = process.env.MERCHANT_ENQUIRY;
|
|
47130
47109
|
const response = await axios3.post(url, dataString, { headers });
|
|
@@ -47138,25 +47117,24 @@ var useRedDotPaymentSvc = () => {
|
|
|
47138
47117
|
if (result.response_code === "0") {
|
|
47139
47118
|
const success = {
|
|
47140
47119
|
method: payload.method,
|
|
47141
|
-
paymentStatus: "
|
|
47142
|
-
amountPaid: amount,
|
|
47143
|
-
paidBy: payer,
|
|
47120
|
+
paymentStatus: "paid" /* PAID */,
|
|
47121
|
+
amountPaid: parseInt(amount),
|
|
47144
47122
|
updatedAt: invoiceDate,
|
|
47145
47123
|
transaction_id: transactionId,
|
|
47146
47124
|
message
|
|
47147
47125
|
};
|
|
47148
|
-
await
|
|
47126
|
+
await paySingleUnitBill(refId, success);
|
|
47149
47127
|
} else if (result.response_code !== "0") {
|
|
47150
47128
|
const fail = {
|
|
47151
47129
|
method: payload.method,
|
|
47152
|
-
paymentStatus: "
|
|
47130
|
+
paymentStatus: "failed" /* FAILED */,
|
|
47153
47131
|
updatedAt: invoiceDate,
|
|
47154
47132
|
paidBy: "",
|
|
47155
|
-
amountPaid:
|
|
47133
|
+
amountPaid: 0,
|
|
47156
47134
|
transaction_id: transactionId,
|
|
47157
47135
|
message
|
|
47158
47136
|
};
|
|
47159
|
-
await
|
|
47137
|
+
await paySingleUnitBill(refId, fail);
|
|
47160
47138
|
}
|
|
47161
47139
|
return result;
|
|
47162
47140
|
} catch (error) {
|
|
@@ -47176,7 +47154,9 @@ var useRedDotPaymentSvc = () => {
|
|
|
47176
47154
|
"Content-Length": String(dataString.length)
|
|
47177
47155
|
};
|
|
47178
47156
|
if (!process.env.MERCHANT_PAYMENT) {
|
|
47179
|
-
throw new Error(
|
|
47157
|
+
throw new Error(
|
|
47158
|
+
"MERCHANT_PAYMENT environment variable is not defined."
|
|
47159
|
+
);
|
|
47180
47160
|
}
|
|
47181
47161
|
const url = process.env.MERCHANT_PAYMENT;
|
|
47182
47162
|
const response = await axios3.post(url, dataString, { headers });
|
|
@@ -47185,45 +47165,16 @@ var useRedDotPaymentSvc = () => {
|
|
|
47185
47165
|
return Promise.reject(error || error.message || "Server Internal Error!");
|
|
47186
47166
|
}
|
|
47187
47167
|
};
|
|
47188
|
-
const getMerchantDetailsById = async (_id) => {
|
|
47189
|
-
return useRedDotPaymentRepo().getMerchantDetailsById(_id);
|
|
47190
|
-
};
|
|
47191
47168
|
return {
|
|
47192
|
-
createRedDotAccount,
|
|
47193
47169
|
redirectPaymentTransaction,
|
|
47194
47170
|
enquirePaymentTransaction,
|
|
47195
|
-
payInvoice
|
|
47196
|
-
getMerchantDetailsById
|
|
47171
|
+
payInvoice
|
|
47197
47172
|
};
|
|
47198
47173
|
};
|
|
47199
47174
|
|
|
47200
47175
|
// src/controllers/reddot-payment.controller.ts
|
|
47201
47176
|
import Joi124 from "joi";
|
|
47202
47177
|
function useRedDotPaymentController() {
|
|
47203
|
-
const createRedDotAccount = async (req, res) => {
|
|
47204
|
-
try {
|
|
47205
|
-
const data = req.body;
|
|
47206
|
-
const id = req.params.id;
|
|
47207
|
-
const schema2 = Joi124.object({
|
|
47208
|
-
id: Joi124.string().hex().required(),
|
|
47209
|
-
// organization id
|
|
47210
|
-
paymentMethod: Joi124.string().required(),
|
|
47211
|
-
// payment method (e.g. "Visa / Mastercard / PayNow QR Code")
|
|
47212
|
-
merchant_id: Joi124.string().required(),
|
|
47213
|
-
// merchant id
|
|
47214
|
-
merchant_key: Joi124.string().required()
|
|
47215
|
-
// secret key
|
|
47216
|
-
});
|
|
47217
|
-
const { error } = schema2.validate({ id, ...data });
|
|
47218
|
-
if (error) {
|
|
47219
|
-
return res.status(400).json({ data: null, message: error.message });
|
|
47220
|
-
}
|
|
47221
|
-
const result = await useRedDotPaymentSvc().createRedDotAccount(id, data);
|
|
47222
|
-
return res.json(result);
|
|
47223
|
-
} catch (error) {
|
|
47224
|
-
return res.status(500).json({ message: error.message || error });
|
|
47225
|
-
}
|
|
47226
|
-
};
|
|
47227
47178
|
const redirectPaymentTransaction = async (req, res) => {
|
|
47228
47179
|
try {
|
|
47229
47180
|
const data = req.body;
|
|
@@ -47240,7 +47191,9 @@ function useRedDotPaymentController() {
|
|
|
47240
47191
|
if (error) {
|
|
47241
47192
|
return res.status(400).json({ data: null, message: error.message });
|
|
47242
47193
|
}
|
|
47243
|
-
const result = await useRedDotPaymentSvc().redirectPaymentTransaction(
|
|
47194
|
+
const result = await useRedDotPaymentSvc().redirectPaymentTransaction(
|
|
47195
|
+
data
|
|
47196
|
+
);
|
|
47244
47197
|
return res.json(result);
|
|
47245
47198
|
} catch (error) {
|
|
47246
47199
|
return res.status(500).json({ message: error.message || error });
|
|
@@ -47259,52 +47212,36 @@ function useRedDotPaymentController() {
|
|
|
47259
47212
|
if (error) {
|
|
47260
47213
|
return res.status(400).json({ data: null, message: error.message });
|
|
47261
47214
|
}
|
|
47262
|
-
const result = await useRedDotPaymentSvc().enquirePaymentTransaction(
|
|
47215
|
+
const result = await useRedDotPaymentSvc().enquirePaymentTransaction(
|
|
47216
|
+
data
|
|
47217
|
+
);
|
|
47263
47218
|
return res.json(result);
|
|
47264
47219
|
} catch (error) {
|
|
47265
47220
|
return res.status(500).json({ message: error.message || error });
|
|
47266
47221
|
}
|
|
47267
47222
|
};
|
|
47268
|
-
const getMerchantDetailsById = async (req, res, next) => {
|
|
47269
|
-
try {
|
|
47270
|
-
const _id = req.params.id;
|
|
47271
|
-
const schema2 = Joi124.object({
|
|
47272
|
-
_id: Joi124.string().hex().required()
|
|
47273
|
-
});
|
|
47274
|
-
const { error } = schema2.validate({ _id });
|
|
47275
|
-
if (error) {
|
|
47276
|
-
return res.status(400).json({ data: null, message: error.message });
|
|
47277
|
-
}
|
|
47278
|
-
const result = await useRedDotPaymentSvc().getMerchantDetailsById(_id);
|
|
47279
|
-
return res.json(result);
|
|
47280
|
-
} catch (error) {
|
|
47281
|
-
next(error);
|
|
47282
|
-
}
|
|
47283
|
-
};
|
|
47284
47223
|
return {
|
|
47285
|
-
createRedDotAccount,
|
|
47286
47224
|
redirectPaymentTransaction,
|
|
47287
|
-
enquirePaymentTransaction
|
|
47288
|
-
getMerchantDetailsById
|
|
47225
|
+
enquirePaymentTransaction
|
|
47289
47226
|
};
|
|
47290
47227
|
}
|
|
47291
47228
|
|
|
47292
47229
|
// src/repositories/verification-v2.repo.ts
|
|
47293
47230
|
import {
|
|
47294
47231
|
BadRequestError as BadRequestError195,
|
|
47295
|
-
InternalServerError as
|
|
47232
|
+
InternalServerError as InternalServerError67,
|
|
47296
47233
|
logger as logger175,
|
|
47297
47234
|
makeCacheKey as makeCacheKey64,
|
|
47298
47235
|
paginate as paginate57,
|
|
47299
47236
|
toObjectId as toObjectId18,
|
|
47300
|
-
useAtlas as
|
|
47237
|
+
useAtlas as useAtlas111,
|
|
47301
47238
|
useCache as useCache66
|
|
47302
47239
|
} from "@7365admin1/node-server-utils";
|
|
47303
|
-
import { ObjectId as
|
|
47240
|
+
import { ObjectId as ObjectId124 } from "mongodb";
|
|
47304
47241
|
function useVerificationRepoV2() {
|
|
47305
|
-
const db =
|
|
47242
|
+
const db = useAtlas111.getDb();
|
|
47306
47243
|
if (!db) {
|
|
47307
|
-
throw new
|
|
47244
|
+
throw new InternalServerError67("Unable to connect to server.");
|
|
47308
47245
|
}
|
|
47309
47246
|
const namespace_collection = "verifications";
|
|
47310
47247
|
const collection = db.collection(namespace_collection);
|
|
@@ -47317,7 +47254,7 @@ function useVerificationRepoV2() {
|
|
|
47317
47254
|
{ "metadata.org": 1 }
|
|
47318
47255
|
]);
|
|
47319
47256
|
} catch (error) {
|
|
47320
|
-
throw new
|
|
47257
|
+
throw new InternalServerError67("Failed to create index.");
|
|
47321
47258
|
}
|
|
47322
47259
|
}
|
|
47323
47260
|
async function createTextIndex() {
|
|
@@ -47326,7 +47263,7 @@ function useVerificationRepoV2() {
|
|
|
47326
47263
|
email: "text"
|
|
47327
47264
|
});
|
|
47328
47265
|
} catch (error) {
|
|
47329
|
-
throw new
|
|
47266
|
+
throw new InternalServerError67("Failed to create text index on email.");
|
|
47330
47267
|
}
|
|
47331
47268
|
}
|
|
47332
47269
|
const { delNamespace, setCache, getCache, delCache } = useCache66(namespace_collection);
|
|
@@ -47348,12 +47285,12 @@ function useVerificationRepoV2() {
|
|
|
47348
47285
|
level: "info",
|
|
47349
47286
|
message: String(error)
|
|
47350
47287
|
});
|
|
47351
|
-
throw new
|
|
47288
|
+
throw new InternalServerError67("Server internal error.");
|
|
47352
47289
|
}
|
|
47353
47290
|
}
|
|
47354
47291
|
async function updateVerificationStatusById(_id, status, session) {
|
|
47355
47292
|
try {
|
|
47356
|
-
_id = new
|
|
47293
|
+
_id = new ObjectId124(_id);
|
|
47357
47294
|
} catch (error) {
|
|
47358
47295
|
throw new BadRequestError195("Invalid verification ID format.");
|
|
47359
47296
|
}
|
|
@@ -47373,7 +47310,7 @@ function useVerificationRepoV2() {
|
|
|
47373
47310
|
});
|
|
47374
47311
|
return result;
|
|
47375
47312
|
} catch (error) {
|
|
47376
|
-
throw new
|
|
47313
|
+
throw new InternalServerError67("Error updating verification status.");
|
|
47377
47314
|
}
|
|
47378
47315
|
}
|
|
47379
47316
|
async function getByVerificationCode(verificationCode) {
|
|
@@ -47396,7 +47333,7 @@ function useVerificationRepoV2() {
|
|
|
47396
47333
|
});
|
|
47397
47334
|
return data;
|
|
47398
47335
|
} catch (error) {
|
|
47399
|
-
throw new
|
|
47336
|
+
throw new InternalServerError67(
|
|
47400
47337
|
"Internal server error, failed to retrieve verification."
|
|
47401
47338
|
);
|
|
47402
47339
|
}
|
|
@@ -47418,7 +47355,7 @@ function useVerificationRepoV2() {
|
|
|
47418
47355
|
});
|
|
47419
47356
|
return data;
|
|
47420
47357
|
} catch (error) {
|
|
47421
|
-
throw new
|
|
47358
|
+
throw new InternalServerError67(
|
|
47422
47359
|
"Internal server error, failed to retrieve verification."
|
|
47423
47360
|
);
|
|
47424
47361
|
}
|
|
@@ -47496,7 +47433,7 @@ function useVerificationRepoV2() {
|
|
|
47496
47433
|
}
|
|
47497
47434
|
async function updateStatusById(_id, status, session) {
|
|
47498
47435
|
try {
|
|
47499
|
-
_id = new
|
|
47436
|
+
_id = new ObjectId124(_id);
|
|
47500
47437
|
} catch (error) {
|
|
47501
47438
|
throw new BadRequestError195("Invalid verification ID format.");
|
|
47502
47439
|
}
|
|
@@ -47522,7 +47459,7 @@ function useVerificationRepoV2() {
|
|
|
47522
47459
|
});
|
|
47523
47460
|
return result;
|
|
47524
47461
|
} catch (error) {
|
|
47525
|
-
throw new
|
|
47462
|
+
throw new InternalServerError67("Error updating verification status.");
|
|
47526
47463
|
}
|
|
47527
47464
|
}
|
|
47528
47465
|
return {
|
|
@@ -47545,8 +47482,8 @@ import {
|
|
|
47545
47482
|
getDirectory as getDirectory4,
|
|
47546
47483
|
BadRequestError as BadRequestError196,
|
|
47547
47484
|
NotFoundError as NotFoundError51,
|
|
47548
|
-
InternalServerError as
|
|
47549
|
-
useAtlas as
|
|
47485
|
+
InternalServerError as InternalServerError68,
|
|
47486
|
+
useAtlas as useAtlas112,
|
|
47550
47487
|
hashPassword as hashPassword4
|
|
47551
47488
|
} from "@7365admin1/node-server-utils";
|
|
47552
47489
|
import crypto4 from "crypto";
|
|
@@ -47613,7 +47550,7 @@ function useVerificationServiceV2() {
|
|
|
47613
47550
|
email,
|
|
47614
47551
|
metadata
|
|
47615
47552
|
}) {
|
|
47616
|
-
const session =
|
|
47553
|
+
const session = useAtlas112.getClient()?.startSession();
|
|
47617
47554
|
try {
|
|
47618
47555
|
session?.startTransaction();
|
|
47619
47556
|
const user = await _getUserByEmailStatus(email);
|
|
@@ -47665,7 +47602,7 @@ function useVerificationServiceV2() {
|
|
|
47665
47602
|
}
|
|
47666
47603
|
}
|
|
47667
47604
|
async function verify(verificationCode) {
|
|
47668
|
-
const session =
|
|
47605
|
+
const session = useAtlas112.getClient()?.startSession();
|
|
47669
47606
|
try {
|
|
47670
47607
|
session?.startTransaction();
|
|
47671
47608
|
const item = await _getByVerificationCode(verificationCode);
|
|
@@ -47866,14 +47803,14 @@ function useVerificationServiceV2() {
|
|
|
47866
47803
|
});
|
|
47867
47804
|
return "Successfully created a link to reset password. Please check your email.";
|
|
47868
47805
|
} catch (error) {
|
|
47869
|
-
throw new
|
|
47806
|
+
throw new InternalServerError68("Failed to create forget password link.");
|
|
47870
47807
|
}
|
|
47871
47808
|
}
|
|
47872
47809
|
async function cancelUserInvitation(id) {
|
|
47873
47810
|
try {
|
|
47874
47811
|
await _updateStatusById(id, "cancelled");
|
|
47875
47812
|
} catch (error) {
|
|
47876
|
-
throw new
|
|
47813
|
+
throw new InternalServerError68(
|
|
47877
47814
|
`Error cancelling user invitation: ${error}`
|
|
47878
47815
|
);
|
|
47879
47816
|
}
|
|
@@ -48091,17 +48028,17 @@ import { BadRequestError as BadRequestError201, logger as logger180 } from "@736
|
|
|
48091
48028
|
import {
|
|
48092
48029
|
BadRequestError as BadRequestError199,
|
|
48093
48030
|
comparePassword as comparePassword3,
|
|
48094
|
-
InternalServerError as
|
|
48031
|
+
InternalServerError as InternalServerError70,
|
|
48095
48032
|
NotFoundError as NotFoundError53,
|
|
48096
48033
|
useCache as useCache68
|
|
48097
48034
|
} from "@7365admin1/node-server-utils";
|
|
48098
48035
|
import { v4 as uuidv42 } from "uuid";
|
|
48099
48036
|
|
|
48100
48037
|
// src/repositories/user-v2.repo.ts
|
|
48101
|
-
import { ObjectId as
|
|
48038
|
+
import { ObjectId as ObjectId125 } from "mongodb";
|
|
48102
48039
|
import {
|
|
48103
|
-
useAtlas as
|
|
48104
|
-
InternalServerError as
|
|
48040
|
+
useAtlas as useAtlas113,
|
|
48041
|
+
InternalServerError as InternalServerError69,
|
|
48105
48042
|
logger as logger178,
|
|
48106
48043
|
BadRequestError as BadRequestError198,
|
|
48107
48044
|
paginate as paginate58,
|
|
@@ -48115,9 +48052,9 @@ function useUserRepoV2() {
|
|
|
48115
48052
|
const { updateFeedbackCreatedByName } = useFeedbackRepo();
|
|
48116
48053
|
const { updateWorkOrderCreatedByName } = useWorkOrderRepo();
|
|
48117
48054
|
const { updateUserNameBySignatureId } = useOccurrenceEntryRepo();
|
|
48118
|
-
const db =
|
|
48055
|
+
const db = useAtlas113.getDb();
|
|
48119
48056
|
if (!db) {
|
|
48120
|
-
throw new
|
|
48057
|
+
throw new InternalServerError69("Unable to connect to server.");
|
|
48121
48058
|
}
|
|
48122
48059
|
const namespace_collection = "users";
|
|
48123
48060
|
const collection = db.collection(namespace_collection);
|
|
@@ -48126,14 +48063,14 @@ function useUserRepoV2() {
|
|
|
48126
48063
|
try {
|
|
48127
48064
|
await collection.createIndexes([{ key: { email: 1 } }]);
|
|
48128
48065
|
} catch (error) {
|
|
48129
|
-
throw new
|
|
48066
|
+
throw new InternalServerError69("Failed to create text index on user.");
|
|
48130
48067
|
}
|
|
48131
48068
|
}
|
|
48132
48069
|
async function createTextIndex() {
|
|
48133
48070
|
try {
|
|
48134
48071
|
await collection.createIndex({ name: "text", email: "text" });
|
|
48135
48072
|
} catch (error) {
|
|
48136
|
-
throw new
|
|
48073
|
+
throw new InternalServerError69("Failed to create text index on user.");
|
|
48137
48074
|
}
|
|
48138
48075
|
}
|
|
48139
48076
|
async function createUniqueIndex() {
|
|
@@ -48143,7 +48080,7 @@ function useUserRepoV2() {
|
|
|
48143
48080
|
{ unique: true }
|
|
48144
48081
|
);
|
|
48145
48082
|
} catch (error) {
|
|
48146
|
-
throw new
|
|
48083
|
+
throw new InternalServerError69("Failed to create unique index on user.");
|
|
48147
48084
|
}
|
|
48148
48085
|
}
|
|
48149
48086
|
async function createUser(value, session) {
|
|
@@ -48183,7 +48120,7 @@ function useUserRepoV2() {
|
|
|
48183
48120
|
);
|
|
48184
48121
|
return data;
|
|
48185
48122
|
} catch (error) {
|
|
48186
|
-
throw new
|
|
48123
|
+
throw new InternalServerError69("Failed to get user by email.");
|
|
48187
48124
|
}
|
|
48188
48125
|
}
|
|
48189
48126
|
async function getUserByEmailStatus(email) {
|
|
@@ -48206,7 +48143,7 @@ function useUserRepoV2() {
|
|
|
48206
48143
|
);
|
|
48207
48144
|
return data;
|
|
48208
48145
|
} catch (error) {
|
|
48209
|
-
throw new
|
|
48146
|
+
throw new InternalServerError69("Failed to get user by email.");
|
|
48210
48147
|
}
|
|
48211
48148
|
}
|
|
48212
48149
|
async function getUserById(id) {
|
|
@@ -48246,7 +48183,7 @@ function useUserRepoV2() {
|
|
|
48246
48183
|
} catch (error) {
|
|
48247
48184
|
if (error instanceof AppError27)
|
|
48248
48185
|
throw error;
|
|
48249
|
-
throw new
|
|
48186
|
+
throw new InternalServerError69("Failed to get user by id.");
|
|
48250
48187
|
}
|
|
48251
48188
|
}
|
|
48252
48189
|
async function getUserByReferralCode(referralCode) {
|
|
@@ -48263,7 +48200,7 @@ function useUserRepoV2() {
|
|
|
48263
48200
|
);
|
|
48264
48201
|
return data;
|
|
48265
48202
|
} catch (error) {
|
|
48266
|
-
throw new
|
|
48203
|
+
throw new InternalServerError69("Failed to get user by referral code.");
|
|
48267
48204
|
}
|
|
48268
48205
|
}
|
|
48269
48206
|
async function getByEmailApp(email, app) {
|
|
@@ -48283,7 +48220,7 @@ function useUserRepoV2() {
|
|
|
48283
48220
|
);
|
|
48284
48221
|
return data;
|
|
48285
48222
|
} catch (error) {
|
|
48286
|
-
throw new
|
|
48223
|
+
throw new InternalServerError69("Failed to get user by email and app.");
|
|
48287
48224
|
}
|
|
48288
48225
|
}
|
|
48289
48226
|
async function getUsersByOrgId({
|
|
@@ -48310,7 +48247,7 @@ function useUserRepoV2() {
|
|
|
48310
48247
|
}
|
|
48311
48248
|
if (organization) {
|
|
48312
48249
|
try {
|
|
48313
|
-
query.defaultOrg = new
|
|
48250
|
+
query.defaultOrg = new ObjectId125(organization);
|
|
48314
48251
|
cacheOptions.organization = organization.toString();
|
|
48315
48252
|
} catch (error) {
|
|
48316
48253
|
throw new BadRequestError198("Invalid organization ID format.");
|
|
@@ -48429,7 +48366,7 @@ function useUserRepoV2() {
|
|
|
48429
48366
|
});
|
|
48430
48367
|
return result;
|
|
48431
48368
|
} catch (error) {
|
|
48432
|
-
throw new
|
|
48369
|
+
throw new InternalServerError69("Failed to update user password.");
|
|
48433
48370
|
}
|
|
48434
48371
|
}
|
|
48435
48372
|
async function updateUserFieldById({ _id, field, value } = {}, session) {
|
|
@@ -48449,13 +48386,13 @@ function useUserRepoV2() {
|
|
|
48449
48386
|
);
|
|
48450
48387
|
}
|
|
48451
48388
|
try {
|
|
48452
|
-
_id = new
|
|
48389
|
+
_id = new ObjectId125(_id);
|
|
48453
48390
|
} catch (error) {
|
|
48454
48391
|
throw new BadRequestError198("Invalid ID.");
|
|
48455
48392
|
}
|
|
48456
48393
|
if (field === "defaultOrg") {
|
|
48457
48394
|
try {
|
|
48458
|
-
value = new
|
|
48395
|
+
value = new ObjectId125(value);
|
|
48459
48396
|
} catch (error) {
|
|
48460
48397
|
throw new BadRequestError198("Invalid organization ID.");
|
|
48461
48398
|
}
|
|
@@ -48486,7 +48423,7 @@ function useUserRepoV2() {
|
|
|
48486
48423
|
});
|
|
48487
48424
|
return `Successfully updated user ${field}.`;
|
|
48488
48425
|
} catch (error) {
|
|
48489
|
-
throw new
|
|
48426
|
+
throw new InternalServerError69(`Failed to update user ${field}.`);
|
|
48490
48427
|
}
|
|
48491
48428
|
}
|
|
48492
48429
|
async function updateBirthday({
|
|
@@ -48496,7 +48433,7 @@ function useUserRepoV2() {
|
|
|
48496
48433
|
year
|
|
48497
48434
|
}, session) {
|
|
48498
48435
|
try {
|
|
48499
|
-
_id = new
|
|
48436
|
+
_id = new ObjectId125(_id);
|
|
48500
48437
|
} catch (error) {
|
|
48501
48438
|
throw new BadRequestError198("Invalid user ID format.");
|
|
48502
48439
|
}
|
|
@@ -48521,12 +48458,12 @@ function useUserRepoV2() {
|
|
|
48521
48458
|
});
|
|
48522
48459
|
return "Successfully updated user birthday.";
|
|
48523
48460
|
} catch (error) {
|
|
48524
|
-
throw new
|
|
48461
|
+
throw new InternalServerError69("Failed to update user birthday.");
|
|
48525
48462
|
}
|
|
48526
48463
|
}
|
|
48527
48464
|
async function updatePassword({ _id, password }, session) {
|
|
48528
48465
|
try {
|
|
48529
|
-
_id = new
|
|
48466
|
+
_id = new ObjectId125(_id);
|
|
48530
48467
|
} catch (error) {
|
|
48531
48468
|
throw new BadRequestError198("Invalid user ID format.");
|
|
48532
48469
|
}
|
|
@@ -48544,7 +48481,7 @@ function useUserRepoV2() {
|
|
|
48544
48481
|
});
|
|
48545
48482
|
return result;
|
|
48546
48483
|
} catch (error) {
|
|
48547
|
-
throw new
|
|
48484
|
+
throw new InternalServerError69("Failed to update user password.");
|
|
48548
48485
|
}
|
|
48549
48486
|
}
|
|
48550
48487
|
return {
|
|
@@ -48584,7 +48521,7 @@ function useAuthServiceV2() {
|
|
|
48584
48521
|
);
|
|
48585
48522
|
}
|
|
48586
48523
|
if (!user._id) {
|
|
48587
|
-
throw new
|
|
48524
|
+
throw new InternalServerError70("Valid user ID.");
|
|
48588
48525
|
}
|
|
48589
48526
|
if (user.status === "suspended") {
|
|
48590
48527
|
throw new BadRequestError199(
|
|
@@ -48618,7 +48555,7 @@ function useAuthServiceV2() {
|
|
|
48618
48555
|
await delCache(`sid:${sid}`);
|
|
48619
48556
|
return "Session deleted successfully";
|
|
48620
48557
|
} catch (error) {
|
|
48621
|
-
throw new
|
|
48558
|
+
throw new InternalServerError70("Error deleting token");
|
|
48622
48559
|
}
|
|
48623
48560
|
}
|
|
48624
48561
|
async function verifyPassword(_id, password) {
|
|
@@ -48633,7 +48570,7 @@ function useAuthServiceV2() {
|
|
|
48633
48570
|
if (error instanceof BadRequestError199) {
|
|
48634
48571
|
throw error;
|
|
48635
48572
|
}
|
|
48636
|
-
throw new
|
|
48573
|
+
throw new InternalServerError70("Error during password verification");
|
|
48637
48574
|
}
|
|
48638
48575
|
}
|
|
48639
48576
|
return {
|
|
@@ -48648,9 +48585,9 @@ import {
|
|
|
48648
48585
|
BadRequestError as BadRequestError200,
|
|
48649
48586
|
comparePassword as comparePassword4,
|
|
48650
48587
|
hashPassword as hashPassword5,
|
|
48651
|
-
InternalServerError as
|
|
48588
|
+
InternalServerError as InternalServerError71,
|
|
48652
48589
|
NotFoundError as NotFoundError54,
|
|
48653
|
-
useAtlas as
|
|
48590
|
+
useAtlas as useAtlas114,
|
|
48654
48591
|
useS3 as useS33
|
|
48655
48592
|
} from "@7365admin1/node-server-utils";
|
|
48656
48593
|
import "multer";
|
|
@@ -48677,7 +48614,7 @@ function useUserServiceV2() {
|
|
|
48677
48614
|
id = "",
|
|
48678
48615
|
name = ""
|
|
48679
48616
|
}) {
|
|
48680
|
-
const session =
|
|
48617
|
+
const session = useAtlas114.getClient()?.startSession();
|
|
48681
48618
|
session?.startTransaction();
|
|
48682
48619
|
try {
|
|
48683
48620
|
const signUp = await _getVerificationById(id);
|
|
@@ -48743,12 +48680,12 @@ function useUserServiceV2() {
|
|
|
48743
48680
|
throw new BadRequestError200("Passwords do not match.");
|
|
48744
48681
|
}
|
|
48745
48682
|
let hashedPassword;
|
|
48746
|
-
const session =
|
|
48683
|
+
const session = useAtlas114.getClient()?.startSession();
|
|
48747
48684
|
session?.startTransaction();
|
|
48748
48685
|
try {
|
|
48749
48686
|
hashedPassword = await hashPassword5(newPassword);
|
|
48750
48687
|
} catch (error) {
|
|
48751
|
-
throw new
|
|
48688
|
+
throw new InternalServerError71(`Error hashing password: ${error}`);
|
|
48752
48689
|
}
|
|
48753
48690
|
try {
|
|
48754
48691
|
const otpDoc = await _getVerificationById(id);
|
|
@@ -48763,7 +48700,7 @@ function useUserServiceV2() {
|
|
|
48763
48700
|
throw new NotFoundError54("User not found.");
|
|
48764
48701
|
}
|
|
48765
48702
|
if (!user._id) {
|
|
48766
|
-
throw new
|
|
48703
|
+
throw new InternalServerError71("Invalid user ID.");
|
|
48767
48704
|
}
|
|
48768
48705
|
await Promise.all([
|
|
48769
48706
|
_updateVerificationStatusById(id, "complete" /* COMPLETE */, session),
|
|
@@ -48794,7 +48731,7 @@ function useUserServiceV2() {
|
|
|
48794
48731
|
user,
|
|
48795
48732
|
previousProfile
|
|
48796
48733
|
}) {
|
|
48797
|
-
const session =
|
|
48734
|
+
const session = useAtlas114.getClient()?.startSession();
|
|
48798
48735
|
session?.startTransaction();
|
|
48799
48736
|
const _file = {
|
|
48800
48737
|
name: file.originalname,
|
|
@@ -48838,7 +48775,7 @@ function useUserServiceV2() {
|
|
|
48838
48775
|
try {
|
|
48839
48776
|
hashedPassword = await hashPassword5(newPassword);
|
|
48840
48777
|
if (!hashedPassword)
|
|
48841
|
-
throw new
|
|
48778
|
+
throw new InternalServerError71("Error hashing password.");
|
|
48842
48779
|
return await updatePassword({ _id: id, password: hashedPassword });
|
|
48843
48780
|
} catch (error) {
|
|
48844
48781
|
throw error;
|
|
@@ -49281,6 +49218,178 @@ function useUserControllerV2() {
|
|
|
49281
49218
|
updatePasswordById
|
|
49282
49219
|
};
|
|
49283
49220
|
}
|
|
49221
|
+
|
|
49222
|
+
// src/models/role-v2.model.ts
|
|
49223
|
+
import { BadRequestError as BadRequestError203 } from "@7365admin1/node-server-utils";
|
|
49224
|
+
import { ObjectId as ObjectId126 } from "mongodb";
|
|
49225
|
+
var MRoleV2 = class {
|
|
49226
|
+
constructor(value) {
|
|
49227
|
+
if (typeof value._id === "string") {
|
|
49228
|
+
try {
|
|
49229
|
+
value._id = new ObjectId126(value._id);
|
|
49230
|
+
} catch (error) {
|
|
49231
|
+
throw new BadRequestError203("Invalid role-v2 ID format.");
|
|
49232
|
+
}
|
|
49233
|
+
}
|
|
49234
|
+
if (typeof value.site === "string" && value.site.length === 24) {
|
|
49235
|
+
try {
|
|
49236
|
+
value.site = new ObjectId126(value.site);
|
|
49237
|
+
} catch (error) {
|
|
49238
|
+
throw new BadRequestError203("Invalid site ID format.");
|
|
49239
|
+
}
|
|
49240
|
+
}
|
|
49241
|
+
if (typeof value.org === "string" && value.org.length === 24) {
|
|
49242
|
+
try {
|
|
49243
|
+
value.org = new ObjectId126(value.org);
|
|
49244
|
+
} catch (error) {
|
|
49245
|
+
throw new BadRequestError203("Invalid org ID format.");
|
|
49246
|
+
}
|
|
49247
|
+
}
|
|
49248
|
+
if (value.createdBy) {
|
|
49249
|
+
try {
|
|
49250
|
+
value.createdBy = new ObjectId126(value.createdBy);
|
|
49251
|
+
} catch (error) {
|
|
49252
|
+
throw new BadRequestError203("Invalid created by ID format.");
|
|
49253
|
+
}
|
|
49254
|
+
}
|
|
49255
|
+
this._id = value._id ?? new ObjectId126();
|
|
49256
|
+
this.name = value.name ?? "";
|
|
49257
|
+
this.permissions = value.permissions ?? [];
|
|
49258
|
+
this.site = value.site ?? "";
|
|
49259
|
+
this.platform = value.platform ?? "";
|
|
49260
|
+
this.type = value.type ?? "account";
|
|
49261
|
+
this.org = value.org ?? "";
|
|
49262
|
+
this.status = value.status ?? "active";
|
|
49263
|
+
this.createdBy = value.createdBy ?? "";
|
|
49264
|
+
this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
49265
|
+
this.updatedAt = value.updatedAt ?? "";
|
|
49266
|
+
this.deletedAt = value.deletedAt ?? "";
|
|
49267
|
+
}
|
|
49268
|
+
};
|
|
49269
|
+
|
|
49270
|
+
// src/repositories/role-v2.repo.ts
|
|
49271
|
+
import {
|
|
49272
|
+
BadRequestError as BadRequestError204,
|
|
49273
|
+
InternalServerError as InternalServerError72,
|
|
49274
|
+
useAtlas as useAtlas115,
|
|
49275
|
+
logger as logger182,
|
|
49276
|
+
useCache as useCache69
|
|
49277
|
+
} from "@7365admin1/node-server-utils";
|
|
49278
|
+
function useRoleRepoV2() {
|
|
49279
|
+
const db = useAtlas115.getDb();
|
|
49280
|
+
if (!db) {
|
|
49281
|
+
throw new InternalServerError72("Unable to connect to server.");
|
|
49282
|
+
}
|
|
49283
|
+
const namespace_collection = "roles.v2";
|
|
49284
|
+
const collection = db.collection(namespace_collection);
|
|
49285
|
+
async function createIndex() {
|
|
49286
|
+
try {
|
|
49287
|
+
await collection.createIndexes([
|
|
49288
|
+
{ key: { name: 1 } },
|
|
49289
|
+
{ key: { type: 1 } },
|
|
49290
|
+
{ key: { status: 1 } }
|
|
49291
|
+
]);
|
|
49292
|
+
} catch (error) {
|
|
49293
|
+
throw new InternalServerError72("Failed to create index on role.");
|
|
49294
|
+
}
|
|
49295
|
+
}
|
|
49296
|
+
async function createTextIndex() {
|
|
49297
|
+
try {
|
|
49298
|
+
await collection.createIndex({ name: "text" });
|
|
49299
|
+
} catch (error) {
|
|
49300
|
+
throw new InternalServerError72("Failed to create text index on role.");
|
|
49301
|
+
}
|
|
49302
|
+
}
|
|
49303
|
+
async function createUniqueIndex() {
|
|
49304
|
+
try {
|
|
49305
|
+
await collection.createIndex(
|
|
49306
|
+
{ name: 1, site: 1, platform: 1, type: 1, org: 1, deletedAt: 1 },
|
|
49307
|
+
{ unique: true }
|
|
49308
|
+
);
|
|
49309
|
+
} catch (error) {
|
|
49310
|
+
throw new InternalServerError72("Failed to create unique index on role.");
|
|
49311
|
+
}
|
|
49312
|
+
}
|
|
49313
|
+
const { delNamespace } = useCache69(namespace_collection);
|
|
49314
|
+
async function addRole(value, session) {
|
|
49315
|
+
value = new MRoleV2(value);
|
|
49316
|
+
try {
|
|
49317
|
+
const res = await collection.insertOne(value, { session });
|
|
49318
|
+
delNamespace().then(() => {
|
|
49319
|
+
logger182.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
49320
|
+
}).catch((err) => {
|
|
49321
|
+
logger182.error(
|
|
49322
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
49323
|
+
err
|
|
49324
|
+
);
|
|
49325
|
+
});
|
|
49326
|
+
return res.insertedId;
|
|
49327
|
+
} catch (error) {
|
|
49328
|
+
logger182.log({ level: "error", message: `${error}` });
|
|
49329
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
49330
|
+
if (isDuplicated) {
|
|
49331
|
+
throw new BadRequestError204("Role already exists.");
|
|
49332
|
+
}
|
|
49333
|
+
throw new InternalServerError72("Failed to create role.");
|
|
49334
|
+
}
|
|
49335
|
+
}
|
|
49336
|
+
return {
|
|
49337
|
+
createIndex,
|
|
49338
|
+
createTextIndex,
|
|
49339
|
+
createUniqueIndex,
|
|
49340
|
+
addRole
|
|
49341
|
+
};
|
|
49342
|
+
}
|
|
49343
|
+
|
|
49344
|
+
// src/services/role-v2.service.ts
|
|
49345
|
+
function useRoleServiceV2() {
|
|
49346
|
+
const { addRole: _addRole } = useRoleRepoV2();
|
|
49347
|
+
async function createRole(value) {
|
|
49348
|
+
try {
|
|
49349
|
+
return await _addRole(value);
|
|
49350
|
+
} catch (error) {
|
|
49351
|
+
throw error;
|
|
49352
|
+
}
|
|
49353
|
+
}
|
|
49354
|
+
return { createRole };
|
|
49355
|
+
}
|
|
49356
|
+
|
|
49357
|
+
// src/controllers/role-v2.controller.ts
|
|
49358
|
+
import Joi129 from "joi";
|
|
49359
|
+
import { BadRequestError as BadRequestError205, logger as logger183 } from "@7365admin1/node-server-utils";
|
|
49360
|
+
function useRoleControllerV2() {
|
|
49361
|
+
const { createRole: _createRole } = useRoleServiceV2();
|
|
49362
|
+
async function createRole(req, res, next) {
|
|
49363
|
+
const validation = Joi129.object({
|
|
49364
|
+
name: Joi129.string().required(),
|
|
49365
|
+
site: Joi129.string().hex().required(),
|
|
49366
|
+
platform: Joi129.string().required(),
|
|
49367
|
+
permissions: Joi129.array().items(Joi129.string()).required(),
|
|
49368
|
+
type: Joi129.string().optional().allow("", null),
|
|
49369
|
+
org: Joi129.string().hex().optional().allow("", null)
|
|
49370
|
+
});
|
|
49371
|
+
const payload = { ...req.body };
|
|
49372
|
+
const { error, value } = validation.validate(payload, { abortEarly: false });
|
|
49373
|
+
if (error) {
|
|
49374
|
+
const message = error.details.map((item) => item.message).join(", ");
|
|
49375
|
+
logger183.log({ level: "error", message });
|
|
49376
|
+
next(new BadRequestError205(message));
|
|
49377
|
+
return;
|
|
49378
|
+
}
|
|
49379
|
+
try {
|
|
49380
|
+
const role = await _createRole(value);
|
|
49381
|
+
res.status(201).json({ message: "Successfully created role.", data: { role } });
|
|
49382
|
+
return;
|
|
49383
|
+
} catch (error2) {
|
|
49384
|
+
logger183.log({ level: "error", message: error2.message });
|
|
49385
|
+
next(error2);
|
|
49386
|
+
return;
|
|
49387
|
+
}
|
|
49388
|
+
}
|
|
49389
|
+
return {
|
|
49390
|
+
createRole
|
|
49391
|
+
};
|
|
49392
|
+
}
|
|
49284
49393
|
export {
|
|
49285
49394
|
ANPRMode,
|
|
49286
49395
|
AccessTypeProps,
|
|
@@ -49344,6 +49453,7 @@ export {
|
|
|
49344
49453
|
MPromoCode,
|
|
49345
49454
|
MRobot,
|
|
49346
49455
|
MRole,
|
|
49456
|
+
MRoleV2,
|
|
49347
49457
|
MServiceProvider,
|
|
49348
49458
|
MServiceProviderBilling,
|
|
49349
49459
|
MSession,
|
|
@@ -49366,6 +49476,7 @@ export {
|
|
|
49366
49476
|
OvernightParkingRequestStatus,
|
|
49367
49477
|
PERSON_TYPES,
|
|
49368
49478
|
PMDashboardCollection,
|
|
49479
|
+
PStatus,
|
|
49369
49480
|
Period,
|
|
49370
49481
|
PersonStatus,
|
|
49371
49482
|
PersonTypes,
|
|
@@ -49373,6 +49484,7 @@ export {
|
|
|
49373
49484
|
SiteStatus,
|
|
49374
49485
|
SortFields,
|
|
49375
49486
|
SortOrder,
|
|
49487
|
+
Status,
|
|
49376
49488
|
SubscriptionType,
|
|
49377
49489
|
UseAccessManagementRepo,
|
|
49378
49490
|
UserStatus,
|
|
@@ -49627,7 +49739,10 @@ export {
|
|
|
49627
49739
|
useRobotRepo,
|
|
49628
49740
|
useRobotService,
|
|
49629
49741
|
useRoleController,
|
|
49742
|
+
useRoleControllerV2,
|
|
49630
49743
|
useRoleRepo,
|
|
49744
|
+
useRoleRepoV2,
|
|
49745
|
+
useRoleServiceV2,
|
|
49631
49746
|
useServiceProviderBillingController,
|
|
49632
49747
|
useServiceProviderBillingRepo,
|
|
49633
49748
|
useServiceProviderBillingService,
|