@7365admin1/core 2.37.0 → 2.39.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +168 -102
- package/dist/index.js +1157 -799
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +965 -614
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.js
CHANGED
|
@@ -32,6 +32,7 @@ var src_exports = {};
|
|
|
32
32
|
__export(src_exports, {
|
|
33
33
|
ANPRMode: () => ANPRMode,
|
|
34
34
|
AccessTypeProps: () => AccessTypeProps,
|
|
35
|
+
AppServiceType: () => AppServiceType,
|
|
35
36
|
BuildingStatus: () => BuildingStatus,
|
|
36
37
|
BulletinRecipient: () => BulletinRecipient,
|
|
37
38
|
BulletinSort: () => BulletinSort,
|
|
@@ -92,6 +93,7 @@ __export(src_exports, {
|
|
|
92
93
|
MPromoCode: () => MPromoCode,
|
|
93
94
|
MRobot: () => MRobot,
|
|
94
95
|
MRole: () => MRole,
|
|
96
|
+
MRoleV2: () => MRoleV2,
|
|
95
97
|
MServiceProvider: () => MServiceProvider,
|
|
96
98
|
MServiceProviderBilling: () => MServiceProviderBilling,
|
|
97
99
|
MSession: () => MSession,
|
|
@@ -114,6 +116,7 @@ __export(src_exports, {
|
|
|
114
116
|
OvernightParkingRequestStatus: () => OvernightParkingRequestStatus,
|
|
115
117
|
PERSON_TYPES: () => PERSON_TYPES,
|
|
116
118
|
PMDashboardCollection: () => PMDashboardCollection,
|
|
119
|
+
PStatus: () => PStatus,
|
|
117
120
|
Period: () => Period,
|
|
118
121
|
PersonStatus: () => PersonStatus,
|
|
119
122
|
PersonTypes: () => PersonTypes,
|
|
@@ -121,6 +124,7 @@ __export(src_exports, {
|
|
|
121
124
|
SiteStatus: () => SiteStatus,
|
|
122
125
|
SortFields: () => SortFields,
|
|
123
126
|
SortOrder: () => SortOrder,
|
|
127
|
+
Status: () => Status,
|
|
124
128
|
SubscriptionType: () => SubscriptionType,
|
|
125
129
|
UseAccessManagementRepo: () => UseAccessManagementRepo,
|
|
126
130
|
UserStatus: () => UserStatus,
|
|
@@ -375,7 +379,10 @@ __export(src_exports, {
|
|
|
375
379
|
useRobotRepo: () => useRobotRepo,
|
|
376
380
|
useRobotService: () => useRobotService,
|
|
377
381
|
useRoleController: () => useRoleController,
|
|
382
|
+
useRoleControllerV2: () => useRoleControllerV2,
|
|
378
383
|
useRoleRepo: () => useRoleRepo,
|
|
384
|
+
useRoleRepoV2: () => useRoleRepoV2,
|
|
385
|
+
useRoleServiceV2: () => useRoleServiceV2,
|
|
379
386
|
useServiceProviderBillingController: () => useServiceProviderBillingController,
|
|
380
387
|
useServiceProviderBillingRepo: () => useServiceProviderBillingRepo,
|
|
381
388
|
useServiceProviderBillingService: () => useServiceProviderBillingService,
|
|
@@ -436,6 +443,19 @@ __export(src_exports, {
|
|
|
436
443
|
});
|
|
437
444
|
module.exports = __toCommonJS(src_exports);
|
|
438
445
|
|
|
446
|
+
// src/models/base.model.ts
|
|
447
|
+
var AppServiceType = /* @__PURE__ */ ((AppServiceType2) => {
|
|
448
|
+
AppServiceType2["REAL_ESTATE_DEVELOPER"] = "real_estate_developer";
|
|
449
|
+
AppServiceType2["PROPERTY_MANAGEMENT_AGENCY"] = "property_management_agency";
|
|
450
|
+
AppServiceType2["SECURITY_AGENCY"] = "security_agency";
|
|
451
|
+
AppServiceType2["CLEANING_SERVICES"] = "cleaning_services";
|
|
452
|
+
AppServiceType2["MECHANICAL_ELECTRICAL_SERVICES"] = "mechanical_electrical_services";
|
|
453
|
+
AppServiceType2["LANDSCAPING_SERVICES"] = "landscaping_services";
|
|
454
|
+
AppServiceType2["PEST_CONTROL_SERVICES"] = "pest_control_services";
|
|
455
|
+
AppServiceType2["POOL_MAINTENANCE_SERVICES"] = "pool_maintenance_services";
|
|
456
|
+
return AppServiceType2;
|
|
457
|
+
})(AppServiceType || {});
|
|
458
|
+
|
|
439
459
|
// src/models/session.model.ts
|
|
440
460
|
var import_node_server_utils = require("@7365admin1/node-server-utils");
|
|
441
461
|
var import_joi = __toESM(require("joi"));
|
|
@@ -5178,6 +5198,7 @@ function useSiteRepo() {
|
|
|
5178
5198
|
|
|
5179
5199
|
// src/services/verification.service.ts
|
|
5180
5200
|
var import_joi11 = __toESM(require("joi"));
|
|
5201
|
+
var import_path = __toESM(require("path"));
|
|
5181
5202
|
function useVerificationService() {
|
|
5182
5203
|
const MailerConfig = {
|
|
5183
5204
|
host: MAILER_TRANSPORT_HOST,
|
|
@@ -5208,7 +5229,6 @@ function useVerificationService() {
|
|
|
5208
5229
|
expireAt: new Date(
|
|
5209
5230
|
(/* @__PURE__ */ new Date()).getTime() + 72 * 60 * 60 * 1e3
|
|
5210
5231
|
).toISOString(),
|
|
5211
|
-
// 72 hours (3 days) from now
|
|
5212
5232
|
createdAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
5213
5233
|
};
|
|
5214
5234
|
if (value.metadata?.org)
|
|
@@ -5296,8 +5316,11 @@ function useVerificationService() {
|
|
|
5296
5316
|
subject = "Service Provider Organization Invite";
|
|
5297
5317
|
}
|
|
5298
5318
|
const res = await add(value);
|
|
5299
|
-
const
|
|
5300
|
-
|
|
5319
|
+
const filePath = import_path.default.resolve(
|
|
5320
|
+
__dirname,
|
|
5321
|
+
"../public/handlebars",
|
|
5322
|
+
value.type
|
|
5323
|
+
);
|
|
5301
5324
|
const link = org ? `${APP_MAIN}/verify/${value.type}/${res}` : `${APP_ORG}/organizations/create?email=${email}`;
|
|
5302
5325
|
const emailContent = (0, import_node_server_utils20.compileHandlebar)({
|
|
5303
5326
|
context: {
|
|
@@ -5333,6 +5356,9 @@ function useVerificationService() {
|
|
|
5333
5356
|
};
|
|
5334
5357
|
try {
|
|
5335
5358
|
const user = await getUserByEmail(email);
|
|
5359
|
+
if (!user) {
|
|
5360
|
+
throw new import_node_server_utils20.NotFoundError("Email not found");
|
|
5361
|
+
}
|
|
5336
5362
|
const res = await add(value);
|
|
5337
5363
|
const dir = __dirname;
|
|
5338
5364
|
const filePath = (0, import_node_server_utils20.getDirectory)(dir, "./public/handlebars/forget-password");
|
|
@@ -13399,7 +13425,7 @@ var schemaVisitorTransaction = import_joi36.default.object({
|
|
|
13399
13425
|
checkOutRemarks: import_joi36.default.string().optional().allow("", null),
|
|
13400
13426
|
expectedCheckIn: import_joi36.default.string().isoDate().optional(),
|
|
13401
13427
|
purpose: import_joi36.default.string().optional().allow(null, ""),
|
|
13402
|
-
|
|
13428
|
+
inviterId: import_joi36.default.any().optional().allow(null, "")
|
|
13403
13429
|
});
|
|
13404
13430
|
var schemaUpdateVisTrans = import_joi36.default.object({
|
|
13405
13431
|
_id: import_joi36.default.string().hex().length(24).required(),
|
|
@@ -13508,11 +13534,11 @@ function MVisitorTransaction(value) {
|
|
|
13508
13534
|
return p;
|
|
13509
13535
|
});
|
|
13510
13536
|
}
|
|
13511
|
-
if (value.
|
|
13537
|
+
if (value.inviterId && typeof value.inviterId === "string") {
|
|
13512
13538
|
try {
|
|
13513
|
-
value.
|
|
13539
|
+
value.inviterId = new import_mongodb39.ObjectId(value.inviterId);
|
|
13514
13540
|
} catch (error2) {
|
|
13515
|
-
throw new Error("Invalid
|
|
13541
|
+
throw new Error("Invalid inviter ID.");
|
|
13516
13542
|
}
|
|
13517
13543
|
}
|
|
13518
13544
|
const newDate = /* @__PURE__ */ new Date();
|
|
@@ -13555,11 +13581,11 @@ function MVisitorTransaction(value) {
|
|
|
13555
13581
|
numberOfPassengers: value.numberOfPassengers ?? null,
|
|
13556
13582
|
email: value.email,
|
|
13557
13583
|
isOvernightParking: value.isOvernightParking ?? false,
|
|
13558
|
-
|
|
13584
|
+
inviterId: value.inviterId ?? "",
|
|
13559
13585
|
overnightParking: value.isOvernightParking == true ? {
|
|
13560
13586
|
status: "pending approval",
|
|
13561
13587
|
remarks: "",
|
|
13562
|
-
updatedBy: value.
|
|
13588
|
+
updatedBy: value.inviterId ?? ""
|
|
13563
13589
|
} : null,
|
|
13564
13590
|
arrivalTime: value.arrivalTime,
|
|
13565
13591
|
duration: value.duration
|
|
@@ -13610,14 +13636,15 @@ function useVisitorTransactionRepo() {
|
|
|
13610
13636
|
page = 1,
|
|
13611
13637
|
limit = 10,
|
|
13612
13638
|
sort = {},
|
|
13613
|
-
status
|
|
13639
|
+
status,
|
|
13614
13640
|
org = "",
|
|
13615
13641
|
site = "",
|
|
13616
13642
|
dateTo = "",
|
|
13617
13643
|
dateFrom = "",
|
|
13618
13644
|
type = "",
|
|
13619
13645
|
checkedOut,
|
|
13620
|
-
plateNumber = ""
|
|
13646
|
+
plateNumber = "",
|
|
13647
|
+
tab = ""
|
|
13621
13648
|
}) {
|
|
13622
13649
|
page = page > 0 ? page - 1 : 0;
|
|
13623
13650
|
const skip = page * limit;
|
|
@@ -13635,7 +13662,6 @@ function useVisitorTransactionRepo() {
|
|
|
13635
13662
|
expectedCheckInFilter.$lte = new Date(dateTo);
|
|
13636
13663
|
}
|
|
13637
13664
|
const query = {
|
|
13638
|
-
status,
|
|
13639
13665
|
...import_mongodb40.ObjectId.isValid(org) && { org: new import_mongodb40.ObjectId(org) },
|
|
13640
13666
|
...import_mongodb40.ObjectId.isValid(site) && { site: new import_mongodb40.ObjectId(site) },
|
|
13641
13667
|
...Object.keys(checkInFilter).length > 0 && { checkIn: checkInFilter },
|
|
@@ -13643,7 +13669,9 @@ function useVisitorTransactionRepo() {
|
|
|
13643
13669
|
...Array.isArray(type) ? { type: { $in: type } } : type ? { type } : {},
|
|
13644
13670
|
...checkedOut == false && { checkOut: { $eq: null } },
|
|
13645
13671
|
...search && { $text: { $search: search } },
|
|
13646
|
-
...plateNumber && { plateNumber }
|
|
13672
|
+
...plateNumber && { plateNumber },
|
|
13673
|
+
...status && { status },
|
|
13674
|
+
...tab == "Overnight Parking" && { isOvernightParking: true }
|
|
13647
13675
|
};
|
|
13648
13676
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
13649
13677
|
try {
|
|
@@ -13789,7 +13817,31 @@ function useVisitorTransactionRepo() {
|
|
|
13789
13817
|
},
|
|
13790
13818
|
{ $sort: sort },
|
|
13791
13819
|
{ $skip: skip },
|
|
13792
|
-
{ $limit: limit }
|
|
13820
|
+
{ $limit: limit },
|
|
13821
|
+
{
|
|
13822
|
+
$lookup: {
|
|
13823
|
+
from: "users",
|
|
13824
|
+
localField: "inviterId",
|
|
13825
|
+
foreignField: "_id",
|
|
13826
|
+
as: "inviterData"
|
|
13827
|
+
}
|
|
13828
|
+
},
|
|
13829
|
+
{
|
|
13830
|
+
$unwind: {
|
|
13831
|
+
path: "$inviterData",
|
|
13832
|
+
preserveNullAndEmptyArrays: true
|
|
13833
|
+
}
|
|
13834
|
+
},
|
|
13835
|
+
{
|
|
13836
|
+
$addFields: {
|
|
13837
|
+
inviterName: "$inviterData.name"
|
|
13838
|
+
}
|
|
13839
|
+
},
|
|
13840
|
+
{
|
|
13841
|
+
$project: {
|
|
13842
|
+
inviterData: 0
|
|
13843
|
+
}
|
|
13844
|
+
}
|
|
13793
13845
|
]).toArray(),
|
|
13794
13846
|
collection.aggregate([...basePipeline, { $count: "total" }]).toArray()
|
|
13795
13847
|
]);
|
|
@@ -14105,7 +14157,7 @@ function MVehicle(value) {
|
|
|
14105
14157
|
block: value.block ?? 0,
|
|
14106
14158
|
level: value.level ?? "",
|
|
14107
14159
|
unit: value.unit ?? "",
|
|
14108
|
-
nric: value.nric,
|
|
14160
|
+
nric: value.nric ?? "",
|
|
14109
14161
|
remarks: value.remarks ?? "",
|
|
14110
14162
|
seasonPassType: value.seasonPassType ?? "",
|
|
14111
14163
|
start: value.start ?? createdAt,
|
|
@@ -14165,7 +14217,7 @@ function MVehicleTransaction(value) {
|
|
|
14165
14217
|
var import_node_server_utils73 = require("@7365admin1/node-server-utils");
|
|
14166
14218
|
var import_fs = require("fs");
|
|
14167
14219
|
var import_joi39 = __toESM(require("joi"));
|
|
14168
|
-
var
|
|
14220
|
+
var path2 = __toESM(require("path"));
|
|
14169
14221
|
var import_urllib = require("urllib");
|
|
14170
14222
|
|
|
14171
14223
|
// src/repositories/vehicle.repo.ts
|
|
@@ -14800,6 +14852,66 @@ function useVehicleRepo() {
|
|
|
14800
14852
|
throw error;
|
|
14801
14853
|
}
|
|
14802
14854
|
}
|
|
14855
|
+
async function bulkUpsertVehicles(values, session) {
|
|
14856
|
+
try {
|
|
14857
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
14858
|
+
return {
|
|
14859
|
+
matchedCount: 0,
|
|
14860
|
+
modifiedCount: 0,
|
|
14861
|
+
upsertedCount: 0
|
|
14862
|
+
};
|
|
14863
|
+
}
|
|
14864
|
+
const now = (/* @__PURE__ */ new Date()).toISOString();
|
|
14865
|
+
const operations = values.map((item) => {
|
|
14866
|
+
const vehicle = MVehicle(item);
|
|
14867
|
+
const plateNumber = Array.isArray(vehicle.plateNumber) ? vehicle.plateNumber[0] : vehicle.plateNumber;
|
|
14868
|
+
const { createdAt, ...rest } = vehicle;
|
|
14869
|
+
return {
|
|
14870
|
+
updateOne: {
|
|
14871
|
+
filter: {
|
|
14872
|
+
site: vehicle.site,
|
|
14873
|
+
plateNumber,
|
|
14874
|
+
$or: [
|
|
14875
|
+
{ deletedAt: "" },
|
|
14876
|
+
{ deletedAt: null },
|
|
14877
|
+
{ deletedAt: { $exists: false } }
|
|
14878
|
+
]
|
|
14879
|
+
},
|
|
14880
|
+
update: {
|
|
14881
|
+
$set: {
|
|
14882
|
+
...rest,
|
|
14883
|
+
plateNumber,
|
|
14884
|
+
updatedAt: now
|
|
14885
|
+
},
|
|
14886
|
+
$setOnInsert: {
|
|
14887
|
+
createdAt: vehicle.createdAt || now
|
|
14888
|
+
}
|
|
14889
|
+
},
|
|
14890
|
+
upsert: true
|
|
14891
|
+
}
|
|
14892
|
+
};
|
|
14893
|
+
});
|
|
14894
|
+
const res = await collection.bulkWrite(operations, {
|
|
14895
|
+
ordered: false,
|
|
14896
|
+
session
|
|
14897
|
+
});
|
|
14898
|
+
return {
|
|
14899
|
+
matchedCount: res.matchedCount,
|
|
14900
|
+
modifiedCount: res.modifiedCount,
|
|
14901
|
+
upsertedCount: res.upsertedCount,
|
|
14902
|
+
upsertedIds: res.upsertedIds
|
|
14903
|
+
};
|
|
14904
|
+
} catch (error) {
|
|
14905
|
+
import_node_server_utils70.logger.log({
|
|
14906
|
+
level: "error",
|
|
14907
|
+
message: error.message
|
|
14908
|
+
});
|
|
14909
|
+
if (error instanceof import_node_server_utils70.AppError) {
|
|
14910
|
+
throw error;
|
|
14911
|
+
}
|
|
14912
|
+
throw new Error("Failed to bulk upsert vehicles.");
|
|
14913
|
+
}
|
|
14914
|
+
}
|
|
14803
14915
|
return {
|
|
14804
14916
|
createIndex,
|
|
14805
14917
|
createTextIndex,
|
|
@@ -14814,7 +14926,8 @@ function useVehicleRepo() {
|
|
|
14814
14926
|
getVehiclesByNRIC,
|
|
14815
14927
|
deleteExpiredVehicles,
|
|
14816
14928
|
getAllVehiclesByUnitId,
|
|
14817
|
-
getAllExpiredVehicles
|
|
14929
|
+
getAllExpiredVehicles,
|
|
14930
|
+
bulkUpsertVehicles
|
|
14818
14931
|
};
|
|
14819
14932
|
}
|
|
14820
14933
|
|
|
@@ -15446,7 +15559,8 @@ function useVehicleService() {
|
|
|
15446
15559
|
getVehicleById: _getVehicleById,
|
|
15447
15560
|
deleteExpiredVehicles: _deleteExpiredVehicles,
|
|
15448
15561
|
getVehicleByPlateNumber: _getVehicleByPlateNumber,
|
|
15449
|
-
getAllExpiredVehicles: _getAllExpiredVehicles
|
|
15562
|
+
getAllExpiredVehicles: _getAllExpiredVehicles,
|
|
15563
|
+
bulkUpsertVehicles: _bulkUpsertVehicles
|
|
15450
15564
|
} = useVehicleRepo();
|
|
15451
15565
|
const {
|
|
15452
15566
|
addPlateNumber: _addPlateNumber,
|
|
@@ -16063,13 +16177,38 @@ function useVehicleService() {
|
|
|
16063
16177
|
session.endSession();
|
|
16064
16178
|
}
|
|
16065
16179
|
}
|
|
16180
|
+
async function bulkUpsertVehicles(values) {
|
|
16181
|
+
const session = import_node_server_utils72.useAtlas.getClient()?.startSession();
|
|
16182
|
+
if (!session) {
|
|
16183
|
+
throw new Error("Unable to start session for vehicle service.");
|
|
16184
|
+
}
|
|
16185
|
+
try {
|
|
16186
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
16187
|
+
throw new Error("Vehicle list is required.");
|
|
16188
|
+
}
|
|
16189
|
+
const sanitizedValues = values.map((item) => {
|
|
16190
|
+
const plateNumber = Array.isArray(item.plateNumber) ? item.plateNumber[0] : item.plateNumber;
|
|
16191
|
+
return {
|
|
16192
|
+
...item,
|
|
16193
|
+
plateNumber: typeof plateNumber === "string" ? plateNumber.trim() : plateNumber
|
|
16194
|
+
};
|
|
16195
|
+
}).filter((item) => item.site && item.plateNumber);
|
|
16196
|
+
if (sanitizedValues.length === 0) {
|
|
16197
|
+
throw new Error("No valid vehicle plate numbers found.");
|
|
16198
|
+
}
|
|
16199
|
+
return await _bulkUpsertVehicles(sanitizedValues, session);
|
|
16200
|
+
} catch (error) {
|
|
16201
|
+
throw error;
|
|
16202
|
+
}
|
|
16203
|
+
}
|
|
16066
16204
|
return {
|
|
16067
16205
|
add,
|
|
16068
16206
|
deleteVehicle,
|
|
16069
16207
|
approveVehicleById,
|
|
16070
16208
|
processDeletingExpiredVehicles,
|
|
16071
16209
|
reactivateVehicleById,
|
|
16072
|
-
updateVehicleById
|
|
16210
|
+
updateVehicleById,
|
|
16211
|
+
bulkUpsertVehicles
|
|
16073
16212
|
};
|
|
16074
16213
|
}
|
|
16075
16214
|
|
|
@@ -16343,8 +16482,8 @@ function useDahuaService() {
|
|
|
16343
16482
|
const utcMs = Number(UTCMs) || Date.now() % 1e3;
|
|
16344
16483
|
const timeData = createFileNameFromEvent(utcSec, utcMs);
|
|
16345
16484
|
const filename = plateNumber ? `${gate}-${timeData}-${plateNumber}.jpeg` : `${gate}-${timeData}.jpeg`;
|
|
16346
|
-
const snapFolder =
|
|
16347
|
-
const dir =
|
|
16485
|
+
const snapFolder = path2.join(__dirname, `../snap/${site}/${filename}`);
|
|
16486
|
+
const dir = path2.dirname(snapFolder);
|
|
16348
16487
|
try {
|
|
16349
16488
|
await import_fs.promises.mkdir(dir, { recursive: true });
|
|
16350
16489
|
await import_fs.promises.writeFile(snapFolder, accumulatedImageBuffer);
|
|
@@ -16616,13 +16755,53 @@ function useDahuaService() {
|
|
|
16616
16755
|
throw error2;
|
|
16617
16756
|
}
|
|
16618
16757
|
}
|
|
16758
|
+
async function bulkInsertPlateNumber(value) {
|
|
16759
|
+
const validation = import_joi39.default.object({
|
|
16760
|
+
host: import_joi39.default.string().required(),
|
|
16761
|
+
username: import_joi39.default.string().required(),
|
|
16762
|
+
password: import_joi39.default.string().required(),
|
|
16763
|
+
plateNumber: import_joi39.default.string().required(),
|
|
16764
|
+
mode: import_joi39.default.string().valid(...Object.values(ANPRMode)).required(),
|
|
16765
|
+
start: import_joi39.default.string().isoDate().optional().allow("", null),
|
|
16766
|
+
end: import_joi39.default.string().isoDate().optional().allow("", null),
|
|
16767
|
+
owner: import_joi39.default.string().optional().allow("", null),
|
|
16768
|
+
isOpenGate: import_joi39.default.boolean().optional().allow(null),
|
|
16769
|
+
vehicleType: import_joi39.default.string().optional().allow("", null),
|
|
16770
|
+
vehicleColor: import_joi39.default.string().optional().allow("", null)
|
|
16771
|
+
});
|
|
16772
|
+
const { error } = validation.validate(value);
|
|
16773
|
+
if (error) {
|
|
16774
|
+
throw new import_node_server_utils73.BadRequestError(`Validation error: ${error.message}`);
|
|
16775
|
+
}
|
|
16776
|
+
value.owner = String(value.owner ?? "").substring(0, 15) || "unknown";
|
|
16777
|
+
value.vehicleType = String(value.vehicleType ?? "").substring(0, 31) || "unknown";
|
|
16778
|
+
value.vehicleColor = String(value.vehicleColor ?? "").substring(0, 31) || "unknown";
|
|
16779
|
+
const _openGate = String(value.isOpenGate);
|
|
16780
|
+
const isOpenGateString = _openGate && _openGate !== "undefined" ? _openGate : "true";
|
|
16781
|
+
const endpoint = `/cgi-bin/recordUpdater.cgi?action=insert&name=${value.mode}&PlateNumber=${value.plateNumber}&VehicleType=${value.vehicleType}&VehicleColor=${value.vehicleColor}&BeginTime=${value.start}&CancelTime=${value.end}&+OpenGate=${isOpenGateString}&MasterOfCar=${value.owner}`;
|
|
16782
|
+
try {
|
|
16783
|
+
const response = await useDahuaDigest({
|
|
16784
|
+
host: value.host,
|
|
16785
|
+
username: value.username,
|
|
16786
|
+
password: value.password,
|
|
16787
|
+
endpoint
|
|
16788
|
+
});
|
|
16789
|
+
return response;
|
|
16790
|
+
} catch (error2) {
|
|
16791
|
+
import_node_server_utils73.logger.error(`[${value.host}] Error bulk add plate number:`, error2);
|
|
16792
|
+
throw new import_node_server_utils73.BadRequestError(
|
|
16793
|
+
`Failed bulk adding plate number: ${error2.message}`
|
|
16794
|
+
);
|
|
16795
|
+
}
|
|
16796
|
+
}
|
|
16619
16797
|
return {
|
|
16620
16798
|
getSnapshot,
|
|
16621
16799
|
getTrafficJunction,
|
|
16622
16800
|
addPlateNumber,
|
|
16623
16801
|
removePlateNumber,
|
|
16624
16802
|
updatePlateNumber,
|
|
16625
|
-
getPlateNumber
|
|
16803
|
+
getPlateNumber,
|
|
16804
|
+
bulkInsertPlateNumber
|
|
16626
16805
|
};
|
|
16627
16806
|
}
|
|
16628
16807
|
|
|
@@ -18745,13 +18924,18 @@ function useBuildingUnitController() {
|
|
|
18745
18924
|
// src/controllers/vehicle.controller.ts
|
|
18746
18925
|
var import_node_server_utils86 = require("@7365admin1/node-server-utils");
|
|
18747
18926
|
var import_joi46 = __toESM(require("joi"));
|
|
18927
|
+
var import_exceljs = __toESM(require("exceljs"));
|
|
18928
|
+
var import_stream = require("stream");
|
|
18929
|
+
var import_csv_parser = __toESM(require("csv-parser"));
|
|
18930
|
+
var import_fs2 = __toESM(require("fs"));
|
|
18748
18931
|
function useVehicleController() {
|
|
18749
18932
|
const {
|
|
18750
18933
|
add: _add,
|
|
18751
18934
|
deleteVehicle: _deleteVehicle,
|
|
18752
18935
|
approveVehicleById: _approveVehicleById,
|
|
18753
18936
|
reactivateVehicleById: _reactivateVehicleById,
|
|
18754
|
-
updateVehicleById: _updateVehicleById
|
|
18937
|
+
updateVehicleById: _updateVehicleById,
|
|
18938
|
+
bulkUpsertVehicles: _bulkUpsertVehicles
|
|
18755
18939
|
} = useVehicleService();
|
|
18756
18940
|
const {
|
|
18757
18941
|
getSeasonPassTypes: _getSeasonPassTypes,
|
|
@@ -18760,6 +18944,183 @@ function useVehicleController() {
|
|
|
18760
18944
|
getVehiclesByNRIC: _getVehiclesByNRIC,
|
|
18761
18945
|
getAllVehiclesByUnitId: _getAllVehiclesByUnitId
|
|
18762
18946
|
} = useVehicleRepo();
|
|
18947
|
+
function normalizeRow(row) {
|
|
18948
|
+
return Object.fromEntries(
|
|
18949
|
+
Object.entries(row).map(([key, value]) => [
|
|
18950
|
+
key,
|
|
18951
|
+
typeof value === "string" ? value.trim() : value
|
|
18952
|
+
])
|
|
18953
|
+
);
|
|
18954
|
+
}
|
|
18955
|
+
function mapRowToVehicle(row) {
|
|
18956
|
+
const cleanRow = normalizeRow(row);
|
|
18957
|
+
return {
|
|
18958
|
+
name: cleanRow.fullName,
|
|
18959
|
+
category: cleanRow.userType,
|
|
18960
|
+
type: cleanRow.recordType,
|
|
18961
|
+
phoneNumber: cleanRow.phoneNumber || "",
|
|
18962
|
+
block: Number(cleanRow.block),
|
|
18963
|
+
level: String(cleanRow.level || ""),
|
|
18964
|
+
unitName: String(cleanRow.unit || ""),
|
|
18965
|
+
plateNumber: String(cleanRow.plateNumber || "").toUpperCase(),
|
|
18966
|
+
remarks: `Model: ${cleanRow.vehicleModel || ""}, Color: ${cleanRow.vehicleColor || ""}`,
|
|
18967
|
+
org: cleanRow.org,
|
|
18968
|
+
site: cleanRow.site,
|
|
18969
|
+
end: parseExpiryDate(cleanRow.subscriptionExpiry)
|
|
18970
|
+
};
|
|
18971
|
+
}
|
|
18972
|
+
function parseExpiryDate(value) {
|
|
18973
|
+
if (!value)
|
|
18974
|
+
return void 0;
|
|
18975
|
+
const [day, monthStr, yearShort] = value.split("-");
|
|
18976
|
+
const months = {
|
|
18977
|
+
Jan: 0,
|
|
18978
|
+
Feb: 1,
|
|
18979
|
+
Mar: 2,
|
|
18980
|
+
Apr: 3,
|
|
18981
|
+
May: 4,
|
|
18982
|
+
Jun: 5,
|
|
18983
|
+
Jul: 6,
|
|
18984
|
+
Aug: 7,
|
|
18985
|
+
Sep: 8,
|
|
18986
|
+
Oct: 9,
|
|
18987
|
+
Nov: 10,
|
|
18988
|
+
Dec: 11
|
|
18989
|
+
};
|
|
18990
|
+
const month = months[monthStr];
|
|
18991
|
+
if (month === void 0)
|
|
18992
|
+
return void 0;
|
|
18993
|
+
const year = 2e3 + Number(yearShort);
|
|
18994
|
+
const date = new Date(year, month, Number(day));
|
|
18995
|
+
return isNaN(date.getTime()) ? void 0 : date.toISOString();
|
|
18996
|
+
}
|
|
18997
|
+
async function uploadCsvVehicles(req, res, next) {
|
|
18998
|
+
try {
|
|
18999
|
+
if (!req.file) {
|
|
19000
|
+
next(new import_node_server_utils86.BadRequestError("CSV file is required."));
|
|
19001
|
+
return;
|
|
19002
|
+
}
|
|
19003
|
+
if (!req.file.originalname.toLowerCase().endsWith(".csv")) {
|
|
19004
|
+
next(new import_node_server_utils86.BadRequestError("Only .csv files are allowed."));
|
|
19005
|
+
return;
|
|
19006
|
+
}
|
|
19007
|
+
const rows = [];
|
|
19008
|
+
const stream = import_stream.Readable.from(req.file.buffer);
|
|
19009
|
+
stream.pipe((0, import_csv_parser.default)()).on("data", (row) => {
|
|
19010
|
+
rows.push(row);
|
|
19011
|
+
}).on("end", async () => {
|
|
19012
|
+
try {
|
|
19013
|
+
const vehicles = rows.map(mapRowToVehicle);
|
|
19014
|
+
const data = await _bulkUpsertVehicles(vehicles);
|
|
19015
|
+
res.status(200).json({
|
|
19016
|
+
message: "CSV import completed.",
|
|
19017
|
+
count: rows.length,
|
|
19018
|
+
data
|
|
19019
|
+
});
|
|
19020
|
+
} catch (error) {
|
|
19021
|
+
import_node_server_utils86.logger.log({ level: "error", message: error.message });
|
|
19022
|
+
next(error);
|
|
19023
|
+
}
|
|
19024
|
+
}).on("error", (error) => {
|
|
19025
|
+
import_node_server_utils86.logger.log({ level: "error", message: error.message });
|
|
19026
|
+
next(error);
|
|
19027
|
+
});
|
|
19028
|
+
} catch (error) {
|
|
19029
|
+
import_node_server_utils86.logger.log({ level: "error", message: error.message });
|
|
19030
|
+
next(error);
|
|
19031
|
+
}
|
|
19032
|
+
}
|
|
19033
|
+
async function uploadExcelVehicles(req, res, next) {
|
|
19034
|
+
try {
|
|
19035
|
+
if (!req.file) {
|
|
19036
|
+
next(new import_node_server_utils86.BadRequestError("Excel file is required."));
|
|
19037
|
+
return;
|
|
19038
|
+
}
|
|
19039
|
+
if (!req.file.originalname.toLowerCase().endsWith(".xlsx")) {
|
|
19040
|
+
next(new import_node_server_utils86.BadRequestError("Only .xlsx files are allowed."));
|
|
19041
|
+
return;
|
|
19042
|
+
}
|
|
19043
|
+
const schema2 = import_joi46.default.object({
|
|
19044
|
+
fullName: import_joi46.default.string().trim().required(),
|
|
19045
|
+
userType: import_joi46.default.string().trim().required(),
|
|
19046
|
+
recordType: import_joi46.default.string().trim().required(),
|
|
19047
|
+
phoneNumber: import_joi46.default.string().trim().allow("", null).optional(),
|
|
19048
|
+
block: import_joi46.default.number().required(),
|
|
19049
|
+
level: import_joi46.default.number().integer().min(1).required(),
|
|
19050
|
+
unit: import_joi46.default.number().integer().min(1).required(),
|
|
19051
|
+
plateNumber: import_joi46.default.string().trim().uppercase().required(),
|
|
19052
|
+
vehicleModel: import_joi46.default.string().trim().allow("", null).optional(),
|
|
19053
|
+
vehicleColor: import_joi46.default.string().trim().allow("", null).optional(),
|
|
19054
|
+
subscriptionExpiry: import_joi46.default.string().trim().allow("", null).optional(),
|
|
19055
|
+
site: import_joi46.default.string().hex().length(24).required(),
|
|
19056
|
+
org: import_joi46.default.string().hex().length(24).required()
|
|
19057
|
+
});
|
|
19058
|
+
const workbook = new import_exceljs.default.Workbook();
|
|
19059
|
+
await workbook.xlsx.readFile(req.file.path);
|
|
19060
|
+
const worksheet = workbook.worksheets[0];
|
|
19061
|
+
if (!worksheet) {
|
|
19062
|
+
next(new import_node_server_utils86.BadRequestError("No worksheet found in uploaded Excel file."));
|
|
19063
|
+
return;
|
|
19064
|
+
}
|
|
19065
|
+
const rows = [];
|
|
19066
|
+
const headerRow = worksheet.getRow(1);
|
|
19067
|
+
const headers = (headerRow.values || []).slice(1).map((header) => String(header ?? "").trim());
|
|
19068
|
+
worksheet.eachRow((row, rowNumber) => {
|
|
19069
|
+
if (rowNumber === 1)
|
|
19070
|
+
return;
|
|
19071
|
+
const rowData = {};
|
|
19072
|
+
headers.forEach((header, index) => {
|
|
19073
|
+
rowData[header] = row.getCell(index + 1).value ?? "";
|
|
19074
|
+
});
|
|
19075
|
+
const hasValue = Object.values(rowData).some(
|
|
19076
|
+
(value) => value !== null && value !== void 0 && value !== ""
|
|
19077
|
+
);
|
|
19078
|
+
if (hasValue) {
|
|
19079
|
+
rows.push(rowData);
|
|
19080
|
+
}
|
|
19081
|
+
});
|
|
19082
|
+
const validRows = [];
|
|
19083
|
+
const invalidRows = [];
|
|
19084
|
+
rows.forEach((row, index) => {
|
|
19085
|
+
const { error, value } = schema2.validate(row, {
|
|
19086
|
+
abortEarly: false,
|
|
19087
|
+
convert: true
|
|
19088
|
+
});
|
|
19089
|
+
if (error) {
|
|
19090
|
+
invalidRows.push({
|
|
19091
|
+
row: index + 2,
|
|
19092
|
+
data: row,
|
|
19093
|
+
errors: error.details.map((d) => d.message)
|
|
19094
|
+
});
|
|
19095
|
+
return;
|
|
19096
|
+
}
|
|
19097
|
+
validRows.push(value);
|
|
19098
|
+
});
|
|
19099
|
+
const vehicles = validRows.map(mapRowToVehicle);
|
|
19100
|
+
let data = {
|
|
19101
|
+
matchedCount: 0,
|
|
19102
|
+
modifiedCount: 0,
|
|
19103
|
+
upsertedCount: 0
|
|
19104
|
+
};
|
|
19105
|
+
if (vehicles.length > 0) {
|
|
19106
|
+
data = await _bulkUpsertVehicles(vehicles);
|
|
19107
|
+
}
|
|
19108
|
+
res.status(200).json({
|
|
19109
|
+
message: "Excel import completed.",
|
|
19110
|
+
sheetName: worksheet.name,
|
|
19111
|
+
totalRows: rows.length,
|
|
19112
|
+
validRows: validRows.length,
|
|
19113
|
+
invalidRows: invalidRows.length,
|
|
19114
|
+
validationErrors: invalidRows,
|
|
19115
|
+
data
|
|
19116
|
+
});
|
|
19117
|
+
import_fs2.default.unlink(req.file.path, () => {
|
|
19118
|
+
});
|
|
19119
|
+
} catch (error) {
|
|
19120
|
+
import_node_server_utils86.logger.log({ level: "error", message: error.message });
|
|
19121
|
+
next(error);
|
|
19122
|
+
}
|
|
19123
|
+
}
|
|
18763
19124
|
async function add(req, res, next) {
|
|
18764
19125
|
const { error, value } = vehicleSchema.validate(req.body, {
|
|
18765
19126
|
abortEarly: false
|
|
@@ -19094,7 +19455,9 @@ function useVehicleController() {
|
|
|
19094
19455
|
approveVehicleById,
|
|
19095
19456
|
getVehiclesByNRIC,
|
|
19096
19457
|
reactivateVehicleById,
|
|
19097
|
-
getAllVehiclesByUnitId
|
|
19458
|
+
getAllVehiclesByUnitId,
|
|
19459
|
+
uploadCsvVehicles,
|
|
19460
|
+
uploadExcelVehicles
|
|
19098
19461
|
};
|
|
19099
19462
|
}
|
|
19100
19463
|
|
|
@@ -19852,21 +20215,6 @@ function useCustomerSiteController() {
|
|
|
19852
20215
|
var import_node_server_utils92 = require("@7365admin1/node-server-utils");
|
|
19853
20216
|
var import_joi51 = __toESM(require("joi"));
|
|
19854
20217
|
var import_mongodb51 = require("mongodb");
|
|
19855
|
-
|
|
19856
|
-
// src/models/base.model.ts
|
|
19857
|
-
var AppServiceType = /* @__PURE__ */ ((AppServiceType2) => {
|
|
19858
|
-
AppServiceType2["REAL_ESTATE_DEVELOPER"] = "real_estate_developer";
|
|
19859
|
-
AppServiceType2["PROPERTY_MANAGEMENT_AGENCY"] = "property_management_agency";
|
|
19860
|
-
AppServiceType2["SECURITY_AGENCY"] = "security_agency";
|
|
19861
|
-
AppServiceType2["CLEANING_SERVICES"] = "cleaning_services";
|
|
19862
|
-
AppServiceType2["MECHANICAL_ELECTRICAL_SERVICES"] = "mechanical_electrical_services";
|
|
19863
|
-
AppServiceType2["LANDSCAPING_SERVICES"] = "landscaping_services";
|
|
19864
|
-
AppServiceType2["PEST_CONTROL_SERVICES"] = "pest_control_services";
|
|
19865
|
-
AppServiceType2["POOL_MAINTENANCE_SERVICES"] = "pool_maintenance_services";
|
|
19866
|
-
return AppServiceType2;
|
|
19867
|
-
})(AppServiceType || {});
|
|
19868
|
-
|
|
19869
|
-
// src/models/attendance-settings.model.ts
|
|
19870
20218
|
var attendanceSettingsSchema = import_joi51.default.object({
|
|
19871
20219
|
site: import_joi51.default.string().hex().required(),
|
|
19872
20220
|
serviceType: import_joi51.default.string().valid(...Object.values(AppServiceType)).required(),
|
|
@@ -22300,7 +22648,7 @@ function useVisitorTransactionService() {
|
|
|
22300
22648
|
org: inviter?.org.toString(),
|
|
22301
22649
|
site: inviter?.site.toString(),
|
|
22302
22650
|
status: "approved" /* APPROVED */,
|
|
22303
|
-
|
|
22651
|
+
inviterId: userId
|
|
22304
22652
|
};
|
|
22305
22653
|
const result = await _add(payload);
|
|
22306
22654
|
const emailContent = (0, import_node_server_utils101.compileHandlebar)({
|
|
@@ -22451,7 +22799,8 @@ function useVisitorTransactionController() {
|
|
|
22451
22799
|
}).optional().allow(null, ""),
|
|
22452
22800
|
checkedOut: import_joi55.default.boolean().allow(null, ""),
|
|
22453
22801
|
plateNumber: import_joi55.default.string().optional().allow(null, ""),
|
|
22454
|
-
order: import_joi55.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */)
|
|
22802
|
+
order: import_joi55.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */),
|
|
22803
|
+
tab: import_joi55.default.string().optional().allow(null, "")
|
|
22455
22804
|
});
|
|
22456
22805
|
const { error, value } = validation.validate(req.query, {
|
|
22457
22806
|
abortEarly: false
|
|
@@ -22475,7 +22824,8 @@ function useVisitorTransactionController() {
|
|
|
22475
22824
|
checkedOut,
|
|
22476
22825
|
sort,
|
|
22477
22826
|
order,
|
|
22478
|
-
plateNumber
|
|
22827
|
+
plateNumber,
|
|
22828
|
+
tab
|
|
22479
22829
|
} = value;
|
|
22480
22830
|
const sortObj = {
|
|
22481
22831
|
[sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
|
|
@@ -22492,7 +22842,8 @@ function useVisitorTransactionController() {
|
|
|
22492
22842
|
dateFrom,
|
|
22493
22843
|
type,
|
|
22494
22844
|
checkedOut,
|
|
22495
|
-
plateNumber
|
|
22845
|
+
plateNumber,
|
|
22846
|
+
tab
|
|
22496
22847
|
});
|
|
22497
22848
|
res.status(200).json(data);
|
|
22498
22849
|
return;
|
|
@@ -29705,7 +30056,7 @@ function useSiteBillingItemService() {
|
|
|
29705
30056
|
}
|
|
29706
30057
|
try {
|
|
29707
30058
|
await session.startTransaction();
|
|
29708
|
-
const billing_item = await _getBillingItemById(id
|
|
30059
|
+
const billing_item = await _getBillingItemById(id);
|
|
29709
30060
|
if (!billing_item) {
|
|
29710
30061
|
throw new import_node_server_utils141.BadRequestError("Billing item not found.");
|
|
29711
30062
|
}
|
|
@@ -30712,10 +31063,32 @@ function useEventManagementController() {
|
|
|
30712
31063
|
var import_node_server_utils148 = require("@7365admin1/node-server-utils");
|
|
30713
31064
|
var import_mongodb85 = require("mongodb");
|
|
30714
31065
|
var import_joi83 = __toESM(require("joi"));
|
|
31066
|
+
var Status = /* @__PURE__ */ ((Status3) => {
|
|
31067
|
+
Status3["PENDING"] = "pending";
|
|
31068
|
+
Status3["COMPLETED"] = "completed";
|
|
31069
|
+
Status3["APPROVED"] = "approved";
|
|
31070
|
+
Status3["REJECTED"] = "rejected";
|
|
31071
|
+
Status3["CANCELLED"] = "cancelled";
|
|
31072
|
+
Status3["RECURRING"] = "recurring";
|
|
31073
|
+
Status3["NONRECURRING"] = "non-recurring";
|
|
31074
|
+
Status3["ACTIVE"] = "active";
|
|
31075
|
+
Status3["INACTIVE"] = "inactive";
|
|
31076
|
+
return Status3;
|
|
31077
|
+
})(Status || {});
|
|
31078
|
+
var PStatus = /* @__PURE__ */ ((PStatus2) => {
|
|
31079
|
+
PStatus2["PROCESSING"] = "processing";
|
|
31080
|
+
PStatus2["UNPAID"] = "unpaid";
|
|
31081
|
+
PStatus2["PAID"] = "paid";
|
|
31082
|
+
PStatus2["OVERDUE"] = "overdue";
|
|
31083
|
+
PStatus2["PARTIAL"] = "partial-payment";
|
|
31084
|
+
PStatus2["AWAITING_PAYMENT"] = "awaiting-payment";
|
|
31085
|
+
PStatus2["FAILED"] = "failed";
|
|
31086
|
+
return PStatus2;
|
|
31087
|
+
})(PStatus || {});
|
|
30715
31088
|
var schemaUnitBilling = import_joi83.default.object({
|
|
30716
31089
|
_id: import_joi83.default.string().hex().optional(),
|
|
30717
|
-
site: import_joi83.default.string().hex().
|
|
30718
|
-
org: import_joi83.default.string().hex().
|
|
31090
|
+
site: import_joi83.default.string().hex().optional().allow(null, ""),
|
|
31091
|
+
org: import_joi83.default.string().hex().optional().allow(null, ""),
|
|
30719
31092
|
billItem: import_joi83.default.string().hex().optional().allow(null, ""),
|
|
30720
31093
|
billName: import_joi83.default.string().optional().allow(null, ""),
|
|
30721
31094
|
unitId: import_joi83.default.string().hex().optional().allow(null, ""),
|
|
@@ -30735,6 +31108,7 @@ var schemaUnitBilling = import_joi83.default.object({
|
|
|
30735
31108
|
paymentStatus: import_joi83.default.string().optional().allow(null, ""),
|
|
30736
31109
|
status: import_joi83.default.string().optional().allow(null, ""),
|
|
30737
31110
|
amountPaid: import_joi83.default.number().optional().allow(null, ""),
|
|
31111
|
+
balanceAmount: import_joi83.default.number().optional().allow(null, ""),
|
|
30738
31112
|
paidBy: import_joi83.default.string().hex().optional().allow(null, ""),
|
|
30739
31113
|
datePaid: import_joi83.default.date().optional().allow(null, ""),
|
|
30740
31114
|
transaction_id: import_joi83.default.string().optional().allow(null, ""),
|
|
@@ -30758,6 +31132,7 @@ var schemaUpdateSiteUnitBilling = import_joi83.default.object({
|
|
|
30758
31132
|
category: import_joi83.default.string().optional().allow(null, ""),
|
|
30759
31133
|
frequency: import_joi83.default.string().optional().allow(null, ""),
|
|
30760
31134
|
totalAmount: import_joi83.default.number().optional().allow(null, ""),
|
|
31135
|
+
balanceAmount: import_joi83.default.number().optional().allow(null, ""),
|
|
30761
31136
|
taxPercentage: import_joi83.default.number().optional().allow(null, ""),
|
|
30762
31137
|
taxAmount: import_joi83.default.number().optional().allow(null, ""),
|
|
30763
31138
|
amount: import_joi83.default.number().optional().allow(null, ""),
|
|
@@ -30823,8 +31198,8 @@ function MUnitBilling(value) {
|
|
|
30823
31198
|
}
|
|
30824
31199
|
return {
|
|
30825
31200
|
_id: value._id ?? new import_mongodb85.ObjectId(),
|
|
30826
|
-
site: value.site,
|
|
30827
|
-
org: value.org,
|
|
31201
|
+
site: value.site ?? "",
|
|
31202
|
+
org: value.org ?? "",
|
|
30828
31203
|
billItem: value.billItem ?? "",
|
|
30829
31204
|
billName: value.billName ?? "",
|
|
30830
31205
|
unitId: value.unitId ?? "",
|
|
@@ -30844,6 +31219,7 @@ function MUnitBilling(value) {
|
|
|
30844
31219
|
paymentStatus: value.paymentStatus ?? "",
|
|
30845
31220
|
status: value.status ?? "active",
|
|
30846
31221
|
amountPaid: value.amountPaid ?? 0,
|
|
31222
|
+
balanceAmount: value.balanceAmount ?? 0,
|
|
30847
31223
|
paidBy: value.paidBy ?? "",
|
|
30848
31224
|
datePaid: value.datePaid ?? "",
|
|
30849
31225
|
transaction_id: value.transaction_id ?? "",
|
|
@@ -30887,7 +31263,7 @@ function useSiteUnitBillingRepo() {
|
|
|
30887
31263
|
value = MUnitBilling(value);
|
|
30888
31264
|
const res = await collection.insertOne(value, { session });
|
|
30889
31265
|
const acronym = createAcronym(value.billName || "NA");
|
|
30890
|
-
const dateFormatted =
|
|
31266
|
+
const dateFormatted = formatDateString(/* @__PURE__ */ new Date());
|
|
30891
31267
|
const newId = new import_mongodb86.ObjectId(res.insertedId).toString().slice(-6);
|
|
30892
31268
|
const referenceNumber = `${acronym}${newId}${dateFormatted}`;
|
|
30893
31269
|
await collection.updateOne(
|
|
@@ -31297,6 +31673,95 @@ function useSiteUnitBillingRepo() {
|
|
|
31297
31673
|
throw error;
|
|
31298
31674
|
}
|
|
31299
31675
|
}
|
|
31676
|
+
async function getResidentUserUnsettledBilling({
|
|
31677
|
+
search = "",
|
|
31678
|
+
page = 1,
|
|
31679
|
+
limit = 10,
|
|
31680
|
+
sort = {},
|
|
31681
|
+
status = "active",
|
|
31682
|
+
site = "",
|
|
31683
|
+
paymentStatus = "all",
|
|
31684
|
+
month,
|
|
31685
|
+
year,
|
|
31686
|
+
unitId
|
|
31687
|
+
}, session) {
|
|
31688
|
+
page = page > 0 ? page - 1 : 0;
|
|
31689
|
+
let dateExpr = {};
|
|
31690
|
+
if (month && year) {
|
|
31691
|
+
const monthNum = parseInt(month, 10);
|
|
31692
|
+
const yearNum = parseInt(year, 10);
|
|
31693
|
+
const startDate = new Date(yearNum, monthNum - 1, 1);
|
|
31694
|
+
const endDate = new Date(yearNum, monthNum, 1);
|
|
31695
|
+
dateExpr.createdAt = {
|
|
31696
|
+
$gte: startDate,
|
|
31697
|
+
$lt: endDate
|
|
31698
|
+
};
|
|
31699
|
+
}
|
|
31700
|
+
const unitSearchRegex = search ? search.trim().replace(/\s+/g, "").replace(/\//g, "\\s*/\\s*") : null;
|
|
31701
|
+
const query = {
|
|
31702
|
+
...paymentStatus === "all" ? { paymentStatus: { $in: ["failed", "overdue"] } } : { paymentStatus },
|
|
31703
|
+
status,
|
|
31704
|
+
...search && {
|
|
31705
|
+
$or: [
|
|
31706
|
+
{ unitOwner: { $regex: search, $options: "i" } },
|
|
31707
|
+
{ billName: { $regex: search, $options: "i" } },
|
|
31708
|
+
{ unit: { $regex: unitSearchRegex, $options: "i" } },
|
|
31709
|
+
{
|
|
31710
|
+
$expr: {
|
|
31711
|
+
$regexMatch: {
|
|
31712
|
+
input: { $toString: "$amountPaid" },
|
|
31713
|
+
regex: search,
|
|
31714
|
+
options: "i"
|
|
31715
|
+
}
|
|
31716
|
+
}
|
|
31717
|
+
}
|
|
31718
|
+
]
|
|
31719
|
+
},
|
|
31720
|
+
...import_mongodb86.ObjectId.isValid(site) && { site: new import_mongodb86.ObjectId(site) },
|
|
31721
|
+
...dateExpr,
|
|
31722
|
+
...import_mongodb86.ObjectId.isValid(unitId) && { unitId: new import_mongodb86.ObjectId(unitId) }
|
|
31723
|
+
};
|
|
31724
|
+
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
31725
|
+
try {
|
|
31726
|
+
const basePipeline = [
|
|
31727
|
+
{ $match: query },
|
|
31728
|
+
{ $sort: sort },
|
|
31729
|
+
{ $skip: page * limit },
|
|
31730
|
+
{ $limit: limit },
|
|
31731
|
+
{
|
|
31732
|
+
$lookup: {
|
|
31733
|
+
from: "site.billing.items",
|
|
31734
|
+
localField: "billItem",
|
|
31735
|
+
foreignField: "_id",
|
|
31736
|
+
pipeline: [
|
|
31737
|
+
{
|
|
31738
|
+
$project: {
|
|
31739
|
+
_id: 1,
|
|
31740
|
+
totalAmount: 1
|
|
31741
|
+
}
|
|
31742
|
+
}
|
|
31743
|
+
],
|
|
31744
|
+
as: "billDetails"
|
|
31745
|
+
}
|
|
31746
|
+
},
|
|
31747
|
+
{
|
|
31748
|
+
$unwind: {
|
|
31749
|
+
path: "$billDetails",
|
|
31750
|
+
preserveNullAndEmptyArrays: true
|
|
31751
|
+
}
|
|
31752
|
+
}
|
|
31753
|
+
];
|
|
31754
|
+
const [items, countResult] = await Promise.all([
|
|
31755
|
+
collection.aggregate(basePipeline, { session }).toArray(),
|
|
31756
|
+
collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
|
|
31757
|
+
]);
|
|
31758
|
+
const totalCount = countResult[0]?.total || 0;
|
|
31759
|
+
const data = (0, import_node_server_utils149.paginate)(items, page, limit, totalCount);
|
|
31760
|
+
return data;
|
|
31761
|
+
} catch (error) {
|
|
31762
|
+
throw error;
|
|
31763
|
+
}
|
|
31764
|
+
}
|
|
31300
31765
|
function delCachedData() {
|
|
31301
31766
|
delNamespace().then(() => {
|
|
31302
31767
|
import_node_server_utils149.logger.log({
|
|
@@ -31313,7 +31778,7 @@ function useSiteUnitBillingRepo() {
|
|
|
31313
31778
|
function createAcronym(billName) {
|
|
31314
31779
|
return billName.split(" ").map((word) => word.charAt(0).toUpperCase()).join("");
|
|
31315
31780
|
}
|
|
31316
|
-
function
|
|
31781
|
+
function formatDateString(today) {
|
|
31317
31782
|
today = typeof today === "string" ? new Date(today) : today;
|
|
31318
31783
|
let month = today.getMonth() + 1;
|
|
31319
31784
|
let day = today.getDate();
|
|
@@ -31329,7 +31794,8 @@ function useSiteUnitBillingRepo() {
|
|
|
31329
31794
|
updateById,
|
|
31330
31795
|
deleteById,
|
|
31331
31796
|
getUnitBillingBySite,
|
|
31332
|
-
getResidentUserBilling
|
|
31797
|
+
getResidentUserBilling,
|
|
31798
|
+
getResidentUserUnsettledBilling
|
|
31333
31799
|
};
|
|
31334
31800
|
}
|
|
31335
31801
|
|
|
@@ -31517,7 +31983,8 @@ function useSiteUnitBillingController() {
|
|
|
31517
31983
|
updateById: _updateById,
|
|
31518
31984
|
deleteById: _deleteById,
|
|
31519
31985
|
getById: _getById,
|
|
31520
|
-
getResidentUserBilling: _getResidentUserBilling
|
|
31986
|
+
getResidentUserBilling: _getResidentUserBilling,
|
|
31987
|
+
getResidentUserUnsettledBilling: _getResidentUserUnsettledBilling
|
|
31521
31988
|
} = useSiteUnitBillingRepo();
|
|
31522
31989
|
async function add(req, res, next) {
|
|
31523
31990
|
const data = { ...req.body };
|
|
@@ -31709,13 +32176,65 @@ function useSiteUnitBillingController() {
|
|
|
31709
32176
|
return;
|
|
31710
32177
|
}
|
|
31711
32178
|
}
|
|
32179
|
+
async function getResidentUserUnsettledBilling(req, res, next) {
|
|
32180
|
+
const validation = import_joi84.default.object({
|
|
32181
|
+
page: import_joi84.default.number().integer().min(1).allow("", null).default(1),
|
|
32182
|
+
limit: import_joi84.default.number().integer().min(1).max(100).allow("", null).default(10),
|
|
32183
|
+
status: import_joi84.default.string().optional().allow(null, ""),
|
|
32184
|
+
search: import_joi84.default.string().optional().allow(null, ""),
|
|
32185
|
+
site: import_joi84.default.string().required(),
|
|
32186
|
+
paymentStatus: import_joi84.default.string().optional().allow(null, ""),
|
|
32187
|
+
month: import_joi84.default.string().optional().allow(null, ""),
|
|
32188
|
+
year: import_joi84.default.string().optional().allow(null, ""),
|
|
32189
|
+
unitId: import_joi84.default.string().optional().allow(null, "")
|
|
32190
|
+
});
|
|
32191
|
+
const query = { ...req.query };
|
|
32192
|
+
const { error } = validation.validate(query, {
|
|
32193
|
+
abortEarly: false
|
|
32194
|
+
});
|
|
32195
|
+
if (error) {
|
|
32196
|
+
const messages = error.details.map((d) => d.message).join(", ");
|
|
32197
|
+
import_node_server_utils151.logger.log({ level: "error", message: messages });
|
|
32198
|
+
next(new import_node_server_utils151.BadRequestError(messages));
|
|
32199
|
+
return;
|
|
32200
|
+
}
|
|
32201
|
+
const search = req.query.search ?? "";
|
|
32202
|
+
const page = parseInt(req.query.page ?? "1");
|
|
32203
|
+
const limit = parseInt(req.query.limit ?? "10");
|
|
32204
|
+
const status = req.query.status ?? "active";
|
|
32205
|
+
const site = req.query.site;
|
|
32206
|
+
const paymentStatus = req.query.paymentStatus ?? "awaiting_payment";
|
|
32207
|
+
const month = req.query.month ?? "";
|
|
32208
|
+
const year = req.query.year ?? "";
|
|
32209
|
+
const unitId = req.query.unitId ?? "";
|
|
32210
|
+
try {
|
|
32211
|
+
const data = await _getResidentUserUnsettledBilling({
|
|
32212
|
+
search,
|
|
32213
|
+
page,
|
|
32214
|
+
limit,
|
|
32215
|
+
status,
|
|
32216
|
+
site,
|
|
32217
|
+
paymentStatus,
|
|
32218
|
+
month,
|
|
32219
|
+
year,
|
|
32220
|
+
unitId
|
|
32221
|
+
});
|
|
32222
|
+
res.status(200).json(data);
|
|
32223
|
+
return;
|
|
32224
|
+
} catch (error2) {
|
|
32225
|
+
import_node_server_utils151.logger.log({ level: "error", message: error2.message });
|
|
32226
|
+
next(error2);
|
|
32227
|
+
return;
|
|
32228
|
+
}
|
|
32229
|
+
}
|
|
31712
32230
|
return {
|
|
31713
32231
|
add,
|
|
31714
32232
|
getAll,
|
|
31715
32233
|
getById,
|
|
31716
32234
|
updateById,
|
|
31717
32235
|
deleteById,
|
|
31718
|
-
getResidentUserBilling
|
|
32236
|
+
getResidentUserBilling,
|
|
32237
|
+
getResidentUserUnsettledBilling
|
|
31719
32238
|
};
|
|
31720
32239
|
}
|
|
31721
32240
|
|
|
@@ -31830,8 +32349,8 @@ var import_node_server_utils152 = require("@7365admin1/node-server-utils");
|
|
|
31830
32349
|
var import_mongodb89 = require("mongodb");
|
|
31831
32350
|
|
|
31832
32351
|
// src/utils/access-management.ts
|
|
31833
|
-
var
|
|
31834
|
-
var
|
|
32352
|
+
var import_fs3 = __toESM(require("fs"));
|
|
32353
|
+
var import_path2 = __toESM(require("path"));
|
|
31835
32354
|
var import_axios = __toESM(require("axios"));
|
|
31836
32355
|
var import_xml2js = require("xml2js");
|
|
31837
32356
|
var import_crypto = __toESM(require("crypto"));
|
|
@@ -31860,8 +32379,8 @@ var minifyXml = (xml) => {
|
|
|
31860
32379
|
return xml.replace(/>\s+</g, "><").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").trim();
|
|
31861
32380
|
};
|
|
31862
32381
|
var readTemplate = (name, params) => {
|
|
31863
|
-
const template =
|
|
31864
|
-
|
|
32382
|
+
const template = import_fs3.default.readFileSync(
|
|
32383
|
+
import_path2.default.join(__dirname, `../src/public/xml-templates/${name}.xml`),
|
|
31865
32384
|
"utf-8"
|
|
31866
32385
|
);
|
|
31867
32386
|
if (!params)
|
|
@@ -31970,14 +32489,14 @@ var import_xml2js2 = require("xml2js");
|
|
|
31970
32489
|
|
|
31971
32490
|
// src/utils/rsa-encryption.ts
|
|
31972
32491
|
var crypto2 = __toESM(require("crypto"));
|
|
31973
|
-
var
|
|
31974
|
-
var
|
|
31975
|
-
var pub =
|
|
31976
|
-
var priv =
|
|
32492
|
+
var import_fs4 = __toESM(require("fs"));
|
|
32493
|
+
var import_path3 = __toESM(require("path"));
|
|
32494
|
+
var pub = import_path3.default.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_pub.pem");
|
|
32495
|
+
var priv = import_path3.default.resolve(process.cwd(), "./src/public/rsa-keys/new_rsa_512_priv.pem");
|
|
31977
32496
|
var EncryptionCredentials = class {
|
|
31978
32497
|
};
|
|
31979
|
-
EncryptionCredentials.RAW_PUBLIC_KEY =
|
|
31980
|
-
EncryptionCredentials.RAW_PRIVATE_KEY =
|
|
32498
|
+
EncryptionCredentials.RAW_PUBLIC_KEY = import_fs4.default.readFileSync(pub, "utf8");
|
|
32499
|
+
EncryptionCredentials.RAW_PRIVATE_KEY = import_fs4.default.readFileSync(priv, "utf8");
|
|
31981
32500
|
var EntrypassRSAEncryption = class extends EncryptionCredentials {
|
|
31982
32501
|
static hexToCardNumber(hex) {
|
|
31983
32502
|
if (!/^[0-9A-Fa-f]{8}$/.test(hex)) {
|
|
@@ -33895,6 +34414,61 @@ function UseAccessManagementRepo() {
|
|
|
33895
34414
|
await session?.endSession();
|
|
33896
34415
|
}
|
|
33897
34416
|
}
|
|
34417
|
+
async function getBlockLevelAndUnitListRepo(params) {
|
|
34418
|
+
const site = new import_mongodb89.ObjectId(params.site);
|
|
34419
|
+
try {
|
|
34420
|
+
const blocks = await collectionName("buildings").aggregate([
|
|
34421
|
+
{
|
|
34422
|
+
$match: {
|
|
34423
|
+
site,
|
|
34424
|
+
status: { $eq: "active" }
|
|
34425
|
+
}
|
|
34426
|
+
},
|
|
34427
|
+
{
|
|
34428
|
+
$project: {
|
|
34429
|
+
_id: 1,
|
|
34430
|
+
name: 1,
|
|
34431
|
+
block: 1
|
|
34432
|
+
}
|
|
34433
|
+
},
|
|
34434
|
+
{
|
|
34435
|
+
$lookup: {
|
|
34436
|
+
from: "building-levels",
|
|
34437
|
+
localField: "_id",
|
|
34438
|
+
foreignField: "block",
|
|
34439
|
+
as: "levels",
|
|
34440
|
+
pipeline: [
|
|
34441
|
+
{
|
|
34442
|
+
$match: { status: { $ne: "deleted" } }
|
|
34443
|
+
},
|
|
34444
|
+
{
|
|
34445
|
+
$lookup: {
|
|
34446
|
+
from: "building-units",
|
|
34447
|
+
localField: "_id",
|
|
34448
|
+
foreignField: "level",
|
|
34449
|
+
pipeline: [
|
|
34450
|
+
{ $match: { status: { $ne: "deleted" } } },
|
|
34451
|
+
{ $project: { _id: 1, name: 1, buildingName: 1, level: 1, block: 1 } }
|
|
34452
|
+
],
|
|
34453
|
+
as: "units"
|
|
34454
|
+
}
|
|
34455
|
+
},
|
|
34456
|
+
{
|
|
34457
|
+
$match: { "units.0": { $exists: true } }
|
|
34458
|
+
}
|
|
34459
|
+
]
|
|
34460
|
+
}
|
|
34461
|
+
},
|
|
34462
|
+
// ✅ Filter out buildings with no levels early
|
|
34463
|
+
{
|
|
34464
|
+
$match: { "levels.0": { $exists: true } }
|
|
34465
|
+
}
|
|
34466
|
+
]).toArray();
|
|
34467
|
+
return blocks;
|
|
34468
|
+
} catch (error) {
|
|
34469
|
+
throw new Error(error.message);
|
|
34470
|
+
}
|
|
34471
|
+
}
|
|
33898
34472
|
return {
|
|
33899
34473
|
createIndexes,
|
|
33900
34474
|
createIndexForEntrypass,
|
|
@@ -33924,7 +34498,8 @@ function UseAccessManagementRepo() {
|
|
|
33924
34498
|
vmsgenerateQrCodesRepo,
|
|
33925
34499
|
addVisitorAccessCardRepo,
|
|
33926
34500
|
signQrCodeRepo,
|
|
33927
|
-
checkoutVisitorRepo
|
|
34501
|
+
checkoutVisitorRepo,
|
|
34502
|
+
getBlockLevelAndUnitListRepo
|
|
33928
34503
|
};
|
|
33929
34504
|
}
|
|
33930
34505
|
|
|
@@ -33933,7 +34508,7 @@ var import_joi85 = __toESM(require("joi"));
|
|
|
33933
34508
|
|
|
33934
34509
|
// src/services/access-management.service.ts
|
|
33935
34510
|
var import_xml2js3 = require("xml2js");
|
|
33936
|
-
var
|
|
34511
|
+
var import_stream2 = require("stream");
|
|
33937
34512
|
var xlsx = __toESM(require("xlsx"));
|
|
33938
34513
|
function useAccessManagementSvc() {
|
|
33939
34514
|
const {
|
|
@@ -33963,7 +34538,8 @@ function useAccessManagementSvc() {
|
|
|
33963
34538
|
vmsgenerateQrCodesRepo,
|
|
33964
34539
|
addVisitorAccessCardRepo,
|
|
33965
34540
|
signQrCodeRepo,
|
|
33966
|
-
checkoutVisitorRepo
|
|
34541
|
+
checkoutVisitorRepo,
|
|
34542
|
+
getBlockLevelAndUnitListRepo
|
|
33967
34543
|
} = UseAccessManagementRepo();
|
|
33968
34544
|
const addPhysicalCardSvc = async (payload) => {
|
|
33969
34545
|
try {
|
|
@@ -34138,7 +34714,7 @@ function useAccessManagementSvc() {
|
|
|
34138
34714
|
};
|
|
34139
34715
|
const convertBufferFile = async (bufferFile) => {
|
|
34140
34716
|
return new Promise((resolve, reject) => {
|
|
34141
|
-
const fileStream =
|
|
34717
|
+
const fileStream = import_stream2.Readable.from(bufferFile);
|
|
34142
34718
|
let fileBuffer = Buffer.alloc(0);
|
|
34143
34719
|
fileStream.on("data", (chunk) => {
|
|
34144
34720
|
fileBuffer = Buffer.concat([fileBuffer, chunk]);
|
|
@@ -34247,6 +34823,14 @@ function useAccessManagementSvc() {
|
|
|
34247
34823
|
throw new Error(err.message);
|
|
34248
34824
|
}
|
|
34249
34825
|
};
|
|
34826
|
+
const getBlockLevelAndUnitListSvc = async (params) => {
|
|
34827
|
+
try {
|
|
34828
|
+
const response = await getBlockLevelAndUnitListRepo({ ...params });
|
|
34829
|
+
return response;
|
|
34830
|
+
} catch (err) {
|
|
34831
|
+
throw new Error(err.message);
|
|
34832
|
+
}
|
|
34833
|
+
};
|
|
34250
34834
|
return {
|
|
34251
34835
|
addPhysicalCardSvc,
|
|
34252
34836
|
addNonPhysicalCardSvc,
|
|
@@ -34280,7 +34864,8 @@ function useAccessManagementSvc() {
|
|
|
34280
34864
|
vmsgenerateQrCodesSvc,
|
|
34281
34865
|
addVisitorAccessCardSvc,
|
|
34282
34866
|
signQrCodeSvc,
|
|
34283
|
-
checkoutVisitorSvc
|
|
34867
|
+
checkoutVisitorSvc,
|
|
34868
|
+
getBlockLevelAndUnitListSvc
|
|
34284
34869
|
};
|
|
34285
34870
|
}
|
|
34286
34871
|
|
|
@@ -34319,7 +34904,8 @@ function useAccessManagementController() {
|
|
|
34319
34904
|
vmsgenerateQrCodesSvc,
|
|
34320
34905
|
addVisitorAccessCardSvc,
|
|
34321
34906
|
signQrCodeSvc,
|
|
34322
|
-
checkoutVisitorSvc
|
|
34907
|
+
checkoutVisitorSvc,
|
|
34908
|
+
getBlockLevelAndUnitListSvc
|
|
34323
34909
|
} = useAccessManagementSvc();
|
|
34324
34910
|
const addPhysicalCard = async (req, res) => {
|
|
34325
34911
|
try {
|
|
@@ -35066,6 +35652,21 @@ function useAccessManagementController() {
|
|
|
35066
35652
|
const removeAccessCard = async ({ cardNo, staffNo, url }) => {
|
|
35067
35653
|
return removeAccessGroup({ cardNo, staffNo, url });
|
|
35068
35654
|
};
|
|
35655
|
+
const getBlockLevelAndUnitList = async (req, res) => {
|
|
35656
|
+
try {
|
|
35657
|
+
const { site } = req.query;
|
|
35658
|
+
if (!site || typeof site !== "string") {
|
|
35659
|
+
throw new Error("Site is required");
|
|
35660
|
+
}
|
|
35661
|
+
const result = await getBlockLevelAndUnitListSvc({ site });
|
|
35662
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
35663
|
+
} catch (error) {
|
|
35664
|
+
return res.status(400).json({
|
|
35665
|
+
data: null,
|
|
35666
|
+
message: error.message
|
|
35667
|
+
});
|
|
35668
|
+
}
|
|
35669
|
+
};
|
|
35069
35670
|
return {
|
|
35070
35671
|
addPhysicalCard,
|
|
35071
35672
|
addNonPhysicalCard,
|
|
@@ -35097,7 +35698,8 @@ function useAccessManagementController() {
|
|
|
35097
35698
|
addVisitorAccessCard,
|
|
35098
35699
|
signQrCode,
|
|
35099
35700
|
checkoutVisitor,
|
|
35100
|
-
removeAccessCard
|
|
35701
|
+
removeAccessCard,
|
|
35702
|
+
getBlockLevelAndUnitList
|
|
35101
35703
|
};
|
|
35102
35704
|
}
|
|
35103
35705
|
|
|
@@ -46379,118 +46981,8 @@ function genericSignature(params, secretKey) {
|
|
|
46379
46981
|
}
|
|
46380
46982
|
|
|
46381
46983
|
// src/repositories/reddot-payment.repository.ts
|
|
46382
|
-
var import_mongodb127 = require("mongodb");
|
|
46383
|
-
|
|
46384
|
-
// src/utils/date-format.util.ts
|
|
46385
|
-
var import_moment_timezone6 = __toESM(require("moment-timezone"));
|
|
46386
|
-
function formatDateString(today, format, dateRange) {
|
|
46387
|
-
today = typeof today === "string" ? new Date(today) : today;
|
|
46388
|
-
let month = today.getMonth() + 1;
|
|
46389
|
-
let day = today.getDate();
|
|
46390
|
-
let year = today.getFullYear();
|
|
46391
|
-
let formattedDate;
|
|
46392
|
-
if (format === "mm-dd-yyyy") {
|
|
46393
|
-
formattedDate = `${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}-${year}`;
|
|
46394
|
-
} else if (format === "dd-mm-yyyy") {
|
|
46395
|
-
formattedDate = `${day.toString().padStart(2, "0")}-${month.toString().padStart(2, "0")}-${year}`;
|
|
46396
|
-
} else if (format === "for-ref") {
|
|
46397
|
-
formattedDate = `${month.toString().padStart(2, "0")}${day.toString().padStart(2, "0")}${year}`;
|
|
46398
|
-
} else if (format === "mm/dd/yyyy") {
|
|
46399
|
-
formattedDate = `${month.toString().padStart(2, "0")}/${day.toString().padStart(2, "0")}/${year}`;
|
|
46400
|
-
} else {
|
|
46401
|
-
formattedDate = `${year}-${month.toString().padStart(2, "0")}-${day.toString().padStart(2, "0")}`;
|
|
46402
|
-
}
|
|
46403
|
-
return formattedDate;
|
|
46404
|
-
}
|
|
46405
|
-
|
|
46406
|
-
// src/models/credit-card.model.ts
|
|
46407
|
-
var import_mongodb124 = require("mongodb");
|
|
46408
|
-
var MCardInfo = class {
|
|
46409
|
-
// this is coming from RDP transaction
|
|
46410
|
-
constructor({
|
|
46411
|
-
_id = new import_mongodb124.ObjectId(),
|
|
46412
|
-
userId,
|
|
46413
|
-
cardType,
|
|
46414
|
-
cardNumber,
|
|
46415
|
-
cardId,
|
|
46416
|
-
fullName,
|
|
46417
|
-
expiryDate,
|
|
46418
|
-
cvv,
|
|
46419
|
-
site,
|
|
46420
|
-
siteName,
|
|
46421
|
-
organization,
|
|
46422
|
-
createdBy,
|
|
46423
|
-
createdAt,
|
|
46424
|
-
updatedAt,
|
|
46425
|
-
transaction_id
|
|
46426
|
-
} = {}) {
|
|
46427
|
-
this._id = _id;
|
|
46428
|
-
this.userId = userId;
|
|
46429
|
-
this.cardType = cardType;
|
|
46430
|
-
this.cardNumber = cardNumber;
|
|
46431
|
-
this.cardId = cardId;
|
|
46432
|
-
this.fullName = fullName;
|
|
46433
|
-
this.expiryDate = expiryDate;
|
|
46434
|
-
this.cvv = cvv;
|
|
46435
|
-
this.site = site;
|
|
46436
|
-
this.siteName = siteName;
|
|
46437
|
-
this.organization = organization;
|
|
46438
|
-
this.createdBy = createdBy;
|
|
46439
|
-
this.createdAt = createdAt;
|
|
46440
|
-
this.updatedAt = updatedAt;
|
|
46441
|
-
this.transaction_id = transaction_id;
|
|
46442
|
-
}
|
|
46443
|
-
};
|
|
46444
|
-
|
|
46445
|
-
// src/models/cart.model.ts
|
|
46446
|
-
var import_mongodb125 = require("mongodb");
|
|
46447
|
-
var MUnitBillings = class {
|
|
46448
|
-
// transaction response messages
|
|
46449
|
-
constructor({
|
|
46450
|
-
_id = new import_mongodb125.ObjectId(),
|
|
46451
|
-
unit,
|
|
46452
|
-
unitId,
|
|
46453
|
-
unitBill,
|
|
46454
|
-
paymentStatus = "Processing" /* processing */,
|
|
46455
|
-
referenceNumber,
|
|
46456
|
-
amountPaid,
|
|
46457
|
-
paidBy,
|
|
46458
|
-
datePaid,
|
|
46459
|
-
billCategory,
|
|
46460
|
-
billFrom,
|
|
46461
|
-
billTo,
|
|
46462
|
-
site,
|
|
46463
|
-
organization,
|
|
46464
|
-
createdBy,
|
|
46465
|
-
createdAt,
|
|
46466
|
-
updatedAt,
|
|
46467
|
-
message
|
|
46468
|
-
} = {}) {
|
|
46469
|
-
this._id = _id;
|
|
46470
|
-
this.unit = unit;
|
|
46471
|
-
this.unitId = unitId;
|
|
46472
|
-
this.referenceNumber = referenceNumber;
|
|
46473
|
-
this.unitBill = unitBill;
|
|
46474
|
-
this.paymentStatus = paymentStatus;
|
|
46475
|
-
this.amountPaid = amountPaid;
|
|
46476
|
-
this.site = site;
|
|
46477
|
-
this.organization = organization;
|
|
46478
|
-
this.paidBy = paidBy;
|
|
46479
|
-
this.datePaid = datePaid;
|
|
46480
|
-
this.billCategory = billCategory;
|
|
46481
|
-
this.billFrom = billFrom;
|
|
46482
|
-
this.billTo = billTo;
|
|
46483
|
-
this.createdBy = createdBy;
|
|
46484
|
-
this.createdAt = createdAt;
|
|
46485
|
-
this.updatedAt = updatedAt;
|
|
46486
|
-
this.message = message;
|
|
46487
|
-
}
|
|
46488
|
-
};
|
|
46489
|
-
|
|
46490
|
-
// src/repositories/payment.repository.ts
|
|
46491
|
-
var import_mongodb126 = require("mongodb");
|
|
46492
46984
|
var import_node_server_utils216 = require("@7365admin1/node-server-utils");
|
|
46493
|
-
var
|
|
46985
|
+
var useRedDotPaymentRepo = () => {
|
|
46494
46986
|
const getDB2 = () => {
|
|
46495
46987
|
const db = import_node_server_utils216.useAtlas.getDb();
|
|
46496
46988
|
if (!db) {
|
|
@@ -46498,347 +46990,75 @@ var PaymentBillRepo = () => {
|
|
|
46498
46990
|
}
|
|
46499
46991
|
return db;
|
|
46500
46992
|
};
|
|
46501
|
-
const
|
|
46502
|
-
return getDB2().collection("
|
|
46993
|
+
const paymentCollection = () => {
|
|
46994
|
+
return getDB2().collection("payments");
|
|
46503
46995
|
};
|
|
46504
|
-
const
|
|
46505
|
-
return getDB2().collection("
|
|
46996
|
+
const unitBillingCollection = () => {
|
|
46997
|
+
return getDB2().collection("site.unit.billing");
|
|
46506
46998
|
};
|
|
46507
|
-
const
|
|
46508
|
-
return getDB2().collection("
|
|
46999
|
+
const orgCollection = () => {
|
|
47000
|
+
return getDB2().collection("organizations");
|
|
46509
47001
|
};
|
|
46510
|
-
const
|
|
46511
|
-
return getDB2().collection("
|
|
47002
|
+
const redDotMerchantCollection = () => {
|
|
47003
|
+
return getDB2().collection("payment-gateways");
|
|
46512
47004
|
};
|
|
46513
|
-
|
|
47005
|
+
async function paySingleUnitBill(refId, payload) {
|
|
46514
47006
|
try {
|
|
46515
47007
|
if (refId)
|
|
46516
47008
|
refId = refId.toString();
|
|
46517
|
-
const unitBillInfo = await
|
|
46518
|
-
|
|
47009
|
+
const unitBillInfo = await unitBillingCollection().findOne({
|
|
47010
|
+
referenceNumber: refId
|
|
47011
|
+
});
|
|
46519
47012
|
if (!unitBillInfo) {
|
|
46520
47013
|
throw new Error("Unit bill info not found");
|
|
46521
47014
|
}
|
|
46522
|
-
if (unitBillInfo?.status === "
|
|
47015
|
+
if (unitBillInfo?.status === "inactive" /* INACTIVE */) {
|
|
46523
47016
|
throw new Error("This Bill is Inactive!");
|
|
46524
47017
|
}
|
|
46525
|
-
|
|
46526
|
-
|
|
46527
|
-
|
|
46528
|
-
|
|
46529
|
-
|
|
46530
|
-
|
|
46531
|
-
|
|
46532
|
-
const amount = payload.amountPaid;
|
|
46533
|
-
const numericPrice = typeof price === "string" ? parseInt(price) : price;
|
|
46534
|
-
const numericAmount = typeof amount === "string" ? parseInt(amount) : amount;
|
|
46535
|
-
if (typeof amount !== "number") {
|
|
46536
|
-
throw new Error("Amount is not a valid number");
|
|
46537
|
-
} else if (typeof price !== "number") {
|
|
46538
|
-
throw new Error("Price s not a valid number");
|
|
47018
|
+
if (payload.paymentStatus === "partial-payment" /* PARTIAL */ && payload.amountPaid) {
|
|
47019
|
+
const totalAmount = parseInt(unitBillInfo.totalAmount);
|
|
47020
|
+
const amountPaid = payload.amountPaid;
|
|
47021
|
+
if (typeof totalAmount !== "number") {
|
|
47022
|
+
throw new Error("Total Amount is not a valid number");
|
|
47023
|
+
} else if (typeof amountPaid !== "number") {
|
|
47024
|
+
throw new Error("Amount Paid is not a valid number");
|
|
46539
47025
|
}
|
|
46540
|
-
payload.
|
|
46541
|
-
} else if (payload.paymentStatus === "
|
|
47026
|
+
payload.balanceAmount = totalAmount - amountPaid;
|
|
47027
|
+
} else if (payload.paymentStatus === "paid" /* PAID */ && payload.amountPaid) {
|
|
46542
47028
|
payload.datePaid = /* @__PURE__ */ new Date();
|
|
46543
|
-
payload.paymentStatus = "
|
|
47029
|
+
payload.paymentStatus = "paid" /* PAID */;
|
|
46544
47030
|
payload.amountPaid;
|
|
46545
47031
|
payload.transaction_id;
|
|
46546
|
-
} else if (payload.paymentStatus === "
|
|
47032
|
+
} else if (payload.paymentStatus === "failed" /* FAILED */) {
|
|
46547
47033
|
payload.amountPaid = 0;
|
|
46548
|
-
payload.
|
|
46549
|
-
payload.datePaid = "";
|
|
46550
|
-
payload.paymentStatus = "Failed" /* failed */;
|
|
47034
|
+
payload.paymentStatus = "failed" /* FAILED */;
|
|
46551
47035
|
payload.transaction_id;
|
|
46552
47036
|
}
|
|
46553
|
-
|
|
46554
|
-
|
|
46555
|
-
|
|
46556
|
-
|
|
46557
|
-
|
|
46558
|
-
|
|
46559
|
-
}
|
|
46560
|
-
};
|
|
46561
|
-
const saveCreditCardInfo = async (payload) => {
|
|
46562
|
-
try {
|
|
46563
|
-
if (payload.userId)
|
|
46564
|
-
payload.userId = new import_mongodb126.ObjectId(payload.userId);
|
|
46565
|
-
if (payload.site)
|
|
46566
|
-
payload.site = new import_mongodb126.ObjectId(payload.site);
|
|
46567
|
-
if (payload.organization)
|
|
46568
|
-
payload.organization = new import_mongodb126.ObjectId(payload.organization);
|
|
46569
|
-
if (payload.createdBy)
|
|
46570
|
-
payload.createdBy = new import_mongodb126.ObjectId(payload.createdBy);
|
|
46571
|
-
const createdAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
46572
|
-
payload.createdAt = createdAt;
|
|
46573
|
-
const result = await creditCollection().insertOne(new MCardInfo(payload));
|
|
46574
|
-
return result;
|
|
46575
|
-
} catch (error) {
|
|
46576
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46577
|
-
}
|
|
46578
|
-
};
|
|
46579
|
-
const checkOutUnitBills = async (payload) => {
|
|
46580
|
-
try {
|
|
46581
|
-
if (payload.unitId)
|
|
46582
|
-
payload.unitId = new import_mongodb126.ObjectId(payload.unitId);
|
|
46583
|
-
if (payload.site)
|
|
46584
|
-
payload.site = new import_mongodb126.ObjectId(payload.site);
|
|
46585
|
-
if (payload.organization)
|
|
46586
|
-
payload.organization = new import_mongodb126.ObjectId(payload.organization);
|
|
46587
|
-
payload.createdAt = await formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
46588
|
-
const addToCart = await cartCollection().insertOne(new MUnitBillings(payload));
|
|
46589
|
-
const unitId = payload.unitId;
|
|
46590
|
-
const dateFormatted = formatDateString(/* @__PURE__ */ new Date(), "for-ref");
|
|
46591
|
-
const unit = unitId?.toString().slice(-4);
|
|
46592
|
-
const newId = new import_mongodb126.ObjectId(addToCart?.insertedId).toString().slice(-4);
|
|
46593
|
-
const referenceNumber = `CRT${unit}${newId}${dateFormatted}`;
|
|
46594
|
-
const result = await cartCollection().findOneAndUpdate({ _id: new import_mongodb126.ObjectId(addToCart.insertedId) }, { $set: { referenceNumber } }, { returnDocument: "after" });
|
|
46595
|
-
return result;
|
|
46596
|
-
} catch (error) {
|
|
46597
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46598
|
-
}
|
|
46599
|
-
};
|
|
46600
|
-
const payUnitCart = async (refId, payload) => {
|
|
46601
|
-
try {
|
|
46602
|
-
if (refId)
|
|
46603
|
-
refId = refId.toString();
|
|
46604
|
-
const updatedAt = formatDateString(/* @__PURE__ */ new Date(), "mm-dd-yyyy");
|
|
46605
|
-
const cartInfo = await cartCollection().findOne({ referenceNumber: refId });
|
|
46606
|
-
const refNumber = cartInfo?.unitBill;
|
|
46607
|
-
if (payload.paymentStatus === "Paid" /* paid */ && payload.amountPaid) {
|
|
46608
|
-
payload.datePaid = /* @__PURE__ */ new Date();
|
|
46609
|
-
payload.paymentStatus = "Paid" /* paid */;
|
|
46610
|
-
payload.amountPaid;
|
|
46611
|
-
} else if (payload.paymentStatus === "Failed" /* failed */) {
|
|
46612
|
-
payload.amountPaid = 0;
|
|
46613
|
-
payload.paidBy = "";
|
|
46614
|
-
payload.datePaid = "";
|
|
46615
|
-
payload.paymentStatus = "Failed" /* failed */;
|
|
46616
|
-
}
|
|
46617
|
-
payload.updatedAt = updatedAt;
|
|
46618
|
-
const result = await cartCollection().findOneAndUpdate({ referenceNumber: refId }, { $set: payload }, { returnDocument: "after" });
|
|
46619
|
-
if (!result) {
|
|
46620
|
-
throw new Error("Failed to Process Transaction. Please Try Again Later");
|
|
46621
|
-
} else {
|
|
46622
|
-
for (const ref of refNumber) {
|
|
46623
|
-
const unitBillInfo = await collection().findOne({ referenceNumber: ref });
|
|
46624
|
-
const billId = unitBillInfo?.billId;
|
|
46625
|
-
const billInfo = await billCollection().findOne({ _id: new import_mongodb126.ObjectId(billId) });
|
|
46626
|
-
const billAmount = billInfo?.price;
|
|
46627
|
-
payload.updatedAt = updatedAt;
|
|
46628
|
-
payload.amountPaid = billAmount;
|
|
46629
|
-
const eachRef = await payUnitBill(ref, payload);
|
|
46630
|
-
}
|
|
46631
|
-
if (!cartInfo) {
|
|
46632
|
-
throw new Error("Cart info not found");
|
|
46633
|
-
}
|
|
46634
|
-
}
|
|
47037
|
+
payload.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
|
|
47038
|
+
const result = await unitBillingCollection().findOneAndUpdate(
|
|
47039
|
+
{ _id: unitBillInfo._id },
|
|
47040
|
+
{ $set: payload },
|
|
47041
|
+
{ returnDocument: "after" }
|
|
47042
|
+
);
|
|
46635
47043
|
return result;
|
|
46636
47044
|
} catch (error) {
|
|
46637
47045
|
throw new Error(error.message || error || "Server Internal Error");
|
|
46638
47046
|
}
|
|
46639
|
-
}
|
|
46640
|
-
|
|
46641
|
-
try {
|
|
46642
|
-
if (refId)
|
|
46643
|
-
refId = refId.toString();
|
|
46644
|
-
const result = await cartCollection().aggregate([
|
|
46645
|
-
{ $match: { referenceNumber: refId } },
|
|
46646
|
-
{
|
|
46647
|
-
$lookup: {
|
|
46648
|
-
from: "unit-bill",
|
|
46649
|
-
localField: "unitBill",
|
|
46650
|
-
foreignField: "referenceNumber",
|
|
46651
|
-
as: "unitBill"
|
|
46652
|
-
}
|
|
46653
|
-
},
|
|
46654
|
-
{
|
|
46655
|
-
$unwind: "$unitBill"
|
|
46656
|
-
},
|
|
46657
|
-
{
|
|
46658
|
-
$lookup: {
|
|
46659
|
-
from: "bill-records",
|
|
46660
|
-
localField: "unitBill.billId",
|
|
46661
|
-
foreignField: "_id",
|
|
46662
|
-
as: "billDetails"
|
|
46663
|
-
}
|
|
46664
|
-
},
|
|
46665
|
-
{
|
|
46666
|
-
$unwind: {
|
|
46667
|
-
path: "$billDetails",
|
|
46668
|
-
preserveNullAndEmptyArrays: true
|
|
46669
|
-
}
|
|
46670
|
-
},
|
|
46671
|
-
{
|
|
46672
|
-
$addFields: {
|
|
46673
|
-
"unitBill.billItemName": "$billDetails.billItem"
|
|
46674
|
-
}
|
|
46675
|
-
},
|
|
46676
|
-
{
|
|
46677
|
-
$project: {
|
|
46678
|
-
"unitBill.paidBy": 0,
|
|
46679
|
-
"unitBill.preDueDateAlert": 0,
|
|
46680
|
-
"unitBill.category": 0,
|
|
46681
|
-
"unitBill.contactNumber": 0,
|
|
46682
|
-
"unitBill.email": 0,
|
|
46683
|
-
"unitBill.site": 0,
|
|
46684
|
-
"unitBill.siteName": 0,
|
|
46685
|
-
"unitBill.organization": 0,
|
|
46686
|
-
"unitBill.billStatus": 0,
|
|
46687
|
-
"unitBill.createdBy": 0,
|
|
46688
|
-
"unitBill.createdAt": 0,
|
|
46689
|
-
"unitBill.updatedAt": 0,
|
|
46690
|
-
"billDetails": 0
|
|
46691
|
-
// Exclude the full billDetails as it's no longer needed
|
|
46692
|
-
}
|
|
46693
|
-
},
|
|
46694
|
-
{
|
|
46695
|
-
$group: {
|
|
46696
|
-
_id: "$_id",
|
|
46697
|
-
unitId: { $first: "$unitId" },
|
|
46698
|
-
referenceNumber: { $first: "$referenceNumber" },
|
|
46699
|
-
unitBill: { $push: "$unitBill" },
|
|
46700
|
-
paymentStatus: { $first: "$paymentStatus" },
|
|
46701
|
-
amountPaid: { $first: "$amountPaid" },
|
|
46702
|
-
site: { $first: "$site" },
|
|
46703
|
-
organization: { $first: "$organization" },
|
|
46704
|
-
paidBy: { $first: "$paidBy" },
|
|
46705
|
-
datePaid: { $first: "$referenceNumber" },
|
|
46706
|
-
billCategory: { $first: "$billCategory" },
|
|
46707
|
-
billFrom: { $first: "$billFrom" },
|
|
46708
|
-
billTo: { $first: "$billTo" },
|
|
46709
|
-
createdBy: { $first: "$createdBy" },
|
|
46710
|
-
createdAt: { $first: "$createdAt" },
|
|
46711
|
-
updatedAt: { $first: "$updatedAt" },
|
|
46712
|
-
transaction_id: { $first: "$transaction_id" }
|
|
46713
|
-
}
|
|
46714
|
-
}
|
|
46715
|
-
]).toArray();
|
|
46716
|
-
if (!result || result.length === 0) {
|
|
46717
|
-
return { success: false, message: "Cart Info Not Found" };
|
|
46718
|
-
}
|
|
46719
|
-
return result[0];
|
|
46720
|
-
} catch (error) {
|
|
46721
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46722
|
-
}
|
|
46723
|
-
};
|
|
46724
|
-
const cancelCheckedOutBillings = async (refId) => {
|
|
46725
|
-
try {
|
|
46726
|
-
if (refId)
|
|
46727
|
-
refId = refId.toString();
|
|
46728
|
-
const result = await cartCollection().findOneAndDelete({ referenceNumber: refId });
|
|
46729
|
-
if (!result) {
|
|
46730
|
-
return { success: false, message: "Cart Info Not Found" };
|
|
46731
|
-
}
|
|
46732
|
-
return { success: true, message: "Cart Deleted Successfully!", referenceNumber: result?.referenceNumber };
|
|
46733
|
-
} catch (error) {
|
|
46734
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46735
|
-
}
|
|
46736
|
-
};
|
|
46737
|
-
return {
|
|
46738
|
-
saveCreditCardInfo,
|
|
46739
|
-
checkOutUnitBills,
|
|
46740
|
-
payUnitBill,
|
|
46741
|
-
payUnitCart,
|
|
46742
|
-
getCheckedOutBillings,
|
|
46743
|
-
cancelCheckedOutBillings
|
|
46744
|
-
};
|
|
46745
|
-
};
|
|
46746
|
-
|
|
46747
|
-
// src/repositories/reddot-payment.repository.ts
|
|
46748
|
-
var import_node_server_utils217 = require("@7365admin1/node-server-utils");
|
|
46749
|
-
var useRedDotPaymentRepo = () => {
|
|
46750
|
-
const getDB2 = () => {
|
|
46751
|
-
const db = import_node_server_utils217.useAtlas.getDb();
|
|
46752
|
-
if (!db) {
|
|
46753
|
-
throw new import_node_server_utils217.InternalServerError("Unable to connect to server.");
|
|
46754
|
-
}
|
|
46755
|
-
return db;
|
|
46756
|
-
};
|
|
46757
|
-
const collection = () => {
|
|
46758
|
-
return getDB2().collection("unit-bill");
|
|
46759
|
-
};
|
|
46760
|
-
const orgCollection = () => {
|
|
46761
|
-
return getDB2().collection("organizations");
|
|
46762
|
-
};
|
|
46763
|
-
const cartCollection = () => {
|
|
46764
|
-
return getDB2().collection("checkout-cart");
|
|
46765
|
-
};
|
|
46766
|
-
const redDotMerchantCollection = () => {
|
|
46767
|
-
return getDB2().collection("reddot-merchant");
|
|
46768
|
-
};
|
|
46769
|
-
const createRedDotAccount = async (_id, payload) => {
|
|
46770
|
-
try {
|
|
46771
|
-
const merchant = await redDotMerchantCollection().insertOne(payload);
|
|
46772
|
-
if (!merchant) {
|
|
46773
|
-
throw new Error("Failed to Add Merchant Details");
|
|
46774
|
-
}
|
|
46775
|
-
const merchantId = merchant?.insertedId;
|
|
46776
|
-
const orgId = new import_mongodb127.ObjectId(_id);
|
|
46777
|
-
const result = await orgCollection().findOneAndUpdate({ _id: orgId }, { $push: { merchant: merchantId } }, {
|
|
46778
|
-
returnDocument: "after"
|
|
46779
|
-
});
|
|
46780
|
-
if (!result) {
|
|
46781
|
-
throw new Error("Organization not found");
|
|
46782
|
-
}
|
|
46783
|
-
return {
|
|
46784
|
-
success: true,
|
|
46785
|
-
message: "Merchant Details successfully added."
|
|
46786
|
-
};
|
|
46787
|
-
} catch (error) {
|
|
46788
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46789
|
-
}
|
|
46790
|
-
};
|
|
46791
|
-
const payUnitBillings = async (refId, payload) => {
|
|
46792
|
-
const checkCart = await cartCollection().findOne({ referenceNumber: refId });
|
|
46793
|
-
if (checkCart) {
|
|
46794
|
-
const multiple = await PaymentBillRepo().payUnitCart(refId, payload);
|
|
46795
|
-
if (multiple) {
|
|
46796
|
-
return await PaymentBillRepo().getCheckedOutBillings(refId);
|
|
46797
|
-
}
|
|
46798
|
-
}
|
|
46799
|
-
const single = await PaymentBillRepo().payUnitBill(refId, payload);
|
|
46800
|
-
return single;
|
|
46801
|
-
};
|
|
46802
|
-
const getMerchantDetailsById = async (_id) => {
|
|
46803
|
-
try {
|
|
46804
|
-
if (_id)
|
|
46805
|
-
_id = new import_mongodb127.ObjectId(_id);
|
|
46806
|
-
const result = await redDotMerchantCollection().aggregate([
|
|
46807
|
-
{
|
|
46808
|
-
$match: {
|
|
46809
|
-
_id
|
|
46810
|
-
}
|
|
46811
|
-
},
|
|
46812
|
-
{
|
|
46813
|
-
$facet: {
|
|
46814
|
-
totalCount: [{ $count: "count" }],
|
|
46815
|
-
items: [{ $sort: { _id: -1 } }]
|
|
46816
|
-
}
|
|
46817
|
-
}
|
|
46818
|
-
]).toArray();
|
|
46819
|
-
const items = result[0].items;
|
|
46820
|
-
return items;
|
|
46821
|
-
} catch (error) {
|
|
46822
|
-
throw new Error(error.message || error || "Server Internal Error");
|
|
46823
|
-
}
|
|
46824
|
-
};
|
|
46825
|
-
return {
|
|
46826
|
-
createRedDotAccount,
|
|
46827
|
-
payUnitBillings,
|
|
46828
|
-
getMerchantDetailsById
|
|
46829
|
-
};
|
|
47047
|
+
}
|
|
47048
|
+
return { paySingleUnitBill };
|
|
46830
47049
|
};
|
|
46831
47050
|
|
|
46832
47051
|
// src/services/reddot-payment.service.ts
|
|
46833
47052
|
var useRedDotPaymentSvc = () => {
|
|
46834
|
-
const
|
|
46835
|
-
return useRedDotPaymentRepo().createRedDotAccount(_id, payload);
|
|
46836
|
-
};
|
|
47053
|
+
const { paySingleUnitBill } = useRedDotPaymentRepo();
|
|
46837
47054
|
const redirectPaymentTransaction = async (payload) => {
|
|
46838
47055
|
try {
|
|
46839
47056
|
const SECRET_KEY2 = payload.merchant_key;
|
|
46840
47057
|
if (!payload.mid && !payload.merchant_key) {
|
|
46841
|
-
return {
|
|
47058
|
+
return {
|
|
47059
|
+
success: false,
|
|
47060
|
+
message: "RDP Not Available on this account. Please Contact Management"
|
|
47061
|
+
};
|
|
46842
47062
|
}
|
|
46843
47063
|
const data = {
|
|
46844
47064
|
mid: payload.mid,
|
|
@@ -46861,7 +47081,9 @@ var useRedDotPaymentSvc = () => {
|
|
|
46861
47081
|
"Content-Length": String(dataString.length)
|
|
46862
47082
|
};
|
|
46863
47083
|
if (!process.env.MERCHANT_PAYMENT) {
|
|
46864
|
-
throw new Error(
|
|
47084
|
+
throw new Error(
|
|
47085
|
+
"MERCHANT_PAYMENT environment variable is not defined."
|
|
47086
|
+
);
|
|
46865
47087
|
}
|
|
46866
47088
|
const url = process.env.MERCHANT_PAYMENT;
|
|
46867
47089
|
const response = await import_axios3.default.post(url, dataString, { headers });
|
|
@@ -46875,7 +47097,10 @@ var useRedDotPaymentSvc = () => {
|
|
|
46875
47097
|
try {
|
|
46876
47098
|
const SECRET_KEY2 = payload.merchant_key;
|
|
46877
47099
|
if (!payload.request_mid && !payload.merchant_key) {
|
|
46878
|
-
return {
|
|
47100
|
+
return {
|
|
47101
|
+
success: false,
|
|
47102
|
+
message: "RDP Not Available on this account. Please Contact Management"
|
|
47103
|
+
};
|
|
46879
47104
|
}
|
|
46880
47105
|
const data = {
|
|
46881
47106
|
request_mid: payload.request_mid,
|
|
@@ -46890,7 +47115,9 @@ var useRedDotPaymentSvc = () => {
|
|
|
46890
47115
|
"Content-Type": "application/json"
|
|
46891
47116
|
};
|
|
46892
47117
|
if (!process.env.MERCHANT_ENQUIRY) {
|
|
46893
|
-
throw new Error(
|
|
47118
|
+
throw new Error(
|
|
47119
|
+
"MERCHANT_PAYMENT environment variable is not defined."
|
|
47120
|
+
);
|
|
46894
47121
|
}
|
|
46895
47122
|
const url = process.env.MERCHANT_ENQUIRY;
|
|
46896
47123
|
const response = await import_axios3.default.post(url, dataString, { headers });
|
|
@@ -46904,25 +47131,24 @@ var useRedDotPaymentSvc = () => {
|
|
|
46904
47131
|
if (result.response_code === "0") {
|
|
46905
47132
|
const success = {
|
|
46906
47133
|
method: payload.method,
|
|
46907
|
-
paymentStatus: "
|
|
46908
|
-
amountPaid: amount,
|
|
46909
|
-
paidBy: payer,
|
|
47134
|
+
paymentStatus: "paid" /* PAID */,
|
|
47135
|
+
amountPaid: parseInt(amount),
|
|
46910
47136
|
updatedAt: invoiceDate,
|
|
46911
47137
|
transaction_id: transactionId,
|
|
46912
47138
|
message
|
|
46913
47139
|
};
|
|
46914
|
-
await
|
|
47140
|
+
await paySingleUnitBill(refId, success);
|
|
46915
47141
|
} else if (result.response_code !== "0") {
|
|
46916
47142
|
const fail = {
|
|
46917
47143
|
method: payload.method,
|
|
46918
|
-
paymentStatus: "
|
|
47144
|
+
paymentStatus: "failed" /* FAILED */,
|
|
46919
47145
|
updatedAt: invoiceDate,
|
|
46920
47146
|
paidBy: "",
|
|
46921
|
-
amountPaid:
|
|
47147
|
+
amountPaid: 0,
|
|
46922
47148
|
transaction_id: transactionId,
|
|
46923
47149
|
message
|
|
46924
47150
|
};
|
|
46925
|
-
await
|
|
47151
|
+
await paySingleUnitBill(refId, fail);
|
|
46926
47152
|
}
|
|
46927
47153
|
return result;
|
|
46928
47154
|
} catch (error) {
|
|
@@ -46942,7 +47168,9 @@ var useRedDotPaymentSvc = () => {
|
|
|
46942
47168
|
"Content-Length": String(dataString.length)
|
|
46943
47169
|
};
|
|
46944
47170
|
if (!process.env.MERCHANT_PAYMENT) {
|
|
46945
|
-
throw new Error(
|
|
47171
|
+
throw new Error(
|
|
47172
|
+
"MERCHANT_PAYMENT environment variable is not defined."
|
|
47173
|
+
);
|
|
46946
47174
|
}
|
|
46947
47175
|
const url = process.env.MERCHANT_PAYMENT;
|
|
46948
47176
|
const response = await import_axios3.default.post(url, dataString, { headers });
|
|
@@ -46951,45 +47179,16 @@ var useRedDotPaymentSvc = () => {
|
|
|
46951
47179
|
return Promise.reject(error || error.message || "Server Internal Error!");
|
|
46952
47180
|
}
|
|
46953
47181
|
};
|
|
46954
|
-
const getMerchantDetailsById = async (_id) => {
|
|
46955
|
-
return useRedDotPaymentRepo().getMerchantDetailsById(_id);
|
|
46956
|
-
};
|
|
46957
47182
|
return {
|
|
46958
|
-
createRedDotAccount,
|
|
46959
47183
|
redirectPaymentTransaction,
|
|
46960
47184
|
enquirePaymentTransaction,
|
|
46961
|
-
payInvoice
|
|
46962
|
-
getMerchantDetailsById
|
|
47185
|
+
payInvoice
|
|
46963
47186
|
};
|
|
46964
47187
|
};
|
|
46965
47188
|
|
|
46966
47189
|
// src/controllers/reddot-payment.controller.ts
|
|
46967
47190
|
var import_joi124 = __toESM(require("joi"));
|
|
46968
47191
|
function useRedDotPaymentController() {
|
|
46969
|
-
const createRedDotAccount = async (req, res) => {
|
|
46970
|
-
try {
|
|
46971
|
-
const data = req.body;
|
|
46972
|
-
const id = req.params.id;
|
|
46973
|
-
const schema2 = import_joi124.default.object({
|
|
46974
|
-
id: import_joi124.default.string().hex().required(),
|
|
46975
|
-
// organization id
|
|
46976
|
-
paymentMethod: import_joi124.default.string().required(),
|
|
46977
|
-
// payment method (e.g. "Visa / Mastercard / PayNow QR Code")
|
|
46978
|
-
merchant_id: import_joi124.default.string().required(),
|
|
46979
|
-
// merchant id
|
|
46980
|
-
merchant_key: import_joi124.default.string().required()
|
|
46981
|
-
// secret key
|
|
46982
|
-
});
|
|
46983
|
-
const { error } = schema2.validate({ id, ...data });
|
|
46984
|
-
if (error) {
|
|
46985
|
-
return res.status(400).json({ data: null, message: error.message });
|
|
46986
|
-
}
|
|
46987
|
-
const result = await useRedDotPaymentSvc().createRedDotAccount(id, data);
|
|
46988
|
-
return res.json(result);
|
|
46989
|
-
} catch (error) {
|
|
46990
|
-
return res.status(500).json({ message: error.message || error });
|
|
46991
|
-
}
|
|
46992
|
-
};
|
|
46993
47192
|
const redirectPaymentTransaction = async (req, res) => {
|
|
46994
47193
|
try {
|
|
46995
47194
|
const data = req.body;
|
|
@@ -47006,7 +47205,9 @@ function useRedDotPaymentController() {
|
|
|
47006
47205
|
if (error) {
|
|
47007
47206
|
return res.status(400).json({ data: null, message: error.message });
|
|
47008
47207
|
}
|
|
47009
|
-
const result = await useRedDotPaymentSvc().redirectPaymentTransaction(
|
|
47208
|
+
const result = await useRedDotPaymentSvc().redirectPaymentTransaction(
|
|
47209
|
+
data
|
|
47210
|
+
);
|
|
47010
47211
|
return res.json(result);
|
|
47011
47212
|
} catch (error) {
|
|
47012
47213
|
return res.status(500).json({ message: error.message || error });
|
|
@@ -47025,43 +47226,27 @@ function useRedDotPaymentController() {
|
|
|
47025
47226
|
if (error) {
|
|
47026
47227
|
return res.status(400).json({ data: null, message: error.message });
|
|
47027
47228
|
}
|
|
47028
|
-
const result = await useRedDotPaymentSvc().enquirePaymentTransaction(
|
|
47229
|
+
const result = await useRedDotPaymentSvc().enquirePaymentTransaction(
|
|
47230
|
+
data
|
|
47231
|
+
);
|
|
47029
47232
|
return res.json(result);
|
|
47030
47233
|
} catch (error) {
|
|
47031
47234
|
return res.status(500).json({ message: error.message || error });
|
|
47032
47235
|
}
|
|
47033
47236
|
};
|
|
47034
|
-
const getMerchantDetailsById = async (req, res, next) => {
|
|
47035
|
-
try {
|
|
47036
|
-
const _id = req.params.id;
|
|
47037
|
-
const schema2 = import_joi124.default.object({
|
|
47038
|
-
_id: import_joi124.default.string().hex().required()
|
|
47039
|
-
});
|
|
47040
|
-
const { error } = schema2.validate({ _id });
|
|
47041
|
-
if (error) {
|
|
47042
|
-
return res.status(400).json({ data: null, message: error.message });
|
|
47043
|
-
}
|
|
47044
|
-
const result = await useRedDotPaymentSvc().getMerchantDetailsById(_id);
|
|
47045
|
-
return res.json(result);
|
|
47046
|
-
} catch (error) {
|
|
47047
|
-
next(error);
|
|
47048
|
-
}
|
|
47049
|
-
};
|
|
47050
47237
|
return {
|
|
47051
|
-
createRedDotAccount,
|
|
47052
47238
|
redirectPaymentTransaction,
|
|
47053
|
-
enquirePaymentTransaction
|
|
47054
|
-
getMerchantDetailsById
|
|
47239
|
+
enquirePaymentTransaction
|
|
47055
47240
|
};
|
|
47056
47241
|
}
|
|
47057
47242
|
|
|
47058
47243
|
// src/repositories/verification-v2.repo.ts
|
|
47059
|
-
var
|
|
47060
|
-
var
|
|
47244
|
+
var import_node_server_utils217 = require("@7365admin1/node-server-utils");
|
|
47245
|
+
var import_mongodb124 = require("mongodb");
|
|
47061
47246
|
function useVerificationRepoV2() {
|
|
47062
|
-
const db =
|
|
47247
|
+
const db = import_node_server_utils217.useAtlas.getDb();
|
|
47063
47248
|
if (!db) {
|
|
47064
|
-
throw new
|
|
47249
|
+
throw new import_node_server_utils217.InternalServerError("Unable to connect to server.");
|
|
47065
47250
|
}
|
|
47066
47251
|
const namespace_collection = "verifications";
|
|
47067
47252
|
const collection = db.collection(namespace_collection);
|
|
@@ -47074,7 +47259,7 @@ function useVerificationRepoV2() {
|
|
|
47074
47259
|
{ "metadata.org": 1 }
|
|
47075
47260
|
]);
|
|
47076
47261
|
} catch (error) {
|
|
47077
|
-
throw new
|
|
47262
|
+
throw new import_node_server_utils217.InternalServerError("Failed to create index.");
|
|
47078
47263
|
}
|
|
47079
47264
|
}
|
|
47080
47265
|
async function createTextIndex() {
|
|
@@ -47083,36 +47268,36 @@ function useVerificationRepoV2() {
|
|
|
47083
47268
|
email: "text"
|
|
47084
47269
|
});
|
|
47085
47270
|
} catch (error) {
|
|
47086
|
-
throw new
|
|
47271
|
+
throw new import_node_server_utils217.InternalServerError("Failed to create text index on email.");
|
|
47087
47272
|
}
|
|
47088
47273
|
}
|
|
47089
|
-
const { delNamespace, setCache, getCache, delCache } = (0,
|
|
47274
|
+
const { delNamespace, setCache, getCache, delCache } = (0, import_node_server_utils217.useCache)(namespace_collection);
|
|
47090
47275
|
async function add(value, session) {
|
|
47091
47276
|
value = new MVerificationV2(value);
|
|
47092
47277
|
try {
|
|
47093
47278
|
const res = await collection.insertOne(value, { session });
|
|
47094
47279
|
delNamespace().then(() => {
|
|
47095
|
-
|
|
47280
|
+
import_node_server_utils217.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
47096
47281
|
}).catch((err) => {
|
|
47097
|
-
|
|
47282
|
+
import_node_server_utils217.logger.error(
|
|
47098
47283
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
47099
47284
|
err
|
|
47100
47285
|
);
|
|
47101
47286
|
});
|
|
47102
47287
|
return res.insertedId;
|
|
47103
47288
|
} catch (error) {
|
|
47104
|
-
|
|
47289
|
+
import_node_server_utils217.logger.log({
|
|
47105
47290
|
level: "info",
|
|
47106
47291
|
message: String(error)
|
|
47107
47292
|
});
|
|
47108
|
-
throw new
|
|
47293
|
+
throw new import_node_server_utils217.InternalServerError("Server internal error.");
|
|
47109
47294
|
}
|
|
47110
47295
|
}
|
|
47111
47296
|
async function updateVerificationStatusById(_id, status, session) {
|
|
47112
47297
|
try {
|
|
47113
|
-
_id = new
|
|
47298
|
+
_id = new import_mongodb124.ObjectId(_id);
|
|
47114
47299
|
} catch (error) {
|
|
47115
|
-
throw new
|
|
47300
|
+
throw new import_node_server_utils217.BadRequestError("Invalid verification ID format.");
|
|
47116
47301
|
}
|
|
47117
47302
|
try {
|
|
47118
47303
|
const result = await collection.updateOne(
|
|
@@ -47121,24 +47306,24 @@ function useVerificationRepoV2() {
|
|
|
47121
47306
|
{ session }
|
|
47122
47307
|
);
|
|
47123
47308
|
delNamespace().then(() => {
|
|
47124
|
-
|
|
47309
|
+
import_node_server_utils217.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
47125
47310
|
}).catch((err) => {
|
|
47126
|
-
|
|
47311
|
+
import_node_server_utils217.logger.error(
|
|
47127
47312
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
47128
47313
|
err
|
|
47129
47314
|
);
|
|
47130
47315
|
});
|
|
47131
47316
|
return result;
|
|
47132
47317
|
} catch (error) {
|
|
47133
|
-
throw new
|
|
47318
|
+
throw new import_node_server_utils217.InternalServerError("Error updating verification status.");
|
|
47134
47319
|
}
|
|
47135
47320
|
}
|
|
47136
47321
|
async function getByVerificationCode(verificationCode) {
|
|
47137
47322
|
try {
|
|
47138
|
-
const cacheKey = (0,
|
|
47323
|
+
const cacheKey = (0, import_node_server_utils217.makeCacheKey)(namespace_collection, { verificationCode });
|
|
47139
47324
|
const cachedData = await getCache(cacheKey);
|
|
47140
47325
|
if (cachedData) {
|
|
47141
|
-
|
|
47326
|
+
import_node_server_utils217.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
47142
47327
|
return cachedData;
|
|
47143
47328
|
}
|
|
47144
47329
|
const query = {
|
|
@@ -47147,35 +47332,35 @@ function useVerificationRepoV2() {
|
|
|
47147
47332
|
};
|
|
47148
47333
|
const data = await collection.findOne(query);
|
|
47149
47334
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
47150
|
-
|
|
47335
|
+
import_node_server_utils217.logger.info(`Cache set for key: ${cacheKey}`);
|
|
47151
47336
|
}).catch((err) => {
|
|
47152
|
-
|
|
47337
|
+
import_node_server_utils217.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
47153
47338
|
});
|
|
47154
47339
|
return data;
|
|
47155
47340
|
} catch (error) {
|
|
47156
|
-
throw new
|
|
47341
|
+
throw new import_node_server_utils217.InternalServerError(
|
|
47157
47342
|
"Internal server error, failed to retrieve verification."
|
|
47158
47343
|
);
|
|
47159
47344
|
}
|
|
47160
47345
|
}
|
|
47161
47346
|
async function getVerificationById(id) {
|
|
47162
47347
|
try {
|
|
47163
|
-
const _id = (0,
|
|
47164
|
-
const cacheKey = (0,
|
|
47348
|
+
const _id = (0, import_node_server_utils217.toObjectId)(id);
|
|
47349
|
+
const cacheKey = (0, import_node_server_utils217.makeCacheKey)(namespace_collection, { id });
|
|
47165
47350
|
const cachedData = await getCache(cacheKey);
|
|
47166
47351
|
if (cachedData) {
|
|
47167
|
-
|
|
47352
|
+
import_node_server_utils217.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
47168
47353
|
return cachedData;
|
|
47169
47354
|
}
|
|
47170
47355
|
const data = await collection.findOne({ _id });
|
|
47171
47356
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
47172
|
-
|
|
47357
|
+
import_node_server_utils217.logger.info(`Cache set for key: ${cacheKey}`);
|
|
47173
47358
|
}).catch((err) => {
|
|
47174
|
-
|
|
47359
|
+
import_node_server_utils217.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
47175
47360
|
});
|
|
47176
47361
|
return data;
|
|
47177
47362
|
} catch (error) {
|
|
47178
|
-
throw new
|
|
47363
|
+
throw new import_node_server_utils217.InternalServerError(
|
|
47179
47364
|
"Internal server error, failed to retrieve verification."
|
|
47180
47365
|
);
|
|
47181
47366
|
}
|
|
@@ -47215,10 +47400,10 @@ function useVerificationRepoV2() {
|
|
|
47215
47400
|
query.email = email;
|
|
47216
47401
|
cacheOptions.email = email;
|
|
47217
47402
|
}
|
|
47218
|
-
const cacheKey = (0,
|
|
47403
|
+
const cacheKey = (0, import_node_server_utils217.makeCacheKey)(namespace_collection, cacheOptions);
|
|
47219
47404
|
const cachedData = await getCache(cacheKey);
|
|
47220
47405
|
if (cachedData) {
|
|
47221
|
-
|
|
47406
|
+
import_node_server_utils217.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
47222
47407
|
return cachedData;
|
|
47223
47408
|
}
|
|
47224
47409
|
try {
|
|
@@ -47239,23 +47424,23 @@ function useVerificationRepoV2() {
|
|
|
47239
47424
|
}
|
|
47240
47425
|
]).toArray();
|
|
47241
47426
|
const length = await collection.countDocuments(query);
|
|
47242
|
-
const data = (0,
|
|
47427
|
+
const data = (0, import_node_server_utils217.paginate)(items, page, limit, length);
|
|
47243
47428
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
47244
|
-
|
|
47429
|
+
import_node_server_utils217.logger.info(`Cache set for key: ${cacheKey}`);
|
|
47245
47430
|
}).catch((err) => {
|
|
47246
|
-
|
|
47431
|
+
import_node_server_utils217.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
47247
47432
|
});
|
|
47248
47433
|
return data;
|
|
47249
47434
|
} catch (error) {
|
|
47250
|
-
|
|
47435
|
+
import_node_server_utils217.logger.log({ level: "error", message: `${error}` });
|
|
47251
47436
|
throw error;
|
|
47252
47437
|
}
|
|
47253
47438
|
}
|
|
47254
47439
|
async function updateStatusById(_id, status, session) {
|
|
47255
47440
|
try {
|
|
47256
|
-
_id = new
|
|
47441
|
+
_id = new import_mongodb124.ObjectId(_id);
|
|
47257
47442
|
} catch (error) {
|
|
47258
|
-
throw new
|
|
47443
|
+
throw new import_node_server_utils217.BadRequestError("Invalid verification ID format.");
|
|
47259
47444
|
}
|
|
47260
47445
|
try {
|
|
47261
47446
|
const result = await collection.updateOne(
|
|
@@ -47264,22 +47449,22 @@ function useVerificationRepoV2() {
|
|
|
47264
47449
|
{ session }
|
|
47265
47450
|
);
|
|
47266
47451
|
delNamespace().then(() => {
|
|
47267
|
-
|
|
47452
|
+
import_node_server_utils217.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
47268
47453
|
}).catch((err) => {
|
|
47269
|
-
|
|
47454
|
+
import_node_server_utils217.logger.error(
|
|
47270
47455
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
47271
47456
|
err
|
|
47272
47457
|
);
|
|
47273
47458
|
});
|
|
47274
|
-
const cacheKey = (0,
|
|
47459
|
+
const cacheKey = (0, import_node_server_utils217.makeCacheKey)(namespace_collection, { _id });
|
|
47275
47460
|
delCache(cacheKey).then(() => {
|
|
47276
|
-
|
|
47461
|
+
import_node_server_utils217.logger.info(`Cache deleted for key: ${cacheKey}`);
|
|
47277
47462
|
}).catch((err) => {
|
|
47278
|
-
|
|
47463
|
+
import_node_server_utils217.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
47279
47464
|
});
|
|
47280
47465
|
return result;
|
|
47281
47466
|
} catch (error) {
|
|
47282
|
-
throw new
|
|
47467
|
+
throw new import_node_server_utils217.InternalServerError("Error updating verification status.");
|
|
47283
47468
|
}
|
|
47284
47469
|
}
|
|
47285
47470
|
return {
|
|
@@ -47295,7 +47480,7 @@ function useVerificationRepoV2() {
|
|
|
47295
47480
|
}
|
|
47296
47481
|
|
|
47297
47482
|
// src/services/verification-v2.service.ts
|
|
47298
|
-
var
|
|
47483
|
+
var import_node_server_utils218 = require("@7365admin1/node-server-utils");
|
|
47299
47484
|
var import_crypto2 = __toESM(require("crypto"));
|
|
47300
47485
|
var import_joi125 = __toESM(require("joi"));
|
|
47301
47486
|
function useVerificationServiceV2() {
|
|
@@ -47306,7 +47491,7 @@ function useVerificationServiceV2() {
|
|
|
47306
47491
|
email: MAILER_EMAIL,
|
|
47307
47492
|
password: MAILER_PASSWORD
|
|
47308
47493
|
};
|
|
47309
|
-
const mailer = new
|
|
47494
|
+
const mailer = new import_node_server_utils218.useMailer(MailerConfig);
|
|
47310
47495
|
const {
|
|
47311
47496
|
add: _add,
|
|
47312
47497
|
updateVerificationStatusById: _updateVerificationStatusById,
|
|
@@ -47321,31 +47506,31 @@ function useVerificationServiceV2() {
|
|
|
47321
47506
|
const { getSiteById } = useSiteRepo();
|
|
47322
47507
|
function errorByType(type, status) {
|
|
47323
47508
|
if ((type === "user-invite" /* USER_INVITE */ || type === "member-invite" /* MEMBER_INVITE */ || type === "service-provider-invite" /* SERVICE_PROVIDER_INVITE */ || type === "service-provider-create-org" /* SERVICE_PROVIDER_CREATE_ORG */) && status === "expired" /* EXPIRED */) {
|
|
47324
|
-
throw new
|
|
47509
|
+
throw new import_node_server_utils218.BadRequestError(
|
|
47325
47510
|
"Invitation has already expired, please contact admin to resend the invitation."
|
|
47326
47511
|
);
|
|
47327
47512
|
}
|
|
47328
47513
|
if (type === "user-sign-up" /* USER_SIGN_UP */ && status === "expired" /* EXPIRED */) {
|
|
47329
|
-
throw new
|
|
47514
|
+
throw new import_node_server_utils218.BadRequestError(
|
|
47330
47515
|
"Sign up verification has expired, please sign up again to get a new verification link."
|
|
47331
47516
|
);
|
|
47332
47517
|
}
|
|
47333
47518
|
if ((type === "user-invite" /* USER_INVITE */ || type === "member-invite" /* MEMBER_INVITE */ || type === "service-provider-invite" /* SERVICE_PROVIDER_INVITE */ || type === "service-provider-create-org" /* SERVICE_PROVIDER_CREATE_ORG */) && status === "complete" /* COMPLETE */) {
|
|
47334
|
-
throw new
|
|
47519
|
+
throw new import_node_server_utils218.BadRequestError(
|
|
47335
47520
|
"User already registered, please login to continue."
|
|
47336
47521
|
);
|
|
47337
47522
|
}
|
|
47338
47523
|
if (type === "forget-password" /* FORGET_PASSWORD */ && status === "complete" /* COMPLETE */) {
|
|
47339
|
-
throw new
|
|
47524
|
+
throw new import_node_server_utils218.BadRequestError(
|
|
47340
47525
|
"Forget password verification has already been used, please request a new one."
|
|
47341
47526
|
);
|
|
47342
47527
|
}
|
|
47343
47528
|
if (type === "forget-password" /* FORGET_PASSWORD */ && status === "expired" /* EXPIRED */) {
|
|
47344
|
-
throw new
|
|
47529
|
+
throw new import_node_server_utils218.BadRequestError(
|
|
47345
47530
|
"Forget password verification has expired, please request a new one."
|
|
47346
47531
|
);
|
|
47347
47532
|
}
|
|
47348
|
-
throw new
|
|
47533
|
+
throw new import_node_server_utils218.BadRequestError("Invalid verification.");
|
|
47349
47534
|
}
|
|
47350
47535
|
function generateVerificationCode(length = 8) {
|
|
47351
47536
|
const chars = "0123456789";
|
|
@@ -47360,17 +47545,17 @@ function useVerificationServiceV2() {
|
|
|
47360
47545
|
email,
|
|
47361
47546
|
metadata
|
|
47362
47547
|
}) {
|
|
47363
|
-
const session =
|
|
47548
|
+
const session = import_node_server_utils218.useAtlas.getClient()?.startSession();
|
|
47364
47549
|
try {
|
|
47365
47550
|
session?.startTransaction();
|
|
47366
47551
|
const user = await _getUserByEmailStatus(email);
|
|
47367
47552
|
if (user) {
|
|
47368
|
-
throw new
|
|
47553
|
+
throw new import_node_server_utils218.BadRequestError(
|
|
47369
47554
|
`Email ${email} is already registered, please login to continue.`
|
|
47370
47555
|
);
|
|
47371
47556
|
}
|
|
47372
47557
|
const verificationCode = generateVerificationCode(6);
|
|
47373
|
-
metadata.password = await (0,
|
|
47558
|
+
metadata.password = await (0, import_node_server_utils218.hashPassword)(metadata.password);
|
|
47374
47559
|
metadata.verificationCode = verificationCode;
|
|
47375
47560
|
const value = {
|
|
47376
47561
|
type: "user-sign-up" /* USER_SIGN_UP */,
|
|
@@ -47382,8 +47567,8 @@ function useVerificationServiceV2() {
|
|
|
47382
47567
|
};
|
|
47383
47568
|
const res = await _add(value);
|
|
47384
47569
|
const dir = __dirname;
|
|
47385
|
-
const filePath = (0,
|
|
47386
|
-
const emailContent = (0,
|
|
47570
|
+
const filePath = (0, import_node_server_utils218.getDirectory)(dir, "./public/handlebars/sign-up-v2");
|
|
47571
|
+
const emailContent = (0, import_node_server_utils218.compileHandlebar)({
|
|
47387
47572
|
context: {
|
|
47388
47573
|
email,
|
|
47389
47574
|
validity: "15 minutes",
|
|
@@ -47397,7 +47582,7 @@ function useVerificationServiceV2() {
|
|
|
47397
47582
|
html: emailContent,
|
|
47398
47583
|
sender: "iService365" /* ISERVICE365 */
|
|
47399
47584
|
}).catch((error) => {
|
|
47400
|
-
|
|
47585
|
+
import_node_server_utils218.logger.log({
|
|
47401
47586
|
level: "error",
|
|
47402
47587
|
message: `Error sending user invite email: ${error}`
|
|
47403
47588
|
});
|
|
@@ -47412,21 +47597,21 @@ function useVerificationServiceV2() {
|
|
|
47412
47597
|
}
|
|
47413
47598
|
}
|
|
47414
47599
|
async function verify(verificationCode) {
|
|
47415
|
-
const session =
|
|
47600
|
+
const session = import_node_server_utils218.useAtlas.getClient()?.startSession();
|
|
47416
47601
|
try {
|
|
47417
47602
|
session?.startTransaction();
|
|
47418
47603
|
const item = await _getByVerificationCode(verificationCode);
|
|
47419
47604
|
if (!item) {
|
|
47420
|
-
throw new
|
|
47605
|
+
throw new import_node_server_utils218.NotFoundError("Verification not found.");
|
|
47421
47606
|
}
|
|
47422
47607
|
switch (item.status) {
|
|
47423
47608
|
case "expired" /* EXPIRED */:
|
|
47424
47609
|
errorByType(item.type, "expired" /* EXPIRED */);
|
|
47425
47610
|
break;
|
|
47426
47611
|
case "cancelled" /* CANCELLED */:
|
|
47427
|
-
throw new
|
|
47612
|
+
throw new import_node_server_utils218.BadRequestError("Verification already cancelled.");
|
|
47428
47613
|
case "complete" /* COMPLETE */:
|
|
47429
|
-
throw new
|
|
47614
|
+
throw new import_node_server_utils218.BadRequestError("Verification already completed.");
|
|
47430
47615
|
}
|
|
47431
47616
|
const expiration = new Date(item.expireAt).getTime();
|
|
47432
47617
|
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
@@ -47442,7 +47627,7 @@ function useVerificationServiceV2() {
|
|
|
47442
47627
|
return { _id, type, email, status, expireAt };
|
|
47443
47628
|
} catch (error) {
|
|
47444
47629
|
await session?.abortTransaction();
|
|
47445
|
-
|
|
47630
|
+
import_node_server_utils218.logger.log({
|
|
47446
47631
|
level: "info",
|
|
47447
47632
|
message: `Error verifying user invitation: ${error}`
|
|
47448
47633
|
});
|
|
@@ -47479,11 +47664,11 @@ function useVerificationServiceV2() {
|
|
|
47479
47664
|
value.type = type;
|
|
47480
47665
|
const res = await _add(value);
|
|
47481
47666
|
const dir = __dirname;
|
|
47482
|
-
const filePath = (0,
|
|
47667
|
+
const filePath = (0, import_node_server_utils218.getDirectory)(dir, `./public/handlebars/${type}`);
|
|
47483
47668
|
const isMember = type === "member-invite" /* MEMBER_INVITE */;
|
|
47484
47669
|
const subject = isMember ? "Member Invite" /* _MEMBER_INVITE */ : "User Invite" /* _USER_INVITE */;
|
|
47485
47670
|
const link = `${APP_MAIN}/verify/${isMember ? "membership" /* MEMBERSHIP */ : "invitation" /* INVITATION */}/${res}`;
|
|
47486
|
-
const emailContent = (0,
|
|
47671
|
+
const emailContent = (0, import_node_server_utils218.compileHandlebar)({
|
|
47487
47672
|
context: {
|
|
47488
47673
|
email: userName,
|
|
47489
47674
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
@@ -47497,7 +47682,7 @@ function useVerificationServiceV2() {
|
|
|
47497
47682
|
html: emailContent,
|
|
47498
47683
|
sender: "iService365" /* ISERVICE365 */
|
|
47499
47684
|
}).catch((error) => {
|
|
47500
|
-
|
|
47685
|
+
import_node_server_utils218.logger.log({
|
|
47501
47686
|
level: "error",
|
|
47502
47687
|
message: `Error sending user ${type} email: ${error}`
|
|
47503
47688
|
});
|
|
@@ -47527,8 +47712,8 @@ function useVerificationServiceV2() {
|
|
|
47527
47712
|
});
|
|
47528
47713
|
if (error) {
|
|
47529
47714
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
47530
|
-
|
|
47531
|
-
throw new
|
|
47715
|
+
import_node_server_utils218.logger.log({ level: "error", message: messages });
|
|
47716
|
+
throw new import_node_server_utils218.BadRequestError(`Invalid input: ${error.message}`);
|
|
47532
47717
|
}
|
|
47533
47718
|
let subject = "Service Provider Invite" /* _SERVICE_PROVIDER_INVITE */;
|
|
47534
47719
|
const value = {
|
|
@@ -47553,9 +47738,9 @@ function useVerificationServiceV2() {
|
|
|
47553
47738
|
}
|
|
47554
47739
|
const res = await _add(value);
|
|
47555
47740
|
const dir = __dirname;
|
|
47556
|
-
const filePath = (0,
|
|
47741
|
+
const filePath = (0, import_node_server_utils218.getDirectory)(dir, `./public/handlebars/${value.type}`);
|
|
47557
47742
|
const link = org ? `${APP_MAIN}/verify/${value.type}/${res}` : `${APP_ORG}/organizations/create?email=${email}`;
|
|
47558
|
-
const emailContent = (0,
|
|
47743
|
+
const emailContent = (0, import_node_server_utils218.compileHandlebar)({
|
|
47559
47744
|
context: {
|
|
47560
47745
|
email: org?.name || email,
|
|
47561
47746
|
validity: VERIFICATION_USER_INVITE_DURATION,
|
|
@@ -47569,7 +47754,7 @@ function useVerificationServiceV2() {
|
|
|
47569
47754
|
html: emailContent,
|
|
47570
47755
|
sender: "iService365" /* ISERVICE365 */
|
|
47571
47756
|
}).catch((error2) => {
|
|
47572
|
-
|
|
47757
|
+
import_node_server_utils218.logger.log({
|
|
47573
47758
|
level: "error",
|
|
47574
47759
|
message: `Error sending user ${value.type} email: ${error2}`
|
|
47575
47760
|
});
|
|
@@ -47591,8 +47776,8 @@ function useVerificationServiceV2() {
|
|
|
47591
47776
|
const user = await _getUserByEmail(email);
|
|
47592
47777
|
const res = await _add(value);
|
|
47593
47778
|
const dir = __dirname;
|
|
47594
|
-
const filePath = (0,
|
|
47595
|
-
const emailContent = (0,
|
|
47779
|
+
const filePath = (0, import_node_server_utils218.getDirectory)(dir, "./public/handlebars/forget-password");
|
|
47780
|
+
const emailContent = (0, import_node_server_utils218.compileHandlebar)({
|
|
47596
47781
|
context: {
|
|
47597
47782
|
userName: user?.name,
|
|
47598
47783
|
validity: VERIFICATION_FORGET_PASSWORD_DURATION,
|
|
@@ -47606,21 +47791,21 @@ function useVerificationServiceV2() {
|
|
|
47606
47791
|
sender: "iService365" /* ISERVICE365 */,
|
|
47607
47792
|
html: emailContent
|
|
47608
47793
|
}).catch((error) => {
|
|
47609
|
-
|
|
47794
|
+
import_node_server_utils218.logger.log({
|
|
47610
47795
|
level: "error",
|
|
47611
47796
|
message: `Error sending forget password email: ${error}`
|
|
47612
47797
|
});
|
|
47613
47798
|
});
|
|
47614
47799
|
return "Successfully created a link to reset password. Please check your email.";
|
|
47615
47800
|
} catch (error) {
|
|
47616
|
-
throw new
|
|
47801
|
+
throw new import_node_server_utils218.InternalServerError("Failed to create forget password link.");
|
|
47617
47802
|
}
|
|
47618
47803
|
}
|
|
47619
47804
|
async function cancelUserInvitation(id) {
|
|
47620
47805
|
try {
|
|
47621
47806
|
await _updateStatusById(id, "cancelled");
|
|
47622
47807
|
} catch (error) {
|
|
47623
|
-
throw new
|
|
47808
|
+
throw new import_node_server_utils218.InternalServerError(
|
|
47624
47809
|
`Error cancelling user invitation: ${error}`
|
|
47625
47810
|
);
|
|
47626
47811
|
}
|
|
@@ -47636,7 +47821,7 @@ function useVerificationServiceV2() {
|
|
|
47636
47821
|
}
|
|
47637
47822
|
|
|
47638
47823
|
// src/controllers/verification-v2.controller.ts
|
|
47639
|
-
var
|
|
47824
|
+
var import_node_server_utils219 = require("@7365admin1/node-server-utils");
|
|
47640
47825
|
var import_joi126 = __toESM(require("joi"));
|
|
47641
47826
|
function useVerificationControllerV2() {
|
|
47642
47827
|
const {
|
|
@@ -47658,15 +47843,15 @@ function useVerificationControllerV2() {
|
|
|
47658
47843
|
);
|
|
47659
47844
|
if (error) {
|
|
47660
47845
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
47661
|
-
|
|
47662
|
-
next(new
|
|
47846
|
+
import_node_server_utils219.logger.log({ level: "error", message: messages });
|
|
47847
|
+
next(new import_node_server_utils219.BadRequestError(messages));
|
|
47663
47848
|
return;
|
|
47664
47849
|
}
|
|
47665
47850
|
const message = await _verify(value.verificationCode);
|
|
47666
47851
|
res.json(message);
|
|
47667
47852
|
return;
|
|
47668
47853
|
} catch (error) {
|
|
47669
|
-
|
|
47854
|
+
import_node_server_utils219.logger.log({ level: "error", message: `${error.message}` });
|
|
47670
47855
|
next(error);
|
|
47671
47856
|
return;
|
|
47672
47857
|
}
|
|
@@ -47684,8 +47869,8 @@ function useVerificationControllerV2() {
|
|
|
47684
47869
|
const { error, value } = schema2.validate(req.body, { abortEarly: false });
|
|
47685
47870
|
if (error) {
|
|
47686
47871
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
47687
|
-
|
|
47688
|
-
next(new
|
|
47872
|
+
import_node_server_utils219.logger.log({ level: "error", message: messages });
|
|
47873
|
+
next(new import_node_server_utils219.BadRequestError(messages));
|
|
47689
47874
|
return;
|
|
47690
47875
|
}
|
|
47691
47876
|
const { email, app, role, name, org, siteId, siteName } = value;
|
|
@@ -47704,7 +47889,7 @@ function useVerificationControllerV2() {
|
|
|
47704
47889
|
res.status(201).json({ message: "Successfully invited user." });
|
|
47705
47890
|
return;
|
|
47706
47891
|
} catch (error2) {
|
|
47707
|
-
|
|
47892
|
+
import_node_server_utils219.logger.log({ level: "error", message: `${error2.message}` });
|
|
47708
47893
|
next(error2);
|
|
47709
47894
|
return;
|
|
47710
47895
|
}
|
|
@@ -47719,8 +47904,8 @@ function useVerificationControllerV2() {
|
|
|
47719
47904
|
const { error, value } = schema2.validate(req.body, { abortEarly: false });
|
|
47720
47905
|
if (error) {
|
|
47721
47906
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
47722
|
-
|
|
47723
|
-
next(new
|
|
47907
|
+
import_node_server_utils219.logger.log({ level: "error", message: messages });
|
|
47908
|
+
next(new import_node_server_utils219.BadRequestError(messages));
|
|
47724
47909
|
return;
|
|
47725
47910
|
}
|
|
47726
47911
|
try {
|
|
@@ -47733,7 +47918,7 @@ function useVerificationControllerV2() {
|
|
|
47733
47918
|
res.cookie("service-provider-email", value.email, cookieOptions).json({ message: "Successfully invited service provider." });
|
|
47734
47919
|
return;
|
|
47735
47920
|
} catch (error2) {
|
|
47736
|
-
|
|
47921
|
+
import_node_server_utils219.logger.log({ level: "error", message: `controller - ${error2.message}` });
|
|
47737
47922
|
next(error2);
|
|
47738
47923
|
return;
|
|
47739
47924
|
}
|
|
@@ -47745,8 +47930,8 @@ function useVerificationControllerV2() {
|
|
|
47745
47930
|
const { error, value } = schema2.validate(req.body, { abortEarly: false });
|
|
47746
47931
|
if (error) {
|
|
47747
47932
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
47748
|
-
|
|
47749
|
-
next(new
|
|
47933
|
+
import_node_server_utils219.logger.log({ level: "error", message: messages });
|
|
47934
|
+
next(new import_node_server_utils219.BadRequestError(messages));
|
|
47750
47935
|
return;
|
|
47751
47936
|
}
|
|
47752
47937
|
const { email } = value;
|
|
@@ -47757,7 +47942,7 @@ function useVerificationControllerV2() {
|
|
|
47757
47942
|
});
|
|
47758
47943
|
return;
|
|
47759
47944
|
} catch (error2) {
|
|
47760
|
-
|
|
47945
|
+
import_node_server_utils219.logger.log({ level: "error", message: `${error2.message}` });
|
|
47761
47946
|
next(error2);
|
|
47762
47947
|
return;
|
|
47763
47948
|
}
|
|
@@ -47777,8 +47962,8 @@ function useVerificationControllerV2() {
|
|
|
47777
47962
|
const { error, value } = schema2.validate(req.query);
|
|
47778
47963
|
if (error) {
|
|
47779
47964
|
const messages = error.details.map((d) => d.message).join(", ");
|
|
47780
|
-
|
|
47781
|
-
next(new
|
|
47965
|
+
import_node_server_utils219.logger.log({ level: "error", message: messages });
|
|
47966
|
+
next(new import_node_server_utils219.BadRequestError(messages));
|
|
47782
47967
|
return;
|
|
47783
47968
|
}
|
|
47784
47969
|
const { search, page, status, app, email, type } = value;
|
|
@@ -47794,7 +47979,7 @@ function useVerificationControllerV2() {
|
|
|
47794
47979
|
res.json(data);
|
|
47795
47980
|
return;
|
|
47796
47981
|
} catch (error2) {
|
|
47797
|
-
|
|
47982
|
+
import_node_server_utils219.logger.log({ level: "error", message: `${error2.message}` });
|
|
47798
47983
|
next(error2);
|
|
47799
47984
|
return;
|
|
47800
47985
|
}
|
|
@@ -47804,8 +47989,8 @@ function useVerificationControllerV2() {
|
|
|
47804
47989
|
const otpId = req.params.id;
|
|
47805
47990
|
const { error } = validation.validate(otpId);
|
|
47806
47991
|
if (error) {
|
|
47807
|
-
|
|
47808
|
-
next(new
|
|
47992
|
+
import_node_server_utils219.logger.log({ level: "error", message: `${error.message}` });
|
|
47993
|
+
next(new import_node_server_utils219.BadRequestError(error.message));
|
|
47809
47994
|
return;
|
|
47810
47995
|
}
|
|
47811
47996
|
try {
|
|
@@ -47815,7 +48000,7 @@ function useVerificationControllerV2() {
|
|
|
47815
48000
|
});
|
|
47816
48001
|
return;
|
|
47817
48002
|
} catch (error2) {
|
|
47818
|
-
|
|
48003
|
+
import_node_server_utils219.logger.log({ level: "error", message: `${error2.message}` });
|
|
47819
48004
|
next(error2);
|
|
47820
48005
|
return;
|
|
47821
48006
|
}
|
|
@@ -47832,38 +48017,38 @@ function useVerificationControllerV2() {
|
|
|
47832
48017
|
|
|
47833
48018
|
// src/controllers/auth-v2.controller.ts
|
|
47834
48019
|
var import_joi127 = __toESM(require("joi"));
|
|
47835
|
-
var
|
|
48020
|
+
var import_node_server_utils223 = require("@7365admin1/node-server-utils");
|
|
47836
48021
|
|
|
47837
48022
|
// src/services/auth-v2.service.ts
|
|
47838
|
-
var
|
|
48023
|
+
var import_node_server_utils221 = require("@7365admin1/node-server-utils");
|
|
47839
48024
|
var import_uuid2 = require("uuid");
|
|
47840
48025
|
|
|
47841
48026
|
// src/repositories/user-v2.repo.ts
|
|
47842
|
-
var
|
|
47843
|
-
var
|
|
48027
|
+
var import_mongodb125 = require("mongodb");
|
|
48028
|
+
var import_node_server_utils220 = require("@7365admin1/node-server-utils");
|
|
47844
48029
|
function useUserRepoV2() {
|
|
47845
48030
|
const { updateFeedbackCreatedByName } = useFeedbackRepo();
|
|
47846
48031
|
const { updateWorkOrderCreatedByName } = useWorkOrderRepo();
|
|
47847
48032
|
const { updateUserNameBySignatureId } = useOccurrenceEntryRepo();
|
|
47848
|
-
const db =
|
|
48033
|
+
const db = import_node_server_utils220.useAtlas.getDb();
|
|
47849
48034
|
if (!db) {
|
|
47850
|
-
throw new
|
|
48035
|
+
throw new import_node_server_utils220.InternalServerError("Unable to connect to server.");
|
|
47851
48036
|
}
|
|
47852
48037
|
const namespace_collection = "users";
|
|
47853
48038
|
const collection = db.collection(namespace_collection);
|
|
47854
|
-
const { delNamespace, setCache, getCache, delCache } = (0,
|
|
48039
|
+
const { delNamespace, setCache, getCache, delCache } = (0, import_node_server_utils220.useCache)(namespace_collection);
|
|
47855
48040
|
async function createIndex() {
|
|
47856
48041
|
try {
|
|
47857
48042
|
await collection.createIndexes([{ key: { email: 1 } }]);
|
|
47858
48043
|
} catch (error) {
|
|
47859
|
-
throw new
|
|
48044
|
+
throw new import_node_server_utils220.InternalServerError("Failed to create text index on user.");
|
|
47860
48045
|
}
|
|
47861
48046
|
}
|
|
47862
48047
|
async function createTextIndex() {
|
|
47863
48048
|
try {
|
|
47864
48049
|
await collection.createIndex({ name: "text", email: "text" });
|
|
47865
48050
|
} catch (error) {
|
|
47866
|
-
throw new
|
|
48051
|
+
throw new import_node_server_utils220.InternalServerError("Failed to create text index on user.");
|
|
47867
48052
|
}
|
|
47868
48053
|
}
|
|
47869
48054
|
async function createUniqueIndex() {
|
|
@@ -47873,7 +48058,7 @@ function useUserRepoV2() {
|
|
|
47873
48058
|
{ unique: true }
|
|
47874
48059
|
);
|
|
47875
48060
|
} catch (error) {
|
|
47876
|
-
throw new
|
|
48061
|
+
throw new import_node_server_utils220.InternalServerError("Failed to create unique index on user.");
|
|
47877
48062
|
}
|
|
47878
48063
|
}
|
|
47879
48064
|
async function createUser(value, session) {
|
|
@@ -47881,71 +48066,71 @@ function useUserRepoV2() {
|
|
|
47881
48066
|
value = MUser(value);
|
|
47882
48067
|
const res = await collection.insertOne(value, { session });
|
|
47883
48068
|
delNamespace().then(
|
|
47884
|
-
() =>
|
|
48069
|
+
() => import_node_server_utils220.logger.info(`Cache cleared for namespace: ${namespace_collection}`)
|
|
47885
48070
|
).catch(
|
|
47886
|
-
(err) =>
|
|
48071
|
+
(err) => import_node_server_utils220.logger.error(
|
|
47887
48072
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
47888
48073
|
err
|
|
47889
48074
|
)
|
|
47890
48075
|
);
|
|
47891
48076
|
return res.insertedId;
|
|
47892
48077
|
} catch (error) {
|
|
47893
|
-
|
|
48078
|
+
import_node_server_utils220.logger.log({ level: "error", message: `${error}` });
|
|
47894
48079
|
if (error.message.includes("duplicate")) {
|
|
47895
|
-
throw new
|
|
48080
|
+
throw new import_node_server_utils220.BadRequestError("User already exists.");
|
|
47896
48081
|
}
|
|
47897
48082
|
throw error;
|
|
47898
48083
|
}
|
|
47899
48084
|
}
|
|
47900
48085
|
async function getUserByEmail(email) {
|
|
47901
48086
|
try {
|
|
47902
|
-
const cacheKey = (0,
|
|
48087
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, { email });
|
|
47903
48088
|
const cachedData = await getCache(cacheKey);
|
|
47904
48089
|
if (cachedData) {
|
|
47905
|
-
|
|
48090
|
+
import_node_server_utils220.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
47906
48091
|
return cachedData;
|
|
47907
48092
|
}
|
|
47908
48093
|
const data = await collection.findOne({
|
|
47909
48094
|
email: { $regex: `^${email}$`, $options: "i" }
|
|
47910
48095
|
});
|
|
47911
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
47912
|
-
(err) =>
|
|
48096
|
+
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils220.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
48097
|
+
(err) => import_node_server_utils220.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
47913
48098
|
);
|
|
47914
48099
|
return data;
|
|
47915
48100
|
} catch (error) {
|
|
47916
|
-
throw new
|
|
48101
|
+
throw new import_node_server_utils220.InternalServerError("Failed to get user by email.");
|
|
47917
48102
|
}
|
|
47918
48103
|
}
|
|
47919
48104
|
async function getUserByEmailStatus(email) {
|
|
47920
48105
|
try {
|
|
47921
|
-
const cacheKey = (0,
|
|
48106
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, {
|
|
47922
48107
|
email,
|
|
47923
48108
|
status: "complete" /* COMPLETE */
|
|
47924
48109
|
});
|
|
47925
48110
|
const cachedData = await getCache(cacheKey);
|
|
47926
48111
|
if (cachedData) {
|
|
47927
|
-
|
|
48112
|
+
import_node_server_utils220.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
47928
48113
|
return cachedData;
|
|
47929
48114
|
}
|
|
47930
48115
|
const data = await collection.findOne({
|
|
47931
48116
|
email: { $regex: `^${email}$`, $options: "i" },
|
|
47932
48117
|
status: "complete" /* COMPLETE */
|
|
47933
48118
|
});
|
|
47934
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
47935
|
-
(err) =>
|
|
48119
|
+
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils220.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
48120
|
+
(err) => import_node_server_utils220.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
47936
48121
|
);
|
|
47937
48122
|
return data;
|
|
47938
48123
|
} catch (error) {
|
|
47939
|
-
throw new
|
|
48124
|
+
throw new import_node_server_utils220.InternalServerError("Failed to get user by email.");
|
|
47940
48125
|
}
|
|
47941
48126
|
}
|
|
47942
48127
|
async function getUserById(id) {
|
|
47943
|
-
const _id = (0,
|
|
48128
|
+
const _id = (0, import_node_server_utils220.toObjectId)(id);
|
|
47944
48129
|
try {
|
|
47945
|
-
const cacheKey = (0,
|
|
48130
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, { id });
|
|
47946
48131
|
const cachedData = await getCache(cacheKey);
|
|
47947
48132
|
if (cachedData) {
|
|
47948
|
-
|
|
48133
|
+
import_node_server_utils220.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
47949
48134
|
return cachedData;
|
|
47950
48135
|
}
|
|
47951
48136
|
const results = await collection.aggregate([
|
|
@@ -47968,52 +48153,52 @@ function useUserRepoV2() {
|
|
|
47968
48153
|
]).toArray();
|
|
47969
48154
|
const data = results.length > 0 ? results[0] : null;
|
|
47970
48155
|
if (!data)
|
|
47971
|
-
throw new
|
|
47972
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
47973
|
-
(err) =>
|
|
48156
|
+
throw new import_node_server_utils220.NotFoundError("User not found.");
|
|
48157
|
+
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils220.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
48158
|
+
(err) => import_node_server_utils220.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
47974
48159
|
);
|
|
47975
48160
|
return data;
|
|
47976
48161
|
} catch (error) {
|
|
47977
|
-
if (error instanceof
|
|
48162
|
+
if (error instanceof import_node_server_utils220.AppError)
|
|
47978
48163
|
throw error;
|
|
47979
|
-
throw new
|
|
48164
|
+
throw new import_node_server_utils220.InternalServerError("Failed to get user by id.");
|
|
47980
48165
|
}
|
|
47981
48166
|
}
|
|
47982
48167
|
async function getUserByReferralCode(referralCode) {
|
|
47983
48168
|
try {
|
|
47984
|
-
const cacheKey = (0,
|
|
48169
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, { referralCode });
|
|
47985
48170
|
const cachedData = await getCache(cacheKey);
|
|
47986
48171
|
if (cachedData) {
|
|
47987
|
-
|
|
48172
|
+
import_node_server_utils220.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
47988
48173
|
return cachedData;
|
|
47989
48174
|
}
|
|
47990
48175
|
const data = await collection.findOne({ referralCode });
|
|
47991
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
47992
|
-
(err) =>
|
|
48176
|
+
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils220.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
48177
|
+
(err) => import_node_server_utils220.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
47993
48178
|
);
|
|
47994
48179
|
return data;
|
|
47995
48180
|
} catch (error) {
|
|
47996
|
-
throw new
|
|
48181
|
+
throw new import_node_server_utils220.InternalServerError("Failed to get user by referral code.");
|
|
47997
48182
|
}
|
|
47998
48183
|
}
|
|
47999
48184
|
async function getByEmailApp(email, app) {
|
|
48000
48185
|
try {
|
|
48001
|
-
const cacheKey = (0,
|
|
48186
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, { email, app });
|
|
48002
48187
|
const cachedData = await getCache(cacheKey);
|
|
48003
48188
|
if (cachedData) {
|
|
48004
|
-
|
|
48189
|
+
import_node_server_utils220.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
48005
48190
|
return cachedData;
|
|
48006
48191
|
}
|
|
48007
48192
|
const data = await collection.findOne({
|
|
48008
48193
|
email,
|
|
48009
48194
|
"roles.app": app
|
|
48010
48195
|
});
|
|
48011
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
48012
|
-
(err) =>
|
|
48196
|
+
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils220.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
48197
|
+
(err) => import_node_server_utils220.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
48013
48198
|
);
|
|
48014
48199
|
return data;
|
|
48015
48200
|
} catch (error) {
|
|
48016
|
-
throw new
|
|
48201
|
+
throw new import_node_server_utils220.InternalServerError("Failed to get user by email and app.");
|
|
48017
48202
|
}
|
|
48018
48203
|
}
|
|
48019
48204
|
async function getUsersByOrgId({
|
|
@@ -48040,24 +48225,24 @@ function useUserRepoV2() {
|
|
|
48040
48225
|
}
|
|
48041
48226
|
if (organization) {
|
|
48042
48227
|
try {
|
|
48043
|
-
query.defaultOrg = new
|
|
48228
|
+
query.defaultOrg = new import_mongodb125.ObjectId(organization);
|
|
48044
48229
|
cacheOptions.organization = organization.toString();
|
|
48045
48230
|
} catch (error) {
|
|
48046
|
-
throw new
|
|
48231
|
+
throw new import_node_server_utils220.BadRequestError("Invalid organization ID format.");
|
|
48047
48232
|
}
|
|
48048
48233
|
}
|
|
48049
48234
|
delNamespace().then(() => {
|
|
48050
|
-
|
|
48235
|
+
import_node_server_utils220.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
48051
48236
|
}).catch((err) => {
|
|
48052
|
-
|
|
48237
|
+
import_node_server_utils220.logger.error(
|
|
48053
48238
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
48054
48239
|
err
|
|
48055
48240
|
);
|
|
48056
48241
|
});
|
|
48057
|
-
const cacheKey = (0,
|
|
48242
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, cacheOptions);
|
|
48058
48243
|
const cachedData = await getCache(cacheKey);
|
|
48059
48244
|
if (cachedData) {
|
|
48060
|
-
|
|
48245
|
+
import_node_server_utils220.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
48061
48246
|
return cachedData;
|
|
48062
48247
|
}
|
|
48063
48248
|
try {
|
|
@@ -48077,15 +48262,15 @@ function useUserRepoV2() {
|
|
|
48077
48262
|
}
|
|
48078
48263
|
]).toArray();
|
|
48079
48264
|
const length = await collection.countDocuments(query);
|
|
48080
|
-
const data = (0,
|
|
48265
|
+
const data = (0, import_node_server_utils220.paginate)(items, page, limit, length);
|
|
48081
48266
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
48082
|
-
|
|
48267
|
+
import_node_server_utils220.logger.info(`Cache set for key: ${cacheKey}`);
|
|
48083
48268
|
}).catch((err) => {
|
|
48084
|
-
|
|
48269
|
+
import_node_server_utils220.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
48085
48270
|
});
|
|
48086
48271
|
return data;
|
|
48087
48272
|
} catch (error) {
|
|
48088
|
-
|
|
48273
|
+
import_node_server_utils220.logger.log({ level: "error", message: `${error}` });
|
|
48089
48274
|
throw error;
|
|
48090
48275
|
}
|
|
48091
48276
|
}
|
|
@@ -48111,17 +48296,17 @@ function useUserRepoV2() {
|
|
|
48111
48296
|
cacheOptions.type = type;
|
|
48112
48297
|
}
|
|
48113
48298
|
delNamespace().then(
|
|
48114
|
-
() =>
|
|
48299
|
+
() => import_node_server_utils220.logger.info(`Cache cleared for namespace: ${namespace_collection}`)
|
|
48115
48300
|
).catch(
|
|
48116
|
-
(err) =>
|
|
48301
|
+
(err) => import_node_server_utils220.logger.error(
|
|
48117
48302
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
48118
48303
|
err
|
|
48119
48304
|
)
|
|
48120
48305
|
);
|
|
48121
|
-
const cacheKey = (0,
|
|
48306
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, cacheOptions);
|
|
48122
48307
|
const cachedData = await getCache(cacheKey);
|
|
48123
48308
|
if (cachedData) {
|
|
48124
|
-
|
|
48309
|
+
import_node_server_utils220.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
48125
48310
|
return cachedData;
|
|
48126
48311
|
}
|
|
48127
48312
|
try {
|
|
@@ -48133,19 +48318,19 @@ function useUserRepoV2() {
|
|
|
48133
48318
|
{ $project: { _id: 1, name: 1, email: 1, type: 1, status: 1 } }
|
|
48134
48319
|
]).toArray();
|
|
48135
48320
|
const length = await collection.countDocuments(query);
|
|
48136
|
-
const data = (0,
|
|
48137
|
-
setCache(cacheKey, data, 15 * 60).then(() =>
|
|
48138
|
-
(err) =>
|
|
48321
|
+
const data = (0, import_node_server_utils220.paginate)(items, page, limit, length);
|
|
48322
|
+
setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils220.logger.info(`Cache set for key: ${cacheKey}`)).catch(
|
|
48323
|
+
(err) => import_node_server_utils220.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
|
|
48139
48324
|
);
|
|
48140
48325
|
return data;
|
|
48141
48326
|
} catch (error) {
|
|
48142
|
-
|
|
48327
|
+
import_node_server_utils220.logger.log({ level: "error", message: `${error}` });
|
|
48143
48328
|
throw error;
|
|
48144
48329
|
}
|
|
48145
48330
|
}
|
|
48146
48331
|
async function updatePasswordById({ _id, password }, session) {
|
|
48147
|
-
const cacheKey = (0,
|
|
48148
|
-
_id = (0,
|
|
48332
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, { _id });
|
|
48333
|
+
_id = (0, import_node_server_utils220.toObjectId)(_id);
|
|
48149
48334
|
try {
|
|
48150
48335
|
const result = await collection.updateOne(
|
|
48151
48336
|
{ _id },
|
|
@@ -48153,13 +48338,13 @@ function useUserRepoV2() {
|
|
|
48153
48338
|
{ session }
|
|
48154
48339
|
);
|
|
48155
48340
|
delCache(cacheKey).then(() => {
|
|
48156
|
-
|
|
48341
|
+
import_node_server_utils220.logger.info(`Cache deleted for key: ${cacheKey}`);
|
|
48157
48342
|
}).catch((err) => {
|
|
48158
|
-
|
|
48343
|
+
import_node_server_utils220.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
48159
48344
|
});
|
|
48160
48345
|
return result;
|
|
48161
48346
|
} catch (error) {
|
|
48162
|
-
throw new
|
|
48347
|
+
throw new import_node_server_utils220.InternalServerError("Failed to update user password.");
|
|
48163
48348
|
}
|
|
48164
48349
|
}
|
|
48165
48350
|
async function updateUserFieldById({ _id, field, value } = {}, session) {
|
|
@@ -48174,20 +48359,20 @@ function useUserRepoV2() {
|
|
|
48174
48359
|
"defaultOrg"
|
|
48175
48360
|
];
|
|
48176
48361
|
if (!allowedFields.includes(field)) {
|
|
48177
|
-
throw new
|
|
48362
|
+
throw new import_node_server_utils220.BadRequestError(
|
|
48178
48363
|
`Field "${field}" is not allowed to be updated.`
|
|
48179
48364
|
);
|
|
48180
48365
|
}
|
|
48181
48366
|
try {
|
|
48182
|
-
_id = new
|
|
48367
|
+
_id = new import_mongodb125.ObjectId(_id);
|
|
48183
48368
|
} catch (error) {
|
|
48184
|
-
throw new
|
|
48369
|
+
throw new import_node_server_utils220.BadRequestError("Invalid ID.");
|
|
48185
48370
|
}
|
|
48186
48371
|
if (field === "defaultOrg") {
|
|
48187
48372
|
try {
|
|
48188
|
-
value = new
|
|
48373
|
+
value = new import_mongodb125.ObjectId(value);
|
|
48189
48374
|
} catch (error) {
|
|
48190
|
-
throw new
|
|
48375
|
+
throw new import_node_server_utils220.BadRequestError("Invalid organization ID.");
|
|
48191
48376
|
}
|
|
48192
48377
|
}
|
|
48193
48378
|
if (field === "name") {
|
|
@@ -48208,15 +48393,15 @@ function useUserRepoV2() {
|
|
|
48208
48393
|
// Dynamically set the field
|
|
48209
48394
|
{ session }
|
|
48210
48395
|
);
|
|
48211
|
-
const cacheKey = (0,
|
|
48396
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, { _id });
|
|
48212
48397
|
delCache(cacheKey).then(() => {
|
|
48213
|
-
|
|
48398
|
+
import_node_server_utils220.logger.info(`Cache deleted for key: ${cacheKey}`);
|
|
48214
48399
|
}).catch((err) => {
|
|
48215
|
-
|
|
48400
|
+
import_node_server_utils220.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
48216
48401
|
});
|
|
48217
48402
|
return `Successfully updated user ${field}.`;
|
|
48218
48403
|
} catch (error) {
|
|
48219
|
-
throw new
|
|
48404
|
+
throw new import_node_server_utils220.InternalServerError(`Failed to update user ${field}.`);
|
|
48220
48405
|
}
|
|
48221
48406
|
}
|
|
48222
48407
|
async function updateBirthday({
|
|
@@ -48226,9 +48411,9 @@ function useUserRepoV2() {
|
|
|
48226
48411
|
year
|
|
48227
48412
|
}, session) {
|
|
48228
48413
|
try {
|
|
48229
|
-
_id = new
|
|
48414
|
+
_id = new import_mongodb125.ObjectId(_id);
|
|
48230
48415
|
} catch (error) {
|
|
48231
|
-
throw new
|
|
48416
|
+
throw new import_node_server_utils220.BadRequestError("Invalid user ID format.");
|
|
48232
48417
|
}
|
|
48233
48418
|
try {
|
|
48234
48419
|
await collection.updateOne(
|
|
@@ -48243,22 +48428,22 @@ function useUserRepoV2() {
|
|
|
48243
48428
|
},
|
|
48244
48429
|
{ session }
|
|
48245
48430
|
);
|
|
48246
|
-
const cacheKey = (0,
|
|
48431
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, { _id });
|
|
48247
48432
|
delCache(cacheKey).then(() => {
|
|
48248
|
-
|
|
48433
|
+
import_node_server_utils220.logger.info(`Cache deleted for key: ${cacheKey}`);
|
|
48249
48434
|
}).catch((err) => {
|
|
48250
|
-
|
|
48435
|
+
import_node_server_utils220.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
48251
48436
|
});
|
|
48252
48437
|
return "Successfully updated user birthday.";
|
|
48253
48438
|
} catch (error) {
|
|
48254
|
-
throw new
|
|
48439
|
+
throw new import_node_server_utils220.InternalServerError("Failed to update user birthday.");
|
|
48255
48440
|
}
|
|
48256
48441
|
}
|
|
48257
48442
|
async function updatePassword({ _id, password }, session) {
|
|
48258
48443
|
try {
|
|
48259
|
-
_id = new
|
|
48444
|
+
_id = new import_mongodb125.ObjectId(_id);
|
|
48260
48445
|
} catch (error) {
|
|
48261
|
-
throw new
|
|
48446
|
+
throw new import_node_server_utils220.BadRequestError("Invalid user ID format.");
|
|
48262
48447
|
}
|
|
48263
48448
|
try {
|
|
48264
48449
|
const result = await collection.updateOne(
|
|
@@ -48266,15 +48451,15 @@ function useUserRepoV2() {
|
|
|
48266
48451
|
{ $set: { password, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
|
|
48267
48452
|
{ session }
|
|
48268
48453
|
);
|
|
48269
|
-
const cacheKey = (0,
|
|
48454
|
+
const cacheKey = (0, import_node_server_utils220.makeCacheKey)(namespace_collection, { _id });
|
|
48270
48455
|
delCache(cacheKey).then(() => {
|
|
48271
|
-
|
|
48456
|
+
import_node_server_utils220.logger.info(`Cache deleted for key: ${cacheKey}`);
|
|
48272
48457
|
}).catch((err) => {
|
|
48273
|
-
|
|
48458
|
+
import_node_server_utils220.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
|
|
48274
48459
|
});
|
|
48275
48460
|
return result;
|
|
48276
48461
|
} catch (error) {
|
|
48277
|
-
throw new
|
|
48462
|
+
throw new import_node_server_utils220.InternalServerError("Failed to update user password.");
|
|
48278
48463
|
}
|
|
48279
48464
|
}
|
|
48280
48465
|
return {
|
|
@@ -48298,7 +48483,7 @@ function useUserRepoV2() {
|
|
|
48298
48483
|
function useAuthServiceV2() {
|
|
48299
48484
|
const { getUserByEmail, getUserById: _getUserById } = useUserRepoV2();
|
|
48300
48485
|
const expiresIn = "15m";
|
|
48301
|
-
const { setCache, delCache } = (0,
|
|
48486
|
+
const { setCache, delCache } = (0, import_node_server_utils221.useCache)("sessions");
|
|
48302
48487
|
const { getByUserIdType } = useMemberRepo();
|
|
48303
48488
|
async function login({
|
|
48304
48489
|
email,
|
|
@@ -48309,26 +48494,26 @@ function useAuthServiceV2() {
|
|
|
48309
48494
|
try {
|
|
48310
48495
|
const user = await getUserByEmail(email);
|
|
48311
48496
|
if (!user) {
|
|
48312
|
-
throw new
|
|
48497
|
+
throw new import_node_server_utils221.NotFoundError(
|
|
48313
48498
|
"Invalid user email. Please check your email and try again."
|
|
48314
48499
|
);
|
|
48315
48500
|
}
|
|
48316
48501
|
if (!user._id) {
|
|
48317
|
-
throw new
|
|
48502
|
+
throw new import_node_server_utils221.InternalServerError("Valid user ID.");
|
|
48318
48503
|
}
|
|
48319
48504
|
if (user.status === "suspended") {
|
|
48320
|
-
throw new
|
|
48505
|
+
throw new import_node_server_utils221.BadRequestError(
|
|
48321
48506
|
"Your account is currently suspended. Please contact support for assistance."
|
|
48322
48507
|
);
|
|
48323
48508
|
}
|
|
48324
|
-
const isPasswordValid = await (0,
|
|
48509
|
+
const isPasswordValid = await (0, import_node_server_utils221.comparePassword)(password, user.password);
|
|
48325
48510
|
if (!isPasswordValid) {
|
|
48326
|
-
throw new
|
|
48511
|
+
throw new import_node_server_utils221.BadRequestError("Invalid password.");
|
|
48327
48512
|
}
|
|
48328
48513
|
if (isMobile) {
|
|
48329
48514
|
const member = await getByUserIdType(user._id, type);
|
|
48330
48515
|
if (!member) {
|
|
48331
|
-
throw new
|
|
48516
|
+
throw new import_node_server_utils221.BadRequestError("No member found.");
|
|
48332
48517
|
}
|
|
48333
48518
|
}
|
|
48334
48519
|
const sid = (0, import_uuid2.v4)();
|
|
@@ -48348,22 +48533,22 @@ function useAuthServiceV2() {
|
|
|
48348
48533
|
await delCache(`sid:${sid}`);
|
|
48349
48534
|
return "Session deleted successfully";
|
|
48350
48535
|
} catch (error) {
|
|
48351
|
-
throw new
|
|
48536
|
+
throw new import_node_server_utils221.InternalServerError("Error deleting token");
|
|
48352
48537
|
}
|
|
48353
48538
|
}
|
|
48354
48539
|
async function verifyPassword(_id, password) {
|
|
48355
48540
|
try {
|
|
48356
48541
|
const user = await _getUserById(_id);
|
|
48357
|
-
const isPasswordMatch = await (0,
|
|
48542
|
+
const isPasswordMatch = await (0, import_node_server_utils221.comparePassword)(password, user.password);
|
|
48358
48543
|
if (!isPasswordMatch) {
|
|
48359
|
-
throw new
|
|
48544
|
+
throw new import_node_server_utils221.BadRequestError("Invalid credentials");
|
|
48360
48545
|
}
|
|
48361
48546
|
return "Verification successful.";
|
|
48362
48547
|
} catch (error) {
|
|
48363
|
-
if (error instanceof
|
|
48548
|
+
if (error instanceof import_node_server_utils221.BadRequestError) {
|
|
48364
48549
|
throw error;
|
|
48365
48550
|
}
|
|
48366
|
-
throw new
|
|
48551
|
+
throw new import_node_server_utils221.InternalServerError("Error during password verification");
|
|
48367
48552
|
}
|
|
48368
48553
|
}
|
|
48369
48554
|
return {
|
|
@@ -48374,7 +48559,7 @@ function useAuthServiceV2() {
|
|
|
48374
48559
|
}
|
|
48375
48560
|
|
|
48376
48561
|
// src/services/user-v2.service.ts
|
|
48377
|
-
var
|
|
48562
|
+
var import_node_server_utils222 = require("@7365admin1/node-server-utils");
|
|
48378
48563
|
var import_multer2 = require("multer");
|
|
48379
48564
|
function useUserServiceV2() {
|
|
48380
48565
|
const {
|
|
@@ -48399,23 +48584,23 @@ function useUserServiceV2() {
|
|
|
48399
48584
|
id = "",
|
|
48400
48585
|
name = ""
|
|
48401
48586
|
}) {
|
|
48402
|
-
const session =
|
|
48587
|
+
const session = import_node_server_utils222.useAtlas.getClient()?.startSession();
|
|
48403
48588
|
session?.startTransaction();
|
|
48404
48589
|
try {
|
|
48405
48590
|
const signUp = await _getVerificationById(id);
|
|
48406
48591
|
if (!signUp)
|
|
48407
|
-
throw new
|
|
48592
|
+
throw new import_node_server_utils222.BadRequestError("Invalid sign up link.");
|
|
48408
48593
|
if (signUp.status === "complete" /* COMPLETE */)
|
|
48409
|
-
throw new
|
|
48594
|
+
throw new import_node_server_utils222.BadRequestError(
|
|
48410
48595
|
"You have already an account created using this link."
|
|
48411
48596
|
);
|
|
48412
48597
|
const expired = signUp.expireAt < (/* @__PURE__ */ new Date()).toISOString();
|
|
48413
48598
|
if (signUp.status === "expired" || expired)
|
|
48414
|
-
throw new
|
|
48599
|
+
throw new import_node_server_utils222.BadRequestError("Sign up link expired.");
|
|
48415
48600
|
const email = signUp.email;
|
|
48416
48601
|
const _user = await _getUserByEmail(email);
|
|
48417
48602
|
if (_user)
|
|
48418
|
-
throw new
|
|
48603
|
+
throw new import_node_server_utils222.BadRequestError(`User already exists: ${email}.`);
|
|
48419
48604
|
let org = null;
|
|
48420
48605
|
if (signUp.metadata?.org) {
|
|
48421
48606
|
org = await getOrgById(signUp.metadata.org);
|
|
@@ -48462,30 +48647,30 @@ function useUserServiceV2() {
|
|
|
48462
48647
|
}
|
|
48463
48648
|
async function resetPassword(id, newPassword, passwordConfirmation) {
|
|
48464
48649
|
if (newPassword !== passwordConfirmation) {
|
|
48465
|
-
throw new
|
|
48650
|
+
throw new import_node_server_utils222.BadRequestError("Passwords do not match.");
|
|
48466
48651
|
}
|
|
48467
48652
|
let hashedPassword;
|
|
48468
|
-
const session =
|
|
48653
|
+
const session = import_node_server_utils222.useAtlas.getClient()?.startSession();
|
|
48469
48654
|
session?.startTransaction();
|
|
48470
48655
|
try {
|
|
48471
|
-
hashedPassword = await (0,
|
|
48656
|
+
hashedPassword = await (0, import_node_server_utils222.hashPassword)(newPassword);
|
|
48472
48657
|
} catch (error) {
|
|
48473
|
-
throw new
|
|
48658
|
+
throw new import_node_server_utils222.InternalServerError(`Error hashing password: ${error}`);
|
|
48474
48659
|
}
|
|
48475
48660
|
try {
|
|
48476
48661
|
const otpDoc = await _getVerificationById(id);
|
|
48477
48662
|
if (!otpDoc) {
|
|
48478
|
-
throw new
|
|
48663
|
+
throw new import_node_server_utils222.NotFoundError("You are using an invalid reset link.");
|
|
48479
48664
|
}
|
|
48480
48665
|
if (otpDoc.status === "complete" /* COMPLETE */) {
|
|
48481
|
-
throw new
|
|
48666
|
+
throw new import_node_server_utils222.BadRequestError("This link has already been invalidated.");
|
|
48482
48667
|
}
|
|
48483
48668
|
const user = await _getUserByEmail(otpDoc.email);
|
|
48484
48669
|
if (!user) {
|
|
48485
|
-
throw new
|
|
48670
|
+
throw new import_node_server_utils222.NotFoundError("User not found.");
|
|
48486
48671
|
}
|
|
48487
48672
|
if (!user._id) {
|
|
48488
|
-
throw new
|
|
48673
|
+
throw new import_node_server_utils222.InternalServerError("Invalid user ID.");
|
|
48489
48674
|
}
|
|
48490
48675
|
await Promise.all([
|
|
48491
48676
|
_updateVerificationStatusById(id, "complete" /* COMPLETE */, session),
|
|
@@ -48503,7 +48688,7 @@ function useUserServiceV2() {
|
|
|
48503
48688
|
session?.endSession();
|
|
48504
48689
|
}
|
|
48505
48690
|
}
|
|
48506
|
-
const s3 = new
|
|
48691
|
+
const s3 = new import_node_server_utils222.useS3({
|
|
48507
48692
|
accessKeyId: SPACES_ACCESS_KEY,
|
|
48508
48693
|
secretAccessKey: SPACES_SECRET_KEY,
|
|
48509
48694
|
endpoint: SPACES_ENDPOINT,
|
|
@@ -48516,7 +48701,7 @@ function useUserServiceV2() {
|
|
|
48516
48701
|
user,
|
|
48517
48702
|
previousProfile
|
|
48518
48703
|
}) {
|
|
48519
|
-
const session =
|
|
48704
|
+
const session = import_node_server_utils222.useAtlas.getClient()?.startSession();
|
|
48520
48705
|
session?.startTransaction();
|
|
48521
48706
|
const _file = {
|
|
48522
48707
|
name: file.originalname,
|
|
@@ -48549,18 +48734,18 @@ function useUserServiceV2() {
|
|
|
48549
48734
|
async function updatePasswordById(id, currentPassword, newPassword, passwordConfirmation) {
|
|
48550
48735
|
let hashedPassword;
|
|
48551
48736
|
const user = await getUserById(id);
|
|
48552
|
-
const isPasswordValid = await (0,
|
|
48737
|
+
const isPasswordValid = await (0, import_node_server_utils222.comparePassword)(
|
|
48553
48738
|
currentPassword,
|
|
48554
48739
|
user.password
|
|
48555
48740
|
);
|
|
48556
48741
|
if (!isPasswordValid)
|
|
48557
|
-
throw new
|
|
48742
|
+
throw new import_node_server_utils222.BadRequestError("Invalid current password.");
|
|
48558
48743
|
if (newPassword !== passwordConfirmation)
|
|
48559
|
-
throw new
|
|
48744
|
+
throw new import_node_server_utils222.BadRequestError("Passwords do not match.");
|
|
48560
48745
|
try {
|
|
48561
|
-
hashedPassword = await (0,
|
|
48746
|
+
hashedPassword = await (0, import_node_server_utils222.hashPassword)(newPassword);
|
|
48562
48747
|
if (!hashedPassword)
|
|
48563
|
-
throw new
|
|
48748
|
+
throw new import_node_server_utils222.InternalServerError("Error hashing password.");
|
|
48564
48749
|
return await updatePassword({ _id: id, password: hashedPassword });
|
|
48565
48750
|
} catch (error) {
|
|
48566
48751
|
throw error;
|
|
@@ -48596,8 +48781,8 @@ function useAuthControllerV2() {
|
|
|
48596
48781
|
});
|
|
48597
48782
|
if (error) {
|
|
48598
48783
|
const messages = error.details.map((d) => d.message);
|
|
48599
|
-
|
|
48600
|
-
next(new
|
|
48784
|
+
import_node_server_utils223.logger.log({ level: "error", message: messages.join(", ") });
|
|
48785
|
+
next(new import_node_server_utils223.BadRequestError(messages.join(", ")));
|
|
48601
48786
|
return;
|
|
48602
48787
|
}
|
|
48603
48788
|
const { email, password, country, orgName } = value;
|
|
@@ -48613,7 +48798,7 @@ function useAuthControllerV2() {
|
|
|
48613
48798
|
return;
|
|
48614
48799
|
} catch (error) {
|
|
48615
48800
|
console.log(error);
|
|
48616
|
-
|
|
48801
|
+
import_node_server_utils223.logger.log({ level: "error", message: error.message });
|
|
48617
48802
|
next(error);
|
|
48618
48803
|
return;
|
|
48619
48804
|
}
|
|
@@ -48631,8 +48816,8 @@ function useAuthControllerV2() {
|
|
|
48631
48816
|
});
|
|
48632
48817
|
if (error) {
|
|
48633
48818
|
const messages = error.details.map((d) => d.message);
|
|
48634
|
-
|
|
48635
|
-
next(new
|
|
48819
|
+
import_node_server_utils223.logger.log({ level: "error", message: messages.join(", ") });
|
|
48820
|
+
next(new import_node_server_utils223.BadRequestError(messages.join(", ")));
|
|
48636
48821
|
return;
|
|
48637
48822
|
}
|
|
48638
48823
|
const session = await _login(value);
|
|
@@ -48644,7 +48829,7 @@ function useAuthControllerV2() {
|
|
|
48644
48829
|
res.cookie("sid", session.sid, cookieOptions).cookie("user", session.user, cookieOptions).json(session);
|
|
48645
48830
|
return;
|
|
48646
48831
|
} catch (error) {
|
|
48647
|
-
|
|
48832
|
+
import_node_server_utils223.logger.log({ level: "error", message: error.message });
|
|
48648
48833
|
next(error);
|
|
48649
48834
|
return;
|
|
48650
48835
|
}
|
|
@@ -48652,7 +48837,7 @@ function useAuthControllerV2() {
|
|
|
48652
48837
|
async function logout(req, res, next) {
|
|
48653
48838
|
const sid = req.headers["authorization"] ?? "";
|
|
48654
48839
|
if (!sid) {
|
|
48655
|
-
next(new
|
|
48840
|
+
next(new import_node_server_utils223.BadRequestError("Session ID is required"));
|
|
48656
48841
|
return;
|
|
48657
48842
|
}
|
|
48658
48843
|
try {
|
|
@@ -48660,7 +48845,7 @@ function useAuthControllerV2() {
|
|
|
48660
48845
|
res.json({ message: "Logged out successfully" });
|
|
48661
48846
|
return;
|
|
48662
48847
|
} catch (error) {
|
|
48663
|
-
|
|
48848
|
+
import_node_server_utils223.logger.log({ level: "error", message: error.message });
|
|
48664
48849
|
next(error);
|
|
48665
48850
|
return;
|
|
48666
48851
|
}
|
|
@@ -48676,8 +48861,8 @@ function useAuthControllerV2() {
|
|
|
48676
48861
|
});
|
|
48677
48862
|
if (error) {
|
|
48678
48863
|
const messages = error.details.map((d) => d.message);
|
|
48679
|
-
|
|
48680
|
-
next(new
|
|
48864
|
+
import_node_server_utils223.logger.log({ level: "error", message: messages.join(", ") });
|
|
48865
|
+
next(new import_node_server_utils223.BadRequestError(messages.join(", ")));
|
|
48681
48866
|
return;
|
|
48682
48867
|
}
|
|
48683
48868
|
const { otp, newPassword, passwordConfirmation } = value;
|
|
@@ -48690,7 +48875,7 @@ function useAuthControllerV2() {
|
|
|
48690
48875
|
res.json({ message });
|
|
48691
48876
|
return;
|
|
48692
48877
|
} catch (error2) {
|
|
48693
|
-
|
|
48878
|
+
import_node_server_utils223.logger.log({ level: "error", message: error2.message });
|
|
48694
48879
|
next(error2);
|
|
48695
48880
|
return;
|
|
48696
48881
|
}
|
|
@@ -48706,8 +48891,8 @@ function useAuthControllerV2() {
|
|
|
48706
48891
|
);
|
|
48707
48892
|
if (error) {
|
|
48708
48893
|
const messages = error.details.map((d) => d.message);
|
|
48709
|
-
|
|
48710
|
-
next(new
|
|
48894
|
+
import_node_server_utils223.logger.log({ level: "error", message: messages.join(", ") });
|
|
48895
|
+
next(new import_node_server_utils223.BadRequestError(messages.join(", ")));
|
|
48711
48896
|
return;
|
|
48712
48897
|
}
|
|
48713
48898
|
const { _id, password } = value;
|
|
@@ -48716,7 +48901,7 @@ function useAuthControllerV2() {
|
|
|
48716
48901
|
res.json({ message });
|
|
48717
48902
|
return;
|
|
48718
48903
|
} catch (error2) {
|
|
48719
|
-
|
|
48904
|
+
import_node_server_utils223.logger.log({ level: "error", message: error2.message });
|
|
48720
48905
|
next(error2);
|
|
48721
48906
|
return;
|
|
48722
48907
|
}
|
|
@@ -48733,7 +48918,7 @@ function useAuthControllerV2() {
|
|
|
48733
48918
|
// src/controllers/user-v2.controller.ts
|
|
48734
48919
|
var import_joi128 = __toESM(require("joi"));
|
|
48735
48920
|
var import_multer3 = require("multer");
|
|
48736
|
-
var
|
|
48921
|
+
var import_node_server_utils224 = require("@7365admin1/node-server-utils");
|
|
48737
48922
|
function useUserControllerV2() {
|
|
48738
48923
|
const {
|
|
48739
48924
|
updateBirthday: _updateBirthday,
|
|
@@ -48747,16 +48932,16 @@ function useUserControllerV2() {
|
|
|
48747
48932
|
const { createUserBySignUp, updateUserProfile: _updateUserProfile, updatePasswordById: _updatePasswordById } = useUserServiceV2();
|
|
48748
48933
|
function rejectValidation(error, next) {
|
|
48749
48934
|
const message = error.details.map((d) => d.message).join(", ");
|
|
48750
|
-
|
|
48751
|
-
next(new
|
|
48935
|
+
import_node_server_utils224.logger.log({ level: "error", message });
|
|
48936
|
+
next(new import_node_server_utils224.BadRequestError(message));
|
|
48752
48937
|
}
|
|
48753
48938
|
async function getById(req, res, next) {
|
|
48754
48939
|
const validation = import_joi128.default.string().hex().required();
|
|
48755
48940
|
const _id = req.params.id;
|
|
48756
48941
|
const { error, value } = validation.validate(_id);
|
|
48757
48942
|
if (error) {
|
|
48758
|
-
|
|
48759
|
-
next(new
|
|
48943
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error.message}` });
|
|
48944
|
+
next(new import_node_server_utils224.BadRequestError(error.message));
|
|
48760
48945
|
return;
|
|
48761
48946
|
}
|
|
48762
48947
|
try {
|
|
@@ -48764,7 +48949,7 @@ function useUserControllerV2() {
|
|
|
48764
48949
|
res.json(user);
|
|
48765
48950
|
return;
|
|
48766
48951
|
} catch (error2) {
|
|
48767
|
-
|
|
48952
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error2.message}` });
|
|
48768
48953
|
next(error2);
|
|
48769
48954
|
return;
|
|
48770
48955
|
}
|
|
@@ -48778,7 +48963,7 @@ function useUserControllerV2() {
|
|
|
48778
48963
|
res.json(user);
|
|
48779
48964
|
return;
|
|
48780
48965
|
} catch (err) {
|
|
48781
|
-
|
|
48966
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${err.message}` });
|
|
48782
48967
|
next(err);
|
|
48783
48968
|
return;
|
|
48784
48969
|
}
|
|
@@ -48845,8 +49030,8 @@ function useUserControllerV2() {
|
|
|
48845
49030
|
const payload = { ...req.body };
|
|
48846
49031
|
const { error, value } = validation.validate({ id, ...payload });
|
|
48847
49032
|
if (error) {
|
|
48848
|
-
|
|
48849
|
-
next(new
|
|
49033
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error.message}` });
|
|
49034
|
+
next(new import_node_server_utils224.BadRequestError(error.message));
|
|
48850
49035
|
return;
|
|
48851
49036
|
}
|
|
48852
49037
|
try {
|
|
@@ -48854,14 +49039,14 @@ function useUserControllerV2() {
|
|
|
48854
49039
|
res.status(201).json({ message: "Successfully created account." });
|
|
48855
49040
|
return;
|
|
48856
49041
|
} catch (error2) {
|
|
48857
|
-
|
|
49042
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error2.message}` });
|
|
48858
49043
|
next(error2);
|
|
48859
49044
|
return;
|
|
48860
49045
|
}
|
|
48861
49046
|
}
|
|
48862
49047
|
async function updateUserProfile(req, res, next) {
|
|
48863
49048
|
if (!req.file) {
|
|
48864
|
-
next(new
|
|
49049
|
+
next(new import_node_server_utils224.BadRequestError("File is required!"));
|
|
48865
49050
|
return;
|
|
48866
49051
|
}
|
|
48867
49052
|
const validation = import_joi128.default.object({
|
|
@@ -48870,8 +49055,8 @@ function useUserControllerV2() {
|
|
|
48870
49055
|
const payload = { ...req.body };
|
|
48871
49056
|
const { error, value } = validation.validate(payload);
|
|
48872
49057
|
if (error) {
|
|
48873
|
-
|
|
48874
|
-
next(new
|
|
49058
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error.message}` });
|
|
49059
|
+
next(new import_node_server_utils224.BadRequestError(error.message));
|
|
48875
49060
|
return;
|
|
48876
49061
|
}
|
|
48877
49062
|
const user = req.headers.user ?? "";
|
|
@@ -48884,7 +49069,7 @@ function useUserControllerV2() {
|
|
|
48884
49069
|
res.json({ message: "Successfully updated profile picture." });
|
|
48885
49070
|
return;
|
|
48886
49071
|
} catch (error2) {
|
|
48887
|
-
|
|
49072
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error2.message}` });
|
|
48888
49073
|
next(error2);
|
|
48889
49074
|
return;
|
|
48890
49075
|
}
|
|
@@ -48914,8 +49099,8 @@ function useUserControllerV2() {
|
|
|
48914
49099
|
const payload = { ...req.body };
|
|
48915
49100
|
const { error } = validation.validate({ _id, ...payload });
|
|
48916
49101
|
if (error) {
|
|
48917
|
-
|
|
48918
|
-
next(new
|
|
49102
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error.message}` });
|
|
49103
|
+
next(new import_node_server_utils224.BadRequestError(error.message));
|
|
48919
49104
|
return;
|
|
48920
49105
|
}
|
|
48921
49106
|
try {
|
|
@@ -48923,7 +49108,7 @@ function useUserControllerV2() {
|
|
|
48923
49108
|
res.json({ message });
|
|
48924
49109
|
return;
|
|
48925
49110
|
} catch (error2) {
|
|
48926
|
-
|
|
49111
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error2.message}` });
|
|
48927
49112
|
next(error2);
|
|
48928
49113
|
return;
|
|
48929
49114
|
}
|
|
@@ -48945,8 +49130,8 @@ function useUserControllerV2() {
|
|
|
48945
49130
|
const payload = { ...req.body };
|
|
48946
49131
|
const { error } = validation.validate({ _id, ...payload });
|
|
48947
49132
|
if (error) {
|
|
48948
|
-
|
|
48949
|
-
next(new
|
|
49133
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error.message}` });
|
|
49134
|
+
next(new import_node_server_utils224.BadRequestError(error.message));
|
|
48950
49135
|
return;
|
|
48951
49136
|
}
|
|
48952
49137
|
try {
|
|
@@ -48954,7 +49139,7 @@ function useUserControllerV2() {
|
|
|
48954
49139
|
res.json({ message });
|
|
48955
49140
|
return;
|
|
48956
49141
|
} catch (error2) {
|
|
48957
|
-
|
|
49142
|
+
import_node_server_utils224.logger.log({ level: "error", message: `${error2.message}` });
|
|
48958
49143
|
next(error2);
|
|
48959
49144
|
return;
|
|
48960
49145
|
}
|
|
@@ -48973,7 +49158,7 @@ function useUserControllerV2() {
|
|
|
48973
49158
|
...payload
|
|
48974
49159
|
});
|
|
48975
49160
|
if (error) {
|
|
48976
|
-
next(new
|
|
49161
|
+
next(new import_node_server_utils224.BadRequestError(error.message));
|
|
48977
49162
|
return;
|
|
48978
49163
|
}
|
|
48979
49164
|
const currentPassword = req.body.currentPassword ?? "";
|
|
@@ -49003,10 +49188,177 @@ function useUserControllerV2() {
|
|
|
49003
49188
|
updatePasswordById
|
|
49004
49189
|
};
|
|
49005
49190
|
}
|
|
49191
|
+
|
|
49192
|
+
// src/models/role-v2.model.ts
|
|
49193
|
+
var import_node_server_utils225 = require("@7365admin1/node-server-utils");
|
|
49194
|
+
var import_mongodb126 = require("mongodb");
|
|
49195
|
+
var MRoleV2 = class {
|
|
49196
|
+
constructor(value) {
|
|
49197
|
+
if (typeof value._id === "string") {
|
|
49198
|
+
try {
|
|
49199
|
+
value._id = new import_mongodb126.ObjectId(value._id);
|
|
49200
|
+
} catch (error) {
|
|
49201
|
+
throw new import_node_server_utils225.BadRequestError("Invalid role-v2 ID format.");
|
|
49202
|
+
}
|
|
49203
|
+
}
|
|
49204
|
+
if (typeof value.site === "string" && value.site.length === 24) {
|
|
49205
|
+
try {
|
|
49206
|
+
value.site = new import_mongodb126.ObjectId(value.site);
|
|
49207
|
+
} catch (error) {
|
|
49208
|
+
throw new import_node_server_utils225.BadRequestError("Invalid site ID format.");
|
|
49209
|
+
}
|
|
49210
|
+
}
|
|
49211
|
+
if (typeof value.org === "string" && value.org.length === 24) {
|
|
49212
|
+
try {
|
|
49213
|
+
value.org = new import_mongodb126.ObjectId(value.org);
|
|
49214
|
+
} catch (error) {
|
|
49215
|
+
throw new import_node_server_utils225.BadRequestError("Invalid org ID format.");
|
|
49216
|
+
}
|
|
49217
|
+
}
|
|
49218
|
+
if (value.createdBy) {
|
|
49219
|
+
try {
|
|
49220
|
+
value.createdBy = new import_mongodb126.ObjectId(value.createdBy);
|
|
49221
|
+
} catch (error) {
|
|
49222
|
+
throw new import_node_server_utils225.BadRequestError("Invalid created by ID format.");
|
|
49223
|
+
}
|
|
49224
|
+
}
|
|
49225
|
+
this._id = value._id ?? new import_mongodb126.ObjectId();
|
|
49226
|
+
this.name = value.name ?? "";
|
|
49227
|
+
this.permissions = value.permissions ?? [];
|
|
49228
|
+
this.site = value.site ?? "";
|
|
49229
|
+
this.platform = value.platform ?? "";
|
|
49230
|
+
this.type = value.type ?? "account";
|
|
49231
|
+
this.org = value.org ?? "";
|
|
49232
|
+
this.status = value.status ?? "active";
|
|
49233
|
+
this.createdBy = value.createdBy ?? "";
|
|
49234
|
+
this.createdAt = value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
49235
|
+
this.updatedAt = value.updatedAt ?? "";
|
|
49236
|
+
this.deletedAt = value.deletedAt ?? "";
|
|
49237
|
+
}
|
|
49238
|
+
};
|
|
49239
|
+
|
|
49240
|
+
// src/repositories/role-v2.repo.ts
|
|
49241
|
+
var import_node_server_utils226 = require("@7365admin1/node-server-utils");
|
|
49242
|
+
function useRoleRepoV2() {
|
|
49243
|
+
const db = import_node_server_utils226.useAtlas.getDb();
|
|
49244
|
+
if (!db) {
|
|
49245
|
+
throw new import_node_server_utils226.InternalServerError("Unable to connect to server.");
|
|
49246
|
+
}
|
|
49247
|
+
const namespace_collection = "roles.v2";
|
|
49248
|
+
const collection = db.collection(namespace_collection);
|
|
49249
|
+
async function createIndex() {
|
|
49250
|
+
try {
|
|
49251
|
+
await collection.createIndexes([
|
|
49252
|
+
{ key: { name: 1 } },
|
|
49253
|
+
{ key: { type: 1 } },
|
|
49254
|
+
{ key: { status: 1 } }
|
|
49255
|
+
]);
|
|
49256
|
+
} catch (error) {
|
|
49257
|
+
throw new import_node_server_utils226.InternalServerError("Failed to create index on role.");
|
|
49258
|
+
}
|
|
49259
|
+
}
|
|
49260
|
+
async function createTextIndex() {
|
|
49261
|
+
try {
|
|
49262
|
+
await collection.createIndex({ name: "text" });
|
|
49263
|
+
} catch (error) {
|
|
49264
|
+
throw new import_node_server_utils226.InternalServerError("Failed to create text index on role.");
|
|
49265
|
+
}
|
|
49266
|
+
}
|
|
49267
|
+
async function createUniqueIndex() {
|
|
49268
|
+
try {
|
|
49269
|
+
await collection.createIndex(
|
|
49270
|
+
{ name: 1, site: 1, platform: 1, type: 1, org: 1, deletedAt: 1 },
|
|
49271
|
+
{ unique: true }
|
|
49272
|
+
);
|
|
49273
|
+
} catch (error) {
|
|
49274
|
+
throw new import_node_server_utils226.InternalServerError("Failed to create unique index on role.");
|
|
49275
|
+
}
|
|
49276
|
+
}
|
|
49277
|
+
const { delNamespace } = (0, import_node_server_utils226.useCache)(namespace_collection);
|
|
49278
|
+
async function addRole(value, session) {
|
|
49279
|
+
value = new MRoleV2(value);
|
|
49280
|
+
try {
|
|
49281
|
+
const res = await collection.insertOne(value, { session });
|
|
49282
|
+
delNamespace().then(() => {
|
|
49283
|
+
import_node_server_utils226.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
49284
|
+
}).catch((err) => {
|
|
49285
|
+
import_node_server_utils226.logger.error(
|
|
49286
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
49287
|
+
err
|
|
49288
|
+
);
|
|
49289
|
+
});
|
|
49290
|
+
return res.insertedId;
|
|
49291
|
+
} catch (error) {
|
|
49292
|
+
import_node_server_utils226.logger.log({ level: "error", message: `${error}` });
|
|
49293
|
+
const isDuplicated = error.message.includes("duplicate");
|
|
49294
|
+
if (isDuplicated) {
|
|
49295
|
+
throw new import_node_server_utils226.BadRequestError("Role already exists.");
|
|
49296
|
+
}
|
|
49297
|
+
throw new import_node_server_utils226.InternalServerError("Failed to create role.");
|
|
49298
|
+
}
|
|
49299
|
+
}
|
|
49300
|
+
return {
|
|
49301
|
+
createIndex,
|
|
49302
|
+
createTextIndex,
|
|
49303
|
+
createUniqueIndex,
|
|
49304
|
+
addRole
|
|
49305
|
+
};
|
|
49306
|
+
}
|
|
49307
|
+
|
|
49308
|
+
// src/services/role-v2.service.ts
|
|
49309
|
+
function useRoleServiceV2() {
|
|
49310
|
+
const { addRole: _addRole } = useRoleRepoV2();
|
|
49311
|
+
async function createRole(value) {
|
|
49312
|
+
try {
|
|
49313
|
+
return await _addRole(value);
|
|
49314
|
+
} catch (error) {
|
|
49315
|
+
throw error;
|
|
49316
|
+
}
|
|
49317
|
+
}
|
|
49318
|
+
return { createRole };
|
|
49319
|
+
}
|
|
49320
|
+
|
|
49321
|
+
// src/controllers/role-v2.controller.ts
|
|
49322
|
+
var import_joi129 = __toESM(require("joi"));
|
|
49323
|
+
var import_node_server_utils227 = require("@7365admin1/node-server-utils");
|
|
49324
|
+
function useRoleControllerV2() {
|
|
49325
|
+
const { createRole: _createRole } = useRoleServiceV2();
|
|
49326
|
+
async function createRole(req, res, next) {
|
|
49327
|
+
const validation = import_joi129.default.object({
|
|
49328
|
+
name: import_joi129.default.string().required(),
|
|
49329
|
+
site: import_joi129.default.string().hex().required(),
|
|
49330
|
+
platform: import_joi129.default.string().required(),
|
|
49331
|
+
permissions: import_joi129.default.array().items(import_joi129.default.string()).required(),
|
|
49332
|
+
type: import_joi129.default.string().optional().allow("", null),
|
|
49333
|
+
org: import_joi129.default.string().hex().optional().allow("", null)
|
|
49334
|
+
});
|
|
49335
|
+
const payload = { ...req.body };
|
|
49336
|
+
const { error, value } = validation.validate(payload, { abortEarly: false });
|
|
49337
|
+
if (error) {
|
|
49338
|
+
const message = error.details.map((item) => item.message).join(", ");
|
|
49339
|
+
import_node_server_utils227.logger.log({ level: "error", message });
|
|
49340
|
+
next(new import_node_server_utils227.BadRequestError(message));
|
|
49341
|
+
return;
|
|
49342
|
+
}
|
|
49343
|
+
try {
|
|
49344
|
+
const role = await _createRole(value);
|
|
49345
|
+
res.status(201).json({ message: "Successfully created role.", data: { role } });
|
|
49346
|
+
return;
|
|
49347
|
+
} catch (error2) {
|
|
49348
|
+
import_node_server_utils227.logger.log({ level: "error", message: error2.message });
|
|
49349
|
+
next(error2);
|
|
49350
|
+
return;
|
|
49351
|
+
}
|
|
49352
|
+
}
|
|
49353
|
+
return {
|
|
49354
|
+
createRole
|
|
49355
|
+
};
|
|
49356
|
+
}
|
|
49006
49357
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49007
49358
|
0 && (module.exports = {
|
|
49008
49359
|
ANPRMode,
|
|
49009
49360
|
AccessTypeProps,
|
|
49361
|
+
AppServiceType,
|
|
49010
49362
|
BuildingStatus,
|
|
49011
49363
|
BulletinRecipient,
|
|
49012
49364
|
BulletinSort,
|
|
@@ -49067,6 +49419,7 @@ function useUserControllerV2() {
|
|
|
49067
49419
|
MPromoCode,
|
|
49068
49420
|
MRobot,
|
|
49069
49421
|
MRole,
|
|
49422
|
+
MRoleV2,
|
|
49070
49423
|
MServiceProvider,
|
|
49071
49424
|
MServiceProviderBilling,
|
|
49072
49425
|
MSession,
|
|
@@ -49089,6 +49442,7 @@ function useUserControllerV2() {
|
|
|
49089
49442
|
OvernightParkingRequestStatus,
|
|
49090
49443
|
PERSON_TYPES,
|
|
49091
49444
|
PMDashboardCollection,
|
|
49445
|
+
PStatus,
|
|
49092
49446
|
Period,
|
|
49093
49447
|
PersonStatus,
|
|
49094
49448
|
PersonTypes,
|
|
@@ -49096,6 +49450,7 @@ function useUserControllerV2() {
|
|
|
49096
49450
|
SiteStatus,
|
|
49097
49451
|
SortFields,
|
|
49098
49452
|
SortOrder,
|
|
49453
|
+
Status,
|
|
49099
49454
|
SubscriptionType,
|
|
49100
49455
|
UseAccessManagementRepo,
|
|
49101
49456
|
UserStatus,
|
|
@@ -49350,7 +49705,10 @@ function useUserControllerV2() {
|
|
|
49350
49705
|
useRobotRepo,
|
|
49351
49706
|
useRobotService,
|
|
49352
49707
|
useRoleController,
|
|
49708
|
+
useRoleControllerV2,
|
|
49353
49709
|
useRoleRepo,
|
|
49710
|
+
useRoleRepoV2,
|
|
49711
|
+
useRoleServiceV2,
|
|
49354
49712
|
useServiceProviderBillingController,
|
|
49355
49713
|
useServiceProviderBillingRepo,
|
|
49356
49714
|
useServiceProviderBillingService,
|