@7365admin1/core 2.12.0 → 2.13.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 +6 -0
- package/dist/index.d.ts +43 -4
- package/dist/index.js +582 -117
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +582 -117
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -4759,7 +4759,8 @@ function useMemberRepo() {
|
|
|
4759
4759
|
try {
|
|
4760
4760
|
const data = await collection.find({
|
|
4761
4761
|
role: { $in: roles },
|
|
4762
|
-
type,
|
|
4762
|
+
// type,
|
|
4763
|
+
// ...(type && { type }),
|
|
4763
4764
|
status: "active"
|
|
4764
4765
|
}).toArray();
|
|
4765
4766
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
@@ -6880,7 +6881,7 @@ function useMemberService() {
|
|
|
6880
6881
|
throw new BadRequestError29("No owner role found.");
|
|
6881
6882
|
}
|
|
6882
6883
|
const roles = owner.map((r) => r._id?.toString() ?? "");
|
|
6883
|
-
const ownerMembers = await getByRoles(roles, type);
|
|
6884
|
+
const ownerMembers = await getByRoles(roles, type = "");
|
|
6884
6885
|
if (!ownerMembers.length) {
|
|
6885
6886
|
throw new BadRequestError29("No owner members found.");
|
|
6886
6887
|
}
|
|
@@ -14674,7 +14675,7 @@ function MPerson(value) {
|
|
|
14674
14675
|
return {
|
|
14675
14676
|
_id: value._id,
|
|
14676
14677
|
name: value.name,
|
|
14677
|
-
contact: value.contact,
|
|
14678
|
+
contact: value.contact ?? "",
|
|
14678
14679
|
block: value.block,
|
|
14679
14680
|
level: value.level,
|
|
14680
14681
|
unit: value.unit,
|
|
@@ -15136,7 +15137,8 @@ function usePersonRepo() {
|
|
|
15136
15137
|
$or: [
|
|
15137
15138
|
{ name: { $regex: search, $options: "i" } },
|
|
15138
15139
|
{ email: { $regex: search, $options: "i" } },
|
|
15139
|
-
{ nric: { $regex: search, $options: "i" } }
|
|
15140
|
+
{ nric: { $regex: search, $options: "i" } },
|
|
15141
|
+
{ "plates.plateNumber": { $regex: search, $options: "i" } }
|
|
15140
15142
|
]
|
|
15141
15143
|
},
|
|
15142
15144
|
...ObjectId44.isValid(org) && { org: new ObjectId44(org) },
|
|
@@ -18561,7 +18563,7 @@ function useVisitorTransactionService() {
|
|
|
18561
18563
|
} else {
|
|
18562
18564
|
const payload = {
|
|
18563
18565
|
name: value.name || "",
|
|
18564
|
-
contact: value.contact,
|
|
18566
|
+
contact: value.contact ?? "",
|
|
18565
18567
|
nric,
|
|
18566
18568
|
type: value.type,
|
|
18567
18569
|
companyName: value.company ? [value.company] : [],
|
|
@@ -23717,16 +23719,26 @@ function useDocumentManagementRepo() {
|
|
|
23717
23719
|
site = ""
|
|
23718
23720
|
}) {
|
|
23719
23721
|
page = page > 0 ? page - 1 : 0;
|
|
23722
|
+
try {
|
|
23723
|
+
site = new ObjectId70(site);
|
|
23724
|
+
} catch (error) {
|
|
23725
|
+
throw new BadRequestError119("Invalid site ID format.");
|
|
23726
|
+
}
|
|
23720
23727
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
23721
23728
|
const cacheOptions = {
|
|
23722
23729
|
page,
|
|
23723
23730
|
limit,
|
|
23724
23731
|
status,
|
|
23732
|
+
site: site?.toString(),
|
|
23725
23733
|
sort: JSON.stringify(sort)
|
|
23726
23734
|
};
|
|
23727
23735
|
const query = {
|
|
23728
23736
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
|
|
23729
23737
|
};
|
|
23738
|
+
if (site) {
|
|
23739
|
+
query.site = site;
|
|
23740
|
+
cacheOptions.site = site;
|
|
23741
|
+
}
|
|
23730
23742
|
if (search) {
|
|
23731
23743
|
query.$or = [
|
|
23732
23744
|
{ name: { $regex: search, $options: "i" } },
|
|
@@ -27400,11 +27412,11 @@ var EAccessCardTypes = /* @__PURE__ */ ((EAccessCardTypes2) => {
|
|
|
27400
27412
|
EAccessCardTypes2["QR"] = "QRCODE";
|
|
27401
27413
|
return EAccessCardTypes2;
|
|
27402
27414
|
})(EAccessCardTypes || {});
|
|
27403
|
-
var EAccessCardUserTypes = /* @__PURE__ */ ((
|
|
27404
|
-
|
|
27405
|
-
|
|
27406
|
-
|
|
27407
|
-
return
|
|
27415
|
+
var EAccessCardUserTypes = /* @__PURE__ */ ((EAccessCardUserTypes3) => {
|
|
27416
|
+
EAccessCardUserTypes3["RESIDENT"] = "Resident/Tenant";
|
|
27417
|
+
EAccessCardUserTypes3["CONTRACTOR"] = "Contractor";
|
|
27418
|
+
EAccessCardUserTypes3["VISITOR"] = "Visitor";
|
|
27419
|
+
return EAccessCardUserTypes3;
|
|
27408
27420
|
})(EAccessCardUserTypes || {});
|
|
27409
27421
|
var AccessTypeProps = /* @__PURE__ */ ((AccessTypeProps2) => {
|
|
27410
27422
|
AccessTypeProps2["NORMAL"] = "Normal";
|
|
@@ -27505,6 +27517,114 @@ import {
|
|
|
27505
27517
|
useAtlas as useAtlas74
|
|
27506
27518
|
} from "@7365admin1/node-server-utils";
|
|
27507
27519
|
import { ObjectId as ObjectId83 } from "mongodb";
|
|
27520
|
+
|
|
27521
|
+
// src/utils/access-management.ts
|
|
27522
|
+
import fs2 from "fs";
|
|
27523
|
+
import path2 from "path";
|
|
27524
|
+
import axios from "axios";
|
|
27525
|
+
import crypto from "crypto";
|
|
27526
|
+
var ALGORITHM = "aes-256-gcm";
|
|
27527
|
+
var SECRET_KEY = crypto.createSecretKey(
|
|
27528
|
+
new Uint8Array(crypto.createHash("sha256").update("acm-secret-key").digest())
|
|
27529
|
+
);
|
|
27530
|
+
function decryptAcmUrl(encryptedText) {
|
|
27531
|
+
const [ivB64, authTagB64, encryptedB64] = encryptedText.split(":");
|
|
27532
|
+
const iv = Buffer.from(ivB64, "base64");
|
|
27533
|
+
const authTag = Buffer.from(authTagB64, "base64");
|
|
27534
|
+
const encrypted = Buffer.from(encryptedB64, "base64");
|
|
27535
|
+
const decipher = crypto.createDecipheriv(
|
|
27536
|
+
ALGORITHM,
|
|
27537
|
+
SECRET_KEY,
|
|
27538
|
+
new Uint8Array(iv)
|
|
27539
|
+
);
|
|
27540
|
+
decipher.setAuthTag(new Uint8Array(authTag));
|
|
27541
|
+
const decrypted = Buffer.concat([
|
|
27542
|
+
decipher.update(encrypted),
|
|
27543
|
+
decipher.final()
|
|
27544
|
+
]);
|
|
27545
|
+
return decrypted.toString("utf8");
|
|
27546
|
+
}
|
|
27547
|
+
var minifyXml = (xml) => {
|
|
27548
|
+
return xml.replace(/>\s+</g, "><").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").trim();
|
|
27549
|
+
};
|
|
27550
|
+
var readTemplate = (name, params) => {
|
|
27551
|
+
const template = fs2.readFileSync(
|
|
27552
|
+
path2.join(__dirname, `../src/public/xml-templates/${name}.xml`),
|
|
27553
|
+
"utf-8"
|
|
27554
|
+
);
|
|
27555
|
+
if (!params)
|
|
27556
|
+
return minifyXml(template);
|
|
27557
|
+
const replacedTemplate = Object.entries(params).reduce(
|
|
27558
|
+
(acc, [key, value]) => acc.replace(`{{${key}}}`, value),
|
|
27559
|
+
template
|
|
27560
|
+
);
|
|
27561
|
+
return minifyXml(replacedTemplate);
|
|
27562
|
+
};
|
|
27563
|
+
async function sendCommand(command, url) {
|
|
27564
|
+
try {
|
|
27565
|
+
const decrypt = decryptAcmUrl(url);
|
|
27566
|
+
const response = await axios.post(decrypt, {
|
|
27567
|
+
command
|
|
27568
|
+
});
|
|
27569
|
+
if (response.status === 200 || response.status === 201)
|
|
27570
|
+
return response.data;
|
|
27571
|
+
} catch (error) {
|
|
27572
|
+
return Promise.reject(error);
|
|
27573
|
+
}
|
|
27574
|
+
}
|
|
27575
|
+
var formatDoorAccessLevels = (data) => {
|
|
27576
|
+
const doorAccessLevels = data.RESULT.TRACKID.SUB_RESULT.ACCESS_LEVEL;
|
|
27577
|
+
return doorAccessLevels.map((door) => {
|
|
27578
|
+
return {
|
|
27579
|
+
name: door._.trim(),
|
|
27580
|
+
// Remove any leading/trailing spaces
|
|
27581
|
+
no: door.$.NO
|
|
27582
|
+
// Extract the number
|
|
27583
|
+
};
|
|
27584
|
+
});
|
|
27585
|
+
};
|
|
27586
|
+
var formatLiftAccessLevels = (data, search) => {
|
|
27587
|
+
const liftAccessLevels = data.RESULT.TRACKID.SUB_RESULT.LIFT_ACCESS_LEVEL;
|
|
27588
|
+
const result = liftAccessLevels.map((level) => {
|
|
27589
|
+
return {
|
|
27590
|
+
name: level._.trim(),
|
|
27591
|
+
no: level.$.NO
|
|
27592
|
+
};
|
|
27593
|
+
});
|
|
27594
|
+
if (search) {
|
|
27595
|
+
return result.filter(
|
|
27596
|
+
(item) => item.name.toLowerCase().includes(search.toLowerCase())
|
|
27597
|
+
);
|
|
27598
|
+
}
|
|
27599
|
+
return result;
|
|
27600
|
+
};
|
|
27601
|
+
var formatAccessGroup = (data, search) => {
|
|
27602
|
+
const accessGroup = data.RESULT.TRACKID.SUB_RESULT.ACCESS_GROUP;
|
|
27603
|
+
const result = accessGroup.map((ag) => {
|
|
27604
|
+
return {
|
|
27605
|
+
no: ag._.trim(),
|
|
27606
|
+
name: ag.$.NAME
|
|
27607
|
+
};
|
|
27608
|
+
});
|
|
27609
|
+
if (search) {
|
|
27610
|
+
return result.filter(
|
|
27611
|
+
(item) => item.name.toLowerCase().includes(search.toLowerCase())
|
|
27612
|
+
);
|
|
27613
|
+
}
|
|
27614
|
+
return result;
|
|
27615
|
+
};
|
|
27616
|
+
var formatEntryPassDate = (date) => {
|
|
27617
|
+
if (!date)
|
|
27618
|
+
return null;
|
|
27619
|
+
const newDate = new Date(date);
|
|
27620
|
+
const year = newDate.getFullYear();
|
|
27621
|
+
const month = String(newDate.getMonth() + 1).padStart(2, "0");
|
|
27622
|
+
const day = String(newDate.getDate()).padStart(2, "0");
|
|
27623
|
+
return `${year}${month}${day}`;
|
|
27624
|
+
};
|
|
27625
|
+
|
|
27626
|
+
// src/repositories/access-management.repo.ts
|
|
27627
|
+
import { parseStringPromise } from "xml2js";
|
|
27508
27628
|
function UseAccessManagementRepo() {
|
|
27509
27629
|
function collection() {
|
|
27510
27630
|
const db = useAtlas74.getDb();
|
|
@@ -28290,6 +28410,255 @@ function UseAccessManagementRepo() {
|
|
|
28290
28410
|
await session?.endSession();
|
|
28291
28411
|
}
|
|
28292
28412
|
}
|
|
28413
|
+
async function accessandLiftCardsRepo(params) {
|
|
28414
|
+
try {
|
|
28415
|
+
const { accessLevel, liftAccessLevel, site, userType, type } = params;
|
|
28416
|
+
const siteId = new ObjectId83(site);
|
|
28417
|
+
const query = {
|
|
28418
|
+
site: { $in: [siteId] },
|
|
28419
|
+
userType,
|
|
28420
|
+
type,
|
|
28421
|
+
userId: null,
|
|
28422
|
+
assignedUnit: null,
|
|
28423
|
+
accessLevel,
|
|
28424
|
+
liftAccessLevel,
|
|
28425
|
+
isActivated: true
|
|
28426
|
+
};
|
|
28427
|
+
const result = await collection().aggregate([
|
|
28428
|
+
{
|
|
28429
|
+
$match: query
|
|
28430
|
+
},
|
|
28431
|
+
{
|
|
28432
|
+
$facet: {
|
|
28433
|
+
counts: [{ $count: "count" }]
|
|
28434
|
+
}
|
|
28435
|
+
}
|
|
28436
|
+
], { allowDiskUse: true }).toArray();
|
|
28437
|
+
return result;
|
|
28438
|
+
} catch (error) {
|
|
28439
|
+
throw new Error(error.message);
|
|
28440
|
+
}
|
|
28441
|
+
}
|
|
28442
|
+
async function replaceCardRepo(params) {
|
|
28443
|
+
const session = useAtlas74.getClient()?.startSession();
|
|
28444
|
+
try {
|
|
28445
|
+
session?.startTransaction();
|
|
28446
|
+
const siteId = new ObjectId83(params.site);
|
|
28447
|
+
const userId = new ObjectId83(params.userId);
|
|
28448
|
+
const cardId = new ObjectId83(params.cardId);
|
|
28449
|
+
const quantity = 1;
|
|
28450
|
+
const cardCredentials = await collection().findOneAndUpdate(
|
|
28451
|
+
{ _id: cardId },
|
|
28452
|
+
{ $set: { replacementStatus: "Issuance" } },
|
|
28453
|
+
{ returnDocument: "after" }
|
|
28454
|
+
);
|
|
28455
|
+
const unit = [cardCredentials?.assignedUnit];
|
|
28456
|
+
const date = /* @__PURE__ */ new Date();
|
|
28457
|
+
const endDate = new Date(date.setFullYear(date.getFullYear() + 10));
|
|
28458
|
+
const res = await collection().aggregate([{ $sort: { cardNo: -1 } }, { $limit: 2 }]).toArray();
|
|
28459
|
+
const prevCard = res && res?.[1]?.cardNo || "-1";
|
|
28460
|
+
const currentCard = res && res?.[0]?.cardNo || "0";
|
|
28461
|
+
let availableCardNo = [];
|
|
28462
|
+
let num = parseInt(prevCard, 10) + 1;
|
|
28463
|
+
while (availableCardNo.length < (unit.length > 0 ? unit.length : quantity)) {
|
|
28464
|
+
if (num === parseInt(currentCard, 10)) {
|
|
28465
|
+
num++;
|
|
28466
|
+
}
|
|
28467
|
+
availableCardNo.push(num);
|
|
28468
|
+
num++;
|
|
28469
|
+
}
|
|
28470
|
+
const cardNumbers = availableCardNo.map((no) => no.toString().padStart(10, "0"));
|
|
28471
|
+
const accessCards = [];
|
|
28472
|
+
const convertedUnits = unit.map((obj) => new ObjectId83(obj));
|
|
28473
|
+
for (let j = 0; j < (unit.length > 0 ? unit.length : quantity); j++) {
|
|
28474
|
+
accessCards.push(
|
|
28475
|
+
new MAccessCard({
|
|
28476
|
+
userId,
|
|
28477
|
+
site: siteId,
|
|
28478
|
+
type: cardCredentials?.type,
|
|
28479
|
+
accessLevel: cardCredentials?.accessLevel,
|
|
28480
|
+
accessGroup: cardCredentials?.accessGroup,
|
|
28481
|
+
accessType: cardCredentials?.accessType,
|
|
28482
|
+
cardNo: cardNumbers[j],
|
|
28483
|
+
pin: "123456",
|
|
28484
|
+
qrData: "092222",
|
|
28485
|
+
startDate: /* @__PURE__ */ new Date(),
|
|
28486
|
+
endDate,
|
|
28487
|
+
isActivated: true,
|
|
28488
|
+
isAntiPassBack: false,
|
|
28489
|
+
isLiftCard: cardCredentials?.isLiftCard ? true : false,
|
|
28490
|
+
liftAccessLevel: cardCredentials?.liftAccessLevel,
|
|
28491
|
+
userType: cardCredentials?.userType,
|
|
28492
|
+
doorName: cardCredentials?.doorName,
|
|
28493
|
+
liftName: cardCredentials?.liftName,
|
|
28494
|
+
assignedUnit: convertedUnits[j],
|
|
28495
|
+
replacementStatus: "Issuance",
|
|
28496
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
28497
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
28498
|
+
})
|
|
28499
|
+
);
|
|
28500
|
+
}
|
|
28501
|
+
const commands = accessCards.map((item, index) => {
|
|
28502
|
+
let ag = null;
|
|
28503
|
+
if (item.accessGroup !== void 0) {
|
|
28504
|
+
if (item.accessGroup?.length > 0) {
|
|
28505
|
+
ag = item.accessGroup.map((g) => `<GROUP_NAME>${g}</GROUP_NAME>`).join("\n ");
|
|
28506
|
+
}
|
|
28507
|
+
}
|
|
28508
|
+
const command = {
|
|
28509
|
+
commandId1: index * 2 + 1,
|
|
28510
|
+
commandId2: index * 2 + 2,
|
|
28511
|
+
staffName: `STAFF-${item._id.toString().slice(-10)}`,
|
|
28512
|
+
staffNo1: `STAFF-${item._id.toString().slice(-10)}`,
|
|
28513
|
+
staffNo2: `STAFF-${item._id.toString().slice(-10)}`,
|
|
28514
|
+
dateOfJoin: formatEntryPassDate(item.startDate),
|
|
28515
|
+
accessLevel: item.accessLevel ?? "0",
|
|
28516
|
+
cardNo: item.cardNo,
|
|
28517
|
+
pin: typeof item.pin === "string" && item.pin.trim() !== "" ? item.pin : "123456",
|
|
28518
|
+
startDate: formatEntryPassDate(item.startDate),
|
|
28519
|
+
endDate: formatEntryPassDate(item.endDate),
|
|
28520
|
+
cardType: 0,
|
|
28521
|
+
isActivated: item.isActivated ? 1 : 0,
|
|
28522
|
+
isAntiPassBack: item.isAntiPassBack ? 1 : 0,
|
|
28523
|
+
isLiftCard: item.isLiftCard ? 1 : 0,
|
|
28524
|
+
isLiftActivate: item.isLiftCard ? 1 : 0,
|
|
28525
|
+
liftAccessLevel: item.liftAccessLevel || 1,
|
|
28526
|
+
liftAccessStartDate: formatEntryPassDate(item.liftAccessStartDate) || "19770510",
|
|
28527
|
+
liftAccessEndDate: formatEntryPassDate(item.liftAccessEndDate) || "19770510",
|
|
28528
|
+
accessGroup: ag
|
|
28529
|
+
};
|
|
28530
|
+
return readTemplate(`${item.accessLevel !== null ? "add-card" : "add-card-lift"}`, { ...command });
|
|
28531
|
+
}).flat();
|
|
28532
|
+
const response = await sendCommand(commands.join("").toString(), params.acm_url);
|
|
28533
|
+
const result = await parseStringPromise(response, { explicitArray: false });
|
|
28534
|
+
if (result && result.RESULT.$.STCODE !== "0") {
|
|
28535
|
+
throw new Error("Command failed, server error.");
|
|
28536
|
+
}
|
|
28537
|
+
const card = await collection().insertMany(accessCards);
|
|
28538
|
+
await session?.commitTransaction();
|
|
28539
|
+
return card;
|
|
28540
|
+
} catch (error) {
|
|
28541
|
+
await session?.abortTransaction();
|
|
28542
|
+
throw new Error(error.message);
|
|
28543
|
+
} finally {
|
|
28544
|
+
await session?.endSession();
|
|
28545
|
+
}
|
|
28546
|
+
}
|
|
28547
|
+
async function updateNFCStatusRepo(params) {
|
|
28548
|
+
const session = useAtlas74.getClient()?.startSession();
|
|
28549
|
+
try {
|
|
28550
|
+
session?.startTransaction();
|
|
28551
|
+
const results = [];
|
|
28552
|
+
for (let nfc of params.nfcList) {
|
|
28553
|
+
nfc._id = new ObjectId83(nfc._id);
|
|
28554
|
+
const card = await collection().findOne({ _id: nfc._id }, { session });
|
|
28555
|
+
if (card) {
|
|
28556
|
+
const updateFields = {
|
|
28557
|
+
status: nfc.status,
|
|
28558
|
+
vmsRemarks: nfc?.vmsRemarks,
|
|
28559
|
+
userId: null,
|
|
28560
|
+
updatedAt: nfc?.updatedAt ?? /* @__PURE__ */ new Date()
|
|
28561
|
+
};
|
|
28562
|
+
if (nfc.status !== "Returned") {
|
|
28563
|
+
updateFields.isActivated = false;
|
|
28564
|
+
} else {
|
|
28565
|
+
updateFields.isActivated = true;
|
|
28566
|
+
}
|
|
28567
|
+
const res = await collection().updateOne({ _id: card._id }, { $set: updateFields }, { session });
|
|
28568
|
+
results.push({ nfcId: nfc._id, modifiedCount: res.modifiedCount });
|
|
28569
|
+
}
|
|
28570
|
+
}
|
|
28571
|
+
await session?.commitTransaction();
|
|
28572
|
+
return results;
|
|
28573
|
+
} catch (error) {
|
|
28574
|
+
await session?.abortTransaction();
|
|
28575
|
+
throw new Error(error.message);
|
|
28576
|
+
} finally {
|
|
28577
|
+
await session?.endSession();
|
|
28578
|
+
}
|
|
28579
|
+
}
|
|
28580
|
+
async function doorAndLiftDropdownRepo(params) {
|
|
28581
|
+
try {
|
|
28582
|
+
const { site, type, userType } = params;
|
|
28583
|
+
const id = new ObjectId83(site);
|
|
28584
|
+
const res = collection().aggregate([
|
|
28585
|
+
{
|
|
28586
|
+
$match: {
|
|
28587
|
+
site: { $in: [id] },
|
|
28588
|
+
type,
|
|
28589
|
+
userType,
|
|
28590
|
+
isActivated: true,
|
|
28591
|
+
assignedUnit: null,
|
|
28592
|
+
userId: null,
|
|
28593
|
+
$or: [
|
|
28594
|
+
{ $and: [{ doorName: { $ne: null } }, { doorName: { $ne: "" } }, { accessLevel: { $ne: null } }] },
|
|
28595
|
+
{ $and: [{ liftName: { $ne: null } }, { liftName: { $ne: "" } }, { liftAccessLevel: { $ne: null } }] }
|
|
28596
|
+
]
|
|
28597
|
+
}
|
|
28598
|
+
},
|
|
28599
|
+
{
|
|
28600
|
+
$facet: {
|
|
28601
|
+
totalCount: [{ $count: "count" }],
|
|
28602
|
+
accessData: [
|
|
28603
|
+
{
|
|
28604
|
+
$group: {
|
|
28605
|
+
_id: null,
|
|
28606
|
+
accessLevels: {
|
|
28607
|
+
$addToSet: {
|
|
28608
|
+
$cond: [
|
|
28609
|
+
{ $and: [{ $ne: ["$doorName", null] }, { $ne: ["$doorName", ""] }, { $ne: ["$accessLevel", null] }] },
|
|
28610
|
+
{ name: "$doorName", no: "$accessLevel" },
|
|
28611
|
+
"$$REMOVE"
|
|
28612
|
+
]
|
|
28613
|
+
}
|
|
28614
|
+
},
|
|
28615
|
+
liftAccessLevels: {
|
|
28616
|
+
$addToSet: {
|
|
28617
|
+
$cond: [
|
|
28618
|
+
{ $and: [{ $ne: ["$liftName", null] }, { $ne: ["$liftName", ""] }, { $ne: ["$liftAccessLevel", null] }] },
|
|
28619
|
+
{ name: "$liftName", no: "$liftAccessLevel" },
|
|
28620
|
+
"$$REMOVE"
|
|
28621
|
+
]
|
|
28622
|
+
}
|
|
28623
|
+
}
|
|
28624
|
+
}
|
|
28625
|
+
},
|
|
28626
|
+
{
|
|
28627
|
+
$project: {
|
|
28628
|
+
_id: 0,
|
|
28629
|
+
accessLevels: 1,
|
|
28630
|
+
liftAccessLevels: 1
|
|
28631
|
+
}
|
|
28632
|
+
}
|
|
28633
|
+
]
|
|
28634
|
+
}
|
|
28635
|
+
}
|
|
28636
|
+
]).toArray();
|
|
28637
|
+
return res;
|
|
28638
|
+
} catch (error) {
|
|
28639
|
+
throw new Error(error.message);
|
|
28640
|
+
}
|
|
28641
|
+
}
|
|
28642
|
+
async function cardReplacementRepo(params) {
|
|
28643
|
+
const session = useAtlas74.getClient()?.startSession();
|
|
28644
|
+
try {
|
|
28645
|
+
const { cardId, remarks } = params;
|
|
28646
|
+
const id = new ObjectId83(cardId);
|
|
28647
|
+
session?.startTransaction();
|
|
28648
|
+
const card = await collection().findOneAndUpdate(
|
|
28649
|
+
{ _id: id },
|
|
28650
|
+
{ $set: { remarks, replacementStatus: "Pending", requestDate: /* @__PURE__ */ new Date(), isActivated: false } },
|
|
28651
|
+
{ returnDocument: "after", session }
|
|
28652
|
+
);
|
|
28653
|
+
await session?.commitTransaction();
|
|
28654
|
+
return card;
|
|
28655
|
+
} catch (error) {
|
|
28656
|
+
await session?.abortTransaction();
|
|
28657
|
+
throw new Error(error.message);
|
|
28658
|
+
} finally {
|
|
28659
|
+
await session?.endSession();
|
|
28660
|
+
}
|
|
28661
|
+
}
|
|
28293
28662
|
return {
|
|
28294
28663
|
createIndexes,
|
|
28295
28664
|
createIndexForEntrypass,
|
|
@@ -28300,111 +28669,20 @@ function UseAccessManagementRepo() {
|
|
|
28300
28669
|
availableAccessCardsRepo,
|
|
28301
28670
|
userTypeAccessCardsRepo,
|
|
28302
28671
|
assignedAccessCardsRepo,
|
|
28303
|
-
acknowlegdeCardRepo
|
|
28672
|
+
acknowlegdeCardRepo,
|
|
28673
|
+
accessandLiftCardsRepo,
|
|
28674
|
+
replaceCardRepo,
|
|
28675
|
+
updateNFCStatusRepo,
|
|
28676
|
+
doorAndLiftDropdownRepo,
|
|
28677
|
+
cardReplacementRepo
|
|
28304
28678
|
};
|
|
28305
28679
|
}
|
|
28306
28680
|
|
|
28307
28681
|
// src/controllers/access-management.controller.ts
|
|
28308
28682
|
import Joi85 from "joi";
|
|
28309
28683
|
|
|
28310
|
-
// src/utils/access-management.ts
|
|
28311
|
-
import fs2 from "fs";
|
|
28312
|
-
import path2 from "path";
|
|
28313
|
-
import axios from "axios";
|
|
28314
|
-
import crypto from "crypto";
|
|
28315
|
-
var ALGORITHM = "aes-256-gcm";
|
|
28316
|
-
var SECRET_KEY = crypto.createSecretKey(
|
|
28317
|
-
new Uint8Array(crypto.createHash("sha256").update("acm-secret-key").digest())
|
|
28318
|
-
);
|
|
28319
|
-
function decryptAcmUrl(encryptedText) {
|
|
28320
|
-
const [ivB64, authTagB64, encryptedB64] = encryptedText.split(":");
|
|
28321
|
-
const iv = Buffer.from(ivB64, "base64");
|
|
28322
|
-
const authTag = Buffer.from(authTagB64, "base64");
|
|
28323
|
-
const encrypted = Buffer.from(encryptedB64, "base64");
|
|
28324
|
-
const decipher = crypto.createDecipheriv(
|
|
28325
|
-
ALGORITHM,
|
|
28326
|
-
SECRET_KEY,
|
|
28327
|
-
new Uint8Array(iv)
|
|
28328
|
-
);
|
|
28329
|
-
decipher.setAuthTag(new Uint8Array(authTag));
|
|
28330
|
-
const decrypted = Buffer.concat([
|
|
28331
|
-
decipher.update(encrypted),
|
|
28332
|
-
decipher.final()
|
|
28333
|
-
]);
|
|
28334
|
-
return decrypted.toString("utf8");
|
|
28335
|
-
}
|
|
28336
|
-
var minifyXml = (xml) => {
|
|
28337
|
-
return xml.replace(/>\s+</g, "><").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").trim();
|
|
28338
|
-
};
|
|
28339
|
-
var readTemplate = (name, params) => {
|
|
28340
|
-
const template = fs2.readFileSync(
|
|
28341
|
-
path2.join(__dirname, `../src/public/xml-templates/${name}.xml`),
|
|
28342
|
-
"utf-8"
|
|
28343
|
-
);
|
|
28344
|
-
if (!params)
|
|
28345
|
-
return minifyXml(template);
|
|
28346
|
-
const replacedTemplate = Object.entries(params).reduce(
|
|
28347
|
-
(acc, [key, value]) => acc.replace(`{{${key}}}`, value),
|
|
28348
|
-
template
|
|
28349
|
-
);
|
|
28350
|
-
return minifyXml(replacedTemplate);
|
|
28351
|
-
};
|
|
28352
|
-
async function sendCommand(command, url) {
|
|
28353
|
-
try {
|
|
28354
|
-
const decrypt = decryptAcmUrl(url);
|
|
28355
|
-
const response = await axios.post(decrypt, {
|
|
28356
|
-
command
|
|
28357
|
-
});
|
|
28358
|
-
if (response.status === 200 || response.status === 201)
|
|
28359
|
-
return response.data;
|
|
28360
|
-
} catch (error) {
|
|
28361
|
-
return Promise.reject(error);
|
|
28362
|
-
}
|
|
28363
|
-
}
|
|
28364
|
-
var formatDoorAccessLevels = (data) => {
|
|
28365
|
-
const doorAccessLevels = data.RESULT.TRACKID.SUB_RESULT.ACCESS_LEVEL;
|
|
28366
|
-
return doorAccessLevels.map((door) => {
|
|
28367
|
-
return {
|
|
28368
|
-
name: door._.trim(),
|
|
28369
|
-
// Remove any leading/trailing spaces
|
|
28370
|
-
no: door.$.NO
|
|
28371
|
-
// Extract the number
|
|
28372
|
-
};
|
|
28373
|
-
});
|
|
28374
|
-
};
|
|
28375
|
-
var formatLiftAccessLevels = (data, search) => {
|
|
28376
|
-
const liftAccessLevels = data.RESULT.TRACKID.SUB_RESULT.LIFT_ACCESS_LEVEL;
|
|
28377
|
-
const result = liftAccessLevels.map((level) => {
|
|
28378
|
-
return {
|
|
28379
|
-
name: level._.trim(),
|
|
28380
|
-
no: level.$.NO
|
|
28381
|
-
};
|
|
28382
|
-
});
|
|
28383
|
-
if (search) {
|
|
28384
|
-
return result.filter(
|
|
28385
|
-
(item) => item.name.toLowerCase().includes(search.toLowerCase())
|
|
28386
|
-
);
|
|
28387
|
-
}
|
|
28388
|
-
return result;
|
|
28389
|
-
};
|
|
28390
|
-
var formatAccessGroup = (data, search) => {
|
|
28391
|
-
const accessGroup = data.RESULT.TRACKID.SUB_RESULT.ACCESS_GROUP;
|
|
28392
|
-
const result = accessGroup.map((ag) => {
|
|
28393
|
-
return {
|
|
28394
|
-
no: ag._.trim(),
|
|
28395
|
-
name: ag.$.NAME
|
|
28396
|
-
};
|
|
28397
|
-
});
|
|
28398
|
-
if (search) {
|
|
28399
|
-
return result.filter(
|
|
28400
|
-
(item) => item.name.toLowerCase().includes(search.toLowerCase())
|
|
28401
|
-
);
|
|
28402
|
-
}
|
|
28403
|
-
return result;
|
|
28404
|
-
};
|
|
28405
|
-
|
|
28406
28684
|
// src/services/access-management.service.ts
|
|
28407
|
-
import { parseStringPromise } from "xml2js";
|
|
28685
|
+
import { parseStringPromise as parseStringPromise2 } from "xml2js";
|
|
28408
28686
|
import { useCache as useCache47 } from "@7365admin1/node-server-utils";
|
|
28409
28687
|
var namespace = "cache:acm";
|
|
28410
28688
|
function useAccessManagementSvc() {
|
|
@@ -28416,7 +28694,12 @@ function useAccessManagementSvc() {
|
|
|
28416
28694
|
availableAccessCardsRepo,
|
|
28417
28695
|
userTypeAccessCardsRepo,
|
|
28418
28696
|
assignedAccessCardsRepo,
|
|
28419
|
-
acknowlegdeCardRepo
|
|
28697
|
+
acknowlegdeCardRepo,
|
|
28698
|
+
accessandLiftCardsRepo,
|
|
28699
|
+
replaceCardRepo,
|
|
28700
|
+
updateNFCStatusRepo,
|
|
28701
|
+
doorAndLiftDropdownRepo,
|
|
28702
|
+
cardReplacementRepo
|
|
28420
28703
|
} = UseAccessManagementRepo();
|
|
28421
28704
|
const addPhysicalCardSvc = async (payload) => {
|
|
28422
28705
|
try {
|
|
@@ -28458,7 +28741,7 @@ function useAccessManagementSvc() {
|
|
|
28458
28741
|
}
|
|
28459
28742
|
const command = readTemplate("door-levels");
|
|
28460
28743
|
const response = await sendCommand(command, params.acm_url);
|
|
28461
|
-
const res = await
|
|
28744
|
+
const res = await parseStringPromise2(response, { explicitArray: false });
|
|
28462
28745
|
const format = await formatDoorAccessLevels(res);
|
|
28463
28746
|
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28464
28747
|
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
@@ -28481,7 +28764,7 @@ function useAccessManagementSvc() {
|
|
|
28481
28764
|
}
|
|
28482
28765
|
const command = readTemplate("lift-levels");
|
|
28483
28766
|
const response = await sendCommand(command, params.acm_url);
|
|
28484
|
-
const res = await
|
|
28767
|
+
const res = await parseStringPromise2(response, { explicitArray: false });
|
|
28485
28768
|
const format = await formatLiftAccessLevels(res);
|
|
28486
28769
|
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28487
28770
|
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
@@ -28504,7 +28787,7 @@ function useAccessManagementSvc() {
|
|
|
28504
28787
|
}
|
|
28505
28788
|
const command = readTemplate("access-group");
|
|
28506
28789
|
const response = await sendCommand(command, params.acm_url);
|
|
28507
|
-
const res = await
|
|
28790
|
+
const res = await parseStringPromise2(response, { explicitArray: false });
|
|
28508
28791
|
const format = await formatAccessGroup(res);
|
|
28509
28792
|
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28510
28793
|
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
@@ -28561,6 +28844,46 @@ function useAccessManagementSvc() {
|
|
|
28561
28844
|
throw new Error(err.message);
|
|
28562
28845
|
}
|
|
28563
28846
|
};
|
|
28847
|
+
const accessandLiftCardsSvc = async (params) => {
|
|
28848
|
+
try {
|
|
28849
|
+
const response = await accessandLiftCardsRepo({ ...params });
|
|
28850
|
+
return response;
|
|
28851
|
+
} catch (err) {
|
|
28852
|
+
throw new Error(err.message);
|
|
28853
|
+
}
|
|
28854
|
+
};
|
|
28855
|
+
const replaceCardSvc = async (params) => {
|
|
28856
|
+
try {
|
|
28857
|
+
const response = await replaceCardRepo({ ...params });
|
|
28858
|
+
return response;
|
|
28859
|
+
} catch (err) {
|
|
28860
|
+
throw new Error(err.message);
|
|
28861
|
+
}
|
|
28862
|
+
};
|
|
28863
|
+
const updateNFCStatusSvc = async (params) => {
|
|
28864
|
+
try {
|
|
28865
|
+
const response = await updateNFCStatusRepo({ ...params });
|
|
28866
|
+
return response;
|
|
28867
|
+
} catch (err) {
|
|
28868
|
+
throw new Error(err.message);
|
|
28869
|
+
}
|
|
28870
|
+
};
|
|
28871
|
+
const doorAndLiftDropdownSvc = async (params) => {
|
|
28872
|
+
try {
|
|
28873
|
+
const response = await doorAndLiftDropdownRepo({ ...params });
|
|
28874
|
+
return response;
|
|
28875
|
+
} catch (err) {
|
|
28876
|
+
throw new Error(err.message);
|
|
28877
|
+
}
|
|
28878
|
+
};
|
|
28879
|
+
const cardReplacementSvc = async (params) => {
|
|
28880
|
+
try {
|
|
28881
|
+
const response = await cardReplacementRepo({ ...params });
|
|
28882
|
+
return response;
|
|
28883
|
+
} catch (err) {
|
|
28884
|
+
throw new Error(err.message);
|
|
28885
|
+
}
|
|
28886
|
+
};
|
|
28564
28887
|
return {
|
|
28565
28888
|
addPhysicalCardSvc,
|
|
28566
28889
|
addNonPhysicalCardSvc,
|
|
@@ -28572,7 +28895,12 @@ function useAccessManagementSvc() {
|
|
|
28572
28895
|
availableAccessCardsSvc,
|
|
28573
28896
|
userTypeAccessCardsSvc,
|
|
28574
28897
|
assignedAccessCardsSvc,
|
|
28575
|
-
acknowlegdeCardSvc
|
|
28898
|
+
acknowlegdeCardSvc,
|
|
28899
|
+
accessandLiftCardsSvc,
|
|
28900
|
+
replaceCardSvc,
|
|
28901
|
+
updateNFCStatusSvc,
|
|
28902
|
+
doorAndLiftDropdownSvc,
|
|
28903
|
+
cardReplacementSvc
|
|
28576
28904
|
};
|
|
28577
28905
|
}
|
|
28578
28906
|
|
|
@@ -28589,7 +28917,12 @@ function useAccessManagementController() {
|
|
|
28589
28917
|
availableAccessCardsSvc,
|
|
28590
28918
|
userTypeAccessCardsSvc,
|
|
28591
28919
|
assignedAccessCardsSvc,
|
|
28592
|
-
acknowlegdeCardSvc
|
|
28920
|
+
acknowlegdeCardSvc,
|
|
28921
|
+
accessandLiftCardsSvc,
|
|
28922
|
+
replaceCardSvc,
|
|
28923
|
+
updateNFCStatusSvc,
|
|
28924
|
+
doorAndLiftDropdownSvc,
|
|
28925
|
+
cardReplacementSvc
|
|
28593
28926
|
} = useAccessManagementSvc();
|
|
28594
28927
|
const addPhysicalCard = async (req, res) => {
|
|
28595
28928
|
try {
|
|
@@ -28661,7 +28994,7 @@ function useAccessManagementController() {
|
|
|
28661
28994
|
accessGroup: Joi85.array().items(Joi85.string().required()).required(),
|
|
28662
28995
|
userType: Joi85.string().required(),
|
|
28663
28996
|
doorName: Joi85.string().required(),
|
|
28664
|
-
liftName: Joi85.string().
|
|
28997
|
+
liftName: Joi85.string().optional().allow("", null),
|
|
28665
28998
|
unit: Joi85.array().items(Joi85.string()).optional().allow(null),
|
|
28666
28999
|
startDate: Joi85.date().required(),
|
|
28667
29000
|
endDate: Joi85.date().required(),
|
|
@@ -28892,6 +29225,123 @@ function useAccessManagementController() {
|
|
|
28892
29225
|
});
|
|
28893
29226
|
}
|
|
28894
29227
|
};
|
|
29228
|
+
const accessandLiftCards = async (req, res) => {
|
|
29229
|
+
try {
|
|
29230
|
+
const {
|
|
29231
|
+
accessLevel = null,
|
|
29232
|
+
liftAccessLevel = null,
|
|
29233
|
+
site,
|
|
29234
|
+
userType,
|
|
29235
|
+
type
|
|
29236
|
+
} = req.query;
|
|
29237
|
+
const schema2 = Joi85.object({
|
|
29238
|
+
accessLevel: Joi85.string().optional().allow("", null),
|
|
29239
|
+
liftAccessLevel: Joi85.string().optional().allow("", null),
|
|
29240
|
+
site: Joi85.string().hex().required(),
|
|
29241
|
+
userType: Joi85.string().valid(...Object.values(EAccessCardUserTypes)).required(),
|
|
29242
|
+
type: Joi85.string().valid(...Object.values(EAccessCardTypes)).required()
|
|
29243
|
+
});
|
|
29244
|
+
const { error } = schema2.validate({ accessLevel, liftAccessLevel, site, userType, type });
|
|
29245
|
+
if (error) {
|
|
29246
|
+
return res.status(400).json({ message: error.message });
|
|
29247
|
+
}
|
|
29248
|
+
const result = await accessandLiftCardsSvc({ accessLevel, liftAccessLevel, site, userType, type });
|
|
29249
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29250
|
+
} catch (error) {
|
|
29251
|
+
return res.status(500).json({
|
|
29252
|
+
data: null,
|
|
29253
|
+
message: error.message
|
|
29254
|
+
});
|
|
29255
|
+
}
|
|
29256
|
+
};
|
|
29257
|
+
const replaceCard = async (req, res) => {
|
|
29258
|
+
try {
|
|
29259
|
+
const { userId, cardId, site, acm_url } = req.body;
|
|
29260
|
+
const schema2 = Joi85.object({
|
|
29261
|
+
userId: Joi85.string().required(),
|
|
29262
|
+
cardId: Joi85.string().required(),
|
|
29263
|
+
site: Joi85.string().required(),
|
|
29264
|
+
acm_url: Joi85.string().required()
|
|
29265
|
+
});
|
|
29266
|
+
const { error } = schema2.validate({ userId, cardId, site, acm_url });
|
|
29267
|
+
if (error) {
|
|
29268
|
+
return res.status(400).json({ message: error.message });
|
|
29269
|
+
}
|
|
29270
|
+
const result = await replaceCardSvc({ userId, cardId, site, acm_url });
|
|
29271
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29272
|
+
} catch (error) {
|
|
29273
|
+
return res.status(500).json({
|
|
29274
|
+
data: null,
|
|
29275
|
+
message: error.message
|
|
29276
|
+
});
|
|
29277
|
+
}
|
|
29278
|
+
};
|
|
29279
|
+
const updateNFCStatus = async (req, res) => {
|
|
29280
|
+
try {
|
|
29281
|
+
const { nfcList = [], visitorId } = req.body;
|
|
29282
|
+
const schema2 = Joi85.object({
|
|
29283
|
+
nfcList: Joi85.array().items({
|
|
29284
|
+
_id: Joi85.string().hex().length(24).required(),
|
|
29285
|
+
status: Joi85.string().required(),
|
|
29286
|
+
vmsRemarks: Joi85.string().allow(null, "").optional(),
|
|
29287
|
+
updatedAt: Joi85.date().optional().allow(null, "")
|
|
29288
|
+
}),
|
|
29289
|
+
visitorId: Joi85.string().optional().allow(null, "")
|
|
29290
|
+
});
|
|
29291
|
+
const { error } = schema2.validate({ nfcList, visitorId });
|
|
29292
|
+
if (error) {
|
|
29293
|
+
return res.status(400).json({ message: error.message });
|
|
29294
|
+
}
|
|
29295
|
+
const result = await updateNFCStatusSvc({ nfcList, visitorId });
|
|
29296
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29297
|
+
} catch (error) {
|
|
29298
|
+
return res.status(500).json({
|
|
29299
|
+
data: null,
|
|
29300
|
+
message: error.message
|
|
29301
|
+
});
|
|
29302
|
+
}
|
|
29303
|
+
};
|
|
29304
|
+
const doorAndLiftDropdown = async (req, res) => {
|
|
29305
|
+
try {
|
|
29306
|
+
const { site, type, userType } = req.query;
|
|
29307
|
+
const schema2 = Joi85.object({
|
|
29308
|
+
site: Joi85.string().hex().required(),
|
|
29309
|
+
type: Joi85.string().required(),
|
|
29310
|
+
userType: Joi85.string().required()
|
|
29311
|
+
});
|
|
29312
|
+
const { error } = schema2.validate({ site, type, userType });
|
|
29313
|
+
if (error) {
|
|
29314
|
+
return res.status(400).json({ message: error.message });
|
|
29315
|
+
}
|
|
29316
|
+
const result = await doorAndLiftDropdownSvc({ site, type, userType });
|
|
29317
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29318
|
+
} catch (error) {
|
|
29319
|
+
return res.status(500).json({
|
|
29320
|
+
data: null,
|
|
29321
|
+
message: error.message
|
|
29322
|
+
});
|
|
29323
|
+
}
|
|
29324
|
+
};
|
|
29325
|
+
const cardReplacement = async (req, res) => {
|
|
29326
|
+
try {
|
|
29327
|
+
const { cardId, remarks } = req.body;
|
|
29328
|
+
const schema2 = Joi85.object({
|
|
29329
|
+
cardId: Joi85.string().required(),
|
|
29330
|
+
remarks: Joi85.string().optional().allow("", null)
|
|
29331
|
+
});
|
|
29332
|
+
const { error } = schema2.validate({ cardId, remarks });
|
|
29333
|
+
if (error) {
|
|
29334
|
+
return res.status(400).json({ message: error.message });
|
|
29335
|
+
}
|
|
29336
|
+
const result = await cardReplacementSvc({ cardId, remarks });
|
|
29337
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29338
|
+
} catch (error) {
|
|
29339
|
+
return res.status(500).json({
|
|
29340
|
+
data: null,
|
|
29341
|
+
message: error.message
|
|
29342
|
+
});
|
|
29343
|
+
}
|
|
29344
|
+
};
|
|
28895
29345
|
return {
|
|
28896
29346
|
addPhysicalCard,
|
|
28897
29347
|
addNonPhysicalCard,
|
|
@@ -28903,7 +29353,12 @@ function useAccessManagementController() {
|
|
|
28903
29353
|
availableAccessCards,
|
|
28904
29354
|
userTypeAccessCards,
|
|
28905
29355
|
assignedAccessCards,
|
|
28906
|
-
acknowlegdeCard
|
|
29356
|
+
acknowlegdeCard,
|
|
29357
|
+
accessandLiftCards,
|
|
29358
|
+
replaceCard,
|
|
29359
|
+
updateNFCStatus,
|
|
29360
|
+
doorAndLiftDropdown,
|
|
29361
|
+
cardReplacement
|
|
28907
29362
|
};
|
|
28908
29363
|
}
|
|
28909
29364
|
|
|
@@ -34587,16 +35042,26 @@ function useOnlineFormRepo() {
|
|
|
34587
35042
|
site = ""
|
|
34588
35043
|
}) {
|
|
34589
35044
|
page = page > 0 ? page - 1 : 0;
|
|
35045
|
+
try {
|
|
35046
|
+
site = new ObjectId103(site);
|
|
35047
|
+
} catch (error) {
|
|
35048
|
+
throw new BadRequestError168("Invalid site ID format.");
|
|
35049
|
+
}
|
|
34590
35050
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
34591
35051
|
const cacheOptions = {
|
|
34592
35052
|
page,
|
|
34593
35053
|
limit,
|
|
34594
35054
|
status,
|
|
35055
|
+
site: site?.toString(),
|
|
34595
35056
|
sort: JSON.stringify(sort)
|
|
34596
35057
|
};
|
|
34597
35058
|
const query = {
|
|
34598
35059
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
|
|
34599
35060
|
};
|
|
35061
|
+
if (site) {
|
|
35062
|
+
query.site = site;
|
|
35063
|
+
cacheOptions.site = site;
|
|
35064
|
+
}
|
|
34600
35065
|
if (search) {
|
|
34601
35066
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
34602
35067
|
cacheOptions.search = search;
|
|
@@ -34940,7 +35405,7 @@ function useOnlineFormController() {
|
|
|
34940
35405
|
}
|
|
34941
35406
|
async function deleteOnlineFormById(req, res, next) {
|
|
34942
35407
|
const validation = Joi106.string().hex().required();
|
|
34943
|
-
const _id = req.
|
|
35408
|
+
const _id = req.query.id;
|
|
34944
35409
|
const { error } = validation.validate(_id);
|
|
34945
35410
|
if (error) {
|
|
34946
35411
|
logger148.log({ level: "error", message: error.message });
|