@7365admin1/core 2.11.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 +12 -0
- package/dist/index.d.ts +54 -5
- package/dist/index.js +793 -145
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +793 -145
- 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(() => {
|
|
@@ -5397,6 +5398,7 @@ function useRoleRepo() {
|
|
|
5397
5398
|
}
|
|
5398
5399
|
}
|
|
5399
5400
|
const { delNamespace, setCache, getCache, delCache } = useCache12(namespace_collection);
|
|
5401
|
+
const { delNamespace: _delDashboardNameSpace } = useCache12("dashboard");
|
|
5400
5402
|
async function addRole(value, session) {
|
|
5401
5403
|
value = new MRole(value);
|
|
5402
5404
|
try {
|
|
@@ -5659,15 +5661,21 @@ function useRoleRepo() {
|
|
|
5659
5661
|
{ session }
|
|
5660
5662
|
);
|
|
5661
5663
|
if (res.modifiedCount === 0) {
|
|
5662
|
-
throw new InternalServerError13("Unable to update
|
|
5664
|
+
throw new InternalServerError13("Unable to update role status.");
|
|
5663
5665
|
}
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
logger16.info(`Cache deleted for key: ${cacheKey}`);
|
|
5666
|
+
delNamespace().then(() => {
|
|
5667
|
+
logger16.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5667
5668
|
}).catch((err) => {
|
|
5668
|
-
logger16.error(
|
|
5669
|
+
logger16.error(
|
|
5670
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5671
|
+
err
|
|
5672
|
+
);
|
|
5673
|
+
});
|
|
5674
|
+
_delDashboardNameSpace().then(() => {
|
|
5675
|
+
logger16.info(`Cache cleared for namespace: dashboard`);
|
|
5676
|
+
}).catch((err) => {
|
|
5677
|
+
logger16.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
5669
5678
|
});
|
|
5670
|
-
return "Successfully deleted role.";
|
|
5671
5679
|
} catch (error) {
|
|
5672
5680
|
throw new InternalServerError13("Failed to delete role.");
|
|
5673
5681
|
}
|
|
@@ -6764,7 +6772,7 @@ function useRoleController() {
|
|
|
6764
6772
|
}
|
|
6765
6773
|
async function deleteRole(req, res, next) {
|
|
6766
6774
|
const validation = Joi15.string().hex().required();
|
|
6767
|
-
const _id = req.
|
|
6775
|
+
const _id = req.query.id;
|
|
6768
6776
|
const { error } = validation.validate(_id);
|
|
6769
6777
|
if (error) {
|
|
6770
6778
|
logger21.log({ level: "error", message: error.message });
|
|
@@ -6873,7 +6881,7 @@ function useMemberService() {
|
|
|
6873
6881
|
throw new BadRequestError29("No owner role found.");
|
|
6874
6882
|
}
|
|
6875
6883
|
const roles = owner.map((r) => r._id?.toString() ?? "");
|
|
6876
|
-
const ownerMembers = await getByRoles(roles, type);
|
|
6884
|
+
const ownerMembers = await getByRoles(roles, type = "");
|
|
6877
6885
|
if (!ownerMembers.length) {
|
|
6878
6886
|
throw new BadRequestError29("No owner members found.");
|
|
6879
6887
|
}
|
|
@@ -7415,7 +7423,7 @@ function useFileController() {
|
|
|
7415
7423
|
}
|
|
7416
7424
|
async function deleteFile(req, res, next) {
|
|
7417
7425
|
const validation = Joi18.string().hex().required();
|
|
7418
|
-
const _id = req.
|
|
7426
|
+
const _id = req.query.id;
|
|
7419
7427
|
const { error } = validation.validate(_id);
|
|
7420
7428
|
if (error) {
|
|
7421
7429
|
logger25.log({ level: "error", message: error.message });
|
|
@@ -10893,7 +10901,6 @@ function useFeedbackController() {
|
|
|
10893
10901
|
async function deleteFeedback(req, res, next) {
|
|
10894
10902
|
const validation = Joi28.string().hex().required();
|
|
10895
10903
|
const _id = req.query.id;
|
|
10896
|
-
console.log(_id);
|
|
10897
10904
|
const { error } = validation.validate(_id);
|
|
10898
10905
|
if (error) {
|
|
10899
10906
|
logger39.log({ level: "error", message: error.message });
|
|
@@ -14668,7 +14675,7 @@ function MPerson(value) {
|
|
|
14668
14675
|
return {
|
|
14669
14676
|
_id: value._id,
|
|
14670
14677
|
name: value.name,
|
|
14671
|
-
contact: value.contact,
|
|
14678
|
+
contact: value.contact ?? "",
|
|
14672
14679
|
block: value.block,
|
|
14673
14680
|
level: value.level,
|
|
14674
14681
|
unit: value.unit,
|
|
@@ -15130,7 +15137,8 @@ function usePersonRepo() {
|
|
|
15130
15137
|
$or: [
|
|
15131
15138
|
{ name: { $regex: search, $options: "i" } },
|
|
15132
15139
|
{ email: { $regex: search, $options: "i" } },
|
|
15133
|
-
{ nric: { $regex: search, $options: "i" } }
|
|
15140
|
+
{ nric: { $regex: search, $options: "i" } },
|
|
15141
|
+
{ "plates.plateNumber": { $regex: search, $options: "i" } }
|
|
15134
15142
|
]
|
|
15135
15143
|
},
|
|
15136
15144
|
...ObjectId44.isValid(org) && { org: new ObjectId44(org) },
|
|
@@ -18555,7 +18563,7 @@ function useVisitorTransactionService() {
|
|
|
18555
18563
|
} else {
|
|
18556
18564
|
const payload = {
|
|
18557
18565
|
name: value.name || "",
|
|
18558
|
-
contact: value.contact,
|
|
18566
|
+
contact: value.contact ?? "",
|
|
18559
18567
|
nric,
|
|
18560
18568
|
type: value.type,
|
|
18561
18569
|
companyName: value.company ? [value.company] : [],
|
|
@@ -20842,13 +20850,38 @@ function usePatrolRouteRepo() {
|
|
|
20842
20850
|
throw error;
|
|
20843
20851
|
}
|
|
20844
20852
|
}
|
|
20853
|
+
async function getById(_id, session) {
|
|
20854
|
+
try {
|
|
20855
|
+
_id = new ObjectId60(_id);
|
|
20856
|
+
} catch (error) {
|
|
20857
|
+
throw new BadRequestError107("Invalid patrol log ID format.");
|
|
20858
|
+
}
|
|
20859
|
+
const cacheKey = makeCacheKey33(namespace_collection, { _id });
|
|
20860
|
+
const cachedData = await getCache(cacheKey);
|
|
20861
|
+
if (cachedData) {
|
|
20862
|
+
logger89.info(`Cache hit for key: ${cacheKey}`);
|
|
20863
|
+
return cachedData;
|
|
20864
|
+
}
|
|
20865
|
+
try {
|
|
20866
|
+
const data = await collection.findOne({ _id }, { session });
|
|
20867
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
20868
|
+
logger89.info(`Cache set for key: ${cacheKey}`);
|
|
20869
|
+
}).catch((err) => {
|
|
20870
|
+
logger89.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
20871
|
+
});
|
|
20872
|
+
return data;
|
|
20873
|
+
} catch (error) {
|
|
20874
|
+
throw error;
|
|
20875
|
+
}
|
|
20876
|
+
}
|
|
20845
20877
|
return {
|
|
20846
20878
|
createTextIndex,
|
|
20847
20879
|
add,
|
|
20848
20880
|
getAll,
|
|
20849
20881
|
updateById,
|
|
20850
20882
|
deleteById,
|
|
20851
|
-
getScheduledRoute
|
|
20883
|
+
getScheduledRoute,
|
|
20884
|
+
getById
|
|
20852
20885
|
};
|
|
20853
20886
|
}
|
|
20854
20887
|
|
|
@@ -20861,7 +20894,8 @@ function usePatrolRouteController() {
|
|
|
20861
20894
|
getAll: _getAll,
|
|
20862
20895
|
updateById: _updateById,
|
|
20863
20896
|
deleteById: _deleteById,
|
|
20864
|
-
getScheduledRoute: _getScheduledRoute
|
|
20897
|
+
getScheduledRoute: _getScheduledRoute,
|
|
20898
|
+
getById: _getById
|
|
20865
20899
|
} = usePatrolRouteRepo();
|
|
20866
20900
|
async function add(req, res, next) {
|
|
20867
20901
|
const data = { ...req.body };
|
|
@@ -21029,12 +21063,34 @@ function usePatrolRouteController() {
|
|
|
21029
21063
|
return;
|
|
21030
21064
|
}
|
|
21031
21065
|
}
|
|
21066
|
+
async function getById(req, res, next) {
|
|
21067
|
+
const id = req.params.id;
|
|
21068
|
+
const validation = Joi64.object({
|
|
21069
|
+
id: Joi64.string().hex().required()
|
|
21070
|
+
});
|
|
21071
|
+
const { error } = validation.validate({ id });
|
|
21072
|
+
if (error) {
|
|
21073
|
+
next(new BadRequestError108(error.message));
|
|
21074
|
+
return;
|
|
21075
|
+
}
|
|
21076
|
+
try {
|
|
21077
|
+
const routes = await _getById(id);
|
|
21078
|
+
res.json({
|
|
21079
|
+
message: "Successfully retrieved patrol routes.",
|
|
21080
|
+
data: routes
|
|
21081
|
+
});
|
|
21082
|
+
return;
|
|
21083
|
+
} catch (error2) {
|
|
21084
|
+
next(error2);
|
|
21085
|
+
}
|
|
21086
|
+
}
|
|
21032
21087
|
return {
|
|
21033
21088
|
add,
|
|
21034
21089
|
getAll,
|
|
21035
21090
|
updateById,
|
|
21036
21091
|
deleteById,
|
|
21037
|
-
getScheduledRoute
|
|
21092
|
+
getScheduledRoute,
|
|
21093
|
+
getById
|
|
21038
21094
|
};
|
|
21039
21095
|
}
|
|
21040
21096
|
|
|
@@ -21293,6 +21349,30 @@ function usePatrolLogRepo() {
|
|
|
21293
21349
|
throw error;
|
|
21294
21350
|
}
|
|
21295
21351
|
}
|
|
21352
|
+
async function getById(_id, session) {
|
|
21353
|
+
try {
|
|
21354
|
+
_id = new ObjectId62(_id);
|
|
21355
|
+
} catch (error) {
|
|
21356
|
+
throw new BadRequestError110("Invalid patrol log ID format.");
|
|
21357
|
+
}
|
|
21358
|
+
const cacheKey = makeCacheKey34(namespace_collection, { _id });
|
|
21359
|
+
const cachedData = await getCache(cacheKey);
|
|
21360
|
+
if (cachedData) {
|
|
21361
|
+
logger92.info(`Cache hit for key: ${cacheKey}`);
|
|
21362
|
+
return cachedData;
|
|
21363
|
+
}
|
|
21364
|
+
try {
|
|
21365
|
+
const data = await collection.findOne({ _id }, { session });
|
|
21366
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
21367
|
+
logger92.info(`Cache set for key: ${cacheKey}`);
|
|
21368
|
+
}).catch((err) => {
|
|
21369
|
+
logger92.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
21370
|
+
});
|
|
21371
|
+
return data;
|
|
21372
|
+
} catch (error) {
|
|
21373
|
+
throw error;
|
|
21374
|
+
}
|
|
21375
|
+
}
|
|
21296
21376
|
function delCachedData() {
|
|
21297
21377
|
delNamespace().then(() => {
|
|
21298
21378
|
logger92.log({
|
|
@@ -21312,7 +21392,8 @@ function usePatrolLogRepo() {
|
|
|
21312
21392
|
add,
|
|
21313
21393
|
getAll,
|
|
21314
21394
|
updateById,
|
|
21315
|
-
deleteById
|
|
21395
|
+
deleteById,
|
|
21396
|
+
getById
|
|
21316
21397
|
};
|
|
21317
21398
|
}
|
|
21318
21399
|
|
|
@@ -21389,7 +21470,8 @@ function usePatrolLogController() {
|
|
|
21389
21470
|
const {
|
|
21390
21471
|
getAll: _getAll,
|
|
21391
21472
|
updateById: _updateById,
|
|
21392
|
-
deleteById: _deleteById
|
|
21473
|
+
deleteById: _deleteById,
|
|
21474
|
+
getById: _getById
|
|
21393
21475
|
} = usePatrolLogRepo();
|
|
21394
21476
|
const { add: _add } = usePatrolLogService();
|
|
21395
21477
|
async function add(req, res, next) {
|
|
@@ -21501,7 +21583,28 @@ function usePatrolLogController() {
|
|
|
21501
21583
|
return;
|
|
21502
21584
|
}
|
|
21503
21585
|
}
|
|
21504
|
-
|
|
21586
|
+
async function getById(req, res, next) {
|
|
21587
|
+
const id = req.params.id;
|
|
21588
|
+
const validation = Joi66.object({
|
|
21589
|
+
id: Joi66.string().hex().required()
|
|
21590
|
+
});
|
|
21591
|
+
const { error } = validation.validate({ id });
|
|
21592
|
+
if (error) {
|
|
21593
|
+
next(new BadRequestError112(error.message));
|
|
21594
|
+
return;
|
|
21595
|
+
}
|
|
21596
|
+
try {
|
|
21597
|
+
const logs = await _getById(id);
|
|
21598
|
+
res.json({
|
|
21599
|
+
message: "Successfully retrieved patrol log.",
|
|
21600
|
+
data: logs
|
|
21601
|
+
});
|
|
21602
|
+
return;
|
|
21603
|
+
} catch (error2) {
|
|
21604
|
+
next(error2);
|
|
21605
|
+
}
|
|
21606
|
+
}
|
|
21607
|
+
return { add, getAll, updateById, deleteById, getById };
|
|
21505
21608
|
}
|
|
21506
21609
|
|
|
21507
21610
|
// src/models/site-facility.model.ts
|
|
@@ -23616,16 +23719,26 @@ function useDocumentManagementRepo() {
|
|
|
23616
23719
|
site = ""
|
|
23617
23720
|
}) {
|
|
23618
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
|
+
}
|
|
23619
23727
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
23620
23728
|
const cacheOptions = {
|
|
23621
23729
|
page,
|
|
23622
23730
|
limit,
|
|
23623
23731
|
status,
|
|
23732
|
+
site: site?.toString(),
|
|
23624
23733
|
sort: JSON.stringify(sort)
|
|
23625
23734
|
};
|
|
23626
23735
|
const query = {
|
|
23627
23736
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
|
|
23628
23737
|
};
|
|
23738
|
+
if (site) {
|
|
23739
|
+
query.site = site;
|
|
23740
|
+
cacheOptions.site = site;
|
|
23741
|
+
}
|
|
23629
23742
|
if (search) {
|
|
23630
23743
|
query.$or = [
|
|
23631
23744
|
{ name: { $regex: search, $options: "i" } },
|
|
@@ -24034,7 +24147,7 @@ function useDocumentManagementController() {
|
|
|
24034
24147
|
}
|
|
24035
24148
|
async function deleteDocumentById(req, res, next) {
|
|
24036
24149
|
const validation = Joi74.string().hex().required();
|
|
24037
|
-
const _id = req.
|
|
24150
|
+
const _id = req.query.id;
|
|
24038
24151
|
const { error } = validation.validate(_id);
|
|
24039
24152
|
if (error) {
|
|
24040
24153
|
logger102.log({ level: "error", message: error.message });
|
|
@@ -27299,11 +27412,11 @@ var EAccessCardTypes = /* @__PURE__ */ ((EAccessCardTypes2) => {
|
|
|
27299
27412
|
EAccessCardTypes2["QR"] = "QRCODE";
|
|
27300
27413
|
return EAccessCardTypes2;
|
|
27301
27414
|
})(EAccessCardTypes || {});
|
|
27302
|
-
var EAccessCardUserTypes = /* @__PURE__ */ ((
|
|
27303
|
-
|
|
27304
|
-
|
|
27305
|
-
|
|
27306
|
-
return
|
|
27415
|
+
var EAccessCardUserTypes = /* @__PURE__ */ ((EAccessCardUserTypes3) => {
|
|
27416
|
+
EAccessCardUserTypes3["RESIDENT"] = "Resident/Tenant";
|
|
27417
|
+
EAccessCardUserTypes3["CONTRACTOR"] = "Contractor";
|
|
27418
|
+
EAccessCardUserTypes3["VISITOR"] = "Visitor";
|
|
27419
|
+
return EAccessCardUserTypes3;
|
|
27307
27420
|
})(EAccessCardUserTypes || {});
|
|
27308
27421
|
var AccessTypeProps = /* @__PURE__ */ ((AccessTypeProps2) => {
|
|
27309
27422
|
AccessTypeProps2["NORMAL"] = "Normal";
|
|
@@ -27404,6 +27517,114 @@ import {
|
|
|
27404
27517
|
useAtlas as useAtlas74
|
|
27405
27518
|
} from "@7365admin1/node-server-utils";
|
|
27406
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";
|
|
27407
27628
|
function UseAccessManagementRepo() {
|
|
27408
27629
|
function collection() {
|
|
27409
27630
|
const db = useAtlas74.getDb();
|
|
@@ -28154,120 +28375,314 @@ function UseAccessManagementRepo() {
|
|
|
28154
28375
|
throw new Error(error.message);
|
|
28155
28376
|
}
|
|
28156
28377
|
}
|
|
28157
|
-
|
|
28158
|
-
|
|
28159
|
-
|
|
28160
|
-
|
|
28161
|
-
|
|
28162
|
-
|
|
28163
|
-
|
|
28164
|
-
|
|
28165
|
-
|
|
28166
|
-
|
|
28167
|
-
|
|
28168
|
-
|
|
28169
|
-
|
|
28170
|
-
|
|
28171
|
-
|
|
28172
|
-
|
|
28173
|
-
|
|
28174
|
-
|
|
28175
|
-
|
|
28176
|
-
|
|
28177
|
-
|
|
28178
|
-
|
|
28179
|
-
|
|
28180
|
-
|
|
28181
|
-
|
|
28182
|
-
|
|
28183
|
-
|
|
28184
|
-
|
|
28185
|
-
|
|
28186
|
-
|
|
28187
|
-
|
|
28188
|
-
|
|
28189
|
-
|
|
28190
|
-
|
|
28191
|
-
);
|
|
28192
|
-
decipher.setAuthTag(new Uint8Array(authTag));
|
|
28193
|
-
const decrypted = Buffer.concat([
|
|
28194
|
-
decipher.update(encrypted),
|
|
28195
|
-
decipher.final()
|
|
28196
|
-
]);
|
|
28197
|
-
return decrypted.toString("utf8");
|
|
28198
|
-
}
|
|
28199
|
-
var minifyXml = (xml) => {
|
|
28200
|
-
return xml.replace(/>\s+</g, "><").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").trim();
|
|
28201
|
-
};
|
|
28202
|
-
var readTemplate = (name, params) => {
|
|
28203
|
-
const template = fs2.readFileSync(
|
|
28204
|
-
path2.join(__dirname, `../src/public/xml-templates/${name}.xml`),
|
|
28205
|
-
"utf-8"
|
|
28206
|
-
);
|
|
28207
|
-
if (!params)
|
|
28208
|
-
return minifyXml(template);
|
|
28209
|
-
const replacedTemplate = Object.entries(params).reduce(
|
|
28210
|
-
(acc, [key, value]) => acc.replace(`{{${key}}}`, value),
|
|
28211
|
-
template
|
|
28212
|
-
);
|
|
28213
|
-
return minifyXml(replacedTemplate);
|
|
28214
|
-
};
|
|
28215
|
-
async function sendCommand(command, url) {
|
|
28216
|
-
try {
|
|
28217
|
-
const decrypt = decryptAcmUrl(url);
|
|
28218
|
-
const response = await axios.post(decrypt, {
|
|
28219
|
-
command
|
|
28220
|
-
});
|
|
28221
|
-
if (response.status === 200 || response.status === 201)
|
|
28222
|
-
return response.data;
|
|
28223
|
-
} catch (error) {
|
|
28224
|
-
return Promise.reject(error);
|
|
28378
|
+
async function acknowlegdeCardRepo(params) {
|
|
28379
|
+
const session = useAtlas74.getClient()?.startSession();
|
|
28380
|
+
try {
|
|
28381
|
+
session?.startTransaction();
|
|
28382
|
+
const { userId, cardId, site } = params;
|
|
28383
|
+
const allUserId = await Promise.all(userId.map(async (id) => new ObjectId83(id)));
|
|
28384
|
+
const allCardId = await Promise.all(cardId.map(async (id) => new ObjectId83(id)));
|
|
28385
|
+
const siteId = new ObjectId83(site);
|
|
28386
|
+
const result = await collection().updateMany(
|
|
28387
|
+
{
|
|
28388
|
+
$or: [
|
|
28389
|
+
{
|
|
28390
|
+
_id: { $in: allCardId },
|
|
28391
|
+
site: siteId
|
|
28392
|
+
},
|
|
28393
|
+
{
|
|
28394
|
+
userId: { $in: allUserId },
|
|
28395
|
+
site: siteId,
|
|
28396
|
+
isActivated: false,
|
|
28397
|
+
replacementStatus: "Issuance"
|
|
28398
|
+
}
|
|
28399
|
+
]
|
|
28400
|
+
},
|
|
28401
|
+
{ $set: { replacementStatus: "Complete" } },
|
|
28402
|
+
{ session }
|
|
28403
|
+
);
|
|
28404
|
+
await session?.commitTransaction();
|
|
28405
|
+
return result;
|
|
28406
|
+
} catch (error) {
|
|
28407
|
+
await session?.abortTransaction();
|
|
28408
|
+
throw new Error(error.message);
|
|
28409
|
+
} finally {
|
|
28410
|
+
await session?.endSession();
|
|
28411
|
+
}
|
|
28225
28412
|
}
|
|
28226
|
-
|
|
28227
|
-
|
|
28228
|
-
|
|
28229
|
-
|
|
28230
|
-
|
|
28231
|
-
|
|
28232
|
-
|
|
28233
|
-
|
|
28234
|
-
|
|
28235
|
-
|
|
28236
|
-
|
|
28237
|
-
|
|
28238
|
-
|
|
28239
|
-
|
|
28240
|
-
|
|
28241
|
-
|
|
28242
|
-
|
|
28243
|
-
|
|
28244
|
-
|
|
28245
|
-
|
|
28246
|
-
|
|
28247
|
-
|
|
28248
|
-
|
|
28249
|
-
|
|
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
|
+
}
|
|
28250
28441
|
}
|
|
28251
|
-
|
|
28252
|
-
|
|
28253
|
-
|
|
28254
|
-
|
|
28255
|
-
|
|
28256
|
-
|
|
28257
|
-
|
|
28258
|
-
|
|
28259
|
-
|
|
28260
|
-
|
|
28261
|
-
|
|
28262
|
-
|
|
28263
|
-
|
|
28264
|
-
|
|
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
|
+
}
|
|
28265
28546
|
}
|
|
28266
|
-
|
|
28267
|
-
|
|
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
|
+
}
|
|
28662
|
+
return {
|
|
28663
|
+
createIndexes,
|
|
28664
|
+
createIndexForEntrypass,
|
|
28665
|
+
addPhysicalCardRepo,
|
|
28666
|
+
addNonPhysicalCardRepo,
|
|
28667
|
+
accessManagementSettingsRepo,
|
|
28668
|
+
allAccessCardsCountsRepo,
|
|
28669
|
+
availableAccessCardsRepo,
|
|
28670
|
+
userTypeAccessCardsRepo,
|
|
28671
|
+
assignedAccessCardsRepo,
|
|
28672
|
+
acknowlegdeCardRepo,
|
|
28673
|
+
accessandLiftCardsRepo,
|
|
28674
|
+
replaceCardRepo,
|
|
28675
|
+
updateNFCStatusRepo,
|
|
28676
|
+
doorAndLiftDropdownRepo,
|
|
28677
|
+
cardReplacementRepo
|
|
28678
|
+
};
|
|
28679
|
+
}
|
|
28680
|
+
|
|
28681
|
+
// src/controllers/access-management.controller.ts
|
|
28682
|
+
import Joi85 from "joi";
|
|
28268
28683
|
|
|
28269
28684
|
// src/services/access-management.service.ts
|
|
28270
|
-
import { parseStringPromise } from "xml2js";
|
|
28685
|
+
import { parseStringPromise as parseStringPromise2 } from "xml2js";
|
|
28271
28686
|
import { useCache as useCache47 } from "@7365admin1/node-server-utils";
|
|
28272
28687
|
var namespace = "cache:acm";
|
|
28273
28688
|
function useAccessManagementSvc() {
|
|
@@ -28278,7 +28693,13 @@ function useAccessManagementSvc() {
|
|
|
28278
28693
|
allAccessCardsCountsRepo,
|
|
28279
28694
|
availableAccessCardsRepo,
|
|
28280
28695
|
userTypeAccessCardsRepo,
|
|
28281
|
-
assignedAccessCardsRepo
|
|
28696
|
+
assignedAccessCardsRepo,
|
|
28697
|
+
acknowlegdeCardRepo,
|
|
28698
|
+
accessandLiftCardsRepo,
|
|
28699
|
+
replaceCardRepo,
|
|
28700
|
+
updateNFCStatusRepo,
|
|
28701
|
+
doorAndLiftDropdownRepo,
|
|
28702
|
+
cardReplacementRepo
|
|
28282
28703
|
} = UseAccessManagementRepo();
|
|
28283
28704
|
const addPhysicalCardSvc = async (payload) => {
|
|
28284
28705
|
try {
|
|
@@ -28320,7 +28741,7 @@ function useAccessManagementSvc() {
|
|
|
28320
28741
|
}
|
|
28321
28742
|
const command = readTemplate("door-levels");
|
|
28322
28743
|
const response = await sendCommand(command, params.acm_url);
|
|
28323
|
-
const res = await
|
|
28744
|
+
const res = await parseStringPromise2(response, { explicitArray: false });
|
|
28324
28745
|
const format = await formatDoorAccessLevels(res);
|
|
28325
28746
|
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28326
28747
|
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
@@ -28343,7 +28764,7 @@ function useAccessManagementSvc() {
|
|
|
28343
28764
|
}
|
|
28344
28765
|
const command = readTemplate("lift-levels");
|
|
28345
28766
|
const response = await sendCommand(command, params.acm_url);
|
|
28346
|
-
const res = await
|
|
28767
|
+
const res = await parseStringPromise2(response, { explicitArray: false });
|
|
28347
28768
|
const format = await formatLiftAccessLevels(res);
|
|
28348
28769
|
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28349
28770
|
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
@@ -28354,10 +28775,22 @@ function useAccessManagementSvc() {
|
|
|
28354
28775
|
};
|
|
28355
28776
|
const accessGroupsSvc = async (params) => {
|
|
28356
28777
|
try {
|
|
28778
|
+
const key = `${namespace}:${params.user}:access-groups`;
|
|
28779
|
+
const listKey = `${namespace}:${params.user}:list`;
|
|
28780
|
+
const { redis } = useCache47(key);
|
|
28781
|
+
const cachedData = await getCache({ key, redis });
|
|
28782
|
+
if (cachedData) {
|
|
28783
|
+
console.log("\u26A1 Cache hit:", key);
|
|
28784
|
+
redis.expire(key, 60).catch(console.error);
|
|
28785
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28786
|
+
return cachedData;
|
|
28787
|
+
}
|
|
28357
28788
|
const command = readTemplate("access-group");
|
|
28358
28789
|
const response = await sendCommand(command, params.acm_url);
|
|
28359
|
-
const res = await
|
|
28790
|
+
const res = await parseStringPromise2(response, { explicitArray: false });
|
|
28360
28791
|
const format = await formatAccessGroup(res);
|
|
28792
|
+
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28793
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28361
28794
|
return format;
|
|
28362
28795
|
} catch (err) {
|
|
28363
28796
|
throw new Error(err.message);
|
|
@@ -28403,6 +28836,54 @@ function useAccessManagementSvc() {
|
|
|
28403
28836
|
throw new Error(err.message);
|
|
28404
28837
|
}
|
|
28405
28838
|
};
|
|
28839
|
+
const acknowlegdeCardSvc = async (params) => {
|
|
28840
|
+
try {
|
|
28841
|
+
const response = await acknowlegdeCardRepo({ ...params });
|
|
28842
|
+
return response;
|
|
28843
|
+
} catch (err) {
|
|
28844
|
+
throw new Error(err.message);
|
|
28845
|
+
}
|
|
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
|
+
};
|
|
28406
28887
|
return {
|
|
28407
28888
|
addPhysicalCardSvc,
|
|
28408
28889
|
addNonPhysicalCardSvc,
|
|
@@ -28413,7 +28894,13 @@ function useAccessManagementSvc() {
|
|
|
28413
28894
|
allAccessCardsCountsSvc,
|
|
28414
28895
|
availableAccessCardsSvc,
|
|
28415
28896
|
userTypeAccessCardsSvc,
|
|
28416
|
-
assignedAccessCardsSvc
|
|
28897
|
+
assignedAccessCardsSvc,
|
|
28898
|
+
acknowlegdeCardSvc,
|
|
28899
|
+
accessandLiftCardsSvc,
|
|
28900
|
+
replaceCardSvc,
|
|
28901
|
+
updateNFCStatusSvc,
|
|
28902
|
+
doorAndLiftDropdownSvc,
|
|
28903
|
+
cardReplacementSvc
|
|
28417
28904
|
};
|
|
28418
28905
|
}
|
|
28419
28906
|
|
|
@@ -28429,7 +28916,13 @@ function useAccessManagementController() {
|
|
|
28429
28916
|
allAccessCardsCountsSvc,
|
|
28430
28917
|
availableAccessCardsSvc,
|
|
28431
28918
|
userTypeAccessCardsSvc,
|
|
28432
|
-
assignedAccessCardsSvc
|
|
28919
|
+
assignedAccessCardsSvc,
|
|
28920
|
+
acknowlegdeCardSvc,
|
|
28921
|
+
accessandLiftCardsSvc,
|
|
28922
|
+
replaceCardSvc,
|
|
28923
|
+
updateNFCStatusSvc,
|
|
28924
|
+
doorAndLiftDropdownSvc,
|
|
28925
|
+
cardReplacementSvc
|
|
28433
28926
|
} = useAccessManagementSvc();
|
|
28434
28927
|
const addPhysicalCard = async (req, res) => {
|
|
28435
28928
|
try {
|
|
@@ -28501,7 +28994,7 @@ function useAccessManagementController() {
|
|
|
28501
28994
|
accessGroup: Joi85.array().items(Joi85.string().required()).required(),
|
|
28502
28995
|
userType: Joi85.string().required(),
|
|
28503
28996
|
doorName: Joi85.string().required(),
|
|
28504
|
-
liftName: Joi85.string().
|
|
28997
|
+
liftName: Joi85.string().optional().allow("", null),
|
|
28505
28998
|
unit: Joi85.array().items(Joi85.string()).optional().allow(null),
|
|
28506
28999
|
startDate: Joi85.date().required(),
|
|
28507
29000
|
endDate: Joi85.date().required(),
|
|
@@ -28592,10 +29085,11 @@ function useAccessManagementController() {
|
|
|
28592
29085
|
const accessGroups = async (req, res) => {
|
|
28593
29086
|
try {
|
|
28594
29087
|
const { acm_url } = req.query;
|
|
29088
|
+
const user = req.cookies?.sid;
|
|
28595
29089
|
if (!acm_url || typeof acm_url !== "string") {
|
|
28596
29090
|
throw new Error("Access Control URL is required");
|
|
28597
29091
|
}
|
|
28598
|
-
const result = await accessGroupsSvc({ acm_url });
|
|
29092
|
+
const result = await accessGroupsSvc({ acm_url, user });
|
|
28599
29093
|
return res.status(200).json({ message: "Success", data: result });
|
|
28600
29094
|
} catch (error) {
|
|
28601
29095
|
return res.status(400).json({
|
|
@@ -28710,6 +29204,144 @@ function useAccessManagementController() {
|
|
|
28710
29204
|
});
|
|
28711
29205
|
}
|
|
28712
29206
|
};
|
|
29207
|
+
const acknowlegdeCard = async (req, res) => {
|
|
29208
|
+
try {
|
|
29209
|
+
const { userId, site, cardId } = req.body;
|
|
29210
|
+
const schema2 = Joi85.object({
|
|
29211
|
+
userId: Joi85.array().items(Joi85.string().hex()).required(),
|
|
29212
|
+
cardId: Joi85.array().items(Joi85.string().hex()).required(),
|
|
29213
|
+
site: Joi85.string().hex().required()
|
|
29214
|
+
});
|
|
29215
|
+
const { error } = schema2.validate({ userId, cardId, site });
|
|
29216
|
+
if (error) {
|
|
29217
|
+
return res.status(400).json({ message: error.message });
|
|
29218
|
+
}
|
|
29219
|
+
const result = await acknowlegdeCardSvc({ userId, cardId, site });
|
|
29220
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29221
|
+
} catch (error) {
|
|
29222
|
+
return res.status(500).json({
|
|
29223
|
+
data: null,
|
|
29224
|
+
message: error.message
|
|
29225
|
+
});
|
|
29226
|
+
}
|
|
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
|
+
};
|
|
28713
29345
|
return {
|
|
28714
29346
|
addPhysicalCard,
|
|
28715
29347
|
addNonPhysicalCard,
|
|
@@ -28720,7 +29352,13 @@ function useAccessManagementController() {
|
|
|
28720
29352
|
allAccessCardsCounts,
|
|
28721
29353
|
availableAccessCards,
|
|
28722
29354
|
userTypeAccessCards,
|
|
28723
|
-
assignedAccessCards
|
|
29355
|
+
assignedAccessCards,
|
|
29356
|
+
acknowlegdeCard,
|
|
29357
|
+
accessandLiftCards,
|
|
29358
|
+
replaceCard,
|
|
29359
|
+
updateNFCStatus,
|
|
29360
|
+
doorAndLiftDropdown,
|
|
29361
|
+
cardReplacement
|
|
28724
29362
|
};
|
|
28725
29363
|
}
|
|
28726
29364
|
|
|
@@ -34404,16 +35042,26 @@ function useOnlineFormRepo() {
|
|
|
34404
35042
|
site = ""
|
|
34405
35043
|
}) {
|
|
34406
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
|
+
}
|
|
34407
35050
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
34408
35051
|
const cacheOptions = {
|
|
34409
35052
|
page,
|
|
34410
35053
|
limit,
|
|
34411
35054
|
status,
|
|
35055
|
+
site: site?.toString(),
|
|
34412
35056
|
sort: JSON.stringify(sort)
|
|
34413
35057
|
};
|
|
34414
35058
|
const query = {
|
|
34415
35059
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
|
|
34416
35060
|
};
|
|
35061
|
+
if (site) {
|
|
35062
|
+
query.site = site;
|
|
35063
|
+
cacheOptions.site = site;
|
|
35064
|
+
}
|
|
34417
35065
|
if (search) {
|
|
34418
35066
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
34419
35067
|
cacheOptions.search = search;
|
|
@@ -34757,7 +35405,7 @@ function useOnlineFormController() {
|
|
|
34757
35405
|
}
|
|
34758
35406
|
async function deleteOnlineFormById(req, res, next) {
|
|
34759
35407
|
const validation = Joi106.string().hex().required();
|
|
34760
|
-
const _id = req.
|
|
35408
|
+
const _id = req.query.id;
|
|
34761
35409
|
const { error } = validation.validate(_id);
|
|
34762
35410
|
if (error) {
|
|
34763
35411
|
logger148.log({ level: "error", message: error.message });
|