@7365admin1/core 2.10.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/.github/workflows/main.yml +1 -1
- package/CHANGELOG.md +12 -0
- package/dist/index.d.ts +21 -1
- package/dist/index.js +1161 -644
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +596 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/dist/public/rsa-keys/new_rsa_512_priv.pem +0 -3
- package/dist/public/rsa-keys/new_rsa_512_pub.pem +0 -3
package/dist/index.mjs
CHANGED
|
@@ -934,6 +934,7 @@ function useWorkOrderRepo() {
|
|
|
934
934
|
}
|
|
935
935
|
}
|
|
936
936
|
const { delNamespace, setCache, getCache, delCache } = useCache3(namespace_collection);
|
|
937
|
+
const { delNamespace: _delDashboardNameSpace } = useCache3("dashboard");
|
|
937
938
|
async function createWorkOrder(value, session) {
|
|
938
939
|
try {
|
|
939
940
|
value = MWorkOrder(value);
|
|
@@ -946,6 +947,11 @@ function useWorkOrderRepo() {
|
|
|
946
947
|
err
|
|
947
948
|
);
|
|
948
949
|
});
|
|
950
|
+
_delDashboardNameSpace().then(() => {
|
|
951
|
+
logger5.info(`Cache cleared for namespace: dashboard`);
|
|
952
|
+
}).catch((err) => {
|
|
953
|
+
logger5.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
954
|
+
});
|
|
949
955
|
return res.insertedId;
|
|
950
956
|
} catch (error) {
|
|
951
957
|
throw error;
|
|
@@ -1182,11 +1188,18 @@ function useWorkOrderRepo() {
|
|
|
1182
1188
|
if (res.modifiedCount === 0) {
|
|
1183
1189
|
throw new InternalServerError3("Unable to update work order.");
|
|
1184
1190
|
}
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1191
|
+
delNamespace().then(() => {
|
|
1192
|
+
logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
1193
|
+
}).catch((err) => {
|
|
1194
|
+
logger5.error(
|
|
1195
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
1196
|
+
err
|
|
1197
|
+
);
|
|
1198
|
+
});
|
|
1199
|
+
_delDashboardNameSpace().then(() => {
|
|
1200
|
+
logger5.info(`Cache cleared for namespace: dashboard`);
|
|
1188
1201
|
}).catch((err) => {
|
|
1189
|
-
logger5.error(`Failed to
|
|
1202
|
+
logger5.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
1190
1203
|
});
|
|
1191
1204
|
return res.modifiedCount;
|
|
1192
1205
|
} catch (error) {
|
|
@@ -1209,11 +1222,18 @@ function useWorkOrderRepo() {
|
|
|
1209
1222
|
if (res.modifiedCount === 0) {
|
|
1210
1223
|
throw new InternalServerError3("Unable to update work order status.");
|
|
1211
1224
|
}
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
logger5.info(`Cache deleted for key: ${cacheKey}`);
|
|
1225
|
+
delNamespace().then(() => {
|
|
1226
|
+
logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
1215
1227
|
}).catch((err) => {
|
|
1216
|
-
logger5.error(
|
|
1228
|
+
logger5.error(
|
|
1229
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
1230
|
+
err
|
|
1231
|
+
);
|
|
1232
|
+
});
|
|
1233
|
+
_delDashboardNameSpace().then(() => {
|
|
1234
|
+
logger5.info(`Cache cleared for namespace: dashboard`);
|
|
1235
|
+
}).catch((err) => {
|
|
1236
|
+
logger5.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
1217
1237
|
});
|
|
1218
1238
|
return res.modifiedCount;
|
|
1219
1239
|
} catch (error) {
|
|
@@ -1231,11 +1251,18 @@ function useWorkOrderRepo() {
|
|
|
1231
1251
|
{ $set: updateValue },
|
|
1232
1252
|
session
|
|
1233
1253
|
);
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
logger5.info(`Cache deleted for key: ${cacheKey}`);
|
|
1254
|
+
delNamespace().then(() => {
|
|
1255
|
+
logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
1237
1256
|
}).catch((err) => {
|
|
1238
|
-
logger5.error(
|
|
1257
|
+
logger5.error(
|
|
1258
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
1259
|
+
err
|
|
1260
|
+
);
|
|
1261
|
+
});
|
|
1262
|
+
_delDashboardNameSpace().then(() => {
|
|
1263
|
+
logger5.info(`Cache cleared for namespace: dashboard`);
|
|
1264
|
+
}).catch((err) => {
|
|
1265
|
+
logger5.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
1239
1266
|
});
|
|
1240
1267
|
return res.modifiedCount;
|
|
1241
1268
|
} catch (error) {
|
|
@@ -1265,11 +1292,18 @@ function useWorkOrderRepo() {
|
|
|
1265
1292
|
"Unable to mark work order as completed."
|
|
1266
1293
|
);
|
|
1267
1294
|
}
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1295
|
+
delNamespace().then(() => {
|
|
1296
|
+
logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
1297
|
+
}).catch((err) => {
|
|
1298
|
+
logger5.error(
|
|
1299
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
1300
|
+
err
|
|
1301
|
+
);
|
|
1302
|
+
});
|
|
1303
|
+
_delDashboardNameSpace().then(() => {
|
|
1304
|
+
logger5.info(`Cache cleared for namespace: dashboard`);
|
|
1271
1305
|
}).catch((err) => {
|
|
1272
|
-
logger5.error(`Failed to
|
|
1306
|
+
logger5.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
1273
1307
|
});
|
|
1274
1308
|
return res.modifiedCount;
|
|
1275
1309
|
} catch (error) {
|
|
@@ -1296,11 +1330,18 @@ function useWorkOrderRepo() {
|
|
|
1296
1330
|
if (res.modifiedCount === 0) {
|
|
1297
1331
|
throw new InternalServerError3("Unable to delete work order.");
|
|
1298
1332
|
}
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1333
|
+
delNamespace().then(() => {
|
|
1334
|
+
logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
1335
|
+
}).catch((err) => {
|
|
1336
|
+
logger5.error(
|
|
1337
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
1338
|
+
err
|
|
1339
|
+
);
|
|
1340
|
+
});
|
|
1341
|
+
_delDashboardNameSpace().then(() => {
|
|
1342
|
+
logger5.info(`Cache cleared for namespace: dashboard`);
|
|
1302
1343
|
}).catch((err) => {
|
|
1303
|
-
logger5.error(`Failed to
|
|
1344
|
+
logger5.error(`Failed to clear cache for namespace: dashboard`, err);
|
|
1304
1345
|
});
|
|
1305
1346
|
return res.modifiedCount;
|
|
1306
1347
|
} catch (error) {
|
|
@@ -2858,6 +2899,14 @@ function useVerificationRepo() {
|
|
|
2858
2899
|
throw new InternalServerError7("Error updating verification status.");
|
|
2859
2900
|
}
|
|
2860
2901
|
}
|
|
2902
|
+
async function getByStatus(status) {
|
|
2903
|
+
try {
|
|
2904
|
+
const data = await collection.find({ status }).toArray();
|
|
2905
|
+
return data;
|
|
2906
|
+
} catch (error) {
|
|
2907
|
+
return Promise.reject(error);
|
|
2908
|
+
}
|
|
2909
|
+
}
|
|
2861
2910
|
return {
|
|
2862
2911
|
createIndex,
|
|
2863
2912
|
createTextIndex,
|
|
@@ -2865,7 +2914,8 @@ function useVerificationRepo() {
|
|
|
2865
2914
|
getById,
|
|
2866
2915
|
getVerifications,
|
|
2867
2916
|
getByIdByType,
|
|
2868
|
-
updateStatusById
|
|
2917
|
+
updateStatusById,
|
|
2918
|
+
getByStatus
|
|
2869
2919
|
};
|
|
2870
2920
|
}
|
|
2871
2921
|
|
|
@@ -4119,7 +4169,8 @@ function useVerificationService() {
|
|
|
4119
4169
|
const {
|
|
4120
4170
|
add,
|
|
4121
4171
|
getById: _getById,
|
|
4122
|
-
updateStatusById: _updateStatusById
|
|
4172
|
+
updateStatusById: _updateStatusById,
|
|
4173
|
+
getByStatus: _getByStatus
|
|
4123
4174
|
} = useVerificationRepo();
|
|
4124
4175
|
const { getUserByEmail } = useUserRepo();
|
|
4125
4176
|
const { getById: getOrgById, getByEmail: getOrgByEmail } = useOrgRepo();
|
|
@@ -4365,7 +4416,6 @@ function useVerificationService() {
|
|
|
4365
4416
|
}
|
|
4366
4417
|
async function cancelUserInvitation(id) {
|
|
4367
4418
|
try {
|
|
4368
|
-
await verify(id);
|
|
4369
4419
|
await updateStatusById(id, "cancelled");
|
|
4370
4420
|
} catch (error) {
|
|
4371
4421
|
throw new InternalServerError11(
|
|
@@ -4427,6 +4477,30 @@ function useVerificationService() {
|
|
|
4427
4477
|
throw error;
|
|
4428
4478
|
}
|
|
4429
4479
|
}
|
|
4480
|
+
async function checkExpiredInvitation() {
|
|
4481
|
+
const session = useAtlas10.getClient()?.startSession();
|
|
4482
|
+
session?.startTransaction();
|
|
4483
|
+
try {
|
|
4484
|
+
const verifications = await _getByStatus("pending");
|
|
4485
|
+
for (const verification of verifications) {
|
|
4486
|
+
const expiration = new Date(verification.expireAt).getTime();
|
|
4487
|
+
const now = (/* @__PURE__ */ new Date()).getTime();
|
|
4488
|
+
if (now > expiration) {
|
|
4489
|
+
await _updateStatusById(verification._id.toString(), "expired");
|
|
4490
|
+
}
|
|
4491
|
+
}
|
|
4492
|
+
return "Successfully checked for expired invitations.";
|
|
4493
|
+
} catch (error) {
|
|
4494
|
+
await session?.abortTransaction();
|
|
4495
|
+
logger14.log({
|
|
4496
|
+
level: "info",
|
|
4497
|
+
message: `Error checking expired user invitation: ${error}`
|
|
4498
|
+
});
|
|
4499
|
+
throw error;
|
|
4500
|
+
} finally {
|
|
4501
|
+
session?.endSession();
|
|
4502
|
+
}
|
|
4503
|
+
}
|
|
4430
4504
|
return {
|
|
4431
4505
|
createUserInvite,
|
|
4432
4506
|
createForgetPassword,
|
|
@@ -4435,7 +4509,8 @@ function useVerificationService() {
|
|
|
4435
4509
|
verify,
|
|
4436
4510
|
cancelUserInvitation,
|
|
4437
4511
|
updateStatusById,
|
|
4438
|
-
signUp
|
|
4512
|
+
signUp,
|
|
4513
|
+
checkExpiredInvitation
|
|
4439
4514
|
};
|
|
4440
4515
|
}
|
|
4441
4516
|
|
|
@@ -5322,6 +5397,7 @@ function useRoleRepo() {
|
|
|
5322
5397
|
}
|
|
5323
5398
|
}
|
|
5324
5399
|
const { delNamespace, setCache, getCache, delCache } = useCache12(namespace_collection);
|
|
5400
|
+
const { delNamespace: _delDashboardNameSpace } = useCache12("dashboard");
|
|
5325
5401
|
async function addRole(value, session) {
|
|
5326
5402
|
value = new MRole(value);
|
|
5327
5403
|
try {
|
|
@@ -5584,15 +5660,21 @@ function useRoleRepo() {
|
|
|
5584
5660
|
{ session }
|
|
5585
5661
|
);
|
|
5586
5662
|
if (res.modifiedCount === 0) {
|
|
5587
|
-
throw new InternalServerError13("Unable to update
|
|
5663
|
+
throw new InternalServerError13("Unable to update role status.");
|
|
5588
5664
|
}
|
|
5589
|
-
|
|
5590
|
-
|
|
5591
|
-
logger16.info(`Cache deleted for key: ${cacheKey}`);
|
|
5665
|
+
delNamespace().then(() => {
|
|
5666
|
+
logger16.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5592
5667
|
}).catch((err) => {
|
|
5593
|
-
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);
|
|
5594
5677
|
});
|
|
5595
|
-
return "Successfully deleted role.";
|
|
5596
5678
|
} catch (error) {
|
|
5597
5679
|
throw new InternalServerError13("Failed to delete role.");
|
|
5598
5680
|
}
|
|
@@ -5645,6 +5727,16 @@ function useFileRepo() {
|
|
|
5645
5727
|
const namespace_collection = "files";
|
|
5646
5728
|
const collection = db.collection(namespace_collection);
|
|
5647
5729
|
const { delNamespace, getCache, setCache } = useCache13(namespace_collection);
|
|
5730
|
+
async function createIndex() {
|
|
5731
|
+
try {
|
|
5732
|
+
await collection.createIndexes([
|
|
5733
|
+
{ key: { createdAt: 1 } },
|
|
5734
|
+
{ key: { status: 1 } }
|
|
5735
|
+
]);
|
|
5736
|
+
} catch (error) {
|
|
5737
|
+
throw new InternalServerError14("Failed to create index on feedback.");
|
|
5738
|
+
}
|
|
5739
|
+
}
|
|
5648
5740
|
async function createFile(value, session) {
|
|
5649
5741
|
try {
|
|
5650
5742
|
value = new MFile(value);
|
|
@@ -5773,7 +5865,8 @@ function useFileRepo() {
|
|
|
5773
5865
|
deleteFileById,
|
|
5774
5866
|
getAllDraftedFiles,
|
|
5775
5867
|
updateStatusById,
|
|
5776
|
-
getFileById
|
|
5868
|
+
getFileById,
|
|
5869
|
+
createIndex
|
|
5777
5870
|
};
|
|
5778
5871
|
}
|
|
5779
5872
|
|
|
@@ -6678,7 +6771,7 @@ function useRoleController() {
|
|
|
6678
6771
|
}
|
|
6679
6772
|
async function deleteRole(req, res, next) {
|
|
6680
6773
|
const validation = Joi15.string().hex().required();
|
|
6681
|
-
const _id = req.
|
|
6774
|
+
const _id = req.query.id;
|
|
6682
6775
|
const { error } = validation.validate(_id);
|
|
6683
6776
|
if (error) {
|
|
6684
6777
|
logger21.log({ level: "error", message: error.message });
|
|
@@ -7329,7 +7422,7 @@ function useFileController() {
|
|
|
7329
7422
|
}
|
|
7330
7423
|
async function deleteFile(req, res, next) {
|
|
7331
7424
|
const validation = Joi18.string().hex().required();
|
|
7332
|
-
const _id = req.
|
|
7425
|
+
const _id = req.query.id;
|
|
7333
7426
|
const { error } = validation.validate(_id);
|
|
7334
7427
|
if (error) {
|
|
7335
7428
|
logger25.log({ level: "error", message: error.message });
|
|
@@ -10807,7 +10900,6 @@ function useFeedbackController() {
|
|
|
10807
10900
|
async function deleteFeedback(req, res, next) {
|
|
10808
10901
|
const validation = Joi28.string().hex().required();
|
|
10809
10902
|
const _id = req.query.id;
|
|
10810
|
-
console.log(_id);
|
|
10811
10903
|
const { error } = validation.validate(_id);
|
|
10812
10904
|
if (error) {
|
|
10813
10905
|
logger39.log({ level: "error", message: error.message });
|
|
@@ -20756,13 +20848,38 @@ function usePatrolRouteRepo() {
|
|
|
20756
20848
|
throw error;
|
|
20757
20849
|
}
|
|
20758
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
|
+
}
|
|
20759
20875
|
return {
|
|
20760
20876
|
createTextIndex,
|
|
20761
20877
|
add,
|
|
20762
20878
|
getAll,
|
|
20763
20879
|
updateById,
|
|
20764
20880
|
deleteById,
|
|
20765
|
-
getScheduledRoute
|
|
20881
|
+
getScheduledRoute,
|
|
20882
|
+
getById
|
|
20766
20883
|
};
|
|
20767
20884
|
}
|
|
20768
20885
|
|
|
@@ -20775,7 +20892,8 @@ function usePatrolRouteController() {
|
|
|
20775
20892
|
getAll: _getAll,
|
|
20776
20893
|
updateById: _updateById,
|
|
20777
20894
|
deleteById: _deleteById,
|
|
20778
|
-
getScheduledRoute: _getScheduledRoute
|
|
20895
|
+
getScheduledRoute: _getScheduledRoute,
|
|
20896
|
+
getById: _getById
|
|
20779
20897
|
} = usePatrolRouteRepo();
|
|
20780
20898
|
async function add(req, res, next) {
|
|
20781
20899
|
const data = { ...req.body };
|
|
@@ -20943,12 +21061,34 @@ function usePatrolRouteController() {
|
|
|
20943
21061
|
return;
|
|
20944
21062
|
}
|
|
20945
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
|
+
}
|
|
20946
21085
|
return {
|
|
20947
21086
|
add,
|
|
20948
21087
|
getAll,
|
|
20949
21088
|
updateById,
|
|
20950
21089
|
deleteById,
|
|
20951
|
-
getScheduledRoute
|
|
21090
|
+
getScheduledRoute,
|
|
21091
|
+
getById
|
|
20952
21092
|
};
|
|
20953
21093
|
}
|
|
20954
21094
|
|
|
@@ -21207,6 +21347,30 @@ function usePatrolLogRepo() {
|
|
|
21207
21347
|
throw error;
|
|
21208
21348
|
}
|
|
21209
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
|
+
}
|
|
21210
21374
|
function delCachedData() {
|
|
21211
21375
|
delNamespace().then(() => {
|
|
21212
21376
|
logger92.log({
|
|
@@ -21226,7 +21390,8 @@ function usePatrolLogRepo() {
|
|
|
21226
21390
|
add,
|
|
21227
21391
|
getAll,
|
|
21228
21392
|
updateById,
|
|
21229
|
-
deleteById
|
|
21393
|
+
deleteById,
|
|
21394
|
+
getById
|
|
21230
21395
|
};
|
|
21231
21396
|
}
|
|
21232
21397
|
|
|
@@ -21303,7 +21468,8 @@ function usePatrolLogController() {
|
|
|
21303
21468
|
const {
|
|
21304
21469
|
getAll: _getAll,
|
|
21305
21470
|
updateById: _updateById,
|
|
21306
|
-
deleteById: _deleteById
|
|
21471
|
+
deleteById: _deleteById,
|
|
21472
|
+
getById: _getById
|
|
21307
21473
|
} = usePatrolLogRepo();
|
|
21308
21474
|
const { add: _add } = usePatrolLogService();
|
|
21309
21475
|
async function add(req, res, next) {
|
|
@@ -21415,7 +21581,28 @@ function usePatrolLogController() {
|
|
|
21415
21581
|
return;
|
|
21416
21582
|
}
|
|
21417
21583
|
}
|
|
21418
|
-
|
|
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 };
|
|
21419
21606
|
}
|
|
21420
21607
|
|
|
21421
21608
|
// src/models/site-facility.model.ts
|
|
@@ -23948,7 +24135,7 @@ function useDocumentManagementController() {
|
|
|
23948
24135
|
}
|
|
23949
24136
|
async function deleteDocumentById(req, res, next) {
|
|
23950
24137
|
const validation = Joi74.string().hex().required();
|
|
23951
|
-
const _id = req.
|
|
24138
|
+
const _id = req.query.id;
|
|
23952
24139
|
const { error } = validation.validate(_id);
|
|
23953
24140
|
if (error) {
|
|
23954
24141
|
logger102.log({ level: "error", message: error.message });
|
|
@@ -27647,22 +27834,31 @@ function UseAccessManagementRepo() {
|
|
|
27647
27834
|
throw new Error(error.message);
|
|
27648
27835
|
}
|
|
27649
27836
|
}
|
|
27837
|
+
function getAfterSecondSlash(term) {
|
|
27838
|
+
const first = term.indexOf("/");
|
|
27839
|
+
if (first === -1)
|
|
27840
|
+
return "";
|
|
27841
|
+
const second = term.indexOf("/", first + 1);
|
|
27842
|
+
if (second === -1)
|
|
27843
|
+
return "";
|
|
27844
|
+
return term.substring(second + 1).toLowerCase();
|
|
27845
|
+
}
|
|
27650
27846
|
function buildSearchQuery(search) {
|
|
27651
27847
|
if (!search) {
|
|
27652
27848
|
return {};
|
|
27653
27849
|
}
|
|
27654
27850
|
const terms = search.split("/").map((s) => s.trim()).filter(Boolean);
|
|
27655
|
-
if (search.includes("/")
|
|
27656
|
-
switch (
|
|
27657
|
-
case 3:
|
|
27851
|
+
if (search.includes("/")) {
|
|
27852
|
+
switch (true) {
|
|
27853
|
+
case terms.length >= 3:
|
|
27658
27854
|
return {
|
|
27659
27855
|
$and: [
|
|
27660
27856
|
{ $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
|
|
27661
27857
|
{ $expr: { $eq: [{ $toLower: "$level.level" }, terms[1].toLowerCase()] } },
|
|
27662
|
-
{ $expr: { $eq: [{ $toLower: "$level.units.name" },
|
|
27858
|
+
{ $expr: { $eq: [{ $toLower: "$level.units.name" }, getAfterSecondSlash(search)] } }
|
|
27663
27859
|
]
|
|
27664
27860
|
};
|
|
27665
|
-
case 2:
|
|
27861
|
+
case terms.length === 2:
|
|
27666
27862
|
return {
|
|
27667
27863
|
$and: [
|
|
27668
27864
|
{ $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
|
|
@@ -27893,6 +28089,207 @@ function UseAccessManagementRepo() {
|
|
|
27893
28089
|
throw new Error(error.message);
|
|
27894
28090
|
}
|
|
27895
28091
|
}
|
|
28092
|
+
async function assignedAccessCardsRepo(params) {
|
|
28093
|
+
try {
|
|
28094
|
+
const site = new ObjectId83(params.site);
|
|
28095
|
+
const userType = params.userType;
|
|
28096
|
+
const type = params.type;
|
|
28097
|
+
const search = params.search;
|
|
28098
|
+
const query = {
|
|
28099
|
+
site: { $in: [site] }
|
|
28100
|
+
};
|
|
28101
|
+
const searchQuery = buildSearchQuery(search);
|
|
28102
|
+
const result = await collectionName("buildings").aggregate([
|
|
28103
|
+
// ✅ Match early with index-friendly query
|
|
28104
|
+
{
|
|
28105
|
+
$match: {
|
|
28106
|
+
...query,
|
|
28107
|
+
status: { $ne: "deleted" }
|
|
28108
|
+
}
|
|
28109
|
+
},
|
|
28110
|
+
// ✅ Only project needed fields before heavy lookups
|
|
28111
|
+
{
|
|
28112
|
+
$project: {
|
|
28113
|
+
_id: 1,
|
|
28114
|
+
name: 1,
|
|
28115
|
+
site: 1
|
|
28116
|
+
}
|
|
28117
|
+
},
|
|
28118
|
+
// ✅ Use localField/foreignField for better index usage
|
|
28119
|
+
{
|
|
28120
|
+
$lookup: {
|
|
28121
|
+
from: "building-levels",
|
|
28122
|
+
localField: "_id",
|
|
28123
|
+
foreignField: "block",
|
|
28124
|
+
pipeline: [
|
|
28125
|
+
{ $match: { status: { $ne: "deleted" } } },
|
|
28126
|
+
{
|
|
28127
|
+
$lookup: {
|
|
28128
|
+
from: "building-units",
|
|
28129
|
+
localField: "_id",
|
|
28130
|
+
foreignField: "level",
|
|
28131
|
+
pipeline: [
|
|
28132
|
+
{ $match: { status: { $ne: "deleted" } } },
|
|
28133
|
+
{ $project: { _id: 1, name: 1 } },
|
|
28134
|
+
{
|
|
28135
|
+
$lookup: {
|
|
28136
|
+
from: "access-cards",
|
|
28137
|
+
localField: "_id",
|
|
28138
|
+
foreignField: "assignedUnit",
|
|
28139
|
+
pipeline: [
|
|
28140
|
+
{
|
|
28141
|
+
$match: {
|
|
28142
|
+
isActivated: true,
|
|
28143
|
+
userType,
|
|
28144
|
+
type
|
|
28145
|
+
}
|
|
28146
|
+
},
|
|
28147
|
+
{
|
|
28148
|
+
$group: {
|
|
28149
|
+
_id: null,
|
|
28150
|
+
accessLevels: { $addToSet: "$accessLevel" },
|
|
28151
|
+
liftAccessLevels: { $addToSet: "$liftAccessLevel" },
|
|
28152
|
+
doorNames: { $addToSet: "$doorName" },
|
|
28153
|
+
liftNames: { $addToSet: "$liftName" },
|
|
28154
|
+
cards: {
|
|
28155
|
+
$push: {
|
|
28156
|
+
_id: "$_id",
|
|
28157
|
+
cardNo: "$cardNo",
|
|
28158
|
+
accessLevel: "$accessLevel",
|
|
28159
|
+
liftAccessLevel: "$liftAccessLevel",
|
|
28160
|
+
doorName: "$doorName",
|
|
28161
|
+
liftName: "$liftName"
|
|
28162
|
+
}
|
|
28163
|
+
}
|
|
28164
|
+
}
|
|
28165
|
+
},
|
|
28166
|
+
{
|
|
28167
|
+
$project: {
|
|
28168
|
+
_id: 0,
|
|
28169
|
+
accessCardCount: {
|
|
28170
|
+
$size: "$cards"
|
|
28171
|
+
},
|
|
28172
|
+
accessLevels: 1,
|
|
28173
|
+
liftAccessLevels: 1,
|
|
28174
|
+
doorNames: 1,
|
|
28175
|
+
liftNames: 1
|
|
28176
|
+
}
|
|
28177
|
+
}
|
|
28178
|
+
],
|
|
28179
|
+
as: "fAccessCards"
|
|
28180
|
+
}
|
|
28181
|
+
},
|
|
28182
|
+
{
|
|
28183
|
+
$match: {
|
|
28184
|
+
"fAccessCards.0": { $exists: true }
|
|
28185
|
+
}
|
|
28186
|
+
}
|
|
28187
|
+
],
|
|
28188
|
+
as: "units"
|
|
28189
|
+
}
|
|
28190
|
+
},
|
|
28191
|
+
{
|
|
28192
|
+
$match: { "units.0": { $exists: true } }
|
|
28193
|
+
},
|
|
28194
|
+
{
|
|
28195
|
+
$project: {
|
|
28196
|
+
_id: 1,
|
|
28197
|
+
level: 1,
|
|
28198
|
+
units: 1
|
|
28199
|
+
}
|
|
28200
|
+
}
|
|
28201
|
+
],
|
|
28202
|
+
as: "level"
|
|
28203
|
+
}
|
|
28204
|
+
},
|
|
28205
|
+
// ✅ Filter out buildings with no levels early
|
|
28206
|
+
{
|
|
28207
|
+
$match: { "level.0": { $exists: true } }
|
|
28208
|
+
},
|
|
28209
|
+
// ✅ Unwind to flatten the hierarchy
|
|
28210
|
+
{
|
|
28211
|
+
$unwind: {
|
|
28212
|
+
path: "$level",
|
|
28213
|
+
preserveNullAndEmptyArrays: false
|
|
28214
|
+
}
|
|
28215
|
+
},
|
|
28216
|
+
{
|
|
28217
|
+
$unwind: {
|
|
28218
|
+
path: "$level.units",
|
|
28219
|
+
preserveNullAndEmptyArrays: false
|
|
28220
|
+
}
|
|
28221
|
+
},
|
|
28222
|
+
{
|
|
28223
|
+
$unwind: {
|
|
28224
|
+
path: "$level.units.fAccessCards",
|
|
28225
|
+
preserveNullAndEmptyArrays: false
|
|
28226
|
+
}
|
|
28227
|
+
},
|
|
28228
|
+
// // Groups by unit _id and keeps only the first occurrence
|
|
28229
|
+
{
|
|
28230
|
+
$group: {
|
|
28231
|
+
_id: "$level.units._id",
|
|
28232
|
+
doc: { $first: "$$ROOT" }
|
|
28233
|
+
}
|
|
28234
|
+
},
|
|
28235
|
+
{
|
|
28236
|
+
$replaceRoot: { newRoot: "$doc" }
|
|
28237
|
+
},
|
|
28238
|
+
// ✅ Apply search filter
|
|
28239
|
+
{
|
|
28240
|
+
$match: {
|
|
28241
|
+
...searchQuery
|
|
28242
|
+
}
|
|
28243
|
+
},
|
|
28244
|
+
{
|
|
28245
|
+
$project: {
|
|
28246
|
+
name: 1,
|
|
28247
|
+
"level.level": 1,
|
|
28248
|
+
"level.units.name": 1,
|
|
28249
|
+
"level.units.fAccessCards": 1
|
|
28250
|
+
}
|
|
28251
|
+
}
|
|
28252
|
+
], { allowDiskUse: true }).toArray();
|
|
28253
|
+
return result;
|
|
28254
|
+
} catch (error) {
|
|
28255
|
+
throw new Error(error.message);
|
|
28256
|
+
}
|
|
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
|
+
}
|
|
27896
28293
|
return {
|
|
27897
28294
|
createIndexes,
|
|
27898
28295
|
createIndexForEntrypass,
|
|
@@ -27901,7 +28298,9 @@ function UseAccessManagementRepo() {
|
|
|
27901
28298
|
accessManagementSettingsRepo,
|
|
27902
28299
|
allAccessCardsCountsRepo,
|
|
27903
28300
|
availableAccessCardsRepo,
|
|
27904
|
-
userTypeAccessCardsRepo
|
|
28301
|
+
userTypeAccessCardsRepo,
|
|
28302
|
+
assignedAccessCardsRepo,
|
|
28303
|
+
acknowlegdeCardRepo
|
|
27905
28304
|
};
|
|
27906
28305
|
}
|
|
27907
28306
|
|
|
@@ -28006,6 +28405,8 @@ var formatAccessGroup = (data, search) => {
|
|
|
28006
28405
|
|
|
28007
28406
|
// src/services/access-management.service.ts
|
|
28008
28407
|
import { parseStringPromise } from "xml2js";
|
|
28408
|
+
import { useCache as useCache47 } from "@7365admin1/node-server-utils";
|
|
28409
|
+
var namespace = "cache:acm";
|
|
28009
28410
|
function useAccessManagementSvc() {
|
|
28010
28411
|
const {
|
|
28011
28412
|
addPhysicalCardRepo,
|
|
@@ -28013,7 +28414,9 @@ function useAccessManagementSvc() {
|
|
|
28013
28414
|
accessManagementSettingsRepo,
|
|
28014
28415
|
allAccessCardsCountsRepo,
|
|
28015
28416
|
availableAccessCardsRepo,
|
|
28016
|
-
userTypeAccessCardsRepo
|
|
28417
|
+
userTypeAccessCardsRepo,
|
|
28418
|
+
assignedAccessCardsRepo,
|
|
28419
|
+
acknowlegdeCardRepo
|
|
28017
28420
|
} = UseAccessManagementRepo();
|
|
28018
28421
|
const addPhysicalCardSvc = async (payload) => {
|
|
28019
28422
|
try {
|
|
@@ -28031,12 +28434,34 @@ function useAccessManagementSvc() {
|
|
|
28031
28434
|
throw new Error(err.message);
|
|
28032
28435
|
}
|
|
28033
28436
|
};
|
|
28437
|
+
const setCache = async (params) => {
|
|
28438
|
+
const { key, data, ttlSeconds = 60, redis } = params;
|
|
28439
|
+
const jsonData = JSON.stringify(data);
|
|
28440
|
+
await redis.set(key, jsonData, "EX", ttlSeconds);
|
|
28441
|
+
};
|
|
28442
|
+
const getCache = async (params) => {
|
|
28443
|
+
const { key, redis } = params;
|
|
28444
|
+
const result = await redis.get(key);
|
|
28445
|
+
return result ? JSON.parse(result) : null;
|
|
28446
|
+
};
|
|
28034
28447
|
const doorAccessLevelsSvc = async (params) => {
|
|
28035
28448
|
try {
|
|
28449
|
+
const key = `${namespace}:${params.user}:door-levels`;
|
|
28450
|
+
const listKey = `${namespace}:${params.user}:list`;
|
|
28451
|
+
const { redis } = useCache47(key);
|
|
28452
|
+
const cachedData = await getCache({ key, redis });
|
|
28453
|
+
if (cachedData) {
|
|
28454
|
+
console.log("\u26A1 Cache hit:", key);
|
|
28455
|
+
redis.expire(key, 60).catch(console.error);
|
|
28456
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28457
|
+
return cachedData;
|
|
28458
|
+
}
|
|
28036
28459
|
const command = readTemplate("door-levels");
|
|
28037
28460
|
const response = await sendCommand(command, params.acm_url);
|
|
28038
28461
|
const res = await parseStringPromise(response, { explicitArray: false });
|
|
28039
28462
|
const format = await formatDoorAccessLevels(res);
|
|
28463
|
+
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28464
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28040
28465
|
return format;
|
|
28041
28466
|
} catch (err) {
|
|
28042
28467
|
throw new Error(err.message);
|
|
@@ -28044,10 +28469,22 @@ function useAccessManagementSvc() {
|
|
|
28044
28469
|
};
|
|
28045
28470
|
const liftAccessLevelsSvc = async (params) => {
|
|
28046
28471
|
try {
|
|
28472
|
+
const key = `${namespace}:${params.user}:lift-levels`;
|
|
28473
|
+
const listKey = `${namespace}:${params.user}:list`;
|
|
28474
|
+
const { redis } = useCache47(key);
|
|
28475
|
+
const cachedData = await getCache({ key, redis });
|
|
28476
|
+
if (cachedData) {
|
|
28477
|
+
console.log("\u26A1 Cache hit:", key);
|
|
28478
|
+
redis.expire(key, 60).catch(console.error);
|
|
28479
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28480
|
+
return cachedData;
|
|
28481
|
+
}
|
|
28047
28482
|
const command = readTemplate("lift-levels");
|
|
28048
28483
|
const response = await sendCommand(command, params.acm_url);
|
|
28049
28484
|
const res = await parseStringPromise(response, { explicitArray: false });
|
|
28050
28485
|
const format = await formatLiftAccessLevels(res);
|
|
28486
|
+
await setCache({ key, data: format, ttlSeconds: 60, redis });
|
|
28487
|
+
redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
|
|
28051
28488
|
return format;
|
|
28052
28489
|
} catch (error) {
|
|
28053
28490
|
throw new Error(error.message);
|
|
@@ -28055,10 +28492,22 @@ function useAccessManagementSvc() {
|
|
|
28055
28492
|
};
|
|
28056
28493
|
const accessGroupsSvc = async (params) => {
|
|
28057
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
|
+
}
|
|
28058
28505
|
const command = readTemplate("access-group");
|
|
28059
28506
|
const response = await sendCommand(command, params.acm_url);
|
|
28060
28507
|
const res = await parseStringPromise(response, { explicitArray: false });
|
|
28061
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);
|
|
28062
28511
|
return format;
|
|
28063
28512
|
} catch (err) {
|
|
28064
28513
|
throw new Error(err.message);
|
|
@@ -28096,6 +28545,22 @@ function useAccessManagementSvc() {
|
|
|
28096
28545
|
throw new Error(err.message);
|
|
28097
28546
|
}
|
|
28098
28547
|
};
|
|
28548
|
+
const assignedAccessCardsSvc = async (params) => {
|
|
28549
|
+
try {
|
|
28550
|
+
const response = await assignedAccessCardsRepo({ ...params });
|
|
28551
|
+
return response;
|
|
28552
|
+
} catch (err) {
|
|
28553
|
+
throw new Error(err.message);
|
|
28554
|
+
}
|
|
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
|
+
};
|
|
28099
28564
|
return {
|
|
28100
28565
|
addPhysicalCardSvc,
|
|
28101
28566
|
addNonPhysicalCardSvc,
|
|
@@ -28105,7 +28570,9 @@ function useAccessManagementSvc() {
|
|
|
28105
28570
|
accessManagementSettingsSvc,
|
|
28106
28571
|
allAccessCardsCountsSvc,
|
|
28107
28572
|
availableAccessCardsSvc,
|
|
28108
|
-
userTypeAccessCardsSvc
|
|
28573
|
+
userTypeAccessCardsSvc,
|
|
28574
|
+
assignedAccessCardsSvc,
|
|
28575
|
+
acknowlegdeCardSvc
|
|
28109
28576
|
};
|
|
28110
28577
|
}
|
|
28111
28578
|
|
|
@@ -28120,7 +28587,9 @@ function useAccessManagementController() {
|
|
|
28120
28587
|
accessManagementSettingsSvc,
|
|
28121
28588
|
allAccessCardsCountsSvc,
|
|
28122
28589
|
availableAccessCardsSvc,
|
|
28123
|
-
userTypeAccessCardsSvc
|
|
28590
|
+
userTypeAccessCardsSvc,
|
|
28591
|
+
assignedAccessCardsSvc,
|
|
28592
|
+
acknowlegdeCardSvc
|
|
28124
28593
|
} = useAccessManagementSvc();
|
|
28125
28594
|
const addPhysicalCard = async (req, res) => {
|
|
28126
28595
|
try {
|
|
@@ -28251,10 +28720,11 @@ function useAccessManagementController() {
|
|
|
28251
28720
|
const doorAccessLevels = async (req, res) => {
|
|
28252
28721
|
try {
|
|
28253
28722
|
const { acm_url } = req.query;
|
|
28723
|
+
const user = req.cookies?.sid;
|
|
28254
28724
|
if (!acm_url || typeof acm_url !== "string") {
|
|
28255
28725
|
throw new Error("Access Control URL is required");
|
|
28256
28726
|
}
|
|
28257
|
-
const result = await doorAccessLevelsSvc({ acm_url });
|
|
28727
|
+
const result = await doorAccessLevelsSvc({ acm_url, user });
|
|
28258
28728
|
return res.status(200).json({ message: "Success", data: result });
|
|
28259
28729
|
} catch (error) {
|
|
28260
28730
|
return res.status(400).json({
|
|
@@ -28266,10 +28736,11 @@ function useAccessManagementController() {
|
|
|
28266
28736
|
const liftAccessLevels = async (req, res) => {
|
|
28267
28737
|
try {
|
|
28268
28738
|
const { acm_url } = req.query;
|
|
28739
|
+
const user = req.cookies?.sid;
|
|
28269
28740
|
if (!acm_url || typeof acm_url !== "string") {
|
|
28270
28741
|
throw new Error("Access Control URL is required");
|
|
28271
28742
|
}
|
|
28272
|
-
const result = await liftAccessLevelsSvc({ acm_url });
|
|
28743
|
+
const result = await liftAccessLevelsSvc({ acm_url, user });
|
|
28273
28744
|
return res.status(200).json({ message: "Success", data: result });
|
|
28274
28745
|
} catch (error) {
|
|
28275
28746
|
return res.status(400).json({
|
|
@@ -28281,10 +28752,11 @@ function useAccessManagementController() {
|
|
|
28281
28752
|
const accessGroups = async (req, res) => {
|
|
28282
28753
|
try {
|
|
28283
28754
|
const { acm_url } = req.query;
|
|
28755
|
+
const user = req.cookies?.sid;
|
|
28284
28756
|
if (!acm_url || typeof acm_url !== "string") {
|
|
28285
28757
|
throw new Error("Access Control URL is required");
|
|
28286
28758
|
}
|
|
28287
|
-
const result = await accessGroupsSvc({ acm_url });
|
|
28759
|
+
const result = await accessGroupsSvc({ acm_url, user });
|
|
28288
28760
|
return res.status(200).json({ message: "Success", data: result });
|
|
28289
28761
|
} catch (error) {
|
|
28290
28762
|
return res.status(400).json({
|
|
@@ -28377,6 +28849,49 @@ function useAccessManagementController() {
|
|
|
28377
28849
|
});
|
|
28378
28850
|
}
|
|
28379
28851
|
};
|
|
28852
|
+
const assignedAccessCards = async (req, res) => {
|
|
28853
|
+
try {
|
|
28854
|
+
const { site, userType, type, search = "" } = req.query;
|
|
28855
|
+
const schema2 = Joi85.object({
|
|
28856
|
+
site: Joi85.string().hex().required(),
|
|
28857
|
+
userType: Joi85.string().required(),
|
|
28858
|
+
type: Joi85.string().required(),
|
|
28859
|
+
search: Joi85.string().optional().allow("", null)
|
|
28860
|
+
});
|
|
28861
|
+
const { error } = schema2.validate({ site, userType, type, search });
|
|
28862
|
+
if (error) {
|
|
28863
|
+
return res.status(400).json({ message: error.message });
|
|
28864
|
+
}
|
|
28865
|
+
const result = await assignedAccessCardsSvc({ site, userType, type, search });
|
|
28866
|
+
return res.status(200).json({ message: "Success", data: result });
|
|
28867
|
+
} catch (error) {
|
|
28868
|
+
return res.status(500).json({
|
|
28869
|
+
data: null,
|
|
28870
|
+
message: error.message
|
|
28871
|
+
});
|
|
28872
|
+
}
|
|
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
|
+
};
|
|
28380
28895
|
return {
|
|
28381
28896
|
addPhysicalCard,
|
|
28382
28897
|
addNonPhysicalCard,
|
|
@@ -28386,7 +28901,9 @@ function useAccessManagementController() {
|
|
|
28386
28901
|
accessManagementSettings,
|
|
28387
28902
|
allAccessCardsCounts,
|
|
28388
28903
|
availableAccessCards,
|
|
28389
|
-
userTypeAccessCards
|
|
28904
|
+
userTypeAccessCards,
|
|
28905
|
+
assignedAccessCards,
|
|
28906
|
+
acknowlegdeCard
|
|
28390
28907
|
};
|
|
28391
28908
|
}
|
|
28392
28909
|
|
|
@@ -28456,7 +28973,7 @@ import {
|
|
|
28456
28973
|
makeCacheKey as makeCacheKey45,
|
|
28457
28974
|
paginate as paginate39,
|
|
28458
28975
|
useAtlas as useAtlas75,
|
|
28459
|
-
useCache as
|
|
28976
|
+
useCache as useCache48
|
|
28460
28977
|
} from "@7365admin1/node-server-utils";
|
|
28461
28978
|
import { ObjectId as ObjectId85 } from "mongodb";
|
|
28462
28979
|
function useNfcPatrolTagRepo() {
|
|
@@ -28467,8 +28984,8 @@ function useNfcPatrolTagRepo() {
|
|
|
28467
28984
|
const namespace_collection = "nfc-patrol-tags";
|
|
28468
28985
|
const namespace_collection_nfc_patrol_routes = "nfc-patrol-routes";
|
|
28469
28986
|
const collection = db.collection(namespace_collection);
|
|
28470
|
-
const { delNamespace, getCache, setCache } =
|
|
28471
|
-
const { delNamespace: delNamespaceNfcPatrolRoutes } =
|
|
28987
|
+
const { delNamespace, getCache, setCache } = useCache48(namespace_collection);
|
|
28988
|
+
const { delNamespace: delNamespaceNfcPatrolRoutes } = useCache48(
|
|
28472
28989
|
namespace_collection_nfc_patrol_routes
|
|
28473
28990
|
);
|
|
28474
28991
|
async function createIndexes() {
|
|
@@ -28915,7 +29432,7 @@ import {
|
|
|
28915
29432
|
NotFoundError as NotFoundError37,
|
|
28916
29433
|
paginate as paginate40,
|
|
28917
29434
|
useAtlas as useAtlas77,
|
|
28918
|
-
useCache as
|
|
29435
|
+
useCache as useCache49
|
|
28919
29436
|
} from "@7365admin1/node-server-utils";
|
|
28920
29437
|
import { ObjectId as ObjectId87 } from "mongodb";
|
|
28921
29438
|
function useOccurrenceBookRepo() {
|
|
@@ -28947,7 +29464,7 @@ function useOccurrenceBookRepo() {
|
|
|
28947
29464
|
}
|
|
28948
29465
|
const namespace_collection = "occurrence-books";
|
|
28949
29466
|
const collection = db.collection(namespace_collection);
|
|
28950
|
-
const { delNamespace, getCache, setCache } =
|
|
29467
|
+
const { delNamespace, getCache, setCache } = useCache49(namespace_collection);
|
|
28951
29468
|
async function add(value, session) {
|
|
28952
29469
|
try {
|
|
28953
29470
|
value = MOccurrenceBook(value);
|
|
@@ -29525,7 +30042,7 @@ import {
|
|
|
29525
30042
|
NotFoundError as NotFoundError38,
|
|
29526
30043
|
paginate as paginate41,
|
|
29527
30044
|
useAtlas as useAtlas79,
|
|
29528
|
-
useCache as
|
|
30045
|
+
useCache as useCache50
|
|
29529
30046
|
} from "@7365admin1/node-server-utils";
|
|
29530
30047
|
import { ObjectId as ObjectId89 } from "mongodb";
|
|
29531
30048
|
function useBulletinVideoRepo() {
|
|
@@ -29544,7 +30061,7 @@ function useBulletinVideoRepo() {
|
|
|
29544
30061
|
}
|
|
29545
30062
|
const namespace_collection = "bulletin-videos";
|
|
29546
30063
|
const collection = db.collection(namespace_collection);
|
|
29547
|
-
const { delNamespace, getCache, setCache } =
|
|
30064
|
+
const { delNamespace, getCache, setCache } = useCache50(namespace_collection);
|
|
29548
30065
|
async function add(value, session) {
|
|
29549
30066
|
try {
|
|
29550
30067
|
value = MBulletinVideo(value);
|
|
@@ -30076,7 +30593,7 @@ import {
|
|
|
30076
30593
|
InternalServerError as InternalServerError51,
|
|
30077
30594
|
logger as logger127,
|
|
30078
30595
|
useAtlas as useAtlas81,
|
|
30079
|
-
useCache as
|
|
30596
|
+
useCache as useCache51,
|
|
30080
30597
|
paginate as paginate42,
|
|
30081
30598
|
makeCacheKey as makeCacheKey48
|
|
30082
30599
|
} from "@7365admin1/node-server-utils";
|
|
@@ -30088,7 +30605,7 @@ function useStatementOfAccountRepo() {
|
|
|
30088
30605
|
}
|
|
30089
30606
|
const namespace_collection = "site.statement-of-accounts";
|
|
30090
30607
|
const collection = db.collection(namespace_collection);
|
|
30091
|
-
const { delNamespace, getCache, setCache } =
|
|
30608
|
+
const { delNamespace, getCache, setCache } = useCache51(namespace_collection);
|
|
30092
30609
|
async function createTextIndex() {
|
|
30093
30610
|
try {
|
|
30094
30611
|
await collection.createIndex({
|
|
@@ -30851,7 +31368,7 @@ import {
|
|
|
30851
31368
|
NotFoundError as NotFoundError40,
|
|
30852
31369
|
paginate as paginate43,
|
|
30853
31370
|
useAtlas as useAtlas83,
|
|
30854
|
-
useCache as
|
|
31371
|
+
useCache as useCache52
|
|
30855
31372
|
} from "@7365admin1/node-server-utils";
|
|
30856
31373
|
import { ObjectId as ObjectId93 } from "mongodb";
|
|
30857
31374
|
function useEntryPassSettingsRepo() {
|
|
@@ -30861,7 +31378,7 @@ function useEntryPassSettingsRepo() {
|
|
|
30861
31378
|
}
|
|
30862
31379
|
const namespace_collection = "site.entrypass-settings";
|
|
30863
31380
|
const collection = db.collection(namespace_collection);
|
|
30864
|
-
const { delNamespace, getCache, setCache } =
|
|
31381
|
+
const { delNamespace, getCache, setCache } = useCache52(namespace_collection);
|
|
30865
31382
|
async function createTextIndex() {
|
|
30866
31383
|
try {
|
|
30867
31384
|
await collection.createIndex({
|
|
@@ -31423,7 +31940,7 @@ import {
|
|
|
31423
31940
|
logger as logger133,
|
|
31424
31941
|
makeCacheKey as makeCacheKey50,
|
|
31425
31942
|
useAtlas as useAtlas84,
|
|
31426
|
-
useCache as
|
|
31943
|
+
useCache as useCache53
|
|
31427
31944
|
} from "@7365admin1/node-server-utils";
|
|
31428
31945
|
function useDashboardRepo() {
|
|
31429
31946
|
const db = useAtlas84.getDb();
|
|
@@ -31434,7 +31951,7 @@ function useDashboardRepo() {
|
|
|
31434
31951
|
const work_order_collection = db.collection("work-orders");
|
|
31435
31952
|
const visitor_collection = db.collection("visitor.transactions");
|
|
31436
31953
|
const namespace_collection = "dashboard";
|
|
31437
|
-
const { delNamespace, getCache, setCache } =
|
|
31954
|
+
const { delNamespace, getCache, setCache } = useCache53(namespace_collection);
|
|
31438
31955
|
async function getAll({
|
|
31439
31956
|
site = ""
|
|
31440
31957
|
}, session) {
|
|
@@ -31598,7 +32115,7 @@ import {
|
|
|
31598
32115
|
makeCacheKey as makeCacheKey51,
|
|
31599
32116
|
paginate as paginate44,
|
|
31600
32117
|
useAtlas as useAtlas85,
|
|
31601
|
-
useCache as
|
|
32118
|
+
useCache as useCache54
|
|
31602
32119
|
} from "@7365admin1/node-server-utils";
|
|
31603
32120
|
import { ObjectId as ObjectId95 } from "mongodb";
|
|
31604
32121
|
function useNfcPatrolRouteRepo() {
|
|
@@ -31608,7 +32125,7 @@ function useNfcPatrolRouteRepo() {
|
|
|
31608
32125
|
}
|
|
31609
32126
|
const namespace_collection = "nfc-patrol-routes";
|
|
31610
32127
|
const collection = db.collection(namespace_collection);
|
|
31611
|
-
const { delNamespace, getCache, setCache } =
|
|
32128
|
+
const { delNamespace, getCache, setCache } = useCache54(namespace_collection);
|
|
31612
32129
|
async function createIndexes() {
|
|
31613
32130
|
try {
|
|
31614
32131
|
await collection.createIndexes([
|
|
@@ -32345,7 +32862,7 @@ import {
|
|
|
32345
32862
|
NotFoundError as NotFoundError43,
|
|
32346
32863
|
paginate as paginate45,
|
|
32347
32864
|
useAtlas as useAtlas87,
|
|
32348
|
-
useCache as
|
|
32865
|
+
useCache as useCache55
|
|
32349
32866
|
} from "@7365admin1/node-server-utils";
|
|
32350
32867
|
import { ObjectId as ObjectId97 } from "mongodb";
|
|
32351
32868
|
function useIncidentReportRepo() {
|
|
@@ -32376,7 +32893,7 @@ function useIncidentReportRepo() {
|
|
|
32376
32893
|
}
|
|
32377
32894
|
const namespace_collection = "incident-reports";
|
|
32378
32895
|
const collection = db.collection(namespace_collection);
|
|
32379
|
-
const { delNamespace, getCache, setCache } =
|
|
32896
|
+
const { delNamespace, getCache, setCache } = useCache55(namespace_collection);
|
|
32380
32897
|
async function add(value, session) {
|
|
32381
32898
|
try {
|
|
32382
32899
|
value = MIncidentReport(value);
|
|
@@ -33117,7 +33634,7 @@ import {
|
|
|
33117
33634
|
makeCacheKey as makeCacheKey53,
|
|
33118
33635
|
NotFoundError as NotFoundError45,
|
|
33119
33636
|
useAtlas as useAtlas89,
|
|
33120
|
-
useCache as
|
|
33637
|
+
useCache as useCache56
|
|
33121
33638
|
} from "@7365admin1/node-server-utils";
|
|
33122
33639
|
import { ObjectId as ObjectId99 } from "mongodb";
|
|
33123
33640
|
function useNfcPatrolSettingsRepository() {
|
|
@@ -33127,7 +33644,7 @@ function useNfcPatrolSettingsRepository() {
|
|
|
33127
33644
|
}
|
|
33128
33645
|
const namespace_collection = "site.nfc-patrol-settings";
|
|
33129
33646
|
const collection = db.collection(namespace_collection);
|
|
33130
|
-
const { delNamespace, setCache, getCache } =
|
|
33647
|
+
const { delNamespace, setCache, getCache } = useCache56(namespace_collection);
|
|
33131
33648
|
async function createIndexes() {
|
|
33132
33649
|
try {
|
|
33133
33650
|
await collection.createIndexes([{ key: { site: 1 }, unique: true }]);
|
|
@@ -33372,7 +33889,7 @@ import {
|
|
|
33372
33889
|
NotFoundError as NotFoundError46,
|
|
33373
33890
|
paginate as paginate46,
|
|
33374
33891
|
useAtlas as useAtlas91,
|
|
33375
|
-
useCache as
|
|
33892
|
+
useCache as useCache57
|
|
33376
33893
|
} from "@7365admin1/node-server-utils";
|
|
33377
33894
|
|
|
33378
33895
|
// src/models/occurrence-subject.model.ts
|
|
@@ -33449,7 +33966,7 @@ function useOccurrenceSubjectRepo() {
|
|
|
33449
33966
|
}
|
|
33450
33967
|
const namespace_collection = "occurrence-subjects";
|
|
33451
33968
|
const collection = db.collection(namespace_collection);
|
|
33452
|
-
const { delNamespace, getCache, setCache } =
|
|
33969
|
+
const { delNamespace, getCache, setCache } = useCache57(namespace_collection);
|
|
33453
33970
|
async function add(value, session) {
|
|
33454
33971
|
try {
|
|
33455
33972
|
value = MOccurrenceSubject(value);
|
|
@@ -34017,7 +34534,7 @@ import {
|
|
|
34017
34534
|
NotFoundError as NotFoundError47,
|
|
34018
34535
|
paginate as paginate47,
|
|
34019
34536
|
useAtlas as useAtlas93,
|
|
34020
|
-
useCache as
|
|
34537
|
+
useCache as useCache58
|
|
34021
34538
|
} from "@7365admin1/node-server-utils";
|
|
34022
34539
|
import { ObjectId as ObjectId103 } from "mongodb";
|
|
34023
34540
|
function useOnlineFormRepo() {
|
|
@@ -34027,7 +34544,7 @@ function useOnlineFormRepo() {
|
|
|
34027
34544
|
}
|
|
34028
34545
|
const namespace_collection = "online-forms";
|
|
34029
34546
|
const collection = db.collection(namespace_collection);
|
|
34030
|
-
const { delNamespace, getCache, setCache } =
|
|
34547
|
+
const { delNamespace, getCache, setCache } = useCache58(namespace_collection);
|
|
34031
34548
|
async function createTextIndex() {
|
|
34032
34549
|
try {
|
|
34033
34550
|
await collection.createIndex({
|
|
@@ -34763,7 +35280,7 @@ import {
|
|
|
34763
35280
|
makeCacheKey as makeCacheKey56,
|
|
34764
35281
|
paginate as paginate48,
|
|
34765
35282
|
useAtlas as useAtlas95,
|
|
34766
|
-
useCache as
|
|
35283
|
+
useCache as useCache59
|
|
34767
35284
|
} from "@7365admin1/node-server-utils";
|
|
34768
35285
|
import { ObjectId as ObjectId105 } from "mongodb";
|
|
34769
35286
|
function useNfcPatrolLogRepo() {
|
|
@@ -34773,7 +35290,7 @@ function useNfcPatrolLogRepo() {
|
|
|
34773
35290
|
}
|
|
34774
35291
|
const namespace_collection = "nfc-patrol-logs";
|
|
34775
35292
|
const collection = db.collection(namespace_collection);
|
|
34776
|
-
const { delNamespace, getCache, setCache } =
|
|
35293
|
+
const { delNamespace, getCache, setCache } = useCache59(namespace_collection);
|
|
34777
35294
|
async function createIndexes() {
|
|
34778
35295
|
try {
|
|
34779
35296
|
await collection.createIndexes([
|