@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/dist/index.js CHANGED
@@ -1224,6 +1224,7 @@ function useWorkOrderRepo() {
1224
1224
  }
1225
1225
  }
1226
1226
  const { delNamespace, setCache, getCache, delCache } = (0, import_node_server_utils7.useCache)(namespace_collection);
1227
+ const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils7.useCache)("dashboard");
1227
1228
  async function createWorkOrder(value, session) {
1228
1229
  try {
1229
1230
  value = MWorkOrder(value);
@@ -1236,6 +1237,11 @@ function useWorkOrderRepo() {
1236
1237
  err
1237
1238
  );
1238
1239
  });
1240
+ _delDashboardNameSpace().then(() => {
1241
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: dashboard`);
1242
+ }).catch((err) => {
1243
+ import_node_server_utils7.logger.error(`Failed to clear cache for namespace: dashboard`, err);
1244
+ });
1239
1245
  return res.insertedId;
1240
1246
  } catch (error) {
1241
1247
  throw error;
@@ -1472,11 +1478,18 @@ function useWorkOrderRepo() {
1472
1478
  if (res.modifiedCount === 0) {
1473
1479
  throw new import_node_server_utils7.InternalServerError("Unable to update work order.");
1474
1480
  }
1475
- const cacheKey = (0, import_node_server_utils7.makeCacheKey)(namespace_collection, { _id });
1476
- delCache(cacheKey).then(() => {
1477
- import_node_server_utils7.logger.info(`Cache deleted for key: ${cacheKey}`);
1481
+ delNamespace().then(() => {
1482
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1478
1483
  }).catch((err) => {
1479
- import_node_server_utils7.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
1484
+ import_node_server_utils7.logger.error(
1485
+ `Failed to clear cache for namespace: ${namespace_collection}`,
1486
+ err
1487
+ );
1488
+ });
1489
+ _delDashboardNameSpace().then(() => {
1490
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: dashboard`);
1491
+ }).catch((err) => {
1492
+ import_node_server_utils7.logger.error(`Failed to clear cache for namespace: dashboard`, err);
1480
1493
  });
1481
1494
  return res.modifiedCount;
