@7365admin1/core 2.10.0 → 2.11.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}`);
1505
1517
  }).catch((err) => {
1506
- import_node_server_utils7.logger.error(`Failed to delete cache for key: ${cacheKey}`, 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`);
1525
+ }).catch((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}`);
1587
+ }).catch((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`);
1561
1595
  }).catch((err) => {
1562
- import_node_server_utils7.logger.error(`Failed to delete cache for key: ${cacheKey}`, 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}`);
1592
1625
  }).catch((err) => {
1593
- import_node_server_utils7.logger.error(`Failed to delete cache for key: ${cacheKey}`, 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`);
1633
+ }).catch((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
 
@@ -5838,6 +5913,16 @@ function useFileRepo() {
5838
5913
  const namespace_collection = "files";
5839
5914
  const collection = db.collection(namespace_collection);
5840
5915
  const { delNamespace, getCache, setCache } = (0, import_node_server_utils24.useCache)(namespace_collection);
5916
+ async function createIndex() {
5917
+ try {
5918
+ await collection.createIndexes([
5919
+ { key: { createdAt: 1 } },
5920
+ { key: { status: 1 } }
5921
+ ]);
5922
+ } catch (error) {
5923
+ throw new import_node_server_utils24.InternalServerError("Failed to create index on feedback.");
5924
+ }
5925
+ }
5841
5926
  async function createFile(value, session) {
5842
5927
  try {
5843
5928
  value = new MFile(value);
@@ -5966,7 +6051,8 @@ function useFileRepo() {
5966
6051
  deleteFileById,
5967
6052
  getAllDraftedFiles,
5968
6053
  updateStatusById,
5969
- getFileById
6054
+ getFileById,
6055
+ createIndex
5970
6056
  };
5971
6057
  }
5972
6058
 
@@ -27492,22 +27578,31 @@ function UseAccessManagementRepo() {
27492
27578
  throw new Error(error.message);
27493
27579
  }
27494
27580
  }
27581
+ function getAfterSecondSlash(term) {
27582
+ const first = term.indexOf("/");
27583
+ if (first === -1)
27584
+ return "";
27585
+ const second = term.indexOf("/", first + 1);
27586
+ if (second === -1)
27587
+ return "";
27588
+ return term.substring(second + 1).toLowerCase();
27589
+ }
27495
27590
  function buildSearchQuery(search) {
27496
27591
  if (!search) {
27497
27592
  return {};
27498
27593
  }
27499
27594
  const terms = search.split("/").map((s) => s.trim()).filter(Boolean);
27500
- if (search.includes("/") && terms.length <= 3) {
27501
- switch (terms.length) {
27502
- case 3:
27595
+ if (search.includes("/")) {
27596
+ switch (true) {
27597
+ case terms.length >= 3:
27503
27598
  return {
27504
27599
  $and: [
27505
27600
  { $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
27506
27601
  { $expr: { $eq: [{ $toLower: "$level.level" }, terms[1].toLowerCase()] } },
27507
- { $expr: { $eq: [{ $toLower: "$level.units.name" }, terms[2].toLowerCase()] } }
27602
+ { $expr: { $eq: [{ $toLower: "$level.units.name" }, getAfterSecondSlash(search)] } }
27508
27603
  ]
27509
27604
  };
27510
- case 2:
27605
+ case terms.length === 2:
27511
27606
  return {
27512
27607
  $and: [
27513
27608
  { $expr: { $eq: [{ $toLower: "$name" }, terms[0].toLowerCase()] } },
@@ -27738,6 +27833,172 @@ function UseAccessManagementRepo() {
27738
27833
  throw new Error(error.message);
27739
27834
  }
27740
27835
  }
27836
+ async function assignedAccessCardsRepo(params) {
27837
+ try {
27838
+ const site = new import_mongodb83.ObjectId(params.site);
27839
+ const userType = params.userType;
27840
+ const type = params.type;
27841
+ const search = params.search;
27842
+ const query = {
27843
+ site: { $in: [site] }
27844
+ };
27845
+ const searchQuery = buildSearchQuery(search);
27846
+ const result = await collectionName("buildings").aggregate([
27847
+ // ✅ Match early with index-friendly query
27848
+ {
27849
+ $match: {
27850
+ ...query,
27851
+ status: { $ne: "deleted" }
27852
+ }
27853
+ },
27854
+ // ✅ Only project needed fields before heavy lookups
27855
+ {
27856
+ $project: {
27857
+ _id: 1,
27858
+ name: 1,
27859
+ site: 1
27860
+ }
27861
+ },
27862
+ // ✅ Use localField/foreignField for better index usage
27863
+ {
27864
+ $lookup: {
27865
+ from: "building-levels",
27866
+ localField: "_id",
27867
+ foreignField: "block",
27868
+ pipeline: [
27869
+ { $match: { status: { $ne: "deleted" } } },
27870
+ {
27871
+ $lookup: {
27872
+ from: "building-units",
27873
+ localField: "_id",
27874
+ foreignField: "level",
27875
+ pipeline: [
27876
+ { $match: { status: { $ne: "deleted" } } },
27877
+ { $project: { _id: 1, name: 1 } },
27878
+ {
27879
+ $lookup: {
27880
+ from: "access-cards",
27881
+ localField: "_id",
27882
+ foreignField: "assignedUnit",
27883
+ pipeline: [
27884
+ {
27885
+ $match: {
27886
+ isActivated: true,
27887
+ userType,
27888
+ type
27889
+ }
27890
+ },
27891
+ {
27892
+ $group: {
27893
+ _id: null,
27894
+ accessLevels: { $addToSet: "$accessLevel" },
27895
+ liftAccessLevels: { $addToSet: "$liftAccessLevel" },
27896
+ doorNames: { $addToSet: "$doorName" },
27897
+ liftNames: { $addToSet: "$liftName" },
27898
+ cards: {
27899
+ $push: {
27900
+ _id: "$_id",
27901
+ cardNo: "$cardNo",
27902
+ accessLevel: "$accessLevel",
27903
+ liftAccessLevel: "$liftAccessLevel",
27904
+ doorName: "$doorName",
27905
+ liftName: "$liftName"
27906
+ }
27907
+ }
27908
+ }
27909
+ },
27910
+ {
27911
+ $project: {
27912
+ _id: 0,
27913
+ accessCardCount: {
27914
+ $size: "$cards"
27915
+ },
27916
+ accessLevels: 1,
27917
+ liftAccessLevels: 1,
27918
+ doorNames: 1,
27919
+ liftNames: 1
27920
+ }
27921
+ }
27922
+ ],
27923
+ as: "fAccessCards"
27924
+ }
27925
+ },
27926
+ {
27927
+ $match: {
27928
+ "fAccessCards.0": { $exists: true }
27929
+ }
27930
+ }
27931
+ ],
27932
+ as: "units"
27933
+ }
27934
+ },
27935
+ {
27936
+ $match: { "units.0": { $exists: true } }
27937
+ },
27938
+ {
27939
+ $project: {
27940
+ _id: 1,
27941
+ level: 1,
27942
+ units: 1
27943
+ }
27944
+ }
27945
+ ],
27946
+ as: "level"
27947
+ }
27948
+ },
27949
+ // ✅ Filter out buildings with no levels early
27950
+ {
27951
+ $match: { "level.0": { $exists: true } }
27952
+ },
27953
+ // ✅ Unwind to flatten the hierarchy
27954
+ {
27955
+ $unwind: {
27956
+ path: "$level",
27957
+ preserveNullAndEmptyArrays: false
27958
+ }
27959
+ },
27960
+ {
27961
+ $unwind: {
27962
+ path: "$level.units",
27963
+ preserveNullAndEmptyArrays: false
27964
+ }
27965
+ },
27966
+ {
27967
+ $unwind: {
27968
+ path: "$level.units.fAccessCards",
27969
+ preserveNullAndEmptyArrays: false
27970
+ }
27971
+ },
27972
+ // // Groups by unit _id and keeps only the first occurrence
27973
+ {
27974
+ $group: {
27975
+ _id: "$level.units._id",
27976
+ doc: { $first: "$$ROOT" }
27977
+ }
27978
+ },
27979
+ {
27980
+ $replaceRoot: { newRoot: "$doc" }
27981
+ },
27982
+ // ✅ Apply search filter
27983
+ {
27984
+ $match: {
27985
+ ...searchQuery
27986
+ }
27987
+ },
27988
+ {
27989
+ $project: {
27990
+ name: 1,
27991
+ "level.level": 1,
27992
+ "level.units.name": 1,
27993
+ "level.units.fAccessCards": 1
27994
+ }
27995
+ }
27996
+ ], { allowDiskUse: true }).toArray();
27997
+ return result;
27998
+ } catch (error) {
27999
+ throw new Error(error.message);
28000
+ }
28001
+ }
27741
28002
  return {
27742
28003
  createIndexes,
27743
28004
  createIndexForEntrypass,
@@ -27746,7 +28007,8 @@ function UseAccessManagementRepo() {
27746
28007
  accessManagementSettingsRepo,
27747
28008
  allAccessCardsCountsRepo,
27748
28009
  availableAccessCardsRepo,
27749
- userTypeAccessCardsRepo
28010
+ userTypeAccessCardsRepo,
28011
+ assignedAccessCardsRepo
27750
28012
  };
27751
28013
  }
27752
28014
 
@@ -27851,6 +28113,8 @@ var formatAccessGroup = (data, search) => {
27851
28113
 
27852
28114
  // src/services/access-management.service.ts
27853
28115
  var import_xml2js = require("xml2js");
28116
+ var import_node_server_utils150 = require("@7365admin1/node-server-utils");
28117
+ var namespace = "cache:acm";
27854
28118
  function useAccessManagementSvc() {
27855
28119
  const {
27856
28120
  addPhysicalCardRepo,
@@ -27858,7 +28122,8 @@ function useAccessManagementSvc() {
27858
28122
  accessManagementSettingsRepo,
27859
28123
  allAccessCardsCountsRepo,
27860
28124
  availableAccessCardsRepo,
27861
- userTypeAccessCardsRepo
28125
+ userTypeAccessCardsRepo,
28126
+ assignedAccessCardsRepo
27862
28127
  } = UseAccessManagementRepo();
27863
28128
  const addPhysicalCardSvc = async (payload) => {
27864
28129
  try {
@@ -27876,12 +28141,34 @@ function useAccessManagementSvc() {
27876
28141
  throw new Error(err.message);
27877
28142
  }
27878
28143
  };
28144
+ const setCache = async (params) => {
28145
+ const { key, data, ttlSeconds = 60, redis } = params;
28146
+ const jsonData = JSON.stringify(data);
28147
+ await redis.set(key, jsonData, "EX", ttlSeconds);
28148
+ };
28149
+ const getCache = async (params) => {
28150
+ const { key, redis } = params;
28151
+ const result = await redis.get(key);
28152
+ return result ? JSON.parse(result) : null;
28153
+ };
27879
28154
  const doorAccessLevelsSvc = async (params) => {
27880
28155
  try {
28156
+ const key = `${namespace}:${params.user}:door-levels`;
28157
+ const listKey = `${namespace}:${params.user}:list`;
28158
+ const { redis } = (0, import_node_server_utils150.useCache)(key);
28159
+ const cachedData = await getCache({ key, redis });
28160
+ if (cachedData) {
28161
+ console.log("\u26A1 Cache hit:", key);
28162
+ redis.expire(key, 60).catch(console.error);
28163
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
28164
+ return cachedData;
28165
+ }
27881
28166
  const command = readTemplate("door-levels");
27882
28167
  const response = await sendCommand(command, params.acm_url);
27883
28168
  const res = await (0, import_xml2js.parseStringPromise)(response, { explicitArray: false });
27884
28169
  const format = await formatDoorAccessLevels(res);
28170
+ await setCache({ key, data: format, ttlSeconds: 60, redis });
28171
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
27885
28172
  return format;
27886
28173
  } catch (err) {
27887
28174
  throw new Error(err.message);
@@ -27889,10 +28176,22 @@ function useAccessManagementSvc() {
27889
28176
  };
27890
28177
  const liftAccessLevelsSvc = async (params) => {
27891
28178
  try {
28179
+ const key = `${namespace}:${params.user}:lift-levels`;
28180
+ const listKey = `${namespace}:${params.user}:list`;
28181
+ const { redis } = (0, import_node_server_utils150.useCache)(key);
28182
+ const cachedData = await getCache({ key, redis });
28183
+ if (cachedData) {
28184
+ console.log("\u26A1 Cache hit:", key);
28185
+ redis.expire(key, 60).catch(console.error);
28186
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
28187
+ return cachedData;
28188
+ }
27892
28189
  const command = readTemplate("lift-levels");
27893
28190
  const response = await sendCommand(command, params.acm_url);
27894
28191
  const res = await (0, import_xml2js.parseStringPromise)(response, { explicitArray: false });
27895
28192
  const format = await formatLiftAccessLevels(res);
28193
+ await setCache({ key, data: format, ttlSeconds: 60, redis });
28194
+ redis.lrem(listKey, 0, key).then(() => redis.lpush(listKey, key)).then(() => redis.ltrim(listKey, 0, 9)).catch(console.error);
27896
28195
  return format;
27897
28196
  } catch (error) {
27898
28197
  throw new Error(error.message);
@@ -27941,6 +28240,14 @@ function useAccessManagementSvc() {
27941
28240
  throw new Error(err.message);
27942
28241
  }
27943
28242
  };
28243
+ const assignedAccessCardsSvc = async (params) => {
28244
+ try {
28245
+ const response = await assignedAccessCardsRepo({ ...params });
28246
+ return response;
28247
+ } catch (err) {
28248
+ throw new Error(err.message);
28249
+ }
28250
+ };
27944
28251
  return {
27945
28252
  addPhysicalCardSvc,
27946
28253
  addNonPhysicalCardSvc,
@@ -27950,7 +28257,8 @@ function useAccessManagementSvc() {
27950
28257
  accessManagementSettingsSvc,
27951
28258
  allAccessCardsCountsSvc,
27952
28259
  availableAccessCardsSvc,
27953
- userTypeAccessCardsSvc
28260
+ userTypeAccessCardsSvc,
28261
+ assignedAccessCardsSvc
27954
28262
  };
27955
28263
  }
27956
28264
 
@@ -27965,7 +28273,8 @@ function useAccessManagementController() {
27965
28273
  accessManagementSettingsSvc,
27966
28274
  allAccessCardsCountsSvc,
27967
28275
  availableAccessCardsSvc,
27968
- userTypeAccessCardsSvc
28276
+ userTypeAccessCardsSvc,
28277
+ assignedAccessCardsSvc
27969
28278
  } = useAccessManagementSvc();
27970
28279
  const addPhysicalCard = async (req, res) => {
27971
28280
  try {
@@ -28096,10 +28405,11 @@ function useAccessManagementController() {
28096
28405
  const doorAccessLevels = async (req, res) => {
28097
28406
  try {
28098
28407
  const { acm_url } = req.query;
28408
+ const user = req.cookies?.sid;
28099
28409
  if (!acm_url || typeof acm_url !== "string") {
28100
28410
  throw new Error("Access Control URL is required");
28101
28411
  }
28102
- const result = await doorAccessLevelsSvc({ acm_url });
28412
+ const result = await doorAccessLevelsSvc({ acm_url, user });
28103
28413
  return res.status(200).json({ message: "Success", data: result });
28104
28414
  } catch (error) {
28105
28415
  return res.status(400).json({
@@ -28111,10 +28421,11 @@ function useAccessManagementController() {
28111
28421
  const liftAccessLevels = async (req, res) => {
28112
28422
  try {
28113
28423
  const { acm_url } = req.query;
28424
+ const user = req.cookies?.sid;
28114
28425
  if (!acm_url || typeof acm_url !== "string") {
28115
28426
  throw new Error("Access Control URL is required");
28116
28427
  }
28117
- const result = await liftAccessLevelsSvc({ acm_url });
28428
+ const result = await liftAccessLevelsSvc({ acm_url, user });
28118
28429
  return res.status(200).json({ message: "Success", data: result });
28119
28430
  } catch (error) {
28120
28431
  return res.status(400).json({
@@ -28222,6 +28533,28 @@ function useAccessManagementController() {
28222
28533
  });
28223
28534
  }
28224
28535
  };
28536
+ const assignedAccessCards = async (req, res) => {
28537
+ try {
28538
+ const { site, userType, type, search = "" } = req.query;
28539
+ const schema2 = import_joi85.default.object({
28540
+ site: import_joi85.default.string().hex().required(),
28541
+ userType: import_joi85.default.string().required(),
28542
+ type: import_joi85.default.string().required(),
28543
+ search: import_joi85.default.string().optional().allow("", null)
28544
+ });
28545
+ const { error } = schema2.validate({ site, userType, type, search });
28546
+ if (error) {
28547
+ return res.status(400).json({ message: error.message });
28548
+ }
28549
+ const result = await assignedAccessCardsSvc({ site, userType, type, search });
28550
+ return res.status(200).json({ message: "Success", data: result });
28551
+ } catch (error) {
28552
+ return res.status(500).json({
28553
+ data: null,
28554
+ message: error.message
28555
+ });
28556
+ }
28557
+ };
28225
28558
  return {
28226
28559
  addPhysicalCard,
28227
28560
  addNonPhysicalCard,
@@ -28231,14 +28564,15 @@ function useAccessManagementController() {
28231
28564
  accessManagementSettings,
28232
28565
  allAccessCardsCounts,
28233
28566
  availableAccessCards,
28234
- userTypeAccessCards
28567
+ userTypeAccessCards,
28568
+ assignedAccessCards
28235
28569
  };
28236
28570
  }
28237
28571
 
28238
28572
  // src/models/nfc-patrol-tag.model.ts
28239
28573
  var import_mongodb84 = require("mongodb");
28240
28574
  var import_joi86 = __toESM(require("joi"));
28241
- var import_node_server_utils150 = require("@7365admin1/node-server-utils");
28575
+ var import_node_server_utils151 = require("@7365admin1/node-server-utils");
28242
28576
  var DEVICE_STATUS = {
28243
28577
  CONFIGURED: "Configured",
28244
28578
  NOT_CONFIGURED: "Not Configured"
@@ -28265,21 +28599,21 @@ function MNfcPatrolTag(value) {
28265
28599
  try {
28266
28600
  value._id = new import_mongodb84.ObjectId(value._id);
28267
28601
  } catch {
28268
- throw new import_node_server_utils150.BadRequestError("Invalid ID.");
28602
+ throw new import_node_server_utils151.BadRequestError("Invalid ID.");
28269
28603
  }
28270
28604
  }
28271
28605
  if (value.site && typeof value.site === "string") {
28272
28606
  try {
28273
28607
  value.site = new import_mongodb84.ObjectId(value.site);
28274
28608
  } catch {
28275
- throw new import_node_server_utils150.BadRequestError("Invalid site ID.");
28609
+ throw new import_node_server_utils151.BadRequestError("Invalid site ID.");
28276
28610
  }
28277
28611
  }
28278
28612
  if (value.createdBy && typeof value.createdBy === "string") {
28279
28613
  try {
28280
28614
  value.createdBy = new import_mongodb84.ObjectId(value.createdBy);
28281
28615
  } catch {
28282
- throw new import_node_server_utils150.BadRequestError("Invalid Created By ID.");
28616
+ throw new import_node_server_utils151.BadRequestError("Invalid Created By ID.");
28283
28617
  }
28284
28618
  }
28285
28619
  return {
@@ -28294,18 +28628,18 @@ function MNfcPatrolTag(value) {
28294
28628
  }
28295
28629
 
28296
28630
  // src/repositories/nfc-patrol-tag.repository.ts
28297
- var import_node_server_utils151 = require("@7365admin1/node-server-utils");
28631
+ var import_node_server_utils152 = require("@7365admin1/node-server-utils");
28298
28632
  var import_mongodb85 = require("mongodb");
28299
28633
  function useNfcPatrolTagRepo() {
28300
- const db = import_node_server_utils151.useAtlas.getDb();
28634
+ const db = import_node_server_utils152.useAtlas.getDb();
28301
28635
  if (!db) {
28302
- throw new import_node_server_utils151.InternalServerError("Unable to connect to server.");
28636
+ throw new import_node_server_utils152.InternalServerError("Unable to connect to server.");
28303
28637
  }
28304
28638
  const namespace_collection = "nfc-patrol-tags";
28305
28639
  const namespace_collection_nfc_patrol_routes = "nfc-patrol-routes";
28306
28640
  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)(
28641
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils152.useCache)(namespace_collection);
28642
+ const { delNamespace: delNamespaceNfcPatrolRoutes } = (0, import_node_server_utils152.useCache)(
28309
28643
  namespace_collection_nfc_patrol_routes
28310
28644
  );
28311
28645
  async function createIndexes() {
@@ -28321,7 +28655,7 @@ function useNfcPatrolTagRepo() {
28321
28655
  { key: { site: 1 } }
28322
28656
  ]);
28323
28657
  } catch (error) {
28324
- throw new import_node_server_utils151.InternalServerError(
28658
+ throw new import_node_server_utils152.InternalServerError(
28325
28659
  "Failed to create index on nfc patrol tags."
28326
28660
  );
28327
28661
  }
@@ -28335,7 +28669,7 @@ function useNfcPatrolTagRepo() {
28335
28669
  } catch (error) {
28336
28670
  const isDuplicated = error.message.includes("duplicate");
28337
28671
  if (isDuplicated) {
28338
- throw new import_node_server_utils151.BadRequestError(
28672
+ throw new import_node_server_utils152.BadRequestError(
28339
28673
  "NFC Patrol Tag ID and or Name already exists."
28340
28674
  );
28341
28675
  }
@@ -28351,7 +28685,7 @@ function useNfcPatrolTagRepo() {
28351
28685
  try {
28352
28686
  site = new import_mongodb85.ObjectId(site);
28353
28687
  } catch (error) {
28354
- throw new import_node_server_utils151.BadRequestError("Invalid site ID format.");
28688
+ throw new import_node_server_utils152.BadRequestError("Invalid site ID format.");
28355
28689
  }
28356
28690
  const query = {
28357
28691
  site
@@ -28361,10 +28695,10 @@ function useNfcPatrolTagRepo() {
28361
28695
  page,
28362
28696
  limit
28363
28697
  };
28364
- const cacheKey = (0, import_node_server_utils151.makeCacheKey)(namespace_collection, cacheOptions);
28698
+ const cacheKey = (0, import_node_server_utils152.makeCacheKey)(namespace_collection, cacheOptions);
28365
28699
  const cachedData = await getCache(cacheKey);
28366
28700
  if (cachedData) {
28367
- import_node_server_utils151.logger.info(`Cache hit for key: ${cacheKey}`);
28701
+ import_node_server_utils152.logger.info(`Cache hit for key: ${cacheKey}`);
28368
28702
  return cachedData;
28369
28703
  }
28370
28704
  try {
@@ -28378,11 +28712,11 @@ function useNfcPatrolTagRepo() {
28378
28712
  { session }
28379
28713
  ).toArray();
28380
28714
  const length = await collection.countDocuments(query, { session });
28381
- const data = (0, import_node_server_utils151.paginate)(items, page, limit, length);
28715
+ const data = (0, import_node_server_utils152.paginate)(items, page, limit, length);
28382
28716
  setCache(cacheKey, data, 15 * 60).then(() => {
28383
- import_node_server_utils151.logger.info(`Cache set for key: ${cacheKey}`);
28717
+ import_node_server_utils152.logger.info(`Cache set for key: ${cacheKey}`);
28384
28718
  }).catch((err) => {
28385
- import_node_server_utils151.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
28719
+ import_node_server_utils152.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
28386
28720
  });
28387
28721
  return data;
28388
28722
  } catch (error) {
@@ -28395,19 +28729,19 @@ function useNfcPatrolTagRepo() {
28395
28729
  try {
28396
28730
  findObject.site = new import_mongodb85.ObjectId(findObject.site);
28397
28731
  } catch {
28398
- throw new import_node_server_utils151.BadRequestError("Invalid site ID.");
28732
+ throw new import_node_server_utils152.BadRequestError("Invalid site ID.");
28399
28733
  }
28400
28734
  }
28401
28735
  if (updateType == "Edit" && findObject?._id && typeof findObject._id === "string") {
28402
28736
  try {
28403
28737
  findObject._id = new import_mongodb85.ObjectId(findObject._id);
28404
28738
  } catch {
28405
- throw new import_node_server_utils151.BadRequestError("Invalid nfc patrol tag document ID.");
28739
+ throw new import_node_server_utils152.BadRequestError("Invalid nfc patrol tag document ID.");
28406
28740
  }
28407
28741
  try {
28408
28742
  setData.updatedBy = new import_mongodb85.ObjectId(setData.updatedBy);
28409
28743
  } catch {
28410
- throw new import_node_server_utils151.BadRequestError("Invalid updatedBy ID.");
28744
+ throw new import_node_server_utils152.BadRequestError("Invalid updatedBy ID.");
28411
28745
  }
28412
28746
  }
28413
28747
  const historyEntry = {
@@ -28433,7 +28767,7 @@ function useNfcPatrolTagRepo() {
28433
28767
  session
28434
28768
  });
28435
28769
  if (res.modifiedCount === 0) {
28436
- throw new import_node_server_utils151.InternalServerError(
28770
+ throw new import_node_server_utils152.InternalServerError(
28437
28771
  `Unable to ${updateType} NFC Patrol Tag.`
28438
28772
  );
28439
28773
  }
@@ -28448,12 +28782,12 @@ function useNfcPatrolTagRepo() {
28448
28782
  tagUID: setData?.tagUID
28449
28783
  });
28450
28784
  if (existingDoc) {
28451
- throw new import_node_server_utils151.BadRequestError(
28785
+ throw new import_node_server_utils152.BadRequestError(
28452
28786
  `NFC Patrol Tag is already assigned to ID: ${existingDoc.tagID}. Reset it before reassigning.`
28453
28787
  );
28454
28788
  }
28455
28789
  } else {
28456
- throw new import_node_server_utils151.BadRequestError(
28790
+ throw new import_node_server_utils152.BadRequestError(
28457
28791
  "NFC Patrol Tag ID and or Name already exists."
28458
28792
  );
28459
28793
  }
@@ -28463,23 +28797,23 @@ function useNfcPatrolTagRepo() {
28463
28797
  }
28464
28798
  function delCachedData() {
28465
28799
  delNamespace().then(() => {
28466
- import_node_server_utils151.logger.log({
28800
+ import_node_server_utils152.logger.log({
28467
28801
  level: "info",
28468
28802
  message: `Cache namespace cleared for ${namespace_collection}`
28469
28803
  });
28470
28804
  }).catch((err) => {
28471
- import_node_server_utils151.logger.log({
28805
+ import_node_server_utils152.logger.log({
28472
28806
  level: "error",
28473
28807
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
28474
28808
  });
28475
28809
  });
28476
28810
  delNamespaceNfcPatrolRoutes().then(() => {
28477
- import_node_server_utils151.logger.log({
28811
+ import_node_server_utils152.logger.log({
28478
28812
  level: "info",
28479
28813
  message: `Cache namespace cleared for ${namespace_collection}`
28480
28814
  });
28481
28815
  }).catch((err) => {
28482
- import_node_server_utils151.logger.log({
28816
+ import_node_server_utils152.logger.log({
28483
28817
  level: "error",
28484
28818
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
28485
28819
  });
@@ -28494,11 +28828,11 @@ function useNfcPatrolTagRepo() {
28494
28828
  }
28495
28829
 
28496
28830
  // src/services/nfc-patrol-tag.service.ts
28497
- var import_node_server_utils152 = require("@7365admin1/node-server-utils");
28831
+ var import_node_server_utils153 = require("@7365admin1/node-server-utils");
28498
28832
  function useNfcPatrolTagService() {
28499
28833
  const { add: _add, updateNfcPatrolTagBySite: _updateNfcPatrolTagBySite } = useNfcPatrolTagRepo();
28500
28834
  async function add(value) {
28501
- const session = import_node_server_utils152.useAtlas.getClient()?.startSession();
28835
+ const session = import_node_server_utils153.useAtlas.getClient()?.startSession();
28502
28836
  session?.startTransaction();
28503
28837
  try {
28504
28838
  await _add(value, session);
@@ -28512,7 +28846,7 @@ function useNfcPatrolTagService() {
28512
28846
  }
28513
28847
  }
28514
28848
  async function updateNfcPatrolTagBySite(updateType, data) {
28515
- const session = import_node_server_utils152.useAtlas.getClient()?.startSession();
28849
+ const session = import_node_server_utils153.useAtlas.getClient()?.startSession();
28516
28850
  session?.startTransaction();
28517
28851
  try {
28518
28852
  let successMessage = "Successfully Updated the NFC Patrol Tag.";
@@ -28520,11 +28854,11 @@ function useNfcPatrolTagService() {
28520
28854
  case "Configure": {
28521
28855
  const { site, tagID, tagUID } = data;
28522
28856
  if (!tagID)
28523
- throw new import_node_server_utils152.BadRequestError("tagID is required for Configure");
28857
+ throw new import_node_server_utils153.BadRequestError("tagID is required for Configure");
28524
28858
  if (!tagUID)
28525
- throw new import_node_server_utils152.BadRequestError("tagUID is required for Configure");
28859
+ throw new import_node_server_utils153.BadRequestError("tagUID is required for Configure");
28526
28860
  if (!site)
28527
- throw new import_node_server_utils152.BadRequestError("site is required for Configure");
28861
+ throw new import_node_server_utils153.BadRequestError("site is required for Configure");
28528
28862
  const findObject = { site, tagID };
28529
28863
  const setData = { tagUID, status: DEVICE_STATUS.CONFIGURED };
28530
28864
  await _updateNfcPatrolTagBySite(
@@ -28539,9 +28873,9 @@ function useNfcPatrolTagService() {
28539
28873
  case "Reset": {
28540
28874
  const { site, tagID } = data;
28541
28875
  if (!tagID)
28542
- throw new import_node_server_utils152.BadRequestError("tagID is required for Reset");
28876
+ throw new import_node_server_utils153.BadRequestError("tagID is required for Reset");
28543
28877
  if (!site)
28544
- throw new import_node_server_utils152.BadRequestError("site is required for Reset");
28878
+ throw new import_node_server_utils153.BadRequestError("site is required for Reset");
28545
28879
  const findObject = { site, tagID };
28546
28880
  const setData = { status: DEVICE_STATUS.NOT_CONFIGURED };
28547
28881
  await _updateNfcPatrolTagBySite(
@@ -28556,15 +28890,15 @@ function useNfcPatrolTagService() {
28556
28890
  case "Edit": {
28557
28891
  const { tagID, name, _id, site, updatedBy } = data;
28558
28892
  if (!_id)
28559
- throw new import_node_server_utils152.BadRequestError("_id is required for Edit");
28893
+ throw new import_node_server_utils153.BadRequestError("_id is required for Edit");
28560
28894
  if (!site)
28561
- throw new import_node_server_utils152.BadRequestError("site is required for Edit");
28895
+ throw new import_node_server_utils153.BadRequestError("site is required for Edit");
28562
28896
  if (!tagID)
28563
- throw new import_node_server_utils152.BadRequestError("tagID is required for Edit");
28897
+ throw new import_node_server_utils153.BadRequestError("tagID is required for Edit");
28564
28898
  if (!name)
28565
- throw new import_node_server_utils152.BadRequestError("name is required for Edit");
28899
+ throw new import_node_server_utils153.BadRequestError("name is required for Edit");
28566
28900
  if (!updatedBy)
28567
- throw new import_node_server_utils152.BadRequestError("updatedBy is required for Edit");
28901
+ throw new import_node_server_utils153.BadRequestError("updatedBy is required for Edit");
28568
28902
  const findObject = { _id, site };
28569
28903
  const setData = { name, tagID, updatedBy };
28570
28904
  await _updateNfcPatrolTagBySite(
@@ -28576,7 +28910,7 @@ function useNfcPatrolTagService() {
28576
28910
  break;
28577
28911
  }
28578
28912
  default:
28579
- throw new import_node_server_utils152.BadRequestError(`Invalid updateType: ${updateType}`);
28913
+ throw new import_node_server_utils153.BadRequestError(`Invalid updateType: ${updateType}`);
28580
28914
  }
28581
28915
  await session?.commitTransaction();
28582
28916
  return successMessage;
@@ -28594,7 +28928,7 @@ function useNfcPatrolTagService() {
28594
28928
  }
28595
28929
 
28596
28930
  // src/controllers/nfc-patrol-tag.controller.ts
28597
- var import_node_server_utils153 = require("@7365admin1/node-server-utils");
28931
+ var import_node_server_utils154 = require("@7365admin1/node-server-utils");
28598
28932
  var import_joi87 = __toESM(require("joi"));
28599
28933
  function useNfcPatrolTagController() {
28600
28934
  const { add: _add, updateNfcPatrolTagBySite: _updateNfcPatrolTagBySite } = useNfcPatrolTagService();
@@ -28611,8 +28945,8 @@ function useNfcPatrolTagController() {
28611
28945
  });
28612
28946
  if (error) {
28613
28947
  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));
28948
+ import_node_server_utils154.logger.log({ level: "error", message: messages });
28949
+ next(new import_node_server_utils154.BadRequestError(messages));
28616
28950
  return;
28617
28951
  }
28618
28952
  try {
@@ -28620,7 +28954,7 @@ function useNfcPatrolTagController() {
28620
28954
  res.status(201).json(data);
28621
28955
  return;
28622
28956
  } catch (error2) {
28623
- import_node_server_utils153.logger.log({ level: "error", message: error2.message });
28957
+ import_node_server_utils154.logger.log({ level: "error", message: error2.message });
28624
28958
  next(error2);
28625
28959
  return;
28626
28960
  }
@@ -28637,8 +28971,8 @@ function useNfcPatrolTagController() {
28637
28971
  });
28638
28972
  if (error) {
28639
28973
  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));
28974
+ import_node_server_utils154.logger.log({ level: "error", message: messages });
28975
+ next(new import_node_server_utils154.BadRequestError(messages));
28642
28976
  return;
28643
28977
  }
28644
28978
  const page = parseInt(req.query.page ?? "1");
@@ -28653,7 +28987,7 @@ function useNfcPatrolTagController() {
28653
28987
  res.status(200).json(data);
28654
28988
  return;
28655
28989
  } catch (error2) {
28656
- import_node_server_utils153.logger.log({ level: "error", message: error2.message });
28990
+ import_node_server_utils154.logger.log({ level: "error", message: error2.message });
28657
28991
  next(error2);
28658
28992
  return;
28659
28993
  }
@@ -28670,8 +29004,8 @@ function useNfcPatrolTagController() {
28670
29004
  });
28671
29005
  if (error) {
28672
29006
  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));
29007
+ import_node_server_utils154.logger.log({ level: "error", message: messages });
29008
+ next(new import_node_server_utils154.BadRequestError(messages));
28675
29009
  return;
28676
29010
  }
28677
29011
  try {
@@ -28683,7 +29017,7 @@ function useNfcPatrolTagController() {
28683
29017
  res.status(200).json({ message: result });
28684
29018
  return;
28685
29019
  } catch (error2) {
28686
- import_node_server_utils153.logger.log({ level: "error", message: error2.message });
29020
+ import_node_server_utils154.logger.log({ level: "error", message: error2.message });
28687
29021
  next(error2);
28688
29022
  return;
28689
29023
  }
@@ -28744,12 +29078,12 @@ function MOccurrenceBook(value) {
28744
29078
  }
28745
29079
 
28746
29080
  // src/repositories/occurrence-book.repo.ts
28747
- var import_node_server_utils154 = require("@7365admin1/node-server-utils");
29081
+ var import_node_server_utils155 = require("@7365admin1/node-server-utils");
28748
29082
  var import_mongodb87 = require("mongodb");
28749
29083
  function useOccurrenceBookRepo() {
28750
- const db = import_node_server_utils154.useAtlas.getDb();
29084
+ const db = import_node_server_utils155.useAtlas.getDb();
28751
29085
  if (!db) {
28752
- throw new import_node_server_utils154.InternalServerError("Unable to connect to server.");
29086
+ throw new import_node_server_utils155.InternalServerError("Unable to connect to server.");
28753
29087
  }
28754
29088
  async function createIndexes() {
28755
29089
  try {
@@ -28757,7 +29091,7 @@ function useOccurrenceBookRepo() {
28757
29091
  { key: { site: 1, status: 1, date: 1, closedAt: 1 } }
28758
29092
  ]);
28759
29093
  } catch (error) {
28760
- throw new import_node_server_utils154.InternalServerError(
29094
+ throw new import_node_server_utils155.InternalServerError(
28761
29095
  "Failed to create index on occurrence books."
28762
29096
  );
28763
29097
  }
@@ -28768,22 +29102,22 @@ function useOccurrenceBookRepo() {
28768
29102
  entryCounter: "text"
28769
29103
  });
28770
29104
  } catch (error) {
28771
- throw new import_node_server_utils154.InternalServerError(
29105
+ throw new import_node_server_utils155.InternalServerError(
28772
29106
  "Failed to create text index on occurrence books."
28773
29107
  );
28774
29108
  }
28775
29109
  }
28776
29110
  const namespace_collection = "occurrence-books";
28777
29111
  const collection = db.collection(namespace_collection);
28778
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils154.useCache)(namespace_collection);
29112
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils155.useCache)(namespace_collection);
28779
29113
  async function add(value, session) {
28780
29114
  try {
28781
29115
  value = MOccurrenceBook(value);
28782
29116
  const res = await collection.insertOne(value, { session });
28783
29117
  delNamespace().then(() => {
28784
- import_node_server_utils154.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29118
+ import_node_server_utils155.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28785
29119
  }).catch((err) => {
28786
- import_node_server_utils154.logger.error(
29120
+ import_node_server_utils155.logger.error(
28787
29121
  `Failed to clear cache for namespace: ${namespace_collection}`,
28788
29122
  err
28789
29123
  );
@@ -28792,7 +29126,7 @@ function useOccurrenceBookRepo() {
28792
29126
  } catch (error) {
28793
29127
  const isDuplicated = error.message.includes("duplicate");
28794
29128
  if (isDuplicated) {
28795
- throw new import_node_server_utils154.BadRequestError("Occurence book already exists.");
29129
+ throw new import_node_server_utils155.BadRequestError("Occurence book already exists.");
28796
29130
  }
28797
29131
  throw error;
28798
29132
  }
@@ -28810,7 +29144,7 @@ function useOccurrenceBookRepo() {
28810
29144
  try {
28811
29145
  site = new import_mongodb87.ObjectId(site);
28812
29146
  } catch (error) {
28813
- throw new import_node_server_utils154.BadRequestError("Invalid site ID format.");
29147
+ throw new import_node_server_utils155.BadRequestError("Invalid site ID format.");
28814
29148
  }
28815
29149
  const query = {
28816
29150
  site,
@@ -28830,10 +29164,10 @@ function useOccurrenceBookRepo() {
28830
29164
  if (typeof date === "string") {
28831
29165
  const [day, month, year] = date.split("/").map(Number);
28832
29166
  if (!day || !month || !year) {
28833
- throw new import_node_server_utils154.BadRequestError("Invalid date format. Use DD/MM/YYYY.");
29167
+ throw new import_node_server_utils155.BadRequestError("Invalid date format. Use DD/MM/YYYY.");
28834
29168
  }
28835
29169
  if (day > 31 || month > 12) {
28836
- throw new import_node_server_utils154.BadRequestError("Invalid date value.");
29170
+ throw new import_node_server_utils155.BadRequestError("Invalid date value.");
28837
29171
  }
28838
29172
  dateObj = new Date(Date.UTC(year, month - 1, day));
28839
29173
  } else {
@@ -28867,10 +29201,10 @@ function useOccurrenceBookRepo() {
28867
29201
  query.$text = { $search: search };
28868
29202
  cacheOptions.search = search;
28869
29203
  }
28870
- const cacheKey = (0, import_node_server_utils154.makeCacheKey)(namespace_collection, cacheOptions);
29204
+ const cacheKey = (0, import_node_server_utils155.makeCacheKey)(namespace_collection, cacheOptions);
28871
29205
  const cachedData = await getCache(cacheKey);
28872
29206
  if (cachedData) {
28873
- import_node_server_utils154.logger.info(`Cache hit for key: ${cacheKey}`);
29207
+ import_node_server_utils155.logger.info(`Cache hit for key: ${cacheKey}`);
28874
29208
  return cachedData;
28875
29209
  }
28876
29210
  try {
@@ -28884,11 +29218,11 @@ function useOccurrenceBookRepo() {
28884
29218
  { session }
28885
29219
  ).toArray();
28886
29220
  const length = await collection.countDocuments(query, { session });
28887
- const data = (0, import_node_server_utils154.paginate)(items, page, limit, length);
29221
+ const data = (0, import_node_server_utils155.paginate)(items, page, limit, length);
28888
29222
  setCache(cacheKey, data, 15 * 60).then(() => {
28889
- import_node_server_utils154.logger.info(`Cache set for key: ${cacheKey}`);
29223
+ import_node_server_utils155.logger.info(`Cache set for key: ${cacheKey}`);
28890
29224
  }).catch((err) => {
28891
- import_node_server_utils154.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29225
+ import_node_server_utils155.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
28892
29226
  });
28893
29227
  return data;
28894
29228
  } catch (error) {
@@ -28899,23 +29233,23 @@ function useOccurrenceBookRepo() {
28899
29233
  try {
28900
29234
  _id = new import_mongodb87.ObjectId(_id);
28901
29235
  } catch (error) {
28902
- throw new import_node_server_utils154.BadRequestError("Invalid occurrence book ID format.");
29236
+ throw new import_node_server_utils155.BadRequestError("Invalid occurrence book ID format.");
28903
29237
  }
28904
- const cacheKey = (0, import_node_server_utils154.makeCacheKey)(namespace_collection, { _id });
29238
+ const cacheKey = (0, import_node_server_utils155.makeCacheKey)(namespace_collection, { _id });
28905
29239
  const cachedData = await getCache(cacheKey);
28906
29240
  if (cachedData) {
28907
- import_node_server_utils154.logger.info(`Cache hit for key: ${cacheKey}`);
29241
+ import_node_server_utils155.logger.info(`Cache hit for key: ${cacheKey}`);
28908
29242
  return cachedData;
28909
29243
  }
28910
29244
  try {
28911
29245
  const data = await collection.findOne({ _id }, { session });
28912
29246
  if (!data) {
28913
- throw new import_node_server_utils154.NotFoundError("Occurrence book not found.");
29247
+ throw new import_node_server_utils155.NotFoundError("Occurrence book not found.");
28914
29248
  }
28915
29249
  setCache(cacheKey, data, 15 * 60).then(() => {
28916
- import_node_server_utils154.logger.info(`Cache set for key: ${cacheKey}`);
29250
+ import_node_server_utils155.logger.info(`Cache set for key: ${cacheKey}`);
28917
29251
  }).catch((err) => {
28918
- import_node_server_utils154.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29252
+ import_node_server_utils155.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
28919
29253
  });
28920
29254
  return data;
28921
29255
  } catch (error) {
@@ -28927,7 +29261,7 @@ function useOccurrenceBookRepo() {
28927
29261
  try {
28928
29262
  _id = new import_mongodb87.ObjectId(_id);
28929
29263
  } catch (error) {
28930
- throw new import_node_server_utils154.BadRequestError("Invalid ID format.");
29264
+ throw new import_node_server_utils155.BadRequestError("Invalid ID format.");
28931
29265
  }
28932
29266
  try {
28933
29267
  const res = await collection.updateOne(
@@ -28936,14 +29270,14 @@ function useOccurrenceBookRepo() {
28936
29270
  { session }
28937
29271
  );
28938
29272
  if (res.modifiedCount === 0) {
28939
- throw new import_node_server_utils154.InternalServerError(
29273
+ throw new import_node_server_utils155.InternalServerError(
28940
29274
  "Unable to update daily occurrence book."
28941
29275
  );
28942
29276
  }
28943
29277
  delNamespace().then(() => {
28944
- import_node_server_utils154.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29278
+ import_node_server_utils155.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28945
29279
  }).catch((err) => {
28946
- import_node_server_utils154.logger.error(
29280
+ import_node_server_utils155.logger.error(
28947
29281
  `Failed to clear cache for namespace: ${namespace_collection}`,
28948
29282
  err
28949
29283
  );
@@ -28957,7 +29291,7 @@ function useOccurrenceBookRepo() {
28957
29291
  try {
28958
29292
  _id = new import_mongodb87.ObjectId(_id);
28959
29293
  } catch (error) {
28960
- throw new import_node_server_utils154.BadRequestError("Invalid occurrence book ID format.");
29294
+ throw new import_node_server_utils155.BadRequestError("Invalid occurrence book ID format.");
28961
29295
  }
28962
29296
  try {
28963
29297
  const updateValue = {
@@ -28967,12 +29301,12 @@ function useOccurrenceBookRepo() {
28967
29301
  };
28968
29302
  const res = await collection.updateOne({ _id }, { $set: updateValue });
28969
29303
  if (res.modifiedCount === 0) {
28970
- throw new import_node_server_utils154.InternalServerError("Unable to delete occurrence book.");
29304
+ throw new import_node_server_utils155.InternalServerError("Unable to delete occurrence book.");
28971
29305
  }
28972
29306
  delNamespace().then(() => {
28973
- import_node_server_utils154.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29307
+ import_node_server_utils155.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28974
29308
  }).catch((err) => {
28975
- import_node_server_utils154.logger.error(
29309
+ import_node_server_utils155.logger.error(
28976
29310
  `Failed to clear cache for namespace: ${namespace_collection}`,
28977
29311
  err
28978
29312
  );
@@ -28992,12 +29326,12 @@ function useOccurrenceBookRepo() {
28992
29326
  { session }
28993
29327
  );
28994
29328
  if (res.modifiedCount === 0) {
28995
- throw new import_node_server_utils154.InternalServerError("Unable to close daily occurrence book.");
29329
+ throw new import_node_server_utils155.InternalServerError("Unable to close daily occurrence book.");
28996
29330
  }
28997
29331
  delNamespace().then(() => {
28998
- import_node_server_utils154.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29332
+ import_node_server_utils155.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28999
29333
  }).catch((err) => {
29000
- import_node_server_utils154.logger.error(
29334
+ import_node_server_utils155.logger.error(
29001
29335
  `Failed to clear cache for namespace: ${namespace_collection}`,
29002
29336
  err
29003
29337
  );
@@ -29020,7 +29354,7 @@ function useOccurrenceBookRepo() {
29020
29354
  }
29021
29355
 
29022
29356
  // src/services/occurrence-book.service.ts
29023
- var import_node_server_utils155 = require("@7365admin1/node-server-utils");
29357
+ var import_node_server_utils156 = require("@7365admin1/node-server-utils");
29024
29358
  function useOccurrenceBookService() {
29025
29359
  const {
29026
29360
  add: _add,
@@ -29034,7 +29368,7 @@ function useOccurrenceBookService() {
29034
29368
  } = useCounterRepo();
29035
29369
  const { getAllSites: _getAllSites } = useSiteRepo();
29036
29370
  async function add(value) {
29037
- const session = import_node_server_utils155.useAtlas.getClient()?.startSession();
29371
+ const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
29038
29372
  session?.startTransaction();
29039
29373
  const counterName = "occurrence-book";
29040
29374
  try {
@@ -29056,7 +29390,7 @@ function useOccurrenceBookService() {
29056
29390
  }
29057
29391
  }
29058
29392
  async function updateOccurrenceBookById(id, value) {
29059
- const session = import_node_server_utils155.useAtlas.getClient()?.startSession();
29393
+ const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
29060
29394
  session?.startTransaction();
29061
29395
  try {
29062
29396
  await _updateOccurrenceBookById(id, value, session);
@@ -29074,7 +29408,7 @@ function useOccurrenceBookService() {
29074
29408
  const counterName = "occurrence-book";
29075
29409
  let page = 1;
29076
29410
  let entryCounter = 0;
29077
- const session = import_node_server_utils155.useAtlas.getClient()?.startSession();
29411
+ const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
29078
29412
  session?.startTransaction();
29079
29413
  const existingCounter = await _getByType(counterName);
29080
29414
  if (!existingCounter) {
@@ -29112,7 +29446,7 @@ function useOccurrenceBookService() {
29112
29446
  }
29113
29447
  }
29114
29448
  async function processCloseDOB() {
29115
- const session = import_node_server_utils155.useAtlas.getClient()?.startSession();
29449
+ const session = import_node_server_utils156.useAtlas.getClient()?.startSession();
29116
29450
  session?.startTransaction();
29117
29451
  try {
29118
29452
  await _closeOccurrenceBooks(session);
@@ -29133,7 +29467,7 @@ function useOccurrenceBookService() {
29133
29467
  }
29134
29468
 
29135
29469
  // src/controllers/occurrence-book.controller.ts
29136
- var import_node_server_utils156 = require("@7365admin1/node-server-utils");
29470
+ var import_node_server_utils157 = require("@7365admin1/node-server-utils");
29137
29471
  var import_joi89 = __toESM(require("joi"));
29138
29472
  function useOccurrenceBookController() {
29139
29473
  const {
@@ -29153,8 +29487,8 @@ function useOccurrenceBookController() {
29153
29487
  });
29154
29488
  if (error) {
29155
29489
  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));
29490
+ import_node_server_utils157.logger.log({ level: "error", message: messages });
29491
+ next(new import_node_server_utils157.BadRequestError(messages));
29158
29492
  return;
29159
29493
  }
29160
29494
  try {
@@ -29162,7 +29496,7 @@ function useOccurrenceBookController() {
29162
29496
  res.status(201).json(data);
29163
29497
  return;
29164
29498
  } catch (error2) {
29165
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29499
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29166
29500
  next(error2);
29167
29501
  return;
29168
29502
  }
@@ -29189,8 +29523,8 @@ function useOccurrenceBookController() {
29189
29523
  });
29190
29524
  if (error) {
29191
29525
  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));
29526
+ import_node_server_utils157.logger.log({ level: "error", message: messages });
29527
+ next(new import_node_server_utils157.BadRequestError(messages));
29194
29528
  return;
29195
29529
  }
29196
29530
  const search = req.query.search ?? "";
@@ -29221,7 +29555,7 @@ function useOccurrenceBookController() {
29221
29555
  res.status(200).json(data);
29222
29556
  return;
29223
29557
  } catch (error2) {
29224
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29558
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29225
29559
  next(error2);
29226
29560
  return;
29227
29561
  }
@@ -29231,8 +29565,8 @@ function useOccurrenceBookController() {
29231
29565
  const _id = req.params.id;
29232
29566
  const { error } = validation.validate(_id);
29233
29567
  if (error) {
29234
- import_node_server_utils156.logger.log({ level: "error", message: error.message });
29235
- next(new import_node_server_utils156.BadRequestError(error.message));
29568
+ import_node_server_utils157.logger.log({ level: "error", message: error.message });
29569
+ next(new import_node_server_utils157.BadRequestError(error.message));
29236
29570
  return;
29237
29571
  }
29238
29572
  try {
@@ -29240,7 +29574,7 @@ function useOccurrenceBookController() {
29240
29574
  res.status(200).json(data);
29241
29575
  return;
29242
29576
  } catch (error2) {
29243
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29577
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29244
29578
  next(error2);
29245
29579
  return;
29246
29580
  }
@@ -29253,8 +29587,8 @@ function useOccurrenceBookController() {
29253
29587
  });
29254
29588
  if (error) {
29255
29589
  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));
29590
+ import_node_server_utils157.logger.log({ level: "error", message: messages });
29591
+ next(new import_node_server_utils157.BadRequestError(messages));
29258
29592
  return;
29259
29593
  }
29260
29594
  try {
@@ -29262,7 +29596,7 @@ function useOccurrenceBookController() {
29262
29596
  res.status(200).json({ message: result });
29263
29597
  return;
29264
29598
  } catch (error2) {
29265
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29599
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29266
29600
  next(error2);
29267
29601
  return;
29268
29602
  }
@@ -29272,8 +29606,8 @@ function useOccurrenceBookController() {
29272
29606
  const _id = req.params.id;
29273
29607
  const { error } = validation.validate(_id);
29274
29608
  if (error) {
29275
- import_node_server_utils156.logger.log({ level: "error", message: error.message });
29276
- next(new import_node_server_utils156.BadRequestError(error.message));
29609
+ import_node_server_utils157.logger.log({ level: "error", message: error.message });
29610
+ next(new import_node_server_utils157.BadRequestError(error.message));
29277
29611
  return;
29278
29612
  }
29279
29613
  try {
@@ -29281,7 +29615,7 @@ function useOccurrenceBookController() {
29281
29615
  res.status(200).json({ message: "Successfully deleted occurrence book." });
29282
29616
  return;
29283
29617
  } catch (error2) {
29284
- import_node_server_utils156.logger.log({ level: "error", message: error2.message });
29618
+ import_node_server_utils157.logger.log({ level: "error", message: error2.message });
29285
29619
  next(error2);
29286
29620
  return;
29287
29621
  }
@@ -29345,33 +29679,33 @@ function MBulletinVideo(value) {
29345
29679
  }
29346
29680
 
29347
29681
  // src/repositories/bulletin-video.repo.ts
29348
- var import_node_server_utils157 = require("@7365admin1/node-server-utils");
29682
+ var import_node_server_utils158 = require("@7365admin1/node-server-utils");
29349
29683
  var import_mongodb89 = require("mongodb");
29350
29684
  function useBulletinVideoRepo() {
29351
- const db = import_node_server_utils157.useAtlas.getDb();
29685
+ const db = import_node_server_utils158.useAtlas.getDb();
29352
29686
  if (!db) {
29353
- throw new import_node_server_utils157.InternalServerError("Unable to connect to server.");
29687
+ throw new import_node_server_utils158.InternalServerError("Unable to connect to server.");
29354
29688
  }
29355
29689
  async function createIndexes() {
29356
29690
  try {
29357
29691
  await collection.createIndexes([{ key: { site: 1 } }]);
29358
29692
  } catch (error) {
29359
- throw new import_node_server_utils157.InternalServerError(
29693
+ throw new import_node_server_utils158.InternalServerError(
29360
29694
  "Failed to create index on bulletin videos."
29361
29695
  );
29362
29696
  }
29363
29697
  }
29364
29698
  const namespace_collection = "bulletin-videos";
29365
29699
  const collection = db.collection(namespace_collection);
29366
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils157.useCache)(namespace_collection);
29700
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils158.useCache)(namespace_collection);
29367
29701
  async function add(value, session) {
29368
29702
  try {
29369
29703
  value = MBulletinVideo(value);
29370
29704
  const res = await collection.insertOne(value, { session });
29371
29705
  delNamespace().then(() => {
29372
- import_node_server_utils157.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29706
+ import_node_server_utils158.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29373
29707
  }).catch((err) => {
29374
- import_node_server_utils157.logger.error(
29708
+ import_node_server_utils158.logger.error(
29375
29709
  `Failed to clear cache for namespace: ${namespace_collection}`,
29376
29710
  err
29377
29711
  );
@@ -29380,7 +29714,7 @@ function useBulletinVideoRepo() {
29380
29714
  } catch (error) {
29381
29715
  const isDuplicated = error.message.includes("duplicate");
29382
29716
  if (isDuplicated) {
29383
- throw new import_node_server_utils157.BadRequestError("Bulletin video already exists.");
29717
+ throw new import_node_server_utils158.BadRequestError("Bulletin video already exists.");
29384
29718
  }
29385
29719
  throw error;
29386
29720
  }
@@ -29396,7 +29730,7 @@ function useBulletinVideoRepo() {
29396
29730
  try {
29397
29731
  site = new import_mongodb89.ObjectId(site);
29398
29732
  } catch (error) {
29399
- throw new import_node_server_utils157.BadRequestError("Invalid site ID format.");
29733
+ throw new import_node_server_utils158.BadRequestError("Invalid site ID format.");
29400
29734
  }
29401
29735
  const query = {
29402
29736
  site,
@@ -29414,10 +29748,10 @@ function useBulletinVideoRepo() {
29414
29748
  query.$text = { $search: search };
29415
29749
  cacheOptions.search = search;
29416
29750
  }
29417
- const cacheKey = (0, import_node_server_utils157.makeCacheKey)(namespace_collection, cacheOptions);
29751
+ const cacheKey = (0, import_node_server_utils158.makeCacheKey)(namespace_collection, cacheOptions);
29418
29752
  const cachedData = await getCache(cacheKey);
29419
29753
  if (cachedData) {
29420
- import_node_server_utils157.logger.info(`Cache hit for key: ${cacheKey}`);
29754
+ import_node_server_utils158.logger.info(`Cache hit for key: ${cacheKey}`);
29421
29755
  return cachedData;
29422
29756
  }
29423
29757
  try {
@@ -29431,11 +29765,11 @@ function useBulletinVideoRepo() {
29431
29765
  { session }
29432
29766
  ).toArray();
29433
29767
  const length = await collection.countDocuments(query, { session });
29434
- const data = (0, import_node_server_utils157.paginate)(items, page, limit, length);
29768
+ const data = (0, import_node_server_utils158.paginate)(items, page, limit, length);
29435
29769
  setCache(cacheKey, data, 15 * 60).then(() => {
29436
- import_node_server_utils157.logger.info(`Cache set for key: ${cacheKey}`);
29770
+ import_node_server_utils158.logger.info(`Cache set for key: ${cacheKey}`);
29437
29771
  }).catch((err) => {
29438
- import_node_server_utils157.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29772
+ import_node_server_utils158.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29439
29773
  });
29440
29774
  return data;
29441
29775
  } catch (error) {
@@ -29446,12 +29780,12 @@ function useBulletinVideoRepo() {
29446
29780
  try {
29447
29781
  _id = new import_mongodb89.ObjectId(_id);
29448
29782
  } catch (error) {
29449
- throw new import_node_server_utils157.BadRequestError("Invalid bulletin video ID format.");
29783
+ throw new import_node_server_utils158.BadRequestError("Invalid bulletin video ID format.");
29450
29784
  }
29451
- const cacheKey = (0, import_node_server_utils157.makeCacheKey)(namespace_collection, { _id });
29785
+ const cacheKey = (0, import_node_server_utils158.makeCacheKey)(namespace_collection, { _id });
29452
29786
  const cachedData = await getCache(cacheKey);
29453
29787
  if (cachedData) {
29454
- import_node_server_utils157.logger.info(`Cache hit for key: ${cacheKey}`);
29788
+ import_node_server_utils158.logger.info(`Cache hit for key: ${cacheKey}`);
29455
29789
  return cachedData;
29456
29790
  }
29457
29791
  try {
@@ -29460,12 +29794,12 @@ function useBulletinVideoRepo() {
29460
29794
  { session }
29461
29795
  );
29462
29796
  if (!data) {
29463
- throw new import_node_server_utils157.NotFoundError("Bulletin video not found.");
29797
+ throw new import_node_server_utils158.NotFoundError("Bulletin video not found.");
29464
29798
  }
29465
29799
  setCache(cacheKey, data, 15 * 60).then(() => {
29466
- import_node_server_utils157.logger.info(`Cache set for key: ${cacheKey}`);
29800
+ import_node_server_utils158.logger.info(`Cache set for key: ${cacheKey}`);
29467
29801
  }).catch((err) => {
29468
- import_node_server_utils157.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29802
+ import_node_server_utils158.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
29469
29803
  });
29470
29804
  return data;
29471
29805
  } catch (error) {
@@ -29477,7 +29811,7 @@ function useBulletinVideoRepo() {
29477
29811
  try {
29478
29812
  _id = new import_mongodb89.ObjectId(_id);
29479
29813
  } catch (error) {
29480
- throw new import_node_server_utils157.BadRequestError("Invalid ID format.");
29814
+ throw new import_node_server_utils158.BadRequestError("Invalid ID format.");
29481
29815
  }
29482
29816
  if (value.file && typeof value.file === "string") {
29483
29817
  try {
@@ -29493,12 +29827,12 @@ function useBulletinVideoRepo() {
29493
29827
  { session }
29494
29828
  );
29495
29829
  if (res.modifiedCount === 0) {
29496
- throw new import_node_server_utils157.InternalServerError("Unable to update bulletin board.");
29830
+ throw new import_node_server_utils158.InternalServerError("Unable to update bulletin board.");
29497
29831
  }
29498
29832
  delNamespace().then(() => {
29499
- import_node_server_utils157.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29833
+ import_node_server_utils158.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29500
29834
  }).catch((err) => {
29501
- import_node_server_utils157.logger.error(
29835
+ import_node_server_utils158.logger.error(
29502
29836
  `Failed to clear cache for namespace: ${namespace_collection}`,
29503
29837
  err
29504
29838
  );
@@ -29512,7 +29846,7 @@ function useBulletinVideoRepo() {
29512
29846
  try {
29513
29847
  _id = new import_mongodb89.ObjectId(_id);
29514
29848
  } catch (error) {
29515
- throw new import_node_server_utils157.BadRequestError("Invalid bulletin video ID format.");
29849
+ throw new import_node_server_utils158.BadRequestError("Invalid bulletin video ID format.");
29516
29850
  }
29517
29851
  try {
29518
29852
  const updateValue = {
@@ -29526,12 +29860,12 @@ function useBulletinVideoRepo() {
29526
29860
  { session }
29527
29861
  );
29528
29862
  if (res.modifiedCount === 0) {
29529
- throw new import_node_server_utils157.InternalServerError("Unable to delete bulletin video.");
29863
+ throw new import_node_server_utils158.InternalServerError("Unable to delete bulletin video.");
29530
29864
  }
29531
29865
  delNamespace().then(() => {
29532
- import_node_server_utils157.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29866
+ import_node_server_utils158.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
29533
29867
  }).catch((err) => {
29534
- import_node_server_utils157.logger.error(
29868
+ import_node_server_utils158.logger.error(
29535
29869
  `Failed to clear cache for namespace: ${namespace_collection}`,
29536
29870
  err
29537
29871
  );
@@ -29552,7 +29886,7 @@ function useBulletinVideoRepo() {
29552
29886
  }
29553
29887
 
29554
29888
  // src/services/bulletin-video.service.ts
29555
- var import_node_server_utils158 = require("@7365admin1/node-server-utils");
29889
+ var import_node_server_utils159 = require("@7365admin1/node-server-utils");
29556
29890
  function useBulletinVideoService() {
29557
29891
  const {
29558
29892
  add: _add,
@@ -29562,7 +29896,7 @@ function useBulletinVideoService() {
29562
29896
  } = useBulletinVideoRepo();
29563
29897
  const { deleteFileById: _deleteFileById } = useFileRepo();
29564
29898
  async function add(value) {
29565
- const session = import_node_server_utils158.useAtlas.getClient()?.startSession();
29899
+ const session = import_node_server_utils159.useAtlas.getClient()?.startSession();
29566
29900
  session?.startTransaction();
29567
29901
  try {
29568
29902
  await _add(value, session);
@@ -29576,7 +29910,7 @@ function useBulletinVideoService() {
29576
29910
  }
29577
29911
  }
29578
29912
  async function updateBulletinVideoById(id, value) {
29579
- const session = import_node_server_utils158.useAtlas.getClient()?.startSession();
29913
+ const session = import_node_server_utils159.useAtlas.getClient()?.startSession();
29580
29914
  session?.startTransaction();
29581
29915
  try {
29582
29916
  if (value.file)
@@ -29592,7 +29926,7 @@ function useBulletinVideoService() {
29592
29926
  }
29593
29927
  }
29594
29928
  async function deleteBulletinVideoById(id) {
29595
- const session = import_node_server_utils158.useAtlas.getClient()?.startSession();
29929
+ const session = import_node_server_utils159.useAtlas.getClient()?.startSession();
29596
29930
  session?.startTransaction();
29597
29931
  try {
29598
29932
  const existingBulletinVideo = await _getBulletinVideoById(id);
@@ -29616,7 +29950,7 @@ function useBulletinVideoService() {
29616
29950
  }
29617
29951
 
29618
29952
  // src/controllers/bulletin-video.controller.ts
29619
- var import_node_server_utils159 = require("@7365admin1/node-server-utils");
29953
+ var import_node_server_utils160 = require("@7365admin1/node-server-utils");
29620
29954
  var import_joi91 = __toESM(require("joi"));
29621
29955
  function useBulletinVideoController() {
29622
29956
  const { add: _add, updateBulletinVideoById: _updateBulletinVideoById } = useBulletinVideoService();
@@ -29632,8 +29966,8 @@ function useBulletinVideoController() {
29632
29966
  });
29633
29967
  if (error) {
29634
29968
  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));
29969
+ import_node_server_utils160.logger.log({ level: "error", message: messages });
29970
+ next(new import_node_server_utils160.BadRequestError(messages));
29637
29971
  return;
29638
29972
  }
29639
29973
  try {
@@ -29641,7 +29975,7 @@ function useBulletinVideoController() {
29641
29975
  res.status(201).json(data);
29642
29976
  return;
29643
29977
  } catch (error2) {
29644
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
29978
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29645
29979
  next(error2);
29646
29980
  return;
29647
29981
  }
@@ -29663,8 +29997,8 @@ function useBulletinVideoController() {
29663
29997
  });
29664
29998
  if (error) {
29665
29999
  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));
30000
+ import_node_server_utils160.logger.log({ level: "error", message: messages });
30001
+ next(new import_node_server_utils160.BadRequestError(messages));
29668
30002
  return;
29669
30003
  }
29670
30004
  const search = req.query.search ?? "";
@@ -29691,7 +30025,7 @@ function useBulletinVideoController() {
29691
30025
  res.status(200).json(data);
29692
30026
  return;
29693
30027
  } catch (error2) {
29694
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
30028
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29695
30029
  next(error2);
29696
30030
  return;
29697
30031
  }
@@ -29701,8 +30035,8 @@ function useBulletinVideoController() {
29701
30035
  const _id = req.params.id;
29702
30036
  const { error } = validation.validate(_id);
29703
30037
  if (error) {
29704
- import_node_server_utils159.logger.log({ level: "error", message: error.message });
29705
- next(new import_node_server_utils159.BadRequestError(error.message));
30038
+ import_node_server_utils160.logger.log({ level: "error", message: error.message });
30039
+ next(new import_node_server_utils160.BadRequestError(error.message));
29706
30040
  return;
29707
30041
  }
29708
30042
  try {
@@ -29710,7 +30044,7 @@ function useBulletinVideoController() {
29710
30044
  res.status(200).json(data);
29711
30045
  return;
29712
30046
  } catch (error2) {
29713
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
30047
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29714
30048
  next(error2);
29715
30049
  return;
29716
30050
  }
@@ -29723,8 +30057,8 @@ function useBulletinVideoController() {
29723
30057
  });
29724
30058
  if (error) {
29725
30059
  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));
30060
+ import_node_server_utils160.logger.log({ level: "error", message: messages });
30061
+ next(new import_node_server_utils160.BadRequestError(messages));
29728
30062
  return;
29729
30063
  }
29730
30064
  try {
@@ -29732,7 +30066,7 @@ function useBulletinVideoController() {
29732
30066
  res.status(200).json({ message: result });
29733
30067
  return;
29734
30068
  } catch (error2) {
29735
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
30069
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29736
30070
  next(error2);
29737
30071
  return;
29738
30072
  }
@@ -29742,8 +30076,8 @@ function useBulletinVideoController() {
29742
30076
  const _id = req.params.id;
29743
30077
  const { error } = validation.validate(_id);
29744
30078
  if (error) {
29745
- import_node_server_utils159.logger.log({ level: "error", message: error.message });
29746
- next(new import_node_server_utils159.BadRequestError(error.message));
30079
+ import_node_server_utils160.logger.log({ level: "error", message: error.message });
30080
+ next(new import_node_server_utils160.BadRequestError(error.message));
29747
30081
  return;
29748
30082
  }
29749
30083
  try {
@@ -29751,7 +30085,7 @@ function useBulletinVideoController() {
29751
30085
  res.status(200).json({ message: "Successfully deleted bulletin video." });
29752
30086
  return;
29753
30087
  } catch (error2) {
29754
- import_node_server_utils159.logger.log({ level: "error", message: error2.message });
30088
+ import_node_server_utils160.logger.log({ level: "error", message: error2.message });
29755
30089
  next(error2);
29756
30090
  return;
29757
30091
  }
@@ -29766,7 +30100,7 @@ function useBulletinVideoController() {
29766
30100
  }
29767
30101
 
29768
30102
  // src/models/site-soa.model.ts
29769
- var import_node_server_utils160 = require("@7365admin1/node-server-utils");
30103
+ var import_node_server_utils161 = require("@7365admin1/node-server-utils");
29770
30104
  var import_mongodb90 = require("mongodb");
29771
30105
  var import_joi92 = __toESM(require("joi"));
29772
30106
  var schemaSOABillingItem = import_joi92.default.object({
@@ -29824,35 +30158,35 @@ var schemaUpdateStatementOfAccount = import_joi92.default.object({
29824
30158
  function MStatementOfAccount(value) {
29825
30159
  const { error } = schemaStatementOfAccount.validate(value);
29826
30160
  if (error) {
29827
- import_node_server_utils160.logger.info(`Unit Billing: ${error.message}`);
29828
- throw new import_node_server_utils160.BadRequestError(error.message);
30161
+ import_node_server_utils161.logger.info(`Unit Billing: ${error.message}`);
30162
+ throw new import_node_server_utils161.BadRequestError(error.message);
29829
30163
  }
29830
30164
  if (value._id && typeof value._id === "string") {
29831
30165
  try {
29832
30166
  value._id = new import_mongodb90.ObjectId(value._id);
29833
30167
  } catch {
29834
- throw new import_node_server_utils160.BadRequestError("Invalid _id format");
30168
+ throw new import_node_server_utils161.BadRequestError("Invalid _id format");
29835
30169
  }
29836
30170
  }
29837
30171
  if (value.site && typeof value.site === "string") {
29838
30172
  try {
29839
30173
  value.site = new import_mongodb90.ObjectId(value.site);
29840
30174
  } catch {
29841
- throw new import_node_server_utils160.BadRequestError("Invalid site format");
30175
+ throw new import_node_server_utils161.BadRequestError("Invalid site format");
29842
30176
  }
29843
30177
  }
29844
30178
  if (value.createdBy && typeof value.createdBy === "string") {
29845
30179
  try {
29846
30180
  value.createdBy = new import_mongodb90.ObjectId(value.createdBy);
29847
30181
  } catch {
29848
- throw new import_node_server_utils160.BadRequestError("Invalid createBy format");
30182
+ throw new import_node_server_utils161.BadRequestError("Invalid createBy format");
29849
30183
  }
29850
30184
  }
29851
30185
  if (value.unitId && typeof value.unitId === "string") {
29852
30186
  try {
29853
30187
  value.unitId = new import_mongodb90.ObjectId(value.unitId);
29854
30188
  } catch {
29855
- throw new import_node_server_utils160.BadRequestError("Invalid unitId format");
30189
+ throw new import_node_server_utils161.BadRequestError("Invalid unitId format");
29856
30190
  }
29857
30191
  }
29858
30192
  if (value.billing && Array.isArray(value.billing)) {
@@ -29861,7 +30195,7 @@ function MStatementOfAccount(value) {
29861
30195
  try {
29862
30196
  bill._id = new import_mongodb90.ObjectId(bill._id);
29863
30197
  } catch {
29864
- throw new import_node_server_utils160.BadRequestError("Invalid billing id format");
30198
+ throw new import_node_server_utils161.BadRequestError("Invalid billing id format");
29865
30199
  }
29866
30200
  }
29867
30201
  return bill;
@@ -29889,16 +30223,16 @@ function MStatementOfAccount(value) {
29889
30223
  }
29890
30224
 
29891
30225
  // src/repositories/site-soa.repo.ts
29892
- var import_node_server_utils161 = require("@7365admin1/node-server-utils");
30226
+ var import_node_server_utils162 = require("@7365admin1/node-server-utils");
29893
30227
  var import_mongodb91 = require("mongodb");
29894
30228
  function useStatementOfAccountRepo() {
29895
- const db = import_node_server_utils161.useAtlas.getDb();
30229
+ const db = import_node_server_utils162.useAtlas.getDb();
29896
30230
  if (!db) {
29897
30231
  throw new Error("Unable to connect to server.");
29898
30232
  }
29899
30233
  const namespace_collection = "site.statement-of-accounts";
29900
30234
  const collection = db.collection(namespace_collection);
29901
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils161.useCache)(namespace_collection);
30235
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils162.useCache)(namespace_collection);
29902
30236
  async function createTextIndex() {
29903
30237
  try {
29904
30238
  await collection.createIndex({
@@ -29906,11 +30240,11 @@ function useStatementOfAccountRepo() {
29906
30240
  });
29907
30241
  return "Successfully created text index on site SOA.";
29908
30242
  } catch (error) {
29909
- import_node_server_utils161.logger.log({
30243
+ import_node_server_utils162.logger.log({
29910
30244
  level: "error",
29911
30245
  message: error.message
29912
30246
  });
29913
- throw new import_node_server_utils161.InternalServerError("Failed to create text index on site SOA.");
30247
+ throw new import_node_server_utils162.InternalServerError("Failed to create text index on site SOA.");
29914
30248
  }
29915
30249
  }
29916
30250
  async function add(value, session) {
@@ -29920,15 +30254,15 @@ function useStatementOfAccountRepo() {
29920
30254
  delCachedData();
29921
30255
  return res.insertedId;
29922
30256
  } catch (error) {
29923
- import_node_server_utils161.logger.log({
30257
+ import_node_server_utils162.logger.log({
29924
30258
  level: "error",
29925
30259
  message: error.message
29926
30260
  });
29927
30261
  const isDuplicated = error.message.includes("duplicate");
29928
30262
  if (isDuplicated) {
29929
- throw new import_node_server_utils161.BadRequestError("Site SOA already exist.");
30263
+ throw new import_node_server_utils162.BadRequestError("Site SOA already exist.");
29930
30264
  }
29931
- if (error instanceof import_node_server_utils161.AppError) {
30265
+ if (error instanceof import_node_server_utils162.AppError) {
29932
30266
  throw error;
29933
30267
  } else {
29934
30268
  throw new Error("Failed to create Site SOA");
@@ -29984,10 +30318,10 @@ function useStatementOfAccountRepo() {
29984
30318
  ...dateFrom && { dateFrom: dateFrom.toString() },
29985
30319
  ...dateTo && { dateTo: dateTo.toString() }
29986
30320
  };
29987
- const cacheKey = (0, import_node_server_utils161.makeCacheKey)(namespace_collection, cacheOptions);
30321
+ const cacheKey = (0, import_node_server_utils162.makeCacheKey)(namespace_collection, cacheOptions);
29988
30322
  const cachedData = await getCache(cacheKey);
29989
30323
  if (cachedData) {
29990
- import_node_server_utils161.logger.info(`Cache hit for key: ${cacheKey}`);
30324
+ import_node_server_utils162.logger.info(`Cache hit for key: ${cacheKey}`);
29991
30325
  return cachedData;
29992
30326
  }
29993
30327
  try {
@@ -30014,9 +30348,9 @@ function useStatementOfAccountRepo() {
30014
30348
  collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
30015
30349
  ]);
30016
30350
  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)
30351
+ const data = (0, import_node_server_utils162.paginate)(items, page, limit, totalCount);
30352
+ setCache(cacheKey, data, 15 * 60).then(() => import_node_server_utils162.logger.info(`Cache set for key: ${cacheKey}`)).catch(
30353
+ (err) => import_node_server_utils162.logger.error(`Failed to set cache for key: ${cacheKey}`, err)
30020
30354
  );
30021
30355
  return data;
30022
30356
  } catch (error) {
@@ -30027,13 +30361,13 @@ function useStatementOfAccountRepo() {
30027
30361
  try {
30028
30362
  _id = new import_mongodb91.ObjectId(_id);
30029
30363
  } catch (error) {
30030
- throw new import_node_server_utils161.BadRequestError("Invalid ID.");
30364
+ throw new import_node_server_utils162.BadRequestError("Invalid ID.");
30031
30365
  }
30032
- const cacheKey = (0, import_node_server_utils161.makeCacheKey)(namespace_collection, { _id: String(_id) });
30366
+ const cacheKey = (0, import_node_server_utils162.makeCacheKey)(namespace_collection, { _id: String(_id) });
30033
30367
  try {
30034
30368
  const cached = await getCache(cacheKey);
30035
30369
  if (cached) {
30036
- import_node_server_utils161.logger.log({
30370
+ import_node_server_utils162.logger.log({
30037
30371
  level: "info",
30038
30372
  message: `Cache hit for getById soa: ${cacheKey}`
30039
30373
  });
@@ -30043,22 +30377,22 @@ function useStatementOfAccountRepo() {
30043
30377
  _id
30044
30378
  });
30045
30379
  setCache(cacheKey, result, 300).then(() => {
30046
- import_node_server_utils161.logger.log({
30380
+ import_node_server_utils162.logger.log({
30047
30381
  level: "info",
30048
30382
  message: `Cache set for ssoa by id: ${cacheKey}`
30049
30383
  });
30050
30384
  }).catch((err) => {
30051
- import_node_server_utils161.logger.log({
30385
+ import_node_server_utils162.logger.log({
30052
30386
  level: "error",
30053
30387
  message: `Failed to set cache for soa by id: ${err.message}`
30054
30388
  });
30055
30389
  });
30056
30390
  return result;
30057
30391
  } catch (error) {
30058
- if (error instanceof import_node_server_utils161.AppError) {
30392
+ if (error instanceof import_node_server_utils162.AppError) {
30059
30393
  throw error;
30060
30394
  } else {
30061
- throw new import_node_server_utils161.InternalServerError("Failed to get soa by id.");
30395
+ throw new import_node_server_utils162.InternalServerError("Failed to get soa by id.");
30062
30396
  }
30063
30397
  }
30064
30398
  }
@@ -30066,7 +30400,7 @@ function useStatementOfAccountRepo() {
30066
30400
  try {
30067
30401
  _id = new import_mongodb91.ObjectId(_id);
30068
30402
  } catch (error) {
30069
- throw new import_node_server_utils161.BadRequestError("Invalid site SOA transaction ID format.");
30403
+ throw new import_node_server_utils162.BadRequestError("Invalid site SOA transaction ID format.");
30070
30404
  }
30071
30405
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
30072
30406
  try {
@@ -30085,7 +30419,7 @@ function useStatementOfAccountRepo() {
30085
30419
  try {
30086
30420
  _id = new import_mongodb91.ObjectId(_id);
30087
30421
  } catch (error) {
30088
- throw new import_node_server_utils161.BadRequestError("Invalid site SOA transaction ID format.");
30422
+ throw new import_node_server_utils162.BadRequestError("Invalid site SOA transaction ID format.");
30089
30423
  }
30090
30424
  try {
30091
30425
  const updateValue = {
@@ -30095,7 +30429,7 @@ function useStatementOfAccountRepo() {
30095
30429
  };
30096
30430
  const res = await collection.updateOne({ _id }, { $set: updateValue });
30097
30431
  if (res.modifiedCount === 0) {
30098
- throw new import_node_server_utils161.InternalServerError("Unable to delete site SOA.");
30432
+ throw new import_node_server_utils162.InternalServerError("Unable to delete site SOA.");
30099
30433
  }
30100
30434
  delCachedData();
30101
30435
  return res.modifiedCount;
@@ -30107,7 +30441,7 @@ function useStatementOfAccountRepo() {
30107
30441
  try {
30108
30442
  _id = new import_mongodb91.ObjectId(_id);
30109
30443
  } catch (error) {
30110
- throw new import_node_server_utils161.BadRequestError("Invalid file ID format.");
30444
+ throw new import_node_server_utils162.BadRequestError("Invalid file ID format.");
30111
30445
  }
30112
30446
  try {
30113
30447
  const res = await collection.updateOne(
@@ -30118,17 +30452,17 @@ function useStatementOfAccountRepo() {
30118
30452
  delCachedData();
30119
30453
  return res;
30120
30454
  } catch (error) {
30121
- throw new import_node_server_utils161.InternalServerError("Failed to update soa request.");
30455
+ throw new import_node_server_utils162.InternalServerError("Failed to update soa request.");
30122
30456
  }
30123
30457
  }
30124
30458
  function delCachedData() {
30125
30459
  delNamespace().then(() => {
30126
- import_node_server_utils161.logger.log({
30460
+ import_node_server_utils162.logger.log({
30127
30461
  level: "info",
30128
30462
  message: `Cache namespace cleared for ${namespace_collection}`
30129
30463
  });
30130
30464
  }).catch((err) => {
30131
- import_node_server_utils161.logger.log({
30465
+ import_node_server_utils162.logger.log({
30132
30466
  level: "error",
30133
30467
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
30134
30468
  });
@@ -30146,19 +30480,19 @@ function useStatementOfAccountRepo() {
30146
30480
  }
30147
30481
 
30148
30482
  // src/controllers/site-soa.controller.ts
30149
- var import_node_server_utils163 = require("@7365admin1/node-server-utils");
30483
+ var import_node_server_utils164 = require("@7365admin1/node-server-utils");
30150
30484
 
30151
30485
  // src/services/site-soa.service.ts
30152
- var import_node_server_utils162 = require("@7365admin1/node-server-utils");
30486
+ var import_node_server_utils163 = require("@7365admin1/node-server-utils");
30153
30487
  var import_puppeteer = require("puppeteer");
30154
30488
  function useStatementOfAccountService() {
30155
30489
  const { add: _add } = useStatementOfAccountRepo();
30156
30490
  const { getUnitBillingBySite } = useSiteUnitBillingRepo();
30157
30491
  const { getUserById } = useUserRepo();
30158
30492
  async function add(value, dateFrom, dateTo) {
30159
- const session = import_node_server_utils162.useAtlas.getClient()?.startSession();
30493
+ const session = import_node_server_utils163.useAtlas.getClient()?.startSession();
30160
30494
  if (!session) {
30161
- throw new import_node_server_utils162.BadRequestError("Database session not available.");
30495
+ throw new import_node_server_utils163.BadRequestError("Database session not available.");
30162
30496
  }
30163
30497
  try {
30164
30498
  await session.startTransaction();
@@ -30184,7 +30518,7 @@ function useStatementOfAccountService() {
30184
30518
  try {
30185
30519
  unit._id = unit._id.toString();
30186
30520
  } catch {
30187
- throw new import_node_server_utils162.BadRequestError("Invalid unit id format/type");
30521
+ throw new import_node_server_utils163.BadRequestError("Invalid unit id format/type");
30188
30522
  }
30189
30523
  return unit;
30190
30524
  });
@@ -30197,7 +30531,7 @@ function useStatementOfAccountService() {
30197
30531
  await session.commitTransaction();
30198
30532
  return result;
30199
30533
  } catch (error) {
30200
- import_node_server_utils162.logger.log({
30534
+ import_node_server_utils163.logger.log({
30201
30535
  level: "error",
30202
30536
  message: `Failed to create soa: ${error.message}`
30203
30537
  });
@@ -30273,7 +30607,7 @@ function useStatementOfAccountService() {
30273
30607
  await browser.close();
30274
30608
  return pdfBuffer;
30275
30609
  } catch (error) {
30276
- import_node_server_utils162.logger.log({
30610
+ import_node_server_utils163.logger.log({
30277
30611
  level: "error",
30278
30612
  message: `Failed to create soa pdf: ${error.message}`
30279
30613
  });
@@ -30313,7 +30647,7 @@ function useStatementOfAccountController() {
30313
30647
  abortEarly: false
30314
30648
  });
30315
30649
  if (bodyError) {
30316
- throw new import_node_server_utils163.BadRequestError(bodyError.message);
30650
+ throw new import_node_server_utils164.BadRequestError(bodyError.message);
30317
30651
  }
30318
30652
  const { error: queryError, value: queryValue } = validation.validate(
30319
30653
  query,
@@ -30322,7 +30656,7 @@ function useStatementOfAccountController() {
30322
30656
  }
30323
30657
  );
30324
30658
  if (queryError) {
30325
- throw new import_node_server_utils163.BadRequestError(queryError.message);
30659
+ throw new import_node_server_utils164.BadRequestError(queryError.message);
30326
30660
  }
30327
30661
  try {
30328
30662
  const soa = await _add(bodyValue, queryValue.dateFrom, queryValue.dateTo);
@@ -30352,8 +30686,8 @@ function useStatementOfAccountController() {
30352
30686
  });
30353
30687
  if (error) {
30354
30688
  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));
30689
+ import_node_server_utils164.logger.log({ level: "error", message: messages });
30690
+ next(new import_node_server_utils164.BadRequestError(messages));
30357
30691
  return;
30358
30692
  }
30359
30693
  const search = req.query.search ?? "";
@@ -30386,7 +30720,7 @@ function useStatementOfAccountController() {
30386
30720
  res.status(200).json(data);
30387
30721
  return;
30388
30722
  } catch (error2) {
30389
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
30723
+ import_node_server_utils164.logger.log({ level: "error", message: error2.message });
30390
30724
  next(error2);
30391
30725
  return;
30392
30726
  }
@@ -30398,7 +30732,7 @@ function useStatementOfAccountController() {
30398
30732
  });
30399
30733
  const { error } = validation.validate({ id });
30400
30734
  if (error) {
30401
- next(new import_node_server_utils163.BadRequestError(error.message));
30735
+ next(new import_node_server_utils164.BadRequestError(error.message));
30402
30736
  return;
30403
30737
  }
30404
30738
  try {
@@ -30420,8 +30754,8 @@ function useStatementOfAccountController() {
30420
30754
  });
30421
30755
  if (error) {
30422
30756
  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));
30757
+ import_node_server_utils164.logger.log({ level: "error", message: messages });
30758
+ next(new import_node_server_utils164.BadRequestError(messages));
30425
30759
  return;
30426
30760
  }
30427
30761
  try {
@@ -30429,7 +30763,7 @@ function useStatementOfAccountController() {
30429
30763
  res.status(200).json({ message: result });
30430
30764
  return;
30431
30765
  } catch (error2) {
30432
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
30766
+ import_node_server_utils164.logger.log({ level: "error", message: error2.message });
30433
30767
  next(error2);
30434
30768
  return;
30435
30769
  }
@@ -30439,8 +30773,8 @@ function useStatementOfAccountController() {
30439
30773
  const _id = req.params.id;
30440
30774
  const { error } = validation.validate(_id);
30441
30775
  if (error) {
30442
- import_node_server_utils163.logger.log({ level: "error", message: error.message });
30443
- next(new import_node_server_utils163.BadRequestError(error.message));
30776
+ import_node_server_utils164.logger.log({ level: "error", message: error.message });
30777
+ next(new import_node_server_utils164.BadRequestError(error.message));
30444
30778
  return;
30445
30779
  }
30446
30780
  try {
@@ -30448,7 +30782,7 @@ function useStatementOfAccountController() {
30448
30782
  res.status(200).json({ message: "Successfully deleted site SOA." });
30449
30783
  return;
30450
30784
  } catch (error2) {
30451
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
30785
+ import_node_server_utils164.logger.log({ level: "error", message: error2.message });
30452
30786
  next(error2);
30453
30787
  return;
30454
30788
  }
@@ -30466,8 +30800,8 @@ function useStatementOfAccountController() {
30466
30800
  const { error } = validation.validate(query, { abortEarly: false });
30467
30801
  if (error) {
30468
30802
  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));
30803
+ import_node_server_utils164.logger.log({ level: "error", message: messages });
30804
+ next(new import_node_server_utils164.BadRequestError(messages));
30471
30805
  return;
30472
30806
  }
30473
30807
  const url = req.query.url;
@@ -30484,7 +30818,7 @@ function useStatementOfAccountController() {
30484
30818
  ];
30485
30819
  const appKeyRaw = req.query.appKey ?? "PROPERTY";
30486
30820
  if (!ALLOWED_APP_KEYS.includes(appKeyRaw)) {
30487
- throw new import_node_server_utils163.BadRequestError(`Invalid appKey: ${appKeyRaw}`);
30821
+ throw new import_node_server_utils164.BadRequestError(`Invalid appKey: ${appKeyRaw}`);
30488
30822
  }
30489
30823
  const appKey = appKeyRaw;
30490
30824
  const pdfBuffer = await _generatePDF(
@@ -30512,7 +30846,7 @@ function useStatementOfAccountController() {
30512
30846
  res.end(pdfBuffer);
30513
30847
  } catch (error) {
30514
30848
  console.error("PDF generation error:", error);
30515
- import_node_server_utils163.logger.log({ level: "error", message: error.message });
30849
+ import_node_server_utils164.logger.log({ level: "error", message: error.message });
30516
30850
  next(error);
30517
30851
  return;
30518
30852
  }
@@ -30528,8 +30862,8 @@ function useStatementOfAccountController() {
30528
30862
  });
30529
30863
  if (error) {
30530
30864
  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));
30865
+ import_node_server_utils164.logger.log({ level: "error", message: messages });
30866
+ next(new import_node_server_utils164.BadRequestError(messages));
30533
30867
  return;
30534
30868
  }
30535
30869
  try {
@@ -30540,7 +30874,7 @@ function useStatementOfAccountController() {
30540
30874
  res.status(200).json({ message: result });
30541
30875
  return;
30542
30876
  } catch (error2) {
30543
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
30877
+ import_node_server_utils164.logger.log({ level: "error", message: error2.message });
30544
30878
  next(error2);
30545
30879
  return;
30546
30880
  }
@@ -30557,7 +30891,7 @@ function useStatementOfAccountController() {
30557
30891
  }
30558
30892
 
30559
30893
  // src/models/site-entrypass-settings.model.ts
30560
- var import_node_server_utils164 = require("@7365admin1/node-server-utils");
30894
+ var import_node_server_utils165 = require("@7365admin1/node-server-utils");
30561
30895
  var import_mongodb92 = require("mongodb");
30562
30896
  var import_joi94 = __toESM(require("joi"));
30563
30897
  var schemaEntryPassSettings = import_joi94.default.object({
@@ -30601,28 +30935,28 @@ var schemaUpdateEntryPassSettings = import_joi94.default.object({
30601
30935
  function MEntryPassSettings(value) {
30602
30936
  const { error } = schemaEntryPassSettings.validate(value);
30603
30937
  if (error) {
30604
- import_node_server_utils164.logger.info(`Entry Pass Settings: ${error.message}`);
30605
- throw new import_node_server_utils164.BadRequestError(error.message);
30938
+ import_node_server_utils165.logger.info(`Entry Pass Settings: ${error.message}`);
30939
+ throw new import_node_server_utils165.BadRequestError(error.message);
30606
30940
  }
30607
30941
  if (value._id && typeof value._id === "string") {
30608
30942
  try {
30609
30943
  value._id = new import_mongodb92.ObjectId(value._id);
30610
30944
  } catch {
30611
- throw new import_node_server_utils164.BadRequestError("Invalid _id format");
30945
+ throw new import_node_server_utils165.BadRequestError("Invalid _id format");
30612
30946
  }
30613
30947
  }
30614
30948
  if (value.site && typeof value.site === "string") {
30615
30949
  try {
30616
30950
  value.site = new import_mongodb92.ObjectId(value.site);
30617
30951
  } catch {
30618
- throw new import_node_server_utils164.BadRequestError("Invalid site format");
30952
+ throw new import_node_server_utils165.BadRequestError("Invalid site format");
30619
30953
  }
30620
30954
  }
30621
30955
  if (value.org && typeof value.org === "string") {
30622
30956
  try {
30623
30957
  value.org = new import_mongodb92.ObjectId(value.org);
30624
30958
  } catch {
30625
- throw new import_node_server_utils164.BadRequestError("Invalid org format");
30959
+ throw new import_node_server_utils165.BadRequestError("Invalid org format");
30626
30960
  }
30627
30961
  }
30628
30962
  return {
@@ -30649,23 +30983,23 @@ function MEntryPassSettings(value) {
30649
30983
  }
30650
30984
 
30651
30985
  // src/repositories/site-entrypass-settings.repo.ts
30652
- var import_node_server_utils165 = require("@7365admin1/node-server-utils");
30986
+ var import_node_server_utils166 = require("@7365admin1/node-server-utils");
30653
30987
  var import_mongodb93 = require("mongodb");
30654
30988
  function useEntryPassSettingsRepo() {
30655
- const db = import_node_server_utils165.useAtlas.getDb();
30989
+ const db = import_node_server_utils166.useAtlas.getDb();
30656
30990
  if (!db) {
30657
- throw new import_node_server_utils165.InternalServerError("Unable to connect to server.");
30991
+ throw new import_node_server_utils166.InternalServerError("Unable to connect to server.");
30658
30992
  }
30659
30993
  const namespace_collection = "site.entrypass-settings";
30660
30994
  const collection = db.collection(namespace_collection);
30661
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils165.useCache)(namespace_collection);
30995
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils166.useCache)(namespace_collection);
30662
30996
  async function createTextIndex() {
30663
30997
  try {
30664
30998
  await collection.createIndex({
30665
30999
  name: "text"
30666
31000
  });
30667
31001
  } catch (error) {
30668
- throw new import_node_server_utils165.InternalServerError(
31002
+ throw new import_node_server_utils166.InternalServerError(
30669
31003
  "Failed to create text index on entry pass settings."
30670
31004
  );
30671
31005
  }
@@ -30675,9 +31009,9 @@ function useEntryPassSettingsRepo() {
30675
31009
  value = MEntryPassSettings(value);
30676
31010
  const res = await collection.insertOne(value, { session });
30677
31011
  delNamespace().then(() => {
30678
- import_node_server_utils165.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
31012
+ import_node_server_utils166.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30679
31013
  }).catch((err) => {
30680
- import_node_server_utils165.logger.error(
31014
+ import_node_server_utils166.logger.error(
30681
31015
  `Failed to clear cache for namespace: ${namespace_collection}`,
30682
31016
  err
30683
31017
  );
@@ -30686,7 +31020,7 @@ function useEntryPassSettingsRepo() {
30686
31020
  } catch (error) {
30687
31021
  const isDuplicated = error.message.includes("duplicate");
30688
31022
  if (isDuplicated) {
30689
- throw new import_node_server_utils165.BadRequestError("Card already exists.");
31023
+ throw new import_node_server_utils166.BadRequestError("Card already exists.");
30690
31024
  }
30691
31025
  throw error;
30692
31026
  }
@@ -30711,10 +31045,10 @@ function useEntryPassSettingsRepo() {
30711
31045
  const query = {
30712
31046
  ...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } }
30713
31047
  };
30714
- const cacheKey = (0, import_node_server_utils165.makeCacheKey)(namespace_collection, cacheOptions);
31048
+ const cacheKey = (0, import_node_server_utils166.makeCacheKey)(namespace_collection, cacheOptions);
30715
31049
  const cachedData = await getCache(cacheKey);
30716
31050
  if (cachedData) {
30717
- import_node_server_utils165.logger.info(`Cache hit for key: ${cacheKey}`);
31051
+ import_node_server_utils166.logger.info(`Cache hit for key: ${cacheKey}`);
30718
31052
  return cachedData;
30719
31053
  }
30720
31054
  try {
@@ -30747,11 +31081,11 @@ function useEntryPassSettingsRepo() {
30747
31081
  }
30748
31082
  ]).toArray();
30749
31083
  const length = await collection.countDocuments(query);
30750
- const data = (0, import_node_server_utils165.paginate)(items, page, limit, length);
31084
+ const data = (0, import_node_server_utils166.paginate)(items, page, limit, length);
30751
31085
  setCache(cacheKey, data, 15 * 60).then(() => {
30752
- import_node_server_utils165.logger.info(`Cache set for key: ${cacheKey}`);
31086
+ import_node_server_utils166.logger.info(`Cache set for key: ${cacheKey}`);
30753
31087
  }).catch((err) => {
30754
- import_node_server_utils165.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31088
+ import_node_server_utils166.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
30755
31089
  });
30756
31090
  return data;
30757
31091
  } catch (error) {
@@ -30762,12 +31096,12 @@ function useEntryPassSettingsRepo() {
30762
31096
  try {
30763
31097
  _id = new import_mongodb93.ObjectId(_id);
30764
31098
  } catch (error) {
30765
- throw new import_node_server_utils165.BadRequestError("Invalid entry pass settings ID format.");
31099
+ throw new import_node_server_utils166.BadRequestError("Invalid entry pass settings ID format.");
30766
31100
  }
30767
- const cacheKey = (0, import_node_server_utils165.makeCacheKey)(namespace_collection, { _id });
31101
+ const cacheKey = (0, import_node_server_utils166.makeCacheKey)(namespace_collection, { _id });
30768
31102
  const cachedData = await getCache(cacheKey);
30769
31103
  if (cachedData) {
30770
- import_node_server_utils165.logger.info(`Cache hit for key: ${cacheKey}`);
31104
+ import_node_server_utils166.logger.info(`Cache hit for key: ${cacheKey}`);
30771
31105
  return cachedData;
30772
31106
  }
30773
31107
  try {
@@ -30813,12 +31147,12 @@ function useEntryPassSettingsRepo() {
30813
31147
  }
30814
31148
  ]).toArray();
30815
31149
  if (!data || !data.length) {
30816
- throw new import_node_server_utils165.NotFoundError("Entry Pass Settings not found.");
31150
+ throw new import_node_server_utils166.NotFoundError("Entry Pass Settings not found.");
30817
31151
  }
30818
31152
  setCache(cacheKey, data[0], 15 * 60).then(() => {
30819
- import_node_server_utils165.logger.info(`Cache set for key: ${cacheKey}`);
31153
+ import_node_server_utils166.logger.info(`Cache set for key: ${cacheKey}`);
30820
31154
  }).catch((err) => {
30821
- import_node_server_utils165.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31155
+ import_node_server_utils166.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
30822
31156
  });
30823
31157
  return data[0];
30824
31158
  } catch (error) {
@@ -30829,7 +31163,7 @@ function useEntryPassSettingsRepo() {
30829
31163
  try {
30830
31164
  _id = new import_mongodb93.ObjectId(_id);
30831
31165
  } catch (error) {
30832
- throw new import_node_server_utils165.BadRequestError("Invalid entry pass settings ID format.");
31166
+ throw new import_node_server_utils166.BadRequestError("Invalid entry pass settings ID format.");
30833
31167
  }
30834
31168
  try {
30835
31169
  const updateValue = {
@@ -30838,12 +31172,12 @@ function useEntryPassSettingsRepo() {
30838
31172
  };
30839
31173
  const res = await collection.updateOne({ _id }, { $set: updateValue });
30840
31174
  if (res.modifiedCount === 0) {
30841
- throw new import_node_server_utils165.InternalServerError("Unable to update entry pass settings.");
31175
+ throw new import_node_server_utils166.InternalServerError("Unable to update entry pass settings.");
30842
31176
  }
30843
31177
  delNamespace().then(() => {
30844
- import_node_server_utils165.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
31178
+ import_node_server_utils166.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30845
31179
  }).catch((err) => {
30846
- import_node_server_utils165.logger.error(
31180
+ import_node_server_utils166.logger.error(
30847
31181
  `Failed to clear cache for namespace: ${namespace_collection}`,
30848
31182
  err
30849
31183
  );
@@ -30857,7 +31191,7 @@ function useEntryPassSettingsRepo() {
30857
31191
  try {
30858
31192
  _id = new import_mongodb93.ObjectId(_id);
30859
31193
  } catch (error) {
30860
- throw new import_node_server_utils165.BadRequestError("Invalid card ID format.");
31194
+ throw new import_node_server_utils166.BadRequestError("Invalid card ID format.");
30861
31195
  }
30862
31196
  try {
30863
31197
  const updateValue = {
@@ -30871,12 +31205,12 @@ function useEntryPassSettingsRepo() {
30871
31205
  { session }
30872
31206
  );
30873
31207
  if (res.modifiedCount === 0) {
30874
- throw new import_node_server_utils165.InternalServerError("Unable to delete entry pass settings.");
31208
+ throw new import_node_server_utils166.InternalServerError("Unable to delete entry pass settings.");
30875
31209
  }
30876
31210
  delNamespace().then(() => {
30877
- import_node_server_utils165.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
31211
+ import_node_server_utils166.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30878
31212
  }).catch((err) => {
30879
- import_node_server_utils165.logger.error(
31213
+ import_node_server_utils166.logger.error(
30880
31214
  `Failed to clear cache for namespace: ${namespace_collection}`,
30881
31215
  err
30882
31216
  );
@@ -30890,12 +31224,12 @@ function useEntryPassSettingsRepo() {
30890
31224
  try {
30891
31225
  site = new import_mongodb93.ObjectId(site);
30892
31226
  } catch (error) {
30893
- throw new import_node_server_utils165.BadRequestError("Invalid entry pass settings ID format.");
31227
+ throw new import_node_server_utils166.BadRequestError("Invalid entry pass settings ID format.");
30894
31228
  }
30895
- const cacheKey = (0, import_node_server_utils165.makeCacheKey)(namespace_collection, { site });
31229
+ const cacheKey = (0, import_node_server_utils166.makeCacheKey)(namespace_collection, { site });
30896
31230
  const cachedData = await getCache(cacheKey);
30897
31231
  if (cachedData) {
30898
- import_node_server_utils165.logger.info(`Cache hit for key: ${cacheKey}`);
31232
+ import_node_server_utils166.logger.info(`Cache hit for key: ${cacheKey}`);
30899
31233
  return cachedData;
30900
31234
  }
30901
31235
  try {
@@ -30941,12 +31275,12 @@ function useEntryPassSettingsRepo() {
30941
31275
  }
30942
31276
  ]).toArray();
30943
31277
  if (!data || !data.length) {
30944
- throw new import_node_server_utils165.NotFoundError("Entry Pass Settings not found.");
31278
+ throw new import_node_server_utils166.NotFoundError("Entry Pass Settings not found.");
30945
31279
  }
30946
31280
  setCache(cacheKey, data[0], 15 * 60).then(() => {
30947
- import_node_server_utils165.logger.info(`Cache set for key: ${cacheKey}`);
31281
+ import_node_server_utils166.logger.info(`Cache set for key: ${cacheKey}`);
30948
31282
  }).catch((err) => {
30949
- import_node_server_utils165.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31283
+ import_node_server_utils166.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
30950
31284
  });
30951
31285
  return data[0];
30952
31286
  } catch (error) {
@@ -30957,7 +31291,7 @@ function useEntryPassSettingsRepo() {
30957
31291
  try {
30958
31292
  site = new import_mongodb93.ObjectId(site);
30959
31293
  } catch (error) {
30960
- throw new import_node_server_utils165.BadRequestError("Invalid entry pass settings ID format.");
31294
+ throw new import_node_server_utils166.BadRequestError("Invalid entry pass settings ID format.");
30961
31295
  }
30962
31296
  try {
30963
31297
  const updateValue = {
@@ -30966,12 +31300,12 @@ function useEntryPassSettingsRepo() {
30966
31300
  };
30967
31301
  const res = await collection.updateOne({ site }, { $set: updateValue });
30968
31302
  if (res.modifiedCount === 0) {
30969
- throw new import_node_server_utils165.InternalServerError("Unable to update entry pass settings.");
31303
+ throw new import_node_server_utils166.InternalServerError("Unable to update entry pass settings.");
30970
31304
  }
30971
31305
  delNamespace().then(() => {
30972
- import_node_server_utils165.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
31306
+ import_node_server_utils166.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
30973
31307
  }).catch((err) => {
30974
- import_node_server_utils165.logger.error(
31308
+ import_node_server_utils166.logger.error(
30975
31309
  `Failed to clear cache for namespace: ${namespace_collection}`,
30976
31310
  err
30977
31311
  );
@@ -30994,7 +31328,7 @@ function useEntryPassSettingsRepo() {
30994
31328
  }
30995
31329
 
30996
31330
  // src/controllers/site-entrypass-settings.controller.ts
30997
- var import_node_server_utils166 = require("@7365admin1/node-server-utils");
31331
+ var import_node_server_utils167 = require("@7365admin1/node-server-utils");
30998
31332
  var import_joi95 = __toESM(require("joi"));
30999
31333
  function useEntryPassSettingsController() {
31000
31334
  const {
@@ -31018,8 +31352,8 @@ function useEntryPassSettingsController() {
31018
31352
  });
31019
31353
  if (error) {
31020
31354
  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));
31355
+ import_node_server_utils167.logger.log({ level: "error", message: messages });
31356
+ next(new import_node_server_utils167.BadRequestError(messages));
31023
31357
  return;
31024
31358
  }
31025
31359
  try {
@@ -31027,7 +31361,7 @@ function useEntryPassSettingsController() {
31027
31361
  res.status(201).json({ message: data });
31028
31362
  return;
31029
31363
  } catch (error2) {
31030
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31364
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31031
31365
  next(error2);
31032
31366
  return;
31033
31367
  }
@@ -31045,8 +31379,8 @@ function useEntryPassSettingsController() {
31045
31379
  query.status = req.query.status;
31046
31380
  const { error } = validation.validate(query);
31047
31381
  if (error) {
31048
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31049
- next(new import_node_server_utils166.BadRequestError(error.message));
31382
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31383
+ next(new import_node_server_utils167.BadRequestError(error.message));
31050
31384
  return;
31051
31385
  }
31052
31386
  const search = req.query.search ?? "";
@@ -31060,7 +31394,7 @@ function useEntryPassSettingsController() {
31060
31394
  res.json(data);
31061
31395
  return;
31062
31396
  } catch (error2) {
31063
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31397
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31064
31398
  next(error2);
31065
31399
  return;
31066
31400
  }
@@ -31070,8 +31404,8 @@ function useEntryPassSettingsController() {
31070
31404
  const _id = req.params.id;
31071
31405
  const { error } = validation.validate(_id);
31072
31406
  if (error) {
31073
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31074
- next(new import_node_server_utils166.BadRequestError(error.message));
31407
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31408
+ next(new import_node_server_utils167.BadRequestError(error.message));
31075
31409
  return;
31076
31410
  }
31077
31411
  try {
@@ -31079,7 +31413,7 @@ function useEntryPassSettingsController() {
31079
31413
  res.json(data);
31080
31414
  return;
31081
31415
  } catch (error2) {
31082
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31416
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31083
31417
  next(error2);
31084
31418
  return;
31085
31419
  }
@@ -31111,8 +31445,8 @@ function useEntryPassSettingsController() {
31111
31445
  const payload = { ...req.body, updatedBy };
31112
31446
  const { error } = validation.validate({ _id, ...payload });
31113
31447
  if (error) {
31114
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31115
- next(new import_node_server_utils166.BadRequestError(error.message));
31448
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31449
+ next(new import_node_server_utils167.BadRequestError(error.message));
31116
31450
  return;
31117
31451
  }
31118
31452
  try {
@@ -31120,7 +31454,7 @@ function useEntryPassSettingsController() {
31120
31454
  res.json({ message: "Successfully updated entry pass settings." });
31121
31455
  return;
31122
31456
  } catch (error2) {
31123
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31457
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31124
31458
  next(error2);
31125
31459
  return;
31126
31460
  }
@@ -31130,8 +31464,8 @@ function useEntryPassSettingsController() {
31130
31464
  const _id = req.params.id;
31131
31465
  const { error } = validation.validate(_id);
31132
31466
  if (error) {
31133
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31134
- next(new import_node_server_utils166.BadRequestError(error.message));
31467
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31468
+ next(new import_node_server_utils167.BadRequestError(error.message));
31135
31469
  return;
31136
31470
  }
31137
31471
  try {
@@ -31139,7 +31473,7 @@ function useEntryPassSettingsController() {
31139
31473
  res.json({ message: "Successfully deleted entry pass settings." });
31140
31474
  return;
31141
31475
  } catch (error2) {
31142
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31476
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31143
31477
  next(error2);
31144
31478
  return;
31145
31479
  }
@@ -31149,8 +31483,8 @@ function useEntryPassSettingsController() {
31149
31483
  const _id = req.params.site;
31150
31484
  const { error } = validation.validate(_id);
31151
31485
  if (error) {
31152
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31153
- next(new import_node_server_utils166.BadRequestError(error.message));
31486
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31487
+ next(new import_node_server_utils167.BadRequestError(error.message));
31154
31488
  return;
31155
31489
  }
31156
31490
  try {
@@ -31158,7 +31492,7 @@ function useEntryPassSettingsController() {
31158
31492
  res.json(data);
31159
31493
  return;
31160
31494
  } catch (error2) {
31161
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31495
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31162
31496
  next(error2);
31163
31497
  return;
31164
31498
  }
@@ -31189,8 +31523,8 @@ function useEntryPassSettingsController() {
31189
31523
  const payload = { ...req.body, updatedBy };
31190
31524
  const { error } = validation.validate({ ...payload });
31191
31525
  if (error) {
31192
- import_node_server_utils166.logger.log({ level: "error", message: error.message });
31193
- next(new import_node_server_utils166.BadRequestError(error.message));
31526
+ import_node_server_utils167.logger.log({ level: "error", message: error.message });
31527
+ next(new import_node_server_utils167.BadRequestError(error.message));
31194
31528
  return;
31195
31529
  }
31196
31530
  try {
@@ -31198,7 +31532,7 @@ function useEntryPassSettingsController() {
31198
31532
  res.json({ message: "Successfully updated entry pass settings." });
31199
31533
  return;
31200
31534
  } catch (error2) {
31201
- import_node_server_utils166.logger.log({ level: "error", message: error2.message });
31535
+ import_node_server_utils167.logger.log({ level: "error", message: error2.message });
31202
31536
  next(error2);
31203
31537
  return;
31204
31538
  }
@@ -31215,17 +31549,17 @@ function useEntryPassSettingsController() {
31215
31549
  }
31216
31550
 
31217
31551
  // src/repositories/dashboard.repo.ts
31218
- var import_node_server_utils167 = require("@7365admin1/node-server-utils");
31552
+ var import_node_server_utils168 = require("@7365admin1/node-server-utils");
31219
31553
  function useDashboardRepo() {
31220
- const db = import_node_server_utils167.useAtlas.getDb();
31554
+ const db = import_node_server_utils168.useAtlas.getDb();
31221
31555
  if (!db) {
31222
- throw new import_node_server_utils167.InternalServerError("Unable to connect to server.");
31556
+ throw new import_node_server_utils168.InternalServerError("Unable to connect to server.");
31223
31557
  }
31224
31558
  const feedback_collection = db.collection("feedbacks");
31225
31559
  const work_order_collection = db.collection("work-orders");
31226
31560
  const visitor_collection = db.collection("visitor.transactions");
31227
31561
  const namespace_collection = "dashboard";
31228
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils167.useCache)(namespace_collection);
31562
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils168.useCache)(namespace_collection);
31229
31563
  async function getAll({
31230
31564
  site = ""
31231
31565
  }, session) {
@@ -31236,10 +31570,10 @@ function useDashboardRepo() {
31236
31570
  const cacheOptions = {
31237
31571
  site: site.toString()
31238
31572
  };
31239
- const cacheKey = (0, import_node_server_utils167.makeCacheKey)(namespace_collection, cacheOptions);
31573
+ const cacheKey = (0, import_node_server_utils168.makeCacheKey)(namespace_collection, cacheOptions);
31240
31574
  const cachedData = await getCache(cacheKey);
31241
31575
  if (cachedData) {
31242
- import_node_server_utils167.logger.info(`Cache hit for key: ${cacheKey}`);
31576
+ import_node_server_utils168.logger.info(`Cache hit for key: ${cacheKey}`);
31243
31577
  return cachedData;
31244
31578
  }
31245
31579
  try {
@@ -31262,9 +31596,9 @@ function useDashboardRepo() {
31262
31596
  incidentReport: null
31263
31597
  };
31264
31598
  setCache(cacheKey, data, 10).then(() => {
31265
- import_node_server_utils167.logger.info(`Cache set for key: ${cacheKey}`);
31599
+ import_node_server_utils168.logger.info(`Cache set for key: ${cacheKey}`);
31266
31600
  }).catch((err) => {
31267
- import_node_server_utils167.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31601
+ import_node_server_utils168.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31268
31602
  });
31269
31603
  return data;
31270
31604
  } catch (error) {
@@ -31277,7 +31611,7 @@ function useDashboardRepo() {
31277
31611
  }
31278
31612
 
31279
31613
  // src/controllers/dashboard.controller.ts
31280
- var import_node_server_utils168 = require("@7365admin1/node-server-utils");
31614
+ var import_node_server_utils169 = require("@7365admin1/node-server-utils");
31281
31615
  var import_joi96 = __toESM(require("joi"));
31282
31616
  function useDashboardController() {
31283
31617
  const { getAll: _getAll } = useDashboardRepo();
@@ -31291,8 +31625,8 @@ function useDashboardController() {
31291
31625
  });
31292
31626
  if (error) {
31293
31627
  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));
31628
+ import_node_server_utils169.logger.log({ level: "error", message: messages });
31629
+ next(new import_node_server_utils169.BadRequestError(messages));
31296
31630
  return;
31297
31631
  }
31298
31632
  const site = req.query.site ?? "";
@@ -31303,7 +31637,7 @@ function useDashboardController() {
31303
31637
  res.status(200).json(data);
31304
31638
  return;
31305
31639
  } catch (error2) {
31306
- import_node_server_utils168.logger.log({ level: "error", message: error2.message });
31640
+ import_node_server_utils169.logger.log({ level: "error", message: error2.message });
31307
31641
  next(error2);
31308
31642
  return;
31309
31643
  }
@@ -31316,7 +31650,7 @@ function useDashboardController() {
31316
31650
  // src/models/nfc-patrol-route.model.ts
31317
31651
  var import_mongodb94 = require("mongodb");
31318
31652
  var import_joi97 = __toESM(require("joi"));
31319
- var import_node_server_utils169 = require("@7365admin1/node-server-utils");
31653
+ var import_node_server_utils170 = require("@7365admin1/node-server-utils");
31320
31654
  var schemaNfcPatrolRoute = import_joi97.default.object({
31321
31655
  _id: import_joi97.default.string().length(24).hex().optional().allow(null, ""),
31322
31656
  site: import_joi97.default.string().length(24).hex().required(),
@@ -31345,25 +31679,25 @@ var schemaNfcPatrolRoute = import_joi97.default.object({
31345
31679
  function MNfcPatrolRoute(value) {
31346
31680
  const { error } = schemaNfcPatrolRoute.validate(value);
31347
31681
  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);
31682
+ import_node_server_utils170.logger.info(`NFC Patrol Route Model: ${error.message}`);
31683
+ throw new import_node_server_utils170.BadRequestError(error.message);
31350
31684
  }
31351
31685
  if (value._id && typeof value._id === "string") {
31352
31686
  try {
31353
31687
  value._id = new import_mongodb94.ObjectId(value._id);
31354
31688
  } catch (error2) {
31355
- throw new import_node_server_utils169.BadRequestError("Invalid _id format");
31689
+ throw new import_node_server_utils170.BadRequestError("Invalid _id format");
31356
31690
  }
31357
31691
  }
31358
31692
  try {
31359
31693
  value.site = new import_mongodb94.ObjectId(value.site);
31360
31694
  } catch (error2) {
31361
- throw new import_node_server_utils169.BadRequestError("Invalid site format");
31695
+ throw new import_node_server_utils170.BadRequestError("Invalid site format");
31362
31696
  }
31363
31697
  try {
31364
31698
  value.createdBy = new import_mongodb94.ObjectId(value.createdBy);
31365
31699
  } catch (error2) {
31366
- throw new import_node_server_utils169.BadRequestError("Invalid createdBy format");
31700
+ throw new import_node_server_utils170.BadRequestError("Invalid createdBy format");
31367
31701
  }
31368
31702
  return {
31369
31703
  _id: value._id ?? new import_mongodb94.ObjectId(),
@@ -31381,16 +31715,16 @@ function MNfcPatrolRoute(value) {
31381
31715
  }
31382
31716
 
31383
31717
  // src/repositories/nfc-patrol-route.repository.ts
31384
- var import_node_server_utils170 = require("@7365admin1/node-server-utils");
31718
+ var import_node_server_utils171 = require("@7365admin1/node-server-utils");
31385
31719
  var import_mongodb95 = require("mongodb");
31386
31720
  function useNfcPatrolRouteRepo() {
31387
- const db = import_node_server_utils170.useAtlas.getDb();
31721
+ const db = import_node_server_utils171.useAtlas.getDb();
31388
31722
  if (!db) {
31389
- throw new import_node_server_utils170.InternalServerError("Unable to connect to server.");
31723
+ throw new import_node_server_utils171.InternalServerError("Unable to connect to server.");
31390
31724
  }
31391
31725
  const namespace_collection = "nfc-patrol-routes";
31392
31726
  const collection = db.collection(namespace_collection);
31393
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils170.useCache)(namespace_collection);
31727
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils171.useCache)(namespace_collection);
31394
31728
  async function createIndexes() {
31395
31729
  try {
31396
31730
  await collection.createIndexes([
@@ -31398,7 +31732,7 @@ function useNfcPatrolRouteRepo() {
31398
31732
  { key: { name: "text" }, name: "text-index" }
31399
31733
  ]);
31400
31734
  } catch (error) {
31401
- throw new import_node_server_utils170.InternalServerError(
31735
+ throw new import_node_server_utils171.InternalServerError(
31402
31736
  `Failed to create index on ${namespace_collection}.`
31403
31737
  );
31404
31738
  }
@@ -31412,7 +31746,7 @@ function useNfcPatrolRouteRepo() {
31412
31746
  } catch (error) {
31413
31747
  const isDuplicated = error.message.includes("duplicate");
31414
31748
  if (isDuplicated) {
31415
- throw new import_node_server_utils170.BadRequestError("NFC Patrol Route Name already exists.");
31749
+ throw new import_node_server_utils171.BadRequestError("NFC Patrol Route Name already exists.");
31416
31750
  }
31417
31751
  throw error;
31418
31752
  }
@@ -31428,7 +31762,7 @@ function useNfcPatrolRouteRepo() {
31428
31762
  try {
31429
31763
  site = new import_mongodb95.ObjectId(site);
31430
31764
  } catch (error) {
31431
- throw new import_node_server_utils170.BadRequestError("Invalid site ID format.");
31765
+ throw new import_node_server_utils171.BadRequestError("Invalid site ID format.");
31432
31766
  }
31433
31767
  const query = {
31434
31768
  site
@@ -31456,10 +31790,10 @@ function useNfcPatrolRouteRepo() {
31456
31790
  cacheOptions.search = search;
31457
31791
  if (filter)
31458
31792
  cacheOptions.filter = filter;
31459
- const cacheKey = (0, import_node_server_utils170.makeCacheKey)(namespace_collection, cacheOptions);
31793
+ const cacheKey = (0, import_node_server_utils171.makeCacheKey)(namespace_collection, cacheOptions);
31460
31794
  const cachedData = await getCache(cacheKey);
31461
31795
  if (cachedData) {
31462
- import_node_server_utils170.logger.info(`Cache hit for key: ${cacheKey}`);
31796
+ import_node_server_utils171.logger.info(`Cache hit for key: ${cacheKey}`);
31463
31797
  return cachedData;
31464
31798
  }
31465
31799
  try {
@@ -31484,11 +31818,11 @@ function useNfcPatrolRouteRepo() {
31484
31818
  { session }
31485
31819
  ).toArray();
31486
31820
  const length = await collection.countDocuments(query, { session });
31487
- const data = (0, import_node_server_utils170.paginate)(items, page, limit, length);
31821
+ const data = (0, import_node_server_utils171.paginate)(items, page, limit, length);
31488
31822
  setCache(cacheKey, data, 15 * 60).then(() => {
31489
- import_node_server_utils170.logger.info(`Cache set for key: ${cacheKey}`);
31823
+ import_node_server_utils171.logger.info(`Cache set for key: ${cacheKey}`);
31490
31824
  }).catch((err) => {
31491
- import_node_server_utils170.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31825
+ import_node_server_utils171.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
31492
31826
  });
31493
31827
  return data;
31494
31828
  } catch (error) {
@@ -31499,7 +31833,7 @@ function useNfcPatrolRouteRepo() {
31499
31833
  try {
31500
31834
  _id = new import_mongodb95.ObjectId(_id);
31501
31835
  } catch (error) {
31502
- throw new import_node_server_utils170.BadRequestError("Invalid ID.");
31836
+ throw new import_node_server_utils171.BadRequestError("Invalid ID.");
31503
31837
  }
31504
31838
  const cacheParams = {
31505
31839
  _id: String(_id)
@@ -31507,11 +31841,11 @@ function useNfcPatrolRouteRepo() {
31507
31841
  if (isStart === true) {
31508
31842
  cacheParams.isStart = true;
31509
31843
  }
31510
- const cacheKey = (0, import_node_server_utils170.makeCacheKey)(namespace_collection, cacheParams);
31844
+ const cacheKey = (0, import_node_server_utils171.makeCacheKey)(namespace_collection, cacheParams);
31511
31845
  try {
31512
31846
  const cached = await getCache(cacheKey);
31513
31847
  if (cached) {
31514
- import_node_server_utils170.logger.log({
31848
+ import_node_server_utils171.logger.log({
31515
31849
  level: "info",
31516
31850
  message: `Cache hit for getById ${namespace_collection}: ${cacheKey}`
31517
31851
  });
@@ -31579,22 +31913,22 @@ function useNfcPatrolRouteRepo() {
31579
31913
  result = await collection.findOne({ _id });
31580
31914
  }
31581
31915
  setCache(cacheKey, result, 300).then(() => {
31582
- import_node_server_utils170.logger.log({
31916
+ import_node_server_utils171.logger.log({
31583
31917
  level: "info",
31584
31918
  message: `Cache set for ${namespace_collection} by id: ${cacheKey}`
31585
31919
  });
31586
31920
  }).catch((err) => {
31587
- import_node_server_utils170.logger.log({
31921
+ import_node_server_utils171.logger.log({
31588
31922
  level: "error",
31589
31923
  message: `Failed to set cache for ${namespace_collection} by id: ${err.message}`
31590
31924
  });
31591
31925
  });
31592
31926
  return result;
31593
31927
  } catch (error) {
31594
- if (error instanceof import_node_server_utils170.AppError) {
31928
+ if (error instanceof import_node_server_utils171.AppError) {
31595
31929
  throw error;
31596
31930
  } else {
31597
- throw new import_node_server_utils170.InternalServerError(
31931
+ throw new import_node_server_utils171.InternalServerError(
31598
31932
  `Failed to get ${namespace_collection} by id.`
31599
31933
  );
31600
31934
  }
@@ -31603,24 +31937,24 @@ function useNfcPatrolRouteRepo() {
31603
31937
  async function updateById(_id, value, session) {
31604
31938
  const { error } = schemaNfcPatrolRoute.validate(value);
31605
31939
  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);
31940
+ import_node_server_utils171.logger.info(`NFC Patrol Route Repository: ${error.message}`);
31941
+ throw new import_node_server_utils171.BadRequestError(error.message);
31608
31942
  }
31609
31943
  try {
31610
31944
  _id = new import_mongodb95.ObjectId(_id);
31611
31945
  } catch (error2) {
31612
- throw new import_node_server_utils170.BadRequestError("Invalid ID.");
31946
+ throw new import_node_server_utils171.BadRequestError("Invalid ID.");
31613
31947
  }
31614
31948
  try {
31615
31949
  value.site = new import_mongodb95.ObjectId(value.site);
31616
31950
  } catch (error2) {
31617
- throw new import_node_server_utils170.BadRequestError("Invalid site format");
31951
+ throw new import_node_server_utils171.BadRequestError("Invalid site format");
31618
31952
  }
31619
31953
  if (value.updatedBy) {
31620
31954
  try {
31621
31955
  value.updatedBy = new import_mongodb95.ObjectId(value.updatedBy);
31622
31956
  } catch (error2) {
31623
- throw new import_node_server_utils170.BadRequestError("Invalid createdBy format");
31957
+ throw new import_node_server_utils171.BadRequestError("Invalid createdBy format");
31624
31958
  }
31625
31959
  }
31626
31960
  value.updatedAt = /* @__PURE__ */ new Date();
@@ -31632,19 +31966,19 @@ function useNfcPatrolRouteRepo() {
31632
31966
  );
31633
31967
  delCachedData();
31634
31968
  if (res.modifiedCount === 0) {
31635
- throw new import_node_server_utils170.BadRequestError("NFC Patrol Route not found.");
31969
+ throw new import_node_server_utils171.BadRequestError("NFC Patrol Route not found.");
31636
31970
  }
31637
31971
  return res;
31638
31972
  } catch (error2) {
31639
- import_node_server_utils170.logger.log({
31973
+ import_node_server_utils171.logger.log({
31640
31974
  level: "error",
31641
31975
  message: error2.message
31642
31976
  });
31643
31977
  const isDuplicated = error2.message.includes("duplicate");
31644
31978
  if (isDuplicated) {
31645
- throw new import_node_server_utils170.BadRequestError("NFC Patrol Route already exists.");
31979
+ throw new import_node_server_utils171.BadRequestError("NFC Patrol Route already exists.");
31646
31980
  }
31647
- if (error2 instanceof import_node_server_utils170.AppError) {
31981
+ if (error2 instanceof import_node_server_utils171.AppError) {
31648
31982
  throw error2;
31649
31983
  } else {
31650
31984
  throw new Error("Failed to update NFC Patrol Route.");
@@ -31653,12 +31987,12 @@ function useNfcPatrolRouteRepo() {
31653
31987
  }
31654
31988
  function delCachedData() {
31655
31989
  delNamespace().then(() => {
31656
- import_node_server_utils170.logger.log({
31990
+ import_node_server_utils171.logger.log({
31657
31991
  level: "info",
31658
31992
  message: `Cache namespace cleared for ${namespace_collection}`
31659
31993
  });
31660
31994
  }).catch((err) => {
31661
- import_node_server_utils170.logger.log({
31995
+ import_node_server_utils171.logger.log({
31662
31996
  level: "error",
31663
31997
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
31664
31998
  });
@@ -31674,11 +32008,11 @@ function useNfcPatrolRouteRepo() {
31674
32008
  }
31675
32009
 
31676
32010
  // src/services/nfc-patrol-route.service.ts
31677
- var import_node_server_utils171 = require("@7365admin1/node-server-utils");
32011
+ var import_node_server_utils172 = require("@7365admin1/node-server-utils");
31678
32012
  function useNfcPatrolRouteService() {
31679
32013
  const { add: _add, updateById: _updateById } = useNfcPatrolRouteRepo();
31680
32014
  async function add(value) {
31681
- const session = import_node_server_utils171.useAtlas.getClient()?.startSession();
32015
+ const session = import_node_server_utils172.useAtlas.getClient()?.startSession();
31682
32016
  session?.startTransaction();
31683
32017
  try {
31684
32018
  await _add(value, session);
@@ -31692,9 +32026,9 @@ function useNfcPatrolRouteService() {
31692
32026
  }
31693
32027
  }
31694
32028
  async function updateById(id, data) {
31695
- const session = import_node_server_utils171.useAtlas.getClient()?.startSession();
32029
+ const session = import_node_server_utils172.useAtlas.getClient()?.startSession();
31696
32030
  if (!session) {
31697
- throw new import_node_server_utils171.BadRequestError("Database session not available.");
32031
+ throw new import_node_server_utils172.BadRequestError("Database session not available.");
31698
32032
  }
31699
32033
  try {
31700
32034
  await session.startTransaction();
@@ -31702,7 +32036,7 @@ function useNfcPatrolRouteService() {
31702
32036
  await session.commitTransaction();
31703
32037
  return "Successfully updated NFC Patrol Route.";
31704
32038
  } catch (error) {
31705
- import_node_server_utils171.logger.log({
32039
+ import_node_server_utils172.logger.log({
31706
32040
  level: "error",
31707
32041
  message: `Failed to update NFC Patrol Route: ${error.message}`
31708
32042
  });
@@ -31719,7 +32053,7 @@ function useNfcPatrolRouteService() {
31719
32053
  }
31720
32054
 
31721
32055
  // src/controllers/nfc-patrol-route.controller.ts
31722
- var import_node_server_utils172 = require("@7365admin1/node-server-utils");
32056
+ var import_node_server_utils173 = require("@7365admin1/node-server-utils");
31723
32057
  var import_joi98 = __toESM(require("joi"));
31724
32058
  function useNfcPatrolRouteController() {
31725
32059
  const { add: _add, updateById: _updateById } = useNfcPatrolRouteService();
@@ -31736,8 +32070,8 @@ function useNfcPatrolRouteController() {
31736
32070
  });
31737
32071
  if (error) {
31738
32072
  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));
32073
+ import_node_server_utils173.logger.log({ level: "error", message: messages });
32074
+ next(new import_node_server_utils173.BadRequestError(messages));
31741
32075
  return;
31742
32076
  }
31743
32077
  try {
@@ -31745,7 +32079,7 @@ function useNfcPatrolRouteController() {
31745
32079
  res.status(201).json(data);
31746
32080
  return;
31747
32081
  } catch (error2) {
31748
- import_node_server_utils172.logger.log({ level: "error", message: error2.message });
32082
+ import_node_server_utils173.logger.log({ level: "error", message: error2.message });
31749
32083
  next(error2);
31750
32084
  return;
31751
32085
  }
@@ -31764,8 +32098,8 @@ function useNfcPatrolRouteController() {
31764
32098
  });
31765
32099
  if (error) {
31766
32100
  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));
32101
+ import_node_server_utils173.logger.log({ level: "error", message: messages });
32102
+ next(new import_node_server_utils173.BadRequestError(messages));
31769
32103
  return;
31770
32104
  }
31771
32105
  const page = parseInt(req.query.page ?? "1");
@@ -31784,7 +32118,7 @@ function useNfcPatrolRouteController() {
31784
32118
  res.status(200).json(data);
31785
32119
  return;
31786
32120
  } catch (error2) {
31787
- import_node_server_utils172.logger.log({ level: "error", message: error2.message });
32121
+ import_node_server_utils173.logger.log({ level: "error", message: error2.message });
31788
32122
  next(error2);
31789
32123
  return;
31790
32124
  }
@@ -31801,13 +32135,13 @@ function useNfcPatrolRouteController() {
31801
32135
  { convert: true }
31802
32136
  );
31803
32137
  if (error) {
31804
- next(new import_node_server_utils172.BadRequestError(error.message));
32138
+ next(new import_node_server_utils173.BadRequestError(error.message));
31805
32139
  return;
31806
32140
  }
31807
32141
  try {
31808
32142
  const nfcPatrolRoute = await _getById(value?.id, value?.isStart);
31809
32143
  if (!nfcPatrolRoute) {
31810
- throw new import_node_server_utils172.NotFoundError("NFC Patrol Route not found.");
32144
+ throw new import_node_server_utils173.NotFoundError("NFC Patrol Route not found.");
31811
32145
  }
31812
32146
  res.json({
31813
32147
  message: "Successfully retrieved nfc patrol route.",
@@ -32104,21 +32438,21 @@ function MIncidentReport(value) {
32104
32438
  }
32105
32439
 
32106
32440
  // src/services/incident-report.service.ts
32107
- var import_node_server_utils174 = require("@7365admin1/node-server-utils");
32441
+ var import_node_server_utils175 = require("@7365admin1/node-server-utils");
32108
32442
 
32109
32443
  // src/repositories/incident-report.repo.ts
32110
- var import_node_server_utils173 = require("@7365admin1/node-server-utils");
32444
+ var import_node_server_utils174 = require("@7365admin1/node-server-utils");
32111
32445
  var import_mongodb97 = require("mongodb");
32112
32446
  function useIncidentReportRepo() {
32113
- const db = import_node_server_utils173.useAtlas.getDb();
32447
+ const db = import_node_server_utils174.useAtlas.getDb();
32114
32448
  if (!db) {
32115
- throw new import_node_server_utils173.InternalServerError("Unable to connect to server.");
32449
+ throw new import_node_server_utils174.InternalServerError("Unable to connect to server.");
32116
32450
  }
32117
32451
  async function createIndexes() {
32118
32452
  try {
32119
32453
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
32120
32454
  } catch (error) {
32121
- throw new import_node_server_utils173.InternalServerError(
32455
+ throw new import_node_server_utils174.InternalServerError(
32122
32456
  "Failed to create index on bulletin videos."
32123
32457
  );
32124
32458
  }
@@ -32130,22 +32464,22 @@ function useIncidentReportRepo() {
32130
32464
  "incidentInformation.incidentTypeAndTime.typeOfIncident": "text"
32131
32465
  });
32132
32466
  } catch (error) {
32133
- throw new import_node_server_utils173.InternalServerError(
32467
+ throw new import_node_server_utils174.InternalServerError(
32134
32468
  "Failed to create text index on event management."
32135
32469
  );
32136
32470
  }
32137
32471
  }
32138
32472
  const namespace_collection = "incident-reports";
32139
32473
  const collection = db.collection(namespace_collection);
32140
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils173.useCache)(namespace_collection);
32474
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils174.useCache)(namespace_collection);
32141
32475
  async function add(value, session) {
32142
32476
  try {
32143
32477
  value = MIncidentReport(value);
32144
32478
  const res = await collection.insertOne(value, { session });
32145
32479
  delNamespace().then(() => {
32146
- import_node_server_utils173.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32480
+ import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32147
32481
  }).catch((err) => {
32148
- import_node_server_utils173.logger.error(
32482
+ import_node_server_utils174.logger.error(
32149
32483
  `Failed to clear cache for namespace: ${namespace_collection}`,
32150
32484
  err
32151
32485
  );
@@ -32154,7 +32488,7 @@ function useIncidentReportRepo() {
32154
32488
  } catch (error) {
32155
32489
  const isDuplicated = error.message.includes("duplicate");
32156
32490
  if (isDuplicated) {
32157
- throw new import_node_server_utils173.BadRequestError("Incident report already exists.");
32491
+ throw new import_node_server_utils174.BadRequestError("Incident report already exists.");
32158
32492
  }
32159
32493
  throw error;
32160
32494
  }
@@ -32173,7 +32507,7 @@ function useIncidentReportRepo() {
32173
32507
  try {
32174
32508
  site = new import_mongodb97.ObjectId(site);
32175
32509
  } catch (error) {
32176
- throw new import_node_server_utils173.BadRequestError("Invalid site ID format.");
32510
+ throw new import_node_server_utils174.BadRequestError("Invalid site ID format.");
32177
32511
  }
32178
32512
  if (dateFrom) {
32179
32513
  const startDate = new Date(dateFrom);
@@ -32229,10 +32563,10 @@ function useIncidentReportRepo() {
32229
32563
  if (search) {
32230
32564
  cacheOptions.search = search;
32231
32565
  }
32232
- const cacheKey = (0, import_node_server_utils173.makeCacheKey)(namespace_collection, cacheOptions);
32566
+ const cacheKey = (0, import_node_server_utils174.makeCacheKey)(namespace_collection, cacheOptions);
32233
32567
  const cachedData = await getCache(cacheKey);
32234
32568
  if (cachedData) {
32235
- import_node_server_utils173.logger.info(`Cache hit for key: ${cacheKey}`);
32569
+ import_node_server_utils174.logger.info(`Cache hit for key: ${cacheKey}`);
32236
32570
  return cachedData;
32237
32571
  }
32238
32572
  try {
@@ -32246,11 +32580,11 @@ function useIncidentReportRepo() {
32246
32580
  { session }
32247
32581
  ).toArray();
32248
32582
  const length = await collection.countDocuments(query, { session });
32249
- const data = (0, import_node_server_utils173.paginate)(items, page, limit, length);
32583
+ const data = (0, import_node_server_utils174.paginate)(items, page, limit, length);
32250
32584
  setCache(cacheKey, data, 15 * 60).then(() => {
32251
- import_node_server_utils173.logger.info(`Cache set for key: ${cacheKey}`);
32585
+ import_node_server_utils174.logger.info(`Cache set for key: ${cacheKey}`);
32252
32586
  }).catch((err) => {
32253
- import_node_server_utils173.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32587
+ import_node_server_utils174.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32254
32588
  });
32255
32589
  return data;
32256
32590
  } catch (error) {
@@ -32261,12 +32595,12 @@ function useIncidentReportRepo() {
32261
32595
  try {
32262
32596
  _id = new import_mongodb97.ObjectId(_id);
32263
32597
  } catch (error) {
32264
- throw new import_node_server_utils173.BadRequestError("Invalid incident report ID format.");
32598
+ throw new import_node_server_utils174.BadRequestError("Invalid incident report ID format.");
32265
32599
  }
32266
- const cacheKey = (0, import_node_server_utils173.makeCacheKey)(namespace_collection, { _id });
32600
+ const cacheKey = (0, import_node_server_utils174.makeCacheKey)(namespace_collection, { _id });
32267
32601
  const cachedData = await getCache(cacheKey);
32268
32602
  if (cachedData) {
32269
- import_node_server_utils173.logger.info(`Cache hit for key: ${cacheKey}`);
32603
+ import_node_server_utils174.logger.info(`Cache hit for key: ${cacheKey}`);
32270
32604
  return cachedData;
32271
32605
  }
32272
32606
  try {
@@ -32275,12 +32609,12 @@ function useIncidentReportRepo() {
32275
32609
  { session }
32276
32610
  );
32277
32611
  if (!data) {
32278
- throw new import_node_server_utils173.NotFoundError("Incident report not found.");
32612
+ throw new import_node_server_utils174.NotFoundError("Incident report not found.");
32279
32613
  }
32280
32614
  setCache(cacheKey, data, 15 * 60).then(() => {
32281
- import_node_server_utils173.logger.info(`Cache set for key: ${cacheKey}`);
32615
+ import_node_server_utils174.logger.info(`Cache set for key: ${cacheKey}`);
32282
32616
  }).catch((err) => {
32283
- import_node_server_utils173.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32617
+ import_node_server_utils174.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32284
32618
  });
32285
32619
  return data;
32286
32620
  } catch (error) {
@@ -32292,7 +32626,7 @@ function useIncidentReportRepo() {
32292
32626
  try {
32293
32627
  _id = new import_mongodb97.ObjectId(_id);
32294
32628
  } catch (error) {
32295
- throw new import_node_server_utils173.BadRequestError("Invalid ID format.");
32629
+ throw new import_node_server_utils174.BadRequestError("Invalid ID format.");
32296
32630
  }
32297
32631
  if (value.organization && typeof value.organization === "string") {
32298
32632
  try {
@@ -32332,14 +32666,14 @@ function useIncidentReportRepo() {
32332
32666
  { session }
32333
32667
  );
32334
32668
  if (res.modifiedCount === 0) {
32335
- throw new import_node_server_utils173.InternalServerError(
32669
+ throw new import_node_server_utils174.InternalServerError(
32336
32670
  "Unable to update daily occurrence Subject."
32337
32671
  );
32338
32672
  }
32339
32673
  delNamespace().then(() => {
32340
- import_node_server_utils173.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32674
+ import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32341
32675
  }).catch((err) => {
32342
- import_node_server_utils173.logger.error(
32676
+ import_node_server_utils174.logger.error(
32343
32677
  `Failed to clear cache for namespace: ${namespace_collection}`,
32344
32678
  err
32345
32679
  );
@@ -32353,7 +32687,7 @@ function useIncidentReportRepo() {
32353
32687
  try {
32354
32688
  _id = new import_mongodb97.ObjectId(_id);
32355
32689
  } catch (error) {
32356
- throw new import_node_server_utils173.BadRequestError("Invalid occurrence subject ID format.");
32690
+ throw new import_node_server_utils174.BadRequestError("Invalid occurrence subject ID format.");
32357
32691
  }
32358
32692
  try {
32359
32693
  const updateValue = {
@@ -32363,12 +32697,12 @@ function useIncidentReportRepo() {
32363
32697
  };
32364
32698
  const res = await collection.updateOne({ _id }, { $set: updateValue });
32365
32699
  if (res.modifiedCount === 0) {
32366
- throw new import_node_server_utils173.InternalServerError("Unable to delete occurrence subject.");
32700
+ throw new import_node_server_utils174.InternalServerError("Unable to delete occurrence subject.");
32367
32701
  }
32368
32702
  delNamespace().then(() => {
32369
- import_node_server_utils173.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32703
+ import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32370
32704
  }).catch((err) => {
32371
- import_node_server_utils173.logger.error(
32705
+ import_node_server_utils174.logger.error(
32372
32706
  `Failed to clear cache for namespace: ${namespace_collection}`,
32373
32707
  err
32374
32708
  );
@@ -32383,7 +32717,7 @@ function useIncidentReportRepo() {
32383
32717
  try {
32384
32718
  _id = new import_mongodb97.ObjectId(_id);
32385
32719
  } catch (error) {
32386
- throw new import_node_server_utils173.BadRequestError("Invalid ID format.");
32720
+ throw new import_node_server_utils174.BadRequestError("Invalid ID format.");
32387
32721
  }
32388
32722
  try {
32389
32723
  const res = await collection.updateOne(
@@ -32392,14 +32726,14 @@ function useIncidentReportRepo() {
32392
32726
  { session }
32393
32727
  );
32394
32728
  if (res.modifiedCount === 0) {
32395
- throw new import_node_server_utils173.InternalServerError(
32729
+ throw new import_node_server_utils174.InternalServerError(
32396
32730
  `Unable to ${value.status} incident report.`
32397
32731
  );
32398
32732
  }
32399
32733
  delNamespace().then(() => {
32400
- import_node_server_utils173.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32734
+ import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32401
32735
  }).catch((err) => {
32402
- import_node_server_utils173.logger.error(
32736
+ import_node_server_utils174.logger.error(
32403
32737
  `Failed to clear cache for namespace: ${namespace_collection}`,
32404
32738
  err
32405
32739
  );
@@ -32440,7 +32774,7 @@ function useIncidentReportService() {
32440
32774
  const { getById: _getOrganizationById } = useOrgRepo();
32441
32775
  const { deleteFile } = useFileService();
32442
32776
  async function add(value) {
32443
- const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
32777
+ const session = import_node_server_utils175.useAtlas.getClient()?.startSession();
32444
32778
  session?.startTransaction();
32445
32779
  try {
32446
32780
  if (value.incidentInformation.siteInfo.site) {
@@ -32465,7 +32799,7 @@ function useIncidentReportService() {
32465
32799
  session
32466
32800
  );
32467
32801
  if (!file) {
32468
- throw new import_node_server_utils174.NotFoundError("File not found.");
32802
+ throw new import_node_server_utils175.NotFoundError("File not found.");
32469
32803
  }
32470
32804
  }
32471
32805
  }
@@ -32480,7 +32814,7 @@ function useIncidentReportService() {
32480
32814
  }
32481
32815
  }
32482
32816
  async function updateIncidentReportById(id, value) {
32483
- const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
32817
+ const session = import_node_server_utils175.useAtlas.getClient()?.startSession();
32484
32818
  session?.startTransaction();
32485
32819
  try {
32486
32820
  const incidentReport = await _getIncidentReportById(id);
@@ -32514,7 +32848,7 @@ function useIncidentReportService() {
32514
32848
  }
32515
32849
  }
32516
32850
  async function createIncidentSummary(value) {
32517
- const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
32851
+ const session = import_node_server_utils175.useAtlas.getClient()?.startSession();
32518
32852
  session?.startTransaction();
32519
32853
  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
32854
  ' +
@@ -32565,13 +32899,13 @@ function useIncidentReportService() {
32565
32899
  }
32566
32900
  }
32567
32901
  async function reviewIncidentReport(id, value) {
32568
- const session = import_node_server_utils174.useAtlas.getClient()?.startSession();
32902
+ const session = import_node_server_utils175.useAtlas.getClient()?.startSession();
32569
32903
  session?.startTransaction();
32570
32904
  try {
32571
32905
  if (value.approvedBy) {
32572
32906
  const approvedBy = await getUserById(value.approvedBy);
32573
32907
  if (!approvedBy || !approvedBy.name)
32574
- throw new import_node_server_utils174.BadRequestError("Created by not found.");
32908
+ throw new import_node_server_utils175.BadRequestError("Created by not found.");
32575
32909
  value.approvedByName = approvedBy.name;
32576
32910
  value.approvedBy = approvedBy._id;
32577
32911
  }
@@ -32594,7 +32928,7 @@ function useIncidentReportService() {
32594
32928
  }
32595
32929
 
32596
32930
  // src/controllers/incident-report.controller.ts
32597
- var import_node_server_utils175 = require("@7365admin1/node-server-utils");
32931
+ var import_node_server_utils176 = require("@7365admin1/node-server-utils");
32598
32932
  var import_joi100 = __toESM(require("joi"));
32599
32933
  function useIncidentReportController() {
32600
32934
  const {
@@ -32615,8 +32949,8 @@ function useIncidentReportController() {
32615
32949
  });
32616
32950
  if (error) {
32617
32951
  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));
32952
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
32953
+ next(new import_node_server_utils176.BadRequestError(messages));
32620
32954
  return;
32621
32955
  }
32622
32956
  try {
@@ -32624,7 +32958,7 @@ function useIncidentReportController() {
32624
32958
  res.status(201).json({ data });
32625
32959
  return;
32626
32960
  } catch (error2) {
32627
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
32961
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32628
32962
  next(error2);
32629
32963
  return;
32630
32964
  }
@@ -32648,8 +32982,8 @@ function useIncidentReportController() {
32648
32982
  });
32649
32983
  if (error) {
32650
32984
  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));
32985
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
32986
+ next(new import_node_server_utils176.BadRequestError(messages));
32653
32987
  return;
32654
32988
  }
32655
32989
  const search = req.query.search ?? "";
@@ -32680,7 +33014,7 @@ function useIncidentReportController() {
32680
33014
  res.status(200).json(data);
32681
33015
  return;
32682
33016
  } catch (error2) {
32683
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33017
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32684
33018
  next(error2);
32685
33019
  return;
32686
33020
  }
@@ -32690,8 +33024,8 @@ function useIncidentReportController() {
32690
33024
  const _id = req.params.id;
32691
33025
  const { error } = validation.validate(_id);
32692
33026
  if (error) {
32693
- import_node_server_utils175.logger.log({ level: "error", message: error.message });
32694
- next(new import_node_server_utils175.BadRequestError(error.message));
33027
+ import_node_server_utils176.logger.log({ level: "error", message: error.message });
33028
+ next(new import_node_server_utils176.BadRequestError(error.message));
32695
33029
  return;
32696
33030
  }
32697
33031
  try {
@@ -32699,7 +33033,7 @@ function useIncidentReportController() {
32699
33033
  res.status(200).json(data);
32700
33034
  return;
32701
33035
  } catch (error2) {
32702
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33036
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32703
33037
  next(error2);
32704
33038
  return;
32705
33039
  }
@@ -32712,8 +33046,8 @@ function useIncidentReportController() {
32712
33046
  });
32713
33047
  if (error) {
32714
33048
  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));
33049
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
33050
+ next(new import_node_server_utils176.BadRequestError(messages));
32717
33051
  return;
32718
33052
  }
32719
33053
  try {
@@ -32721,7 +33055,7 @@ function useIncidentReportController() {
32721
33055
  res.status(200).json({ message: result });
32722
33056
  return;
32723
33057
  } catch (error2) {
32724
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33058
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32725
33059
  next(error2);
32726
33060
  return;
32727
33061
  }
@@ -32731,8 +33065,8 @@ function useIncidentReportController() {
32731
33065
  const _id = req.params.id;
32732
33066
  const { error } = validation.validate(_id);
32733
33067
  if (error) {
32734
- import_node_server_utils175.logger.log({ level: "error", message: error.message });
32735
- next(new import_node_server_utils175.BadRequestError(error.message));
33068
+ import_node_server_utils176.logger.log({ level: "error", message: error.message });
33069
+ next(new import_node_server_utils176.BadRequestError(error.message));
32736
33070
  return;
32737
33071
  }
32738
33072
  try {
@@ -32740,7 +33074,7 @@ function useIncidentReportController() {
32740
33074
  res.status(200).json({ message: "Successfully deleted incident report." });
32741
33075
  return;
32742
33076
  } catch (error2) {
32743
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33077
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32744
33078
  next(error2);
32745
33079
  return;
32746
33080
  }
@@ -32752,8 +33086,8 @@ function useIncidentReportController() {
32752
33086
  });
32753
33087
  if (error) {
32754
33088
  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));
33089
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
33090
+ next(new import_node_server_utils176.BadRequestError(messages));
32757
33091
  return;
32758
33092
  }
32759
33093
  try {
@@ -32764,7 +33098,7 @@ function useIncidentReportController() {
32764
33098
  res.status(201).json(data);
32765
33099
  return;
32766
33100
  } catch (error2) {
32767
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33101
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32768
33102
  next(error2);
32769
33103
  return;
32770
33104
  }
@@ -32786,8 +33120,8 @@ function useIncidentReportController() {
32786
33120
  const { error } = schema2.validate(payload);
32787
33121
  if (error) {
32788
33122
  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));
33123
+ import_node_server_utils176.logger.log({ level: "error", message: messages });
33124
+ next(new import_node_server_utils176.BadRequestError(messages));
32791
33125
  return;
32792
33126
  }
32793
33127
  try {
@@ -32795,7 +33129,7 @@ function useIncidentReportController() {
32795
33129
  res.status(200).json({ message: result });
32796
33130
  return;
32797
33131
  } catch (error2) {
32798
- import_node_server_utils175.logger.log({ level: "error", message: error2.message });
33132
+ import_node_server_utils176.logger.log({ level: "error", message: error2.message });
32799
33133
  next(error2);
32800
33134
  return;
32801
33135
  }
@@ -32814,7 +33148,7 @@ function useIncidentReportController() {
32814
33148
  // src/models/nfc-patrol-settings.model.ts
32815
33149
  var import_mongodb98 = require("mongodb");
32816
33150
  var import_joi101 = __toESM(require("joi"));
32817
- var import_node_server_utils176 = require("@7365admin1/node-server-utils");
33151
+ var import_node_server_utils177 = require("@7365admin1/node-server-utils");
32818
33152
  var objectId = import_joi101.default.string().hex().length(24);
32819
33153
  var nfcPatrolSettingsSchema = import_joi101.default.object({
32820
33154
  site: objectId.required(),
@@ -32833,14 +33167,14 @@ var nfcPatrolSettingsSchemaUpdate = import_joi101.default.object({
32833
33167
  function MNfcPatrolSettings(value) {
32834
33168
  const { error } = nfcPatrolSettingsSchema.validate(value);
32835
33169
  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);
33170
+ import_node_server_utils177.logger.info(`NFC Patrol Settings Model: ${error.message}`);
33171
+ throw new import_node_server_utils177.BadRequestError(error.message);
32838
33172
  }
32839
33173
  if (value.site) {
32840
33174
  try {
32841
33175
  value.site = new import_mongodb98.ObjectId(value.site);
32842
33176
  } catch (error2) {
32843
- throw new import_node_server_utils176.BadRequestError("Invalid site ID format.");
33177
+ throw new import_node_server_utils177.BadRequestError("Invalid site ID format.");
32844
33178
  }
32845
33179
  }
32846
33180
  return {
@@ -32853,14 +33187,14 @@ function MNfcPatrolSettings(value) {
32853
33187
  function MNfcPatrolSettingsUpdate(value) {
32854
33188
  const { error } = nfcPatrolSettingsSchemaUpdate.validate(value);
32855
33189
  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);
33190
+ import_node_server_utils177.logger.info(`NFC Patrol Settings Model: ${error.message}`);
33191
+ throw new import_node_server_utils177.BadRequestError(error.message);
32858
33192
  }
32859
33193
  if (value.updatedBy) {
32860
33194
  try {
32861
33195
  value.updatedBy = new import_mongodb98.ObjectId(value.updatedBy);
32862
33196
  } catch (error2) {
32863
- throw new import_node_server_utils176.BadRequestError("Invalid updatedBy ID format.");
33197
+ throw new import_node_server_utils177.BadRequestError("Invalid updatedBy ID format.");
32864
33198
  }
32865
33199
  }
32866
33200
  return {
@@ -32871,21 +33205,21 @@ function MNfcPatrolSettingsUpdate(value) {
32871
33205
  }
32872
33206
 
32873
33207
  // src/repositories/nfc-patrol-settings.repository.ts
32874
- var import_node_server_utils177 = require("@7365admin1/node-server-utils");
33208
+ var import_node_server_utils178 = require("@7365admin1/node-server-utils");
32875
33209
  var import_mongodb99 = require("mongodb");
32876
33210
  function useNfcPatrolSettingsRepository() {
32877
- const db = import_node_server_utils177.useAtlas.getDb();
33211
+ const db = import_node_server_utils178.useAtlas.getDb();
32878
33212
  if (!db) {
32879
- throw new import_node_server_utils177.InternalServerError("Unable to connect to server.");
33213
+ throw new import_node_server_utils178.InternalServerError("Unable to connect to server.");
32880
33214
  }
32881
33215
  const namespace_collection = "site.nfc-patrol-settings";
32882
33216
  const collection = db.collection(namespace_collection);
32883
- const { delNamespace, setCache, getCache } = (0, import_node_server_utils177.useCache)(namespace_collection);
33217
+ const { delNamespace, setCache, getCache } = (0, import_node_server_utils178.useCache)(namespace_collection);
32884
33218
  async function createIndexes() {
32885
33219
  try {
32886
33220
  await collection.createIndexes([{ key: { site: 1 }, unique: true }]);
32887
33221
  } catch (error) {
32888
- throw new import_node_server_utils177.InternalServerError(
33222
+ throw new import_node_server_utils178.InternalServerError(
32889
33223
  "Failed to create index on nfc patrol settings."
32890
33224
  );
32891
33225
  }
@@ -32904,20 +33238,20 @@ function useNfcPatrolSettingsRepository() {
32904
33238
  try {
32905
33239
  site = new import_mongodb99.ObjectId(site);
32906
33240
  } catch (error) {
32907
- throw new import_node_server_utils177.BadRequestError("Invalid nfc patrol settings site ID format.");
33241
+ throw new import_node_server_utils178.BadRequestError("Invalid nfc patrol settings site ID format.");
32908
33242
  }
32909
33243
  const query = { site };
32910
- const cacheKey = (0, import_node_server_utils177.makeCacheKey)(namespace_collection, {
33244
+ const cacheKey = (0, import_node_server_utils178.makeCacheKey)(namespace_collection, {
32911
33245
  site: site.toString()
32912
33246
  });
32913
33247
  if (!session) {
32914
33248
  const cachedData = await getCache(cacheKey);
32915
33249
  if (cachedData) {
32916
- import_node_server_utils177.logger.info(`Cache hit for key: ${cacheKey}`);
33250
+ import_node_server_utils178.logger.info(`Cache hit for key: ${cacheKey}`);
32917
33251
  return cachedData;
32918
33252
  }
32919
33253
  } else {
32920
- import_node_server_utils177.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
33254
+ import_node_server_utils178.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
32921
33255
  }
32922
33256
  try {
32923
33257
  const data = await collection.aggregate([
@@ -32935,9 +33269,9 @@ function useNfcPatrolSettingsRepository() {
32935
33269
  return null;
32936
33270
  }
32937
33271
  setCache(cacheKey, data[0], 15 * 60).then(() => {
32938
- import_node_server_utils177.logger.info(`Cache set for key: ${cacheKey}`);
33272
+ import_node_server_utils178.logger.info(`Cache set for key: ${cacheKey}`);
32939
33273
  }).catch((err) => {
32940
- import_node_server_utils177.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33274
+ import_node_server_utils178.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
32941
33275
  });
32942
33276
  return data[0];
32943
33277
  } catch (error) {
@@ -32948,7 +33282,7 @@ function useNfcPatrolSettingsRepository() {
32948
33282
  try {
32949
33283
  site = new import_mongodb99.ObjectId(site);
32950
33284
  } catch (error) {
32951
- throw new import_node_server_utils177.BadRequestError("Invalid attendance settings ID format.");
33285
+ throw new import_node_server_utils178.BadRequestError("Invalid attendance settings ID format.");
32952
33286
  }
32953
33287
  try {
32954
33288
  value = MNfcPatrolSettingsUpdate(value);
@@ -32958,12 +33292,12 @@ function useNfcPatrolSettingsRepository() {
32958
33292
  { session }
32959
33293
  );
32960
33294
  if (res.matchedCount === 0) {
32961
- throw new import_node_server_utils177.NotFoundError("NFC patrol settings not found for this site.");
33295
+ throw new import_node_server_utils178.NotFoundError("NFC patrol settings not found for this site.");
32962
33296
  }
32963
33297
  delNamespace().then(() => {
32964
- import_node_server_utils177.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33298
+ import_node_server_utils178.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
32965
33299
  }).catch((err) => {
32966
- import_node_server_utils177.logger.error(
33300
+ import_node_server_utils178.logger.error(
32967
33301
  `Failed to clear cache for namespace: ${namespace_collection}`,
32968
33302
  err
32969
33303
  );
@@ -32975,12 +33309,12 @@ function useNfcPatrolSettingsRepository() {
32975
33309
  }
32976
33310
  function delCachedData() {
32977
33311
  delNamespace().then(() => {
32978
- import_node_server_utils177.logger.log({
33312
+ import_node_server_utils178.logger.log({
32979
33313
  level: "info",
32980
33314
  message: `Cache namespace cleared for ${namespace_collection}`
32981
33315
  });
32982
33316
  }).catch((err) => {
32983
- import_node_server_utils177.logger.log({
33317
+ import_node_server_utils178.logger.log({
32984
33318
  level: "error",
32985
33319
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
32986
33320
  });
@@ -32995,7 +33329,7 @@ function useNfcPatrolSettingsRepository() {
32995
33329
  }
32996
33330
 
32997
33331
  // src/services/nfc-patrol-settings.service.ts
32998
- var import_node_server_utils178 = require("@7365admin1/node-server-utils");
33332
+ var import_node_server_utils179 = require("@7365admin1/node-server-utils");
32999
33333
  function useNfcPatrolSettingsService() {
33000
33334
  const {
33001
33335
  createNfcPatrolSettings,
@@ -33006,10 +33340,10 @@ function useNfcPatrolSettingsService() {
33006
33340
  try {
33007
33341
  let settings = await _getNfcPatrolSettingsBySite(site);
33008
33342
  if (!settings) {
33009
- import_node_server_utils178.logger.info(
33343
+ import_node_server_utils179.logger.info(
33010
33344
  `No attendance settings found for site ${site}, creating default settings`
33011
33345
  );
33012
- const session = import_node_server_utils178.useAtlas.getClient()?.startSession();
33346
+ const session = import_node_server_utils179.useAtlas.getClient()?.startSession();
33013
33347
  try {
33014
33348
  session?.startTransaction();
33015
33349
  await createNfcPatrolSettings(
@@ -33031,14 +33365,14 @@ function useNfcPatrolSettingsService() {
33031
33365
  }
33032
33366
  return settings;
33033
33367
  } catch (error) {
33034
- import_node_server_utils178.logger.error(`Error fetching nfc patrol settings by site:`, error);
33368
+ import_node_server_utils179.logger.error(`Error fetching nfc patrol settings by site:`, error);
33035
33369
  throw error;
33036
33370
  }
33037
33371
  }
33038
33372
  async function updateNfcPatrolSettings(site, value) {
33039
- const session = import_node_server_utils178.useAtlas.getClient()?.startSession();
33373
+ const session = import_node_server_utils179.useAtlas.getClient()?.startSession();
33040
33374
  if (!session) {
33041
- throw new import_node_server_utils178.BadRequestError("Database session not available.");
33375
+ throw new import_node_server_utils179.BadRequestError("Database session not available.");
33042
33376
  }
33043
33377
  try {
33044
33378
  await session.startTransaction();
@@ -33046,7 +33380,7 @@ function useNfcPatrolSettingsService() {
33046
33380
  await session.commitTransaction();
33047
33381
  return "Successfully updated NFC Patrol Settings.";
33048
33382
  } catch (error) {
33049
- import_node_server_utils178.logger.log({
33383
+ import_node_server_utils179.logger.log({
33050
33384
  level: "error",
33051
33385
  message: `Failed to update NFC Patrol Settings: ${error.message}`
33052
33386
  });
@@ -33061,7 +33395,7 @@ function useNfcPatrolSettingsService() {
33061
33395
 
33062
33396
  // src/controllers/nfc-patrol-settings.controller.ts
33063
33397
  var import_joi102 = __toESM(require("joi"));
33064
- var import_node_server_utils179 = require("@7365admin1/node-server-utils");
33398
+ var import_node_server_utils180 = require("@7365admin1/node-server-utils");
33065
33399
  function useNfcPatrolSettingsController() {
33066
33400
  const { getNfcPatrolSettingsBySite: _getNfcPatrolSettingsBySite } = useNfcPatrolSettingsService();
33067
33401
  const { updateNfcPatrolSettings: _updateNfcPatrolSettings } = useNfcPatrolSettingsService();
@@ -33070,8 +33404,8 @@ function useNfcPatrolSettingsController() {
33070
33404
  const site = req.params.site;
33071
33405
  const { error } = validation.validate(site);
33072
33406
  if (error) {
33073
- import_node_server_utils179.logger.log({ level: "error", message: error.message });
33074
- next(new import_node_server_utils179.BadRequestError(error.message));
33407
+ import_node_server_utils180.logger.log({ level: "error", message: error.message });
33408
+ next(new import_node_server_utils180.BadRequestError(error.message));
33075
33409
  return;
33076
33410
  }
33077
33411
  try {
@@ -33079,7 +33413,7 @@ function useNfcPatrolSettingsController() {
33079
33413
  res.json(data);
33080
33414
  return;
33081
33415
  } catch (error2) {
33082
- import_node_server_utils179.logger.log({ level: "error", message: error2.message });
33416
+ import_node_server_utils180.logger.log({ level: "error", message: error2.message });
33083
33417
  next(error2);
33084
33418
  return;
33085
33419
  }
@@ -33098,7 +33432,7 @@ function useNfcPatrolSettingsController() {
33098
33432
  res.json({ message: "NFC patrol settings updated successfully." });
33099
33433
  return;
33100
33434
  } catch (error) {
33101
- import_node_server_utils179.logger.log({ level: "error", message: error.message });
33435
+ import_node_server_utils180.logger.log({ level: "error", message: error.message });
33102
33436
  next(error);
33103
33437
  return;
33104
33438
  }
@@ -33110,10 +33444,10 @@ function useNfcPatrolSettingsController() {
33110
33444
  }
33111
33445
 
33112
33446
  // src/services/occurrence-entry.service.ts
33113
- var import_node_server_utils181 = require("@7365admin1/node-server-utils");
33447
+ var import_node_server_utils182 = require("@7365admin1/node-server-utils");
33114
33448
 
33115
33449
  // src/repositories/occurrence-subject.repo.ts
33116
- var import_node_server_utils180 = require("@7365admin1/node-server-utils");
33450
+ var import_node_server_utils181 = require("@7365admin1/node-server-utils");
33117
33451
 
33118
33452
  // src/models/occurrence-subject.model.ts
33119
33453
  var import_mongodb100 = require("mongodb");
@@ -33163,15 +33497,15 @@ function MOccurrenceSubject(value) {
33163
33497
  // src/repositories/occurrence-subject.repo.ts
33164
33498
  var import_mongodb101 = require("mongodb");
33165
33499
  function useOccurrenceSubjectRepo() {
33166
- const db = import_node_server_utils180.useAtlas.getDb();
33500
+ const db = import_node_server_utils181.useAtlas.getDb();
33167
33501
  if (!db) {
33168
- throw new import_node_server_utils180.InternalServerError("Unable to connect to server.");
33502
+ throw new import_node_server_utils181.InternalServerError("Unable to connect to server.");
33169
33503
  }
33170
33504
  async function createIndexes() {
33171
33505
  try {
33172
33506
  await collection.createIndexes([{ key: { site: 1 } }]);
33173
33507
  } catch (error) {
33174
- throw new import_node_server_utils180.InternalServerError(
33508
+ throw new import_node_server_utils181.InternalServerError(
33175
33509
  "Failed to create index on occurrence subjects."
33176
33510
  );
33177
33511
  }
@@ -33182,22 +33516,22 @@ function useOccurrenceSubjectRepo() {
33182
33516
  subject: "text"
33183
33517
  });
33184
33518
  } catch (error) {
33185
- throw new import_node_server_utils180.InternalServerError(
33519
+ throw new import_node_server_utils181.InternalServerError(
33186
33520
  "Failed to create text index on occurrence subjects."
33187
33521
  );
33188
33522
  }
33189
33523
  }
33190
33524
  const namespace_collection = "occurrence-subjects";
33191
33525
  const collection = db.collection(namespace_collection);
33192
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils180.useCache)(namespace_collection);
33526
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils181.useCache)(namespace_collection);
33193
33527
  async function add(value, session) {
33194
33528
  try {
33195
33529
  value = MOccurrenceSubject(value);
33196
33530
  const res = await collection.insertOne(value, { session });
33197
33531
  delNamespace().then(() => {
33198
- import_node_server_utils180.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33532
+ import_node_server_utils181.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33199
33533
  }).catch((err) => {
33200
- import_node_server_utils180.logger.error(
33534
+ import_node_server_utils181.logger.error(
33201
33535
  `Failed to clear cache for namespace: ${namespace_collection}`,
33202
33536
  err
33203
33537
  );
@@ -33206,7 +33540,7 @@ function useOccurrenceSubjectRepo() {
33206
33540
  } catch (error) {
33207
33541
  const isDuplicated = error.message.includes("duplicate");
33208
33542
  if (isDuplicated) {
33209
- throw new import_node_server_utils180.BadRequestError("Occurrence subject already exists.");
33543
+ throw new import_node_server_utils181.BadRequestError("Occurrence subject already exists.");
33210
33544
  }
33211
33545
  throw error;
33212
33546
  }
@@ -33222,7 +33556,7 @@ function useOccurrenceSubjectRepo() {
33222
33556
  try {
33223
33557
  site = new import_mongodb101.ObjectId(site);
33224
33558
  } catch (error) {
33225
- throw new import_node_server_utils180.BadRequestError("Invalid site ID format.");
33559
+ throw new import_node_server_utils181.BadRequestError("Invalid site ID format.");
33226
33560
  }
33227
33561
  const baseQuery = {
33228
33562
  site,
@@ -33241,10 +33575,10 @@ function useOccurrenceSubjectRepo() {
33241
33575
  query.$text = { $search: search };
33242
33576
  cacheOptions.search = search;
33243
33577
  }
33244
- const cacheKey = (0, import_node_server_utils180.makeCacheKey)(namespace_collection, cacheOptions);
33578
+ const cacheKey = (0, import_node_server_utils181.makeCacheKey)(namespace_collection, cacheOptions);
33245
33579
  const cachedData = await getCache(cacheKey);
33246
33580
  if (cachedData) {
33247
- import_node_server_utils180.logger.info(`Cache hit for key: ${cacheKey}`);
33581
+ import_node_server_utils181.logger.info(`Cache hit for key: ${cacheKey}`);
33248
33582
  return cachedData;
33249
33583
  }
33250
33584
  try {
@@ -33302,11 +33636,11 @@ function useOccurrenceSubjectRepo() {
33302
33636
  ]).toArray();
33303
33637
  length = await collection.countDocuments(regexQuery, { session });
33304
33638
  }
33305
- const data = (0, import_node_server_utils180.paginate)(items, page, limit, length);
33639
+ const data = (0, import_node_server_utils181.paginate)(items, page, limit, length);
33306
33640
  setCache(cacheKey, data, 15 * 60).then(() => {
33307
- import_node_server_utils180.logger.info(`Cache set for key: ${cacheKey}`);
33641
+ import_node_server_utils181.logger.info(`Cache set for key: ${cacheKey}`);
33308
33642
  }).catch((err) => {
33309
- import_node_server_utils180.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33643
+ import_node_server_utils181.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33310
33644
  });
33311
33645
  return data;
33312
33646
  } catch (error) {
@@ -33317,23 +33651,23 @@ function useOccurrenceSubjectRepo() {
33317
33651
  try {
33318
33652
  _id = new import_mongodb101.ObjectId(_id);
33319
33653
  } catch (error) {
33320
- throw new import_node_server_utils180.BadRequestError("Invalid occurrence subject ID format.");
33654
+ throw new import_node_server_utils181.BadRequestError("Invalid occurrence subject ID format.");
33321
33655
  }
33322
- const cacheKey = (0, import_node_server_utils180.makeCacheKey)(namespace_collection, { _id });
33656
+ const cacheKey = (0, import_node_server_utils181.makeCacheKey)(namespace_collection, { _id });
33323
33657
  const cachedData = await getCache(cacheKey);
33324
33658
  if (cachedData) {
33325
- import_node_server_utils180.logger.info(`Cache hit for key: ${cacheKey}`);
33659
+ import_node_server_utils181.logger.info(`Cache hit for key: ${cacheKey}`);
33326
33660
  return cachedData;
33327
33661
  }
33328
33662
  try {
33329
33663
  const data = await collection.findOne({ _id }, { session });
33330
33664
  if (!data) {
33331
- throw new import_node_server_utils180.NotFoundError("Occurrence subject not found.");
33665
+ throw new import_node_server_utils181.NotFoundError("Occurrence subject not found.");
33332
33666
  }
33333
33667
  setCache(cacheKey, data, 15 * 60).then(() => {
33334
- import_node_server_utils180.logger.info(`Cache set for key: ${cacheKey}`);
33668
+ import_node_server_utils181.logger.info(`Cache set for key: ${cacheKey}`);
33335
33669
  }).catch((err) => {
33336
- import_node_server_utils180.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33670
+ import_node_server_utils181.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33337
33671
  });
33338
33672
  return data;
33339
33673
  } catch (error) {
@@ -33345,7 +33679,7 @@ function useOccurrenceSubjectRepo() {
33345
33679
  try {
33346
33680
  _id = new import_mongodb101.ObjectId(_id);
33347
33681
  } catch (error) {
33348
- throw new import_node_server_utils180.BadRequestError("Invalid ID format.");
33682
+ throw new import_node_server_utils181.BadRequestError("Invalid ID format.");
33349
33683
  }
33350
33684
  try {
33351
33685
  const res = await collection.updateOne(
@@ -33354,14 +33688,14 @@ function useOccurrenceSubjectRepo() {
33354
33688
  { session }
33355
33689
  );
33356
33690
  if (res.modifiedCount === 0) {
33357
- throw new import_node_server_utils180.InternalServerError(
33691
+ throw new import_node_server_utils181.InternalServerError(
33358
33692
  "Unable to update daily occurrence Subject."
33359
33693
  );
33360
33694
  }
33361
33695
  delNamespace().then(() => {
33362
- import_node_server_utils180.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33696
+ import_node_server_utils181.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33363
33697
  }).catch((err) => {
33364
- import_node_server_utils180.logger.error(
33698
+ import_node_server_utils181.logger.error(
33365
33699
  `Failed to clear cache for namespace: ${namespace_collection}`,
33366
33700
  err
33367
33701
  );
@@ -33375,7 +33709,7 @@ function useOccurrenceSubjectRepo() {
33375
33709
  try {
33376
33710
  _id = new import_mongodb101.ObjectId(_id);
33377
33711
  } catch (error) {
33378
- throw new import_node_server_utils180.BadRequestError("Invalid occurrence subject ID format.");
33712
+ throw new import_node_server_utils181.BadRequestError("Invalid occurrence subject ID format.");
33379
33713
  }
33380
33714
  try {
33381
33715
  const updateValue = {
@@ -33385,12 +33719,12 @@ function useOccurrenceSubjectRepo() {
33385
33719
  };
33386
33720
  const res = await collection.updateOne({ _id }, { $set: updateValue });
33387
33721
  if (res.modifiedCount === 0) {
33388
- throw new import_node_server_utils180.InternalServerError("Unable to delete occurrence subject.");
33722
+ throw new import_node_server_utils181.InternalServerError("Unable to delete occurrence subject.");
33389
33723
  }
33390
33724
  delNamespace().then(() => {
33391
- import_node_server_utils180.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33725
+ import_node_server_utils181.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33392
33726
  }).catch((err) => {
33393
- import_node_server_utils180.logger.error(
33727
+ import_node_server_utils181.logger.error(
33394
33728
  `Failed to clear cache for namespace: ${namespace_collection}`,
33395
33729
  err
33396
33730
  );
@@ -33427,7 +33761,7 @@ function useOccurrenceEntryService() {
33427
33761
  const { getOccurrenceSubjectById: _getOccurrenceSubjectById } = useOccurrenceSubjectRepo();
33428
33762
  const { getUserById: _getUserById } = useUserRepo();
33429
33763
  async function add(value) {
33430
- const session = import_node_server_utils181.useAtlas.getClient()?.startSession();
33764
+ const session = import_node_server_utils182.useAtlas.getClient()?.startSession();
33431
33765
  session?.startTransaction();
33432
33766
  try {
33433
33767
  const [existingEntryWithBookId, occurrenceBook, occurrenceSubject, user] = await Promise.all([
@@ -33463,7 +33797,7 @@ function useOccurrenceEntryService() {
33463
33797
  }
33464
33798
  }
33465
33799
  async function updateOccurrenceEntryById(id, value) {
33466
- const session = import_node_server_utils181.useAtlas.getClient()?.startSession();
33800
+ const session = import_node_server_utils182.useAtlas.getClient()?.startSession();
33467
33801
  session?.startTransaction();
33468
33802
  try {
33469
33803
  const occurrenceEntry = await _getOccurrenceEntryById(id);
@@ -33490,7 +33824,7 @@ function useOccurrenceEntryService() {
33490
33824
  }
33491
33825
 
33492
33826
  // src/controllers/occurrence-entry.controller.ts
33493
- var import_node_server_utils182 = require("@7365admin1/node-server-utils");
33827
+ var import_node_server_utils183 = require("@7365admin1/node-server-utils");
33494
33828
  var import_joi104 = __toESM(require("joi"));
33495
33829
  function useOccurrenceEntryController() {
33496
33830
  const { add: _add, updateOccurrenceEntryById: _updateOccurrenceEntryById } = useOccurrenceEntryService();
@@ -33507,8 +33841,8 @@ function useOccurrenceEntryController() {
33507
33841
  });
33508
33842
  if (error) {
33509
33843
  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));
33844
+ import_node_server_utils183.logger.log({ level: "error", message: messages });
33845
+ next(new import_node_server_utils183.BadRequestError(messages));
33512
33846
  return;
33513
33847
  }
33514
33848
  try {
@@ -33516,7 +33850,7 @@ function useOccurrenceEntryController() {
33516
33850
  res.status(201).json(data);
33517
33851
  return;
33518
33852
  } catch (error2) {
33519
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
33853
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33520
33854
  next(error2);
33521
33855
  return;
33522
33856
  }
@@ -33539,8 +33873,8 @@ function useOccurrenceEntryController() {
33539
33873
  });
33540
33874
  if (error) {
33541
33875
  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));
33876
+ import_node_server_utils183.logger.log({ level: "error", message: messages });
33877
+ next(new import_node_server_utils183.BadRequestError(messages));
33544
33878
  return;
33545
33879
  }
33546
33880
  const search = req.query.search ?? "";
@@ -33569,7 +33903,7 @@ function useOccurrenceEntryController() {
33569
33903
  res.status(200).json(data);
33570
33904
  return;
33571
33905
  } catch (error2) {
33572
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
33906
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33573
33907
  next(error2);
33574
33908
  return;
33575
33909
  }
@@ -33579,8 +33913,8 @@ function useOccurrenceEntryController() {
33579
33913
  const _id = req.params.id;
33580
33914
  const { error } = validation.validate(_id);
33581
33915
  if (error) {
33582
- import_node_server_utils182.logger.log({ level: "error", message: error.message });
33583
- next(new import_node_server_utils182.BadRequestError(error.message));
33916
+ import_node_server_utils183.logger.log({ level: "error", message: error.message });
33917
+ next(new import_node_server_utils183.BadRequestError(error.message));
33584
33918
  return;
33585
33919
  }
33586
33920
  try {
@@ -33588,7 +33922,7 @@ function useOccurrenceEntryController() {
33588
33922
  res.status(200).json(data);
33589
33923
  return;
33590
33924
  } catch (error2) {
33591
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
33925
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33592
33926
  next(error2);
33593
33927
  return;
33594
33928
  }
@@ -33601,8 +33935,8 @@ function useOccurrenceEntryController() {
33601
33935
  });
33602
33936
  if (error) {
33603
33937
  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));
33938
+ import_node_server_utils183.logger.log({ level: "error", message: messages });
33939
+ next(new import_node_server_utils183.BadRequestError(messages));
33606
33940
  return;
33607
33941
  }
33608
33942
  try {
@@ -33610,7 +33944,7 @@ function useOccurrenceEntryController() {
33610
33944
  res.status(200).json({ message: result });
33611
33945
  return;
33612
33946
  } catch (error2) {
33613
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
33947
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33614
33948
  next(error2);
33615
33949
  return;
33616
33950
  }
@@ -33620,8 +33954,8 @@ function useOccurrenceEntryController() {
33620
33954
  const _id = req.params.id;
33621
33955
  const { error } = validation.validate(_id);
33622
33956
  if (error) {
33623
- import_node_server_utils182.logger.log({ level: "error", message: error.message });
33624
- next(new import_node_server_utils182.BadRequestError(error.message));
33957
+ import_node_server_utils183.logger.log({ level: "error", message: error.message });
33958
+ next(new import_node_server_utils183.BadRequestError(error.message));
33625
33959
  return;
33626
33960
  }
33627
33961
  try {
@@ -33629,7 +33963,7 @@ function useOccurrenceEntryController() {
33629
33963
  res.status(200).json({ message: "Successfully deleted occurrence entry." });
33630
33964
  return;
33631
33965
  } catch (error2) {
33632
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
33966
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33633
33967
  next(error2);
33634
33968
  return;
33635
33969
  }
@@ -33639,8 +33973,8 @@ function useOccurrenceEntryController() {
33639
33973
  const _id = req.params.id;
33640
33974
  const { error } = validation.validate(_id);
33641
33975
  if (error) {
33642
- import_node_server_utils182.logger.log({ level: "error", message: error.message });
33643
- next(new import_node_server_utils182.BadRequestError(error.message));
33976
+ import_node_server_utils183.logger.log({ level: "error", message: error.message });
33977
+ next(new import_node_server_utils183.BadRequestError(error.message));
33644
33978
  return;
33645
33979
  }
33646
33980
  try {
@@ -33648,7 +33982,7 @@ function useOccurrenceEntryController() {
33648
33982
  res.status(200).json({ count: data });
33649
33983
  return;
33650
33984
  } catch (error2) {
33651
- import_node_server_utils182.logger.log({ level: "error", message: error2.message });
33985
+ import_node_server_utils183.logger.log({ level: "error", message: error2.message });
33652
33986
  next(error2);
33653
33987
  return;
33654
33988
  }
@@ -33749,23 +34083,23 @@ function MOnlineForm(value) {
33749
34083
  }
33750
34084
 
33751
34085
  // src/repositories/online-form.repo.ts
33752
- var import_node_server_utils183 = require("@7365admin1/node-server-utils");
34086
+ var import_node_server_utils184 = require("@7365admin1/node-server-utils");
33753
34087
  var import_mongodb103 = require("mongodb");
33754
34088
  function useOnlineFormRepo() {
33755
- const db = import_node_server_utils183.useAtlas.getDb();
34089
+ const db = import_node_server_utils184.useAtlas.getDb();
33756
34090
  if (!db) {
33757
- throw new import_node_server_utils183.InternalServerError("Unable to connect to server.");
34091
+ throw new import_node_server_utils184.InternalServerError("Unable to connect to server.");
33758
34092
  }
33759
34093
  const namespace_collection = "online-forms";
33760
34094
  const collection = db.collection(namespace_collection);
33761
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils183.useCache)(namespace_collection);
34095
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils184.useCache)(namespace_collection);
33762
34096
  async function createTextIndex() {
33763
34097
  try {
33764
34098
  await collection.createIndex({
33765
34099
  name: "text"
33766
34100
  });
33767
34101
  } catch (error) {
33768
- throw new import_node_server_utils183.InternalServerError(
34102
+ throw new import_node_server_utils184.InternalServerError(
33769
34103
  "Failed to create text index on online form."
33770
34104
  );
33771
34105
  }
@@ -33775,9 +34109,9 @@ function useOnlineFormRepo() {
33775
34109
  value = MOnlineForm(value);
33776
34110
  const res = await collection.insertOne(value, { session });
33777
34111
  delNamespace().then(() => {
33778
- import_node_server_utils183.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
34112
+ import_node_server_utils184.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33779
34113
  }).catch((err) => {
33780
- import_node_server_utils183.logger.error(
34114
+ import_node_server_utils184.logger.error(
33781
34115
  `Failed to clear cache for namespace: ${namespace_collection}`,
33782
34116
  err
33783
34117
  );
@@ -33786,7 +34120,7 @@ function useOnlineFormRepo() {
33786
34120
  } catch (error) {
33787
34121
  const isDuplicated = error.message.includes("duplicate");
33788
34122
  if (isDuplicated) {
33789
- throw new import_node_server_utils183.BadRequestError("Online Form already exists.");
34123
+ throw new import_node_server_utils184.BadRequestError("Online Form already exists.");
33790
34124
  }
33791
34125
  throw error;
33792
34126
  }
@@ -33815,10 +34149,10 @@ function useOnlineFormRepo() {
33815
34149
  query.$or = [{ name: { $regex: search, $options: "i" } }];
33816
34150
  cacheOptions.search = search;
33817
34151
  }
33818
- const cacheKey = (0, import_node_server_utils183.makeCacheKey)(namespace_collection, cacheOptions);
34152
+ const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, cacheOptions);
33819
34153
  const cachedData = await getCache(cacheKey);
33820
34154
  if (cachedData) {
33821
- import_node_server_utils183.logger.info(`Cache hit for key: ${cacheKey}`);
34155
+ import_node_server_utils184.logger.info(`Cache hit for key: ${cacheKey}`);
33822
34156
  return cachedData;
33823
34157
  }
33824
34158
  try {
@@ -33839,11 +34173,11 @@ function useOnlineFormRepo() {
33839
34173
  }
33840
34174
  ]).toArray();
33841
34175
  const length = await collection.countDocuments(query);
33842
- const data = (0, import_node_server_utils183.paginate)(items, page, limit, length);
34176
+ const data = (0, import_node_server_utils184.paginate)(items, page, limit, length);
33843
34177
  setCache(cacheKey, data, 15 * 60).then(() => {
33844
- import_node_server_utils183.logger.info(`Cache set for key: ${cacheKey}`);
34178
+ import_node_server_utils184.logger.info(`Cache set for key: ${cacheKey}`);
33845
34179
  }).catch((err) => {
33846
- import_node_server_utils183.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34180
+ import_node_server_utils184.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33847
34181
  });
33848
34182
  return data;
33849
34183
  } catch (error) {
@@ -33854,12 +34188,12 @@ function useOnlineFormRepo() {
33854
34188
  try {
33855
34189
  _id = new import_mongodb103.ObjectId(_id);
33856
34190
  } catch (error) {
33857
- throw new import_node_server_utils183.BadRequestError("Invalid online form ID format.");
34191
+ throw new import_node_server_utils184.BadRequestError("Invalid online form ID format.");
33858
34192
  }
33859
- const cacheKey = (0, import_node_server_utils183.makeCacheKey)(namespace_collection, { _id });
34193
+ const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, { _id });
33860
34194
  const cachedData = await getCache(cacheKey);
33861
34195
  if (cachedData) {
33862
- import_node_server_utils183.logger.info(`Cache hit for key: ${cacheKey}`);
34196
+ import_node_server_utils184.logger.info(`Cache hit for key: ${cacheKey}`);
33863
34197
  return cachedData;
33864
34198
  }
33865
34199
  try {
@@ -33881,12 +34215,12 @@ function useOnlineFormRepo() {
33881
34215
  }
33882
34216
  ]).toArray();
33883
34217
  if (!data || !data.length) {
33884
- throw new import_node_server_utils183.NotFoundError("Document not found.");
34218
+ throw new import_node_server_utils184.NotFoundError("Document not found.");
33885
34219
  }
33886
34220
  setCache(cacheKey, data[0], 15 * 60).then(() => {
33887
- import_node_server_utils183.logger.info(`Cache set for key: ${cacheKey}`);
34221
+ import_node_server_utils184.logger.info(`Cache set for key: ${cacheKey}`);
33888
34222
  }).catch((err) => {
33889
- import_node_server_utils183.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34223
+ import_node_server_utils184.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
33890
34224
  });
33891
34225
  return data[0];
33892
34226
  } catch (error) {
@@ -33897,7 +34231,7 @@ function useOnlineFormRepo() {
33897
34231
  try {
33898
34232
  _id = new import_mongodb103.ObjectId(_id);
33899
34233
  } catch (error) {
33900
- throw new import_node_server_utils183.BadRequestError("Invalid online form ID format.");
34234
+ throw new import_node_server_utils184.BadRequestError("Invalid online form ID format.");
33901
34235
  }
33902
34236
  try {
33903
34237
  const updateValue = {
@@ -33906,12 +34240,12 @@ function useOnlineFormRepo() {
33906
34240
  };
33907
34241
  const res = await collection.updateOne({ _id }, { $set: updateValue });
33908
34242
  if (res.modifiedCount === 0) {
33909
- throw new import_node_server_utils183.InternalServerError("Unable to update online form.");
34243
+ throw new import_node_server_utils184.InternalServerError("Unable to update online form.");
33910
34244
  }
33911
34245
  delNamespace().then(() => {
33912
- import_node_server_utils183.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
34246
+ import_node_server_utils184.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33913
34247
  }).catch((err) => {
33914
- import_node_server_utils183.logger.error(
34248
+ import_node_server_utils184.logger.error(
33915
34249
  `Failed to clear cache for namespace: ${namespace_collection}`,
33916
34250
  err
33917
34251
  );
@@ -33925,7 +34259,7 @@ function useOnlineFormRepo() {
33925
34259
  try {
33926
34260
  _id = new import_mongodb103.ObjectId(_id);
33927
34261
  } catch (error) {
33928
- throw new import_node_server_utils183.BadRequestError("Invalid online form ID format.");
34262
+ throw new import_node_server_utils184.BadRequestError("Invalid online form ID format.");
33929
34263
  }
33930
34264
  try {
33931
34265
  const updateValue = {
@@ -33939,12 +34273,12 @@ function useOnlineFormRepo() {
33939
34273
  { session }
33940
34274
  );
33941
34275
  if (res.modifiedCount === 0) {
33942
- throw new import_node_server_utils183.InternalServerError("Unable to delete online form.");
34276
+ throw new import_node_server_utils184.InternalServerError("Unable to delete online form.");
33943
34277
  }
33944
34278
  delNamespace().then(() => {
33945
- import_node_server_utils183.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
34279
+ import_node_server_utils184.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
33946
34280
  }).catch((err) => {
33947
- import_node_server_utils183.logger.error(
34281
+ import_node_server_utils184.logger.error(
33948
34282
  `Failed to clear cache for namespace: ${namespace_collection}`,
33949
34283
  err
33950
34284
  );
@@ -33958,7 +34292,7 @@ function useOnlineFormRepo() {
33958
34292
  try {
33959
34293
  site = new import_mongodb103.ObjectId(site);
33960
34294
  } catch (error) {
33961
- throw new import_node_server_utils183.BadRequestError(
34295
+ throw new import_node_server_utils184.BadRequestError(
33962
34296
  "Invalid online form configuration site ID format."
33963
34297
  );
33964
34298
  }
@@ -33977,10 +34311,10 @@ function useOnlineFormRepo() {
33977
34311
  cacheOptions.search = search;
33978
34312
  }
33979
34313
  cacheOptions.site = site;
33980
- const cacheKey = (0, import_node_server_utils183.makeCacheKey)(namespace_collection, { site });
34314
+ const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, { site });
33981
34315
  const cachedData = await getCache(cacheKey);
33982
34316
  if (cachedData) {
33983
- import_node_server_utils183.logger.info(`Cache hit for key: ${cacheKey}`);
34317
+ import_node_server_utils184.logger.info(`Cache hit for key: ${cacheKey}`);
33984
34318
  return cachedData;
33985
34319
  }
33986
34320
  try {
@@ -33999,11 +34333,11 @@ function useOnlineFormRepo() {
33999
34333
  }
34000
34334
  ]).toArray();
34001
34335
  const length = await collection.countDocuments(query);
34002
- const data = (0, import_node_server_utils183.paginate)(items, page, limit, length);
34336
+ const data = (0, import_node_server_utils184.paginate)(items, page, limit, length);
34003
34337
  setCache(cacheKey, data, 15 * 60).then(() => {
34004
- import_node_server_utils183.logger.info(`Cache set for key: ${cacheKey}`);
34338
+ import_node_server_utils184.logger.info(`Cache set for key: ${cacheKey}`);
34005
34339
  }).catch((err) => {
34006
- import_node_server_utils183.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34340
+ import_node_server_utils184.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34007
34341
  });
34008
34342
  return data;
34009
34343
  } catch (error) {
@@ -34022,7 +34356,7 @@ function useOnlineFormRepo() {
34022
34356
  }
34023
34357
 
34024
34358
  // src/controllers/online-form.controller.ts
34025
- var import_node_server_utils184 = require("@7365admin1/node-server-utils");
34359
+ var import_node_server_utils185 = require("@7365admin1/node-server-utils");
34026
34360
  var import_joi106 = __toESM(require("joi"));
34027
34361
  function useOnlineFormController() {
34028
34362
  const {
@@ -34045,8 +34379,8 @@ function useOnlineFormController() {
34045
34379
  });
34046
34380
  if (error) {
34047
34381
  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));
34382
+ import_node_server_utils185.logger.log({ level: "error", message: messages });
34383
+ next(new import_node_server_utils185.BadRequestError(messages));
34050
34384
  return;
34051
34385
  }
34052
34386
  try {
@@ -34054,7 +34388,7 @@ function useOnlineFormController() {
34054
34388
  res.status(201).json({ message: data });
34055
34389
  return;
34056
34390
  } catch (error2) {
34057
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34391
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34058
34392
  next(error2);
34059
34393
  return;
34060
34394
  }
@@ -34072,8 +34406,8 @@ function useOnlineFormController() {
34072
34406
  query.status = req.query.status;
34073
34407
  const { error } = validation.validate(query);
34074
34408
  if (error) {
34075
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34076
- next(new import_node_server_utils184.BadRequestError(error.message));
34409
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34410
+ next(new import_node_server_utils185.BadRequestError(error.message));
34077
34411
  return;
34078
34412
  }
34079
34413
  const search = req.query.search ?? "";
@@ -34087,7 +34421,7 @@ function useOnlineFormController() {
34087
34421
  res.json(data);
34088
34422
  return;
34089
34423
  } catch (error2) {
34090
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34424
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34091
34425
  next(error2);
34092
34426
  return;
34093
34427
  }
@@ -34097,8 +34431,8 @@ function useOnlineFormController() {
34097
34431
  const _id = req.params.id;
34098
34432
  const { error } = validation.validate(_id);
34099
34433
  if (error) {
34100
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34101
- next(new import_node_server_utils184.BadRequestError(error.message));
34434
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34435
+ next(new import_node_server_utils185.BadRequestError(error.message));
34102
34436
  return;
34103
34437
  }
34104
34438
  try {
@@ -34106,7 +34440,7 @@ function useOnlineFormController() {
34106
34440
  res.json(data);
34107
34441
  return;
34108
34442
  } catch (error2) {
34109
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34443
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34110
34444
  next(error2);
34111
34445
  return;
34112
34446
  }
@@ -34138,8 +34472,8 @@ function useOnlineFormController() {
34138
34472
  const payload = { ...req.body, updatedBy };
34139
34473
  const { error } = validation.validate({ _id, ...payload });
34140
34474
  if (error) {
34141
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34142
- next(new import_node_server_utils184.BadRequestError(error.message));
34475
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34476
+ next(new import_node_server_utils185.BadRequestError(error.message));
34143
34477
  return;
34144
34478
  }
34145
34479
  try {
@@ -34147,7 +34481,7 @@ function useOnlineFormController() {
34147
34481
  res.json({ message: "Successfully updated online form." });
34148
34482
  return;
34149
34483
  } catch (error2) {
34150
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34484
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34151
34485
  next(error2);
34152
34486
  return;
34153
34487
  }
@@ -34157,8 +34491,8 @@ function useOnlineFormController() {
34157
34491
  const _id = req.params.id;
34158
34492
  const { error } = validation.validate(_id);
34159
34493
  if (error) {
34160
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34161
- next(new import_node_server_utils184.BadRequestError(error.message));
34494
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34495
+ next(new import_node_server_utils185.BadRequestError(error.message));
34162
34496
  return;
34163
34497
  }
34164
34498
  try {
@@ -34166,7 +34500,7 @@ function useOnlineFormController() {
34166
34500
  res.json({ message: "Successfully deleted online form." });
34167
34501
  return;
34168
34502
  } catch (error2) {
34169
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34503
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34170
34504
  next(error2);
34171
34505
  return;
34172
34506
  }
@@ -34178,8 +34512,8 @@ function useOnlineFormController() {
34178
34512
  query.status = req.query.status;
34179
34513
  const { error } = validation.validate(_id);
34180
34514
  if (error) {
34181
- import_node_server_utils184.logger.log({ level: "error", message: error.message });
34182
- next(new import_node_server_utils184.BadRequestError(error.message));
34515
+ import_node_server_utils185.logger.log({ level: "error", message: error.message });
34516
+ next(new import_node_server_utils185.BadRequestError(error.message));
34183
34517
  return;
34184
34518
  }
34185
34519
  try {
@@ -34187,7 +34521,7 @@ function useOnlineFormController() {
34187
34521
  res.json(data);
34188
34522
  return;
34189
34523
  } catch (error2) {
34190
- import_node_server_utils184.logger.log({ level: "error", message: error2.message });
34524
+ import_node_server_utils185.logger.log({ level: "error", message: error2.message });
34191
34525
  next(error2);
34192
34526
  return;
34193
34527
  }
@@ -34203,14 +34537,14 @@ function useOnlineFormController() {
34203
34537
  }
34204
34538
 
34205
34539
  // src/services/occurrence-subject.service.ts
34206
- var import_node_server_utils185 = require("@7365admin1/node-server-utils");
34540
+ var import_node_server_utils186 = require("@7365admin1/node-server-utils");
34207
34541
  function useOccurrenceSubjectService() {
34208
34542
  const {
34209
34543
  add: _add,
34210
34544
  updateOccurrenceSubjectById: _updateOccurrenceSubjectById
34211
34545
  } = useOccurrenceSubjectRepo();
34212
34546
  async function add(value) {
34213
- const session = import_node_server_utils185.useAtlas.getClient()?.startSession();
34547
+ const session = import_node_server_utils186.useAtlas.getClient()?.startSession();
34214
34548
  session?.startTransaction();
34215
34549
  try {
34216
34550
  await _add(value, session);
@@ -34224,7 +34558,7 @@ function useOccurrenceSubjectService() {
34224
34558
  }
34225
34559
  }
34226
34560
  async function updateOccurrenceSubjectById(id, value) {
34227
- const session = import_node_server_utils185.useAtlas.getClient()?.startSession();
34561
+ const session = import_node_server_utils186.useAtlas.getClient()?.startSession();
34228
34562
  session?.startTransaction();
34229
34563
  try {
34230
34564
  await _updateOccurrenceSubjectById(id, value, session);
@@ -34244,7 +34578,7 @@ function useOccurrenceSubjectService() {
34244
34578
  }
34245
34579
 
34246
34580
  // src/controllers/occurrence-subject.controller.ts
34247
- var import_node_server_utils186 = require("@7365admin1/node-server-utils");
34581
+ var import_node_server_utils187 = require("@7365admin1/node-server-utils");
34248
34582
  var import_joi107 = __toESM(require("joi"));
34249
34583
  function useOccurrenceSubjectController() {
34250
34584
  const {
@@ -34263,8 +34597,8 @@ function useOccurrenceSubjectController() {
34263
34597
  });
34264
34598
  if (error) {
34265
34599
  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));
34600
+ import_node_server_utils187.logger.log({ level: "error", message: messages });
34601
+ next(new import_node_server_utils187.BadRequestError(messages));
34268
34602
  return;
34269
34603
  }
34270
34604
  try {
@@ -34272,7 +34606,7 @@ function useOccurrenceSubjectController() {
34272
34606
  res.status(201).json(data);
34273
34607
  return;
34274
34608
  } catch (error2) {
34275
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34609
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34276
34610
  next(error2);
34277
34611
  return;
34278
34612
  }
@@ -34294,8 +34628,8 @@ function useOccurrenceSubjectController() {
34294
34628
  });
34295
34629
  if (error) {
34296
34630
  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));
34631
+ import_node_server_utils187.logger.log({ level: "error", message: messages });
34632
+ next(new import_node_server_utils187.BadRequestError(messages));
34299
34633
  return;
34300
34634
  }
34301
34635
  const search = req.query.search ?? "";
@@ -34322,7 +34656,7 @@ function useOccurrenceSubjectController() {
34322
34656
  res.status(200).json(data);
34323
34657
  return;
34324
34658
  } catch (error2) {
34325
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34659
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34326
34660
  next(error2);
34327
34661
  return;
34328
34662
  }
@@ -34332,8 +34666,8 @@ function useOccurrenceSubjectController() {
34332
34666
  const _id = req.params.id;
34333
34667
  const { error } = validation.validate(_id);
34334
34668
  if (error) {
34335
- import_node_server_utils186.logger.log({ level: "error", message: error.message });
34336
- next(new import_node_server_utils186.BadRequestError(error.message));
34669
+ import_node_server_utils187.logger.log({ level: "error", message: error.message });
34670
+ next(new import_node_server_utils187.BadRequestError(error.message));
34337
34671
  return;
34338
34672
  }
34339
34673
  try {
@@ -34341,7 +34675,7 @@ function useOccurrenceSubjectController() {
34341
34675
  res.status(200).json(data);
34342
34676
  return;
34343
34677
  } catch (error2) {
34344
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34678
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34345
34679
  next(error2);
34346
34680
  return;
34347
34681
  }
@@ -34354,8 +34688,8 @@ function useOccurrenceSubjectController() {
34354
34688
  });
34355
34689
  if (error) {
34356
34690
  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));
34691
+ import_node_server_utils187.logger.log({ level: "error", message: messages });
34692
+ next(new import_node_server_utils187.BadRequestError(messages));
34359
34693
  return;
34360
34694
  }
34361
34695
  try {
@@ -34363,7 +34697,7 @@ function useOccurrenceSubjectController() {
34363
34697
  res.status(200).json({ message: result });
34364
34698
  return;
34365
34699
  } catch (error2) {
34366
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34700
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34367
34701
  next(error2);
34368
34702
  return;
34369
34703
  }
@@ -34373,8 +34707,8 @@ function useOccurrenceSubjectController() {
34373
34707
  const _id = req.params.id;
34374
34708
  const { error } = validation.validate(_id);
34375
34709
  if (error) {
34376
- import_node_server_utils186.logger.log({ level: "error", message: error.message });
34377
- next(new import_node_server_utils186.BadRequestError(error.message));
34710
+ import_node_server_utils187.logger.log({ level: "error", message: error.message });
34711
+ next(new import_node_server_utils187.BadRequestError(error.message));
34378
34712
  return;
34379
34713
  }
34380
34714
  try {
@@ -34382,7 +34716,7 @@ function useOccurrenceSubjectController() {
34382
34716
  res.status(200).json({ message: "Successfully deleted occurrence subject." });
34383
34717
  return;
34384
34718
  } catch (error2) {
34385
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
34719
+ import_node_server_utils187.logger.log({ level: "error", message: error2.message });
34386
34720
  next(error2);
34387
34721
  return;
34388
34722
  }
@@ -34399,7 +34733,7 @@ function useOccurrenceSubjectController() {
34399
34733
  // src/models/nfc-patrol-log.model.ts
34400
34734
  var import_mongodb104 = require("mongodb");
34401
34735
  var import_joi108 = __toESM(require("joi"));
34402
- var import_node_server_utils187 = require("@7365admin1/node-server-utils");
34736
+ var import_node_server_utils188 = require("@7365admin1/node-server-utils");
34403
34737
  var schemaNfcPatrolLog = import_joi108.default.object({
34404
34738
  _id: import_joi108.default.string().length(24).hex().optional().allow(null, ""),
34405
34739
  site: import_joi108.default.string().length(24).hex().required(),
@@ -34444,33 +34778,33 @@ var schemaNfcPatrolLog = import_joi108.default.object({
34444
34778
  function MNfcPatrolLog(valueArg) {
34445
34779
  const { error, value } = schemaNfcPatrolLog.validate(valueArg);
34446
34780
  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);
34781
+ import_node_server_utils188.logger.info(`NFC Patrol Log Model: ${error.message}`);
34782
+ throw new import_node_server_utils188.BadRequestError(error.message);
34449
34783
  }
34450
34784
  if (value._id && typeof value._id === "string") {
34451
34785
  try {
34452
34786
  value._id = new import_mongodb104.ObjectId(value._id);
34453
34787
  } catch (error2) {
34454
- throw new import_node_server_utils187.BadRequestError("Invalid _id format");
34788
+ throw new import_node_server_utils188.BadRequestError("Invalid _id format");
34455
34789
  }
34456
34790
  }
34457
34791
  try {
34458
34792
  value.site = new import_mongodb104.ObjectId(value.site);
34459
34793
  } catch (error2) {
34460
- throw new import_node_server_utils187.BadRequestError("Invalid site format");
34794
+ throw new import_node_server_utils188.BadRequestError("Invalid site format");
34461
34795
  }
34462
34796
  if (value?.createdBy) {
34463
34797
  try {
34464
34798
  value.createdBy = new import_mongodb104.ObjectId(value.createdBy);
34465
34799
  } catch (error2) {
34466
- throw new import_node_server_utils187.BadRequestError("Invalid createdBy format");
34800
+ throw new import_node_server_utils188.BadRequestError("Invalid createdBy format");
34467
34801
  }
34468
34802
  }
34469
34803
  if (value?.route?._id) {
34470
34804
  try {
34471
34805
  value.route._id = new import_mongodb104.ObjectId(value.route._id);
34472
34806
  } catch (error2) {
34473
- throw new import_node_server_utils187.BadRequestError("Invalid route _id format");
34807
+ throw new import_node_server_utils188.BadRequestError("Invalid route _id format");
34474
34808
  }
34475
34809
  }
34476
34810
  return {
@@ -34487,16 +34821,16 @@ function MNfcPatrolLog(valueArg) {
34487
34821
  }
34488
34822
 
34489
34823
  // src/repositories/nfc-patrol-log.repository.ts
34490
- var import_node_server_utils188 = require("@7365admin1/node-server-utils");
34824
+ var import_node_server_utils189 = require("@7365admin1/node-server-utils");
34491
34825
  var import_mongodb105 = require("mongodb");
34492
34826
  function useNfcPatrolLogRepo() {
34493
- const db = import_node_server_utils188.useAtlas.getDb();
34827
+ const db = import_node_server_utils189.useAtlas.getDb();
34494
34828
  if (!db) {
34495
- throw new import_node_server_utils188.InternalServerError("Unable to connect to server.");
34829
+ throw new import_node_server_utils189.InternalServerError("Unable to connect to server.");
34496
34830
  }
34497
34831
  const namespace_collection = "nfc-patrol-logs";
34498
34832
  const collection = db.collection(namespace_collection);
34499
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils188.useCache)(namespace_collection);
34833
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils189.useCache)(namespace_collection);
34500
34834
  async function createIndexes() {
34501
34835
  try {
34502
34836
  await collection.createIndexes([
@@ -34512,7 +34846,7 @@ function useNfcPatrolLogRepo() {
34512
34846
  }
34513
34847
  ]);
34514
34848
  } catch (error) {
34515
- throw new import_node_server_utils188.InternalServerError(
34849
+ throw new import_node_server_utils189.InternalServerError(
34516
34850
  `Failed to create index on ${namespace_collection}.`
34517
34851
  );
34518
34852
  }
@@ -34526,7 +34860,7 @@ function useNfcPatrolLogRepo() {
34526
34860
  } catch (error) {
34527
34861
  const isDuplicated = error.message.includes("duplicate");
34528
34862
  if (isDuplicated) {
34529
- throw new import_node_server_utils188.BadRequestError("NFC Patrol Log already exists.");
34863
+ throw new import_node_server_utils189.BadRequestError("NFC Patrol Log already exists.");
34530
34864
  }
34531
34865
  throw error;
34532
34866
  }
@@ -34543,7 +34877,7 @@ function useNfcPatrolLogRepo() {
34543
34877
  try {
34544
34878
  siteId = typeof site === "string" ? new import_mongodb105.ObjectId(site) : site;
34545
34879
  } catch {
34546
- throw new import_node_server_utils188.BadRequestError("Invalid site ID format.");
34880
+ throw new import_node_server_utils189.BadRequestError("Invalid site ID format.");
34547
34881
  }
34548
34882
  const query = {
34549
34883
  site: siteId
@@ -34570,10 +34904,10 @@ function useNfcPatrolLogRepo() {
34570
34904
  if (route?.startTime) {
34571
34905
  cacheOptions.routeStartTime = route?.startTime;
34572
34906
  }
34573
- const cacheKey = (0, import_node_server_utils188.makeCacheKey)(namespace_collection, cacheOptions);
34907
+ const cacheKey = (0, import_node_server_utils189.makeCacheKey)(namespace_collection, cacheOptions);
34574
34908
  const cachedData = await getCache(cacheKey);
34575
34909
  if (cachedData) {
34576
- import_node_server_utils188.logger.info(`Cache hit for key: ${cacheKey}`);
34910
+ import_node_server_utils189.logger.info(`Cache hit for key: ${cacheKey}`);
34577
34911
  return cachedData;
34578
34912
  }
34579
34913
  try {
@@ -34587,11 +34921,11 @@ function useNfcPatrolLogRepo() {
34587
34921
  { session }
34588
34922
  ).toArray();
34589
34923
  const length = await collection.countDocuments(query, { session });
34590
- const data = (0, import_node_server_utils188.paginate)(items, pageIndex, limit, length);
34924
+ const data = (0, import_node_server_utils189.paginate)(items, pageIndex, limit, length);
34591
34925
  setCache(cacheKey, data, 15 * 60).then(() => {
34592
- import_node_server_utils188.logger.info(`Cache set for key: ${cacheKey}`);
34926
+ import_node_server_utils189.logger.info(`Cache set for key: ${cacheKey}`);
34593
34927
  }).catch((err) => {
34594
- import_node_server_utils188.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34928
+ import_node_server_utils189.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
34595
34929
  });
34596
34930
  return data;
34597
34931
  } catch (error) {
@@ -34600,12 +34934,12 @@ function useNfcPatrolLogRepo() {
34600
34934
  }
34601
34935
  function delCachedData() {
34602
34936
  delNamespace().then(() => {
34603
- import_node_server_utils188.logger.log({
34937
+ import_node_server_utils189.logger.log({
34604
34938
  level: "info",
34605
34939
  message: `Cache namespace cleared for ${namespace_collection}`
34606
34940
  });
34607
34941
  }).catch((err) => {
34608
- import_node_server_utils188.logger.log({
34942
+ import_node_server_utils189.logger.log({
34609
34943
  level: "error",
34610
34944
  message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
34611
34945
  });
@@ -34619,11 +34953,11 @@ function useNfcPatrolLogRepo() {
34619
34953
  }
34620
34954
 
34621
34955
  // src/services/nfc-patrol-log.service.ts
34622
- var import_node_server_utils189 = require("@7365admin1/node-server-utils");
34956
+ var import_node_server_utils190 = require("@7365admin1/node-server-utils");
34623
34957
  function useNfcPatrolLogService() {
34624
34958
  const { add: _add } = useNfcPatrolLogRepo();
34625
34959
  async function add(value) {
34626
- const session = import_node_server_utils189.useAtlas.getClient()?.startSession();
34960
+ const session = import_node_server_utils190.useAtlas.getClient()?.startSession();
34627
34961
  session?.startTransaction();
34628
34962
  try {
34629
34963
  await _add(value, session);
@@ -34642,7 +34976,7 @@ function useNfcPatrolLogService() {
34642
34976
  }
34643
34977
 
34644
34978
  // src/controllers/nfc-patrol-log.controller.ts
34645
- var import_node_server_utils190 = require("@7365admin1/node-server-utils");
34979
+ var import_node_server_utils191 = require("@7365admin1/node-server-utils");
34646
34980
  var import_joi109 = __toESM(require("joi"));
34647
34981
  function useNfcPatrolLogController() {
34648
34982
  const { add: _add } = useNfcPatrolLogService();
@@ -34654,7 +34988,7 @@ function useNfcPatrolLogController() {
34654
34988
  res.status(201).json(data);
34655
34989
  return;
34656
34990
  } catch (error) {
34657
- import_node_server_utils190.logger.log({ level: "error", message: error.message });
34991
+ import_node_server_utils191.logger.log({ level: "error", message: error.message });
34658
34992
  next(error);
34659
34993
  return;
34660
34994
  }
@@ -34687,8 +35021,8 @@ function useNfcPatrolLogController() {
34687
35021
  });
34688
35022
  if (error) {
34689
35023
  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));
35024
+ import_node_server_utils191.logger.log({ level: "error", message: messages });
35025
+ next(new import_node_server_utils191.BadRequestError(messages));
34692
35026
  return;
34693
35027
  }
34694
35028
  const { page, limit, site, date, route } = value;
@@ -34703,7 +35037,7 @@ function useNfcPatrolLogController() {
34703
35037
  res.status(200).json(data);
34704
35038
  return;
34705
35039
  } catch (error2) {
34706
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
35040
+ import_node_server_utils191.logger.log({ level: "error", message: error2.message });
34707
35041
  next(error2);
34708
35042
  return;
34709
35043
  }