@7365admin1/core 2.11.0 → 2.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +11 -1
- package/dist/index.js +205 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +205 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -5397,6 +5397,7 @@ function useRoleRepo() {
|
|
|
5397
5397
|
}
|
|
5398
5398
|
}
|
|
5399
5399
|
const { delNamespace, setCache, getCache, delCache } = useCache12(namespace_collection);
|
|
5400
|
+
const { delNamespace: _delDashboardNameSpace } = useCache12("dashboard");
|
|
5400
5401
|
async function addRole(value, session) {
|
|
5401
5402
|
value = new MRole(value);
|
|
5402
5403
|
try {
|
|
@@ -5659,15 +5660,21 @@ function useRoleRepo() {
|
|
|
5659
5660
|
{ session }
|
|
5660
5661
|
);
|
|
5661
5662
|
if (res.modifiedCount === 0) {
|
|
5662
|
-
throw new InternalServerError13("Unable to update
|
|
5663
|
+
throw new InternalServerError13("Unable to update role status.");
|
|
5663
5664
|
}
|
|
5664
|
-
|
|
5665
|
-
|
|
5666
|
-
logger16.info(`Cache deleted for key: ${cacheKey}`);
|
|
5665
|
+
delNamespace().then(() => {
|
|
5666
|
+
logger16.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5667
5667
|
}).catch((err) => {
|
|
5668
|
-
logger16.error(
|
|
5668
|
+
logger16.error(
|
|
5669
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5670
|
+
err
|
|
5671
|
+
);
|
|
5672
|
+
});
|
|
5673
|
+
_delDashboardNameSpace().then(() => {
|
|
5674
|
+
logger16.info(`Cache cleared for namespace: dashboard`);
|
|
5675
|
+
}).catch((err) => {
|
|
5676
|
+
logger16.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
5669
5677
|
});
|
|
5670
|
-
return "Successfully deleted role.";
|
|
5671
5678
|
} catch (error) {
|
|
5672
5679
|
throw new InternalServerError13("Failed to delete role.");
|
|
5673
5680
|
}
|
|
@@ -6764,7 +6771,7 @@ function useRoleController() {
|
|
|
6764
6771
|
}
|
|
6765
6772
|
async function deleteRole(req, res, next) {
|
|
6766
6773
|
const validation = Joi15.string().hex().required();
|
|
6767
|
-
const _id = req.
|
|
6774
|
+
const _id = req.query.id;
|
|
6768
6775
|
const { error } = validation.validate(_id);
|
|
6769
6776
|
if (error) {
|
|
6770
6777
|
logger21.log({ level: "error", message: error.message });
|
|
@@ -7415,7 +7422,7 @@ function useFileController() {
|
|
|
7415
7422
|
}
|
|
7416
7423
|
async function deleteFile(req, res, next) {
|
|
7417
7424
|
const validation = Joi18.string().hex().required();
|
|
7418
|
-
const _id = req.
|
|
7425
|
+
const _id = req.query.id;
|
|
7419
7426
|
const { error } = validation.validate(_id);
|
|
7420
7427
|
if (error) {
|
|
7421
7428
|
logger25.log({ level: "error", message: error.message });
|
|
@@ -10893,7 +10900,6 @@ function useFeedbackController() {
|
|
|
10893
10900
|
async function deleteFeedback(req, res, next) {
|
|
10894
10901
|
const validation = Joi28.string().hex().required();
|
|
10895
10902
|
const _id = req.query.id;
|
|
10896
|
-
console.log(_id);
|
|
10897
10903
|
const { error } = validation.validate(_id);
|
|
10898
10904
|
if (error) {
|
|
10899
10905
|
logger39.log({ level: "error", message: error.message });
|
|
@@ -20842,13 +20848,38 @@ function usePatrolRouteRepo() {
|
|
|
20842
20848
|
throw error;
|
|
20843
20849
|
}
|
|
20844
20850
|
}
|
|
20851
|
+
async function getById(_id, session) {
|
|
20852
|
+
try {
|
|
20853
|
+
_id = new ObjectId60(_id);
|
|
20854
|
+
} catch (error) {
|
|
20855
|
+
throw new BadRequestError107("Invalid patrol log ID format.");
|
|
20856
|
+
}
|
|
20857
|
+
const cacheKey = makeCacheKey33(namespace_collection, { _id });
|
|
20858
|
+
const cachedData = await getCache(cacheKey);
|
|
20859
|
+
if (cachedData) {
|
|
20860
|
+
logger89.info(`Cache hit for key: ${cacheKey}`);
|
|
20861
|
+
return cachedData;
|
|
20862
|
+
}
|
|
20863
|
+
try {
|
|
20864
|
+
const data = await collection.findOne({ _id }, { session });
|
|
20865
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
20866
|
+
logger89.info(`Cache set for key: ${cacheKey}`);
|
|
20867
|
+
}).catch((err) => {
|
|
20868
|
+
logger89.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
20869
|
+
});
|
|
20870
|
+
return data;
|
|
20871
|
+
} catch (error) {
|
|
20872
|
+
throw error;
|
|
20873
|
+
}
|
|
20874
|
+
}
|
|
20845
20875
|
return {
|
|
20846
20876
|
createTextIndex,
|
|
20847
20877
|
add,
|
|
20848
20878
|
getAll,
|
|
20849
20879
|
updateById,
|
|
20850
20880
|
deleteById,
|
|
20851
|
-
getScheduledRoute
|
|
20881
|
+
getScheduledRoute,
|
|
20882
|
+
getById
|
|
20852
20883
|
};
|
|
20853
20884
|
}
|
|
20854
20885
|
|
|
@@ -20861,7 +20892,8 @@ function usePatrolRouteController() {
|
|
|
20861
20892
|
getAll: _getAll,
|
|
20862
20893
|
updateById: _updateById,
|
|
20863
20894
|
deleteById: _deleteById,
|
|
20864
|
-
getScheduledRoute: _getScheduledRoute
|
|
20895
|
+
getScheduledRoute: _getScheduledRoute,
|
|
20896
|
+
getById: _getById
|
|
20865
20897
|
} = usePatrolRouteRepo();
|
|
20866
20898
|
async function add(req, res, next) {
|
|
20867
20899
|
const data = { ...req.body };
|
|
@@ -21029,12 +21061,34 @@ function usePatrolRouteController() {
|
|
|
21029
21061
|
return;
|
|
21030
21062
|
}
|
|
21031
21063
|
}
|
|
21064
|
+
async function getById(req, res, next) {
|
|
21065
|
+
const id = req.params.id;
|
|
21066
|
+
const validation = Joi64.object({
|
|
21067
|
+
id: Joi64.string().hex().required()
|
|
21068
|
+
});
|
|
21069
|
+
const { error } = validation.validate({ id });
|
|
21070
|
+
if (error) {
|
|
21071
|
+
next(new BadRequestError108(error.message));
|
|
21072
|
+
return;
|
|
21073
|
+
}
|
|
21074
|
+
try {
|
|
21075
|
+
const routes = await _getById(id);
|
|
21076
|
+
res.json({
|
|
21077
|
+
message: "Successfully retrieved patrol routes.",
|
|
21078
|
+
data: routes
|
|
21079
|
+
});
|
|
21080
|
+
return;
|
|
21081
|
+
} catch (error2) {
|
|
21082
|
+
next(error2);
|
|
21083
|
+
}
|
|
21084
|
+
}
|
|
21032
21085
|
return {
|
|
21033
21086
|
add,
|
|
21034
21087
|
getAll,
|
|
21035
21088
|
updateById,
|
|
21036
21089
|
deleteById,
|
|
21037
|
-
getScheduledRoute
|
|
21090
|
+
getScheduledRoute,
|
|
21091
|
+
getById
|
|
21038
21092
|
};
|
|
21039
21093
|
}
|
|
21040
21094
|
|
|
@@ -21293,6 +21347,30 @@ function usePatrolLogRepo() {
|
|
|
21293
21347
|
throw error;
|
|
21294
21348
|
}
|
|
21295
21349
|
}
|
|
21350
|
+
async function getById(_id, session) {
|
|
21351
|
+
try {
|
|
21352
|
+
_id = new ObjectId62(_id);
|
|
21353
|
+
} catch (error) {
|
|
21354
|
+
throw new BadRequestError110("Invalid patrol log ID format.");
|
|
21355
|
+
}
|
|
21356
|
+
const cacheKey = makeCacheKey34(namespace_collection, { _id });
|
|
21357
|
+
const cachedData = await getCache(cacheKey);
|
|
21358
|
+
if (cachedData) {
|
|
21359
|
+
logger92.info(`Cache hit for key: ${cacheKey}`);
|
|
21360
|
+
return cachedData;
|
|
21361
|
+
}
|
|
21362
|
+
try {
|
|
21363
|
+
const data = await collection.findOne({ _id }, { session });
|
|
21364
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
21365
|
+
logger92.info(`Cache set for key: ${cacheKey}`);
|
|
21366
|
+
}).catch((err) => {
|
|
21367
|
+
logger92.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
21368
|
+
});
|
|
21369
|
+
return data;
|
|
21370
|
+
} catch (error) {
|
|
21371
|
+
throw error;
|
|
21372
|
+
}
|
|
21373
|
+
}
|
|
21296
21374
|
function delCachedData() {
|
|
21297
21375
|
delNamespace().then(() => {
|
|
21298
21376
|
logger92.log({
|
|
@@ -21312,7 +21390,8 @@ function usePatrolLogRepo() {
|
|
|
21312
21390
|
add,
|
|
21313
21391
|
getAll,
|
|
21314
21392
|
updateById,
|
|
21315
|
-
deleteById
|
|
21393
|
+
deleteById,
|
|
21394
|
+
getById
|
|
21316
21395
|
};
|
|
21317
21396
|
}
|
|
21318
21397
|
|
|
@@ -21389,7 +21468,8 @@ function usePatrolLogController() {
|
|
|
21389
21468
|
const {
|
|
21390
21469
|
getAll: _getAll,
|
|
21391
21470
|
updateById: _updateById,
|
|
21392
|
-
deleteById: _deleteById
|
|
21471
|
+
deleteById: _deleteById,
|
|
21472
|
+
getById: _getById
|
|
21393
21473
|
} = usePatrolLogRepo();
|
|
21394
21474
|
const { add: _add } = usePatrolLogService();
|
|
21395
21475
|
async function add(req, res, next) {
|
|
@@ -21501,7 +21581,28 @@ function usePatrolLogController() {
|
|
|
21501
21581
|
return;
|
|
21502
21582
|
}
|
|
21503
21583
|
}
|
|
21504
|
-
|
|
21584
|
+
async function getById(req, res, next) {
|
|
21585
|
+
const id = req.params.id;
|
|
21586
|
+
const validation = Joi66.object({
|
|
21587
|
+
id: Joi66.string().hex().required()
|
|
21588
|
+
});
|
|
21589
|
+
const { error } = validation.validate({ id });
|
|
21590
|
+
if (error) {
|
|
21591
|
+
next(new BadRequestError112(error.message));
|
|
21592
|
+
return;
|
|
21593
|
+
}
|
|
21594
|
+
try {
|
|
21595
|
+
const logs = await _getById(id);
|
|
21596
|
+
res.json({
|
|
21597
|
+
message: "Successfully retrieved patrol log.",
|
|
21598
|
+
data: logs
|
|
21599
|
+
});
|
|
21600
|
+
return;
|
|
21601
|
+
} catch (error2) {
|
|
21602
|
+
next(error2);
|
|
21603
|
+
}
|
|
21604
|
+
}
|
|
21605
|
+
return { add, getAll, updateById, deleteById, getById };
|
|
21505
21606
|
}
|
|
21506
21607
|
|
|
21507
21608
|
// src/models/site-facility.model.ts
|
|
@@ -24034,7 +24135,7 @@ function useDocumentManagementController() {
|
|
|
24034
24135
|
}
|
|
24035
24136
|
async function deleteDocumentById(req, res, next) {
|
|
24036
24137
|
const validation = Joi74.string().hex().required();
|
|
24037
|
-
const _id = req.
|
|
24138
|
+
const _id = req.query.id;
|
|
24038
24139
|
const { error } = validation.validate(_id);
|
|
24039
24140
|
if (error) {
|
|
24040
24141
|
logger102.log({ level: "error", message: error.message });
|
|
@@ -28154,6 +28255,41 @@ function UseAccessManagementRepo() {
|
|
|
28154
28255
|
throw new Error(error.message);
|
|
28155
28256
|
}
|
|
28156
28257
|
}
|
|
28258
|
+
async function acknowlegdeCardRepo(params) {
|
|
28259
|
+
const session = useAtlas74.getClient()?.startSession();
|
|
28260
|
+
try {
|
|
28261
|
+
session?.startTransaction();
|
|
28262
|
+
const { userId, cardId, site } = params;
|
|
28263
|
+
const allUserId = await Promise.all(userId.map(async (id) => new ObjectId83(id)));
|
|
28264
|
+
const allCardId = await Promise.all(cardId.map(async (id) => new ObjectId83(id)));
|
|
28265
|
+
const siteId = new ObjectId83(site);
|
|
28266
|
+
const result = await collection().updateMany(
|
|
28267
|
+
{
|
|
28268
|
+
$or: [
|
|
28269
|
+
{
|
|
28270
|
+
_id: { $in: allCardId },
|
|
28271
|
+
site: siteId
|
|
28272
|
+
},
|
|
28273
|
+
{
|
|
28274
|
+
userId: { $in: allUserId },
|
|
28275
|
+
site: siteId,
|
|
28276
|
+
isActivated: false,
|
|
28277
|
+
replacementStatus: "Issuance"
|
|
28278
|
+
}
|
|
28279
|
+
]
|
|
28280
|
+
},
|
|
28281
|
+
{ $set: { replacementStatus: "Complete" } },
|
|
28282
|
+
{ session }
|
|
28283
|
+
);
|
|
28284
|
+
await session?.commitTransaction();
|
|
28285
|
+
return result;
|
|
28286
|
+
} catch (error) {
|
|
28287
|
+
await session?.abortTransaction();
|
|
28288
|
+
throw new Error(error.message);
|
|
28289
|
+
} finally {
|
|
28290
|
+
await session?.endSession();
|
|
28291
|
+
}
|
|
28292
|
+
}
|
|
28157
28293
|
return {
|
|
28158
28294
|
createIndexes,
|
|
28159
28295
|
createIndexForEntrypass,
|
|
@@ -28163,7 +28299,8 @@ function UseAccessManagementRepo() {
|
|
|
28163
28299
|
allAccessCardsCountsRepo,
|
|
28164
28300
|
availableAccessCardsRepo,
|
|
28165
28301
|
userTypeAccessCardsRepo,
|
|
28166
|
-
assignedAccessCardsRepo
|
|
28302
|
+
assignedAccessCardsRepo,
|
|
28303
|
+
acknowlegdeCardRepo
|
|
28167
28304
|
};
|
|
28168
28305
|
}
|
|
28169
28306
|
|
|
@@ -28278,7 +28415,8 @@ function useAccessManagementSvc() {
|
|
|
28278
28415
|
allAccessCardsCountsRepo,
|
|
28279
28416
|
availableAccessCardsRepo,
|
|
28280
28417
|
userTypeAccessCardsRepo,
|
|
28281
|
-
assignedAccessCardsRepo
|
|
28418
|
+
assignedAccessCardsRepo,
|
|
28419
|
+
acknowlegdeCardRepo
|
|
28282
28420
|
} = UseAccessManagementRepo();
|
|
28283
28421
|
const addPhysicalCardSvc = async (payload) => {
|
|
28284
28422
|
try {
|
|
@@ -28354,10 +28492,22 @@ function useAccessManagementSvc() {
|
|
|
28354
28492
|
};
|
|
28355
28493
|
const accessGroupsSvc = async (params) => {
|
|
28356
28494
|
try {
|
|
28495
|
+
const key = `${namespace}:${params.user}:access-groups`;
|
|
28496
|
+
const listKey = `${namespace}:${params.user}:list`;
|
|
28497
|
+
const { redis } = useCache47(key);
|
|
28498
|
+
const cachedData = await getCache({ key, redis });
|
|
28499
|
+
if (cachedData) {
|
|
28500
|
+
console.log("\u26A1 Cache hit:", key);
|
|
28501
|
+
redis.expire(key, 60).catch(console.error);
|
|
28502
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28503
|
+
return cachedData;
|
|
28504
|
+
}
|
|
28357
28505
|
const command = readTemplate("access-group");
|
|
28358
28506
|
const response = await sendCommand(command, params.acm_url);
|
|
28359
28507
|
const res = await parseStringPromise(response, { explicitArray: false });
|
|
28360
28508
|
const format = await formatAccessGroup(res);
|
|
28509
|
+
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28510
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28361
28511
|
return format;
|
|
28362
28512
|
} catch (err) {
|
|
28363
28513
|
throw new Error(err.message);
|
|
@@ -28403,6 +28553,14 @@ function useAccessManagementSvc() {
|
|
|
28403
28553
|
throw new Error(err.message);
|
|
28404
28554
|
}
|
|
28405
28555
|
};
|
|
28556
|
+
const acknowlegdeCardSvc = async (params) => {
|
|
28557
|
+
try {
|
|
28558
|
+
const response = await acknowlegdeCardRepo({ ...params });
|
|
28559
|
+
return response;
|
|
28560
|
+
} catch (err) {
|
|
28561
|
+
throw new Error(err.message);
|
|
28562
|
+
}
|
|
28563
|
+
};
|
|
28406
28564
|
return {
|
|
28407
28565
|
addPhysicalCardSvc,
|
|
28408
28566
|
addNonPhysicalCardSvc,
|
|
@@ -28413,7 +28571,8 @@ function useAccessManagementSvc() {
|
|
|
28413
28571
|
allAccessCardsCountsSvc,
|
|
28414
28572
|
availableAccessCardsSvc,
|
|
28415
28573
|
userTypeAccessCardsSvc,
|
|
28416
|
-
assignedAccessCardsSvc
|
|
28574
|
+
assignedAccessCardsSvc,
|
|
28575
|
+
acknowlegdeCardSvc
|
|
28417
28576
|
};
|
|
28418
28577
|
}
|
|
28419
28578
|
|
|
@@ -28429,7 +28588,8 @@ function useAccessManagementController() {
|
|
|
28429
28588
|
allAccessCardsCountsSvc,
|
|
28430
28589
|
availableAccessCardsSvc,
|
|
28431
28590
|
userTypeAccessCardsSvc,
|
|
28432
|
-
assignedAccessCardsSvc
|
|
28591
|
+
assignedAccessCardsSvc,
|
|
28592
|
+
acknowlegdeCardSvc
|
|
28433
28593
|
} = useAccessManagementSvc();
|
|
28434
28594
|
const addPhysicalCard = async (req, res) => {
|
|
28435
28595
|
try {
|
|
@@ -28592,10 +28752,11 @@ function useAccessManagementController() {
|
|
|
28592
28752
|
const accessGroups = async (req, res) => {
|
|
28593
28753
|
try {
|
|
28594
28754
|
const { acm_url } = req.query;
|
|
28755
|
+
const user = req.cookies?.sid;
|
|
28595
28756
|
if (!acm_url || typeof acm_url !== "string") {
|
|
28596
28757
|
throw new Error("Access Control URL is required");
|
|
28597
28758
|
}
|
|
28598
|
-
const result = await accessGroupsSvc({ acm_url });
|
|
28759
|
+
const result = await accessGroupsSvc({ acm_url, user });
|
|
28599
28760
|
return res.status(200).json({ message: "Success", data: result });
|
|
28600
28761
|
} catch (error) {
|
|
28601
28762
|
return res.status(400).json({
|
|
@@ -28710,6 +28871,27 @@ function useAccessManagementController() {
|
|
|
28710
28871
|
});
|
|
28711
28872
|
}
|
|
28712
28873
|
};
|
|
28874
|
+
const acknowlegdeCard = async (req, res) => {
|
|
28875
|
+
try {
|
|
28876
|
+
const { userId, site, cardId } = req.body;
|
|
28877
|
+
const schema2 = Joi85.object({
|
|
28878
|
+
userId: Joi85.array().items(Joi85.string().hex()).required(),
|
|
28879
|
+
cardId: Joi85.array().items(Joi85.string().hex()).required(),
|
|
28880
|
+
site: Joi85.string().hex().required()
|
|
28881
|
+
});
|
|
28882
|
+
const { error } = schema2.validate({ userId, cardId, site });
|
|
28883
|
+
if (error) {
|
|
28884
|
+
return res.status(400).json({ message: error.message });
|
|
28885
|
+
}
|
|
28886
|
+
const result = await acknowlegdeCardSvc({ userId, cardId, site });
|
|
28887
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
28888
|
+
} catch (error) {
|
|
28889
|
+
return res.status(500).json({
|
|
28890
|
+
data: null,
|
|
28891
|
+
message: error.message
|
|
28892
|
+
});
|
|
28893
|
+
}
|
|
28894
|
+
};
|
|
28713
28895
|
return {
|
|
28714
28896
|
addPhysicalCard,
|
|
28715
28897
|
addNonPhysicalCard,
|
|
@@ -28720,7 +28902,8 @@ function useAccessManagementController() {
|
|
|
28720
28902
|
allAccessCardsCounts,
|
|
28721
28903
|
availableAccessCards,
|
|
28722
28904
|
userTypeAccessCards,
|
|
28723
|
-
assignedAccessCards
|
|
28905
|
+
assignedAccessCards,
|
|
28906
|
+
acknowlegdeCard
|
|
28724
28907
|
};
|
|
28725
28908
|
}
|
|
28726
28909
|
|