1482
1495
  } catch (error) {
@@ -1499,11 +1512,18 @@ function useWorkOrderRepo() {
1499
1512
  if (res.modifiedCount === 0) {
1500
1513
  throw new import_node_server_utils7.InternalServerError("Unable to update work order status.");
1501
1514
  }
1502
- const cacheKey = (0, import_node_server_utils7.makeCacheKey)(namespace_collection, { _id });
1503
- delCache(cacheKey).then(() => {
1504
- import_node_server_utils7.logger.info(`Cache deleted for key: ${cacheKey}`);
1515
+ delNamespace().then(() => {
1516
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1517
+ }).catch((err) => {
1518
+ import_node_server_utils7.logger.error(
1519
+ `Failed to clear cache for namespace: ${namespace_collection}`,
1520
+ err
1521
+ );
1522
+ });
1523
+ _delDashboardNameSpace().then(() => {
1524
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: dashboard`);
1505
1525
  }).catch((err) => {
1506
- import_node_server_utils7.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
1526
+ import_node_server_utils7.logger.error(`Failed to clear cache for namespace: dashboard`, err);
1507
1527
  });
1508
1528
  return res.modifiedCount;
1509
1529
  } catch (error) {
@@ -1521,11 +1541,18 @@ function useWorkOrderRepo() {
1521
1541
  { $set: updateValue },
1522
1542
  session
1523
1543
  );
1524
- const cacheKey = (0, import_node_server_utils7.makeCacheKey)(namespace_collection, { createdBy: _id });
1525
- delCache(cacheKey).then(() => {
1526
- import_node_server_utils7.logger.info(`Cache deleted for key: ${cacheKey}`);
1544
+ delNamespace().then(() => {
1545
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1546
+ }).catch((err) => {
1547
+ import_node_server_utils7.logger.error(
1548
+ `Failed to clear cache for namespace: ${namespace_collection}`,
1549
+ err
1550
+ );
1551
+ });
1552
+ _delDashboardNameSpace().then(() => {
1553
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: dashboard`);
1527
1554
  }).catch((err) => {
1528
- import_node_server_utils7.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
1555
+ import_node_server_utils7.logger.error(`Failed to clear cache for namespace: dashboard`, err);
1529
1556
  });
1530
1557
  return res.modifiedCount;
1531
1558
  } catch (error) {
@@ -1555,11 +1582,18 @@ function useWorkOrderRepo() {
1555
1582
  "Unable to mark work order as completed."
1556
1583
  );
1557
1584
  }
1558
- const cacheKey = (0, import_node_server_utils7.makeCacheKey)(namespace_collection, { _id });
1559
- delCache(cacheKey).then(() => {
1560
- import_node_server_utils7.logger.info(`Cache deleted for key: ${cacheKey}`);
1585
+ delNamespace().then(() => {
1586
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1561
1587
  }).catch((err) => {
1562
- import_node_server_utils7.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
1588
+ import_node_server_utils7.logger.error(
1589
+ `Failed to clear cache for namespace: ${namespace_collection}`,
1590
+ err
1591
+ );
1592
+ });
1593
+ _delDashboardNameSpace().then(() => {
1594
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: dashboard`);
1595
+ }).catch((err) => {
1596
+ import_node_server_utils7.logger.error(`Failed to clear cache for namespace: dashboard`, err);
1563
1597
  });
1564
1598
  return res.modifiedCount;
1565
1599
  } catch (error) {
@@ -1586,11 +1620,18 @@ function useWorkOrderRepo() {
1586
1620
  if (res.modifiedCount === 0) {
1587
1621
  throw new import_node_server_utils7.InternalServerError("Unable to delete work order.");
1588
1622
  }
1589
- const cacheKey = (0, import_node_server_utils7.makeCacheKey)(namespace_collection, { _id });
1590
- delCache(cacheKey).then(() => {
1591
- import_node_server_utils7.logger.info(`Cache deleted for key: ${cacheKey}`);
1623
+ delNamespace().then(() => {
1624
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1625
+ }).catch((err) => {
1626
+ import_node_server_utils7.logger.error(
1627
+ `Failed to clear cache for namespace: ${namespace_collection}`,
1628
+ err
1629
+ );
1630
+ });
1631
+ _delDashboardNameSpace().then(() => {
1632
+ import_node_server_utils7.logger.info(`Cache cleared for namespace: dashboard`);
1592
1633
  }).catch((err) => {
1593
- import_node_server_utils7.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
1634
+ import_node_server_utils7.logger.error(`Failed to clear cache for namespace: dashboard`, err);
1594
1635
  });
1595
1636
  return res.modifiedCount;
1596
1637
  } catch (error) {
@@ -3115,6 +3156,14 @@ function useVerificationRepo() {
3115
3156
  throw new import_node_server_utils12.InternalServerError("Error updating verification status.");
3116
3157
  }
3117
3158
  }
3159
+ async function getByStatus(status) {
3160
+ try {
3161
+ const data = await collection.find({ status }).toArray();
3162
+ return data;
3163
+ } catch (error) {
3164
+ return Promise.reject(error);
3165
+ }
3166
+ }
3118
3167
  return {
3119
3168
  createIndex,
3120
3169
  createTextIndex,
@@ -3122,7 +3171,8 @@ function useVerificationRepo() {
3122
3171
  getById,
3123
3172
  getVerifications,
3124
3173
  getByIdByType,
3125
- updateStatusById
3174
+ updateStatusById,
3175
+ getByStatus
3126
3176
  };
3127
3177
  }
3128
3178
 
@@ -4347,7 +4397,8 @@ function useVerificationService() {
4347
4397
  const {
4348
4398
  add,
4349
4399
  getById: _getById,
4350
- updateStatusById: _updateStatusById
4400
+ updateStatusById: _updateStatusById,
4401
+ getByStatus: _getByStatus
4351
4402
  } = useVerificationRepo();
4352
4403
  const { getUserByEmail } = useUserRepo();
4353
4404
  const { getById: getOrgById, getByEmail: getOrgByEmail } = useOrgRepo();
@@ -4593,7 +4644,6 @@ function useVerificationService() {
4593
4644
  }
4594
4645
  async function cancelUserInvitation(id) {
4595
4646
  try {
4596
- await verify(id);
4597
4647
  await updateStatusById(id, "cancelled");
4598
4648
  } catch (error) {
4599
4649
  throw new import_node_server_utils19.InternalServerError(
@@ -4655,6 +4705,30 @@ function useVerificationService() {
4655
4705
  throw error;
4656
4706
  }
4657
4707
  }
4708
+ async function checkExpiredInvitation() {
4709
+ const session = import_node_server_utils19.useAtlas.getClient()?.startSession();
4710
+ session?.startTransaction();
4711
+ try {
4712
+ const verifications = await _getByStatus("pending");
4713
+ for (const verification of verifications) {
4714
+ const expiration = new Date(verification.expireAt).getTime();
4715
+ const now = (/* @__PURE__ */ new Date()).getTime();
4716
+ if (now > expiration) {
4717
+ await _updateStatusById(verification._id.toString(), "expired");
4718
+ }
4719
+ }
4720
+ return "Successfully checked for expired invitations.";
4721
+ } catch (error) {
4722
+ await session?.abortTransaction();
4723
+ import_node_server_utils19.logger.log({
4724
+ level: "info",
4725
+ message: `Error checking expired user invitation: ${error}`
4726
+ });
4727
+ throw error;
4728
+ } finally {
4729
+ session?.endSession();
4730
+ }
4731
+ }
4658
4732
  return {
4659
4733
  createUserInvite,
4660
4734
  createForgetPassword,
@@ -4663,7 +4737,8 @@ function useVerificationService() {
4663
4737
  verify,
4664
4738
  cancelUserInvitation,
4665
4739
  updateStatusById,
4666
- signUp
4740
+ signUp,
4741
+ checkExpiredInvitation
4667
4742
  };
4668
4743
  }
4669
4744
 
@@ -5523,6 +5598,7 @@ function useRoleRepo() {
5523
5598
  }
5524
5599
  }
5525
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");
5526
5602
  async function addRole(value, session) {
5527
5603
  value = new MRole(value);
5528
5604
  try {
@@ -5785,15 +5861,21 @@ function useRoleRepo() {
5785
5861
  { session }
5786
5862
  );
5787
5863
  if (res.modifiedCount === 0) {
5788
- 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.");
5789
5865
  }
5790
- const cacheKey = (0, import_node_server_utils23.makeCacheKey)(namespace_collection, { _id });
5791
- delCache(cacheKey).then(() => {
5792
- 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}`);
5793
5868
  }).catch((err) => {
5794
- 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);
5795
5878
  });
5796
- return "Successfully deleted role.";
5797
5879
  } catch (error) {
5798
5880
  throw new import_node_server_utils23.InternalServerError("Failed to delete role.");
5799
5881
  }
@@ -5838,6 +5920,16 @@ function useFileRepo() {
5838
5920
  const namespace_collection = "files";
5839
5921
  const collection = db.collection(namespace_collection);
5840
5922
  const { delNamespace, getCache, setCache } = (0, import_node_server_utils24.useCache)(namespace_collection);
5923
+ async function createIndex() {
5924
+ try {
5925
+ await collection.createIndexes([
5926
+ { key: { createdAt: 1 } },
5927
+ { key: { status: 1 } }
5928
+ ]);
5929
+ } catch (error) {
5930
+ throw new import_node_server_utils24.InternalServerError("Failed to create index on feedback.");
5931
+ }
5932
+ }
5841
5933
  async function createFile(value, session) {
5842
5934
  try {
5843
5935
  value = new MFile(value);
@@ -5966,7 +6058,8 @@ function useFileRepo() {
5966
6058
  deleteFileById,
5967
6059
  getAllDraftedFiles,
5968
6060
  updateStatusById,
5969
- getFileById
6061
+ getFileById,
6062
+ createIndex
5970
6063
  };
5971
6064
  }
5972
6065
 
@@ -6871,7 +6964,7 @@ function useRoleController() {
6871
6964
  }
6872
6965
  async function deleteRole(req, res, next) {
6873
6966
  const validation = import_joi15.default.string().hex().required();
6874
- const _id = req.params.id;
6967
+ const _id = req.query.id;
6875
6968
  const { error } = validation.validate(_id);
6876
6969
  if (error) {
6877
6970
  import_node_server_utils29.logger.log({ level: "error", message: error.message });
@@ -7522,7 +7615,7 @@ function useFileController() {
7522
7615
  }
7523
7616
  async function deleteFile(req, res, next) {
7524
7617
  const validation = import_joi18.default.string().hex().required();
7525
- const _id = req.params.id;
7618
+ const _id = req.query.id;
7526
7619
  const { error } = validation.validate(_id);
7527
7620
  if (error) {
7528
7621
  import_node_server_utils34.logger.log({ level: "error", message: error.message });
@@ -10936,7 +11029,6 @@ function useFeedbackController() {
10936
11029
  async function deleteFeedback(req, res, next) {
10937
11030
  const validation = import_joi28.default.string().hex().required();
10938
11031
  const _id = req.query.id;
10939
- console.log(_id);
10940
11032
  const { error } = validation.validate(_id);
10941
11033
  if (error) {
10942
11034
  import_node_server_utils55.logger.log({ level: "error", message: error.message });
@@ -20716,13 +20808,38 @@ function usePatrolRouteRepo() {
20716
20808
  throw error;
20717
20809
  }
20718
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
+ }
20719
20835
  return {
20720
20836
  createTextIndex,
20721
20837
  add,
20722
20838
  getAll,
20723
20839
  updateById,
20724
20840
  deleteById,
20725
- getScheduledRoute
20841
+ getScheduledRoute,
20842
+ getById
20726
20843
  };
20727
20844
  }
20728
20845
 
@@ -20735,7 +20852,8 @@ function usePatrolRouteController() {
20735
20852
  getAll: _getAll,
20736
20853
  updateById: _updateById,
20737
20854
  deleteById: _deleteById,
20738
- getScheduledRoute: _getScheduledRoute
20855
+ getScheduledRoute: _getScheduledRoute,
20856
+ getById: _getById
20739
20857
  } = usePatrolRouteRepo();
20740
20858
  async function add(req, res, next) {
20741
20859
  const data = { ...req.body };
@@ -20903,12 +21021,34 @@ function usePatrolRouteController() {
20903
21021
  return;
20904
21022
  }
20905
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
+ }
20906
21045
  return {
20907
21046
  add,
20908
21047
  getAll,
20909
21048
  updateById,
20910
21049
  deleteById,
20911
- getScheduledRoute
21050
+ getScheduledRoute,
21051
+ getById
20912
21052
  };
20913
21053
  }
20914
21054
 
@@ -21158,6 +21298,30 @@ function usePatrolLogRepo() {
21158
21298
  throw error;
21159
21299
  }
21160
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
+ }
21161
21325
  function delCachedData() {
21162
21326
  delNamespace().then(() => {
21163
21327
  import_node_server_utils116.logger.log({
@@ -21177,7 +21341,8 @@ function usePatrolLogRepo() {
21177
21341
  add,
21178
21342
  getAll,
21179
21343
  updateById,
21180
- deleteById
21344
+ deleteById,
21345
+ getById
21181
21346
  };
21182
21347
  }
21183
21348
 
@@ -21249,7 +21414,8 @@ function usePatrolLogController() {
21249
21414
  const {
21250
21415
  getAll: _getAll,
21251
21416
  updateById: _updateById,
21252
- deleteById: _deleteById
21417
+ deleteById: _deleteById,
21418
+ getById: _getById
21253
21419
  } = usePatrolLogRepo();
21254
21420
  const { add: _add } = usePatrolLogService();
21255
21421
  async function add(req, res, next) {
@@ -21361,7 +21527,28 @@ function usePatrolLogController() {
21361
21527
  return;
21362
21528
  }
21363
21529
  }
21364
- 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 };
21365
21552
  }
21366
21553
 
21367
21554
  // src/models/site-facility.model.ts
@@ -23854,7 +24041,7 @@ function useDocumentManagementController() {
23854
24041
  }
23855
24042
  async function deleteDocumentById(req, res, next) {
23856
24043
  const validation = import_joi74.default.string().hex().required();
23857
- const _id = req.params.id;
24044
+ const _id = req.query.id;
23858
24045
  const { error } = validation.validate(_id);
23859
24046
  if (error) {
23860
24047
  import_node_server_utils130.logger.log({ level: "error", message: error.message });
@@ -27492,22 +27679,31 @@ function UseAccessManagementRepo() {
27492
27679
  throw new Error(error.message);
27493
27680
  }
27494
27681
  }
27682
+ function getAfterSecondSlash(term) {
27683
+ const first = term.indexOf("/");
27684
+ if (first === -1)
27685
+ return "";
27686
+ const second = term.indexOf("/", first + 1);
27687
+ if (second === -1)
27688
+ return "";
27689
+ return term.substring(second + 1).toLowerCase();
27690
+ }
27495
27691
  function buildSearchQuery(search) {
27496
27692
  if (!search) {
27497
27693
  return {};
27498
27694
  }
27499
27695
  const terms = search.split("/").map((s) => s.trim()).filter(Boolean);
27500
- if (search.includes("/") && terms.length <= 3) {
27501
- switch (terms.length) {
27502
- case 3:
27696
+ if (search.includes("/")) {
27697
+ switch (true) {
27698
+ case terms.length >= 3:
27503
27699
  return {
27504
27700
  $and: [
27505
27701
  { $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
27506
27702
  { $expr: { $eq: [{ $toLower: "$level.level" }, terms[1].toLowerCase()] } },
27507
- { $expr: { $eq: [{ $toLower: "$level.units.name" }, terms[2].toLowerCase()] } }
27703
+ { $expr: { $eq: [{ $toLower: "$level.units.name" }, getAfterSecondSlash(search)] } }
27508
27704
  ]
27509
27705
  };
27510
- case 2:
27706
+ case terms.length === 2:
27511
27707
  return {
27512
27708
  $and: [
27513
27709
  { $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
@@ -27738,6 +27934,207 @@ function UseAccessManagementRepo() {
27738
27934
  throw new Error(error.message);
27739
27935
  }
27740
27936
  }
27937
+ async function assignedAccessCardsRepo(params) {
27938
+ try {
27939
+ const site = new import_mongodb83.ObjectId(params.site);
27940
+ const userType = params.userType;
27941
+ const type = params.type;
27942
+ const search = params.search;
27943
+ const query = {
27944
+ site: { $in: [site] }
27945
+ };
27946
+ const searchQuery = buildSearchQuery(search);
27947
+ const result = await collectionName("buildings").aggregate([
27948
+ // ✅ Match early with index-friendly query
27949
+ {
27950
+ $match: {
27951
+ ...query,
27952
+ status: { $ne: "deleted" }
27953
+ }
27954
+ },
27955
+ // ✅ Only project needed fields before heavy lookups
27956
+ {
27957
+ $project: {
27958
+ _id: 1,
27959
+ name: 1,
27960
+ site: 1
27961
+ }
27962
+ },
27963
+ // ✅ Use localField/foreignField for better index usage
27964
+ {
27965
+ $lookup: {
27966
+ from: "building-levels",
27967
+ localField: "_id",
27968
+ foreignField: "block",
27969
+ pipeline: [
27970
+ { $match: { status: { $ne: "deleted" } } },
27971
+ {
27972
+ $lookup: {
27973
+ from: "building-units",
27974
+ localField: "_id",
27975
+ foreignField: "level",
27976
+ pipeline: [
27977
+ { $match: { status: { $ne: "deleted" } } },
27978
+ { $project: { _id: 1, name: 1 } },
27979
+ {
27980
+ $lookup: {
27981
+ from: "access-cards",
27982
+ localField: "_id",
27983
+ foreignField: "assignedUnit",
27984
+ pipeline: [
27985
+ {
27986
+ $match: {
27987
+ isActivated: true,
27988
+ userType,
27989
+ type
27990
+ }
27991
+ },
27992
+ {
27993
+ $group: {
27994
+ _id: null,
27995
+ accessLevels: { $addToSet: "$accessLevel" },
27996
+ liftAccessLevels: { $addToSet: "$liftAccessLevel" },
27997
+ doorNames: { $addToSet: "$doorName" },
27998
+ liftNames: { $addToSet: "$liftName" },
27999
+ cards: {
28000
+ $push: {
28001
+ _id: "$_id",
28002
+ cardNo: "$cardNo",
28003
+ accessLevel: "$accessLevel",
28004
+ liftAccessLevel: "$liftAccessLevel",
28005
+ doorName: "$doorName",
28006
+ liftName: "$liftName"
28007
+ }
28008
+ }
28009
+ }
28010
+ },
28011
+ {
28012
+ $project: {
28013
+ _id: 0,
28014
+ accessCardCount: {
28015
+ $size: "$cards"
28016
+ },
28017
+ accessLevels: 1,
28018
+ liftAccessLevels: 1,
28019
+ doorNames: 1,
28020
+ liftNames: 1
28021
+ }
28022
+ }
28023
+ ],
28024
+ as: "fAccessCards"
28025
+ }
28026
+ },
28027
+ {
28028
+ $match: {
28029
+ "fAccessCards.0": { $exists: true }
28030
+ }
28031
+ }
28032
+ ],
28033
+ as: "units"
28034
+ }
28035
+ },
28036
+ {
28037
+ $match: { "units.0": { $exists: true } }
28038
+ },
28039
+ {
28040
+ $project: {
28041
+ _id: 1,
28042
+ level: 1,
28043
+ units: 1
28044
+ }
28045
+ }
28046
+ ],
28047
+ as: "level"
28048
+ }
28049
+ },
28050
+ // ✅ Filter out buildings with no levels early
28051
+ {
28052
+ $match: { "level.0": { $exists: true } }
28053
+ },
28054
+ // ✅ Unwind to flatten the hierarchy
28055
+ {
28056
+ $unwind: {
28057
+ path: "$level",
28058
+ preserveNullAndEmptyArrays: false
28059
+ }
28060
+ },
28061
+ {
28062
+ $unwind: {
28063
+ path: "$level.units",
28064
+ preserveNullAndEmptyArrays: false
28065
+ }
28066
+ },
28067
+ {
28068
+ $unwind: {
28069
+ path: "$level.units.fAccessCards",
28070
+ preserveNullAndEmptyArrays: false
28071
+ }
28072
+ },
28073
+ // // Groups by unit _id and keeps only the first occurrence
28074
+ {
28075
+ $group: {
28076
+ _id: "$level.units._id",
28077
+ doc: { $first: "$$ROOT" }
28078
+ }
28079
+ },
28080
+ {
28081
+ $replaceRoot: { newRoot: "$doc" }
28082
+ },
28083
+ // ✅ Apply search filter
28084
+ {
28085
+ $match: {
28086
+ ...searchQuery
28087
+ }
28088
+ },
28089
+ {
28090
+ $project: {
28091
+ name: 1,
28092
+ "level.level": 1,
28093
+ "level.units.name": 1,
28094
+ "level.units.fAccessCards": 1
28095
+ }
28096
+ }
28097
+ ], { allowDiskUse: true }).toArray();
28098
+ return result;
28099
+ } catch (error) {
28100
+ throw new Error(error.message);
28101
+ }
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
+ }
27741
28138
  return {
27742
28139
  createIndexes,
27743
28140
  createIndexForEntrypass,
@@ -27746,7 +28143,9 @@ function UseAccessManagementRepo() {
27746
28143
  accessManagementSettingsRepo,
27747
28144
  allAccessCardsCountsRepo,
27748
28145
  availableAccessCardsRepo,
27749
- userTypeAccessCardsRepo
28146
+ userTypeAccessCardsRepo,
28147
+ assignedAccessCardsRepo,
28148
+ acknowlegdeCardRepo
27750
28149
  };
27751
28150
  }
27752
28151
 
@@ -27851,6 +28250,8 @@ var formatAccessGroup = (data, search) => {
27851
28250
 
27852
28251
  // src/services/access-management.service.ts
27853
28252
  var import_xml2js = require("xml2js");
28253
+ var import_node_server_utils150 = require("@7365admin1/node-server-utils");
28254
+ var namespace = "cache:acm";
27854
28255
  function useAccessManagementSvc() {
27855
28256
  const {
27856
28257
  addPhysicalCardRepo,
@@ -27858,7 +28259,9 @@ function useAccessManagementSvc() {
27858
28259
  accessManagementSettingsRepo,
27859
28260
  allAccessCardsCountsRepo,
27860
28261
  availableAccessCardsRepo,
27861
- userTypeAccessCardsRepo
28262
+ userTypeAccessCardsRepo,
28263
+ assignedAccessCardsRepo,
28264
+ acknowlegdeCardRepo
27862
28265
  } = UseAccessManagementRepo();
27863
28266
  const addPhysicalCardSvc = async (payload) => {
27864
28267
  try {
@@ -27876,12 +28279,34 @@ function useAccessManagementSvc() {
27876
28279
  throw new Error(err.message);
27877
28280
  }
27878
28281
  };
28282
+ const setCache = async (params) => {
28283
+ const { key, data, ttlSeconds = 60, redis } = params;
28284
+ const jsonData = JSON.stringify(data);
28285
+ await redis.set(key, jsonData, "EX", ttlSeconds);
28286
+ };
28287
+ const getCache = async (params) => {
28288
+ const { key, redis } = params;
28289
+ const result = await redis.get(key);
28290
+ return result ? JSON.parse(result) : null;
28291
+ };
27879
28292
  const doorAccessLevelsSvc = async (params) => {
27880
28293
  try {
28294
+ const key = `${namespace}:${params.user}:door-levels`;
28295
+ const listKey = `${namespace}:${params.user}:list`;
28296
+ const { redis } = (0, import_node_server_utils150.useCache)(key);
28297
+ const cachedData = await getCache({ key, redis });
28298
+ if (cachedData) {
28299
+ console.log("\u26A1 Cache hit:", key);
28300
+ redis.expire(key, 60).catch(console.error);
28301
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
28302
+ return cachedData;
28303
+ }
27881
28304
  const command = readTemplate("door-levels");
27882
28305
  const response = await sendCommand(command, params.acm_url);
27883
28306
  const res = await (0, import_xml2js.parseStringPromise)(response, { explicitArray: false });
27884
28307
  const format = await formatDoorAccessLevels(res);
28308
+ await setCache({ key, data: format, ttlSeconds: 60, redis });
28309
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
27885
28310
  return format;
27886
28311
  } catch (err) {
27887
28312
  throw new Error(err.message);
@@ -27889,10 +28314,22 @@ function useAccessManagementSvc() {
27889
28314
  };
27890
28315
  const liftAccessLevelsSvc = async (params) => {
27891
28316
  try {
28317
+ const key = `${namespace}:${params.user}:lift-levels`;
28318
+ const listKey = `${namespace}:${params.user}:list`;
28319
+ const { redis } = (0, import_node_server_utils150.useCache)(key);
28320
+ const cachedData = await getCache({ key, redis });
28321
+ if (cachedData) {
28322
+ console.log("\u26A1 Cache hit:", key);
28323
+ redis.expire(key, 60).catch(console.error);
28324
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
28325
+ return cachedData;
28326
+ }
27892
28327
  const command = readTemplate("lift-levels");
27893
28328
  const response = await sendCommand(command, params.acm_url);
27894
28329
  const res = await (0, import_xml2js.parseStringPromise)(response, { explicitArray: false });
27895
28330
  const format = await formatLiftAccessLevels(res);
28331
+ await setCache({ key, data: format, ttlSeconds: 60, redis });
28332
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
27896
28333
  return format;
27897
28334
  } catch (error) {
27898
28335
  throw new Error(error.message);
@@ -27900,10 +28337,22 @@ function useAccessManagementSvc() {
27900
28337
  };
27901
28338
  const accessGroupsSvc = async (params) => {
27902
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
+ }
27903
28350
  const command = readTemplate("access-group");
27904
28351
  const response = await sendCommand(command, params.acm_url);
27905
28352
  const res = await (0, import_xml2js.parseStringPromise)(response, { explicitArray: false });
27906
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);
27907
28356
  return format;
27908
28357
  } catch (err) {
27909
28358
  throw new Error(err.message);
@@ -27941,6 +28390,22 @@ function useAccessManagementSvc() {
27941
28390
  throw new Error(err.message);
27942
28391
  }
27943
28392
  };
28393
+ const assignedAccessCardsSvc = async (params) => {
28394
+ try {
28395
+ const response = await assignedAccessCardsRepo({ ...params });
28396
+ return response;
28397
+ } catch (err) {
28398
+ throw new Error(err.message);
28399
+ }
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
+ };
27944
28409
  return {
27945
28410
  addPhysicalCardSvc,
27946
28411
  addNonPhysicalCardSvc,
@@ -27950,7 +28415,9 @@ function useAccessManagementSvc() {
27950
28415
  accessManagementSettingsSvc,
27951
28416
  allAccessCardsCountsSvc,
27952
28417
  availableAccessCardsSvc,
27953
- userTypeAccessCardsSvc
28418
+ userTypeAccessCardsSvc,
28419
+ assignedAccessCardsSvc,
28420
+ acknowlegdeCardSvc
27954
28421
  };
27955
28422
  }
27956
28423
 
@@ -27965,7 +28432,9 @@ function useAccessManagementController() {
27965
28432
  accessManagementSettingsSvc,
27966
28433
  allAccessCardsCountsSvc,
27967
28434
  availableAccessCardsSvc,
27968
- userTypeAccessCardsSvc
28435
+ userTypeAccessCardsSvc,
28436
+ assignedAccessCardsSvc,
28437
+ acknowlegdeCardSvc
27969
28438
  } = useAccessManagementSvc();
27970
28439
  const addPhysicalCard = async (req, res) => {
27971
28440
  try {
@@ -28096,10 +28565,11 @@ function useAccessManagementController() {
28096
28565
  const doorAccessLevels = async (req, res) => {
28097
28566
  try {
28098
28567
  const { acm_url } = req.query;
28568
+ const user = req.cookies?.sid;
28099
28569
  if (!acm_url || typeof acm_url !== "string") {
28100
28570
  throw new Error("Access Control URL is required");
28101
28571
  }
28102
- const result = await doorAccessLevelsSvc({ acm_url });
28572
+ const result = await doorAccessLevelsSvc({ acm_url, user });
28103
28573
  return res.status(200).json({ message: "Success", data: result });
28104
28574
  } catch (error) {
28105
28575
  return res.status(400).json({
@@ -28111,10 +28581,11 @@ function useAccessManagementController() {
28111
28581
  const liftAccessLevels = async (req, res) => {
28112
28582
  try {
28113
28583
  const { acm_url } = req.query;
28584
+ const user = req.cookies?.sid;
28114
28585
  if (!acm_url || typeof acm_url !== "string") {
28115
28586
  throw new Error("Access Control URL is required");
28116
28587
  }
28117
- const result = await liftAccessLevelsSvc({ acm_url });
28588
+ const result = await liftAccessLevelsSvc({ acm_url, user });
28118
28589
  return res.status(200).json({ message: "Success", data: result });
28119
28590
  } catch (error) {
28120
28591
  return res.status(400).json({
@@ -28126,10 +28597,11 @@ function useAccessManagementController() {
28126
28597
  const accessGroups = async (req, res) => {
28127
28598
  try {
28128
28599
  const { acm_url } = req.query;
28600
+ const user = req.cookies?.sid;
28129
28601
  if (!acm_url || typeof acm_url !== "string") {
28130
28602
  throw new Error("Access Control URL is required");
28131
28603
  }
28132
- const result = await accessGroupsSvc({ acm_url });
28604
+ const result = await accessGroupsSvc({ acm_url, user });
28133
28605
  return res.status(200).json({ message: "Success", data: result });
28134
28606
  } catch (error) {
28135
28607
  return res.status(400).json({
@@ -28222,6 +28694,49 @@ function useAccessManagementController() {
28222
28694
  });
28223
28695
  }
28224
28696
  };
28697
+ const assignedAccessCards = async (req, res) => {
28698
+ try {
28699
+ const { site, userType, type, search = "" } = req.query;
28700
+ const schema2 = import_joi85.default.object({
28701
+ site: import_joi85.default.string().hex().required(),
28702
+ userType: import_joi85.default.string().required(),
28703
+ type: import_joi85.default.string().required(),
28704
+ search: import_joi85.default.string().optional().allow("", null)
28705
+ });
28706
+ const { error } = schema2.validate({ site, userType, type, search });
28707
+ if (error) {
28708
+ return res.status(400).json({ message: error.message });
28709
+ }
28710
+ const result = await assignedAccessCardsSvc({ site, userType, type, search });
28711
+ return res.status(200).json({ message: "Success", data: result });
28712
+ } catch (error) {
28713
+ return res.status(500).json({
28714
+ data: null,
28715
+ message: error.message
28716
+ });
28717
+ }
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
+ };
28225
28740
  return {
28226
28741
  addPhysicalCard,
28227
28742
  addNonPhysicalCard,
@@ -28231,14 +28746,16 @@ function useAccessManagementController() {
28231
28746
  accessManagementSettings,
28232
28747
  allAccessCardsCounts,
28233
28748
  availableAccessCards,
28234
- userTypeAccessCards
28749
+ userTypeAccessCards,
28750
+ assignedAccessCards,
28751
+ acknowlegdeCard
28235
28752
  };
28236
28753
  }
28237
28754
 
28238
28755
  // src/models/nfc-patrol-tag.model.ts
28239
28756
  var import_mongodb84 = require("mongodb");
28240
28757
  var import_joi86 = __toESM(require("joi"));
28241
- var import_node_server_utils150 = require("@7365admin1/node-server-utils");
28758
+ var import_node_server_utils151 = require("@7365admin1/node-server-utils");
28242
28759
  var DEVICE_STATUS = {
28243
28760
  CONFIGURED: "Configured",
28244
28761
  NOT_CONFIGURED: "Not Configured"
@@ -28265,21 +28782,21 @@ function MNfcPatrolTag(value) {
28265
28782
  try {
28266
28783
  value._id = new import_mongodb84.ObjectId(value._id);
28267
28784
  } catch {
28268
- throw new import_node_server_utils150.BadRequestError("Invalid ID.");
28785
+ throw new import_node_server_utils151.BadRequestError("Invalid ID.");
28269
28786
  }
28270
28787
  }
28271
28788
  if (value.site && typeof value.site === "string") {
28272
28789
  try {
28273
28790
  value.site = new import_mongodb84.ObjectId(value.site);
28274
28791
  } catch {
28275
- throw new import_node_server_utils150.BadRequestError("Invalid site ID.");
28792
+ throw new import_node_server_utils151.BadRequestError("Invalid site ID.");
28276
28793
  }
28277
28794
  }
28278
28795
  if (value.createdBy && typeof value.createdBy === "string") {
28279
28796
  try {
28280
28797
  value.createdBy = new import_mongodb84.ObjectId(value.createdBy);
28281
28798
  } catch {
28282
- throw new import_node_server_utils150.BadRequestError("Invalid Created By ID.");
28799
+ throw new import_node_server_utils151.BadRequestError("Invalid Created By ID.");
28283
28800
  }
28284
28801
  }
28285
28802
  return {
@@ -28294,18 +28811,18 @@ function MNfcPatrolTag(value) {
28294
28811
  }
28295
28812
 
28296
28813
  // src/repositories/nfc-patrol-tag.repository.ts
28297
- var import_node_server_utils151 = require("@7365admin1/node-server-utils");
28814
+ var import_node_server_utils152 = require("@7365admin1/node-server-utils");
28298
28815
  var import_mongodb85 = require("mongodb");
28299
28816
  function useNfcPatrolTagRepo() {
28300
- const db = import_node_server_utils151.useAtlas.getDb();
28817
+ const db = import_node_server_utils152.useAtlas.getDb();
28301
28818
  if (!db) {
28302
- throw new import_node_server_utils151.InternalServerError("Unable to connect to server.");
28819
+ throw new import_node_server_utils152.InternalServerError("Unable to connect to server.");
28303
28820
  }
28304
28821
  const namespace_collection = "nfc-patrol-tags";
28305
28822
  const namespace_collection_nfc_patrol_routes = "nfc-patrol-routes";
28306
28823
  const collection = db.collection(namespace_collection);
28307
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils151.useCache)(namespace_collection);
28308
- const { delNamespace: delNamespaceNfcPatrolRoutes } = (0, import_node_server_utils151.useCache)(
28824
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils152.useCache)(namespace_collection);
28825
+ const { delNamespace: delNamespaceNfcPatrolRoutes } = (0, import_node_server_utils152.useCache)(
28309
28826
  namespace_collection_nfc_patrol_routes
28310
28827
  );
28311
28828
  async function createIndexes() {
@@ -28321,7 +28838,7 @@ function useNfcPatrolTagRepo() {
28321
28838
  { key: { site: 1 } }
28322
28839
  ]);
28323
28840
  } catch (error) {
28324
- throw new import_node_server_utils151.InternalServerError(
28841
+ throw new import_node_server_utils152.InternalServerError(
28325
28842
  "Failed to create index on nfc patrol tags."
28326
28843
  );
28327
28844
  }
@@ -28335,7 +28852,7 @@ function useNfcPatrolTagRepo() {
28335
28852
  } catch (error) {
28336
28853
  const isDuplicated = error.message.includes("duplicate");
28337
28854
  if (isDuplicated) {
28338
- throw new import_node_server_utils151.BadRequestError(
28855
+ throw new import_node_server_utils152.BadRequestError(
28339
28856
  "NFC Patrol Tag ID and or Name already exists."
28340
28857
  );
28341
28858
  }
@@ -28351,7 +28868,7 @@ function useNfcPatrolTagRepo() {
28351
28868
  try {
28352
28869
  site = new import_mongodb85.ObjectId(site);
28353
28870
  } catch (error) {
28354
- throw new import_node_server_utils151.BadRequestError("Invalid site ID format.");
28871
+ throw new import_node_server_utils152.BadRequestError("Invalid site ID format.");
28355
28872
  }
28356
28873
  const query = {
28357
28874
  site
@@ -28361,10 +28878,10 @@ function useNfcPatrolTagRepo() {
28361
28878
  page,
28362
28879
  limit
28363
28880
  };
28364
- const cacheKey = (0, import_node_server_utils151.makeCacheKey)(namespace_collection, cacheOptions);
28881
+ const cacheKey = (0, import_node_server_utils152.makeCacheKey)(namespace_collection, cacheOptions);
28365
28882
  const cachedData = await getCache(cacheKey);
28366
28883
  if (cachedData) {
28367
- import_node_server_utils151.logger.info(`Cache hit for key: ${cacheKey}`);
28884
+ import_node_server_utils152.logger.info(`Cache hit for key: ${cacheKey}`);
28368
28885
  return cachedData;
28369
28886
  }
28370
28887
  try {
@@ -28378,11 +28895,11 @@ function useNfcPatrolTagRepo() {
28378
28895
  { session }
28379
28896
  ).toArray();
28380
28897
  const length = await collection.countDocuments(query, { session });
28381
- const data = (0, import_node_server_utils151.paginate)(items, page, limit, length);
28898
+ const data = (0, import_node_server_utils152.paginate)(items, page, limit, length);
28382
28899
  setCache(cacheKey, data, 15 * 60).then(() => {
28383
- import_node_server_utils151.logger.info(`Cache set for key: ${cacheKey}`);
28900
+ import_node_server_utils152.logger.info(`Cache set for key: ${cacheKey}`);
28384
28901
  }).catch((err) => {
28385
- import_node_server_utils151.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
28902
+ import_node_server_utils152.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
28386
28903
  });
28387
28904
  return data;
28388
28905
  } catch (error) {
@@ -28395,19 +28912,19 @@ function useNfcPatrolTagRepo() {
28395
28912
  try {
28396
28913
  findObject.site = new import_mongodb85.ObjectId(findObject.site);
28397
28914
  } catch {
28398
- throw new import_node_server_utils151.BadRequestError("Invalid site ID.");
28915
+ throw new import_node_server_utils152.BadRequestError("Invalid site ID.");
28399
28916
  }
28400
28917
  }
28401
28918
  if (updateType == "Edit" && findObject?._id && typeof findObject._id === "string") {
28402
28919
  try {
28403
28920
  findObject._id = new import_mongodb85.ObjectId(findObject._id);
28404
28921
  } catch {
28405
- throw new import_node_server_utils151.BadRequestError("Invalid nfc patrol tag document ID.");
28922
+ throw new import_node_server_utils152.BadRequestError("Invalid nfc patrol tag document ID.");
28406
28923
  }
28407
28924
  try {
28408
28925
  setData.updatedBy = new import_mongodb85.ObjectId(setData.updatedBy);
28409
28926
  } catch {
28410
- throw new import_node_server_utils151.BadRequestError("Invalid updatedBy ID.");
28927
+ throw new import_node_server_utils152.BadRequestError("Invalid updatedBy ID.");
28411
28928
  }
28412
28929
  }
28413
28930
  const historyEntry = {
@@ -28433,7 +28950,7 @@ function useNfcPatrolTagRepo() {
28433
28950
  session
28434
28951
  });
28435
28952
  if (res.modifiedCount === 0) {
28436
- throw new import_node_server_utils151.InternalServerError(
28953
+ throw new import_node_server_utils152.InternalServerError(
28437
28954
  `Unable to ${updateType} NFC Patrol Tag.`
28438
28955
  );
28439
28956
  }
@@ -28448,12 +28965,12 @@ function useNfcPatrolTagRepo() {
28448
28965
  tagUID: setData?.tagUID
28449
28966
  });
28450
28967
  if (existingDoc) {
28451
- throw new import_node_server_utils151.BadRequestError(
28968
+ throw new import_node_server_utils152.BadRequestError(
28452
28969
  `NFC Patrol Tag is already assigned to ID: ${existingDoc.tagID}. Reset it before reassigning.`
28453
28970
  );
28454
28971
  }
28455
28972
  } else {
28456
- throw new import_node_server_utils151.BadRequestError(
28973
+ throw new import_node_server_utils152.BadRequestError(
28457
28974
  "NFC Patrol Tag ID and or Name already exists."
28458
28975
  );
28459
28976
  }
@@ -28463,23 +28980,23 @@ function useNfcPatrolTagRepo() {
28463
28980
  }
28464
28981
  function delCachedData() {
28465
28982
  delNamespace().then(() => {
28466
- import_node_server_utils151.logger.log({
28983
+ import_node_server_utils152.logger.log({
28467
28984
  level: "info",
28468
28985
  message: `Cache namespace cleared for ${namespace_collection}`
28469
28986
  });
28470
28987
  }).catch((err) => {
28471
- import_node_server_utils151.logger.log({
28988
+ import_node_server_utils152.logger.log({
28472
28989
  level: "error",
28473
28990
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
28474
28991
  });
28475
28992
  });
28476
28993
  delNamespaceNfcPatrolRoutes().then(() => {
28477
- import_node_server_utils151.logger.log({
28994
+ import_node_server_utils152.logger.log({
28478
28995
  level: "info",
28479
28996
  message: `Cache namespace cleared for ${namespace_collection}`
28480
28997
  });
28481
28998
  }).catch((err) => {
28482
- import_node_server_utils151.logger.log({
28999
+ import_node_server_utils152.logger.log({
28483
29000
  level: "error",
28484
29001
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
28485
29002
  });
@@ -28494,11 +29011,11 @@ function useNfcPatrolTagRepo() {
28494
29011
  }
28495
29012
 
28496
29013
  // src/services/nfc-patrol-tag.service.ts
28497
- var import_node_server_utils152 = require("@7365admin1/node-server-utils");
29014
+ var import_node_server_utils153 = require("@7365admin1/node-server-utils");
28498
29015
  function useNfcPatrolTagService() {
28499
29016
  const { add: _add, updateNfcPatrolTagBySite: _updateNfcPatrolTagBySite } = useNfcPatrolTagRepo();
28500
29017
  async function add(value) {
28501
- const session = import_node_server_utils152.useAtlas.getClient()?.startSession();
29018
+ const session = import_node_server_utils153.useAtlas.getClient()?.startSession();
28502
29019
  session?.startTransaction();
28503
29020
  try {
28504
29021
  await _add(value, session);
@@ -28512,7 +29029,7 @@ function useNfcPatrolTagService() {
28512
29029
  }
28513
29030
  }
28514
29031
  async function updateNfcPatrolTagBySite(updateType, data) {
28515
- const session = import_node_server_utils152.useAtlas.getClient()?.startSession();
29032
+ const session = import_node_server_utils153.useAtlas.getClient()?.startSession();
28516
29033
  session?.startTransaction();
28517
29034
  try {
28518
29035
  let successMessage = "Successfully Updated the NFC Patrol Tag.";
@@ -28520,11 +29037,11 @@ function useNfcPatrolTagService() {
28520
29037
  case "Configure": {
28521
29038
  const { site, tagID, tagUID } = data;
28522
29039
  if (!tagID)
28523
- throw new import_node_server_utils152.BadRequestError("tagID is required for Configure");
29040
+ throw new import_node_server_utils153.BadRequestError("tagID is required for Configure");
28524
29041
  if (!tagUID)
28525
- throw new import_node_server_utils152.BadRequestError("tagUID is required for Configure");
29042
+ throw new import_node_server_utils153.BadRequestError("tagUID is required for Configure");
28526
29043
  if (!site)
28527
- throw new import_node_server_utils152.BadRequestError("site is required for Configure");
29044
+ throw new import_node_server_utils153.BadRequestError("site is required for Configure");
28528
29045
  const findObject = { site, tagID };
28529
29046
  const setData = { tagUID, status: DEVICE_STATUS.CONFIGURED };
28530
29047
  await _updateNfcPatrolTagBySite(
@@ -28539,9 +29056,9 @@ function useNfcPatrolTagService() {
28539
29056
  case "Reset": {
28540
29057
  const { site, tagID } = data;
28541
29058
  if (!tagID)
28542
- throw new import_node_server_utils152.BadRequestError("tagID is required for Reset");
29059
+ throw new import_node_server_utils153.BadRequestError("tagID is required for Reset");
28543
29060
  if (!site)
28544
- throw new import_node_server_utils152.BadRequestError("site is required for Reset");
29061
+ throw new import_node_server_utils153.BadRequestError("site is required for Reset");
28545
29062
  const findObject = { site, tagID };
28546
29063
  const setData = { status: DEVICE_STATUS.NOT_CONFIGURED };
28547
29064
  await _updateNfcPatrolTagBySite(
@@ -28556,15 +29073,15 @@ function useNfcPatrolTagService() {
28556
29073
  case "Edit": {
28557
29074
  const { tagID, name, _id, site, updatedBy } = data;
28558
29075
  if (!_id)
28559
- throw new import_node_server_utils152.BadRequestError("_id is required for Edit");
29076
+ throw new import_node_server_utils153.BadRequestError("_id is required for Edit");
28560
29077
  if (!site)
28561
- throw new import_node_server_utils152.BadRequestError("site is required for Edit");
29078
+ throw new import_node_server_utils153.BadRequestError("site is required for Edit");
28562
29079
  if (!tagID)
28563
- throw new import_node_server_utils152.BadRequestError("tagID is required for Edit");
29080
+ throw new import_node_server_utils153.BadRequestError("tagID is required for Edit");
28564
29081
  if (!name)
28565
- throw new import_node_server_utils152.BadRequestError("name is required for Edit");
29082
+ throw new import_node_server_utils153.BadRequestError("name is required for Edit");
28566
29083
  if (!updatedBy)
28567
- throw new import_node_server_utils152.BadRequestError("updatedBy is required for Edit");
29084
+ throw new import_node_server_utils153.BadRequestError("updatedBy is required for Edit");
28568
29085
  const findObject = { _id, site };
28569
29086
  const setData = { name, tagID, updatedBy };
28570
29087
  await _updateNfcPatrolTagBySite(
@@ -28576,7 +29093,7 @@ function useNfcPatrolTagService() {
28576
29093
  break;
28577
29094
  }
28578
29095
  default:
28579
- throw new import_node_server_utils152.BadRequestError(`Invalid updateType: ${updateType}`);
29096
+ throw new import_node_server_utils153.BadRequestError(`Invalid updateType: ${updateType}`);
28580
29097
  }
28581
29098
  await session?.commitTransaction();
28582
29099
  return successMessage;
@@ -28594,7 +29111,7 @@ function useNfcPatrolTagService() {
28594
29111
  }
28595
29112
 
28596
29113
  // src/controllers/nfc-patrol-tag.controller.ts
28597
- var import_node_server_utils153 = require("@7365admin1/node-server-utils");
29114
+ var import_node_server_utils154 = require("@7365admin1/node-server-utils");
28598
29115
  var import_joi87 = __toESM(require("joi"));
28599
29116
  function useNfcPatrolTagController() {
28600
29117
  const { add: _add, updateNfcPatrolTagBySite: _updateNfcPatrolTagBySite } = useNfcPatrolTagService();
@@ -28611,8 +29128,8 @@ function useNfcPatrolTagController() {
28611
29128
  });
28612
29129
  if (error) {
28613
29130
  const messages = error.details.map((d) => d.message).join(", ");
28614
- import_node_server_utils153.logger.log({ level: "error", message: messages });
28615
- next(new import_node_server_utils153.BadRequestError(messages));
29131
+ import_node_server_utils154.logger.log({ level: "error", message: messages });
29132
+ next(new import_node_server_utils154.BadRequestError(messages));
28616
29133
  return;
28617
29134
  }
28618
29135
  try {
@@ -28620,7 +29137,7 @@ function useNfcPatrolTagController() {
28620
29137
  res.status(201).json(data);
28621
29138
  return;
28622
29139
  } catch (error2) {
28623
- import_node_server_utils153.logger.log({ level: "error", message: error2.message });
29140
+ import_node_server_utils154.logger.log({ level: "error", message: error2.message });
28624
29141
  next(error2);
28625
29142
  return;
28626
29143
  }
@@ -28637,8 +29154,8 @@ function useNfcPatrolTagController() {
28637
29154
  });
28638
29155
  if (error) {
28639
29156
  const messages = error.details.map((d) => d.message).join(", ");
28640
- import_node_server_utils153.logger.log({ level: "error", message: messages });
28641
- next(new import_node_server_utils153.BadRequestError(messages));
29157
+ import_node_server_utils154.logger.log({ level: "error", message: messages });
29158
+ next(new import_node_server_utils154.BadRequestError(messages));
28642
29159
  return;
28643
29160
  }
28644
29161
  const page = parseInt(req.query.page ?? "1");
@@ -28653,7 +29170,7 @@ function useNfcPatrolTagController() {
28653
29170
  res.status(200).json(data);
28654
29171
  return;
28655
29172
  } catch (error2) {
28656
- import_node_server_utils153.logger.log({ level: "error", message: error2.message });
29173
+ import_node_server_utils154.logger.log({ level: "error", message: error2.message });
28657
29174
  next(error2);
28658
29175
  return;
28659
29176
  }
@@ -28670,8 +29187,8 @@ function useNfcPatrolTagController() {
28670
29187
  });
28671
29188
  if (error) {
28672
29189
  const messages = error.details.map((d) => d.message).join(", ");
28673
- import_node_server_utils153.logger.log({ level: "error", message: messages });
28674
- next(new import_node_server_utils153.BadRequestError(messages));
29190
+ import_node_server_utils154.logger.log({ level: "error", message: messages });
29191
+ next(new import_node_server_utils154.BadRequestError(messages));
28675
29192
  return;
28676
29193
  }
28677
29194
  try {
@@ -28683,7 +29200,7 @@ function useNfcPatrolTagController() {
28683
29200
  res.status(200).json({ message: result });
28684
29201
  return;
28685
29202
  } catch (error2) {
28686
- import_node_server_utils153.logger.log({ level: "error", message: error2.message });
29203
+ import_node_server_utils154.logger.log({ level: "error", message: error2.message });
28687
29204
  next(error2);
28688
29205
  return;
28689
29206
  }
@@ -28744,12 +29261,12 @@ function MOccurrenceBook(value) {
28744
29261
  }
28745
29262
 
28746
29263
  // src/repositories/occurrence-book.repo.ts
28747
- var import_node_server_utils154 = require("@7365admin1/node-server-utils");
29264
+ var import_node_server_utils155 = require("@7365admin1/node-server-utils");
28748
29265
  var import_mongodb87 = require("mongodb");
28749
29266
  function useOccurrenceBookRepo() {
28750
- const db = import_node_server_utils154.useAtlas.getDb();
29267
+ const db = import_node_server_utils155.useAtlas.getDb();
28751
29268
  if (!db) {
28752
- throw new import_node_server_utils154.InternalServerError("Unable to connect to server.");
29269
+ throw new import_node_server_utils155.InternalServerError("Unable to connect to server.");
28753
29270
  }
28754
29271
  async function createIndexes() {
28755
29272
  try {
@@ -28757,7 +29274,7 @@ function useOccurrenceBookRepo() {
28757
29274
  { key: { site: 1, status: 1, date: 1, closedAt: 1 } }
28758
29275
  ]);
28759
29276
  } catch (error) {
28760
- throw new import_node_server_utils154.InternalServerError(
29277
+ throw new import_node_server_utils155.InternalServerError(
28761
29278
  "Failed to create index on occurrence books."
28762
29279
  );
28763
29280
  }
@@ -28768,22 +29285,22 @@ function useOccurrenceBookRepo() {
28768
29285
  entryCounter: "text"
28769
29286
  });
28770
29287
  } catch (error) {
28771
- throw new import_node_server_utils154.InternalServerError(
29288
+ throw new import_node_server_utils155.InternalServerError(
28772
29289
  "Failed to create text index on occurrence books."
28773
29290
  );
28774
29291
  }
28775
29292
  }
28776
29293
  const namespace_collection = "occurrence-books";
28777
29294
  const collection = db.collection(namespace_collection);
28778
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils154.useCache)(namespace_collection);
29295
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils155.useCache)(namespace_collection);
28779
29296
  async function add(value, session) {
28780
29297
  try {
28781
29298
  value = MOccurrenceBook(value);
28782
29299
  const res = await collection.insertOne(value, { session });
28783
29300
  delNamespace().then(() => {
28784
- import_node_server_utils154.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29301
+ import_node_server_utils155.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28785
29302
  }).catch((err) => {
28786
- import_node_server_utils154.logger.error(
29303
+ import_node_server_utils155.logger.error(
28787
29304
  `Failed to clear cache for namespace: ${namespace_collection}`,
28788
29305
  err
28789
29306
  );
@@ -28792,7 +29309,7 @@ function useOccurrenceBookRepo() {
28792
29309
  } catch (error) {
28793
29310
  const isDuplicated = error.message.includes("duplicate");
28794
29311
  if (isDuplicated) {
28795
- throw new import_node_server_utils154.BadRequestError("Occurence book already exists.");
29312
+ throw new import_node_server_utils155.BadRequestError("Occurence book already exists.");
28796
29313
  }
28797
29314
  throw error;
28798
29315
  }
@@ -28810,7 +29327,7 @@ function useOccurrenceBookRepo() {
28810
29327
  try {
28811
29328
  site = new import_mongodb87.ObjectId(site);
28812
29329
  } catch (error) {
28813
- throw new import_node_server_utils154.BadRequestError("Invalid site ID format.");
29330
+ throw new import_node_server_utils155.BadRequestError("Invalid site ID format.");
28814
29331
  }
28815
29332
  const query = {
28816
29333
  site,
@@ -28830,10 +29347,10 @@ function useOccurrenceBookRepo() {
28830
29347
  if (typeof date === "string") {
28831
29348
  const [day, month, year] = date.split("/").map(Number);
28832
29349
  if (!day || !month || !year) {
28833
- throw new import_node_server_utils154.BadRequestError("Invalid date format. Use DD/MM/YYYY.");
29350
+ throw new import_node_server_utils155.BadRequestError("Invalid date format. Use DD/MM/YYYY.");
28834
29351
  }
28835
29352
  if (day > 31 || month > 12) {
28836
- throw new import_node_server_utils154.BadRequestError("Invalid date value.");
29353
+ throw new import_node_server_utils155.BadRequestError("Invalid date value.");
28837
29354
  }
28838
29355
  dateObj = new Date(Date.UTC(year, month - 1, day));
28839
29356
  } else {
@@ -28867,10 +29384,10 @@ function useOccurrenceBookRepo() {
28867
29384
  query.$text = { $search: search };
28868
29385
  cacheOptions.search = search;
28869
29386
  }
28870
- const cacheKey = (0, import_node_server_utils154.makeCacheKey)(namespace_collection, cacheOptions);
29387
+ const cacheKey = (0, import_node_server_utils155.makeCacheKey)(namespace_collection, cacheOptions);
28871
29388
  const cachedData = await getCache(cacheKey);
28872
29389
  if (cachedData) {
28873
- import_node_server_utils154.logger.info(`Cache hit for key: ${cacheKey}`);
29390
+ import_node_server_utils155.logger.info(`Cache hit for key: ${cacheKey}`);
28874
29391
  return cachedData;
28875
29392
  }
28876
29393
  try {
@@ -28884,11 +29401,11 @@ function useOccurrenceBookRepo() {
28884
29401
  { session }
28885
29402
  ).toArray();
28886
29403
  const length = await collection.countDocuments(query, { session });
28887
- const data = (0, import_node_server_utils154.paginate)(items, page, limit, length);
29404
+ const data = (0, import_node_server_utils155.paginate)(items, page, limit, length);
28888
29405
  setCache(cacheKey, data, 15 * 60).then(() => {
28889
- import_node_server_utils154.logger.info(`Cache set for key: ${cacheKey}`);
29406
+ import_node_server_utils155.logger.info(`Cache set for key: ${cacheKey}`);
28890
29407
  }).catch((err) => {
28891
- import_node_server_utils154.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29408
+ import_node_server_utils155.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
28892
29409
  });
28893
29410
  return data;
28894
29411
  } catch (error) {
@@ -28899,23 +29416,23 @@ function useOccurrenceBookRepo() {
28899
29416
  try {
28900
29417
  _id = new import_mongodb87.ObjectId(_id);
28901
29418
  } catch (error) {
28902
- throw new import_node_server_utils154.BadRequestError("Invalid occurrence book ID format.");
29419
+ throw new import_node_server_utils155.BadRequestError("Invalid occurrence book ID format.");
28903
29420
  }
28904
- const cacheKey = (0, import_node_server_utils154.makeCacheKey)(namespace_collection, { _id });
29421
+ const cacheKey = (0, import_node_server_utils155.makeCacheKey)(namespace_collection, { _id });
28905
29422
  const cachedData = await getCache(cacheKey);
28906
29423
  if (cachedData) {
28907
- import_node_server_utils154.logger.info(`Cache hit for key: ${cacheKey}`);
29424
+ import_node_server_utils155.logger.info(`Cache hit for key: ${cacheKey}`);
28908
29425
  return cachedData;
28909
29426
  }
28910
29427
  try {
28911
29428
  const data = await collection.findOne({ _id }, { session });
28912
29429
  if (!data) {
28913
- throw new import_node_server_utils154.NotFoundError("Occurrence book not found.");
29430
+ throw new import_node_server_utils155.NotFoundError("Occurrence book not found.");
28914
29431
  }
28915
29432
  setCache(cacheKey, data, 15 * 60).then(() => {
28916
- import_node_server_utils154.logger.info(`Cache set for key: ${cacheKey}`);
29433
+ import_node_server_utils155.logger.info(`Cache set for key: ${cacheKey}`);
28917
29434
  }).catch((err) => {
28918
- import_node_server_utils154.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29435
+ import_node_server_utils155.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
28919
29436
  });
28920
29437
  return data;
28921
29438
  } catch (error) {
@@ -28927,7 +29444,7 @@ function useOccurrenceBookRepo() {
28927
29444
  try {
28928
29445
  _id = new import_mongodb87.ObjectId(_id);
28929
29446
  } catch (error) {
28930
- throw new import_node_server_utils154.BadRequestError("Invalid ID format.");
29447
+ throw new import_node_server_utils155.BadRequestError("Invalid ID format.");
28931
29448
  }
28932
29449
  try {
28933
29450
  const res = await collection.updateOne(
@@ -28936,14 +29453,14 @@ function useOccurrenceBookRepo() {
28936
29453
  { session }
28937
29454
  );
28938
29455
  if (res.modifiedCount === 0) {
28939
- throw new import_node_server_utils154.InternalServerError(
29456
+ throw new import_node_server_utils155.InternalServerError(
28940
29457
  "Unable to update daily occurrence book."
28941
29458
  );
28942
29459
  }
28943
29460
  delNamespace().then(() => {
28944
- import_node_server_utils154.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29461
+ import_node_server_utils155.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28945
29462
  }).catch((err) => {
28946
- import_node_server_utils154.logger.error(
29463
+ import_node_server_utils155.logger.error(
28947
29464
  `Failed to clear cache for namespace: ${namespace_collection}`,
28948
29465
  err
28949
29466
  );
@@ -28957,7 +29474,7 @@ function useOccurrenceBookRepo() {
28957
29474
  try {
28958
29475
  _id = new import_mongodb87.ObjectId(_id);
28959
29476
  } catch (error) {
28960
- throw new import_node_server_utils154.BadRequestError("Invalid occurrence book ID format.");
29477
+ throw new import_node_server_utils155.BadRequestError("Invalid occurrence book ID format.");
28961
29478
  }
28962
29479
  try {
28963
29480
  const updateValue = {
@@ -28967,12 +29484,12 @@ function useOccurrenceBookRepo() {
28967
29484
  };
28968
29485
  const res = await collection.updateOne({ _id }, { $set: updateValue });
28969
29486
  if (res.modifiedCount === 0) {
28970
- throw new import_node_server_utils154.InternalServerError("Unable to delete occurrence book.");
29487
+ throw new import_node_server_utils155.InternalServerError("Unable to delete occurrence book.");
28971
29488
  }
28972
29489
  delNamespace().then(() => {
28973
- import_node_server_utils154.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29490
+ import_node_server_utils155.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28974
29491
  }).catch((err) => {
28975
- import_node_server_utils154.logger.error(
29492
+ import_node_server_utils155.logger.error(
28976
29493
  `Failed to clear cache for namespace: ${namespace_collection}`,
28977
29494
  err
28978
29495
  );
@@ -28992,12 +29509,12 @@ function useOccurrenceBookRepo() {
28992
29509
  { session }
28993
29510
  );
28994
29511
  if (res.modifiedCount === 0) {
28995
- throw new import_node_server_utils154.InternalServerError("Unable to close daily occurrence book.");
29512
+ throw new import_node_server_utils155.InternalServerError("Unable to close daily occurrence book.");
28996
29513
  }
28997
29514
  delNamespace().then(() => {
28998
- import_node_server_utils154.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29515
+ import_node_server_utils155.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28999
29516
  }).catch((err) => {
29000
- import_node_server_utils154.logger.error(
29517
+ import_node_server_utils155.logger.error(
29001
29518
  `Failed to clear cache for namespace: ${namespace_collection}`,
29002
29519
  err
29003
29520
  );
@@ -29020,7 +29537,7 @@ function useOccurrenceBookRepo() {
29020
29537
  }
29021
29538
 
29022
29539
  // src/services/occurrence-book.service.ts
29023
- var import_node_server_utils155 = require("@7365admin1/node-server-utils");
29540
+ var import_node_server_utils156 = require("@7365admin1/node-server-utils");
29024
29541
  function useOccurrenceBookService() {
29025
29542
  const {
29026
29543
  add: _add,
@@ -29034,7 +29551,7 @@ function useOccurrenceBookService() {
29034
29551
  } = useCounterRepo();
29035
29552
  const { getAllSites: _getAllSites } = useSiteRepo();
29036
29553
  async function add(value) {
29037
- const session = import_node_server_utils155.useAtlas.getClient()?.startSession();
29554
+ const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
29038
29555
  session?.startTransaction();
29039
29556
  const counterName = "occurrence-book";
29040
29557
  try {
@@ -29056,7 +29573,7 @@ function useOccurrenceBookService() {
29056
29573
  }
29057
29574
  }
29058
29575
  async function updateOccurrenceBookById(id, value) {
29059
- const session = import_node_server_utils155.useAtlas.getClient()?.startSession();
29576
+ const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
29060
29577
  session?.startTransaction();
29061
29578
  try {
29062
29579
  await _updateOccurrenceBookById(id, value, session);
@@ -29074,7 +29591,7 @@ function useOccurrenceBookService() {
29074
29591
  const counterName = "occurrence-book";
29075
29592
  let page = 1;
29076
29593
  let entryCounter = 0;
29077
- const session = import_node_server_utils155.useAtlas.getClient()?.startSession();
29594
+ const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
29078
29595
  session?.startTransaction();
29079
29596
  const existingCounter = await _getByType(counterName);
29080
29597
  if (!existingCounter) {
@@ -29112,7 +29629,7 @@ function useOccurrenceBookService() {
29112
29629
  }
29113
29630
  }
29114
29631
  async function processCloseDOB() {
29115
- const session = import_node_server_utils155.useAtlas.getClient()?.startSession();
29632
+ const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
29116
29633
  session?.startTransaction();
29117
29634
  try {
29118
29635
  await _closeOccurrenceBooks(session);
@@ -29133,7 +29650,7 @@ function useOccurrenceBookService() {
29133
29650
  }
29134
29651
 
29135
29652
  // src/controllers/occurrence-book.controller.ts
29136
- var import_node_server_utils156 = require("@7365admin1/node-server-utils");
29653
+ var import_node_server_utils157 = require("@7365admin1/node-server-utils");
29137
29654
  var import_joi89 = __toESM(require("joi"));
29138
29655
  function useOccurrenceBookController() {
29139
29656
  const {
@@ -29153,8 +29670,8 @@ function useOccurrenceBookController() {
29153
29670
  });
29154
29671
  if (error) {
29155
29672
  const messages = error.details.map((d) => d.message).join(", ");
29156
- import_node_server_utils156.logger.log({ level: "error", message: messages });
29157
- next(new import_node_server_utils156.BadRequestError(messages));
29673
+ import_node_server_utils157.logger.log({ level: "error", message: messages });
29674
+ next(new import_node_server_utils157.BadRequestError(messages));
29158
29675
  return;
29159
29676
  }
29160
29677
  try {
@@ -29162,7 +29679,7 @@ function useOccurrenceBookController() {
29162
29679
  res.status(201).json(data);
29163
29680
  return;
29164
29681
  } catch (error2) {
29165
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29682
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29166
29683
  next(error2);
29167
29684
  return;
29168
29685
  }
@@ -29189,8 +29706,8 @@ function useOccurrenceBookController() {
29189
29706
  });
29190
29707
  if (error) {
29191
29708
  const messages = error.details.map((d) => d.message).join(", ");
29192
- import_node_server_utils156.logger.log({ level: "error", message: messages });
29193
- next(new import_node_server_utils156.BadRequestError(messages));
29709
+ import_node_server_utils157.logger.log({ level: "error", message: messages });
29710
+ next(new import_node_server_utils157.BadRequestError(messages));
29194
29711
  return;
29195
29712
  }
29196
29713
  const search = req.query.search ?? "";
@@ -29221,7 +29738,7 @@ function useOccurrenceBookController() {
29221
29738
  res.status(200).json(data);
29222
29739
  return;
29223
29740
  } catch (error2) {
29224
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29741
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29225
29742
  next(error2);
29226
29743
  return;
29227
29744
  }
@@ -29231,8 +29748,8 @@ function useOccurrenceBookController() {
29231
29748
  const _id = req.params.id;
29232
29749
  const { error } = validation.validate(_id);
29233
29750
  if (error) {
29234
- import_node_server_utils156.logger.log({ level: "error", message: error.message });
29235
- next(new import_node_server_utils156.BadRequestError(error.message));
29751
+ import_node_server_utils157.logger.log({ level: "error", message: error.message });
29752
+ next(new import_node_server_utils157.BadRequestError(error.message));
29236
29753
  return;
29237
29754
  }
29238
29755
  try {
@@ -29240,7 +29757,7 @@ function useOccurrenceBookController() {
29240
29757
  res.status(200).json(data);
29241
29758
  return;
29242
29759
  } catch (error2) {
29243
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29760
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29244
29761
  next(error2);
29245
29762
  return;
29246
29763
  }
@@ -29253,8 +29770,8 @@ function useOccurrenceBookController() {
29253
29770
  });
29254
29771
  if (error) {
29255
29772
  const messages = error.details.map((d) => d.message).join(", ");
29256
- import_node_server_utils156.logger.log({ level: "error", message: messages });
29257
- next(new import_node_server_utils156.BadRequestError(messages));
29773
+ import_node_server_utils157.logger.log({ level: "error", message: messages });
29774
+ next(new import_node_server_utils157.BadRequestError(messages));
29258
29775
  return;
29259
29776
  }
29260
29777
  try {
@@ -29262,7 +29779,7 @@ function useOccurrenceBookController() {
29262
29779
  res.status(200).json({ message: result });
29263
29780
  return;
29264
29781
  } catch (error2) {
29265
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29782
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29266
29783
  next(error2);
29267
29784
  return;
29268
29785
  }
@@ -29272,8 +29789,8 @@ function useOccurrenceBookController() {
29272
29789
  const _id = req.params.id;
29273
29790
  const { error } = validation.validate(_id);
29274
29791
  if (error) {
29275
- import_node_server_utils156.logger.log({ level: "error", message: error.message });
29276
- next(new import_node_server_utils156.BadRequestError(error.message));
29792
+ import_node_server_utils157.logger.log({ level: "error", message: error.message });
29793
+ next(new import_node_server_utils157.BadRequestError(error.message));
29277
29794
  return;
29278
29795
  }
29279
29796
  try {
@@ -29281,7 +29798,7 @@ function useOccurrenceBookController() {
29281
29798
  res.status(200).json({ message: "Successfully deleted occurrence book." });
29282
29799
  return;
29283
29800
  } catch (error2) {
29284
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29801
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29285
29802
  next(error2);
29286
29803
  return;
29287
29804
  }
@@ -29345,33 +29862,33 @@ function MBulletinVideo(value) {
29345
29862
  }
29346
29863
 
29347
29864
  // src/repositories/bulletin-video.repo.ts
29348
- var import_node_server_utils157 = require("@7365admin1/node-server-utils");
29865
+ var import_node_server_utils158 = require("@7365admin1/node-server-utils");
29349
29866
  var import_mongodb89 = require("mongodb");
29350
29867
  function useBulletinVideoRepo() {
29351
- const db = import_node_server_utils157.useAtlas.getDb();
29868
+ const db = import_node_server_utils158.useAtlas.getDb();
29352
29869
  if (!db) {
29353
- throw new import_node_server_utils157.InternalServerError("Unable to connect to server.");
29870
+ throw new import_node_server_utils158.InternalServerError("Unable to connect to server.");
29354
29871
  }
29355
29872
  async function createIndexes() {
29356
29873
  try {
29357
29874
  await collection.createIndexes([{ key: { site: 1 } }]);
29358
29875
  } catch (error) {
29359
- throw new import_node_server_utils157.InternalServerError(
29876
+ throw new import_node_server_utils158.InternalServerError(
29360
29877
  "Failed to create index on bulletin videos."
29361
29878
  );
29362
29879
  }
29363
29880
  }
29364
29881
  const namespace_collection = "bulletin-videos";
29365
29882
  const collection = db.collection(namespace_collection);
29366
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils157.useCache)(namespace_collection);
29883
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils158.useCache)(namespace_collection);
29367
29884
  async function add(value, session) {
29368
29885
  try {
29369
29886
  value = MBulletinVideo(value);
29370
29887
  const res = await collection.insertOne(value, { session });
29371
29888
  delNamespace().then(() => {
29372
- import_node_server_utils157.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29889
+ import_node_server_utils158.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29373
29890
  }).catch((err) => {
29374
- import_node_server_utils157.logger.error(
29891
+ import_node_server_utils158.logger.error(
29375
29892
  `Failed to clear cache for namespace: ${namespace_collection}`,
29376
29893
  err
29377
29894
  );
@@ -29380,7 +29897,7 @@ function useBulletinVideoRepo() {
29380
29897
  } catch (error) {
29381
29898
  const isDuplicated = error.message.includes("duplicate");
29382
29899
  if (isDuplicated) {
29383
- throw new import_node_server_utils157.BadRequestError("Bulletin video already exists.");
29900
+ throw new import_node_server_utils158.BadRequestError("Bulletin video already exists.");
29384
29901
  }
29385
29902
  throw error;
29386
29903
  }
@@ -29396,7 +29913,7 @@ function useBulletinVideoRepo() {
29396
29913
  try {
29397
29914
  site = new import_mongodb89.ObjectId(site);
29398
29915
  } catch (error) {
29399
- throw new import_node_server_utils157.BadRequestError("Invalid site ID format.");
29916
+ throw new import_node_server_utils158.BadRequestError("Invalid site ID format.");
29400
29917
  }
29401
29918
  const query = {
29402
29919
  site,
@@ -29414,10 +29931,10 @@ function useBulletinVideoRepo() {
29414
29931
  query.$text = { $search: search };
29415
29932
  cacheOptions.search = search;
29416
29933
  }
29417
- const cacheKey = (0, import_node_server_utils157.makeCacheKey)(namespace_collection, cacheOptions);
29934
+ const cacheKey = (0, import_node_server_utils158.makeCacheKey)(namespace_collection, cacheOptions);
29418
29935
  const cachedData = await getCache(cacheKey);
29419
29936
  if (cachedData) {
29420
- import_node_server_utils157.logger.info(`Cache hit for key: ${cacheKey}`);
29937
+ import_node_server_utils158.logger.info(`Cache hit for key: ${cacheKey}`);
29421
29938
  return cachedData;
29422
29939
  }
29423
29940
  try {
@@ -29431,11 +29948,11 @@ function useBulletinVideoRepo() {
29431
29948
  { session }
29432
29949
  ).toArray();
29433
29950
  const length = await collection.countDocuments(query, { session });
29434
- const data = (0, import_node_server_utils157.paginate)(items, page, limit, length);
29951
+ const data = (0, import_node_server_utils158.paginate)(items, page, limit, length);
29435
29952
  setCache(cacheKey, data, 15 * 60).then(() => {
29436
- import_node_server_utils157.logger.info(`Cache set for key: ${cacheKey}`);
29953
+ import_node_server_utils158.logger.info(`Cache set for key: ${cacheKey}`);
29437
29954
  }).catch((err) => {
29438
- import_node_server_utils157.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29955
+ import_node_server_utils158.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29439
29956
  });
29440
29957
  return data;
29441
29958
  } catch (error) {
@@ -29446,12 +29963,12 @@ function useBulletinVideoRepo() {
29446
29963
  try {
29447
29964
  _id = new import_mongodb89.ObjectId(_id);
29448
29965
  } catch (error) {
29449
- throw new import_node_server_utils157.BadRequestError("Invalid bulletin video ID format.");
29966
+ throw new import_node_server_utils158.BadRequestError("Invalid bulletin video ID format.");
29450
29967
  }
29451
- const cacheKey = (0, import_node_server_utils157.makeCacheKey)(namespace_collection, { _id });
29968
+ const cacheKey = (0, import_node_server_utils158.makeCacheKey)(namespace_collection, { _id });
29452
29969
  const cachedData = await getCache(cacheKey);
29453
29970
  if (cachedData) {
29454
- import_node_server_utils157.logger.info(`Cache hit for key: ${cacheKey}`);
29971
+ import_node_server_utils158.logger.info(`Cache hit for key: ${cacheKey}`);
29455
29972
  return cachedData;
29456
29973
  }
29457
29974
  try {
@@ -29460,12 +29977,12 @@ function useBulletinVideoRepo() {
29460
29977
  { session }
29461
29978
  );
29462
29979
  if (!data) {
29463
- throw new import_node_server_utils157.NotFoundError("Bulletin video not found.");
29980
+ throw new import_node_server_utils158.NotFoundError("Bulletin video not found.");
29464
29981
  }
29465
29982
  setCache(cacheKey, data, 15 * 60).then(() => {
29466
- import_node_server_utils157.logger.info(`Cache set for key: ${cacheKey}`);
29983
+ import_node_server_utils158.logger.info(`Cache set for key: ${cacheKey}`);
29467
29984
  }).catch((err) => {
29468
- import_node_server_utils157.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29985
+ import_node_server_utils158.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29469
29986
  });
29470
29987
  return data;
29471
29988
  } catch (error) {
@@ -29477,7 +29994,7 @@ function useBulletinVideoRepo() {
29477
29994
  try {
29478
29995
  _id = new import_mongodb89.ObjectId(_id);
29479
29996
  } catch (error) {
29480
- throw new import_node_server_utils157.BadRequestError("Invalid ID format.");
29997
+ throw new import_node_server_utils158.BadRequestError("Invalid ID format.");
29481
29998
  }
29482
29999
  if (value.file && typeof value.file === "string") {
29483
30000
  try {
@@ -29493,12 +30010,12 @@ function useBulletinVideoRepo() {
29493
30010
  { session }
29494
30011
  );
29495
30012
  if (res.modifiedCount === 0) {
29496
- throw new import_node_server_utils157.InternalServerError("Unable to update bulletin board.");
30013
+ throw new import_node_server_utils158.InternalServerError("Unable to update bulletin board.");
29497
30014
  }
29498
30015
  delNamespace().then(() => {
29499
- import_node_server_utils157.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30016
+ import_node_server_utils158.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29500
30017
  }).catch((err) => {
29501
- import_node_server_utils157.logger.error(
30018
+ import_node_server_utils158.logger.error(
29502
30019
  `Failed to clear cache for namespace: ${namespace_collection}`,
29503
30020
  err
29504
30021
  );
@@ -29512,7 +30029,7 @@ function useBulletinVideoRepo() {
29512
30029
  try {
29513
30030
  _id = new import_mongodb89.ObjectId(_id);
29514
30031
  } catch (error) {
29515
- throw new import_node_server_utils157.BadRequestError("Invalid bulletin video ID format.");
30032
+ throw new import_node_server_utils158.BadRequestError("Invalid bulletin video ID format.");
29516
30033
  }
29517
30034
  try {
29518
30035
  const updateValue = {
@@ -29526,12 +30043,12 @@ function useBulletinVideoRepo() {
29526
30043
  { session }
29527
30044
  );
29528
30045
  if (res.modifiedCount === 0) {
29529
- throw new import_node_server_utils157.InternalServerError("Unable to delete bulletin video.");
30046
+ throw new import_node_server_utils158.InternalServerError("Unable to delete bulletin video.");
29530
30047
  }
29531
30048
  delNamespace().then(() => {
29532
- import_node_server_utils157.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30049
+ import_node_server_utils158.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29533
30050
  }).catch((err) => {
29534
- import_node_server_utils157.logger.error(
30051
+ import_node_server_utils158.logger.error(
29535
30052
  `Failed to clear cache for namespace: ${namespace_collection}`,
29536
30053
  err
29537
30054
  );
@@ -29552,7 +30069,7 @@ function useBulletinVideoRepo() {
29552
30069
  }
29553
30070
 
29554
30071
  // src/services/bulletin-video.service.ts
29555
- var import_node_server_utils158 = require("@7365admin1/node-server-utils");
30072
+ var import_node_server_utils159 = require("@7365admin1/node-server-utils");
29556
30073
  function useBulletinVideoService() {
29557
30074
  const {
29558
30075
  add: _add,
@@ -29562,7 +30079,7 @@ function useBulletinVideoService() {
29562
30079
  } = useBulletinVideoRepo();
29563
30080
  const { deleteFileById: _deleteFileById } = useFileRepo();
29564
30081
  async function add(value) {
29565
- const session = import_node_server_utils158.useAtlas.getClient()?.startSession();
30082
+ const session = import_node_server_utils159.useAtlas.getClient()?.startSession();
29566
30083
  session?.startTransaction();
29567
30084
  try {
29568
30085
  await _add(value, session);
@@ -29576,7 +30093,7 @@ function useBulletinVideoService() {
29576
30093
  }
29577
30094
  }
29578
30095
  async function updateBulletinVideoById(id, value) {
29579
- const session = import_node_server_utils158.useAtlas.getClient()?.startSession();
30096
+ const session = import_node_server_utils159.useAtlas.getClient()?.startSession();
29580
30097
  session?.startTransaction();
29581
30098
  try {
29582
30099
  if (value.file)
@@ -29592,7 +30109,7 @@ function useBulletinVideoService() {
29592
30109
  }
29593
30110
  }
29594
30111
  async function deleteBulletinVideoById(id) {
29595
- const session = import_node_server_utils158.useAtlas.getClient()?.startSession();
30112
+ const session = import_node_server_utils159.useAtlas.getClient()?.startSession();
29596
30113
  session?.startTransaction();
29597
30114
  try {
29598
30115
  const existingBulletinVideo = await _getBulletinVideoById(id);
@@ -29616,7 +30133,7 @@ function useBulletinVideoService() {
29616
30133
  }
29617
30134
 
29618
30135
  // src/controllers/bulletin-video.controller.ts
29619
- var import_node_server_utils159 = require("@7365admin1/node-server-utils");
30136
+ var import_node_server_utils160 = require("@7365admin1/node-server-utils");
29620
30137
  var import_joi91 = __toESM(require("joi"));
29621
30138
  function useBulletinVideoController() {
29622
30139
  const { add: _add, updateBulletinVideoById: _updateBulletinVideoById } = useBulletinVideoService();
@@ -29632,8 +30149,8 @@ function useBulletinVideoController() {
29632
30149
  });
29633
30150
  if (error) {
29634
30151
  const messages = error.details.map((d) => d.message).join(", ");
29635
- import_node_server_utils159.logger.log({ level: "error", message: messages });
29636
- next(new import_node_server_utils159.BadRequestError(messages));
30152
+ import_node_server_utils160.logger.log({ level: "error", message: messages });
30153
+ next(new import_node_server_utils160.BadRequestError(messages));
29637
30154
  return;
29638
30155
  }
29639
30156
  try {
@@ -29641,7 +30158,7 @@ function useBulletinVideoController() {
29641
30158
  res.status(201).json(data);
29642
30159
  return;
29643
30160
  } catch (error2) {
29644
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
30161
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29645
30162
  next(error2);
29646
30163
  return;
29647
30164
  }
@@ -29663,8 +30180,8 @@ function useBulletinVideoController() {
29663
30180
  });
29664
30181
  if (error) {
29665
30182
  const messages = error.details.map((d) => d.message).join(", ");
29666
- import_node_server_utils159.logger.log({ level: "error", message: messages });
29667
- next(new import_node_server_utils159.BadRequestError(messages));
30183
+ import_node_server_utils160.logger.log({ level: "error", message: messages });
30184
+ next(new import_node_server_utils160.BadRequestError(messages));
29668
30185
  return;
29669
30186
  }
29670
30187
  const search = req.query.search ?? "";
@@ -29691,7 +30208,7 @@ function useBulletinVideoController() {
29691
30208
  res.status(200).json(data);
29692
30209
  return;
29693
30210
  } catch (error2) {
29694
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
30211
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29695
30212
  next(error2);
29696
30213
  return;
29697
30214
  }
@@ -29701,8 +30218,8 @@ function useBulletinVideoController() {
29701
30218
  const _id = req.params.id;
29702
30219
  const { error } = validation.validate(_id);
29703
30220
  if (error) {
29704
- import_node_server_utils159.logger.log({ level: "error", message: error.message });
29705
- next(new import_node_server_utils159.BadRequestError(error.message));
30221
+ import_node_server_utils160.logger.log({ level: "error", message: error.message });
30222
+ next(new import_node_server_utils160.BadRequestError(error.message));
29706
30223
  return;
29707
30224
  }
29708
30225
  try {
@@ -29710,7 +30227,7 @@ function useBulletinVideoController() {
29710
30227
  res.status(200).json(data);
29711
30228
  return;
29712
30229
  } catch (error2) {
29713
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
30230
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29714
30231
  next(error2);
29715
30232
  return;
29716
30233
  }
@@ -29723,8 +30240,8 @@ function useBulletinVideoController() {
29723
30240
  });
29724
30241
  if (error) {
29725
30242
  const messages = error.details.map((d) => d.message).join(", ");
29726
- import_node_server_utils159.logger.log({ level: "error", message: messages });
29727
- next(new import_node_server_utils159.BadRequestError(messages));
30243
+ import_node_server_utils160.logger.log({ level: "error", message: messages });
30244
+ next(new import_node_server_utils160.BadRequestError(messages));
29728
30245
  return;
29729
30246
  }
29730
30247
  try {
@@ -29732,7 +30249,7 @@ function useBulletinVideoController() {
29732
30249
  res.status(200).json({ message: result });
29733
30250
  return;
29734
30251
  } catch (error2) {
29735
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
30252
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29736
30253
  next(error2);
29737
30254
  return;
29738
30255
  }
@@ -29742,8 +30259,8 @@ function useBulletinVideoController() {
29742
30259
  const _id = req.params.id;
29743
30260
  const { error } = validation.validate(_id);
29744
30261
  if (error) {
29745
- import_node_server_utils159.logger.log({ level: "error", message: error.message });
29746
- next(new import_node_server_utils159.BadRequestError(error.message));
30262
+ import_node_server_utils160.logger.log({ level: "error", message: error.message });
30263
+ next(new import_node_server_utils160.BadRequestError(error.message));
29747
30264
  return;
29748
30265
  }
29749
30266
  try {
@@ -29751,7 +30268,7 @@ function useBulletinVideoController() {
29751
30268
  res.status(200).json({ message: "Successfully deleted bulletin video." });
29752
30269
  return;
29753
30270
  } catch (error2) {
29754
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
30271
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29755
30272
  next(error2);
29756
30273
  return;
29757
30274
  }
@@ -29766,7 +30283,7 @@ function useBulletinVideoController() {
29766
30283
  }
29767
30284
 
29768
30285
  // src/models/site-soa.model.ts
29769
- var import_node_server_utils160 = require("@7365admin1/node-server-utils");
30286
+ var import_node_server_utils161 = require("@7365admin1/node-server-utils");
29770
30287
  var import_mongodb90 = require("mongodb");
29771
30288
  var import_joi92 = __toESM(require("joi"));
29772
30289
  var schemaSOABillingItem = import_joi92.default.object({
@@ -29824,35 +30341,35 @@ var schemaUpdateStatementOfAccount = import_joi92.default.object({
29824
30341
  function MStatementOfAccount(value) {
29825
30342
  const { error } = schemaStatementOfAccount.validate(value);
29826
30343
  if (error) {
29827
- import_node_server_utils160.logger.info(`Unit Billing: ${error.message}`);
29828
- throw new import_node_server_utils160.BadRequestError(error.message);
30344
+ import_node_server_utils161.logger.info(`Unit Billing: ${error.message}`);
30345
+ throw new import_node_server_utils161.BadRequestError(error.message);
29829
30346
  }
29830
30347
  if (value._id && typeof value._id === "string") {
29831
30348
  try {
29832
30349
  value._id = new import_mongodb90.ObjectId(value._id);
29833
30350
  } catch {
29834
- throw new import_node_server_utils160.BadRequestError("Invalid _id format");
30351
+ throw new import_node_server_utils161.BadRequestError("Invalid _id format");
29835
30352
  }
29836
30353
  }
29837
30354
  if (value.site && typeof value.site === "string") {
29838
30355
  try {
29839
30356
  value.site = new import_mongodb90.ObjectId(value.site);
29840
30357
  } catch {
29841
- throw new import_node_server_utils160.BadRequestError("Invalid site format");
30358
+ throw new import_node_server_utils161.BadRequestError("Invalid site format");
29842
30359
  }
29843
30360
  }
29844
30361
  if (value.createdBy && typeof value.createdBy === "string") {
29845
30362
  try {
29846
30363
  value.createdBy = new import_mongodb90.ObjectId(value.createdBy);
29847
30364
  } catch {
29848
- throw new import_node_server_utils160.BadRequestError("Invalid createBy format");
30365
+ throw new import_node_server_utils161.BadRequestError("Invalid createBy format");
29849
30366
  }
29850
30367
  }
29851
30368
  if (value.unitId && typeof value.unitId === "string") {
29852
30369
  try {
29853
30370
  value.unitId = new import_mongodb90.ObjectId(value.unitId);
29854
30371
  } catch {
29855
- throw new import_node_server_utils160.BadRequestError("Invalid unitId format");
30372
+ throw new import_node_server_utils161.BadRequestError("Invalid unitId format");
29856
30373
  }
29857
30374
  }
29858
30375
  if (value.billing && Array.isArray(value.billing)) {
@@ -29861,7 +30378,7 @@ function MStatementOfAccount(value) {
29861
30378
  try {
29862
30379
  bill._id = new import_mongodb90.ObjectId(bill._id);
29863
30380
  } catch {
29864
- throw new import_node_server_utils160.BadRequestError("Invalid billing id format");
30381
+ throw new import_node_server_utils161.BadRequestError("Invalid billing id format");
29865
30382
  }
29866
30383
  }
29867
30384
  return bill;
@@ -29889,16 +30406,16 @@ function MStatementOfAccount(value) {
29889
30406
  }
29890
30407
 
29891
30408
  // src/repositories/site-soa.repo.ts
29892
- var import_node_server_utils161 = require("@7365admin1/node-server-utils");
30409
+ var import_node_server_utils162 = require("@7365admin1/node-server-utils");
29893
30410
  var import_mongodb91 = require("mongodb");
29894
30411
  function useStatementOfAccountRepo() {
29895
- const db = import_node_server_utils161.useAtlas.getDb();
30412
+ const db = import_node_server_utils162.useAtlas.getDb();
29896
30413
  if (!db) {
29897
30414
  throw new Error("Unable to connect to server.");
29898
30415
  }
29899
30416
  const namespace_collection = "site.statement-of-accounts";
29900
30417
  const collection = db.collection(namespace_collection);
29901
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils161.useCache)(namespace_collection);
30418
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils162.useCache)(namespace_collection);
29902
30419
  async function createTextIndex() {
29903
30420
  try {
29904
30421
  await collection.createIndex({
@@ -29906,11 +30423,11 @@ function useStatementOfAccountRepo() {
29906
30423
  });
29907
30424
  return "Successfully created text index on site SOA.";
29908
30425
  } catch (error) {
29909
- import_node_server_utils161.logger.log({
30426
+ import_node_server_utils162.logger.log({
29910
30427
  level: "error",
29911
30428
  message: error.message
29912
30429
  });
29913
- throw new import_node_server_utils161.InternalServerError("Failed to create text index on site SOA.");
30430
+ throw new import_node_server_utils162.InternalServerError("Failed to create text index on site SOA.");
29914
30431
  }
29915
30432
  }
29916
30433
  async function add(value, session) {
@@ -29920,15 +30437,15 @@ function useStatementOfAccountRepo() {
29920
30437
  delCachedData();
29921
30438
  return res.insertedId;
29922
30439
  } catch (error) {
29923
- import_node_server_utils161.logger.log({
30440
+ import_node_server_utils162.logger.log({
29924
30441
  level: "error",
29925
30442
  message: error.message
29926
30443
  });
29927
30444
  const isDuplicated = error.message.includes("duplicate");
29928
30445
  if (isDuplicated) {
29929
- throw new import_node_server_utils161.BadRequestError("Site SOA already exist.");
30446
+ throw new import_node_server_utils162.BadRequestError("Site SOA already exist.");
29930
30447
  }
29931
- if (error instanceof import_node_server_utils161.AppError) {
30448
+ if (error instanceof import_node_server_utils162.AppError) {
29932
30449
  throw error;
29933
30450
  } else {
29934
30451
  throw new Error("Failed to create Site SOA");
@@ -29984,10 +30501,10 @@ function useStatementOfAccountRepo() {
29984
30501
  ...dateFrom && { dateFrom: dateFrom.toString() },
29985
30502
  ...dateTo && { dateTo: dateTo.toString() }
29986
30503
  };
29987
- const cacheKey = (0, import_node_server_utils161.makeCacheKey)(namespace_collection, cacheOptions);
30504
+ const cacheKey = (0, import_node_server_utils162.makeCacheKey)(namespace_collection, cacheOptions);
29988
30505
  const cachedData = await getCache(cacheKey);
29989
30506
  if (cachedData) {
29990
- import_node_server_utils161.logger.info(`Cache hit for key: ${cacheKey}`);
30507
+ import_node_server_utils162.logger.info(`Cache hit for key: ${cacheKey}`);
29991
30508
  return cachedData;
29992
30509
  }
29993
30510
  try {
@@ -30014,9 +30531,9 @@ function useStatementOfAccountRepo() {
30014
30531
  collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
30015
30532
  ]);
30016
30533
  const totalCount = countResult[0]?.total || 0;
30017
- const data = (0, import_node_server_utils161.paginate)(items, page, limit, totalCount);
30018
- setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils161.logger.info(`Cache set for key: ${cacheKey}`)).catch(
30019
- (err) => import_node_server_utils161.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
30534
+ const data = (0, import_node_server_utils162.paginate)(items, page, limit, totalCount);
30535
+ setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils162.logger.info(`Cache set for key: ${cacheKey}`)).catch(
30536
+ (err) => import_node_server_utils162.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
30020
30537
  );
30021
30538
  return data;
30022
30539
  } catch (error) {
@@ -30027,13 +30544,13 @@ function useStatementOfAccountRepo() {
30027
30544
  try {
30028
30545
  _id = new import_mongodb91.ObjectId(_id);
30029
30546
  } catch (error) {
30030
- throw new import_node_server_utils161.BadRequestError("Invalid ID.");
30547
+ throw new import_node_server_utils162.BadRequestError("Invalid ID.");
30031
30548
  }
30032
- const cacheKey = (0, import_node_server_utils161.makeCacheKey)(namespace_collection, { _id: String(_id) });
30549
+ const cacheKey = (0, import_node_server_utils162.makeCacheKey)(namespace_collection, { _id: String(_id) });
30033
30550
  try {
30034
30551
  const cached = await getCache(cacheKey);
30035
30552
  if (cached) {
30036
- import_node_server_utils161.logger.log({
30553
+ import_node_server_utils162.logger.log({
30037
30554
  level: "info",
30038
30555
  message: `Cache hit for getById soa: ${cacheKey}`
30039
30556
  });
@@ -30043,22 +30560,22 @@ function useStatementOfAccountRepo() {
30043
30560
  _id
30044
30561
  });
30045
30562
  setCache(cacheKey, result, 300).then(() => {
30046
- import_node_server_utils161.logger.log({
30563
+ import_node_server_utils162.logger.log({
30047
30564
  level: "info",
30048
30565
  message: `Cache set for ssoa by id: ${cacheKey}`
30049
30566
  });
30050
30567
  }).catch((err) => {
30051
- import_node_server_utils161.logger.log({
30568
+ import_node_server_utils162.logger.log({
30052
30569
  level: "error",
30053
30570
  message: `Failed to set cache for soa by id: ${err.message}`
30054
30571
  });
30055
30572
  });
30056
30573
  return result;
30057
30574
  } catch (error) {
30058
- if (error instanceof import_node_server_utils161.AppError) {
30575
+ if (error instanceof import_node_server_utils162.AppError) {
30059
30576
  throw error;
30060
30577
  } else {
30061
- throw new import_node_server_utils161.InternalServerError("Failed to get soa by id.");
30578
+ throw new import_node_server_utils162.InternalServerError("Failed to get soa by id.");
30062
30579
  }
30063
30580
  }
30064
30581
  }
@@ -30066,7 +30583,7 @@ function useStatementOfAccountRepo() {
30066
30583
  try {
30067
30584
  _id = new import_mongodb91.ObjectId(_id);
30068
30585
  } catch (error) {
30069
- throw new import_node_server_utils161.BadRequestError("Invalid site SOA transaction ID format.");
30586
+ throw new import_node_server_utils162.BadRequestError("Invalid site SOA transaction ID format.");
30070
30587
  }
30071
30588
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
30072
30589
  try {
@@ -30085,7 +30602,7 @@ function useStatementOfAccountRepo() {
30085
30602
  try {
30086
30603
  _id = new import_mongodb91.ObjectId(_id);
30087
30604
  } catch (error) {
30088
- throw new import_node_server_utils161.BadRequestError("Invalid site SOA transaction ID format.");
30605
+ throw new import_node_server_utils162.BadRequestError("Invalid site SOA transaction ID format.");
30089
30606
  }
30090
30607
  try {
30091
30608
  const updateValue = {
@@ -30095,7 +30612,7 @@ function useStatementOfAccountRepo() {
30095
30612
  };
30096
30613
  const res = await collection.updateOne({ _id }, { $set: updateValue });
30097
30614
  if (res.modifiedCount === 0) {
30098
- throw new import_node_server_utils161.InternalServerError("Unable to delete site SOA.");
30615
+ throw new import_node_server_utils162.InternalServerError("Unable to delete site SOA.");
30099
30616
  }
30100
30617
  delCachedData();
30101
30618
  return res.modifiedCount;
@@ -30107,7 +30624,7 @@ function useStatementOfAccountRepo() {
30107
30624
  try {
30108
30625
  _id = new import_mongodb91.ObjectId(_id);
30109
30626
  } catch (error) {
30110
- throw new import_node_server_utils161.BadRequestError("Invalid file ID format.");
30627
+ throw new import_node_server_utils162.BadRequestError("Invalid file ID format.");
30111
30628
  }
30112
30629
  try {
30113
30630
  const res = await collection.updateOne(
@@ -30118,17 +30635,17 @@ function useStatementOfAccountRepo() {
30118
30635
  delCachedData();
30119
30636
  return res;
30120
30637
  } catch (error) {
30121
- throw new import_node_server_utils161.InternalServerError("Failed to update soa request.");
30638
+ throw new import_node_server_utils162.InternalServerError("Failed to update soa request.");
30122
30639
  }
30123
30640
  }
30124
30641
  function delCachedData() {
30125
30642
  delNamespace().then(() => {
30126
- import_node_server_utils161.logger.log({
30643
+ import_node_server_utils162.logger.log({
30127
30644
  level: "info",
30128
30645
  message: `Cache namespace cleared for ${namespace_collection}`
30129
30646
  });
30130
30647
  }).catch((err) => {
30131
- import_node_server_utils161.logger.log({
30648
+ import_node_server_utils162.logger.log({
30132
30649
  level: "error",
30133
30650
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
30134
30651
  });
@@ -30146,19 +30663,19 @@ function useStatementOfAccountRepo() {
30146
30663
  }
30147
30664
 
30148
30665
  // src/controllers/site-soa.controller.ts
30149
- var import_node_server_utils163 = require("@7365admin1/node-server-utils");
30666
+ var import_node_server_utils164 = require("@7365admin1/node-server-utils");
30150
30667
 
30151
30668
  // src/services/site-soa.service.ts
30152
- var import_node_server_utils162 = require("@7365admin1/node-server-utils");
30669
+ var import_node_server_utils163 = require("@7365admin1/node-server-utils");
30153
30670
  var import_puppeteer = require("puppeteer");
30154
30671
  function useStatementOfAccountService() {
30155
30672
  const { add: _add } = useStatementOfAccountRepo();
30156
30673
  const { getUnitBillingBySite } = useSiteUnitBillingRepo();
30157
30674
  const { getUserById } = useUserRepo();
30158
30675
  async function add(value, dateFrom, dateTo) {
30159
- const session = import_node_server_utils162.useAtlas.getClient()?.startSession();
30676
+ const session = import_node_server_utils163.useAtlas.getClient()?.startSession();
30160
30677
  if (!session) {
30161
- throw new import_node_server_utils162.BadRequestError("Database session not available.");
30678
+ throw new import_node_server_utils163.BadRequestError("Database session not available.");
30162
30679
  }
30163
30680
  try {
30164
30681
  await session.startTransaction();
@@ -30184,7 +30701,7 @@ function useStatementOfAccountService() {
30184
30701
  try {
30185
30702
  unit._id = unit._id.toString();
30186
30703
  } catch {
30187
- throw new import_node_server_utils162.BadRequestError("Invalid unit id format/type");
30704
+ throw new import_node_server_utils163.BadRequestError("Invalid unit id format/type");
30188
30705
  }
30189
30706
  return unit;
30190
30707
  });
@@ -30197,7 +30714,7 @@ function useStatementOfAccountService() {
30197
30714
  await session.commitTransaction();
30198
30715
  return result;
30199
30716
  } catch (error) {
30200
- import_node_server_utils162.logger.log({
30717
+ import_node_server_utils163.logger.log({
30201
30718
  level: "error",
30202
30719
  message: `Failed to create soa: ${error.message}`
30203
30720
  });
@@ -30273,7 +30790,7 @@ function useStatementOfAccountService() {
30273
30790
  await browser.close();
30274
30791
  return pdfBuffer;
30275
30792
  } catch (error) {
30276
- import_node_server_utils162.logger.log({
30793
+ import_node_server_utils163.logger.log({
30277
30794
  level: "error",
30278
30795
  message: `Failed to create soa pdf: ${error.message}`
30279
30796
  });
@@ -30313,7 +30830,7 @@ function useStatementOfAccountController() {
30313
30830
  abortEarly: false
30314
30831
  });
30315
30832
  if (bodyError) {
30316
- throw new import_node_server_utils163.BadRequestError(bodyError.message);
30833
+ throw new import_node_server_utils164.BadRequestError(bodyError.message);
30317
30834
  }
30318
30835
  const { error: queryError, value: queryValue } = validation.validate(
30319
30836
  query,
@@ -30322,7 +30839,7 @@ function useStatementOfAccountController() {
30322
30839
  }
30323
30840
  );
30324
30841
  if (queryError) {
30325
- throw new import_node_server_utils163.BadRequestError(queryError.message);
30842
+ throw new import_node_server_utils164.BadRequestError(queryError.message);
30326
30843
  }
30327
30844
  try {
30328
30845
  const soa = await _add(bodyValue, queryValue.dateFrom, queryValue.dateTo);
@@ -30352,8 +30869,8 @@ function useStatementOfAccountController() {
30352
30869
  });
30353
30870
  if (error) {
30354
30871
  const messages = error.details.map((d) => d.message).join(", ");
30355
- import_node_server_utils163.logger.log({ level: "error", message: messages });
30356
- next(new import_node_server_utils163.BadRequestError(messages));
30872
+ import_node_server_utils164.logger.log({ level: "error", message: messages });
30873
+ next(new import_node_server_utils164.BadRequestError(messages));
30357
30874
  return;
30358
30875
  }
30359
30876
  const search = req.query.search ?? "";
@@ -30386,7 +30903,7 @@ function useStatementOfAccountController() {
30386
30903
  res.status(200).json(data);
30387
30904
  return;
30388
30905
  } catch (error2) {
30389
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
30906
+ import_node_server_utils164.logger.log({ level: "error", message: error2.message });
30390
30907
  next(error2);
30391
30908
  return;
30392
30909
  }
@@ -30398,7 +30915,7 @@ function useStatementOfAccountController() {
30398
30915
  });
30399
30916
  const { error } = validation.validate({ id });
30400
30917
  if (error) {
30401
- next(new import_node_server_utils163.BadRequestError(error.message));
30918
+ next(new import_node_server_utils164.BadRequestError(error.message));
30402
30919
  return;
30403
30920
  }
30404
30921
  try {
@@ -30420,8 +30937,8 @@ function useStatementOfAccountController() {
30420
30937
  });
30421
30938
  if (error) {
30422
30939
  const messages = error.details.map((d) => d.message).join(", ");
30423
- import_node_server_utils163.logger.log({ level: "error", message: messages });
30424
- next(new import_node_server_utils163.BadRequestError(messages));
30940
+ import_node_server_utils164.logger.log({ level: "error", message: messages });
30941
+ next(new import_node_server_utils164.BadRequestError(messages));
30425
30942
  return;
30426
30943
  }
30427
30944
  try {
@@ -30429,7 +30946,7 @@ function useStatementOfAccountController() {
30429
30946
  res.status(200).json({ message: result });
30430
30947
  return;
30431
30948
  } catch (error2) {
30432
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
30949
+ import_node_server_utils164.logger.log({ level: "error", message: error2.message });
30433
30950
  next(error2);
30434
30951
  return;
30435
30952
  }
@@ -30439,8 +30956,8 @@ function useStatementOfAccountController() {
30439
30956
  const _id = req.params.id;
30440
30957
  const { error } = validation.validate(_id);
30441
30958
  if (error) {
30442
- import_node_server_utils163.logger.log({ level: "error", message: error.message });
30443
- next(new import_node_server_utils163.BadRequestError(error.message));
30959
+ import_node_server_utils164.logger.log({ level: "error", message: error.message });
30960
+ next(new import_node_server_utils164.BadRequestError(error.message));
30444
30961
  return;
30445
30962
  }
30446
30963
  try {
@@ -30448,7 +30965,7 @@ function useStatementOfAccountController() {
30448
30965
  res.status(200).json({ message: "Successfully deleted site SOA." });
30449
30966
  return;
30450
30967
  } catch (error2) {
30451
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
30968
+ import_node_server_utils164.logger.log({ level: "error", message: error2.message });
30452
30969
  next(error2);
30453
30970
  return;
30454
30971
  }
@@ -30466,8 +30983,8 @@ function useStatementOfAccountController() {
30466
30983
  const { error } = validation.validate(query, { abortEarly: false });
30467
30984
  if (error) {
30468
30985
  const messages = error.details.map((d) => d.message).join(", ");
30469
- import_node_server_utils163.logger.log({ level: "error", message: messages });
30470
- next(new import_node_server_utils163.BadRequestError(messages));
30986
+ import_node_server_utils164.logger.log({ level: "error", message: messages });
30987
+ next(new import_node_server_utils164.BadRequestError(messages));
30471
30988
  return;
30472
30989
  }
30473
30990
  const url = req.query.url;
@@ -30484,7 +31001,7 @@ function useStatementOfAccountController() {
30484
31001
  ];
30485
31002
  const appKeyRaw = req.query.appKey ?? "PROPERTY";
30486
31003
  if (!ALLOWED_APP_KEYS.includes(appKeyRaw)) {
30487
- throw new import_node_server_utils163.BadRequestError(`Invalid appKey: ${appKeyRaw}`);
31004
+ throw new import_node_server_utils164.BadRequestError(`Invalid appKey: ${appKeyRaw}`);
30488
31005
  }
30489
31006
  const appKey = appKeyRaw;
30490
31007
  const pdfBuffer = await _generatePDF(
@@ -30512,7 +31029,7 @@ function useStatementOfAccountController() {
30512
31029
  res.end(pdfBuffer);
30513
31030
  } catch (error) {
30514
31031
  console.error("PDF generation error:", error);
30515
- import_node_server_utils163.logger.log({ level: "error", message: error.message });
31032
+ import_node_server_utils164.logger.log({ level: "error", message: error.message });
30516
31033
  next(error);
30517
31034
  return;
30518
31035
  }
@@ -30528,8 +31045,8 @@ function useStatementOfAccountController() {
30528
31045
  });
30529
31046
  if (error) {
30530
31047
  const messages = error.details.map((d) => d.message).join(", ");
30531
- import_node_server_utils163.logger.log({ level: "error", message: messages });
30532
- next(new import_node_server_utils163.BadRequestError(messages));
31048
+ import_node_server_utils164.logger.log({ level: "error", message: messages });
31049
+ next(new import_node_server_utils164.BadRequestError(messages));
30533
31050
  return;
30534
31051
  }
30535
31052
  try {
@@ -30540,7 +31057,7 @@ function useStatementOfAccountController() {
30540
31057
  res.status(200).json({ message: result });
30541
31058
  return;
30542
31059
  } catch (error2) {
30543
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
31060
+ import_node_server_utils164.logger.log({ level: "error", message: error2.message });
30544
31061
  next(error2);
30545
31062
  return;
30546
31063
  }
@@ -30557,7 +31074,7 @@ function useStatementOfAccountController() {
30557
31074
  }
30558
31075
 
30559
31076
  // src/models/site-entrypass-settings.model.ts
30560
- var import_node_server_utils164 = require("@7365admin1/node-server-utils");
31077
+ var import_node_server_utils165 = require("@7365admin1/node-server-utils");
30561
31078
  var import_mongodb92 = require("mongodb");
30562
31079
  var import_joi94 = __toESM(require("joi"));
30563
31080
  var schemaEntryPassSettings = import_joi94.default.object({
@@ -30601,28 +31118,28 @@ var schemaUpdateEntryPassSettings = import_joi94.default.object({
30601
31118
  function MEntryPassSettings(value) {
30602
31119
  const { error } = schemaEntryPassSettings.validate(value);
30603
31120
  if (error) {
30604
- import_node_server_utils164.logger.info(`Entry Pass Settings: ${error.message}`);
30605
- throw new import_node_server_utils164.BadRequestError(error.message);
31121
+ import_node_server_utils165.logger.info(`Entry Pass Settings: ${error.message}`);
31122
+ throw new import_node_server_utils165.BadRequestError(error.message);
30606
31123
  }
30607
31124
  if (value._id && typeof value._id === "string") {
30608
31125
  try {
30609
31126
  value._id = new import_mongodb92.ObjectId(value._id);
30610
31127
  } catch {
30611
- throw new import_node_server_utils164.BadRequestError("Invalid _id format");
31128
+ throw new import_node_server_utils165.BadRequestError("Invalid _id format");
30612
31129
  }
30613
31130
  }
30614
31131
  if (value.site && typeof value.site === "string") {
30615
31132
  try {
30616
31133
  value.site = new import_mongodb92.ObjectId(value.site);
30617
31134
  } catch {
30618
- throw new import_node_server_utils164.BadRequestError("Invalid site format");
31135
+ throw new import_node_server_utils165.BadRequestError("Invalid site format");
30619
31136
  }
30620
31137
  }
30621
31138
  if (value.org && typeof value.org === "string") {
30622
31139
  try {
30623
31140
  value.org = new import_mongodb92.ObjectId(value.org);
30624
31141
  } catch {
30625
- throw new import_node_server_utils164.BadRequestError("Invalid org format");
31142
+ throw new import_node_server_utils165.BadRequestError("Invalid org format");
30626
31143
  }
30627
31144
  }
30628
31145
  return {
@@ -30649,23 +31166,23 @@ function MEntryPassSettings(value) {
30649
31166
  }
30650
31167
 
30651
31168
  // src/repositories/site-entrypass-settings.repo.ts
30652
- var import_node_server_utils165 = require("@7365admin1/node-server-utils");
31169
+ var import_node_server_utils166 = require("@7365admin1/node-server-utils");
30653
31170
  var import_mongodb93 = require("mongodb");
30654
31171
  function useEntryPassSettingsRepo() {
30655
- const db = import_node_server_utils165.useAtlas.getDb();
31172
+ const db = import_node_server_utils166.useAtlas.getDb();
30656
31173
  if (!db) {
30657
- throw new import_node_server_utils165.InternalServerError("Unable to connect to server.");
31174
+ throw new import_node_server_utils166.InternalServerError("Unable to connect to server.");
30658
31175
  }
30659
31176
  const namespace_collection = "site.entrypass-settings";
30660
31177
  const collection = db.collection(namespace_collection);
30661
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils165.useCache)(namespace_collection);
31178
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils166.useCache)(namespace_collection);
30662
31179
  async function createTextIndex() {
30663
31180
  try {
30664
31181
  await collection.createIndex({
30665
31182
  name: "text"
30666
31183
  });
30667
31184
  } catch (error) {
30668
- throw new import_node_server_utils165.InternalServerError(
31185
+ throw new import_node_server_utils166.InternalServerError(
30669
31186
  "Failed to create text index on entry pass settings."
30670
31187
  );
30671
31188
  }
@@ -30675,9 +31192,9 @@ function useEntryPassSettingsRepo() {
30675
31192
  value = MEntryPassSettings(value);
30676
31193
  const res = await collection.insertOne(value, { session });
30677
31194
  delNamespace().then(() => {
30678
- import_node_server_utils165.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
31195
+ import_node_server_utils166.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30679
31196
  }).catch((err) => {
30680
- import_node_server_utils165.logger.error(
31197
+ import_node_server_utils166.logger.error(
30681
31198
  `Failed to clear cache for namespace: ${namespace_collection}`,
30682
31199
  err
30683
31200
  );
@@ -30686,7 +31203,7 @@ function useEntryPassSettingsRepo() {
30686
31203
  } catch (error) {
30687
31204
  const isDuplicated = error.message.includes("duplicate");
30688
31205
  if (isDuplicated) {
30689
- throw new import_node_server_utils165.BadRequestError("Card already exists.");
31206
+ throw new import_node_server_utils166.BadRequestError("Card already exists.");
30690
31207
  }
30691
31208
  throw error;
30692
31209
  }
@@ -30711,10 +31228,10 @@ function useEntryPassSettingsRepo() {
30711
31228
  const query = {
30712
31229
  ...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
30713
31230
  };
30714
- const cacheKey = (0, import_node_server_utils165.makeCacheKey)(namespace_collection, cacheOptions);
31231
+ const cacheKey = (0, import_node_server_utils166.makeCacheKey)(namespace_collection, cacheOptions);
30715
31232
  const cachedData = await getCache(cacheKey);
30716
31233
  if (cachedData) {
30717
- import_node_server_utils165.logger.info(`Cache hit for key: ${cacheKey}`);
31234
+ import_node_server_utils166.logger.info(`Cache hit for key: ${cacheKey}`);
30718
31235
  return cachedData;
30719
31236
  }
30720
31237
  try {
@@ -30747,11 +31264,11 @@ function useEntryPassSettingsRepo() {
30747
31264
  }
30748
31265
  ]).toArray();
30749
31266
  const length = await collection.countDocuments(query);
30750
- const data = (0, import_node_server_utils165.paginate)(items, page, limit, length);
31267
+ const data = (0, import_node_server_utils166.paginate)(items, page, limit, length);
30751
31268
  setCache(cacheKey, data, 15 * 60).then(() => {
30752
- import_node_server_utils165.logger.info(`Cache set for key: ${cacheKey}`);
31269
+ import_node_server_utils166.logger.info(`Cache set for key: ${cacheKey}`);
30753
31270
  }).catch((err) => {
30754
- import_node_server_utils165.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31271
+ import_node_server_utils166.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
30755
31272
  });
30756
31273
  return data;
30757
31274
  } catch (error) {
@@ -30762,12 +31279,12 @@ function useEntryPassSettingsRepo() {
30762
31279
  try {
30763
31280
  _id = new import_mongodb93.ObjectId(_id);
30764
31281
  } catch (error) {
30765
- throw new import_node_server_utils165.BadRequestError("Invalid entry pass settings ID format.");
31282
+ throw new import_node_server_utils166.BadRequestError("Invalid entry pass settings ID format.");
30766
31283
  }
30767
- const cacheKey = (0, import_node_server_utils165.makeCacheKey)(namespace_collection, { _id });
31284
+ const cacheKey = (0, import_node_server_utils166.makeCacheKey)(namespace_collection, { _id });
30768
31285
  const cachedData = await getCache(cacheKey);
30769
31286
  if (cachedData) {
30770
- import_node_server_utils165.logger.info(`Cache hit for key: ${cacheKey}`);
31287
+ import_node_server_utils166.logger.info(`Cache hit for key: ${cacheKey}`);
30771
31288
  return cachedData;
30772
31289
  }
30773
31290
  try {
@@ -30813,12 +31330,12 @@ function useEntryPassSettingsRepo() {
30813
31330
  }
30814
31331
  ]).toArray();
30815
31332
  if (!data || !data.length) {
30816
- throw new import_node_server_utils165.NotFoundError("Entry Pass Settings not found.");
31333
+ throw new import_node_server_utils166.NotFoundError("Entry Pass Settings not found.");
30817
31334
  }
30818
31335
  setCache(cacheKey, data[0], 15 * 60).then(() => {
30819
- import_node_server_utils165.logger.info(`Cache set for key: ${cacheKey}`);
31336
+ import_node_server_utils166.logger.info(`Cache set for key: ${cacheKey}`);
30820
31337
  }).catch((err) => {
30821
- import_node_server_utils165.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31338
+ import_node_server_utils166.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
30822
31339
  });
30823
31340
  return data[0];
30824
31341
  } catch (error) {
@@ -30829,7 +31346,7 @@ function useEntryPassSettingsRepo() {
30829
31346
  try {
30830
31347
  _id = new import_mongodb93.ObjectId(_id);
30831
31348
  } catch (error) {
30832
- throw new import_node_server_utils165.BadRequestError("Invalid entry pass settings ID format.");
31349
+ throw new import_node_server_utils166.BadRequestError("Invalid entry pass settings ID format.");
30833
31350
  }
30834
31351
  try {
30835
31352
  const updateValue = {
@@ -30838,12 +31355,12 @@ function useEntryPassSettingsRepo() {
30838
31355
  };
30839
31356
  const res = await collection.updateOne({ _id }, { $set: updateValue });
30840
31357
  if (res.modifiedCount === 0) {
30841
- throw new import_node_server_utils165.InternalServerError("Unable to update entry pass settings.");
31358
+ throw new import_node_server_utils166.InternalServerError("Unable to update entry pass settings.");
30842
31359
  }
30843
31360
  delNamespace().then(() => {
30844
- import_node_server_utils165.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
31361
+ import_node_server_utils166.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30845
31362
  }).catch((err) => {
30846
- import_node_server_utils165.logger.error(
31363
+ import_node_server_utils166.logger.error(
30847
31364
  `Failed to clear cache for namespace: ${namespace_collection}`,
30848
31365
  err
30849
31366
  );
@@ -30857,7 +31374,7 @@ function useEntryPassSettingsRepo() {
30857
31374
  try {
30858
31375
  _id = new import_mongodb93.ObjectId(_id);
30859
31376
  } catch (error) {
30860
- throw new import_node_server_utils165.BadRequestError("Invalid card ID format.");
31377
+ throw new import_node_server_utils166.BadRequestError("Invalid card ID format.");
30861
31378
  }
30862
31379
  try {
30863
31380
  const updateValue = {
@@ -30871,12 +31388,12 @@ function useEntryPassSettingsRepo() {
30871
31388
  { session }
30872
31389
  );
30873
31390
  if (res.modifiedCount === 0) {
30874
- throw new import_node_server_utils165.InternalServerError("Unable to delete entry pass settings.");
31391
+ throw new import_node_server_utils166.InternalServerError("Unable to delete entry pass settings.");
30875
31392
  }
30876
31393
  delNamespace().then(() => {
30877
- import_node_server_utils165.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
31394
+ import_node_server_utils166.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30878
31395
  }).catch((err) => {
30879
- import_node_server_utils165.logger.error(
31396
+ import_node_server_utils166.logger.error(
30880
31397
  `Failed to clear cache for namespace: ${namespace_collection}`,
30881
31398
  err
30882
31399
  );
@@ -30890,12 +31407,12 @@ function useEntryPassSettingsRepo() {
30890
31407
  try {
30891
31408
  site = new import_mongodb93.ObjectId(site);
30892
31409
  } catch (error) {
30893
- throw new import_node_server_utils165.BadRequestError("Invalid entry pass settings ID format.");
31410
+ throw new import_node_server_utils166.BadRequestError("Invalid entry pass settings ID format.");
30894
31411
  }
30895
- const cacheKey = (0, import_node_server_utils165.makeCacheKey)(namespace_collection, { site });
31412
+ const cacheKey = (0, import_node_server_utils166.makeCacheKey)(namespace_collection, { site });
30896
31413
  const cachedData = await getCache(cacheKey);
30897
31414
  if (cachedData) {
30898
- import_node_server_utils165.logger.info(`Cache hit for key: ${cacheKey}`);
31415
+ import_node_server_utils166.logger.info(`Cache hit for key: ${cacheKey}`);
30899
31416
  return cachedData;
30900
31417
  }
30901
31418
  try {
@@ -30941,12 +31458,12 @@ function useEntryPassSettingsRepo() {
30941
31458
  }
30942
31459
  ]).toArray();
30943
31460
  if (!data || !data.length) {
30944
- throw new import_node_server_utils165.NotFoundError("Entry Pass Settings not found.");
31461
+ throw new import_node_server_utils166.NotFoundError("Entry Pass Settings not found.");
30945
31462
  }
30946
31463
  setCache(cacheKey, data[0], 15 * 60).then(() => {
30947
- import_node_server_utils165.logger.info(`Cache set for key: ${cacheKey}`);
31464
+ import_node_server_utils166.logger.info(`Cache set for key: ${cacheKey}`);
30948
31465
  }).catch((err) => {
30949
- import_node_server_utils165.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31466
+ import_node_server_utils166.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
30950
31467
  });
30951
31468
  return data[0];
30952
31469
  } catch (error) {
@@ -30957,7 +31474,7 @@ function useEntryPassSettingsRepo() {
30957
31474
  try {
30958
31475
  site = new import_mongodb93.ObjectId(site);
30959
31476
  } catch (error) {
30960
- throw new import_node_server_utils165.BadRequestError("Invalid entry pass settings ID format.");
31477
+ throw new import_node_server_utils166.BadRequestError("Invalid entry pass settings ID format.");
30961
31478
  }
30962
31479
  try {
30963
31480
  const updateValue = {
@@ -30966,12 +31483,12 @@ function useEntryPassSettingsRepo() {
30966
31483
  };
30967
31484
  const res = await collection.updateOne({ site }, { $set: updateValue });
30968
31485
  if (res.modifiedCount === 0) {
30969
- throw new import_node_server_utils165.InternalServerError("Unable to update entry pass settings.");
31486
+ throw new import_node_server_utils166.InternalServerError("Unable to update entry pass settings.");
30970
31487
  }
30971
31488
  delNamespace().then(() => {
30972
- import_node_server_utils165.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
31489
+ import_node_server_utils166.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30973
31490
  }).catch((err) => {
30974
- import_node_server_utils165.logger.error(
31491
+ import_node_server_utils166.logger.error(
30975
31492
  `Failed to clear cache for namespace: ${namespace_collection}`,
30976
31493
  err
30977
31494
  );
@@ -30994,7 +31511,7 @@ function useEntryPassSettingsRepo() {
30994
31511
  }
30995
31512
 
30996
31513
  // src/controllers/site-entrypass-settings.controller.ts
30997
- var import_node_server_utils166 = require("@7365admin1/node-server-utils");
31514
+ var import_node_server_utils167 = require("@7365admin1/node-server-utils");
30998
31515
  var import_joi95 = __toESM(require("joi"));
30999
31516
  function useEntryPassSettingsController() {
31000
31517
  const {
@@ -31018,8 +31535,8 @@ function useEntryPassSettingsController() {
31018
31535
  });
31019
31536
  if (error) {
31020
31537
  const messages = error.details.map((d) => d.message).join(", ");
31021
- import_node_server_utils166.logger.log({ level: "error", message: messages });
31022
- next(new import_node_server_utils166.BadRequestError(messages));
31538
+ import_node_server_utils167.logger.log({ level: "error", message: messages });
31539
+ next(new import_node_server_utils167.BadRequestError(messages));
31023
31540
  return;
31024
31541
  }
31025
31542
  try {
@@ -31027,7 +31544,7 @@ function useEntryPassSettingsController() {
31027
31544
  res.status(201).json({ message: data });
31028
31545
  return;
31029
31546
  } catch (error2) {
31030
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31547
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31031
31548
  next(error2);
31032
31549
  return;
31033
31550
  }
@@ -31045,8 +31562,8 @@ function useEntryPassSettingsController() {
31045
31562
  query.status = req.query.status;
31046
31563
  const { error } = validation.validate(query);
31047
31564
  if (error) {
31048
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31049
- next(new import_node_server_utils166.BadRequestError(error.message));
31565
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31566
+ next(new import_node_server_utils167.BadRequestError(error.message));
31050
31567
  return;
31051
31568
  }
31052
31569
  const search = req.query.search ?? "";
@@ -31060,7 +31577,7 @@ function useEntryPassSettingsController() {
31060
31577
  res.json(data);
31061
31578
  return;
31062
31579
  } catch (error2) {
31063
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31580
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31064
31581
  next(error2);
31065
31582
  return;
31066
31583
  }
@@ -31070,8 +31587,8 @@ function useEntryPassSettingsController() {
31070
31587
  const _id = req.params.id;
31071
31588
  const { error } = validation.validate(_id);
31072
31589
  if (error) {
31073
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31074
- next(new import_node_server_utils166.BadRequestError(error.message));
31590
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31591
+ next(new import_node_server_utils167.BadRequestError(error.message));
31075
31592
  return;
31076
31593
  }
31077
31594
  try {
@@ -31079,7 +31596,7 @@ function useEntryPassSettingsController() {
31079
31596
  res.json(data);
31080
31597
  return;
31081
31598
  } catch (error2) {
31082
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31599
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31083
31600
  next(error2);
31084
31601
  return;
31085
31602
  }
@@ -31111,8 +31628,8 @@ function useEntryPassSettingsController() {
31111
31628
  const payload = { ...req.body, updatedBy };
31112
31629
  const { error } = validation.validate({ _id, ...payload });
31113
31630
  if (error) {
31114
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31115
- next(new import_node_server_utils166.BadRequestError(error.message));
31631
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31632
+ next(new import_node_server_utils167.BadRequestError(error.message));
31116
31633
  return;
31117
31634
  }
31118
31635
  try {
@@ -31120,7 +31637,7 @@ function useEntryPassSettingsController() {
31120
31637
  res.json({ message: "Successfully updated entry pass settings." });
31121
31638
  return;
31122
31639
  } catch (error2) {
31123
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31640
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31124
31641
  next(error2);
31125
31642
  return;
31126
31643
  }
@@ -31130,8 +31647,8 @@ function useEntryPassSettingsController() {
31130
31647
  const _id = req.params.id;
31131
31648
  const { error } = validation.validate(_id);
31132
31649
  if (error) {
31133
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31134
- next(new import_node_server_utils166.BadRequestError(error.message));
31650
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31651
+ next(new import_node_server_utils167.BadRequestError(error.message));
31135
31652
  return;
31136
31653
  }
31137
31654
  try {
@@ -31139,7 +31656,7 @@ function useEntryPassSettingsController() {
31139
31656
  res.json({ message: "Successfully deleted entry pass settings." });
31140
31657
  return;
31141
31658
  } catch (error2) {
31142
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31659
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31143
31660
  next(error2);
31144
31661
  return;
31145
31662
  }
@@ -31149,8 +31666,8 @@ function useEntryPassSettingsController() {
31149
31666
  const _id = req.params.site;
31150
31667
  const { error } = validation.validate(_id);
31151
31668
  if (error) {
31152
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31153
- next(new import_node_server_utils166.BadRequestError(error.message));
31669
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31670
+ next(new import_node_server_utils167.BadRequestError(error.message));
31154
31671
  return;
31155
31672
  }
31156
31673
  try {
@@ -31158,7 +31675,7 @@ function useEntryPassSettingsController() {
31158
31675
  res.json(data);
31159
31676
  return;
31160
31677
  } catch (error2) {
31161
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31678
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31162
31679
  next(error2);
31163
31680
  return;
31164
31681
  }
@@ -31189,8 +31706,8 @@ function useEntryPassSettingsController() {
31189
31706
  const payload = { ...req.body, updatedBy };
31190
31707
  const { error } = validation.validate({ ...payload });
31191
31708
  if (error) {
31192
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31193
- next(new import_node_server_utils166.BadRequestError(error.message));
31709
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31710
+ next(new import_node_server_utils167.BadRequestError(error.message));
31194
31711
  return;
31195
31712
  }
31196
31713
  try {
@@ -31198,7 +31715,7 @@ function useEntryPassSettingsController() {
31198
31715
  res.json({ message: "Successfully updated entry pass settings." });
31199
31716
  return;
31200
31717
  } catch (error2) {
31201
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31718
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31202
31719
  next(error2);
31203
31720
  return;
31204
31721
  }
@@ -31215,17 +31732,17 @@ function useEntryPassSettingsController() {
31215
31732
  }
31216
31733
 
31217
31734
  // src/repositories/dashboard.repo.ts
31218
- var import_node_server_utils167 = require("@7365admin1/node-server-utils");
31735
+ var import_node_server_utils168 = require("@7365admin1/node-server-utils");
31219
31736
  function useDashboardRepo() {
31220
- const db = import_node_server_utils167.useAtlas.getDb();
31737
+ const db = import_node_server_utils168.useAtlas.getDb();
31221
31738
  if (!db) {
31222
- throw new import_node_server_utils167.InternalServerError("Unable to connect to server.");
31739
+ throw new import_node_server_utils168.InternalServerError("Unable to connect to server.");
31223
31740
  }
31224
31741
  const feedback_collection = db.collection("feedbacks");
31225
31742
  const work_order_collection = db.collection("work-orders");
31226
31743
  const visitor_collection = db.collection("visitor.transactions");
31227
31744
  const namespace_collection = "dashboard";
31228
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils167.useCache)(namespace_collection);
31745
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils168.useCache)(namespace_collection);
31229
31746
  async function getAll({
31230
31747
  site = ""
31231
31748
  }, session) {
@@ -31236,10 +31753,10 @@ function useDashboardRepo() {
31236
31753
  const cacheOptions = {
31237
31754
  site: site.toString()
31238
31755
  };
31239
- const cacheKey = (0, import_node_server_utils167.makeCacheKey)(namespace_collection, cacheOptions);
31756
+ const cacheKey = (0, import_node_server_utils168.makeCacheKey)(namespace_collection, cacheOptions);
31240
31757
  const cachedData = await getCache(cacheKey);
31241
31758
  if (cachedData) {
31242
- import_node_server_utils167.logger.info(`Cache hit for key: ${cacheKey}`);
31759
+ import_node_server_utils168.logger.info(`Cache hit for key: ${cacheKey}`);
31243
31760
  return cachedData;
31244
31761
  }
31245
31762
  try {
@@ -31262,9 +31779,9 @@ function useDashboardRepo() {
31262
31779
  incidentReport: null
31263
31780
  };
31264
31781
  setCache(cacheKey, data, 10).then(() => {
31265
- import_node_server_utils167.logger.info(`Cache set for key: ${cacheKey}`);
31782
+ import_node_server_utils168.logger.info(`Cache set for key: ${cacheKey}`);
31266
31783
  }).catch((err) => {
31267
- import_node_server_utils167.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31784
+ import_node_server_utils168.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31268
31785
  });
31269
31786
  return data;
31270
31787
  } catch (error) {
@@ -31277,7 +31794,7 @@ function useDashboardRepo() {
31277
31794
  }
31278
31795
 
31279
31796
  // src/controllers/dashboard.controller.ts
31280
- var import_node_server_utils168 = require("@7365admin1/node-server-utils");
31797
+ var import_node_server_utils169 = require("@7365admin1/node-server-utils");
31281
31798
  var import_joi96 = __toESM(require("joi"));
31282
31799
  function useDashboardController() {
31283
31800
  const { getAll: _getAll } = useDashboardRepo();
@@ -31291,8 +31808,8 @@ function useDashboardController() {
31291
31808
  });
31292
31809
  if (error) {
31293
31810
  const messages = error.details.map((d) => d.message).join(", ");
31294
- import_node_server_utils168.logger.log({ level: "error", message: messages });
31295
- next(new import_node_server_utils168.BadRequestError(messages));
31811
+ import_node_server_utils169.logger.log({ level: "error", message: messages });
31812
+ next(new import_node_server_utils169.BadRequestError(messages));
31296
31813
  return;
31297
31814
  }
31298
31815
  const site = req.query.site ?? "";
@@ -31303,7 +31820,7 @@ function useDashboardController() {
31303
31820
  res.status(200).json(data);
31304
31821
  return;
31305
31822
  } catch (error2) {
31306
- import_node_server_utils168.logger.log({ level: "error", message: error2.message });
31823
+ import_node_server_utils169.logger.log({ level: "error", message: error2.message });
31307
31824
  next(error2);
31308
31825
  return;
31309
31826
  }
@@ -31316,7 +31833,7 @@ function useDashboardController() {
31316
31833
  // src/models/nfc-patrol-route.model.ts
31317
31834
  var import_mongodb94 = require("mongodb");
31318
31835
  var import_joi97 = __toESM(require("joi"));
31319
- var import_node_server_utils169 = require("@7365admin1/node-server-utils");
31836
+ var import_node_server_utils170 = require("@7365admin1/node-server-utils");
31320
31837
  var schemaNfcPatrolRoute = import_joi97.default.object({
31321
31838
  _id: import_joi97.default.string().length(24).hex().optional().allow(null, ""),
31322
31839
  site: import_joi97.default.string().length(24).hex().required(),
@@ -31345,25 +31862,25 @@ var schemaNfcPatrolRoute = import_joi97.default.object({
31345
31862
  function MNfcPatrolRoute(value) {
31346
31863
  const { error } = schemaNfcPatrolRoute.validate(value);
31347
31864
  if (error) {
31348
- import_node_server_utils169.logger.info(`NFC Patrol Route Model: ${error.message}`);
31349
- throw new import_node_server_utils169.BadRequestError(error.message);
31865
+ import_node_server_utils170.logger.info(`NFC Patrol Route Model: ${error.message}`);
31866
+ throw new import_node_server_utils170.BadRequestError(error.message);
31350
31867
  }
31351
31868
  if (value._id && typeof value._id === "string") {
31352
31869
  try {
31353
31870
  value._id = new import_mongodb94.ObjectId(value._id);
31354
31871
  } catch (error2) {
31355
- throw new import_node_server_utils169.BadRequestError("Invalid _id format");
31872
+ throw new import_node_server_utils170.BadRequestError("Invalid _id format");
31356
31873
  }
31357
31874
  }
31358
31875
  try {
31359
31876
  value.site = new import_mongodb94.ObjectId(value.site);
31360
31877
  } catch (error2) {
31361
- throw new import_node_server_utils169.BadRequestError("Invalid site format");
31878
+ throw new import_node_server_utils170.BadRequestError("Invalid site format");
31362
31879
  }
31363
31880
  try {
31364
31881
  value.createdBy = new import_mongodb94.ObjectId(value.createdBy);
31365
31882
  } catch (error2) {
31366
- throw new import_node_server_utils169.BadRequestError("Invalid createdBy format");
31883
+ throw new import_node_server_utils170.BadRequestError("Invalid createdBy format");
31367
31884
  }
31368
31885
  return {
31369
31886
  _id: value._id ?? new import_mongodb94.ObjectId(),
@@ -31381,16 +31898,16 @@ function MNfcPatrolRoute(value) {
31381
31898
  }
31382
31899
 
31383
31900
  // src/repositories/nfc-patrol-route.repository.ts
31384
- var import_node_server_utils170 = require("@7365admin1/node-server-utils");
31901
+ var import_node_server_utils171 = require("@7365admin1/node-server-utils");
31385
31902
  var import_mongodb95 = require("mongodb");
31386
31903
  function useNfcPatrolRouteRepo() {
31387
- const db = import_node_server_utils170.useAtlas.getDb();
31904
+ const db = import_node_server_utils171.useAtlas.getDb();
31388
31905
  if (!db) {
31389
- throw new import_node_server_utils170.InternalServerError("Unable to connect to server.");
31906
+ throw new import_node_server_utils171.InternalServerError("Unable to connect to server.");
31390
31907
  }
31391
31908
  const namespace_collection = "nfc-patrol-routes";
31392
31909
  const collection = db.collection(namespace_collection);
31393
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils170.useCache)(namespace_collection);
31910
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils171.useCache)(namespace_collection);
31394
31911
  async function createIndexes() {
31395
31912
  try {
31396
31913
  await collection.createIndexes([
@@ -31398,7 +31915,7 @@ function useNfcPatrolRouteRepo() {
31398
31915
  { key: { name: "text" }, name: "text-index" }
31399
31916
  ]);
31400
31917
  } catch (error) {
31401
- throw new import_node_server_utils170.InternalServerError(
31918
+ throw new import_node_server_utils171.InternalServerError(
31402
31919
  `Failed to create index on ${namespace_collection}.`
31403
31920
  );
31404
31921
  }
@@ -31412,7 +31929,7 @@ function useNfcPatrolRouteRepo() {
31412
31929
  } catch (error) {
31413
31930
  const isDuplicated = error.message.includes("duplicate");
31414
31931
  if (isDuplicated) {
31415
- throw new import_node_server_utils170.BadRequestError("NFC Patrol Route Name already exists.");
31932
+ throw new import_node_server_utils171.BadRequestError("NFC Patrol Route Name already exists.");
31416
31933
  }
31417
31934
  throw error;
31418
31935
  }
@@ -31428,7 +31945,7 @@ function useNfcPatrolRouteRepo() {
31428
31945
  try {
31429
31946
  site = new import_mongodb95.ObjectId(site);
31430
31947
  } catch (error) {
31431
- throw new import_node_server_utils170.BadRequestError("Invalid site ID format.");
31948
+ throw new import_node_server_utils171.BadRequestError("Invalid site ID format.");
31432
31949
  }
31433
31950
  const query = {
31434
31951
  site
@@ -31456,10 +31973,10 @@ function useNfcPatrolRouteRepo() {
31456
31973
  cacheOptions.search = search;
31457
31974
  if (filter)
31458
31975
  cacheOptions.filter = filter;
31459
- const cacheKey = (0, import_node_server_utils170.makeCacheKey)(namespace_collection, cacheOptions);
31976
+ const cacheKey = (0, import_node_server_utils171.makeCacheKey)(namespace_collection, cacheOptions);
31460
31977
  const cachedData = await getCache(cacheKey);
31461
31978
  if (cachedData) {
31462
- import_node_server_utils170.logger.info(`Cache hit for key: ${cacheKey}`);
31979
+ import_node_server_utils171.logger.info(`Cache hit for key: ${cacheKey}`);
31463
31980
  return cachedData;
31464
31981
  }
31465
31982
  try {
@@ -31484,11 +32001,11 @@ function useNfcPatrolRouteRepo() {
31484
32001
  { session }
31485
32002
  ).toArray();
31486
32003
  const length = await collection.countDocuments(query, { session });
31487
- const data = (0, import_node_server_utils170.paginate)(items, page, limit, length);
32004
+ const data = (0, import_node_server_utils171.paginate)(items, page, limit, length);
31488
32005
  setCache(cacheKey, data, 15 * 60).then(() => {
31489
- import_node_server_utils170.logger.info(`Cache set for key: ${cacheKey}`);
32006
+ import_node_server_utils171.logger.info(`Cache set for key: ${cacheKey}`);
31490
32007
  }).catch((err) => {
31491
- import_node_server_utils170.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32008
+ import_node_server_utils171.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31492
32009
  });
31493
32010
  return data;
31494
32011
  } catch (error) {
@@ -31499,7 +32016,7 @@ function useNfcPatrolRouteRepo() {
31499
32016
  try {
31500
32017
  _id = new import_mongodb95.ObjectId(_id);
31501
32018
  } catch (error) {
31502
- throw new import_node_server_utils170.BadRequestError("Invalid ID.");
32019
+ throw new import_node_server_utils171.BadRequestError("Invalid ID.");
31503
32020
  }
31504
32021
  const cacheParams = {
31505
32022
  _id: String(_id)
@@ -31507,11 +32024,11 @@ function useNfcPatrolRouteRepo() {
31507
32024
  if (isStart === true) {
31508
32025
  cacheParams.isStart = true;
31509
32026
  }
31510
- const cacheKey = (0, import_node_server_utils170.makeCacheKey)(namespace_collection, cacheParams);
32027
+ const cacheKey = (0, import_node_server_utils171.makeCacheKey)(namespace_collection, cacheParams);
31511
32028
  try {
31512
32029
  const cached = await getCache(cacheKey);
31513
32030
  if (cached) {
31514
- import_node_server_utils170.logger.log({
32031
+ import_node_server_utils171.logger.log({
31515
32032
  level: "info",
31516
32033
  message: `Cache hit for getById ${namespace_collection}: ${cacheKey}`
31517
32034
  });
@@ -31579,22 +32096,22 @@ function useNfcPatrolRouteRepo() {
31579
32096
  result = await collection.findOne({ _id });
31580
32097
  }
31581
32098
  setCache(cacheKey, result, 300).then(() => {
31582
- import_node_server_utils170.logger.log({
32099
+ import_node_server_utils171.logger.log({
31583
32100
  level: "info",
31584
32101
  message: `Cache set for ${namespace_collection} by id: ${cacheKey}`
31585
32102
  });
31586
32103
  }).catch((err) => {
31587
- import_node_server_utils170.logger.log({
32104
+ import_node_server_utils171.logger.log({
31588
32105
  level: "error",
31589
32106
  message: `Failed to set cache for ${namespace_collection} by id: ${err.message}`
31590
32107
  });
31591
32108
  });
31592
32109
  return result;
31593
32110
  } catch (error) {
31594
- if (error instanceof import_node_server_utils170.AppError) {
32111
+ if (error instanceof import_node_server_utils171.AppError) {
31595
32112
  throw error;
31596
32113
  } else {
31597
- throw new import_node_server_utils170.InternalServerError(
32114
+ throw new import_node_server_utils171.InternalServerError(
31598
32115
  `Failed to get ${namespace_collection} by id.`
31599
32116
  );
31600
32117
  }
@@ -31603,24 +32120,24 @@ function useNfcPatrolRouteRepo() {
31603
32120
  async function updateById(_id, value, session) {
31604
32121
  const { error } = schemaNfcPatrolRoute.validate(value);
31605
32122
  if (error) {
31606
- import_node_server_utils170.logger.info(`NFC Patrol Route Repository: ${error.message}`);
31607
- throw new import_node_server_utils170.BadRequestError(error.message);
32123
+ import_node_server_utils171.logger.info(`NFC Patrol Route Repository: ${error.message}`);
32124
+ throw new import_node_server_utils171.BadRequestError(error.message);
31608
32125
  }
31609
32126
  try {
31610
32127
  _id = new import_mongodb95.ObjectId(_id);
31611
32128
  } catch (error2) {
31612
- throw new import_node_server_utils170.BadRequestError("Invalid ID.");
32129
+ throw new import_node_server_utils171.BadRequestError("Invalid ID.");
31613
32130
  }
31614
32131
  try {
31615
32132
  value.site = new import_mongodb95.ObjectId(value.site);
31616
32133
  } catch (error2) {
31617
- throw new import_node_server_utils170.BadRequestError("Invalid site format");
32134
+ throw new import_node_server_utils171.BadRequestError("Invalid site format");
31618
32135
  }
31619
32136
  if (value.updatedBy) {
31620
32137
  try {
31621
32138
  value.updatedBy = new import_mongodb95.ObjectId(value.updatedBy);
31622
32139
  } catch (error2) {
31623
- throw new import_node_server_utils170.BadRequestError("Invalid createdBy format");
32140
+ throw new import_node_server_utils171.BadRequestError("Invalid createdBy format");
31624
32141
  }
31625
32142
  }
31626
32143
  value.updatedAt = /* @__PURE__ */ new Date();
@@ -31632,19 +32149,19 @@ function useNfcPatrolRouteRepo() {
31632
32149
  );
31633
32150
  delCachedData();
31634
32151
  if (res.modifiedCount === 0) {
31635
- throw new import_node_server_utils170.BadRequestError("NFC Patrol Route not found.");
32152
+ throw new import_node_server_utils171.BadRequestError("NFC Patrol Route not found.");
31636
32153
  }
31637
32154
  return res;
31638
32155
  } catch (error2) {
31639
- import_node_server_utils170.logger.log({
32156
+ import_node_server_utils171.logger.log({
31640
32157
  level: "error",
31641
32158
  message: error2.message
31642
32159
  });
31643
32160
  const isDuplicated = error2.message.includes("duplicate");
31644
32161
  if (isDuplicated) {
31645
- throw new import_node_server_utils170.BadRequestError("NFC Patrol Route already exists.");
32162
+ throw new import_node_server_utils171.BadRequestError("NFC Patrol Route already exists.");
31646
32163
  }
31647
- if (error2 instanceof import_node_server_utils170.AppError) {
32164
+ if (error2 instanceof import_node_server_utils171.AppError) {
31648
32165
  throw error2;
31649
32166
  } else {
31650
32167
  throw new Error("Failed to update NFC Patrol Route.");
@@ -31653,12 +32170,12 @@ function useNfcPatrolRouteRepo() {
31653
32170
  }
31654
32171
  function delCachedData() {
31655
32172
  delNamespace().then(() => {
31656
- import_node_server_utils170.logger.log({
32173
+ import_node_server_utils171.logger.log({
31657
32174
  level: "info",
31658
32175
  message: `Cache namespace cleared for ${namespace_collection}`
31659
32176
  });
31660
32177
  }).catch((err) => {
31661
- import_node_server_utils170.logger.log({
32178
+ import_node_server_utils171.logger.log({
31662
32179
  level: "error",
31663
32180
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
31664
32181
  });
@@ -31674,11 +32191,11 @@ function useNfcPatrolRouteRepo() {
31674
32191
  }
31675
32192
 
31676
32193
  // src/services/nfc-patrol-route.service.ts
31677
- var import_node_server_utils171 = require("@7365admin1/node-server-utils");
32194
+ var import_node_server_utils172 = require("@7365admin1/node-server-utils");
31678
32195
  function useNfcPatrolRouteService() {
31679
32196
  const { add: _add, updateById: _updateById } = useNfcPatrolRouteRepo();
31680
32197
  async function add(value) {
31681
- const session = import_node_server_utils171.useAtlas.getClient()?.startSession();
32198
+ const session = import_node_server_utils172.useAtlas.getClient()?.startSession();
31682
32199
  session?.startTransaction();
31683
32200
  try {
31684
32201
  await _add(value, session);
@@ -31692,9 +32209,9 @@ function useNfcPatrolRouteService() {
31692
32209
  }
31693
32210
  }
31694
32211
  async function updateById(id, data) {
31695
- const session = import_node_server_utils171.useAtlas.getClient()?.startSession();
32212
+ const session = import_node_server_utils172.useAtlas.getClient()?.startSession();
31696
32213
  if (!session) {
31697
- throw new import_node_server_utils171.BadRequestError("Database session not available.");
32214
+ throw new import_node_server_utils172.BadRequestError("Database session not available.");
31698
32215
  }
31699
32216
  try {
31700
32217
  await session.startTransaction();
@@ -31702,7 +32219,7 @@ function useNfcPatrolRouteService() {
31702
32219
  await session.commitTransaction();
31703
32220
  return "Successfully updated NFC Patrol Route.";
31704
32221
  } catch (error) {
31705
- import_node_server_utils171.logger.log({
32222
+ import_node_server_utils172.logger.log({
31706
32223
  level: "error",
31707
32224
  message: `Failed to update NFC Patrol Route: ${error.message}`
31708
32225
  });
@@ -31719,7 +32236,7 @@ function useNfcPatrolRouteService() {
31719
32236
  }
31720
32237
 
31721
32238
  // src/controllers/nfc-patrol-route.controller.ts
31722
- var import_node_server_utils172 = require("@7365admin1/node-server-utils");
32239
+ var import_node_server_utils173 = require("@7365admin1/node-server-utils");
31723
32240
  var import_joi98 = __toESM(require("joi"));
31724
32241
  function useNfcPatrolRouteController() {
31725
32242
  const { add: _add, updateById: _updateById } = useNfcPatrolRouteService();
@@ -31736,8 +32253,8 @@ function useNfcPatrolRouteController() {
31736
32253
  });
31737
32254
  if (error) {
31738
32255
  const messages = error.details.map((d) => d.message).join(", ");
31739
- import_node_server_utils172.logger.log({ level: "error", message: messages });
31740
- next(new import_node_server_utils172.BadRequestError(messages));
32256
+ import_node_server_utils173.logger.log({ level: "error", message: messages });
32257
+ next(new import_node_server_utils173.BadRequestError(messages));
31741
32258
  return;
31742
32259
  }
31743
32260
  try {
@@ -31745,7 +32262,7 @@ function useNfcPatrolRouteController() {
31745
32262
  res.status(201).json(data);
31746
32263
  return;
31747
32264
  } catch (error2) {
31748
- import_node_server_utils172.logger.log({ level: "error", message: error2.message });
32265
+ import_node_server_utils173.logger.log({ level: "error", message: error2.message });
31749
32266
  next(error2);
31750
32267
  return;
31751
32268
  }
@@ -31764,8 +32281,8 @@ function useNfcPatrolRouteController() {
31764
32281
  });
31765
32282
  if (error) {
31766
32283
  const messages = error.details.map((d) => d.message).join(", ");
31767
- import_node_server_utils172.logger.log({ level: "error", message: messages });
31768
- next(new import_node_server_utils172.BadRequestError(messages));
32284
+ import_node_server_utils173.logger.log({ level: "error", message: messages });
32285
+ next(new import_node_server_utils173.BadRequestError(messages));
31769
32286
  return;
31770
32287
  }
31771
32288
  const page = parseInt(req.query.page ?? "1");
@@ -31784,7 +32301,7 @@ function useNfcPatrolRouteController() {
31784
32301
  res.status(200).json(data);
31785
32302
  return;
31786
32303
  } catch (error2) {
31787
- import_node_server_utils172.logger.log({ level: "error", message: error2.message });
32304
+ import_node_server_utils173.logger.log({ level: "error", message: error2.message });
31788
32305
  next(error2);
31789
32306
  return;
31790
32307
  }
@@ -31801,13 +32318,13 @@ function useNfcPatrolRouteController() {
31801
32318
  { convert: true }
31802
32319
  );
31803
32320
  if (error) {
31804
- next(new import_node_server_utils172.BadRequestError(error.message));
32321
+ next(new import_node_server_utils173.BadRequestError(error.message));
31805
32322
  return;
31806
32323
  }
31807
32324
  try {
31808
32325
  const nfcPatrolRoute = await _getById(value?.id, value?.isStart);
31809
32326
  if (!nfcPatrolRoute) {
31810
- throw new import_node_server_utils172.NotFoundError("NFC Patrol Route not found.");
32327
+ throw new import_node_server_utils173.NotFoundError("NFC Patrol Route not found.");
31811
32328
  }
31812
32329
  res.json({
31813
32330
  message: "Successfully retrieved nfc patrol route.",
@@ -32104,21 +32621,21 @@ function MIncidentReport(value) {
32104
32621
  }
32105
32622
 
32106
32623
  // src/services/incident-report.service.ts
32107
- var import_node_server_utils174 = require("@7365admin1/node-server-utils");
32624
+ var import_node_server_utils175 = require("@7365admin1/node-server-utils");
32108
32625
 
32109
32626
  // src/repositories/incident-report.repo.ts
32110
- var import_node_server_utils173 = require("@7365admin1/node-server-utils");
32627
+ var import_node_server_utils174 = require("@7365admin1/node-server-utils");
32111
32628
  var import_mongodb97 = require("mongodb");
32112
32629
  function useIncidentReportRepo() {
32113
- const db = import_node_server_utils173.useAtlas.getDb();
32630
+ const db = import_node_server_utils174.useAtlas.getDb();
32114
32631
  if (!db) {
32115
- throw new import_node_server_utils173.InternalServerError("Unable to connect to server.");
32632
+ throw new import_node_server_utils174.InternalServerError("Unable to connect to server.");
32116
32633
  }
32117
32634
  async function createIndexes() {
32118
32635
  try {
32119
32636
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
32120
32637
  } catch (error) {
32121
- throw new import_node_server_utils173.InternalServerError(
32638
+ throw new import_node_server_utils174.InternalServerError(
32122
32639
  "Failed to create index on bulletin videos."
32123
32640
  );
32124
32641
  }
@@ -32130,22 +32647,22 @@ function useIncidentReportRepo() {
32130
32647
  "incidentInformation.incidentTypeAndTime.typeOfIncident": "text"
32131
32648
  });
32132
32649
  } catch (error) {
32133
- throw new import_node_server_utils173.InternalServerError(
32650
+ throw new import_node_server_utils174.InternalServerError(
32134
32651
  "Failed to create text index on event management."
32135
32652
  );
32136
32653
  }
32137
32654
  }
32138
32655
  const namespace_collection = "incident-reports";
32139
32656
  const collection = db.collection(namespace_collection);
32140
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils173.useCache)(namespace_collection);
32657
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils174.useCache)(namespace_collection);
32141
32658
  async function add(value, session) {
32142
32659
  try {
32143
32660
  value = MIncidentReport(value);
32144
32661
  const res = await collection.insertOne(value, { session });
32145
32662
  delNamespace().then(() => {
32146
- import_node_server_utils173.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32663
+ import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32147
32664
  }).catch((err) => {
32148
- import_node_server_utils173.logger.error(
32665
+ import_node_server_utils174.logger.error(
32149
32666
  `Failed to clear cache for namespace: ${namespace_collection}`,
32150
32667
  err
32151
32668
  );
@@ -32154,7 +32671,7 @@ function useIncidentReportRepo() {
32154
32671
  } catch (error) {
32155
32672
  const isDuplicated = error.message.includes("duplicate");
32156
32673
  if (isDuplicated) {
32157
- throw new import_node_server_utils173.BadRequestError("Incident report already exists.");
32674
+ throw new import_node_server_utils174.BadRequestError("Incident report already exists.");
32158
32675
  }
32159
32676
  throw error;
32160
32677
  }
@@ -32173,7 +32690,7 @@ function useIncidentReportRepo() {
32173
32690
  try {
32174
32691
  site = new import_mongodb97.ObjectId(site);
32175
32692
  } catch (error) {
32176
- throw new import_node_server_utils173.BadRequestError("Invalid site ID format.");
32693
+ throw new import_node_server_utils174.BadRequestError("Invalid site ID format.");
32177
32694
  }
32178
32695
  if (dateFrom) {
32179
32696
  const startDate = new Date(dateFrom);
@@ -32229,10 +32746,10 @@ function useIncidentReportRepo() {
32229
32746
  if (search) {
32230
32747
  cacheOptions.search = search;
32231
32748
  }
32232
- const cacheKey = (0, import_node_server_utils173.makeCacheKey)(namespace_collection, cacheOptions);
32749
+ const cacheKey = (0, import_node_server_utils174.makeCacheKey)(namespace_collection, cacheOptions);
32233
32750
  const cachedData = await getCache(cacheKey);
32234
32751
  if (cachedData) {
32235
- import_node_server_utils173.logger.info(`Cache hit for key: ${cacheKey}`);
32752
+ import_node_server_utils174.logger.info(`Cache hit for key: ${cacheKey}`);
32236
32753
  return cachedData;
32237
32754
  }
32238
32755
  try {
@@ -32246,11 +32763,11 @@ function useIncidentReportRepo() {
32246
32763
  { session }
32247
32764
  ).toArray();
32248
32765
  const length = await collection.countDocuments(query, { session });
32249
- const data = (0, import_node_server_utils173.paginate)(items, page, limit, length);
32766
+ const data = (0, import_node_server_utils174.paginate)(items, page, limit, length);
32250
32767
  setCache(cacheKey, data, 15 * 60).then(() => {
32251
- import_node_server_utils173.logger.info(`Cache set for key: ${cacheKey}`);
32768
+ import_node_server_utils174.logger.info(`Cache set for key: ${cacheKey}`);
32252
32769
  }).catch((err) => {
32253
- import_node_server_utils173.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32770
+ import_node_server_utils174.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32254
32771
  });
32255
32772
  return data;
32256
32773
  } catch (error) {
@@ -32261,12 +32778,12 @@ function useIncidentReportRepo() {
32261
32778
  try {
32262
32779
  _id = new import_mongodb97.ObjectId(_id);
32263
32780
  } catch (error) {
32264
- throw new import_node_server_utils173.BadRequestError("Invalid incident report ID format.");
32781
+ throw new import_node_server_utils174.BadRequestError("Invalid incident report ID format.");
32265
32782
  }
32266
- const cacheKey = (0, import_node_server_utils173.makeCacheKey)(namespace_collection, { _id });
32783
+ const cacheKey = (0, import_node_server_utils174.makeCacheKey)(namespace_collection, { _id });
32267
32784
  const cachedData = await getCache(cacheKey);
32268
32785
  if (cachedData) {
32269
- import_node_server_utils173.logger.info(`Cache hit for key: ${cacheKey}`);
32786
+ import_node_server_utils174.logger.info(`Cache hit for key: ${cacheKey}`);
32270
32787
  return cachedData;
32271
32788
  }
32272
32789
  try {
@@ -32275,12 +32792,12 @@ function useIncidentReportRepo() {
32275
32792
  { session }
32276
32793
  );
32277
32794
  if (!data) {
32278
- throw new import_node_server_utils173.NotFoundError("Incident report not found.");
32795
+ throw new import_node_server_utils174.NotFoundError("Incident report not found.");
32279
32796
  }
32280
32797
  setCache(cacheKey, data, 15 * 60).then(() => {
32281
- import_node_server_utils173.logger.info(`Cache set for key: ${cacheKey}`);
32798
+ import_node_server_utils174.logger.info(`Cache set for key: ${cacheKey}`);
32282
32799
  }).catch((err) => {
32283
- import_node_server_utils173.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32800
+ import_node_server_utils174.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32284
32801
  });
32285
32802
  return data;
32286
32803
  } catch (error) {
@@ -32292,7 +32809,7 @@ function useIncidentReportRepo() {
32292
32809
  try {
32293
32810
  _id = new import_mongodb97.ObjectId(_id);
32294
32811
  } catch (error) {
32295
- throw new import_node_server_utils173.BadRequestError("Invalid ID format.");
32812
+ throw new import_node_server_utils174.BadRequestError("Invalid ID format.");
32296
32813
  }
32297
32814
  if (value.organization && typeof value.organization === "string") {
32298
32815
  try {
@@ -32332,14 +32849,14 @@ function useIncidentReportRepo() {
32332
32849
  { session }
32333
32850
  );
32334
32851
  if (res.modifiedCount === 0) {
32335
- throw new import_node_server_utils173.InternalServerError(
32852
+ throw new import_node_server_utils174.InternalServerError(
32336
32853
  "Unable to update daily occurrence Subject."
32337
32854
  );
32338
32855
  }
32339
32856
  delNamespace().then(() => {
32340
- import_node_server_utils173.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32857
+ import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32341
32858
  }).catch((err) => {
32342
- import_node_server_utils173.logger.error(
32859
+ import_node_server_utils174.logger.error(
32343
32860
  `Failed to clear cache for namespace: ${namespace_collection}`,
32344
32861
  err
32345
32862
  );
@@ -32353,7 +32870,7 @@ function useIncidentReportRepo() {
32353
32870
  try {
32354
32871
  _id = new import_mongodb97.ObjectId(_id);
32355
32872
  } catch (error) {
32356
- throw new import_node_server_utils173.BadRequestError("Invalid occurrence subject ID format.");
32873
+ throw new import_node_server_utils174.BadRequestError("Invalid occurrence subject ID format.");
32357
32874
  }
32358
32875
  try {
32359
32876
  const updateValue = {
@@ -32363,12 +32880,12 @@ function useIncidentReportRepo() {
32363
32880
  };
32364
32881
  const res = await collection.updateOne({ _id }, { $set: updateValue });
32365
32882
  if (res.modifiedCount === 0) {
32366
- throw new import_node_server_utils173.InternalServerError("Unable to delete occurrence subject.");
32883
+ throw new import_node_server_utils174.InternalServerError("Unable to delete occurrence subject.");
32367
32884
  }
32368
32885
  delNamespace().then(() => {
32369
- import_node_server_utils173.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32886
+ import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32370
32887
  }).catch((err) => {
32371
- import_node_server_utils173.logger.error(
32888
+ import_node_server_utils174.logger.error(
32372
32889
  `Failed to clear cache for namespace: ${namespace_collection}`,
32373
32890
  err
32374
32891
  );
@@ -32383,7 +32900,7 @@ function useIncidentReportRepo() {
32383
32900
  try {
32384
32901
  _id = new import_mongodb97.ObjectId(_id);
32385
32902
  } catch (error) {
32386
- throw new import_node_server_utils173.BadRequestError("Invalid ID format.");
32903
+ throw new import_node_server_utils174.BadRequestError("Invalid ID format.");
32387
32904
  }
32388
32905
  try {
32389
32906
  const res = await collection.updateOne(
@@ -32392,14 +32909,14 @@ function useIncidentReportRepo() {
32392
32909
  { session }
32393
32910
  );
32394
32911
  if (res.modifiedCount === 0) {
32395
- throw new import_node_server_utils173.InternalServerError(
32912
+ throw new import_node_server_utils174.InternalServerError(
32396
32913
  `Unable to ${value.status} incident report.`
32397
32914
  );
32398
32915
  }
32399
32916
  delNamespace().then(() => {
32400
- import_node_server_utils173.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32917
+ import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32401
32918
  }).catch((err) => {
32402
- import_node_server_utils173.logger.error(
32919
+ import_node_server_utils174.logger.error(
32403
32920
  `Failed to clear cache for namespace: ${namespace_collection}`,
32404
32921
  err
32405
32922
  );
@@ -32440,7 +32957,7 @@ function useIncidentReportService() {
32440
32957
  const { getById: _getOrganizationById } = useOrgRepo();
32441
32958
  const { deleteFile } = useFileService();
32442
32959
  async function add(value) {
32443
- const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
32960
+ const session = import_node_server_utils175.useAtlas.getClient()?.startSession();
32444
32961
  session?.startTransaction();
32445
32962
  try {
32446
32963
  if (value.incidentInformation.siteInfo.site) {
@@ -32465,7 +32982,7 @@ function useIncidentReportService() {
32465
32982
  session
32466
32983
  );
32467
32984
  if (!file) {
32468
- throw new import_node_server_utils174.NotFoundError("File not found.");
32985
+ throw new import_node_server_utils175.NotFoundError("File not found.");
32469
32986
  }
32470
32987
  }
32471
32988
  }
@@ -32480,7 +32997,7 @@ function useIncidentReportService() {
32480
32997
  }
32481
32998
  }
32482
32999
  async function updateIncidentReportById(id, value) {
32483
- const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
33000
+ const session = import_node_server_utils175.useAtlas.getClient()?.startSession();
32484
33001
  session?.startTransaction();
32485
33002
  try {
32486
33003
  const incidentReport = await _getIncidentReportById(id);
@@ -32514,7 +33031,7 @@ function useIncidentReportService() {
32514
33031
  }
32515
33032
  }
32516
33033
  async function createIncidentSummary(value) {
32517
- const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
33034
+ const session = import_node_server_utils175.useAtlas.getClient()?.startSession();
32518
33035
  session?.startTransaction();
32519
33036
  const sample = `On August 4, 2024, an incident report labeled IR10 was submitted following an earthquake that occurred between 10:00 AM and 10:30 AM at a designated test site. The report indicated that the incident was reported by a complainant named Maryam, who provided her contact information as +65-123456789. The recipient of the complaint was Rash, whose contact number is +65-987654321. The description of the complaint detailed a historical context regarding the origins of Lorem Ipsum text, an academic piece that has been referenced throughout centuries.
32520
33037
  ' +
@@ -32565,13 +33082,13 @@ function useIncidentReportService() {
32565
33082
  }
32566
33083
  }
32567
33084
  async function reviewIncidentReport(id, value) {
32568
- const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
33085
+ const session = import_node_server_utils175.useAtlas.getClient()?.startSession();
32569
33086
  session?.startTransaction();
32570
33087
  try {
32571
33088
  if (value.approvedBy) {
32572
33089
  const approvedBy = await getUserById(value.approvedBy);
32573
33090
  if (!approvedBy || !approvedBy.name)
32574
- throw new import_node_server_utils174.BadRequestError("Created by not found.");
33091
+ throw new import_node_server_utils175.BadRequestError("Created by not found.");
32575
33092
  value.approvedByName = approvedBy.name;
32576
33093
  value.approvedBy = approvedBy._id;
32577
33094
  }
@@ -32594,7 +33111,7 @@ function useIncidentReportService() {
32594
33111
  }
32595
33112
 
32596
33113
  // src/controllers/incident-report.controller.ts
32597
- var import_node_server_utils175 = require("@7365admin1/node-server-utils");
33114
+ var import_node_server_utils176 = require("@7365admin1/node-server-utils");
32598
33115
  var import_joi100 = __toESM(require("joi"));
32599
33116
  function useIncidentReportController() {
32600
33117
  const {
@@ -32615,8 +33132,8 @@ function useIncidentReportController() {
32615
33132
  });
32616
33133
  if (error) {
32617
33134
  const messages = error.details.map((d) => d.message).join(", ");
32618
- import_node_server_utils175.logger.log({ level: "error", message: messages });
32619
- next(new import_node_server_utils175.BadRequestError(messages));
33135
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
33136
+ next(new import_node_server_utils176.BadRequestError(messages));
32620
33137
  return;
32621
33138
  }
32622
33139
  try {
@@ -32624,7 +33141,7 @@ function useIncidentReportController() {
32624
33141
  res.status(201).json({ data });
32625
33142
  return;
32626
33143
  } catch (error2) {
32627
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33144
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32628
33145
  next(error2);
32629
33146
  return;
32630
33147
  }
@@ -32648,8 +33165,8 @@ function useIncidentReportController() {
32648
33165
  });
32649
33166
  if (error) {
32650
33167
  const messages = error.details.map((d) => d.message).join(", ");
32651
- import_node_server_utils175.logger.log({ level: "error", message: messages });
32652
- next(new import_node_server_utils175.BadRequestError(messages));
33168
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
33169
+ next(new import_node_server_utils176.BadRequestError(messages));
32653
33170
  return;
32654
33171
  }
32655
33172
  const search = req.query.search ?? "";
@@ -32680,7 +33197,7 @@ function useIncidentReportController() {
32680
33197
  res.status(200).json(data);
32681
33198
  return;
32682
33199
  } catch (error2) {
32683
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33200
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32684
33201
  next(error2);
32685
33202
  return;
32686
33203
  }
@@ -32690,8 +33207,8 @@ function useIncidentReportController() {
32690
33207
  const _id = req.params.id;
32691
33208
  const { error } = validation.validate(_id);
32692
33209
  if (error) {
32693
- import_node_server_utils175.logger.log({ level: "error", message: error.message });
32694
- next(new import_node_server_utils175.BadRequestError(error.message));
33210
+ import_node_server_utils176.logger.log({ level: "error", message: error.message });
33211
+ next(new import_node_server_utils176.BadRequestError(error.message));
32695
33212
  return;
32696
33213
  }
32697
33214
  try {
@@ -32699,7 +33216,7 @@ function useIncidentReportController() {
32699
33216
  res.status(200).json(data);
32700
33217
  return;
32701
33218
  } catch (error2) {
32702
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33219
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32703
33220
  next(error2);
32704
33221
  return;
32705
33222
  }
@@ -32712,8 +33229,8 @@ function useIncidentReportController() {
32712
33229
  });
32713
33230
  if (error) {
32714
33231
  const messages = error.details.map((d) => d.message).join(", ");
32715
- import_node_server_utils175.logger.log({ level: "error", message: messages });
32716
- next(new import_node_server_utils175.BadRequestError(messages));
33232
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
33233
+ next(new import_node_server_utils176.BadRequestError(messages));
32717
33234
  return;
32718
33235
  }
32719
33236
  try {
@@ -32721,7 +33238,7 @@ function useIncidentReportController() {
32721
33238
  res.status(200).json({ message: result });
32722
33239
  return;
32723
33240
  } catch (error2) {
32724
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33241
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32725
33242
  next(error2);
32726
33243
  return;
32727
33244
  }
@@ -32731,8 +33248,8 @@ function useIncidentReportController() {
32731
33248
  const _id = req.params.id;
32732
33249
  const { error } = validation.validate(_id);
32733
33250
  if (error) {
32734
- import_node_server_utils175.logger.log({ level: "error", message: error.message });
32735
- next(new import_node_server_utils175.BadRequestError(error.message));
33251
+ import_node_server_utils176.logger.log({ level: "error", message: error.message });
33252
+ next(new import_node_server_utils176.BadRequestError(error.message));
32736
33253
  return;
32737
33254
  }
32738
33255
  try {
@@ -32740,7 +33257,7 @@ function useIncidentReportController() {
32740
33257
  res.status(200).json({ message: "Successfully deleted incident report." });
32741
33258
  return;
32742
33259
  } catch (error2) {
32743
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33260
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32744
33261
  next(error2);
32745
33262
  return;
32746
33263
  }
@@ -32752,8 +33269,8 @@ function useIncidentReportController() {
32752
33269
  });
32753
33270
  if (error) {
32754
33271
  const messages = error.details.map((d) => d.message).join(", ");
32755
- import_node_server_utils175.logger.log({ level: "error", message: messages });
32756
- next(new import_node_server_utils175.BadRequestError(messages));
33272
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
33273
+ next(new import_node_server_utils176.BadRequestError(messages));
32757
33274
  return;
32758
33275
  }
32759
33276
  try {
@@ -32764,7 +33281,7 @@ function useIncidentReportController() {
32764
33281
  res.status(201).json(data);
32765
33282
  return;
32766
33283
  } catch (error2) {
32767
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33284
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32768
33285
  next(error2);
32769
33286
  return;
32770
33287
  }
@@ -32786,8 +33303,8 @@ function useIncidentReportController() {
32786
33303
  const { error } = schema2.validate(payload);
32787
33304
  if (error) {
32788
33305
  const messages = error.details.map((d) => d.message).join(", ");
32789
- import_node_server_utils175.logger.log({ level: "error", message: messages });
32790
- next(new import_node_server_utils175.BadRequestError(messages));
33306
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
33307
+ next(new import_node_server_utils176.BadRequestError(messages));
32791
33308
  return;
32792
33309
  }
32793
33310
  try {
@@ -32795,7 +33312,7 @@ function useIncidentReportController() {
32795
33312
  res.status(200).json({ message: result });
32796
33313
  return;
32797
33314
  } catch (error2) {
32798
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33315
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32799
33316
  next(error2);
32800
33317
  return;
32801
33318
  }
@@ -32814,7 +33331,7 @@ function useIncidentReportController() {
32814
33331
  // src/models/nfc-patrol-settings.model.ts
32815
33332
  var import_mongodb98 = require("mongodb");
32816
33333
  var import_joi101 = __toESM(require("joi"));
32817
- var import_node_server_utils176 = require("@7365admin1/node-server-utils");
33334
+ var import_node_server_utils177 = require("@7365admin1/node-server-utils");
32818
33335
  var objectId = import_joi101.default.string().hex().length(24);
32819
33336
  var nfcPatrolSettingsSchema = import_joi101.default.object({
32820
33337
  site: objectId.required(),
@@ -32833,14 +33350,14 @@ var nfcPatrolSettingsSchemaUpdate = import_joi101.default.object({
32833
33350
  function MNfcPatrolSettings(value) {
32834
33351
  const { error } = nfcPatrolSettingsSchema.validate(value);
32835
33352
  if (error) {
32836
- import_node_server_utils176.logger.info(`NFC Patrol Settings Model: ${error.message}`);
32837
- throw new import_node_server_utils176.BadRequestError(error.message);
33353
+ import_node_server_utils177.logger.info(`NFC Patrol Settings Model: ${error.message}`);
33354
+ throw new import_node_server_utils177.BadRequestError(error.message);
32838
33355
  }
32839
33356
  if (value.site) {
32840
33357
  try {
32841
33358
  value.site = new import_mongodb98.ObjectId(value.site);
32842
33359
  } catch (error2) {
32843
- throw new import_node_server_utils176.BadRequestError("Invalid site ID format.");
33360
+ throw new import_node_server_utils177.BadRequestError("Invalid site ID format.");
32844
33361
  }
32845
33362
  }
32846
33363
  return {
@@ -32853,14 +33370,14 @@ function MNfcPatrolSettings(value) {
32853
33370
  function MNfcPatrolSettingsUpdate(value) {
32854
33371
  const { error } = nfcPatrolSettingsSchemaUpdate.validate(value);
32855
33372
  if (error) {
32856
- import_node_server_utils176.logger.info(`NFC Patrol Settings Model: ${error.message}`);
32857
- throw new import_node_server_utils176.BadRequestError(error.message);
33373
+ import_node_server_utils177.logger.info(`NFC Patrol Settings Model: ${error.message}`);
33374
+ throw new import_node_server_utils177.BadRequestError(error.message);
32858
33375
  }
32859
33376
  if (value.updatedBy) {
32860
33377
  try {
32861
33378
  value.updatedBy = new import_mongodb98.ObjectId(value.updatedBy);
32862
33379
  } catch (error2) {
32863
- throw new import_node_server_utils176.BadRequestError("Invalid updatedBy ID format.");
33380
+ throw new import_node_server_utils177.BadRequestError("Invalid updatedBy ID format.");
32864
33381
  }
32865
33382
  }
32866
33383
  return {
@@ -32871,21 +33388,21 @@ function MNfcPatrolSettingsUpdate(value) {
32871
33388
  }
32872
33389
 
32873
33390
  // src/repositories/nfc-patrol-settings.repository.ts
32874
- var import_node_server_utils177 = require("@7365admin1/node-server-utils");
33391
+ var import_node_server_utils178 = require("@7365admin1/node-server-utils");
32875
33392
  var import_mongodb99 = require("mongodb");
32876
33393
  function useNfcPatrolSettingsRepository() {
32877
- const db = import_node_server_utils177.useAtlas.getDb();
33394
+ const db = import_node_server_utils178.useAtlas.getDb();
32878
33395
  if (!db) {
32879
- throw new import_node_server_utils177.InternalServerError("Unable to connect to server.");
33396
+ throw new import_node_server_utils178.InternalServerError("Unable to connect to server.");
32880
33397
  }
32881
33398
  const namespace_collection = "site.nfc-patrol-settings";
32882
33399
  const collection = db.collection(namespace_collection);
32883
- const { delNamespace, setCache, getCache } = (0, import_node_server_utils177.useCache)(namespace_collection);
33400
+ const { delNamespace, setCache, getCache } = (0, import_node_server_utils178.useCache)(namespace_collection);
32884
33401
  async function createIndexes() {
32885
33402
  try {
32886
33403
  await collection.createIndexes([{ key: { site: 1 }, unique: true }]);
32887
33404
  } catch (error) {
32888
- throw new import_node_server_utils177.InternalServerError(
33405
+ throw new import_node_server_utils178.InternalServerError(
32889
33406
  "Failed to create index on nfc patrol settings."
32890
33407
  );
32891
33408
  }
@@ -32904,20 +33421,20 @@ function useNfcPatrolSettingsRepository() {
32904
33421
  try {
32905
33422
  site = new import_mongodb99.ObjectId(site);
32906
33423
  } catch (error) {
32907
- throw new import_node_server_utils177.BadRequestError("Invalid nfc patrol settings site ID format.");
33424
+ throw new import_node_server_utils178.BadRequestError("Invalid nfc patrol settings site ID format.");
32908
33425
  }
32909
33426
  const query = { site };
32910
- const cacheKey = (0, import_node_server_utils177.makeCacheKey)(namespace_collection, {
33427
+ const cacheKey = (0, import_node_server_utils178.makeCacheKey)(namespace_collection, {
32911
33428
  site: site.toString()
32912
33429
  });
32913
33430
  if (!session) {
32914
33431
  const cachedData = await getCache(cacheKey);
32915
33432
  if (cachedData) {
32916
- import_node_server_utils177.logger.info(`Cache hit for key: ${cacheKey}`);
33433
+ import_node_server_utils178.logger.info(`Cache hit for key: ${cacheKey}`);
32917
33434
  return cachedData;
32918
33435
  }
32919
33436
  } else {
32920
- import_node_server_utils177.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
33437
+ import_node_server_utils178.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
32921
33438
  }
32922
33439
  try {
32923
33440
  const data = await collection.aggregate([
@@ -32935,9 +33452,9 @@ function useNfcPatrolSettingsRepository() {
32935
33452
  return null;
32936
33453
  }
32937
33454
  setCache(cacheKey, data[0], 15 * 60).then(() => {
32938
- import_node_server_utils177.logger.info(`Cache set for key: ${cacheKey}`);
33455
+ import_node_server_utils178.logger.info(`Cache set for key: ${cacheKey}`);
32939
33456
  }).catch((err) => {
32940
- import_node_server_utils177.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33457
+ import_node_server_utils178.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32941
33458
  });
32942
33459
  return data[0];
32943
33460
  } catch (error) {
@@ -32948,7 +33465,7 @@ function useNfcPatrolSettingsRepository() {
32948
33465
  try {
32949
33466
  site = new import_mongodb99.ObjectId(site);
32950
33467
  } catch (error) {
32951
- throw new import_node_server_utils177.BadRequestError("Invalid attendance settings ID format.");
33468
+ throw new import_node_server_utils178.BadRequestError("Invalid attendance settings ID format.");
32952
33469
  }
32953
33470
  try {
32954
33471
  value = MNfcPatrolSettingsUpdate(value);
@@ -32958,12 +33475,12 @@ function useNfcPatrolSettingsRepository() {
32958
33475
  { session }
32959
33476
  );
32960
33477
  if (res.matchedCount === 0) {
32961
- throw new import_node_server_utils177.NotFoundError("NFC patrol settings not found for this site.");
33478
+ throw new import_node_server_utils178.NotFoundError("NFC patrol settings not found for this site.");
32962
33479
  }
32963
33480
  delNamespace().then(() => {
32964
- import_node_server_utils177.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33481
+ import_node_server_utils178.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32965
33482
  }).catch((err) => {
32966
- import_node_server_utils177.logger.error(
33483
+ import_node_server_utils178.logger.error(
32967
33484
  `Failed to clear cache for namespace: ${namespace_collection}`,
32968
33485
  err
32969
33486
  );
@@ -32975,12 +33492,12 @@ function useNfcPatrolSettingsRepository() {
32975
33492
  }
32976
33493
  function delCachedData() {
32977
33494
  delNamespace().then(() => {
32978
- import_node_server_utils177.logger.log({
33495
+ import_node_server_utils178.logger.log({
32979
33496
  level: "info",
32980
33497
  message: `Cache namespace cleared for ${namespace_collection}`
32981
33498
  });
32982
33499
  }).catch((err) => {
32983
- import_node_server_utils177.logger.log({
33500
+ import_node_server_utils178.logger.log({
32984
33501
  level: "error",
32985
33502
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
32986
33503
  });
@@ -32995,7 +33512,7 @@ function useNfcPatrolSettingsRepository() {
32995
33512
  }
32996
33513
 
32997
33514
  // src/services/nfc-patrol-settings.service.ts
32998
- var import_node_server_utils178 = require("@7365admin1/node-server-utils");
33515
+ var import_node_server_utils179 = require("@7365admin1/node-server-utils");
32999
33516
  function useNfcPatrolSettingsService() {
33000
33517
  const {
33001
33518
  createNfcPatrolSettings,
@@ -33006,10 +33523,10 @@ function useNfcPatrolSettingsService() {
33006
33523
  try {
33007
33524
  let settings = await _getNfcPatrolSettingsBySite(site);
33008
33525
  if (!settings) {
33009
- import_node_server_utils178.logger.info(
33526
+ import_node_server_utils179.logger.info(
33010
33527
  `No attendance settings found for site ${site}, creating default settings`
33011
33528
  );
33012
- const session = import_node_server_utils178.useAtlas.getClient()?.startSession();
33529
+ const session = import_node_server_utils179.useAtlas.getClient()?.startSession();
33013
33530
  try {
33014
33531
  session?.startTransaction();
33015
33532
  await createNfcPatrolSettings(
@@ -33031,14 +33548,14 @@ function useNfcPatrolSettingsService() {
33031
33548
  }
33032
33549
  return settings;
33033
33550
  } catch (error) {
33034
- import_node_server_utils178.logger.error(`Error fetching nfc patrol settings by site:`, error);
33551
+ import_node_server_utils179.logger.error(`Error fetching nfc patrol settings by site:`, error);
33035
33552
  throw error;
33036
33553
  }
33037
33554
  }
33038
33555
  async function updateNfcPatrolSettings(site, value) {
33039
- const session = import_node_server_utils178.useAtlas.getClient()?.startSession();
33556
+ const session = import_node_server_utils179.useAtlas.getClient()?.startSession();
33040
33557
  if (!session) {
33041
- throw new import_node_server_utils178.BadRequestError("Database session not available.");
33558
+ throw new import_node_server_utils179.BadRequestError("Database session not available.");
33042
33559
  }
33043
33560
  try {
33044
33561
  await session.startTransaction();
@@ -33046,7 +33563,7 @@ function useNfcPatrolSettingsService() {
33046
33563
  await session.commitTransaction();
33047
33564
  return "Successfully updated NFC Patrol Settings.";
33048
33565
  } catch (error) {
33049
- import_node_server_utils178.logger.log({
33566
+ import_node_server_utils179.logger.log({
33050
33567
  level: "error",
33051
33568
  message: `Failed to update NFC Patrol Settings: ${error.message}`
33052
33569
  });
@@ -33061,7 +33578,7 @@ function useNfcPatrolSettingsService() {
33061
33578
 
33062
33579
  // src/controllers/nfc-patrol-settings.controller.ts
33063
33580
  var import_joi102 = __toESM(require("joi"));
33064
- var import_node_server_utils179 = require("@7365admin1/node-server-utils");
33581
+ var import_node_server_utils180 = require("@7365admin1/node-server-utils");
33065
33582
  function useNfcPatrolSettingsController() {
33066
33583
  const { getNfcPatrolSettingsBySite: _getNfcPatrolSettingsBySite } = useNfcPatrolSettingsService();
33067
33584
  const { updateNfcPatrolSettings: _updateNfcPatrolSettings } = useNfcPatrolSettingsService();
@@ -33070,8 +33587,8 @@ function useNfcPatrolSettingsController() {
33070
33587
  const site = req.params.site;
33071
33588
  const { error } = validation.validate(site);
33072
33589
  if (error) {
33073
- import_node_server_utils179.logger.log({ level: "error", message: error.message });
33074
- next(new import_node_server_utils179.BadRequestError(error.message));
33590
+ import_node_server_utils180.logger.log({ level: "error", message: error.message });
33591
+ next(new import_node_server_utils180.BadRequestError(error.message));
33075
33592
  return;
33076
33593
  }
33077
33594
  try {
@@ -33079,7 +33596,7 @@ function useNfcPatrolSettingsController() {
33079
33596
  res.json(data);
33080
33597
  return;
33081
33598
  } catch (error2) {
33082
- import_node_server_utils179.logger.log({ level: "error", message: error2.message });
33599
+ import_node_server_utils180.logger.log({ level: "error", message: error2.message });
33083
33600
  next(error2);
33084
33601
  return;
33085
33602
  }
@@ -33098,7 +33615,7 @@ function useNfcPatrolSettingsController() {
33098
33615
  res.json({ message: "NFC patrol settings updated successfully." });
33099
33616
  return;
33100
33617
  } catch (error) {
33101
- import_node_server_utils179.logger.log({ level: "error", message: error.message });
33618
+ import_node_server_utils180.logger.log({ level: "error", message: error.message });
33102
33619
  next(error);
33103
33620
  return;
33104
33621
  }
@@ -33110,10 +33627,10 @@ function useNfcPatrolSettingsController() {
33110
33627
  }
33111
33628
 
33112
33629
  // src/services/occurrence-entry.service.ts
33113
- var import_node_server_utils181 = require("@7365admin1/node-server-utils");
33630
+ var import_node_server_utils182 = require("@7365admin1/node-server-utils");
33114
33631
 
33115
33632
  // src/repositories/occurrence-subject.repo.ts
33116
- var import_node_server_utils180 = require("@7365admin1/node-server-utils");
33633
+ var import_node_server_utils181 = require("@7365admin1/node-server-utils");
33117
33634
 
33118
33635
  // src/models/occurrence-subject.model.ts
33119
33636
  var import_mongodb100 = require("mongodb");
@@ -33163,15 +33680,15 @@ function MOccurrenceSubject(value) {
33163
33680
  // src/repositories/occurrence-subject.repo.ts
33164
33681
  var import_mongodb101 = require("mongodb");
33165
33682
  function useOccurrenceSubjectRepo() {
33166
- const db = import_node_server_utils180.useAtlas.getDb();
33683
+ const db = import_node_server_utils181.useAtlas.getDb();
33167
33684
  if (!db) {
33168
- throw new import_node_server_utils180.InternalServerError("Unable to connect to server.");
33685
+ throw new import_node_server_utils181.InternalServerError("Unable to connect to server.");
33169
33686
  }
33170
33687
  async function createIndexes() {
33171
33688
  try {
33172
33689
  await collection.createIndexes([{ key: { site: 1 } }]);
33173
33690
  } catch (error) {
33174
- throw new import_node_server_utils180.InternalServerError(
33691
+ throw new import_node_server_utils181.InternalServerError(
33175
33692
  "Failed to create index on occurrence subjects."
33176
33693
  );
33177
33694
  }
@@ -33182,22 +33699,22 @@ function useOccurrenceSubjectRepo() {
33182
33699
  subject: "text"
33183
33700
  });
33184
33701
  } catch (error) {
33185
- throw new import_node_server_utils180.InternalServerError(
33702
+ throw new import_node_server_utils181.InternalServerError(
33186
33703
  "Failed to create text index on occurrence subjects."
33187
33704
  );
33188
33705
  }
33189
33706
  }
33190
33707
  const namespace_collection = "occurrence-subjects";
33191
33708
  const collection = db.collection(namespace_collection);
33192
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils180.useCache)(namespace_collection);
33709
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils181.useCache)(namespace_collection);
33193
33710
  async function add(value, session) {
33194
33711
  try {
33195
33712
  value = MOccurrenceSubject(value);
33196
33713
  const res = await collection.insertOne(value, { session });
33197
33714
  delNamespace().then(() => {
33198
- import_node_server_utils180.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33715
+ import_node_server_utils181.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33199
33716
  }).catch((err) => {
33200
- import_node_server_utils180.logger.error(
33717
+ import_node_server_utils181.logger.error(
33201
33718
  `Failed to clear cache for namespace: ${namespace_collection}`,
33202
33719
  err
33203
33720
  );
@@ -33206,7 +33723,7 @@ function useOccurrenceSubjectRepo() {
33206
33723
  } catch (error) {
33207
33724
  const isDuplicated = error.message.includes("duplicate");
33208
33725
  if (isDuplicated) {
33209
- throw new import_node_server_utils180.BadRequestError("Occurrence subject already exists.");
33726
+ throw new import_node_server_utils181.BadRequestError("Occurrence subject already exists.");
33210
33727
  }
33211
33728
  throw error;
33212
33729
  }
@@ -33222,7 +33739,7 @@ function useOccurrenceSubjectRepo() {
33222
33739
  try {
33223
33740
  site = new import_mongodb101.ObjectId(site);
33224
33741
  } catch (error) {
33225
- throw new import_node_server_utils180.BadRequestError("Invalid site ID format.");
33742
+ throw new import_node_server_utils181.BadRequestError("Invalid site ID format.");
33226
33743
  }
33227
33744
  const baseQuery = {
33228
33745
  site,
@@ -33241,10 +33758,10 @@ function useOccurrenceSubjectRepo() {
33241
33758
  query.$text = { $search: search };
33242
33759
  cacheOptions.search = search;
33243
33760
  }
33244
- const cacheKey = (0, import_node_server_utils180.makeCacheKey)(namespace_collection, cacheOptions);
33761
+ const cacheKey = (0, import_node_server_utils181.makeCacheKey)(namespace_collection, cacheOptions);
33245
33762
  const cachedData = await getCache(cacheKey);
33246
33763
  if (cachedData) {
33247
- import_node_server_utils180.logger.info(`Cache hit for key: ${cacheKey}`);
33764
+ import_node_server_utils181.logger.info(`Cache hit for key: ${cacheKey}`);
33248
33765
  return cachedData;
33249
33766
  }
33250
33767
  try {
@@ -33302,11 +33819,11 @@ function useOccurrenceSubjectRepo() {
33302
33819
  ]).toArray();
33303
33820
  length = await collection.countDocuments(regexQuery, { session });
33304
33821
  }
33305
- const data = (0, import_node_server_utils180.paginate)(items, page, limit, length);
33822
+ const data = (0, import_node_server_utils181.paginate)(items, page, limit, length);
33306
33823
  setCache(cacheKey, data, 15 * 60).then(() => {
33307
- import_node_server_utils180.logger.info(`Cache set for key: ${cacheKey}`);
33824
+ import_node_server_utils181.logger.info(`Cache set for key: ${cacheKey}`);
33308
33825
  }).catch((err) => {
33309
- import_node_server_utils180.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33826
+ import_node_server_utils181.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33310
33827
  });
33311
33828
  return data;
33312
33829
  } catch (error) {
@@ -33317,23 +33834,23 @@ function useOccurrenceSubjectRepo() {
33317
33834
  try {
33318
33835
  _id = new import_mongodb101.ObjectId(_id);
33319
33836
  } catch (error) {
33320
- throw new import_node_server_utils180.BadRequestError("Invalid occurrence subject ID format.");
33837
+ throw new import_node_server_utils181.BadRequestError("Invalid occurrence subject ID format.");
33321
33838
  }
33322
- const cacheKey = (0, import_node_server_utils180.makeCacheKey)(namespace_collection, { _id });
33839
+ const cacheKey = (0, import_node_server_utils181.makeCacheKey)(namespace_collection, { _id });
33323
33840
  const cachedData = await getCache(cacheKey);
33324
33841
  if (cachedData) {
33325
- import_node_server_utils180.logger.info(`Cache hit for key: ${cacheKey}`);
33842
+ import_node_server_utils181.logger.info(`Cache hit for key: ${cacheKey}`);
33326
33843
  return cachedData;
33327
33844
  }
33328
33845
  try {
33329
33846
  const data = await collection.findOne({ _id }, { session });
33330
33847
  if (!data) {
33331
- throw new import_node_server_utils180.NotFoundError("Occurrence subject not found.");
33848
+ throw new import_node_server_utils181.NotFoundError("Occurrence subject not found.");
33332
33849
  }
33333
33850
  setCache(cacheKey, data, 15 * 60).then(() => {
33334
- import_node_server_utils180.logger.info(`Cache set for key: ${cacheKey}`);
33851
+ import_node_server_utils181.logger.info(`Cache set for key: ${cacheKey}`);
33335
33852
  }).catch((err) => {
33336
- import_node_server_utils180.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33853
+ import_node_server_utils181.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33337
33854
  });
33338
33855
  return data;
33339
33856
  } catch (error) {
@@ -33345,7 +33862,7 @@ function useOccurrenceSubjectRepo() {
33345
33862
  try {
33346
33863
  _id = new import_mongodb101.ObjectId(_id);
33347
33864
  } catch (error) {
33348
- throw new import_node_server_utils180.BadRequestError("Invalid ID format.");
33865
+ throw new import_node_server_utils181.BadRequestError("Invalid ID format.");
33349
33866
  }
33350
33867
  try {
33351
33868
  const res = await collection.updateOne(
@@ -33354,14 +33871,14 @@ function useOccurrenceSubjectRepo() {
33354
33871
  { session }
33355
33872
  );
33356
33873
  if (res.modifiedCount === 0) {
33357
- throw new import_node_server_utils180.InternalServerError(
33874
+ throw new import_node_server_utils181.InternalServerError(
33358
33875
  "Unable to update daily occurrence Subject."
33359
33876
  );
33360
33877
  }
33361
33878
  delNamespace().then(() => {
33362
- import_node_server_utils180.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33879
+ import_node_server_utils181.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33363
33880
  }).catch((err) => {
33364
- import_node_server_utils180.logger.error(
33881
+ import_node_server_utils181.logger.error(
33365
33882
  `Failed to clear cache for namespace: ${namespace_collection}`,
33366
33883
  err
33367
33884
  );
@@ -33375,7 +33892,7 @@ function useOccurrenceSubjectRepo() {
33375
33892
  try {
33376
33893
  _id = new import_mongodb101.ObjectId(_id);
33377
33894
  } catch (error) {
33378
- throw new import_node_server_utils180.BadRequestError("Invalid occurrence subject ID format.");
33895
+ throw new import_node_server_utils181.BadRequestError("Invalid occurrence subject ID format.");
33379
33896
  }
33380
33897
  try {
33381
33898
  const updateValue = {
@@ -33385,12 +33902,12 @@ function useOccurrenceSubjectRepo() {
33385
33902
  };
33386
33903
  const res = await collection.updateOne({ _id }, { $set: updateValue });
33387
33904
  if (res.modifiedCount === 0) {
33388
- throw new import_node_server_utils180.InternalServerError("Unable to delete occurrence subject.");
33905
+ throw new import_node_server_utils181.InternalServerError("Unable to delete occurrence subject.");
33389
33906
  }
33390
33907
  delNamespace().then(() => {
33391
- import_node_server_utils180.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33908
+ import_node_server_utils181.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33392
33909
  }).catch((err) => {
33393
- import_node_server_utils180.logger.error(
33910
+ import_node_server_utils181.logger.error(
33394
33911
  `Failed to clear cache for namespace: ${namespace_collection}`,
33395
33912
  err
33396
33913
  );
@@ -33427,7 +33944,7 @@ function useOccurrenceEntryService() {
33427
33944
  const { getOccurrenceSubjectById: _getOccurrenceSubjectById } = useOccurrenceSubjectRepo();
33428
33945
  const { getUserById: _getUserById } = useUserRepo();
33429
33946
  async function add(value) {
33430
- const session = import_node_server_utils181.useAtlas.getClient()?.startSession();
33947
+ const session = import_node_server_utils182.useAtlas.getClient()?.startSession();
33431
33948
  session?.startTransaction();
33432
33949
  try {
33433
33950
  const [existingEntryWithBookId, occurrenceBook, occurrenceSubject, user] = await Promise.all([
@@ -33463,7 +33980,7 @@ function useOccurrenceEntryService() {
33463
33980
  }
33464
33981
  }
33465
33982
  async function updateOccurrenceEntryById(id, value) {
33466
- const session = import_node_server_utils181.useAtlas.getClient()?.startSession();
33983
+ const session = import_node_server_utils182.useAtlas.getClient()?.startSession();
33467
33984
  session?.startTransaction();
33468
33985
  try {
33469
33986
  const occurrenceEntry = await _getOccurrenceEntryById(id);
@@ -33490,7 +34007,7 @@ function useOccurrenceEntryService() {
33490
34007
  }
33491
34008
 
33492
34009
  // src/controllers/occurrence-entry.controller.ts
33493
- var import_node_server_utils182 = require("@7365admin1/node-server-utils");
34010
+ var import_node_server_utils183 = require("@7365admin1/node-server-utils");
33494
34011
  var import_joi104 = __toESM(require("joi"));
33495
34012
  function useOccurrenceEntryController() {
33496
34013
  const { add: _add, updateOccurrenceEntryById: _updateOccurrenceEntryById } = useOccurrenceEntryService();
@@ -33507,8 +34024,8 @@ function useOccurrenceEntryController() {
33507
34024
  });
33508
34025
  if (error) {
33509
34026
  const messages = error.details.map((d) => d.message).join(", ");
33510
- import_node_server_utils182.logger.log({ level: "error", message: messages });
33511
- next(new import_node_server_utils182.BadRequestError(messages));
34027
+ import_node_server_utils183.logger.log({ level: "error", message: messages });
34028
+ next(new import_node_server_utils183.BadRequestError(messages));
33512
34029
  return;
33513
34030
  }
33514
34031
  try {
@@ -33516,7 +34033,7 @@ function useOccurrenceEntryController() {
33516
34033
  res.status(201).json(data);
33517
34034
  return;
33518
34035
  } catch (error2) {
33519
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
34036
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33520
34037
  next(error2);
33521
34038
  return;
33522
34039
  }
@@ -33539,8 +34056,8 @@ function useOccurrenceEntryController() {
33539
34056
  });
33540
34057
  if (error) {
33541
34058
  const messages = error.details.map((d) => d.message).join(", ");
33542
- import_node_server_utils182.logger.log({ level: "error", message: messages });
33543
- next(new import_node_server_utils182.BadRequestError(messages));
34059
+ import_node_server_utils183.logger.log({ level: "error", message: messages });
34060
+ next(new import_node_server_utils183.BadRequestError(messages));
33544
34061
  return;
33545
34062
  }
33546
34063
  const search = req.query.search ?? "";
@@ -33569,7 +34086,7 @@ function useOccurrenceEntryController() {
33569
34086
  res.status(200).json(data);
33570
34087
  return;
33571
34088
  } catch (error2) {
33572
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
34089
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33573
34090
  next(error2);
33574
34091
  return;
33575
34092
  }
@@ -33579,8 +34096,8 @@ function useOccurrenceEntryController() {
33579
34096
  const _id = req.params.id;
33580
34097
  const { error } = validation.validate(_id);
33581
34098
  if (error) {
33582
- import_node_server_utils182.logger.log({ level: "error", message: error.message });
33583
- next(new import_node_server_utils182.BadRequestError(error.message));
34099
+ import_node_server_utils183.logger.log({ level: "error", message: error.message });
34100
+ next(new import_node_server_utils183.BadRequestError(error.message));
33584
34101
  return;
33585
34102
  }
33586
34103
  try {
@@ -33588,7 +34105,7 @@ function useOccurrenceEntryController() {
33588
34105
  res.status(200).json(data);
33589
34106
  return;
33590
34107
  } catch (error2) {
33591
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
34108
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33592
34109
  next(error2);
33593
34110
  return;
33594
34111
  }
@@ -33601,8 +34118,8 @@ function useOccurrenceEntryController() {
33601
34118
  });
33602
34119
  if (error) {
33603
34120
  const messages = error.details.map((d) => d.message).join(", ");
33604
- import_node_server_utils182.logger.log({ level: "error", message: messages });
33605
- next(new import_node_server_utils182.BadRequestError(messages));
34121
+ import_node_server_utils183.logger.log({ level: "error", message: messages });
34122
+ next(new import_node_server_utils183.BadRequestError(messages));
33606
34123
  return;
33607
34124
  }
33608
34125
  try {
@@ -33610,7 +34127,7 @@ function useOccurrenceEntryController() {
33610
34127
  res.status(200).json({ message: result });
33611
34128
  return;
33612
34129
  } catch (error2) {
33613
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
34130
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33614
34131
  next(error2);
33615
34132
  return;
33616
34133
  }
@@ -33620,8 +34137,8 @@ function useOccurrenceEntryController() {
33620
34137
  const _id = req.params.id;
33621
34138
  const { error } = validation.validate(_id);
33622
34139
  if (error) {
33623
- import_node_server_utils182.logger.log({ level: "error", message: error.message });
33624
- next(new import_node_server_utils182.BadRequestError(error.message));
34140
+ import_node_server_utils183.logger.log({ level: "error", message: error.message });
34141
+ next(new import_node_server_utils183.BadRequestError(error.message));
33625
34142
  return;
33626
34143
  }
33627
34144
  try {
@@ -33629,7 +34146,7 @@ function useOccurrenceEntryController() {
33629
34146
  res.status(200).json({ message: "Successfully deleted occurrence entry." });
33630
34147
  return;
33631
34148
  } catch (error2) {
33632
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
34149
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33633
34150
  next(error2);
33634
34151
  return;
33635
34152
  }
@@ -33639,8 +34156,8 @@ function useOccurrenceEntryController() {
33639
34156
  const _id = req.params.id;
33640
34157
  const { error } = validation.validate(_id);
33641
34158
  if (error) {
33642
- import_node_server_utils182.logger.log({ level: "error", message: error.message });
33643
- next(new import_node_server_utils182.BadRequestError(error.message));
34159
+ import_node_server_utils183.logger.log({ level: "error", message: error.message });
34160
+ next(new import_node_server_utils183.BadRequestError(error.message));
33644
34161
  return;
33645
34162
  }
33646
34163
  try {
@@ -33648,7 +34165,7 @@ function useOccurrenceEntryController() {
33648
34165
  res.status(200).json({ count: data });
33649
34166
  return;
33650
34167
  } catch (error2) {
33651
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
34168
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33652
34169
  next(error2);
33653
34170
  return;
33654
34171
  }
@@ -33749,23 +34266,23 @@ function MOnlineForm(value) {
33749
34266
  }
33750
34267
 
33751
34268
  // src/repositories/online-form.repo.ts
33752
- var import_node_server_utils183 = require("@7365admin1/node-server-utils");
34269
+ var import_node_server_utils184 = require("@7365admin1/node-server-utils");
33753
34270
  var import_mongodb103 = require("mongodb");
33754
34271
  function useOnlineFormRepo() {
33755
- const db = import_node_server_utils183.useAtlas.getDb();
34272
+ const db = import_node_server_utils184.useAtlas.getDb();
33756
34273
  if (!db) {
33757
- throw new import_node_server_utils183.InternalServerError("Unable to connect to server.");
34274
+ throw new import_node_server_utils184.InternalServerError("Unable to connect to server.");
33758
34275
  }
33759
34276
  const namespace_collection = "online-forms";
33760
34277
  const collection = db.collection(namespace_collection);
33761
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils183.useCache)(namespace_collection);
34278
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils184.useCache)(namespace_collection);
33762
34279
  async function createTextIndex() {
33763
34280
  try {
33764
34281
  await collection.createIndex({
33765
34282
  name: "text"
33766
34283
  });
33767
34284
  } catch (error) {
33768
- throw new import_node_server_utils183.InternalServerError(
34285
+ throw new import_node_server_utils184.InternalServerError(
33769
34286
  "Failed to create text index on online form."
33770
34287
  );
33771
34288
  }
@@ -33775,9 +34292,9 @@ function useOnlineFormRepo() {
33775
34292
  value = MOnlineForm(value);
33776
34293
  const res = await collection.insertOne(value, { session });
33777
34294
  delNamespace().then(() => {
33778
- import_node_server_utils183.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
34295
+ import_node_server_utils184.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33779
34296
  }).catch((err) => {
33780
- import_node_server_utils183.logger.error(
34297
+ import_node_server_utils184.logger.error(
33781
34298
  `Failed to clear cache for namespace: ${namespace_collection}`,
33782
34299
  err
33783
34300
  );
@@ -33786,7 +34303,7 @@ function useOnlineFormRepo() {
33786
34303
  } catch (error) {
33787
34304
  const isDuplicated = error.message.includes("duplicate");
33788
34305
  if (isDuplicated) {
33789
- throw new import_node_server_utils183.BadRequestError("Online Form already exists.");
34306
+ throw new import_node_server_utils184.BadRequestError("Online Form already exists.");
33790
34307
  }
33791
34308
  throw error;
33792
34309
  }
@@ -33815,10 +34332,10 @@ function useOnlineFormRepo() {
33815
34332
  query.$or = [{ name: { $regex: search, $options: "i" } }];
33816
34333
  cacheOptions.search = search;
33817
34334
  }
33818
- const cacheKey = (0, import_node_server_utils183.makeCacheKey)(namespace_collection, cacheOptions);
34335
+ const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, cacheOptions);
33819
34336
  const cachedData = await getCache(cacheKey);
33820
34337
  if (cachedData) {
33821
- import_node_server_utils183.logger.info(`Cache hit for key: ${cacheKey}`);
34338
+ import_node_server_utils184.logger.info(`Cache hit for key: ${cacheKey}`);
33822
34339
  return cachedData;
33823
34340
  }
33824
34341
  try {
@@ -33839,11 +34356,11 @@ function useOnlineFormRepo() {
33839
34356
  }
33840
34357
  ]).toArray();
33841
34358
  const length = await collection.countDocuments(query);
33842
- const data = (0, import_node_server_utils183.paginate)(items, page, limit, length);
34359
+ const data = (0, import_node_server_utils184.paginate)(items, page, limit, length);
33843
34360
  setCache(cacheKey, data, 15 * 60).then(() => {
33844
- import_node_server_utils183.logger.info(`Cache set for key: ${cacheKey}`);
34361
+ import_node_server_utils184.logger.info(`Cache set for key: ${cacheKey}`);
33845
34362
  }).catch((err) => {
33846
- import_node_server_utils183.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34363
+ import_node_server_utils184.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33847
34364
  });
33848
34365
  return data;
33849
34366
  } catch (error) {
@@ -33854,12 +34371,12 @@ function useOnlineFormRepo() {
33854
34371
  try {
33855
34372
  _id = new import_mongodb103.ObjectId(_id);
33856
34373
  } catch (error) {
33857
- throw new import_node_server_utils183.BadRequestError("Invalid online form ID format.");
34374
+ throw new import_node_server_utils184.BadRequestError("Invalid online form ID format.");
33858
34375
  }
33859
- const cacheKey = (0, import_node_server_utils183.makeCacheKey)(namespace_collection, { _id });
34376
+ const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, { _id });
33860
34377
  const cachedData = await getCache(cacheKey);
33861
34378
  if (cachedData) {
33862
- import_node_server_utils183.logger.info(`Cache hit for key: ${cacheKey}`);
34379
+ import_node_server_utils184.logger.info(`Cache hit for key: ${cacheKey}`);
33863
34380
  return cachedData;
33864
34381
  }
33865
34382
  try {
@@ -33881,12 +34398,12 @@ function useOnlineFormRepo() {
33881
34398
  }
33882
34399
  ]).toArray();
33883
34400
  if (!data || !data.length) {
33884
- throw new import_node_server_utils183.NotFoundError("Document not found.");
34401
+ throw new import_node_server_utils184.NotFoundError("Document not found.");
33885
34402
  }
33886
34403
  setCache(cacheKey, data[0], 15 * 60).then(() => {
33887
- import_node_server_utils183.logger.info(`Cache set for key: ${cacheKey}`);
34404
+ import_node_server_utils184.logger.info(`Cache set for key: ${cacheKey}`);
33888
34405
  }).catch((err) => {
33889
- import_node_server_utils183.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34406
+ import_node_server_utils184.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33890
34407
  });
33891
34408
  return data[0];
33892
34409
  } catch (error) {
@@ -33897,7 +34414,7 @@ function useOnlineFormRepo() {
33897
34414
  try {
33898
34415
  _id = new import_mongodb103.ObjectId(_id);
33899
34416
  } catch (error) {
33900
- throw new import_node_server_utils183.BadRequestError("Invalid online form ID format.");
34417
+ throw new import_node_server_utils184.BadRequestError("Invalid online form ID format.");
33901
34418
  }
33902
34419
  try {
33903
34420
  const updateValue = {
@@ -33906,12 +34423,12 @@ function useOnlineFormRepo() {
33906
34423
  };
33907
34424
  const res = await collection.updateOne({ _id }, { $set: updateValue });
33908
34425
  if (res.modifiedCount === 0) {
33909
- throw new import_node_server_utils183.InternalServerError("Unable to update online form.");
34426
+ throw new import_node_server_utils184.InternalServerError("Unable to update online form.");
33910
34427
  }
33911
34428
  delNamespace().then(() => {
33912
- import_node_server_utils183.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
34429
+ import_node_server_utils184.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33913
34430
  }).catch((err) => {
33914
- import_node_server_utils183.logger.error(
34431
+ import_node_server_utils184.logger.error(
33915
34432
  `Failed to clear cache for namespace: ${namespace_collection}`,
33916
34433
  err
33917
34434
  );
@@ -33925,7 +34442,7 @@ function useOnlineFormRepo() {
33925
34442
  try {
33926
34443
  _id = new import_mongodb103.ObjectId(_id);
33927
34444
  } catch (error) {
33928
- throw new import_node_server_utils183.BadRequestError("Invalid online form ID format.");
34445
+ throw new import_node_server_utils184.BadRequestError("Invalid online form ID format.");
33929
34446
  }
33930
34447
  try {
33931
34448
  const updateValue = {
@@ -33939,12 +34456,12 @@ function useOnlineFormRepo() {
33939
34456
  { session }
33940
34457
  );
33941
34458
  if (res.modifiedCount === 0) {
33942
- throw new import_node_server_utils183.InternalServerError("Unable to delete online form.");
34459
+ throw new import_node_server_utils184.InternalServerError("Unable to delete online form.");
33943
34460
  }
33944
34461
  delNamespace().then(() => {
33945
- import_node_server_utils183.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
34462
+ import_node_server_utils184.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33946
34463
  }).catch((err) => {
33947
- import_node_server_utils183.logger.error(
34464
+ import_node_server_utils184.logger.error(
33948
34465
  `Failed to clear cache for namespace: ${namespace_collection}`,
33949
34466
  err
33950
34467
  );
@@ -33958,7 +34475,7 @@ function useOnlineFormRepo() {
33958
34475
  try {
33959
34476
  site = new import_mongodb103.ObjectId(site);
33960
34477
  } catch (error) {
33961
- throw new import_node_server_utils183.BadRequestError(
34478
+ throw new import_node_server_utils184.BadRequestError(
33962
34479
  "Invalid online form configuration site ID format."
33963
34480
  );
33964
34481
  }
@@ -33977,10 +34494,10 @@ function useOnlineFormRepo() {
33977
34494
  cacheOptions.search = search;
33978
34495
  }
33979
34496
  cacheOptions.site = site;
33980
- const cacheKey = (0, import_node_server_utils183.makeCacheKey)(namespace_collection, { site });
34497
+ const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, { site });
33981
34498
  const cachedData = await getCache(cacheKey);
33982
34499
  if (cachedData) {
33983
- import_node_server_utils183.logger.info(`Cache hit for key: ${cacheKey}`);
34500
+ import_node_server_utils184.logger.info(`Cache hit for key: ${cacheKey}`);
33984
34501
  return cachedData;
33985
34502
  }
33986
34503
  try {
@@ -33999,11 +34516,11 @@ function useOnlineFormRepo() {
33999
34516
  }
34000
34517
  ]).toArray();
34001
34518
  const length = await collection.countDocuments(query);
34002
- const data = (0, import_node_server_utils183.paginate)(items, page, limit, length);
34519
+ const data = (0, import_node_server_utils184.paginate)(items, page, limit, length);
34003
34520
  setCache(cacheKey, data, 15 * 60).then(() => {
34004
- import_node_server_utils183.logger.info(`Cache set for key: ${cacheKey}`);
34521
+ import_node_server_utils184.logger.info(`Cache set for key: ${cacheKey}`);
34005
34522
  }).catch((err) => {
34006
- import_node_server_utils183.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34523
+ import_node_server_utils184.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34007
34524
  });
34008
34525
  return data;
34009
34526
  } catch (error) {
@@ -34022,7 +34539,7 @@ function useOnlineFormRepo() {
34022
34539
  }
34023
34540
 
34024
34541
  // src/controllers/online-form.controller.ts
34025
- var import_node_server_utils184 = require("@7365admin1/node-server-utils");
34542
+ var import_node_server_utils185 = require("@7365admin1/node-server-utils");
34026
34543
  var import_joi106 = __toESM(require("joi"));
34027
34544
  function useOnlineFormController() {
34028
34545
  const {
@@ -34045,8 +34562,8 @@ function useOnlineFormController() {
34045
34562
  });
34046
34563
  if (error) {
34047
34564
  const messages = error.details.map((d) => d.message).join(", ");
34048
- import_node_server_utils184.logger.log({ level: "error", message: messages });
34049
- next(new import_node_server_utils184.BadRequestError(messages));
34565
+ import_node_server_utils185.logger.log({ level: "error", message: messages });
34566
+ next(new import_node_server_utils185.BadRequestError(messages));
34050
34567
  return;
34051
34568
  }
34052
34569
  try {
@@ -34054,7 +34571,7 @@ function useOnlineFormController() {
34054
34571
  res.status(201).json({ message: data });
34055
34572
  return;
34056
34573
  } catch (error2) {
34057
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34574
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34058
34575
  next(error2);
34059
34576
  return;
34060
34577
  }
@@ -34072,8 +34589,8 @@ function useOnlineFormController() {
34072
34589
  query.status = req.query.status;
34073
34590
  const { error } = validation.validate(query);
34074
34591
  if (error) {
34075
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34076
- next(new import_node_server_utils184.BadRequestError(error.message));
34592
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34593
+ next(new import_node_server_utils185.BadRequestError(error.message));
34077
34594
  return;
34078
34595
  }
34079
34596
  const search = req.query.search ?? "";
@@ -34087,7 +34604,7 @@ function useOnlineFormController() {
34087
34604
  res.json(data);
34088
34605
  return;
34089
34606
  } catch (error2) {
34090
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34607
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34091
34608
  next(error2);
34092
34609
  return;
34093
34610
  }
@@ -34097,8 +34614,8 @@ function useOnlineFormController() {
34097
34614
  const _id = req.params.id;
34098
34615
  const { error } = validation.validate(_id);
34099
34616
  if (error) {
34100
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34101
- next(new import_node_server_utils184.BadRequestError(error.message));
34617
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34618
+ next(new import_node_server_utils185.BadRequestError(error.message));
34102
34619
  return;
34103
34620
  }
34104
34621
  try {
@@ -34106,7 +34623,7 @@ function useOnlineFormController() {
34106
34623
  res.json(data);
34107
34624
  return;
34108
34625
  } catch (error2) {
34109
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34626
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34110
34627
  next(error2);
34111
34628
  return;
34112
34629
  }
@@ -34138,8 +34655,8 @@ function useOnlineFormController() {
34138
34655
  const payload = { ...req.body, updatedBy };
34139
34656
  const { error } = validation.validate({ _id, ...payload });
34140
34657
  if (error) {
34141
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34142
- next(new import_node_server_utils184.BadRequestError(error.message));
34658
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34659
+ next(new import_node_server_utils185.BadRequestError(error.message));
34143
34660
  return;
34144
34661
  }
34145
34662
  try {
@@ -34147,7 +34664,7 @@ function useOnlineFormController() {
34147
34664
  res.json({ message: "Successfully updated online form." });
34148
34665
  return;
34149
34666
  } catch (error2) {
34150
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34667
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34151
34668
  next(error2);
34152
34669
  return;
34153
34670
  }
@@ -34157,8 +34674,8 @@ function useOnlineFormController() {
34157
34674
  const _id = req.params.id;
34158
34675
  const { error } = validation.validate(_id);
34159
34676
  if (error) {
34160
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34161
- next(new import_node_server_utils184.BadRequestError(error.message));
34677
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34678
+ next(new import_node_server_utils185.BadRequestError(error.message));
34162
34679
  return;
34163
34680
  }
34164
34681
  try {
@@ -34166,7 +34683,7 @@ function useOnlineFormController() {
34166
34683
  res.json({ message: "Successfully deleted online form." });
34167
34684
  return;
34168
34685
  } catch (error2) {
34169
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34686
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34170
34687
  next(error2);
34171
34688
  return;
34172
34689
  }
@@ -34178,8 +34695,8 @@ function useOnlineFormController() {
34178
34695
  query.status = req.query.status;
34179
34696
  const { error } = validation.validate(_id);
34180
34697
  if (error) {
34181
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34182
- next(new import_node_server_utils184.BadRequestError(error.message));
34698
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34699
+ next(new import_node_server_utils185.BadRequestError(error.message));
34183
34700
  return;
34184
34701
  }
34185
34702
  try {
@@ -34187,7 +34704,7 @@ function useOnlineFormController() {
34187
34704
  res.json(data);
34188
34705
  return;
34189
34706
  } catch (error2) {
34190
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34707
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34191
34708
  next(error2);
34192
34709
  return;
34193
34710
  }
@@ -34203,14 +34720,14 @@ function useOnlineFormController() {
34203
34720
  }
34204
34721
 
34205
34722
  // src/services/occurrence-subject.service.ts
34206
- var import_node_server_utils185 = require("@7365admin1/node-server-utils");
34723
+ var import_node_server_utils186 = require("@7365admin1/node-server-utils");
34207
34724
  function useOccurrenceSubjectService() {
34208
34725
  const {
34209
34726
  add: _add,
34210
34727
  updateOccurrenceSubjectById: _updateOccurrenceSubjectById
34211
34728
  } = useOccurrenceSubjectRepo();
34212
34729
  async function add(value) {
34213
- const session = import_node_server_utils185.useAtlas.getClient()?.startSession();
34730
+ const session = import_node_server_utils186.useAtlas.getClient()?.startSession();
34214
34731
  session?.startTransaction();
34215
34732
  try {
34216
34733
  await _add(value, session);
@@ -34224,7 +34741,7 @@ function useOccurrenceSubjectService() {
34224
34741
  }
34225
34742
  }
34226
34743
  async function updateOccurrenceSubjectById(id, value) {
34227
- const session = import_node_server_utils185.useAtlas.getClient()?.startSession();
34744
+ const session = import_node_server_utils186.useAtlas.getClient()?.startSession();
34228
34745
  session?.startTransaction();
34229
34746
  try {
34230
34747
  await _updateOccurrenceSubjectById(id, value, session);
@@ -34244,7 +34761,7 @@ function useOccurrenceSubjectService() {
34244
34761
  }
34245
34762
 
34246
34763
  // src/controllers/occurrence-subject.controller.ts
34247
- var import_node_server_utils186 = require("@7365admin1/node-server-utils");
34764
+ var import_node_server_utils187 = require("@7365admin1/node-server-utils");
34248
34765
  var import_joi107 = __toESM(require("joi"));
34249
34766
  function useOccurrenceSubjectController() {
34250
34767
  const {
@@ -34263,8 +34780,8 @@ function useOccurrenceSubjectController() {
34263
34780
  });
34264
34781
  if (error) {
34265
34782
  const messages = error.details.map((d) => d.message).join(", ");
34266
- import_node_server_utils186.logger.log({ level: "error", message: messages });
34267
- next(new import_node_server_utils186.BadRequestError(messages));
34783
+ import_node_server_utils187.logger.log({ level: "error", message: messages });
34784
+ next(new import_node_server_utils187.BadRequestError(messages));
34268
34785
  return;
34269
34786
  }
34270
34787
  try {
@@ -34272,7 +34789,7 @@ function useOccurrenceSubjectController() {
34272
34789
  res.status(201).json(data);
34273
34790
  return;
34274
34791
  } catch (error2) {
34275
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34792
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34276
34793
  next(error2);
34277
34794
  return;
34278
34795
  }
@@ -34294,8 +34811,8 @@ function useOccurrenceSubjectController() {
34294
34811
  });
34295
34812
  if (error) {
34296
34813
  const messages = error.details.map((d) => d.message).join(", ");
34297
- import_node_server_utils186.logger.log({ level: "error", message: messages });
34298
- next(new import_node_server_utils186.BadRequestError(messages));
34814
+ import_node_server_utils187.logger.log({ level: "error", message: messages });
34815
+ next(new import_node_server_utils187.BadRequestError(messages));
34299
34816
  return;
34300
34817
  }
34301
34818
  const search = req.query.search ?? "";
@@ -34322,7 +34839,7 @@ function useOccurrenceSubjectController() {
34322
34839
  res.status(200).json(data);
34323
34840
  return;
34324
34841
  } catch (error2) {
34325
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34842
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34326
34843
  next(error2);
34327
34844
  return;
34328
34845
  }
@@ -34332,8 +34849,8 @@ function useOccurrenceSubjectController() {
34332
34849
  const _id = req.params.id;
34333
34850
  const { error } = validation.validate(_id);
34334
34851
  if (error) {
34335
- import_node_server_utils186.logger.log({ level: "error", message: error.message });
34336
- next(new import_node_server_utils186.BadRequestError(error.message));
34852
+ import_node_server_utils187.logger.log({ level: "error", message: error.message });
34853
+ next(new import_node_server_utils187.BadRequestError(error.message));
34337
34854
  return;
34338
34855
  }
34339
34856
  try {
@@ -34341,7 +34858,7 @@ function useOccurrenceSubjectController() {
34341
34858
  res.status(200).json(data);
34342
34859
  return;
34343
34860
  } catch (error2) {
34344
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34861
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34345
34862
  next(error2);
34346
34863
  return;
34347
34864
  }
@@ -34354,8 +34871,8 @@ function useOccurrenceSubjectController() {
34354
34871
  });
34355
34872
  if (error) {
34356
34873
  const messages = error.details.map((d) => d.message).join(", ");
34357
- import_node_server_utils186.logger.log({ level: "error", message: messages });
34358
- next(new import_node_server_utils186.BadRequestError(messages));
34874
+ import_node_server_utils187.logger.log({ level: "error", message: messages });
34875
+ next(new import_node_server_utils187.BadRequestError(messages));
34359
34876
  return;
34360
34877
  }
34361
34878
  try {
@@ -34363,7 +34880,7 @@ function useOccurrenceSubjectController() {
34363
34880
  res.status(200).json({ message: result });
34364
34881
  return;
34365
34882
  } catch (error2) {
34366
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34883
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34367
34884
  next(error2);
34368
34885
  return;
34369
34886
  }
@@ -34373,8 +34890,8 @@ function useOccurrenceSubjectController() {
34373
34890
  const _id = req.params.id;
34374
34891
  const { error } = validation.validate(_id);
34375
34892
  if (error) {
34376
- import_node_server_utils186.logger.log({ level: "error", message: error.message });
34377
- next(new import_node_server_utils186.BadRequestError(error.message));
34893
+ import_node_server_utils187.logger.log({ level: "error", message: error.message });
34894
+ next(new import_node_server_utils187.BadRequestError(error.message));
34378
34895
  return;
34379
34896
  }
34380
34897
  try {
@@ -34382,7 +34899,7 @@ function useOccurrenceSubjectController() {
34382
34899
  res.status(200).json({ message: "Successfully deleted occurrence subject." });
34383
34900
  return;
34384
34901
  } catch (error2) {
34385
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34902
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34386
34903
  next(error2);
34387
34904
  return;
34388
34905
  }
@@ -34399,7 +34916,7 @@ function useOccurrenceSubjectController() {
34399
34916
  // src/models/nfc-patrol-log.model.ts
34400
34917
  var import_mongodb104 = require("mongodb");
34401
34918
  var import_joi108 = __toESM(require("joi"));
34402
- var import_node_server_utils187 = require("@7365admin1/node-server-utils");
34919
+ var import_node_server_utils188 = require("@7365admin1/node-server-utils");
34403
34920
  var schemaNfcPatrolLog = import_joi108.default.object({
34404
34921
  _id: import_joi108.default.string().length(24).hex().optional().allow(null, ""),
34405
34922
  site: import_joi108.default.string().length(24).hex().required(),
@@ -34444,33 +34961,33 @@ var schemaNfcPatrolLog = import_joi108.default.object({
34444
34961
  function MNfcPatrolLog(valueArg) {
34445
34962
  const { error, value } = schemaNfcPatrolLog.validate(valueArg);
34446
34963
  if (error) {
34447
- import_node_server_utils187.logger.info(`NFC Patrol Log Model: ${error.message}`);
34448
- throw new import_node_server_utils187.BadRequestError(error.message);
34964
+ import_node_server_utils188.logger.info(`NFC Patrol Log Model: ${error.message}`);
34965
+ throw new import_node_server_utils188.BadRequestError(error.message);
34449
34966
  }
34450
34967
  if (value._id && typeof value._id === "string") {
34451
34968
  try {
34452
34969
  value._id = new import_mongodb104.ObjectId(value._id);
34453
34970
  } catch (error2) {
34454
- throw new import_node_server_utils187.BadRequestError("Invalid _id format");
34971
+ throw new import_node_server_utils188.BadRequestError("Invalid _id format");
34455
34972
  }
34456
34973
  }
34457
34974
  try {
34458
34975
  value.site = new import_mongodb104.ObjectId(value.site);
34459
34976
  } catch (error2) {
34460
- throw new import_node_server_utils187.BadRequestError("Invalid site format");
34977
+ throw new import_node_server_utils188.BadRequestError("Invalid site format");
34461
34978
  }
34462
34979
  if (value?.createdBy) {
34463
34980
  try {
34464
34981
  value.createdBy = new import_mongodb104.ObjectId(value.createdBy);
34465
34982
  } catch (error2) {
34466
- throw new import_node_server_utils187.BadRequestError("Invalid createdBy format");
34983
+ throw new import_node_server_utils188.BadRequestError("Invalid createdBy format");
34467
34984
  }
34468
34985
  }
34469
34986
  if (value?.route?._id) {
34470
34987
  try {
34471
34988
  value.route._id = new import_mongodb104.ObjectId(value.route._id);
34472
34989
  } catch (error2) {
34473
- throw new import_node_server_utils187.BadRequestError("Invalid route _id format");
34990
+ throw new import_node_server_utils188.BadRequestError("Invalid route _id format");
34474
34991
  }
34475
34992
  }
34476
34993
  return {
@@ -34487,16 +35004,16 @@ function MNfcPatrolLog(valueArg) {
34487
35004
  }
34488
35005
 
34489
35006
  // src/repositories/nfc-patrol-log.repository.ts
34490
- var import_node_server_utils188 = require("@7365admin1/node-server-utils");
35007
+ var import_node_server_utils189 = require("@7365admin1/node-server-utils");
34491
35008
  var import_mongodb105 = require("mongodb");
34492
35009
  function useNfcPatrolLogRepo() {
34493
- const db = import_node_server_utils188.useAtlas.getDb();
35010
+ const db = import_node_server_utils189.useAtlas.getDb();
34494
35011
  if (!db) {
34495
- throw new import_node_server_utils188.InternalServerError("Unable to connect to server.");
35012
+ throw new import_node_server_utils189.InternalServerError("Unable to connect to server.");
34496
35013
  }
34497
35014
  const namespace_collection = "nfc-patrol-logs";
34498
35015
  const collection = db.collection(namespace_collection);
34499
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils188.useCache)(namespace_collection);
35016
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils189.useCache)(namespace_collection);
34500
35017
  async function createIndexes() {
34501
35018
  try {
34502
35019
  await collection.createIndexes([
@@ -34512,7 +35029,7 @@ function useNfcPatrolLogRepo() {
34512
35029
  }
34513
35030
  ]);
34514
35031
  } catch (error) {
34515
- throw new import_node_server_utils188.InternalServerError(
35032
+ throw new import_node_server_utils189.InternalServerError(
34516
35033
  `Failed to create index on ${namespace_collection}.`
34517
35034
  );
34518
35035
  }
@@ -34526,7 +35043,7 @@ function useNfcPatrolLogRepo() {
34526
35043
  } catch (error) {
34527
35044
  const isDuplicated = error.message.includes("duplicate");
34528
35045
  if (isDuplicated) {
34529
- throw new import_node_server_utils188.BadRequestError("NFC Patrol Log already exists.");
35046
+ throw new import_node_server_utils189.BadRequestError("NFC Patrol Log already exists.");
34530
35047
  }
34531
35048
  throw error;
34532
35049
  }
@@ -34543,7 +35060,7 @@ function useNfcPatrolLogRepo() {
34543
35060
  try {
34544
35061
  siteId = typeof site === "string" ? new import_mongodb105.ObjectId(site) : site;
34545
35062
  } catch {
34546
- throw new import_node_server_utils188.BadRequestError("Invalid site ID format.");
35063
+ throw new import_node_server_utils189.BadRequestError("Invalid site ID format.");
34547
35064
  }
34548
35065
  const query = {
34549
35066
  site: siteId
@@ -34570,10 +35087,10 @@ function useNfcPatrolLogRepo() {
34570
35087
  if (route?.startTime) {
34571
35088
  cacheOptions.routeStartTime = route?.startTime;
34572
35089
  }
34573
- const cacheKey = (0, import_node_server_utils188.makeCacheKey)(namespace_collection, cacheOptions);
35090
+ const cacheKey = (0, import_node_server_utils189.makeCacheKey)(namespace_collection, cacheOptions);
34574
35091
  const cachedData = await getCache(cacheKey);
34575
35092
  if (cachedData) {
34576
- import_node_server_utils188.logger.info(`Cache hit for key: ${cacheKey}`);
35093
+ import_node_server_utils189.logger.info(`Cache hit for key: ${cacheKey}`);
34577
35094
  return cachedData;
34578
35095
  }
34579
35096
  try {
@@ -34587,11 +35104,11 @@ function useNfcPatrolLogRepo() {
34587
35104
  { session }
34588
35105
  ).toArray();
34589
35106
  const length = await collection.countDocuments(query, { session });
34590
- const data = (0, import_node_server_utils188.paginate)(items, pageIndex, limit, length);
35107
+ const data = (0, import_node_server_utils189.paginate)(items, pageIndex, limit, length);
34591
35108
  setCache(cacheKey, data, 15 * 60).then(() => {
34592
- import_node_server_utils188.logger.info(`Cache set for key: ${cacheKey}`);
35109
+ import_node_server_utils189.logger.info(`Cache set for key: ${cacheKey}`);
34593
35110
  }).catch((err) => {
34594
- import_node_server_utils188.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
35111
+ import_node_server_utils189.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34595
35112
  });
34596
35113
  return data;
34597
35114
  } catch (error) {
@@ -34600,12 +35117,12 @@ function useNfcPatrolLogRepo() {
34600
35117
  }
34601
35118
  function delCachedData() {
34602
35119
  delNamespace().then(() => {
34603
- import_node_server_utils188.logger.log({
35120
+ import_node_server_utils189.logger.log({
34604
35121
  level: "info",
34605
35122
  message: `Cache namespace cleared for ${namespace_collection}`
34606
35123
  });
34607
35124
  }).catch((err) => {
34608
- import_node_server_utils188.logger.log({
35125
+ import_node_server_utils189.logger.log({
34609
35126
  level: "error",
34610
35127
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
34611
35128
  });
@@ -34619,11 +35136,11 @@ function useNfcPatrolLogRepo() {
34619
35136
  }
34620
35137
 
34621
35138
  // src/services/nfc-patrol-log.service.ts
34622
- var import_node_server_utils189 = require("@7365admin1/node-server-utils");
35139
+ var import_node_server_utils190 = require("@7365admin1/node-server-utils");
34623
35140
  function useNfcPatrolLogService() {
34624
35141
  const { add: _add } = useNfcPatrolLogRepo();
34625
35142
  async function add(value) {
34626
- const session = import_node_server_utils189.useAtlas.getClient()?.startSession();
35143
+ const session = import_node_server_utils190.useAtlas.getClient()?.startSession();
34627
35144
  session?.startTransaction();
34628
35145
  try {
34629
35146
  await _add(value, session);
@@ -34642,7 +35159,7 @@ function useNfcPatrolLogService() {
34642
35159
  }
34643
35160
 
34644
35161
  // src/controllers/nfc-patrol-log.controller.ts
34645
- var import_node_server_utils190 = require("@7365admin1/node-server-utils");
35162
+ var import_node_server_utils191 = require("@7365admin1/node-server-utils");
34646
35163
  var import_joi109 = __toESM(require("joi"));
34647
35164
  function useNfcPatrolLogController() {
34648
35165
  const { add: _add } = useNfcPatrolLogService();
@@ -34654,7 +35171,7 @@ function useNfcPatrolLogController() {
34654
35171
  res.status(201).json(data);
34655
35172
  return;
34656
35173
  } catch (error) {
34657
- import_node_server_utils190.logger.log({ level: "error", message: error.message });
35174
+ import_node_server_utils191.logger.log({ level: "error", message: error.message });
34658
35175
  next(error);
34659
35176
  return;
34660
35177
  }
@@ -34687,8 +35204,8 @@ function useNfcPatrolLogController() {
34687
35204
  });
34688
35205
  if (error) {
34689
35206
  const messages = error.details.map((d) => d.message).join(", ");
34690
- import_node_server_utils190.logger.log({ level: "error", message: messages });
34691
- next(new import_node_server_utils190.BadRequestError(messages));
35207
+ import_node_server_utils191.logger.log({ level: "error", message: messages });
35208
+ next(new import_node_server_utils191.BadRequestError(messages));
34692
35209
  return;
34693
35210
  }
34694
35211
  const { page, limit, site, date, route } = value;
@@ -34703,7 +35220,7 @@ function useNfcPatrolLogController() {
34703
35220
  res.status(200).json(data);
34704
35221
  return;
34705
35222
  } catch (error2) {
34706
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
35223
+ import_node_server_utils191.logger.log({ level: "error", message: error2.message });
34707
35224
  next(error2);
34708
35225
  return;
34709
35226
  }