@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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 2.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - aeab1d6: get latest changes
8
+
3
9
  ## 2.11.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -192,7 +192,7 @@ declare function useRoleRepo(): {
192
192
  }) => Promise<{}>;
193
193
  updateRole: (_id: string | ObjectId, value: TMiniRole, session?: ClientSession) => Promise<ObjectId>;
194
194
  updatePermissionsById: (_id: string | ObjectId, permissions: TRole["permissions"], session?: ClientSession) => Promise<string>;
195
- deleteRole: (_id: string | ObjectId, session?: ClientSession) => Promise<string>;
195
+ deleteRole: (_id: string | ObjectId, session?: ClientSession) => Promise<void>;
196
196
  getOwnerRolesByTypeOrg: (type: string, org: string | ObjectId) => Promise<TRole[]>;
197
197
  };
198
198
 
@@ -2603,6 +2603,7 @@ declare function usePatrolRouteRepo(): {
2603
2603
  start: string;
2604
2604
  day: number;
2605
2605
  }, session?: ClientSession) => Promise<{}>;
2606
+ getById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.WithId<bson.Document> | TPatrolRoute | null>;
2606
2607
  };
2607
2608
 
2608
2609
  declare function usePatrolRouteController(): {
@@ -2611,6 +2612,7 @@ declare function usePatrolRouteController(): {
2611
2612
  updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2612
2613
  deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2613
2614
  getScheduledRoute: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2615
+ getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2614
2616
  };
2615
2617
 
2616
2618
  type logCamera = {
@@ -2674,6 +2676,7 @@ declare function usePatrolLogRepo(): {
2674
2676
  }, session?: ClientSession) => Promise<{}>;
2675
2677
  updateById: (_id: string | ObjectId, value: Partial<TPatrolLog>, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
2676
2678
  deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<string>;
2679
+ getById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.WithId<bson.Document> | TPatrolLog | null>;
2677
2680
  };
2678
2681
 
2679
2682
  declare function usePatrolLogController(): {
@@ -2681,6 +2684,7 @@ declare function usePatrolLogController(): {
2681
2684
  getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2682
2685
  updateById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2683
2686
  deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2687
+ getById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
2684
2688
  };
2685
2689
 
2686
2690
  type TimeSlot = {
@@ -3843,6 +3847,11 @@ declare function UseAccessManagementRepo(): {
3843
3847
  type: string;
3844
3848
  search: string;
3845
3849
  }) => Promise<bson.Document[]>;
3850
+ acknowlegdeCardRepo: (params: {
3851
+ userId: string[];
3852
+ cardId: string[];
3853
+ site: string;
3854
+ }) => Promise<mongodb.UpdateResult<bson.Document>>;
3846
3855
  };
3847
3856
 
3848
3857
  declare function useAccessManagementController(): {
@@ -3856,6 +3865,7 @@ declare function useAccessManagementController(): {
3856
3865
  availableAccessCards: (req: Request, res: Response) => Promise<Response<any, Record<string, any>>>;
3857
3866
  userTypeAccessCards: (req: Request, res: Response) => Promise<Response<any, Record<string, any>>>;
3858
3867
  assignedAccessCards: (req: Request, res: Response) => Promise<Response<any, Record<string, any>>>;
3868
+ acknowlegdeCard: (req: Request, res: Response) => Promise<Response<any, Record<string, any>>>;
3859
3869
  };
3860
3870
 
3861
3871
  declare const DEVICE_STATUS: {
package/dist/index.js CHANGED
@@ -5598,6 +5598,7 @@ function useRoleRepo() {
5598
5598
  }
5599
5599
  }
5600
5600
  const { delNamespace, setCache, getCache, delCache } = (0, import_node_server_utils23.useCache)(namespace_collection);
5601
+ const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils23.useCache)("dashboard");
5601
5602
  async function addRole(value, session) {
5602
5603
  value = new MRole(value);
5603
5604
  try {
@@ -5860,15 +5861,21 @@ function useRoleRepo() {
5860
5861
  { session }
5861
5862
  );
5862
5863
  if (res.modifiedCount === 0) {
5863
- throw new import_node_server_utils23.InternalServerError("Unable to update feedback status.");
5864
+ throw new import_node_server_utils23.InternalServerError("Unable to update role status.");
5864
5865
  }
5865
- const cacheKey = (0, import_node_server_utils23.makeCacheKey)(namespace_collection, { _id });
5866
- delCache(cacheKey).then(() => {
5867
- import_node_server_utils23.logger.info(`Cache deleted for key: ${cacheKey}`);
5866
+ delNamespace().then(() => {
5867
+ import_node_server_utils23.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
5868
5868
  }).catch((err) => {
5869
- import_node_server_utils23.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
5869
+ import_node_server_utils23.logger.error(
5870
+ `Failed to clear cache for namespace: ${namespace_collection}`,
5871
+ err
5872
+ );
5873
+ });
5874
+ _delDashboardNameSpace().then(() => {
5875
+ import_node_server_utils23.logger.info(`Cache cleared for namespace: dashboard`);
5876
+ }).catch((err) => {
5877
+ import_node_server_utils23.logger.error(`Failed to clear cache for namespace: dashboard`, err);
5870
5878
  });
5871
- return "Successfully deleted role.";
5872
5879
  } catch (error) {
5873
5880
  throw new import_node_server_utils23.InternalServerError("Failed to delete role.");
5874
5881
  }
@@ -6957,7 +6964,7 @@ function useRoleController() {
6957
6964
  }
6958
6965
  async function deleteRole(req, res, next) {
6959
6966
  const validation = import_joi15.default.string().hex().required();
6960
- const _id = req.params.id;
6967
+ const _id = req.query.id;
6961
6968
  const { error } = validation.validate(_id);
6962
6969
  if (error) {
6963
6970
  import_node_server_utils29.logger.log({ level: "error", message: error.message });
@@ -7608,7 +7615,7 @@ function useFileController() {
7608
7615
  }
7609
7616
  async function deleteFile(req, res, next) {
7610
7617
  const validation = import_joi18.default.string().hex().required();
7611
- const _id = req.params.id;
7618
+ const _id = req.query.id;
7612
7619
  const { error } = validation.validate(_id);
7613
7620
  if (error) {
7614
7621
  import_node_server_utils34.logger.log({ level: "error", message: error.message });
@@ -11022,7 +11029,6 @@ function useFeedbackController() {
11022
11029
  async function deleteFeedback(req, res, next) {
11023
11030
  const validation = import_joi28.default.string().hex().required();
11024
11031
  const _id = req.query.id;
11025
- console.log(_id);
11026
11032
  const { error } = validation.validate(_id);
11027
11033
  if (error) {
11028
11034
  import_node_server_utils55.logger.log({ level: "error", message: error.message });
@@ -20802,13 +20808,38 @@ function usePatrolRouteRepo() {
20802
20808
  throw error;
20803
20809
  }
20804
20810
  }
20811
+ async function getById(_id, session) {
20812
+ try {
20813
+ _id = new import_mongodb60.ObjectId(_id);
20814
+ } catch (error) {
20815
+ throw new import_node_server_utils113.BadRequestError("Invalid patrol log ID format.");
20816
+ }
20817
+ const cacheKey = (0, import_node_server_utils113.makeCacheKey)(namespace_collection, { _id });
20818
+ const cachedData = await getCache(cacheKey);
20819
+ if (cachedData) {
20820
+ import_node_server_utils113.logger.info(`Cache hit for key: ${cacheKey}`);
20821
+ return cachedData;
20822
+ }
20823
+ try {
20824
+ const data = await collection.findOne({ _id }, { session });
20825
+ setCache(cacheKey, data, 15 * 60).then(() => {
20826
+ import_node_server_utils113.logger.info(`Cache set for key: ${cacheKey}`);
20827
+ }).catch((err) => {
20828
+ import_node_server_utils113.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
20829
+ });
20830
+ return data;
20831
+ } catch (error) {
20832
+ throw error;
20833
+ }
20834
+ }
20805
20835
  return {
20806
20836
  createTextIndex,
20807
20837
  add,
20808
20838
  getAll,
20809
20839
  updateById,
20810
20840
  deleteById,
20811
- getScheduledRoute
20841
+ getScheduledRoute,
20842
+ getById
20812
20843
  };
20813
20844
  }
20814
20845
 
@@ -20821,7 +20852,8 @@ function usePatrolRouteController() {
20821
20852
  getAll: _getAll,
20822
20853
  updateById: _updateById,
20823
20854
  deleteById: _deleteById,
20824
- getScheduledRoute: _getScheduledRoute
20855
+ getScheduledRoute: _getScheduledRoute,
20856
+ getById: _getById
20825
20857
  } = usePatrolRouteRepo();
20826
20858
  async function add(req, res, next) {
20827
20859
  const data = { ...req.body };
@@ -20989,12 +21021,34 @@ function usePatrolRouteController() {
20989
21021
  return;
20990
21022
  }
20991
21023
  }
21024
+ async function getById(req, res, next) {
21025
+ const id = req.params.id;
21026
+ const validation = import_joi64.default.object({
21027
+ id: import_joi64.default.string().hex().required()
21028
+ });
21029
+ const { error } = validation.validate({ id });
21030
+ if (error) {
21031
+ next(new import_node_server_utils114.BadRequestError(error.message));
21032
+ return;
21033
+ }
21034
+ try {
21035
+ const routes = await _getById(id);
21036
+ res.json({
21037
+ message: "Successfully retrieved patrol routes.",
21038
+ data: routes
21039
+ });
21040
+ return;
21041
+ } catch (error2) {
21042
+ next(error2);
21043
+ }
21044
+ }
20992
21045
  return {
20993
21046
  add,
20994
21047
  getAll,
20995
21048
  updateById,
20996
21049
  deleteById,
20997
- getScheduledRoute
21050
+ getScheduledRoute,
21051
+ getById
20998
21052
  };
20999
21053
  }
21000
21054
 
@@ -21244,6 +21298,30 @@ function usePatrolLogRepo() {
21244
21298
  throw error;
21245
21299
  }
21246
21300
  }
21301
+ async function getById(_id, session) {
21302
+ try {
21303
+ _id = new import_mongodb62.ObjectId(_id);
21304
+ } catch (error) {
21305
+ throw new import_node_server_utils116.BadRequestError("Invalid patrol log ID format.");
21306
+ }
21307
+ const cacheKey = (0, import_node_server_utils116.makeCacheKey)(namespace_collection, { _id });
21308
+ const cachedData = await getCache(cacheKey);
21309
+ if (cachedData) {
21310
+ import_node_server_utils116.logger.info(`Cache hit for key: ${cacheKey}`);
21311
+ return cachedData;
21312
+ }
21313
+ try {
21314
+ const data = await collection.findOne({ _id }, { session });
21315
+ setCache(cacheKey, data, 15 * 60).then(() => {
21316
+ import_node_server_utils116.logger.info(`Cache set for key: ${cacheKey}`);
21317
+ }).catch((err) => {
21318
+ import_node_server_utils116.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
21319
+ });
21320
+ return data;
21321
+ } catch (error) {
21322
+ throw error;
21323
+ }
21324
+ }
21247
21325
  function delCachedData() {
21248
21326
  delNamespace().then(() => {
21249
21327
  import_node_server_utils116.logger.log({
@@ -21263,7 +21341,8 @@ function usePatrolLogRepo() {
21263
21341
  add,
21264
21342
  getAll,
21265
21343
  updateById,
21266
- deleteById
21344
+ deleteById,
21345
+ getById
21267
21346
  };
21268
21347
  }
21269
21348
 
@@ -21335,7 +21414,8 @@ function usePatrolLogController() {
21335
21414
  const {
21336
21415
  getAll: _getAll,
21337
21416
  updateById: _updateById,
21338
- deleteById: _deleteById
21417
+ deleteById: _deleteById,
21418
+ getById: _getById
21339
21419
  } = usePatrolLogRepo();
21340
21420
  const { add: _add } = usePatrolLogService();
21341
21421
  async function add(req, res, next) {
@@ -21447,7 +21527,28 @@ function usePatrolLogController() {
21447
21527
  return;
21448
21528
  }
21449
21529
  }
21450
- return { add, getAll, updateById, deleteById };
21530
+ async function getById(req, res, next) {
21531
+ const id = req.params.id;
21532
+ const validation = import_joi66.default.object({
21533
+ id: import_joi66.default.string().hex().required()
21534
+ });
21535
+ const { error } = validation.validate({ id });
21536
+ if (error) {
21537
+ next(new import_node_server_utils118.BadRequestError(error.message));
21538
+ return;
21539
+ }
21540
+ try {
21541
+ const logs = await _getById(id);
21542
+ res.json({
21543
+ message: "Successfully retrieved patrol log.",
21544
+ data: logs
21545
+ });
21546
+ return;
21547
+ } catch (error2) {
21548
+ next(error2);
21549
+ }
21550
+ }
21551
+ return { add, getAll, updateById, deleteById, getById };
21451
21552
  }
21452
21553
 
21453
21554
  // src/models/site-facility.model.ts
@@ -23940,7 +24041,7 @@ function useDocumentManagementController() {
23940
24041
  }
23941
24042
  async function deleteDocumentById(req, res, next) {
23942
24043
  const validation = import_joi74.default.string().hex().required();
23943
- const _id = req.params.id;
24044
+ const _id = req.query.id;
23944
24045
  const { error } = validation.validate(_id);
23945
24046
  if (error) {
23946
24047
  import_node_server_utils130.logger.log({ level: "error", message: error.message });
@@ -27999,6 +28100,41 @@ function UseAccessManagementRepo() {
27999
28100
  throw new Error(error.message);
28000
28101
  }
28001
28102
  }
28103
+ async function acknowlegdeCardRepo(params) {
28104
+ const session = import_node_server_utils149.useAtlas.getClient()?.startSession();
28105
+ try {
28106
+ session?.startTransaction();
28107
+ const { userId, cardId, site } = params;
28108
+ const allUserId = await Promise.all(userId.map(async (id) => new import_mongodb83.ObjectId(id)));
28109
+ const allCardId = await Promise.all(cardId.map(async (id) => new import_mongodb83.ObjectId(id)));
28110
+ const siteId = new import_mongodb83.ObjectId(site);
28111
+ const result = await collection().updateMany(
28112
+ {
28113
+ $or: [
28114
+ {
28115
+ _id: { $in: allCardId },
28116
+ site: siteId
28117
+ },
28118
+ {
28119
+ userId: { $in: allUserId },
28120
+ site: siteId,
28121
+ isActivated: false,
28122
+ replacementStatus: "Issuance"
28123
+ }
28124
+ ]
28125
+ },
28126
+ { $set: { replacementStatus: "Complete" } },
28127
+ { session }
28128
+ );
28129
+ await session?.commitTransaction();
28130
+ return result;
28131
+ } catch (error) {
28132
+ await session?.abortTransaction();
28133
+ throw new Error(error.message);
28134
+ } finally {
28135
+ await session?.endSession();
28136
+ }
28137
+ }
28002
28138
  return {
28003
28139
  createIndexes,
28004
28140
  createIndexForEntrypass,
@@ -28008,7 +28144,8 @@ function UseAccessManagementRepo() {
28008
28144
  allAccessCardsCountsRepo,
28009
28145
  availableAccessCardsRepo,
28010
28146
  userTypeAccessCardsRepo,
28011
- assignedAccessCardsRepo
28147
+ assignedAccessCardsRepo,
28148
+ acknowlegdeCardRepo
28012
28149
  };
28013
28150
  }
28014
28151
 
@@ -28123,7 +28260,8 @@ function useAccessManagementSvc() {
28123
28260
  allAccessCardsCountsRepo,
28124
28261
  availableAccessCardsRepo,
28125
28262
  userTypeAccessCardsRepo,
28126
- assignedAccessCardsRepo
28263
+ assignedAccessCardsRepo,
28264
+ acknowlegdeCardRepo
28127
28265
  } = UseAccessManagementRepo();
28128
28266
  const addPhysicalCardSvc = async (payload) => {
28129
28267
  try {
@@ -28199,10 +28337,22 @@ function useAccessManagementSvc() {
28199
28337
  };
28200
28338
  const accessGroupsSvc = async (params) => {
28201
28339
  try {
28340
+ const key = `${namespace}:${params.user}:access-groups`;
28341
+ const listKey = `${namespace}:${params.user}:list`;
28342
+ const { redis } = (0, import_node_server_utils150.useCache)(key);
28343
+ const cachedData = await getCache({ key, redis });
28344
+ if (cachedData) {
28345
+ console.log("\u26A1 Cache hit:", key);
28346
+ redis.expire(key, 60).catch(console.error);
28347
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
28348
+ return cachedData;
28349
+ }
28202
28350
  const command = readTemplate("access-group");
28203
28351
  const response = await sendCommand(command, params.acm_url);
28204
28352
  const res = await (0, import_xml2js.parseStringPromise)(response, { explicitArray: false });
28205
28353
  const format = await formatAccessGroup(res);
28354
+ await setCache({ key, data: format, ttlSeconds: 60, redis });
28355
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
28206
28356
  return format;
28207
28357
  } catch (err) {
28208
28358
  throw new Error(err.message);
@@ -28248,6 +28398,14 @@ function useAccessManagementSvc() {
28248
28398
  throw new Error(err.message);
28249
28399
  }
28250
28400
  };
28401
+ const acknowlegdeCardSvc = async (params) => {
28402
+ try {
28403
+ const response = await acknowlegdeCardRepo({ ...params });
28404
+ return response;
28405
+ } catch (err) {
28406
+ throw new Error(err.message);
28407
+ }
28408
+ };
28251
28409
  return {
28252
28410
  addPhysicalCardSvc,
28253
28411
  addNonPhysicalCardSvc,
@@ -28258,7 +28416,8 @@ function useAccessManagementSvc() {
28258
28416
  allAccessCardsCountsSvc,
28259
28417
  availableAccessCardsSvc,
28260
28418
  userTypeAccessCardsSvc,
28261
- assignedAccessCardsSvc
28419
+ assignedAccessCardsSvc,
28420
+ acknowlegdeCardSvc
28262
28421
  };
28263
28422
  }
28264
28423
 
@@ -28274,7 +28433,8 @@ function useAccessManagementController() {
28274
28433
  allAccessCardsCountsSvc,
28275
28434
  availableAccessCardsSvc,
28276
28435
  userTypeAccessCardsSvc,
28277
- assignedAccessCardsSvc
28436
+ assignedAccessCardsSvc,
28437
+ acknowlegdeCardSvc
28278
28438
  } = useAccessManagementSvc();
28279
28439
  const addPhysicalCard = async (req, res) => {
28280
28440
  try {
@@ -28437,10 +28597,11 @@ function useAccessManagementController() {
28437
28597
  const accessGroups = async (req, res) => {
28438
28598
  try {
28439
28599
  const { acm_url } = req.query;
28600
+ const user = req.cookies?.sid;
28440
28601
  if (!acm_url || typeof acm_url !== "string") {
28441
28602
  throw new Error("Access Control URL is required");
28442
28603
  }
28443
- const result = await accessGroupsSvc({ acm_url });
28604
+ const result = await accessGroupsSvc({ acm_url, user });
28444
28605
  return res.status(200).json({ message: "Success", data: result });
28445
28606
  } catch (error) {
28446
28607
  return res.status(400).json({
@@ -28555,6 +28716,27 @@ function useAccessManagementController() {
28555
28716
  });
28556
28717
  }
28557
28718
  };
28719
+ const acknowlegdeCard = async (req, res) => {
28720
+ try {
28721
+ const { userId, site, cardId } = req.body;
28722
+ const schema2 = import_joi85.default.object({
28723
+ userId: import_joi85.default.array().items(import_joi85.default.string().hex()).required(),
28724
+ cardId: import_joi85.default.array().items(import_joi85.default.string().hex()).required(),
28725
+ site: import_joi85.default.string().hex().required()
28726
+ });
28727
+ const { error } = schema2.validate({ userId, cardId, site });
28728
+ if (error) {
28729
+ return res.status(400).json({ message: error.message });
28730
+ }
28731
+ const result = await acknowlegdeCardSvc({ userId, cardId, site });
28732
+ return res.status(200).json({ message: "Success", data: result });
28733
+ } catch (error) {
28734
+ return res.status(500).json({
28735
+ data: null,
28736
+ message: error.message
28737
+ });
28738
+ }
28739
+ };
28558
28740
  return {
28559
28741
  addPhysicalCard,
28560
28742
  addNonPhysicalCard,
@@ -28565,7 +28747,8 @@ function useAccessManagementController() {
28565
28747
  allAccessCardsCounts,
28566
28748
  availableAccessCards,
28567
28749
  userTypeAccessCards,
28568
- assignedAccessCards
28750
+ assignedAccessCards,
28751
+ acknowlegdeCard
28569
28752
  };
28570
28753
  }
28571
28754