@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.js
CHANGED
|
@@ -4968,7 +4968,8 @@ function useMemberRepo() {
|
|
|
4968
4968
|
try {
|
|
4969
4969
|
const data = await collection.find({
|
|
4970
4970
|
role: { $in: roles },
|
|
4971
|
-
type,
|
|
4971
|
+
// type,
|
|
4972
|
+
// ...(type && { type }),
|
|
4972
4973
|
status: "active"
|
|
4973
4974
|
}).toArray();
|
|
4974
4975
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
@@ -5598,6 +5599,7 @@ function useRoleRepo() {
|
|
|
5598
5599
|
}
|
|
5599
5600
|
}
|
|
5600
5601
|
const { delNamespace, setCache, getCache, delCache } = (0, import_node_server_utils23.useCache)(namespace_collection);
|
|
5602
|
+
const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils23.useCache)("dashboard");
|
|
5601
5603
|
async function addRole(value, session) {
|
|
5602
5604
|
value = new MRole(value);
|
|
5603
5605
|
try {
|
|
@@ -5860,15 +5862,21 @@ function useRoleRepo() {
|
|
|
5860
5862
|
{ session }
|
|
5861
5863
|
);
|
|
5862
5864
|
if (res.modifiedCount === 0) {
|
|
5863
|
-
throw new import_node_server_utils23.InternalServerError("Unable to update
|
|
5865
|
+
throw new import_node_server_utils23.InternalServerError("Unable to update role status.");
|
|
5864
5866
|
}
|
|
5865
|
-
|
|
5866
|
-
|
|
5867
|
-
import_node_server_utils23.logger.info(`Cache deleted for key: ${cacheKey}`);
|
|
5867
|
+
delNamespace().then(() => {
|
|
5868
|
+
import_node_server_utils23.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5868
5869
|
}).catch((err) => {
|
|
5869
|
-
import_node_server_utils23.logger.error(
|
|
5870
|
+
import_node_server_utils23.logger.error(
|
|
5871
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5872
|
+
err
|
|
5873
|
+
);
|
|
5874
|
+
});
|
|
5875
|
+
_delDashboardNameSpace().then(() => {
|
|
5876
|
+
import_node_server_utils23.logger.info(`Cache cleared for namespace: dashboard`);
|
|
5877
|
+
}).catch((err) => {
|
|
5878
|
+
import_node_server_utils23.logger.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
5870
5879
|
});
|
|
5871
|
-
return "Successfully deleted role.";
|
|
5872
5880
|
} catch (error) {
|
|
5873
5881
|
throw new import_node_server_utils23.InternalServerError("Failed to delete role.");
|
|
5874
5882
|
}
|
|
@@ -6957,7 +6965,7 @@ function useRoleController() {
|
|
|
6957
6965
|
}
|
|
6958
6966
|
async function deleteRole(req, res, next) {
|
|
6959
6967
|
const validation = import_joi15.default.string().hex().required();
|
|
6960
|
-
const _id = req.
|
|
6968
|
+
const _id = req.query.id;
|
|
6961
6969
|
const { error } = validation.validate(_id);
|
|
6962
6970
|
if (error) {
|
|
6963
6971
|
import_node_server_utils29.logger.log({ level: "error", message: error.message });
|
|
@@ -7066,7 +7074,7 @@ function useMemberService() {
|
|
|
7066
7074
|
throw new import_node_server_utils30.BadRequestError("No owner role found.");
|
|
7067
7075
|
}
|
|
7068
7076
|
const roles = owner.map((r) => r._id?.toString() ?? "");
|
|
7069
|
-
const ownerMembers = await getByRoles(roles, type);
|
|
7077
|
+
const ownerMembers = await getByRoles(roles, type = "");
|
|
7070
7078
|
if (!ownerMembers.length) {
|
|
7071
7079
|
throw new import_node_server_utils30.BadRequestError("No owner members found.");
|
|
7072
7080
|
}
|
|
@@ -7608,7 +7616,7 @@ function useFileController() {
|
|
|
7608
7616
|
}
|
|
7609
7617
|
async function deleteFile(req, res, next) {
|
|
7610
7618
|
const validation = import_joi18.default.string().hex().required();
|
|
7611
|
-
const _id = req.
|
|
7619
|
+
const _id = req.query.id;
|
|
7612
7620
|
const { error } = validation.validate(_id);
|
|
7613
7621
|
if (error) {
|
|
7614
7622
|
import_node_server_utils34.logger.log({ level: "error", message: error.message });
|
|
@@ -11022,7 +11030,6 @@ function useFeedbackController() {
|
|
|
11022
11030
|
async function deleteFeedback(req, res, next) {
|
|
11023
11031
|
const validation = import_joi28.default.string().hex().required();
|
|
11024
11032
|
const _id = req.query.id;
|
|
11025
|
-
console.log(_id);
|
|
11026
11033
|
const { error } = validation.validate(_id);
|
|
11027
11034
|
if (error) {
|
|
11028
11035
|
import_node_server_utils55.logger.log({ level: "error", message: error.message });
|
|
@@ -14727,7 +14734,7 @@ function MPerson(value) {
|
|
|
14727
14734
|
return {
|
|
14728
14735
|
_id: value._id,
|
|
14729
14736
|
name: value.name,
|
|
14730
|
-
contact: value.contact,
|
|
14737
|
+
contact: value.contact ?? "",
|
|
14731
14738
|
block: value.block,
|
|
14732
14739
|
level: value.level,
|
|
14733
14740
|
unit: value.unit,
|
|
@@ -15180,7 +15187,8 @@ function usePersonRepo() {
|
|
|
15180
15187
|
$or: [
|
|
15181
15188
|
{ name: { $regex: search, $options: "i" } },
|
|
15182
15189
|
{ email: { $regex: search, $options: "i" } },
|
|
15183
|
-
{ nric: { $regex: search, $options: "i" } }
|
|
15190
|
+
{ nric: { $regex: search, $options: "i" } },
|
|
15191
|
+
{ "plates.plateNumber": { $regex: search, $options: "i" } }
|
|
15184
15192
|
]
|
|
15185
15193
|
},
|
|
15186
15194
|
...import_mongodb44.ObjectId.isValid(org) && { org: new import_mongodb44.ObjectId(org) },
|
|
@@ -18553,7 +18561,7 @@ function useVisitorTransactionService() {
|
|
|
18553
18561
|
} else {
|
|
18554
18562
|
const payload = {
|
|
18555
18563
|
name: value.name || "",
|
|
18556
|
-
contact: value.contact,
|
|
18564
|
+
contact: value.contact ?? "",
|
|
18557
18565
|
nric,
|
|
18558
18566
|
type: value.type,
|
|
18559
18567
|
companyName: value.company ? [value.company] : [],
|
|
@@ -20802,13 +20810,38 @@ function usePatrolRouteRepo() {
|
|
|
20802
20810
|
throw error;
|
|
20803
20811
|
}
|
|
20804
20812
|
}
|
|
20813
|
+
async function getById(_id, session) {
|
|
20814
|
+
try {
|
|
20815
|
+
_id = new import_mongodb60.ObjectId(_id);
|
|
20816
|
+
} catch (error) {
|
|
20817
|
+
throw new import_node_server_utils113.BadRequestError("Invalid patrol log ID format.");
|
|
20818
|
+
}
|
|
20819
|
+
const cacheKey = (0, import_node_server_utils113.makeCacheKey)(namespace_collection, { _id });
|
|
20820
|
+
const cachedData = await getCache(cacheKey);
|
|
20821
|
+
if (cachedData) {
|
|
20822
|
+
import_node_server_utils113.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
20823
|
+
return cachedData;
|
|
20824
|
+
}
|
|
20825
|
+
try {
|
|
20826
|
+
const data = await collection.findOne({ _id }, { session });
|
|
20827
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
20828
|
+
import_node_server_utils113.logger.info(`Cache set for key: ${cacheKey}`);
|
|
20829
|
+
}).catch((err) => {
|
|
20830
|
+
import_node_server_utils113.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
20831
|
+
});
|
|
20832
|
+
return data;
|
|
20833
|
+
} catch (error) {
|
|
20834
|
+
throw error;
|
|
20835
|
+
}
|
|
20836
|
+
}
|
|
20805
20837
|
return {
|
|
20806
20838
|
createTextIndex,
|
|
20807
20839
|
add,
|
|
20808
20840
|
getAll,
|
|
20809
20841
|
updateById,
|
|
20810
20842
|
deleteById,
|
|
20811
|
-
getScheduledRoute
|
|
20843
|
+
getScheduledRoute,
|
|
20844
|
+
getById
|
|
20812
20845
|
};
|
|
20813
20846
|
}
|
|
20814
20847
|
|
|
@@ -20821,7 +20854,8 @@ function usePatrolRouteController() {
|
|
|
20821
20854
|
getAll: _getAll,
|
|
20822
20855
|
updateById: _updateById,
|
|
20823
20856
|
deleteById: _deleteById,
|
|
20824
|
-
getScheduledRoute: _getScheduledRoute
|
|
20857
|
+
getScheduledRoute: _getScheduledRoute,
|
|
20858
|
+
getById: _getById
|
|
20825
20859
|
} = usePatrolRouteRepo();
|
|
20826
20860
|
async function add(req, res, next) {
|
|
20827
20861
|
const data = { ...req.body };
|
|
@@ -20989,12 +21023,34 @@ function usePatrolRouteController() {
|
|
|
20989
21023
|
return;
|
|
20990
21024
|
}
|
|
20991
21025
|
}
|
|
21026
|
+
async function getById(req, res, next) {
|
|
21027
|
+
const id = req.params.id;
|
|
21028
|
+
const validation = import_joi64.default.object({
|
|
21029
|
+
id: import_joi64.default.string().hex().required()
|
|
21030
|
+
});
|
|
21031
|
+
const { error } = validation.validate({ id });
|
|
21032
|
+
if (error) {
|
|
21033
|
+
next(new import_node_server_utils114.BadRequestError(error.message));
|
|
21034
|
+
return;
|
|
21035
|
+
}
|
|
21036
|
+
try {
|
|
21037
|
+
const routes = await _getById(id);
|
|
21038
|
+
res.json({
|
|
21039
|
+
message: "Successfully retrieved patrol routes.",
|
|
21040
|
+
data: routes
|
|
21041
|
+
});
|
|
21042
|
+
return;
|
|
21043
|
+
} catch (error2) {
|
|
21044
|
+
next(error2);
|
|
21045
|
+
}
|
|
21046
|
+
}
|
|
20992
21047
|
return {
|
|
20993
21048
|
add,
|
|
20994
21049
|
getAll,
|
|
20995
21050
|
updateById,
|
|
20996
21051
|
deleteById,
|
|
20997
|
-
getScheduledRoute
|
|
21052
|
+
getScheduledRoute,
|
|
21053
|
+
getById
|
|
20998
21054
|
};
|
|
20999
21055
|
}
|
|
21000
21056
|
|
|
@@ -21244,6 +21300,30 @@ function usePatrolLogRepo() {
|
|
|
21244
21300
|
throw error;
|
|
21245
21301
|
}
|
|
21246
21302
|
}
|
|
21303
|
+
async function getById(_id, session) {
|
|
21304
|
+
try {
|
|
21305
|
+
_id = new import_mongodb62.ObjectId(_id);
|
|
21306
|
+
} catch (error) {
|
|
21307
|
+
throw new import_node_server_utils116.BadRequestError("Invalid patrol log ID format.");
|
|
21308
|
+
}
|
|
21309
|
+
const cacheKey = (0, import_node_server_utils116.makeCacheKey)(namespace_collection, { _id });
|
|
21310
|
+
const cachedData = await getCache(cacheKey);
|
|
21311
|
+
if (cachedData) {
|
|
21312
|
+
import_node_server_utils116.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
21313
|
+
return cachedData;
|
|
21314
|
+
}
|
|
21315
|
+
try {
|
|
21316
|
+
const data = await collection.findOne({ _id }, { session });
|
|
21317
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
21318
|
+
import_node_server_utils116.logger.info(`Cache set for key: ${cacheKey}`);
|
|
21319
|
+
}).catch((err) => {
|
|
21320
|
+
import_node_server_utils116.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
21321
|
+
});
|
|
21322
|
+
return data;
|
|
21323
|
+
} catch (error) {
|
|
21324
|
+
throw error;
|
|
21325
|
+
}
|
|
21326
|
+
}
|
|
21247
21327
|
function delCachedData() {
|
|
21248
21328
|
delNamespace().then(() => {
|
|
21249
21329
|
import_node_server_utils116.logger.log({
|
|
@@ -21263,7 +21343,8 @@ function usePatrolLogRepo() {
|
|
|
21263
21343
|
add,
|
|
21264
21344
|
getAll,
|
|
21265
21345
|
updateById,
|
|
21266
|
-
deleteById
|
|
21346
|
+
deleteById,
|
|
21347
|
+
getById
|
|
21267
21348
|
};
|
|
21268
21349
|
}
|
|
21269
21350
|
|
|
@@ -21335,7 +21416,8 @@ function usePatrolLogController() {
|
|
|
21335
21416
|
const {
|
|
21336
21417
|
getAll: _getAll,
|
|
21337
21418
|
updateById: _updateById,
|
|
21338
|
-
deleteById: _deleteById
|
|
21419
|
+
deleteById: _deleteById,
|
|
21420
|
+
getById: _getById
|
|
21339
21421
|
} = usePatrolLogRepo();
|
|
21340
21422
|
const { add: _add } = usePatrolLogService();
|
|
21341
21423
|
async function add(req, res, next) {
|
|
@@ -21447,7 +21529,28 @@ function usePatrolLogController() {
|
|
|
21447
21529
|
return;
|
|
21448
21530
|
}
|
|
21449
21531
|
}
|
|
21450
|
-
|
|
21532
|
+
async function getById(req, res, next) {
|
|
21533
|
+
const id = req.params.id;
|
|
21534
|
+
const validation = import_joi66.default.object({
|
|
21535
|
+
id: import_joi66.default.string().hex().required()
|
|
21536
|
+
});
|
|
21537
|
+
const { error } = validation.validate({ id });
|
|
21538
|
+
if (error) {
|
|
21539
|
+
next(new import_node_server_utils118.BadRequestError(error.message));
|
|
21540
|
+
return;
|
|
21541
|
+
}
|
|
21542
|
+
try {
|
|
21543
|
+
const logs = await _getById(id);
|
|
21544
|
+
res.json({
|
|
21545
|
+
message: "Successfully retrieved patrol log.",
|
|
21546
|
+
data: logs
|
|
21547
|
+
});
|
|
21548
|
+
return;
|
|
21549
|
+
} catch (error2) {
|
|
21550
|
+
next(error2);
|
|
21551
|
+
}
|
|
21552
|
+
}
|
|
21553
|
+
return { add, getAll, updateById, deleteById, getById };
|
|
21451
21554
|
}
|
|
21452
21555
|
|
|
21453
21556
|
// src/models/site-facility.model.ts
|
|
@@ -23526,16 +23629,26 @@ function useDocumentManagementRepo() {
|
|
|
23526
23629
|
site = ""
|
|
23527
23630
|
}) {
|
|
23528
23631
|
page = page > 0 ? page - 1 : 0;
|
|
23632
|
+
try {
|
|
23633
|
+
site = new import_mongodb70.ObjectId(site);
|
|
23634
|
+
} catch (error) {
|
|
23635
|
+
throw new import_node_server_utils128.BadRequestError("Invalid site ID format.");
|
|
23636
|
+
}
|
|
23529
23637
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
23530
23638
|
const cacheOptions = {
|
|
23531
23639
|
page,
|
|
23532
23640
|
limit,
|
|
23533
23641
|
status,
|
|
23642
|
+
site: site?.toString(),
|
|
23534
23643
|
sort: JSON.stringify(sort)
|
|
23535
23644
|
};
|
|
23536
23645
|
const query = {
|
|
23537
23646
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
|
|
23538
23647
|
};
|
|
23648
|
+
if (site) {
|
|
23649
|
+
query.site = site;
|
|
23650
|
+
cacheOptions.site = site;
|
|
23651
|
+
}
|
|
23539
23652
|
if (search) {
|
|
23540
23653
|
query.$or = [
|
|
23541
23654
|
{ name: { $regex: search, $options: "i" } },
|
|
@@ -23940,7 +24053,7 @@ function useDocumentManagementController() {
|
|
|
23940
24053
|
}
|
|
23941
24054
|
async function deleteDocumentById(req, res, next) {
|
|
23942
24055
|
const validation = import_joi74.default.string().hex().required();
|
|
23943
|
-
const _id = req.
|
|
24056
|
+
const _id = req.query.id;
|
|
23944
24057
|
const { error } = validation.validate(_id);
|
|
23945
24058
|
if (error) {
|
|
23946
24059
|
import_node_server_utils130.logger.log({ level: "error", message: error.message });
|
|
@@ -27148,11 +27261,11 @@ var EAccessCardTypes = /* @__PURE__ */ ((EAccessCardTypes2) => {
|
|
|
27148
27261
|
EAccessCardTypes2["QR"] = "QRCODE";
|
|
27149
27262
|
return EAccessCardTypes2;
|
|
27150
27263
|
})(EAccessCardTypes || {});
|
|
27151
|
-
var EAccessCardUserTypes = /* @__PURE__ */ ((
|
|
27152
|
-
|
|
27153
|
-
|
|
27154
|
-
|
|
27155
|
-
return
|
|
27264
|
+
var EAccessCardUserTypes = /* @__PURE__ */ ((EAccessCardUserTypes3) => {
|
|
27265
|
+
EAccessCardUserTypes3["RESIDENT"] = "Resident/Tenant";
|
|
27266
|
+
EAccessCardUserTypes3["CONTRACTOR"] = "Contractor";
|
|
27267
|
+
EAccessCardUserTypes3["VISITOR"] = "Visitor";
|
|
27268
|
+
return EAccessCardUserTypes3;
|
|
27156
27269
|
})(EAccessCardUserTypes || {});
|
|
27157
27270
|
var AccessTypeProps = /* @__PURE__ */ ((AccessTypeProps2) => {
|
|
27158
27271
|
AccessTypeProps2["NORMAL"] = "Normal";
|
|
@@ -27249,6 +27362,114 @@ var MAccessCard = class {
|
|
|
27249
27362
|
// src/repositories/access-management.repo.ts
|
|
27250
27363
|
var import_node_server_utils149 = require("@7365admin1/node-server-utils");
|
|
27251
27364
|
var import_mongodb83 = require("mongodb");
|
|
27365
|
+
|
|
27366
|
+
// src/utils/access-management.ts
|
|
27367
|
+
var import_fs2 = __toESM(require("fs"));
|
|
27368
|
+
var import_path = __toESM(require("path"));
|
|
27369
|
+
var import_axios = __toESM(require("axios"));
|
|
27370
|
+
var import_crypto = __toESM(require("crypto"));
|
|
27371
|
+
var ALGORITHM = "aes-256-gcm";
|
|
27372
|
+
var SECRET_KEY = import_crypto.default.createSecretKey(
|
|
27373
|
+
new Uint8Array(import_crypto.default.createHash("sha256").update("acm-secret-key").digest())
|
|
27374
|
+
);
|
|
27375
|
+
function decryptAcmUrl(encryptedText) {
|
|
27376
|
+
const [ivB64, authTagB64, encryptedB64] = encryptedText.split(":");
|
|
27377
|
+
const iv = Buffer.from(ivB64, "base64");
|
|
27378
|
+
const authTag = Buffer.from(authTagB64, "base64");
|
|
27379
|
+
const encrypted = Buffer.from(encryptedB64, "base64");
|
|
27380
|
+
const decipher = import_crypto.default.createDecipheriv(
|
|
27381
|
+
ALGORITHM,
|
|
27382
|
+
SECRET_KEY,
|
|
27383
|
+
new Uint8Array(iv)
|
|
27384
|
+
);
|
|
27385
|
+
decipher.setAuthTag(new Uint8Array(authTag));
|
|
27386
|
+
const decrypted = Buffer.concat([
|
|
27387
|
+
decipher.update(encrypted),
|
|
27388
|
+
decipher.final()
|
|
27389
|
+
]);
|
|
27390
|
+
return decrypted.toString("utf8");
|
|
27391
|
+
}
|
|
27392
|
+
var minifyXml = (xml) => {
|
|
27393
|
+
return xml.replace(/>\s+</g, "><").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").trim();
|
|
27394
|
+
};
|
|
27395
|
+
var readTemplate = (name, params) => {
|
|
27396
|
+
const template = import_fs2.default.readFileSync(
|
|
27397
|
+
import_path.default.join(__dirname, `../src/public/xml-templates/${name}.xml`),
|
|
27398
|
+
"utf-8"
|
|
27399
|
+
);
|
|
27400
|
+
if (!params)
|
|
27401
|
+
return minifyXml(template);
|
|
27402
|
+
const replacedTemplate = Object.entries(params).reduce(
|
|
27403
|
+
(acc, [key, value]) => acc.replace(`{{${key}}}`, value),
|
|
27404
|
+
template
|
|
27405
|
+
);
|
|
27406
|
+
return minifyXml(replacedTemplate);
|
|
27407
|
+
};
|
|
27408
|
+
async function sendCommand(command, url) {
|
|
27409
|
+
try {
|
|
27410
|
+
const decrypt = decryptAcmUrl(url);
|
|
27411
|
+
const response = await import_axios.default.post(decrypt, {
|
|
27412
|
+
command
|
|
27413
|
+
});
|
|
27414
|
+
if (response.status === 200 || response.status === 201)
|
|
27415
|
+
return response.data;
|
|
27416
|
+
} catch (error) {
|
|
27417
|
+
return Promise.reject(error);
|
|
27418
|
+
}
|
|
27419
|
+
}
|
|
27420
|
+
var formatDoorAccessLevels = (data) => {
|
|
27421
|
+
const doorAccessLevels = data.RESULT.TRACKID.SUB_RESULT.ACCESS_LEVEL;
|
|
27422
|
+
return doorAccessLevels.map((door) => {
|
|
27423
|
+
return {
|
|
27424
|
+
name: door._.trim(),
|
|
27425
|
+
// Remove any leading/trailing spaces
|
|
27426
|
+
no: door.$.NO
|
|
27427
|
+
// Extract the number
|
|
27428
|
+
};
|
|
27429
|
+
});
|
|
27430
|
+
};
|
|
27431
|
+
var formatLiftAccessLevels = (data, search) => {
|
|
27432
|
+
const liftAccessLevels = data.RESULT.TRACKID.SUB_RESULT.LIFT_ACCESS_LEVEL;
|
|
27433
|
+
const result = liftAccessLevels.map((level) => {
|
|
27434
|
+
return {
|
|
27435
|
+
name: level._.trim(),
|
|
27436
|
+
no: level.$.NO
|
|
27437
|
+
};
|
|
27438
|
+
});
|
|
27439
|
+
if (search) {
|
|
27440
|
+
return result.filter(
|
|
27441
|
+
(item) => item.name.toLowerCase().includes(search.toLowerCase())
|
|
27442
|
+
);
|
|
27443
|
+
}
|
|
27444
|
+
return result;
|
|
27445
|
+
};
|
|
27446
|
+
var formatAccessGroup = (data, search) => {
|
|
27447
|
+
const accessGroup = data.RESULT.TRACKID.SUB_RESULT.ACCESS_GROUP;
|
|
27448
|
+
const result = accessGroup.map((ag) => {
|
|
27449
|
+
return {
|
|
27450
|
+
no: ag._.trim(),
|
|
27451
|
+
name: ag.$.NAME
|
|
27452
|
+
};
|
|
27453
|
+
});
|
|
27454
|
+
if (search) {
|
|
27455
|
+
return result.filter(
|
|
27456
|
+
(item) => item.name.toLowerCase().includes(search.toLowerCase())
|
|
27457
|
+
);
|
|
27458
|
+
}
|
|
27459
|
+
return result;
|
|
27460
|
+
};
|
|
27461
|
+
var formatEntryPassDate = (date) => {
|
|
27462
|
+
if (!date)
|
|
27463
|
+
return null;
|
|
27464
|
+
const newDate = new Date(date);
|
|
27465
|
+
const year = newDate.getFullYear();
|
|
27466
|
+
const month = String(newDate.getMonth() + 1).padStart(2, "0");
|
|
27467
|
+
const day = String(newDate.getDate()).padStart(2, "0");
|
|
27468
|
+
return `${year}${month}${day}`;
|
|
27469
|
+
};
|
|
27470
|
+
|
|
27471
|
+
// src/repositories/access-management.repo.ts
|
|
27472
|
+
var import_xml2js = require("xml2js");
|
|
27252
27473
|
function UseAccessManagementRepo() {
|
|
27253
27474
|
function collection() {
|
|
27254
27475
|
const db = import_node_server_utils149.useAtlas.getDb();
|
|
@@ -27999,120 +28220,314 @@ function UseAccessManagementRepo() {
|
|
|
27999
28220
|
throw new Error(error.message);
|
|
28000
28221
|
}
|
|
28001
28222
|
}
|
|
28002
|
-
|
|
28003
|
-
|
|
28004
|
-
|
|
28005
|
-
|
|
28006
|
-
|
|
28007
|
-
|
|
28008
|
-
|
|
28009
|
-
|
|
28010
|
-
|
|
28011
|
-
|
|
28012
|
-
|
|
28013
|
-
|
|
28014
|
-
|
|
28015
|
-
|
|
28016
|
-
|
|
28017
|
-
|
|
28018
|
-
|
|
28019
|
-
|
|
28020
|
-
|
|
28021
|
-
|
|
28022
|
-
|
|
28023
|
-
|
|
28024
|
-
|
|
28025
|
-
|
|
28026
|
-
|
|
28027
|
-
|
|
28028
|
-
|
|
28029
|
-
|
|
28030
|
-
|
|
28031
|
-
|
|
28032
|
-
|
|
28033
|
-
|
|
28034
|
-
|
|
28035
|
-
|
|
28036
|
-
);
|
|
28037
|
-
decipher.setAuthTag(new Uint8Array(authTag));
|
|
28038
|
-
const decrypted = Buffer.concat([
|
|
28039
|
-
decipher.update(encrypted),
|
|
28040
|
-
decipher.final()
|
|
28041
|
-
]);
|
|
28042
|
-
return decrypted.toString("utf8");
|
|
28043
|
-
}
|
|
28044
|
-
var minifyXml = (xml) => {
|
|
28045
|
-
return xml.replace(/>\s+</g, "><").replace(/\n/g, "").replace(/\r/g, "").replace(/\t/g, "").trim();
|
|
28046
|
-
};
|
|
28047
|
-
var readTemplate = (name, params) => {
|
|
28048
|
-
const template = import_fs2.default.readFileSync(
|
|
28049
|
-
import_path.default.join(__dirname, `../src/public/xml-templates/${name}.xml`),
|
|
28050
|
-
"utf-8"
|
|
28051
|
-
);
|
|
28052
|
-
if (!params)
|
|
28053
|
-
return minifyXml(template);
|
|
28054
|
-
const replacedTemplate = Object.entries(params).reduce(
|
|
28055
|
-
(acc, [key, value]) => acc.replace(`{{${key}}}`, value),
|
|
28056
|
-
template
|
|
28057
|
-
);
|
|
28058
|
-
return minifyXml(replacedTemplate);
|
|
28059
|
-
};
|
|
28060
|
-
async function sendCommand(command, url) {
|
|
28061
|
-
try {
|
|
28062
|
-
const decrypt = decryptAcmUrl(url);
|
|
28063
|
-
const response = await import_axios.default.post(decrypt, {
|
|
28064
|
-
command
|
|
28065
|
-
});
|
|
28066
|
-
if (response.status === 200 || response.status === 201)
|
|
28067
|
-
return response.data;
|
|
28068
|
-
} catch (error) {
|
|
28069
|
-
return Promise.reject(error);
|
|
28223
|
+
async function acknowlegdeCardRepo(params) {
|
|
28224
|
+
const session = import_node_server_utils149.useAtlas.getClient()?.startSession();
|
|
28225
|
+
try {
|
|
28226
|
+
session?.startTransaction();
|
|
28227
|
+
const { userId, cardId, site } = params;
|
|
28228
|
+
const allUserId = await Promise.all(userId.map(async (id) => new import_mongodb83.ObjectId(id)));
|
|
28229
|
+
const allCardId = await Promise.all(cardId.map(async (id) => new import_mongodb83.ObjectId(id)));
|
|
28230
|
+
const siteId = new import_mongodb83.ObjectId(site);
|
|
28231
|
+
const result = await collection().updateMany(
|
|
28232
|
+
{
|
|
28233
|
+
$or: [
|
|
28234
|
+
{
|
|
28235
|
+
_id: { $in: allCardId },
|
|
28236
|
+
site: siteId
|
|
28237
|
+
},
|
|
28238
|
+
{
|
|
28239
|
+
userId: { $in: allUserId },
|
|
28240
|
+
site: siteId,
|
|
28241
|
+
isActivated: false,
|
|
28242
|
+
replacementStatus: "Issuance"
|
|
28243
|
+
}
|
|
28244
|
+
]
|
|
28245
|
+
},
|
|
28246
|
+
{ $set: { replacementStatus: "Complete" } },
|
|
28247
|
+
{ session }
|
|
28248
|
+
);
|
|
28249
|
+
await session?.commitTransaction();
|
|
28250
|
+
return result;
|
|
28251
|
+
} catch (error) {
|
|
28252
|
+
await session?.abortTransaction();
|
|
28253
|
+
throw new Error(error.message);
|
|
28254
|
+
} finally {
|
|
28255
|
+
await session?.endSession();
|
|
28256
|
+
}
|
|
28070
28257
|
}
|
|
28071
|
-
|
|
28072
|
-
|
|
28073
|
-
|
|
28074
|
-
|
|
28075
|
-
|
|
28076
|
-
|
|
28077
|
-
|
|
28078
|
-
|
|
28079
|
-
|
|
28080
|
-
|
|
28081
|
-
|
|
28082
|
-
|
|
28083
|
-
|
|
28084
|
-
|
|
28085
|
-
|
|
28086
|
-
|
|
28087
|
-
|
|
28088
|
-
|
|
28089
|
-
|
|
28090
|
-
|
|
28091
|
-
|
|
28092
|
-
|
|
28093
|
-
|
|
28094
|
-
|
|
28258
|
+
async function accessandLiftCardsRepo(params) {
|
|
28259
|
+
try {
|
|
28260
|
+
const { accessLevel, liftAccessLevel, site, userType, type } = params;
|
|
28261
|
+
const siteId = new import_mongodb83.ObjectId(site);
|
|
28262
|
+
const query = {
|
|
28263
|
+
site: { $in: [siteId] },
|
|
28264
|
+
userType,
|
|
28265
|
+
type,
|
|
28266
|
+
userId: null,
|
|
28267
|
+
assignedUnit: null,
|
|
28268
|
+
accessLevel,
|
|
28269
|
+
liftAccessLevel,
|
|
28270
|
+
isActivated: true
|
|
28271
|
+
};
|
|
28272
|
+
const result = await collection().aggregate([
|
|
28273
|
+
{
|
|
28274
|
+
$match: query
|
|
28275
|
+
},
|
|
28276
|
+
{
|
|
28277
|
+
$facet: {
|
|
28278
|
+
counts: [{ $count: "count" }]
|
|
28279
|
+
}
|
|
28280
|
+
}
|
|
28281
|
+
], { allowDiskUse: true }).toArray();
|
|
28282
|
+
return result;
|
|
28283
|
+
} catch (error) {
|
|
28284
|
+
throw new Error(error.message);
|
|
28285
|
+
}
|
|
28095
28286
|
}
|
|
28096
|
-
|
|
28097
|
-
|
|
28098
|
-
|
|
28099
|
-
|
|
28100
|
-
|
|
28101
|
-
|
|
28102
|
-
|
|
28103
|
-
|
|
28104
|
-
|
|
28105
|
-
|
|
28106
|
-
|
|
28107
|
-
|
|
28108
|
-
|
|
28109
|
-
|
|
28287
|
+
async function replaceCardRepo(params) {
|
|
28288
|
+
const session = import_node_server_utils149.useAtlas.getClient()?.startSession();
|
|
28289
|
+
try {
|
|
28290
|
+
session?.startTransaction();
|
|
28291
|
+
const siteId = new import_mongodb83.ObjectId(params.site);
|
|
28292
|
+
const userId = new import_mongodb83.ObjectId(params.userId);
|
|
28293
|
+
const cardId = new import_mongodb83.ObjectId(params.cardId);
|
|
28294
|
+
const quantity = 1;
|
|
28295
|
+
const cardCredentials = await collection().findOneAndUpdate(
|
|
28296
|
+
{ _id: cardId },
|
|
28297
|
+
{ $set: { replacementStatus: "Issuance" } },
|
|
28298
|
+
{ returnDocument: "after" }
|
|
28299
|
+
);
|
|
28300
|
+
const unit = [cardCredentials?.assignedUnit];
|
|
28301
|
+
const date = /* @__PURE__ */ new Date();
|
|
28302
|
+
const endDate = new Date(date.setFullYear(date.getFullYear() + 10));
|
|
28303
|
+
const res = await collection().aggregate([{ $sort: { cardNo: -1 } }, { $limit: 2 }]).toArray();
|
|
28304
|
+
const prevCard = res && res?.[1]?.cardNo || "-1";
|
|
28305
|
+
const currentCard = res && res?.[0]?.cardNo || "0";
|
|
28306
|
+
let availableCardNo = [];
|
|
28307
|
+
let num = parseInt(prevCard, 10) + 1;
|
|
28308
|
+
while (availableCardNo.length < (unit.length > 0 ? unit.length : quantity)) {
|
|
28309
|
+
if (num === parseInt(currentCard, 10)) {
|
|
28310
|
+
num++;
|
|
28311
|
+
}
|
|
28312
|
+
availableCardNo.push(num);
|
|
28313
|
+
num++;
|
|
28314
|
+
}
|
|
28315
|
+
const cardNumbers = availableCardNo.map((no) => no.toString().padStart(10, "0"));
|
|
28316
|
+
const accessCards = [];
|
|
28317
|
+
const convertedUnits = unit.map((obj) => new import_mongodb83.ObjectId(obj));
|
|
28318
|
+
for (let j = 0; j < (unit.length > 0 ? unit.length : quantity); j++) {
|
|
28319
|
+
accessCards.push(
|
|
28320
|
+
new MAccessCard({
|
|
28321
|
+
userId,
|
|
28322
|
+
site: siteId,
|
|
28323
|
+
type: cardCredentials?.type,
|
|
28324
|
+
accessLevel: cardCredentials?.accessLevel,
|
|
28325
|
+
accessGroup: cardCredentials?.accessGroup,
|
|
28326
|
+
accessType: cardCredentials?.accessType,
|
|
28327
|
+
cardNo: cardNumbers[j],
|
|
28328
|
+
pin: "123456",
|
|
28329
|
+
qrData: "092222",
|
|
28330
|
+
startDate: /* @__PURE__ */ new Date(),
|
|
28331
|
+
endDate,
|
|
28332
|
+
isActivated: true,
|
|
28333
|
+
isAntiPassBack: false,
|
|
28334
|
+
isLiftCard: cardCredentials?.isLiftCard ? true : false,
|
|
28335
|
+
liftAccessLevel: cardCredentials?.liftAccessLevel,
|
|
28336
|
+
userType: cardCredentials?.userType,
|
|
28337
|
+
doorName: cardCredentials?.doorName,
|
|
28338
|
+
liftName: cardCredentials?.liftName,
|
|
28339
|
+
assignedUnit: convertedUnits[j],
|
|
28340
|
+
replacementStatus: "Issuance",
|
|
28341
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
28342
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
28343
|
+
})
|
|
28344
|
+
);
|
|
28345
|
+
}
|
|
28346
|
+
const commands = accessCards.map((item, index) => {
|
|
28347
|
+
let ag = null;
|
|
28348
|
+
if (item.accessGroup !== void 0) {
|
|
28349
|
+
if (item.accessGroup?.length > 0) {
|
|
28350
|
+
ag = item.accessGroup.map((g) => `<GROUP_NAME>${g}</GROUP_NAME>`).join("\n ");
|
|
28351
|
+
}
|
|
28352
|
+
}
|
|
28353
|
+
const command = {
|
|
28354
|
+
commandId1: index * 2 + 1,
|
|
28355
|
+
commandId2: index * 2 + 2,
|
|
28356
|
+
staffName: `STAFF-${item._id.toString().slice(-10)}`,
|
|
28357
|
+
staffNo1: `STAFF-${item._id.toString().slice(-10)}`,
|
|
28358
|
+
staffNo2: `STAFF-${item._id.toString().slice(-10)}`,
|
|
28359
|
+
dateOfJoin: formatEntryPassDate(item.startDate),
|
|
28360
|
+
accessLevel: item.accessLevel ?? "0",
|
|
28361
|
+
cardNo: item.cardNo,
|
|
28362
|
+
pin: typeof item.pin === "string" && item.pin.trim() !== "" ? item.pin : "123456",
|
|
28363
|
+
startDate: formatEntryPassDate(item.startDate),
|
|
28364
|
+
endDate: formatEntryPassDate(item.endDate),
|
|
28365
|
+
cardType: 0,
|
|
28366
|
+
isActivated: item.isActivated ? 1 : 0,
|
|
28367
|
+
isAntiPassBack: item.isAntiPassBack ? 1 : 0,
|
|
28368
|
+
isLiftCard: item.isLiftCard ? 1 : 0,
|
|
28369
|
+
isLiftActivate: item.isLiftCard ? 1 : 0,
|
|
28370
|
+
liftAccessLevel: item.liftAccessLevel || 1,
|
|
28371
|
+
liftAccessStartDate: formatEntryPassDate(item.liftAccessStartDate) || "19770510",
|
|
28372
|
+
liftAccessEndDate: formatEntryPassDate(item.liftAccessEndDate) || "19770510",
|
|
28373
|
+
accessGroup: ag
|
|
28374
|
+
};
|
|
28375
|
+
return readTemplate(`${item.accessLevel !== null ? "add-card" : "add-card-lift"}`, { ...command });
|
|
28376
|
+
}).flat();
|
|
28377
|
+
const response = await sendCommand(commands.join("").toString(), params.acm_url);
|
|
28378
|
+
const result = await (0, import_xml2js.parseStringPromise)(response, { explicitArray: false });
|
|
28379
|
+
if (result && result.RESULT.$.STCODE !== "0") {
|
|
28380
|
+
throw new Error("Command failed, server error.");
|
|
28381
|
+
}
|
|
28382
|
+
const card = await collection().insertMany(accessCards);
|
|
28383
|
+
await session?.commitTransaction();
|
|
28384
|
+
return card;
|
|
28385
|
+
} catch (error) {
|
|
28386
|
+
await session?.abortTransaction();
|
|
28387
|
+
throw new Error(error.message);
|
|
28388
|
+
} finally {
|
|
28389
|
+
await session?.endSession();
|
|
28390
|
+
}
|
|
28110
28391
|
}
|
|
28111
|
-
|
|
28112
|
-
|
|
28392
|
+
async function updateNFCStatusRepo(params) {
|
|
28393
|
+
const session = import_node_server_utils149.useAtlas.getClient()?.startSession();
|
|
28394
|
+
try {
|
|
28395
|
+
session?.startTransaction();
|
|
28396
|
+
const results = [];
|
|
28397
|
+
for (let nfc of params.nfcList) {
|
|
28398
|
+
nfc._id = new import_mongodb83.ObjectId(nfc._id);
|
|
28399
|
+
const card = await collection().findOne({ _id: nfc._id }, { session });
|
|
28400
|
+
if (card) {
|
|
28401
|
+
const updateFields = {
|
|
28402
|
+
status: nfc.status,
|
|
28403
|
+
vmsRemarks: nfc?.vmsRemarks,
|
|
28404
|
+
userId: null,
|
|
28405
|
+
updatedAt: nfc?.updatedAt ?? /* @__PURE__ */ new Date()
|
|
28406
|
+
};
|
|
28407
|
+
if (nfc.status !== "Returned") {
|
|
28408
|
+
updateFields.isActivated = false;
|
|
28409
|
+
} else {
|
|
28410
|
+
updateFields.isActivated = true;
|
|
28411
|
+
}
|
|
28412
|
+
const res = await collection().updateOne({ _id: card._id }, { $set: updateFields }, { session });
|
|
28413
|
+
results.push({ nfcId: nfc._id, modifiedCount: res.modifiedCount });
|
|
28414
|
+
}
|
|
28415
|
+
}
|
|
28416
|
+
await session?.commitTransaction();
|
|
28417
|
+
return results;
|
|
28418
|
+
} catch (error) {
|
|
28419
|
+
await session?.abortTransaction();
|
|
28420
|
+
throw new Error(error.message);
|
|
28421
|
+
} finally {
|
|
28422
|
+
await session?.endSession();
|
|
28423
|
+
}
|
|
28424
|
+
}
|
|
28425
|
+
async function doorAndLiftDropdownRepo(params) {
|
|
28426
|
+
try {
|
|
28427
|
+
const { site, type, userType } = params;
|
|
28428
|
+
const id = new import_mongodb83.ObjectId(site);
|
|
28429
|
+
const res = collection().aggregate([
|
|
28430
|
+
{
|
|
28431
|
+
$match: {
|
|
28432
|
+
site: { $in: [id] },
|
|
28433
|
+
type,
|
|
28434
|
+
userType,
|
|
28435
|
+
isActivated: true,
|
|
28436
|
+
assignedUnit: null,
|
|
28437
|
+
userId: null,
|
|
28438
|
+
$or: [
|
|
28439
|
+
{ $and: [{ doorName: { $ne: null } }, { doorName: { $ne: "" } }, { accessLevel: { $ne: null } }] },
|
|
28440
|
+
{ $and: [{ liftName: { $ne: null } }, { liftName: { $ne: "" } }, { liftAccessLevel: { $ne: null } }] }
|
|
28441
|
+
]
|
|
28442
|
+
}
|
|
28443
|
+
},
|
|
28444
|
+
{
|
|
28445
|
+
$facet: {
|
|
28446
|
+
totalCount: [{ $count: "count" }],
|
|
28447
|
+
accessData: [
|
|
28448
|
+
{
|
|
28449
|
+
$group: {
|
|
28450
|
+
_id: null,
|
|
28451
|
+
accessLevels: {
|
|
28452
|
+
$addToSet: {
|
|
28453
|
+
$cond: [
|
|
28454
|
+
{ $and: [{ $ne: ["$doorName", null] }, { $ne: ["$doorName", ""] }, { $ne: ["$accessLevel", null] }] },
|
|
28455
|
+
{ name: "$doorName", no: "$accessLevel" },
|
|
28456
|
+
"$$REMOVE"
|
|
28457
|
+
]
|
|
28458
|
+
}
|
|
28459
|
+
},
|
|
28460
|
+
liftAccessLevels: {
|
|
28461
|
+
$addToSet: {
|
|
28462
|
+
$cond: [
|
|
28463
|
+
{ $and: [{ $ne: ["$liftName", null] }, { $ne: ["$liftName", ""] }, { $ne: ["$liftAccessLevel", null] }] },
|
|
28464
|
+
{ name: "$liftName", no: "$liftAccessLevel" },
|
|
28465
|
+
"$$REMOVE"
|
|
28466
|
+
]
|
|
28467
|
+
}
|
|
28468
|
+
}
|
|
28469
|
+
}
|
|
28470
|
+
},
|
|
28471
|
+
{
|
|
28472
|
+
$project: {
|
|
28473
|
+
_id: 0,
|
|
28474
|
+
accessLevels: 1,
|
|
28475
|
+
liftAccessLevels: 1
|
|
28476
|
+
}
|
|
28477
|
+
}
|
|
28478
|
+
]
|
|
28479
|
+
}
|
|
28480
|
+
}
|
|
28481
|
+
]).toArray();
|
|
28482
|
+
return res;
|
|
28483
|
+
} catch (error) {
|
|
28484
|
+
throw new Error(error.message);
|
|
28485
|
+
}
|
|
28486
|
+
}
|
|
28487
|
+
async function cardReplacementRepo(params) {
|
|
28488
|
+
const session = import_node_server_utils149.useAtlas.getClient()?.startSession();
|
|
28489
|
+
try {
|
|
28490
|
+
const { cardId, remarks } = params;
|
|
28491
|
+
const id = new import_mongodb83.ObjectId(cardId);
|
|
28492
|
+
session?.startTransaction();
|
|
28493
|
+
const card = await collection().findOneAndUpdate(
|
|
28494
|
+
{ _id: id },
|
|
28495
|
+
{ $set: { remarks, replacementStatus: "Pending", requestDate: /* @__PURE__ */ new Date(), isActivated: false } },
|
|
28496
|
+
{ returnDocument: "after", session }
|
|
28497
|
+
);
|
|
28498
|
+
await session?.commitTransaction();
|
|
28499
|
+
return card;
|
|
28500
|
+
} catch (error) {
|
|
28501
|
+
await session?.abortTransaction();
|
|
28502
|
+
throw new Error(error.message);
|
|
28503
|
+
} finally {
|
|
28504
|
+
await session?.endSession();
|
|
28505
|
+
}
|
|
28506
|
+
}
|
|
28507
|
+
return {
|
|
28508
|
+
createIndexes,
|
|
28509
|
+
createIndexForEntrypass,
|
|
28510
|
+
addPhysicalCardRepo,
|
|
28511
|
+
addNonPhysicalCardRepo,
|
|
28512
|
+
accessManagementSettingsRepo,
|
|
28513
|
+
allAccessCardsCountsRepo,
|
|
28514
|
+
availableAccessCardsRepo,
|
|
28515
|
+
userTypeAccessCardsRepo,
|
|
28516
|
+
assignedAccessCardsRepo,
|
|
28517
|
+
acknowlegdeCardRepo,
|
|
28518
|
+
accessandLiftCardsRepo,
|
|
28519
|
+
replaceCardRepo,
|
|
28520
|
+
updateNFCStatusRepo,
|
|
28521
|
+
doorAndLiftDropdownRepo,
|
|
28522
|
+
cardReplacementRepo
|
|
28523
|
+
};
|
|
28524
|
+
}
|
|
28525
|
+
|
|
28526
|
+
// src/controllers/access-management.controller.ts
|
|
28527
|
+
var import_joi85 = __toESM(require("joi"));
|
|
28113
28528
|
|
|
28114
28529
|
// src/services/access-management.service.ts
|
|
28115
|
-
var
|
|
28530
|
+
var import_xml2js2 = require("xml2js");
|
|
28116
28531
|
var import_node_server_utils150 = require("@7365admin1/node-server-utils");
|
|
28117
28532
|
var namespace = "cache:acm";
|
|
28118
28533
|
function useAccessManagementSvc() {
|
|
@@ -28123,7 +28538,13 @@ function useAccessManagementSvc() {
|
|
|
28123
28538
|
allAccessCardsCountsRepo,
|
|
28124
28539
|
availableAccessCardsRepo,
|
|
28125
28540
|
userTypeAccessCardsRepo,
|
|
28126
|
-
assignedAccessCardsRepo
|
|
28541
|
+
assignedAccessCardsRepo,
|
|
28542
|
+
acknowlegdeCardRepo,
|
|
28543
|
+
accessandLiftCardsRepo,
|
|
28544
|
+
replaceCardRepo,
|
|
28545
|
+
updateNFCStatusRepo,
|
|
28546
|
+
doorAndLiftDropdownRepo,
|
|
28547
|
+
cardReplacementRepo
|
|
28127
28548
|
} = UseAccessManagementRepo();
|
|
28128
28549
|
const addPhysicalCardSvc = async (payload) => {
|
|
28129
28550
|
try {
|
|
@@ -28165,7 +28586,7 @@ function useAccessManagementSvc() {
|
|
|
28165
28586
|
}
|
|
28166
28587
|
const command = readTemplate("door-levels");
|
|
28167
28588
|
const response = await sendCommand(command, params.acm_url);
|
|
28168
|
-
const res = await (0,
|
|
28589
|
+
const res = await (0, import_xml2js2.parseStringPromise)(response, { explicitArray: false });
|
|
28169
28590
|
const format = await formatDoorAccessLevels(res);
|
|
28170
28591
|
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28171
28592
|
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
@@ -28188,7 +28609,7 @@ function useAccessManagementSvc() {
|
|
|
28188
28609
|
}
|
|
28189
28610
|
const command = readTemplate("lift-levels");
|
|
28190
28611
|
const response = await sendCommand(command, params.acm_url);
|
|
28191
|
-
const res = await (0,
|
|
28612
|
+
const res = await (0, import_xml2js2.parseStringPromise)(response, { explicitArray: false });
|
|
28192
28613
|
const format = await formatLiftAccessLevels(res);
|
|
28193
28614
|
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28194
28615
|
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
@@ -28199,10 +28620,22 @@ function useAccessManagementSvc() {
|
|
|
28199
28620
|
};
|
|
28200
28621
|
const accessGroupsSvc = async (params) => {
|
|
28201
28622
|
try {
|
|
28623
|
+
const key = `${namespace}:${params.user}:access-groups`;
|
|
28624
|
+
const listKey = `${namespace}:${params.user}:list`;
|
|
28625
|
+
const { redis } = (0, import_node_server_utils150.useCache)(key);
|
|
28626
|
+
const cachedData = await getCache({ key, redis });
|
|
28627
|
+
if (cachedData) {
|
|
28628
|
+
console.log("\u26A1 Cache hit:", key);
|
|
28629
|
+
redis.expire(key, 60).catch(console.error);
|
|
28630
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28631
|
+
return cachedData;
|
|
28632
|
+
}
|
|
28202
28633
|
const command = readTemplate("access-group");
|
|
28203
28634
|
const response = await sendCommand(command, params.acm_url);
|
|
28204
|
-
const res = await (0,
|
|
28635
|
+
const res = await (0, import_xml2js2.parseStringPromise)(response, { explicitArray: false });
|
|
28205
28636
|
const format = await formatAccessGroup(res);
|
|
28637
|
+
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28638
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28206
28639
|
return format;
|
|
28207
28640
|
} catch (err) {
|
|
28208
28641
|
throw new Error(err.message);
|
|
@@ -28248,6 +28681,54 @@ function useAccessManagementSvc() {
|
|
|
28248
28681
|
throw new Error(err.message);
|
|
28249
28682
|
}
|
|
28250
28683
|
};
|
|
28684
|
+
const acknowlegdeCardSvc = async (params) => {
|
|
28685
|
+
try {
|
|
28686
|
+
const response = await acknowlegdeCardRepo({ ...params });
|
|
28687
|
+
return response;
|
|
28688
|
+
} catch (err) {
|
|
28689
|
+
throw new Error(err.message);
|
|
28690
|
+
}
|
|
28691
|
+
};
|
|
28692
|
+
const accessandLiftCardsSvc = async (params) => {
|
|
28693
|
+
try {
|
|
28694
|
+
const response = await accessandLiftCardsRepo({ ...params });
|
|
28695
|
+
return response;
|
|
28696
|
+
} catch (err) {
|
|
28697
|
+
throw new Error(err.message);
|
|
28698
|
+
}
|
|
28699
|
+
};
|
|
28700
|
+
const replaceCardSvc = async (params) => {
|
|
28701
|
+
try {
|
|
28702
|
+
const response = await replaceCardRepo({ ...params });
|
|
28703
|
+
return response;
|
|
28704
|
+
} catch (err) {
|
|
28705
|
+
throw new Error(err.message);
|
|
28706
|
+
}
|
|
28707
|
+
};
|
|
28708
|
+
const updateNFCStatusSvc = async (params) => {
|
|
28709
|
+
try {
|
|
28710
|
+
const response = await updateNFCStatusRepo({ ...params });
|
|
28711
|
+
return response;
|
|
28712
|
+
} catch (err) {
|
|
28713
|
+
throw new Error(err.message);
|
|
28714
|
+
}
|
|
28715
|
+
};
|
|
28716
|
+
const doorAndLiftDropdownSvc = async (params) => {
|
|
28717
|
+
try {
|
|
28718
|
+
const response = await doorAndLiftDropdownRepo({ ...params });
|
|
28719
|
+
return response;
|
|
28720
|
+
} catch (err) {
|
|
28721
|
+
throw new Error(err.message);
|
|
28722
|
+
}
|
|
28723
|
+
};
|
|
28724
|
+
const cardReplacementSvc = async (params) => {
|
|
28725
|
+
try {
|
|
28726
|
+
const response = await cardReplacementRepo({ ...params });
|
|
28727
|
+
return response;
|
|
28728
|
+
} catch (err) {
|
|
28729
|
+
throw new Error(err.message);
|
|
28730
|
+
}
|
|
28731
|
+
};
|
|
28251
28732
|
return {
|
|
28252
28733
|
addPhysicalCardSvc,
|
|
28253
28734
|
addNonPhysicalCardSvc,
|
|
@@ -28258,7 +28739,13 @@ function useAccessManagementSvc() {
|
|
|
28258
28739
|
allAccessCardsCountsSvc,
|
|
28259
28740
|
availableAccessCardsSvc,
|
|
28260
28741
|
userTypeAccessCardsSvc,
|
|
28261
|
-
assignedAccessCardsSvc
|
|
28742
|
+
assignedAccessCardsSvc,
|
|
28743
|
+
acknowlegdeCardSvc,
|
|
28744
|
+
accessandLiftCardsSvc,
|
|
28745
|
+
replaceCardSvc,
|
|
28746
|
+
updateNFCStatusSvc,
|
|
28747
|
+
doorAndLiftDropdownSvc,
|
|
28748
|
+
cardReplacementSvc
|
|
28262
28749
|
};
|
|
28263
28750
|
}
|
|
28264
28751
|
|
|
@@ -28274,7 +28761,13 @@ function useAccessManagementController() {
|
|
|
28274
28761
|
allAccessCardsCountsSvc,
|
|
28275
28762
|
availableAccessCardsSvc,
|
|
28276
28763
|
userTypeAccessCardsSvc,
|
|
28277
|
-
assignedAccessCardsSvc
|
|
28764
|
+
assignedAccessCardsSvc,
|
|
28765
|
+
acknowlegdeCardSvc,
|
|
28766
|
+
accessandLiftCardsSvc,
|
|
28767
|
+
replaceCardSvc,
|
|
28768
|
+
updateNFCStatusSvc,
|
|
28769
|
+
doorAndLiftDropdownSvc,
|
|
28770
|
+
cardReplacementSvc
|
|
28278
28771
|
} = useAccessManagementSvc();
|
|
28279
28772
|
const addPhysicalCard = async (req, res) => {
|
|
28280
28773
|
try {
|
|
@@ -28346,7 +28839,7 @@ function useAccessManagementController() {
|
|
|
28346
28839
|
accessGroup: import_joi85.default.array().items(import_joi85.default.string().required()).required(),
|
|
28347
28840
|
userType: import_joi85.default.string().required(),
|
|
28348
28841
|
doorName: import_joi85.default.string().required(),
|
|
28349
|
-
liftName: import_joi85.default.string().
|
|
28842
|
+
liftName: import_joi85.default.string().optional().allow("", null),
|
|
28350
28843
|
unit: import_joi85.default.array().items(import_joi85.default.string()).optional().allow(null),
|
|
28351
28844
|
startDate: import_joi85.default.date().required(),
|
|
28352
28845
|
endDate: import_joi85.default.date().required(),
|
|
@@ -28437,10 +28930,11 @@ function useAccessManagementController() {
|
|
|
28437
28930
|
const accessGroups = async (req, res) => {
|
|
28438
28931
|
try {
|
|
28439
28932
|
const { acm_url } = req.query;
|
|
28933
|
+
const user = req.cookies?.sid;
|
|
28440
28934
|
if (!acm_url || typeof acm_url !== "string") {
|
|
28441
28935
|
throw new Error("Access Control URL is required");
|
|
28442
28936
|
}
|
|
28443
|
-
const result = await accessGroupsSvc({ acm_url });
|
|
28937
|
+
const result = await accessGroupsSvc({ acm_url, user });
|
|
28444
28938
|
return res.status(200).json({ message: "Success", data: result });
|
|
28445
28939
|
} catch (error) {
|
|
28446
28940
|
return res.status(400).json({
|
|
@@ -28555,6 +29049,144 @@ function useAccessManagementController() {
|
|
|
28555
29049
|
});
|
|
28556
29050
|
}
|
|
28557
29051
|
};
|
|
29052
|
+
const acknowlegdeCard = async (req, res) => {
|
|
29053
|
+
try {
|
|
29054
|
+
const { userId, site, cardId } = req.body;
|
|
29055
|
+
const schema2 = import_joi85.default.object({
|
|
29056
|
+
userId: import_joi85.default.array().items(import_joi85.default.string().hex()).required(),
|
|
29057
|
+
cardId: import_joi85.default.array().items(import_joi85.default.string().hex()).required(),
|
|
29058
|
+
site: import_joi85.default.string().hex().required()
|
|
29059
|
+
});
|
|
29060
|
+
const { error } = schema2.validate({ userId, cardId, site });
|
|
29061
|
+
if (error) {
|
|
29062
|
+
return res.status(400).json({ message: error.message });
|
|
29063
|
+
}
|
|
29064
|
+
const result = await acknowlegdeCardSvc({ userId, cardId, site });
|
|
29065
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29066
|
+
} catch (error) {
|
|
29067
|
+
return res.status(500).json({
|
|
29068
|
+
data: null,
|
|
29069
|
+
message: error.message
|
|
29070
|
+
});
|
|
29071
|
+
}
|
|
29072
|
+
};
|
|
29073
|
+
const accessandLiftCards = async (req, res) => {
|
|
29074
|
+
try {
|
|
29075
|
+
const {
|
|
29076
|
+
accessLevel = null,
|
|
29077
|
+
liftAccessLevel = null,
|
|
29078
|
+
site,
|
|
29079
|
+
userType,
|
|
29080
|
+
type
|
|
29081
|
+
} = req.query;
|
|
29082
|
+
const schema2 = import_joi85.default.object({
|
|
29083
|
+
accessLevel: import_joi85.default.string().optional().allow("", null),
|
|
29084
|
+
liftAccessLevel: import_joi85.default.string().optional().allow("", null),
|
|
29085
|
+
site: import_joi85.default.string().hex().required(),
|
|
29086
|
+
userType: import_joi85.default.string().valid(...Object.values(EAccessCardUserTypes)).required(),
|
|
29087
|
+
type: import_joi85.default.string().valid(...Object.values(EAccessCardTypes)).required()
|
|
29088
|
+
});
|
|
29089
|
+
const { error } = schema2.validate({ accessLevel, liftAccessLevel, site, userType, type });
|
|
29090
|
+
if (error) {
|
|
29091
|
+
return res.status(400).json({ message: error.message });
|
|
29092
|
+
}
|
|
29093
|
+
const result = await accessandLiftCardsSvc({ accessLevel, liftAccessLevel, site, userType, type });
|
|
29094
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29095
|
+
} catch (error) {
|
|
29096
|
+
return res.status(500).json({
|
|
29097
|
+
data: null,
|
|
29098
|
+
message: error.message
|
|
29099
|
+
});
|
|
29100
|
+
}
|
|
29101
|
+
};
|
|
29102
|
+
const replaceCard = async (req, res) => {
|
|
29103
|
+
try {
|
|
29104
|
+
const { userId, cardId, site, acm_url } = req.body;
|
|
29105
|
+
const schema2 = import_joi85.default.object({
|
|
29106
|
+
userId: import_joi85.default.string().required(),
|
|
29107
|
+
cardId: import_joi85.default.string().required(),
|
|
29108
|
+
site: import_joi85.default.string().required(),
|
|
29109
|
+
acm_url: import_joi85.default.string().required()
|
|
29110
|
+
});
|
|
29111
|
+
const { error } = schema2.validate({ userId, cardId, site, acm_url });
|
|
29112
|
+
if (error) {
|
|
29113
|
+
return res.status(400).json({ message: error.message });
|
|
29114
|
+
}
|
|
29115
|
+
const result = await replaceCardSvc({ userId, cardId, site, acm_url });
|
|
29116
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29117
|
+
} catch (error) {
|
|
29118
|
+
return res.status(500).json({
|
|
29119
|
+
data: null,
|
|
29120
|
+
message: error.message
|
|
29121
|
+
});
|
|
29122
|
+
}
|
|
29123
|
+
};
|
|
29124
|
+
const updateNFCStatus = async (req, res) => {
|
|
29125
|
+
try {
|
|
29126
|
+
const { nfcList = [], visitorId } = req.body;
|
|
29127
|
+
const schema2 = import_joi85.default.object({
|
|
29128
|
+
nfcList: import_joi85.default.array().items({
|
|
29129
|
+
_id: import_joi85.default.string().hex().length(24).required(),
|
|
29130
|
+
status: import_joi85.default.string().required(),
|
|
29131
|
+
vmsRemarks: import_joi85.default.string().allow(null, "").optional(),
|
|
29132
|
+
updatedAt: import_joi85.default.date().optional().allow(null, "")
|
|
29133
|
+
}),
|
|
29134
|
+
visitorId: import_joi85.default.string().optional().allow(null, "")
|
|
29135
|
+
});
|
|
29136
|
+
const { error } = schema2.validate({ nfcList, visitorId });
|
|
29137
|
+
if (error) {
|
|
29138
|
+
return res.status(400).json({ message: error.message });
|
|
29139
|
+
}
|
|
29140
|
+
const result = await updateNFCStatusSvc({ nfcList, visitorId });
|
|
29141
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29142
|
+
} catch (error) {
|
|
29143
|
+
return res.status(500).json({
|
|
29144
|
+
data: null,
|
|
29145
|
+
message: error.message
|
|
29146
|
+
});
|
|
29147
|
+
}
|
|
29148
|
+
};
|
|
29149
|
+
const doorAndLiftDropdown = async (req, res) => {
|
|
29150
|
+
try {
|
|
29151
|
+
const { site, type, userType } = req.query;
|
|
29152
|
+
const schema2 = import_joi85.default.object({
|
|
29153
|
+
site: import_joi85.default.string().hex().required(),
|
|
29154
|
+
type: import_joi85.default.string().required(),
|
|
29155
|
+
userType: import_joi85.default.string().required()
|
|
29156
|
+
});
|
|
29157
|
+
const { error } = schema2.validate({ site, type, userType });
|
|
29158
|
+
if (error) {
|
|
29159
|
+
return res.status(400).json({ message: error.message });
|
|
29160
|
+
}
|
|
29161
|
+
const result = await doorAndLiftDropdownSvc({ site, type, userType });
|
|
29162
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29163
|
+
} catch (error) {
|
|
29164
|
+
return res.status(500).json({
|
|
29165
|
+
data: null,
|
|
29166
|
+
message: error.message
|
|
29167
|
+
});
|
|
29168
|
+
}
|
|
29169
|
+
};
|
|
29170
|
+
const cardReplacement = async (req, res) => {
|
|
29171
|
+
try {
|
|
29172
|
+
const { cardId, remarks } = req.body;
|
|
29173
|
+
const schema2 = import_joi85.default.object({
|
|
29174
|
+
cardId: import_joi85.default.string().required(),
|
|
29175
|
+
remarks: import_joi85.default.string().optional().allow("", null)
|
|
29176
|
+
});
|
|
29177
|
+
const { error } = schema2.validate({ cardId, remarks });
|
|
29178
|
+
if (error) {
|
|
29179
|
+
return res.status(400).json({ message: error.message });
|
|
29180
|
+
}
|
|
29181
|
+
const result = await cardReplacementSvc({ cardId, remarks });
|
|
29182
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
29183
|
+
} catch (error) {
|
|
29184
|
+
return res.status(500).json({
|
|
29185
|
+
data: null,
|
|
29186
|
+
message: error.message
|
|
29187
|
+
});
|
|
29188
|
+
}
|
|
29189
|
+
};
|
|
28558
29190
|
return {
|
|
28559
29191
|
addPhysicalCard,
|
|
28560
29192
|
addNonPhysicalCard,
|
|
@@ -28565,7 +29197,13 @@ function useAccessManagementController() {
|
|
|
28565
29197
|
allAccessCardsCounts,
|
|
28566
29198
|
availableAccessCards,
|
|
28567
29199
|
userTypeAccessCards,
|
|
28568
|
-
assignedAccessCards
|
|
29200
|
+
assignedAccessCards,
|
|
29201
|
+
acknowlegdeCard,
|
|
29202
|
+
accessandLiftCards,
|
|
29203
|
+
replaceCard,
|
|
29204
|
+
updateNFCStatus,
|
|
29205
|
+
doorAndLiftDropdown,
|
|
29206
|
+
cardReplacement
|
|
28569
29207
|
};
|
|
28570
29208
|
}
|
|
28571
29209
|
|
|
@@ -34135,16 +34773,26 @@ function useOnlineFormRepo() {
|
|
|
34135
34773
|
site = ""
|
|
34136
34774
|
}) {
|
|
34137
34775
|
page = page > 0 ? page - 1 : 0;
|
|
34776
|
+
try {
|
|
34777
|
+
site = new import_mongodb103.ObjectId(site);
|
|
34778
|
+
} catch (error) {
|
|
34779
|
+
throw new import_node_server_utils184.BadRequestError("Invalid site ID format.");
|
|
34780
|
+
}
|
|
34138
34781
|
sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
|
|
34139
34782
|
const cacheOptions = {
|
|
34140
34783
|
page,
|
|
34141
34784
|
limit,
|
|
34142
34785
|
status,
|
|
34786
|
+
site: site?.toString(),
|
|
34143
34787
|
sort: JSON.stringify(sort)
|
|
34144
34788
|
};
|
|
34145
34789
|
const query = {
|
|
34146
34790
|
...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
|
|
34147
34791
|
};
|
|
34792
|
+
if (site) {
|
|
34793
|
+
query.site = site;
|
|
34794
|
+
cacheOptions.site = site;
|
|
34795
|
+
}
|
|
34148
34796
|
if (search) {
|
|
34149
34797
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
34150
34798
|
cacheOptions.search = search;
|
|
@@ -34488,7 +35136,7 @@ function useOnlineFormController() {
|
|
|
34488
35136
|
}
|
|
34489
35137
|
async function deleteOnlineFormById(req, res, next) {
|
|
34490
35138
|
const validation = import_joi106.default.string().hex().required();
|
|
34491
|
-
const _id = req.
|
|
35139
|
+
const _id = req.query.id;
|
|
34492
35140
|
const { error } = validation.validate(_id);
|
|
34493
35141
|
if (error) {
|
|
34494
35142
|
import_node_server_utils185.logger.log({ level: "error", message: error.message });
|