@7365admin1/core 2.20.0 → 2.21.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
@@ -65,6 +65,8 @@ __export(src_exports, {
65
65
  MFile: () => MFile,
66
66
  MGuestManagement: () => MGuestManagement,
67
67
  MIncidentReport: () => MIncidentReport,
68
+ MManpowerDesignations: () => MManpowerDesignations,
69
+ MManpowerMonitoring: () => MManpowerMonitoring,
68
70
  MMember: () => MMember,
69
71
  MNfcPatrolLog: () => MNfcPatrolLog,
70
72
  MNfcPatrolRoute: () => MNfcPatrolRoute,
@@ -76,6 +78,7 @@ __export(src_exports, {
76
78
  MOccurrenceSubject: () => MOccurrenceSubject,
77
79
  MOnlineForm: () => MOnlineForm,
78
80
  MOrg: () => MOrg,
81
+ MOvernightParkingApprovalHours: () => MOvernightParkingApprovalHours,
79
82
  MPatrolLog: () => MPatrolLog,
80
83
  MPatrolQuestion: () => MPatrolQuestion,
81
84
  MPatrolRoute: () => MPatrolRoute,
@@ -101,6 +104,8 @@ __export(src_exports, {
101
104
  MWorkOrder: () => MWorkOrder,
102
105
  OrgNature: () => OrgNature,
103
106
  PERSON_TYPES: () => PERSON_TYPES,
107
+ PMDashboardCollection: () => PMDashboardCollection,
108
+ Period: () => Period,
104
109
  PersonTypes: () => PersonTypes,
105
110
  SiteCategories: () => SiteCategories,
106
111
  SiteStatus: () => SiteStatus,
@@ -118,14 +123,30 @@ __export(src_exports, {
118
123
  allowedNatures: () => allowedNatures,
119
124
  attendanceSchema: () => attendanceSchema,
120
125
  attendanceSettingsSchema: () => attendanceSettingsSchema,
126
+ buildings_namespace_collection: () => buildings_namespace_collection,
127
+ bulletin_boards_namespace_collection: () => bulletin_boards_namespace_collection,
128
+ calculatePercentage: () => calculatePercentage,
121
129
  chatSchema: () => chatSchema,
122
130
  customerSchema: () => customerSchema,
131
+ designationsSchema: () => designationsSchema,
132
+ events_namespace_collection: () => events_namespace_collection,
133
+ facility_bookings_namespace_collection: () => facility_bookings_namespace_collection,
123
134
  feedbackSchema: () => feedbackSchema,
135
+ feedbacks_namespace_collection: () => feedbacks_namespace_collection,
124
136
  formatDahuaDate: () => formatDahuaDate,
137
+ getPeriodRangeWithPrevious: () => getPeriodRangeWithPrevious,
138
+ guests_namespace_collection: () => guests_namespace_collection,
125
139
  incidentReportLog: () => incidentReportLog,
140
+ incidents_namespace_collection: () => incidents_namespace_collection,
141
+ landscapeDashboardCollection: () => landscapeDashboardCollection,
142
+ mAndEDashboardCollection: () => mAndEDashboardCollection,
143
+ manpowerDesignationsSchema: () => manpowerDesignationsSchema,
144
+ manpowerMonitoringSchema: () => manpowerMonitoringSchema,
126
145
  nfcPatrolSettingsSchema: () => nfcPatrolSettingsSchema,
127
146
  nfcPatrolSettingsSchemaUpdate: () => nfcPatrolSettingsSchemaUpdate,
128
147
  orgSchema: () => orgSchema,
148
+ pestDashboardCollection: () => pestDashboardCollection,
149
+ poolDashboardCollection: () => poolDashboardCollection,
129
150
  promoCodeSchema: () => promoCodeSchema,
130
151
  robotSchema: () => robotSchema,
131
152
  schema: () => schema,
@@ -152,6 +173,7 @@ __export(src_exports, {
152
173
  schemaOccurrenceEntry: () => schemaOccurrenceEntry,
153
174
  schemaOccurrenceSubject: () => schemaOccurrenceSubject,
154
175
  schemaOnlineForm: () => schemaOnlineForm,
176
+ schemaOvernightParkingApprovalHours: () => schemaOvernightParkingApprovalHours,
155
177
  schemaPatrolLog: () => schemaPatrolLog,
156
178
  schemaPatrolQuestion: () => schemaPatrolQuestion,
157
179
  schemaPatrolRoute: () => schemaPatrolRoute,
@@ -193,7 +215,10 @@ __export(src_exports, {
193
215
  schemaVisitorTransaction: () => schemaVisitorTransaction,
194
216
  schemeCamera: () => schemeCamera,
195
217
  schemeLogCamera: () => schemeLogCamera,
218
+ securityDashboardCollection: () => securityDashboardCollection,
219
+ shiftSchema: () => shiftSchema,
196
220
  siteSchema: () => siteSchema,
221
+ site_people_namespace_collection: () => site_people_namespace_collection,
197
222
  tokenSchema: () => tokenSchema,
198
223
  updateSiteSchema: () => updateSiteSchema,
199
224
  useAccessManagementController: () => useAccessManagementController,
@@ -252,8 +277,15 @@ __export(src_exports, {
252
277
  useInvoiceController: () => useInvoiceController,
253
278
  useInvoiceModel: () => useInvoiceModel,
254
279
  useInvoiceRepo: () => useInvoiceRepo,
280
+ useManpowerDesignationCtrl: () => useManpowerDesignationCtrl,
281
+ useManpowerDesignationRepo: () => useManpowerDesignationRepo,
282
+ useManpowerMonitoringCtrl: () => useManpowerMonitoringCtrl,
283
+ useManpowerMonitoringRepo: () => useManpowerMonitoringRepo,
284
+ useManpowerMonitoringSrvc: () => useManpowerMonitoringSrvc,
255
285
  useMemberController: () => useMemberController,
256
286
  useMemberRepo: () => useMemberRepo,
287
+ useNewDashboardController: () => useNewDashboardController,
288
+ useNewDashboardRepo: () => useNewDashboardRepo,
257
289
  useNfcPatrolLogController: () => useNfcPatrolLogController,
258
290
  useNfcPatrolLogRepo: () => useNfcPatrolLogRepo,
259
291
  useNfcPatrolLogService: () => useNfcPatrolLogService,
@@ -279,6 +311,8 @@ __export(src_exports, {
279
311
  useOnlineFormRepo: () => useOnlineFormRepo,
280
312
  useOrgController: () => useOrgController,
281
313
  useOrgRepo: () => useOrgRepo,
314
+ useOvernightParkingController: () => useOvernightParkingController,
315
+ useOvernightParkingRepo: () => useOvernightParkingRepo,
282
316
  usePatrolLogController: () => usePatrolLogController,
283
317
  usePatrolLogRepo: () => usePatrolLogRepo,
284
318
  usePatrolQuestionController: () => usePatrolQuestionController,
@@ -344,7 +378,10 @@ __export(src_exports, {
344
378
  useWorkOrderService: () => useWorkOrderService,
345
379
  userSchema: () => userSchema,
346
380
  vehicleSchema: () => vehicleSchema,
347
- workOrderSchema: () => workOrderSchema
381
+ vehicles_namespace_collection: () => vehicles_namespace_collection,
382
+ visitors_namespace_collection: () => visitors_namespace_collection,
383
+ workOrderSchema: () => workOrderSchema,
384
+ work_orders_namespace_collection: () => work_orders_namespace_collection
348
385
  });
349
386
  module.exports = __toCommonJS(src_exports);
350
387
 
@@ -594,14 +631,16 @@ function MFeedback(value) {
594
631
 
595
632
  // src/repositories/feedback.repo.ts
596
633
  var import_node_server_utils5 = require("@7365admin1/node-server-utils");
634
+ var feedbacks_namespace_collection = "feedbacks";
597
635
  function useFeedbackRepo() {
598
636
  const db = import_node_server_utils5.useAtlas.getDb();
599
637
  if (!db) {
600
638
  throw new import_node_server_utils5.InternalServerError("Unable to connect to server.");
601
639
  }
602
- const namespace_collection = "feedbacks";
603
- const collection = db.collection(namespace_collection);
604
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils5.useCache)(namespace_collection);
640
+ const collection = db.collection(feedbacks_namespace_collection);
641
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils5.useCache)(
642
+ feedbacks_namespace_collection
643
+ );
605
644
  const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils5.useCache)("dashboard");
606
645
  async function createIndex() {
607
646
  try {
@@ -635,10 +674,12 @@ function useFeedbackRepo() {
635
674
  value = MFeedback(value);
636
675
  const res = await collection.insertOne(value, { session });
637
676
  delNamespace().then(() => {
638
- import_node_server_utils5.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
677
+ import_node_server_utils5.logger.info(
678
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
679
+ );
639
680
  }).catch((err) => {
640
681
  import_node_server_utils5.logger.error(
641
- `Failed to clear cache for namespace: ${namespace_collection}`,
682
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
642
683
  err
643
684
  );
644
685
  });
@@ -726,7 +767,7 @@ function useFeedbackRepo() {
726
767
  cacheOptions.to = to;
727
768
  }
728
769
  console.log("query", JSON.stringify(query));
729
- const cacheKey = (0, import_node_server_utils5.makeCacheKey)(namespace_collection, cacheOptions);
770
+ const cacheKey = (0, import_node_server_utils5.makeCacheKey)(feedbacks_namespace_collection, cacheOptions);
730
771
  const cachedData = await getCache(cacheKey);
731
772
  if (cachedData) {
732
773
  import_node_server_utils5.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -782,7 +823,7 @@ function useFeedbackRepo() {
782
823
  } catch (error) {
783
824
  throw new import_node_server_utils5.BadRequestError("Invalid feedback ID format.");
784
825
  }
785
- const cacheKey = (0, import_node_server_utils5.makeCacheKey)(namespace_collection, { _id });
826
+ const cacheKey = (0, import_node_server_utils5.makeCacheKey)(feedbacks_namespace_collection, { _id });
786
827
  const cachedData = await getCache(cacheKey);
787
828
  if (cachedData) {
788
829
  import_node_server_utils5.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -892,10 +933,12 @@ function useFeedbackRepo() {
892
933
  throw new import_node_server_utils5.InternalServerError("Unable to update feedback.");
893
934
  }
894
935
  delNamespace().then(() => {
895
- import_node_server_utils5.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
936
+ import_node_server_utils5.logger.info(
937
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
938
+ );
896
939
  }).catch((err) => {
897
940
  import_node_server_utils5.logger.error(
898
- `Failed to clear cache for namespace: ${namespace_collection}`,
941
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
899
942
  err
900
943
  );
901
944
  });
@@ -926,10 +969,12 @@ function useFeedbackRepo() {
926
969
  throw new import_node_server_utils5.InternalServerError("Unable to update feedback status.");
927
970
  }
928
971
  delNamespace().then(() => {
929
- import_node_server_utils5.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
972
+ import_node_server_utils5.logger.info(
973
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
974
+ );
930
975
  }).catch((err) => {
931
976
  import_node_server_utils5.logger.error(
932
- `Failed to clear cache for namespace: ${namespace_collection}`,
977
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
933
978
  err
934
979
  );
935
980
  });
@@ -950,10 +995,12 @@ function useFeedbackRepo() {
950
995
  session
951
996
  );
952
997
  delNamespace().then(() => {
953
- import_node_server_utils5.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
998
+ import_node_server_utils5.logger.info(
999
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
1000
+ );
954
1001
  }).catch((err) => {
955
1002
  import_node_server_utils5.logger.error(
956
- `Failed to clear cache for namespace: ${namespace_collection}`,
1003
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
957
1004
  err
958
1005
  );
959
1006
  });
@@ -985,10 +1032,12 @@ function useFeedbackRepo() {
985
1032
  throw new import_node_server_utils5.InternalServerError("Unable to update feedback category.");
986
1033
  }
987
1034
  delNamespace().then(() => {
988
- import_node_server_utils5.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1035
+ import_node_server_utils5.logger.info(
1036
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
1037
+ );
989
1038
  }).catch((err) => {
990
1039
  import_node_server_utils5.logger.error(
991
- `Failed to clear cache for namespace: ${namespace_collection}`,
1040
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
992
1041
  err
993
1042
  );
994
1043
  });
@@ -1022,10 +1071,12 @@ function useFeedbackRepo() {
1022
1071
  throw new import_node_server_utils5.InternalServerError("Unable to mark feedback as completed.");
1023
1072
  }
1024
1073
  delNamespace().then(() => {
1025
- import_node_server_utils5.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1074
+ import_node_server_utils5.logger.info(
1075
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
1076
+ );
1026
1077
  }).catch((err) => {
1027
1078
  import_node_server_utils5.logger.error(
1028
- `Failed to clear cache for namespace: ${namespace_collection}`,
1079
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
1029
1080
  err
1030
1081
  );
1031
1082
  });
@@ -1060,10 +1111,12 @@ function useFeedbackRepo() {
1060
1111
  throw new import_node_server_utils5.InternalServerError("Unable to delete feedback.");
1061
1112
  }
1062
1113
  delNamespace().then(() => {
1063
- import_node_server_utils5.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1114
+ import_node_server_utils5.logger.info(
1115
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
1116
+ );
1064
1117
  }).catch((err) => {
1065
1118
  import_node_server_utils5.logger.error(
1066
- `Failed to clear cache for namespace: ${namespace_collection}`,
1119
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
1067
1120
  err
1068
1121
  );
1069
1122
  });
@@ -1214,13 +1267,13 @@ function MWorkOrder(value) {
1214
1267
 
1215
1268
  // src/repositories/work-order.repo.ts
1216
1269
  var import_node_server_utils7 = require("@7365admin1/node-server-utils");
1270
+ var work_orders_namespace_collection = "work-orders";
1217
1271
  function useWorkOrderRepo() {
1218
1272
  const db = import_node_server_utils7.useAtlas.getDb();
1219
1273
  if (!db) {
1220
1274
  throw new import_node_server_utils7.InternalServerError("Unable to connect to server.");
1221
1275
  }
1222
- const namespace_collection = "work-orders";
1223
- const collection = db.collection(namespace_collection);
1276
+ const collection = db.collection(work_orders_namespace_collection);
1224
1277
  async function createIndex() {
1225
1278
  try {
1226
1279
  await collection.createIndexes([
@@ -1249,17 +1302,21 @@ function useWorkOrderRepo() {
1249
1302
  );
1250
1303
  }
1251
1304
  }
1252
- const { delNamespace, setCache, getCache, delCache } = (0, import_node_server_utils7.useCache)(namespace_collection);
1305
+ const { delNamespace, setCache, getCache, delCache } = (0, import_node_server_utils7.useCache)(
1306
+ work_orders_namespace_collection
1307
+ );
1253
1308
  const { delNamespace: _delDashboardNameSpace } = (0, import_node_server_utils7.useCache)("dashboard");
1254
1309
  async function createWorkOrder(value, session) {
1255
1310
  try {
1256
1311
  value = MWorkOrder(value);
1257
1312
  const res = await collection.insertOne(value, { session });
1258
1313
  delNamespace().then(() => {
1259
- import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1314
+ import_node_server_utils7.logger.info(
1315
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1316
+ );
1260
1317
  }).catch((err) => {
1261
1318
  import_node_server_utils7.logger.error(
1262
- `Failed to clear cache for namespace: ${namespace_collection}`,
1319
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1263
1320
  err
1264
1321
  );
1265
1322
  });
@@ -1326,7 +1383,10 @@ function useWorkOrderRepo() {
1326
1383
  query["metadata.serviceProvider"] = serviceProvider;
1327
1384
  cacheOptions["metadata.serviceProvider"] = serviceProvider;
1328
1385
  }
1329
- const cacheKey = (0, import_node_server_utils7.makeCacheKey)(namespace_collection, cacheOptions);
1386
+ const cacheKey = (0, import_node_server_utils7.makeCacheKey)(
1387
+ work_orders_namespace_collection,
1388
+ cacheOptions
1389
+ );
1330
1390
  const cachedData = await getCache(cacheKey);
1331
1391
  if (cachedData) {
1332
1392
  import_node_server_utils7.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -1383,7 +1443,7 @@ function useWorkOrderRepo() {
1383
1443
  throw new import_node_server_utils7.BadRequestError("Invalid work order ID format.");
1384
1444
  }
1385
1445
  try {
1386
- const cacheKey = (0, import_node_server_utils7.makeCacheKey)(namespace_collection, {
1446
+ const cacheKey = (0, import_node_server_utils7.makeCacheKey)(work_orders_namespace_collection, {
1387
1447
  _id,
1388
1448
  status: { $ne: "deleted" }
1389
1449
  });
@@ -1505,10 +1565,12 @@ function useWorkOrderRepo() {
1505
1565
  throw new import_node_server_utils7.InternalServerError("Unable to update work order.");
1506
1566
  }
1507
1567
  delNamespace().then(() => {
1508
- import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1568
+ import_node_server_utils7.logger.info(
1569
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1570
+ );
1509
1571
  }).catch((err) => {
1510
1572
  import_node_server_utils7.logger.error(
1511
- `Failed to clear cache for namespace: ${namespace_collection}`,
1573
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1512
1574
  err
1513
1575
  );
1514
1576
  });
@@ -1539,10 +1601,12 @@ function useWorkOrderRepo() {
1539
1601
  throw new import_node_server_utils7.InternalServerError("Unable to update work order status.");
1540
1602
  }
1541
1603
  delNamespace().then(() => {
1542
- import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1604
+ import_node_server_utils7.logger.info(
1605
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1606
+ );
1543
1607
  }).catch((err) => {
1544
1608
  import_node_server_utils7.logger.error(
1545
- `Failed to clear cache for namespace: ${namespace_collection}`,
1609
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1546
1610
  err
1547
1611
  );
1548
1612
  });
@@ -1568,10 +1632,12 @@ function useWorkOrderRepo() {
1568
1632
  session
1569
1633
  );
1570
1634
  delNamespace().then(() => {
1571
- import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1635
+ import_node_server_utils7.logger.info(
1636
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1637
+ );
1572
1638
  }).catch((err) => {
1573
1639
  import_node_server_utils7.logger.error(
1574
- `Failed to clear cache for namespace: ${namespace_collection}`,
1640
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1575
1641
  err
1576
1642
  );
1577
1643
  });
@@ -1609,10 +1675,12 @@ function useWorkOrderRepo() {
1609
1675
  );
1610
1676
  }
1611
1677
  delNamespace().then(() => {
1612
- import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1678
+ import_node_server_utils7.logger.info(
1679
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1680
+ );
1613
1681
  }).catch((err) => {
1614
1682
  import_node_server_utils7.logger.error(
1615
- `Failed to clear cache for namespace: ${namespace_collection}`,
1683
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1616
1684
  err
1617
1685
  );
1618
1686
  });
@@ -1647,10 +1715,12 @@ function useWorkOrderRepo() {
1647
1715
  throw new import_node_server_utils7.InternalServerError("Unable to delete work order.");
1648
1716
  }
1649
1717
  delNamespace().then(() => {
1650
- import_node_server_utils7.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
1718
+ import_node_server_utils7.logger.info(
1719
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1720
+ );
1651
1721
  }).catch((err) => {
1652
1722
  import_node_server_utils7.logger.error(
1653
- `Failed to clear cache for namespace: ${namespace_collection}`,
1723
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1654
1724
  err
1655
1725
  );
1656
1726
  });
@@ -2499,7 +2569,32 @@ function useUserRepo() {
2499
2569
  import_node_server_utils9.logger.info(`Cache hit for key: ${cacheKey}`);
2500
2570
  return cachedData;
2501
2571
  }
2502
- const data = await collection.findOne({ _id });
2572
+ const results = await collection.aggregate([
2573
+ { $match: { _id } },
2574
+ {
2575
+ $lookup: {
2576
+ from: "site.service-providers",
2577
+ let: { userOrgId: "$defaultOrg" },
2578
+ pipeline: [
2579
+ {
2580
+ $match: {
2581
+ $expr: { $eq: ["$orgId", "$$userOrgId"] }
2582
+ }
2583
+ },
2584
+ {
2585
+ $project: {
2586
+ _id: 1,
2587
+ name: 1,
2588
+ type: 1,
2589
+ siteId: 1
2590
+ }
2591
+ }
2592
+ ],
2593
+ as: "serviceProviders"
2594
+ }
2595
+ }
2596
+ ]).toArray();
2597
+ const data = results.length > 0 ? results[0] : null;
2503
2598
  if (!data) {
2504
2599
  throw new import_node_server_utils9.NotFoundError("User not found.");
2505
2600
  }
@@ -12993,8 +13088,7 @@ var schemaVisitorTransaction = import_joi36.default.object({
12993
13088
  ).optional().allow(null),
12994
13089
  visitorPass: import_joi36.default.string().optional().allow(null, ""),
12995
13090
  unitName: import_joi36.default.string().optional().allow(null, ""),
12996
- expiredAt: import_joi36.default.date().iso().optional().allow(null, ""),
12997
- visitorId: import_joi36.default.string().hex().length(24).required()
13091
+ expiredAt: import_joi36.default.date().iso().optional().allow(null, "")
12998
13092
  });
12999
13093
  var schemaUpdateVisTrans = import_joi36.default.object({
13000
13094
  _id: import_joi36.default.string().hex().length(24).required(),
@@ -13020,8 +13114,7 @@ var schemaUpdateVisTrans = import_joi36.default.object({
13020
13114
  status: import_joi36.default.string().optional().allow(null, ""),
13021
13115
  remarks: import_joi36.default.string().optional().allow(null, ""),
13022
13116
  manualCheckout: import_joi36.default.boolean().optional().allow(null),
13023
- expiredAt: import_joi36.default.date().iso().optional().allow(null, ""),
13024
- visitorId: import_joi36.default.string().hex().length(24).optional().allow(null)
13117
+ expiredAt: import_joi36.default.date().iso().optional().allow(null, "")
13025
13118
  });
13026
13119
  function MVisitorTransaction(value) {
13027
13120
  const { error } = schemaVisitorTransaction.validate(value);
@@ -13092,7 +13185,6 @@ function MVisitorTransaction(value) {
13092
13185
  visitorPass: value.visitorPass,
13093
13186
  unitName: value.unitName,
13094
13187
  expiredAt: value.expiredAt ?? null,
13095
- visitorId: value.visitorId ?? "",
13096
13188
  createdAt: value.createdAt ?? newDate,
13097
13189
  updatedAt: value.updatedAt ?? "",
13098
13190
  deletedAt: value.deletedAt ?? ""
@@ -13101,14 +13193,16 @@ function MVisitorTransaction(value) {
13101
13193
 
13102
13194
  // src/repositories/visitor-transaction.repo.ts
13103
13195
  var import_mongodb39 = require("mongodb");
13196
+ var visitors_namespace_collection = "visitor.transactions";
13104
13197
  function useVisitorTransactionRepo() {
13105
13198
  const db = import_node_server_utils67.useAtlas.getDb();
13106
13199
  if (!db) {
13107
13200
  throw new import_node_server_utils67.InternalServerError("Unable to connect to server.");
13108
13201
  }
13109
- const namespace_collection = "visitor.transactions";
13110
- const collection = db.collection(namespace_collection);
13111
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils67.useCache)(namespace_collection);
13202
+ const collection = db.collection(visitors_namespace_collection);
13203
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils67.useCache)(
13204
+ visitors_namespace_collection
13205
+ );
13112
13206
  async function createTextIndex() {
13113
13207
  try {
13114
13208
  await collection.createIndex({
@@ -13130,10 +13224,12 @@ function useVisitorTransactionRepo() {
13130
13224
  value = MVisitorTransaction(value);
13131
13225
  const res = await collection.insertOne(value, { session });
13132
13226
  delNamespace().then(() => {
13133
- import_node_server_utils67.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
13227
+ import_node_server_utils67.logger.info(
13228
+ `Cache cleared for namespace: ${visitors_namespace_collection}`
13229
+ );
13134
13230
  }).catch((err) => {
13135
13231
  import_node_server_utils67.logger.error(
13136
- `Failed to clear cache for namespace: ${namespace_collection}`,
13232
+ `Failed to clear cache for namespace: ${visitors_namespace_collection}`,
13137
13233
  err
13138
13234
  );
13139
13235
  });
@@ -13208,7 +13304,7 @@ function useVisitorTransactionRepo() {
13208
13304
  ...checkedOut !== void 0 && { checkedOut },
13209
13305
  ...plateNumber && { plateNumber }
13210
13306
  };
13211
- const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, cacheOptions);
13307
+ const cacheKey = (0, import_node_server_utils67.makeCacheKey)(visitors_namespace_collection, cacheOptions);
13212
13308
  const cachedData = await getCache(cacheKey);
13213
13309
  if (cachedData) {
13214
13310
  import_node_server_utils67.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -13220,6 +13316,36 @@ function useVisitorTransactionRepo() {
13220
13316
  collection.aggregate(
13221
13317
  [
13222
13318
  ...basePipeline,
13319
+ {
13320
+ $lookup: {
13321
+ from: "access-cards",
13322
+ localField: "_id",
13323
+ foreignField: "userId",
13324
+ let: { userId: "$_id" },
13325
+ pipeline: [
13326
+ {
13327
+ $match: {
13328
+ $expr: {
13329
+ $eq: ["$userId", "$$userId"]
13330
+ }
13331
+ }
13332
+ },
13333
+ {
13334
+ $project: {
13335
+ cardNo: 1,
13336
+ type: 1
13337
+ }
13338
+ }
13339
+ ],
13340
+ as: "accessCards"
13341
+ }
13342
+ },
13343
+ {
13344
+ $unwind: {
13345
+ path: "$accessCards",
13346
+ preserveNullAndEmptyArrays: true
13347
+ }
13348
+ },
13223
13349
  { $sort: sort },
13224
13350
  { $skip: skip },
13225
13351
  { $limit: limit }
@@ -13242,7 +13368,7 @@ function useVisitorTransactionRepo() {
13242
13368
  }
13243
13369
  async function getOpenByPlateNumber(plateNumber, site) {
13244
13370
  const _site = typeof site === "string" ? site : (0, import_node_server_utils67.toObjectId)(site);
13245
- const cacheKey = (0, import_node_server_utils67.makeCacheKey)(namespace_collection, {
13371
+ const cacheKey = (0, import_node_server_utils67.makeCacheKey)(visitors_namespace_collection, {
13246
13372
  plateNumber,
13247
13373
  key: "get-open-transaction-plate-number",
13248
13374
  site
@@ -13286,10 +13412,12 @@ function useVisitorTransactionRepo() {
13286
13412
  { session }
13287
13413
  );
13288
13414
  delNamespace().then(() => {
13289
- import_node_server_utils67.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
13415
+ import_node_server_utils67.logger.info(
13416
+ `Cache cleared for namespace: ${visitors_namespace_collection}`
13417
+ );
13290
13418
  }).catch((err) => {
13291
13419
  import_node_server_utils67.logger.error(
13292
- `Failed to clear cache for namespace: ${namespace_collection}`,
13420
+ `Failed to clear cache for namespace: ${visitors_namespace_collection}`,
13293
13421
  err
13294
13422
  );
13295
13423
  });
@@ -13315,10 +13443,12 @@ function useVisitorTransactionRepo() {
13315
13443
  throw new import_node_server_utils67.InternalServerError("Unable to delete visitor transaction.");
13316
13444
  }
13317
13445
  delNamespace().then(() => {
13318
- import_node_server_utils67.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
13446
+ import_node_server_utils67.logger.info(
13447
+ `Cache cleared for namespace: ${visitors_namespace_collection}`
13448
+ );
13319
13449
  }).catch((err) => {
13320
13450
  import_node_server_utils67.logger.error(
13321
- `Failed to clear cache for namespace: ${namespace_collection}`,
13451
+ `Failed to clear cache for namespace: ${visitors_namespace_collection}`,
13322
13452
  err
13323
13453
  );
13324
13454
  });
@@ -13388,10 +13518,12 @@ function useVisitorTransactionRepo() {
13388
13518
  { session }
13389
13519
  );
13390
13520
  delNamespace().then(() => {
13391
- import_node_server_utils67.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
13521
+ import_node_server_utils67.logger.info(
13522
+ `Cache cleared for namespace: ${visitors_namespace_collection}`
13523
+ );
13392
13524
  }).catch((err) => {
13393
13525
  import_node_server_utils67.logger.error(
13394
- `Failed to clear cache for namespace: ${namespace_collection}`,
13526
+ `Failed to clear cache for namespace: ${visitors_namespace_collection}`,
13395
13527
  err
13396
13528
  );
13397
13529
  });
@@ -13593,14 +13725,16 @@ var import_urllib = require("urllib");
13593
13725
  var import_node_server_utils69 = require("@7365admin1/node-server-utils");
13594
13726
  var import_mongodb41 = require("mongodb");
13595
13727
  var import_joi38 = __toESM(require("joi"));
13728
+ var vehicles_namespace_collection = "vehicles";
13596
13729
  function useVehicleRepo() {
13597
13730
  const db = import_node_server_utils69.useAtlas.getDb();
13598
13731
  if (!db) {
13599
13732
  throw new import_node_server_utils69.InternalServerError("Unable to connect to server.");
13600
13733
  }
13601
- const namespace_collection = "vehicles";
13602
- const collection = db.collection(namespace_collection);
13603
- const { delNamespace, setCache, getCache } = (0, import_node_server_utils69.useCache)(namespace_collection);
13734
+ const collection = db.collection(vehicles_namespace_collection);
13735
+ const { delNamespace, setCache, getCache } = (0, import_node_server_utils69.useCache)(
13736
+ vehicles_namespace_collection
13737
+ );
13604
13738
  async function createIndex() {
13605
13739
  try {
13606
13740
  await collection.createIndexes([
@@ -13633,10 +13767,12 @@ function useVehicleRepo() {
13633
13767
  value = MVehicle(value);
13634
13768
  const res = await collection.insertOne(value, { session });
13635
13769
  delNamespace().then(() => {
13636
- import_node_server_utils69.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
13770
+ import_node_server_utils69.logger.info(
13771
+ `Cache cleared for namespace: ${vehicles_namespace_collection}`
13772
+ );
13637
13773
  }).catch((err) => {
13638
13774
  import_node_server_utils69.logger.error(
13639
- `Failed to clear cache for namespace: ${namespace_collection}`,
13775
+ `Failed to clear cache for namespace: ${vehicles_namespace_collection}`,
13640
13776
  err
13641
13777
  );
13642
13778
  });
@@ -13682,7 +13818,7 @@ function useVehicleRepo() {
13682
13818
  query.$text = { $search: search };
13683
13819
  cacheOptions.search = search;
13684
13820
  }
13685
- const cacheKey = (0, import_node_server_utils69.makeCacheKey)(namespace_collection, cacheOptions);
13821
+ const cacheKey = (0, import_node_server_utils69.makeCacheKey)(vehicles_namespace_collection, cacheOptions);
13686
13822
  const cachedData = await getCache(cacheKey);
13687
13823
  if (cachedData) {
13688
13824
  import_node_server_utils69.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -13846,7 +13982,7 @@ function useVehicleRepo() {
13846
13982
  } catch (error) {
13847
13983
  throw new import_node_server_utils69.BadRequestError("Invalid site ID format.");
13848
13984
  }
13849
- const cacheKey = (0, import_node_server_utils69.makeCacheKey)(namespace_collection, {
13985
+ const cacheKey = (0, import_node_server_utils69.makeCacheKey)(vehicles_namespace_collection, {
13850
13986
  site,
13851
13987
  type: "season-pass-type-as-options"
13852
13988
  });
@@ -13899,7 +14035,7 @@ function useVehicleRepo() {
13899
14035
  throw new import_node_server_utils69.BadRequestError("Invalid vehicle ID format.");
13900
14036
  }
13901
14037
  try {
13902
- const cacheKey = (0, import_node_server_utils69.makeCacheKey)(namespace_collection, { _id });
14038
+ const cacheKey = (0, import_node_server_utils69.makeCacheKey)(vehicles_namespace_collection, { _id });
13903
14039
  const cachedData = await getCache(cacheKey);
13904
14040
  if (cachedData) {
13905
14041
  import_node_server_utils69.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -14090,7 +14226,7 @@ function useVehicleRepo() {
14090
14226
  throw new import_node_server_utils69.BadRequestError(error.details[0].message);
14091
14227
  }
14092
14228
  try {
14093
- const cacheKey = (0, import_node_server_utils69.makeCacheKey)(namespace_collection, {
14229
+ const cacheKey = (0, import_node_server_utils69.makeCacheKey)(vehicles_namespace_collection, {
14094
14230
  plateNumber: value,
14095
14231
  status: "active"
14096
14232
  });
@@ -14136,10 +14272,12 @@ function useVehicleRepo() {
14136
14272
  throw new import_node_server_utils69.InternalServerError("Unable to update vehicle.");
14137
14273
  }
14138
14274
  delNamespace().then(() => {
14139
- import_node_server_utils69.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
14275
+ import_node_server_utils69.logger.info(
14276
+ `Cache cleared for namespace: ${vehicles_namespace_collection}`
14277
+ );
14140
14278
  }).catch((err) => {
14141
14279
  import_node_server_utils69.logger.error(
14142
- `Failed to clear cache for namespace: ${namespace_collection}`,
14280
+ `Failed to clear cache for namespace: ${vehicles_namespace_collection}`,
14143
14281
  err
14144
14282
  );
14145
14283
  });
@@ -14167,10 +14305,12 @@ function useVehicleRepo() {
14167
14305
  if (res.modifiedCount === 0)
14168
14306
  throw new import_node_server_utils69.InternalServerError("Unable to delete vehicle.");
14169
14307
  delNamespace().then(() => {
14170
- import_node_server_utils69.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
14308
+ import_node_server_utils69.logger.info(
14309
+ `Cache cleared for namespace: ${vehicles_namespace_collection}`
14310
+ );
14171
14311
  }).catch((err) => {
14172
14312
  import_node_server_utils69.logger.error(
14173
- `Failed to clear cache for namespace: ${namespace_collection}`,
14313
+ `Failed to clear cache for namespace: ${vehicles_namespace_collection}`,
14174
14314
  err
14175
14315
  );
14176
14316
  });
@@ -14184,7 +14324,7 @@ function useVehicleRepo() {
14184
14324
  if (error) {
14185
14325
  throw new import_node_server_utils69.BadRequestError(error.details[0].message);
14186
14326
  }
14187
- const cacheKey = (0, import_node_server_utils69.makeCacheKey)(namespace_collection, {
14327
+ const cacheKey = (0, import_node_server_utils69.makeCacheKey)(vehicles_namespace_collection, {
14188
14328
  plateNumber,
14189
14329
  status: "active"
14190
14330
  });
@@ -14233,7 +14373,7 @@ function useVehicleRepo() {
14233
14373
  limit: String(limit),
14234
14374
  sort: JSON.stringify(sort)
14235
14375
  };
14236
- const cacheKey = (0, import_node_server_utils69.makeCacheKey)(namespace_collection, cacheOptions);
14376
+ const cacheKey = (0, import_node_server_utils69.makeCacheKey)(vehicles_namespace_collection, cacheOptions);
14237
14377
  const cachedData = await getCache(cacheKey);
14238
14378
  if (cachedData) {
14239
14379
  import_node_server_utils69.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -14280,10 +14420,12 @@ function useVehicleRepo() {
14280
14420
  { session }
14281
14421
  );
14282
14422
  delNamespace().then(() => {
14283
- import_node_server_utils69.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
14423
+ import_node_server_utils69.logger.info(
14424
+ `Cache cleared for namespace: ${vehicles_namespace_collection}`
14425
+ );
14284
14426
  }).catch((err) => {
14285
14427
  import_node_server_utils69.logger.error(
14286
- `Failed to clear cache for namespace: ${namespace_collection}`,
14428
+ `Failed to clear cache for namespace: ${vehicles_namespace_collection}`,
14287
14429
  err
14288
14430
  );
14289
14431
  });
@@ -14311,7 +14453,10 @@ function useVehicleRepo() {
14311
14453
  limit,
14312
14454
  sort: JSON.stringify(sort)
14313
14455
  };
14314
- const cacheKey = (0, import_node_server_utils69.makeCacheKey)(namespace_collection, cacheOptions);
14456
+ const cacheKey = (0, import_node_server_utils69.makeCacheKey)(
14457
+ vehicles_namespace_collection,
14458
+ cacheOptions
14459
+ );
14315
14460
  const cachedData = await getCache(cacheKey);
14316
14461
  if (cachedData) {
14317
14462
  import_node_server_utils69.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -14360,14 +14505,16 @@ var import_node_server_utils71 = require("@7365admin1/node-server-utils");
14360
14505
  // src/repositories/person.repo.ts
14361
14506
  var import_node_server_utils70 = require("@7365admin1/node-server-utils");
14362
14507
  var import_mongodb42 = require("mongodb");
14508
+ var site_people_namespace_collection = "site.people";
14363
14509
  function usePersonRepo() {
14364
14510
  const db = import_node_server_utils70.useAtlas.getDb();
14365
14511
  if (!db) {
14366
14512
  throw new import_node_server_utils70.InternalServerError("Unable to connect to server.");
14367
14513
  }
14368
- const namespace_collection = "site.people";
14369
- const collection = db.collection(namespace_collection);
14370
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils70.useCache)(namespace_collection);
14514
+ const collection = db.collection(site_people_namespace_collection);
14515
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils70.useCache)(
14516
+ site_people_namespace_collection
14517
+ );
14371
14518
  async function createIndexes() {
14372
14519
  try {
14373
14520
  await collection.createIndexes([
@@ -14399,10 +14546,12 @@ function usePersonRepo() {
14399
14546
  value = MPerson(value);
14400
14547
  const res = await collection.insertOne(value, { session });
14401
14548
  delNamespace().then(() => {
14402
- import_node_server_utils70.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
14549
+ import_node_server_utils70.logger.info(
14550
+ `Cache cleared for namespace: ${site_people_namespace_collection}`
14551
+ );
14403
14552
  }).catch((err) => {
14404
14553
  import_node_server_utils70.logger.error(
14405
- `Failed to clear cache for namespace: ${namespace_collection}`,
14554
+ `Failed to clear cache for namespace: ${site_people_namespace_collection}`,
14406
14555
  err
14407
14556
  );
14408
14557
  });
@@ -14464,7 +14613,10 @@ function usePersonRepo() {
14464
14613
  ...query.site && { site: query.site.toString() },
14465
14614
  ...PERSON_TYPES.includes(type) && { type }
14466
14615
  };
14467
- const cacheKey = (0, import_node_server_utils70.makeCacheKey)(namespace_collection, cacheOptions);
14616
+ const cacheKey = (0, import_node_server_utils70.makeCacheKey)(
14617
+ site_people_namespace_collection,
14618
+ cacheOptions
14619
+ );
14468
14620
  const cachedData = await getCache(cacheKey);
14469
14621
  if (cachedData) {
14470
14622
  import_node_server_utils70.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -14505,10 +14657,12 @@ function usePersonRepo() {
14505
14657
  { session }
14506
14658
  );
14507
14659
  delNamespace().then(() => {
14508
- import_node_server_utils70.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
14660
+ import_node_server_utils70.logger.info(
14661
+ `Cache cleared for namespace: ${site_people_namespace_collection}`
14662
+ );
14509
14663
  }).catch((err) => {
14510
14664
  import_node_server_utils70.logger.error(
14511
- `Failed to clear cache for namespace: ${namespace_collection}`,
14665
+ `Failed to clear cache for namespace: ${site_people_namespace_collection}`,
14512
14666
  err
14513
14667
  );
14514
14668
  });
@@ -14534,10 +14688,12 @@ function usePersonRepo() {
14534
14688
  throw new import_node_server_utils70.InternalServerError("Unable to delete visitor transaction.");
14535
14689
  }
14536
14690
  delNamespace().then(() => {
14537
- import_node_server_utils70.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
14691
+ import_node_server_utils70.logger.info(
14692
+ `Cache cleared for namespace: ${site_people_namespace_collection}`
14693
+ );
14538
14694
  }).catch((err) => {
14539
14695
  import_node_server_utils70.logger.error(
14540
- `Failed to clear cache for namespace: ${namespace_collection}`,
14696
+ `Failed to clear cache for namespace: ${site_people_namespace_collection}`,
14541
14697
  err
14542
14698
  );
14543
14699
  });
@@ -14552,7 +14708,7 @@ function usePersonRepo() {
14552
14708
  } catch (error) {
14553
14709
  throw new import_node_server_utils70.BadRequestError("Invalid person ID.");
14554
14710
  }
14555
- const cacheKey = (0, import_node_server_utils70.makeCacheKey)(namespace_collection, {
14711
+ const cacheKey = (0, import_node_server_utils70.makeCacheKey)(site_people_namespace_collection, {
14556
14712
  _id: String(_id)
14557
14713
  });
14558
14714
  try {
@@ -14588,7 +14744,7 @@ function usePersonRepo() {
14588
14744
  }
14589
14745
  }
14590
14746
  async function getPersonByPlateNumber(plateNumber) {
14591
- const cacheKey = (0, import_node_server_utils70.makeCacheKey)(namespace_collection, {
14747
+ const cacheKey = (0, import_node_server_utils70.makeCacheKey)(site_people_namespace_collection, {
14592
14748
  plateNumber,
14593
14749
  key: "get-person-plate-number"
14594
14750
  });
@@ -14616,7 +14772,7 @@ function usePersonRepo() {
14616
14772
  }
14617
14773
  async function getByNRIC(value) {
14618
14774
  try {
14619
- const cacheKey = (0, import_node_server_utils70.makeCacheKey)(namespace_collection, {
14775
+ const cacheKey = (0, import_node_server_utils70.makeCacheKey)(site_people_namespace_collection, {
14620
14776
  nric: value
14621
14777
  });
14622
14778
  const cachedData = await getCache(cacheKey);
@@ -14637,7 +14793,7 @@ function usePersonRepo() {
14637
14793
  }
14638
14794
  async function getPersonByPhoneNumber(value) {
14639
14795
  try {
14640
- const cacheKey = (0, import_node_server_utils70.makeCacheKey)(namespace_collection, {
14796
+ const cacheKey = (0, import_node_server_utils70.makeCacheKey)(site_people_namespace_collection, {
14641
14797
  contact: value
14642
14798
  });
14643
14799
  const cachedData = await getCache(cacheKey);
@@ -14663,7 +14819,7 @@ function usePersonRepo() {
14663
14819
  type,
14664
14820
  unit
14665
14821
  }, session) {
14666
- const cacheKey = (0, import_node_server_utils70.makeCacheKey)(namespace_collection, {
14822
+ const cacheKey = (0, import_node_server_utils70.makeCacheKey)(site_people_namespace_collection, {
14667
14823
  unit: JSON.stringify(unit),
14668
14824
  status,
14669
14825
  type,
@@ -14690,7 +14846,7 @@ function usePersonRepo() {
14690
14846
  }
14691
14847
  async function getCompany(search) {
14692
14848
  try {
14693
- const cacheKey = (0, import_node_server_utils70.makeCacheKey)(namespace_collection, {
14849
+ const cacheKey = (0, import_node_server_utils70.makeCacheKey)(site_people_namespace_collection, {
14694
14850
  company: search
14695
14851
  });
14696
14852
  const cachedData = await getCache(cacheKey);
@@ -14749,7 +14905,7 @@ function usePersonRepo() {
14749
14905
  }
14750
14906
  }
14751
14907
  async function getPeopleByPlateNumber(plateNumber) {
14752
- const cacheKey = (0, import_node_server_utils70.makeCacheKey)(namespace_collection, {
14908
+ const cacheKey = (0, import_node_server_utils70.makeCacheKey)(site_people_namespace_collection, {
14753
14909
  plateNumber,
14754
14910
  key: "get-people-plate-number"
14755
14911
  });
@@ -14795,7 +14951,10 @@ function usePersonRepo() {
14795
14951
  sort: JSON.stringify(sort)
14796
14952
  };
14797
14953
  try {
14798
- const cacheKey = (0, import_node_server_utils70.makeCacheKey)(namespace_collection, cacheOptions);
14954
+ const cacheKey = (0, import_node_server_utils70.makeCacheKey)(
14955
+ site_people_namespace_collection,
14956
+ cacheOptions
14957
+ );
14799
14958
  const cachedData = await getCache(cacheKey);
14800
14959
  if (cachedData) {
14801
14960
  import_node_server_utils70.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -16587,14 +16746,16 @@ function MBuildingUnit(value) {
16587
16746
  // src/repositories/building.repository.ts
16588
16747
  var import_node_server_utils79 = require("@7365admin1/node-server-utils");
16589
16748
  var import_mongodb46 = require("mongodb");
16749
+ var buildings_namespace_collection = "buildings";
16590
16750
  function useBuildingRepo() {
16591
16751
  const db = import_node_server_utils79.useAtlas.getDb();
16592
16752
  if (!db) {
16593
16753
  throw new Error("Unable to connect to server.");
16594
16754
  }
16595
- const namespace_collection = "buildings";
16596
- const collection = db.collection(namespace_collection);
16597
- const { getCache, setCache, delNamespace } = (0, import_node_server_utils79.useCache)(namespace_collection);
16755
+ const collection = db.collection(buildings_namespace_collection);
16756
+ const { getCache, setCache, delNamespace } = (0, import_node_server_utils79.useCache)(
16757
+ buildings_namespace_collection
16758
+ );
16598
16759
  async function createIndexes() {
16599
16760
  try {
16600
16761
  await collection.createIndexes([
@@ -16703,7 +16864,7 @@ function useBuildingRepo() {
16703
16864
  ...site && { site },
16704
16865
  ...status && { status }
16705
16866
  };
16706
- const cacheKey = (0, import_node_server_utils79.makeCacheKey)(namespace_collection, cacheParams);
16867
+ const cacheKey = (0, import_node_server_utils79.makeCacheKey)(buildings_namespace_collection, cacheParams);
16707
16868
  import_node_server_utils79.logger.log({
16708
16869
  level: "info",
16709
16870
  message: `Cache key for getAll buildings: ${cacheKey}`
@@ -16748,7 +16909,9 @@ function useBuildingRepo() {
16748
16909
  } catch (error) {
16749
16910
  throw new import_node_server_utils79.BadRequestError("Invalid ID.");
16750
16911
  }
16751
- const cacheKey = (0, import_node_server_utils79.makeCacheKey)(namespace_collection, { _id: String(_id) });
16912
+ const cacheKey = (0, import_node_server_utils79.makeCacheKey)(buildings_namespace_collection, {
16913
+ _id: String(_id)
16914
+ });
16752
16915
  try {
16753
16916
  const cached = await getCache(cacheKey);
16754
16917
  if (cached) {
@@ -16817,7 +16980,7 @@ function useBuildingRepo() {
16817
16980
  block
16818
16981
  };
16819
16982
  const cacheOptions = { ...query };
16820
- const cacheKey = (0, import_node_server_utils79.makeCacheKey)(namespace_collection, cacheOptions);
16983
+ const cacheKey = (0, import_node_server_utils79.makeCacheKey)(buildings_namespace_collection, cacheOptions);
16821
16984
  try {
16822
16985
  const cached = await getCache(cacheKey);
16823
16986
  if (cached) {
@@ -16852,12 +17015,12 @@ function useBuildingRepo() {
16852
17015
  delNamespace().then(() => {
16853
17016
  import_node_server_utils79.logger.log({
16854
17017
  level: "info",
16855
- message: `Cache namespace cleared for ${namespace_collection}`
17018
+ message: `Cache namespace cleared for ${buildings_namespace_collection}`
16856
17019
  });
16857
17020
  }).catch((err) => {
16858
17021
  import_node_server_utils79.logger.log({
16859
17022
  level: "error",
16860
- message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
17023
+ message: `Failed to clear cache namespace for ${buildings_namespace_collection}: ${err.message}`
16861
17024
  });
16862
17025
  });
16863
17026
  }
@@ -20262,9 +20425,9 @@ function useVisitorTransactionService() {
20262
20425
  value.checkIn = startString;
20263
20426
  value.expiredAt = endString;
20264
20427
  }
20265
- await _add(value, session);
20428
+ const result = await _add(value, session);
20266
20429
  await session?.commitTransaction();
20267
- return "Successfully added visitor transaction.";
20430
+ return result;
20268
20431
  } catch (error) {
20269
20432
  await session?.abortTransaction();
20270
20433
  throw error;
@@ -20609,14 +20772,16 @@ function MGuestManagement(value) {
20609
20772
  // src/repositories/guest-management.repo.ts
20610
20773
  var import_node_server_utils101 = require("@7365admin1/node-server-utils");
20611
20774
  var import_mongodb55 = require("mongodb");
20775
+ var guests_namespace_collection = "visitor.guests";
20612
20776
  function useGuestManagementRepo() {
20613
20777
  const db = import_node_server_utils101.useAtlas.getDb();
20614
20778
  if (!db) {
20615
20779
  throw new import_node_server_utils101.InternalServerError("Unable to connect to server.");
20616
20780
  }
20617
- const namespace_collection = "visitor.guests";
20618
- const collection = db.collection(namespace_collection);
20619
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils101.useCache)(namespace_collection);
20781
+ const collection = db.collection(guests_namespace_collection);
20782
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils101.useCache)(
20783
+ guests_namespace_collection
20784
+ );
20620
20785
  async function createTextIndex() {
20621
20786
  try {
20622
20787
  await collection.createIndex({
@@ -20636,10 +20801,12 @@ function useGuestManagementRepo() {
20636
20801
  value = MGuestManagement(value);
20637
20802
  const res = await collection.insertOne(value, { session });
20638
20803
  delNamespace().then(() => {
20639
- import_node_server_utils101.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
20804
+ import_node_server_utils101.logger.info(
20805
+ `Cache cleared for namespace: ${guests_namespace_collection}`
20806
+ );
20640
20807
  }).catch((err) => {
20641
20808
  import_node_server_utils101.logger.error(
20642
- `Failed to clear cache for namespace: ${namespace_collection}`,
20809
+ `Failed to clear cache for namespace: ${guests_namespace_collection}`,
20643
20810
  err
20644
20811
  );
20645
20812
  });
@@ -20691,7 +20858,7 @@ function useGuestManagementRepo() {
20691
20858
  ...query.org && { org: query.org.toString() },
20692
20859
  ...query.site && { site: query.site.toString() }
20693
20860
  };
20694
- const cacheKey = (0, import_node_server_utils101.makeCacheKey)(namespace_collection, cacheOptions);
20861
+ const cacheKey = (0, import_node_server_utils101.makeCacheKey)(guests_namespace_collection, cacheOptions);
20695
20862
  const cachedData = await getCache(cacheKey);
20696
20863
  if (cachedData) {
20697
20864
  import_node_server_utils101.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -20732,10 +20899,12 @@ function useGuestManagementRepo() {
20732
20899
  { session }
20733
20900
  );
20734
20901
  delNamespace().then(() => {
20735
- import_node_server_utils101.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
20902
+ import_node_server_utils101.logger.info(
20903
+ `Cache cleared for namespace: ${guests_namespace_collection}`
20904
+ );
20736
20905
  }).catch((err) => {
20737
20906
  import_node_server_utils101.logger.error(
20738
- `Failed to clear cache for namespace: ${namespace_collection}`,
20907
+ `Failed to clear cache for namespace: ${guests_namespace_collection}`,
20739
20908
  err
20740
20909
  );
20741
20910
  });
@@ -20761,10 +20930,12 @@ function useGuestManagementRepo() {
20761
20930
  throw new import_node_server_utils101.InternalServerError("Unable to delete visitor transaction.");
20762
20931
  }
20763
20932
  delNamespace().then(() => {
20764
- import_node_server_utils101.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
20933
+ import_node_server_utils101.logger.info(
20934
+ `Cache cleared for namespace: ${guests_namespace_collection}`
20935
+ );
20765
20936
  }).catch((err) => {
20766
20937
  import_node_server_utils101.logger.error(
20767
- `Failed to clear cache for namespace: ${namespace_collection}`,
20938
+ `Failed to clear cache for namespace: ${guests_namespace_collection}`,
20768
20939
  err
20769
20940
  );
20770
20941
  });
@@ -24995,14 +25166,16 @@ function MSiteFacilityBooking(value) {
24995
25166
  // src/repositories/site-facility-booking.repo.ts
24996
25167
  var import_node_server_utils126 = require("@7365admin1/node-server-utils");
24997
25168
  var import_mongodb69 = require("mongodb");
25169
+ var facility_bookings_namespace_collection = "site.facilty-booking";
24998
25170
  function useSiteFacilityBookingRepo() {
24999
25171
  const db = import_node_server_utils126.useAtlas.getDb();
25000
25172
  if (!db) {
25001
25173
  throw new import_node_server_utils126.InternalServerError("Unable to connect to server.");
25002
25174
  }
25003
- const namespace_collection = "site.facilty-booking";
25004
- const collection = db.collection(namespace_collection);
25005
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils126.useCache)(namespace_collection);
25175
+ const collection = db.collection(facility_bookings_namespace_collection);
25176
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils126.useCache)(
25177
+ facility_bookings_namespace_collection
25178
+ );
25006
25179
  async function createIndexes() {
25007
25180
  try {
25008
25181
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
@@ -25015,10 +25188,12 @@ function useSiteFacilityBookingRepo() {
25015
25188
  value = MSiteFacilityBooking(value);
25016
25189
  const res = await collection.insertOne(value, { session });
25017
25190
  delNamespace().then(() => {
25018
- import_node_server_utils126.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
25191
+ import_node_server_utils126.logger.info(
25192
+ `Cache cleared for namespace: ${facility_bookings_namespace_collection}`
25193
+ );
25019
25194
  }).catch((err) => {
25020
25195
  import_node_server_utils126.logger.error(
25021
- `Failed to clear cache for namespace: ${namespace_collection}`,
25196
+ `Failed to clear cache for namespace: ${facility_bookings_namespace_collection}`,
25022
25197
  err
25023
25198
  );
25024
25199
  });
@@ -25056,7 +25231,10 @@ function useSiteFacilityBookingRepo() {
25056
25231
  limit,
25057
25232
  ...search && { search }
25058
25233
  };
25059
- const cacheKey = (0, import_node_server_utils126.makeCacheKey)(namespace_collection, cacheOptions);
25234
+ const cacheKey = (0, import_node_server_utils126.makeCacheKey)(
25235
+ facility_bookings_namespace_collection,
25236
+ cacheOptions
25237
+ );
25060
25238
  const cachedData = await getCache(cacheKey);
25061
25239
  if (cachedData) {
25062
25240
  import_node_server_utils126.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -25086,7 +25264,9 @@ function useSiteFacilityBookingRepo() {
25086
25264
  }
25087
25265
  async function getSiteFacilityBookingById(id, session) {
25088
25266
  const _id = (0, import_node_server_utils126.toObjectId)(id);
25089
- const cacheKey = (0, import_node_server_utils126.makeCacheKey)(namespace_collection, { id });
25267
+ const cacheKey = (0, import_node_server_utils126.makeCacheKey)(facility_bookings_namespace_collection, {
25268
+ id
25269
+ });
25090
25270
  const cachedData = await getCache(cacheKey);
25091
25271
  if (cachedData) {
25092
25272
  import_node_server_utils126.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -25132,10 +25312,12 @@ function useSiteFacilityBookingRepo() {
25132
25312
  );
25133
25313
  }
25134
25314
  delNamespace().then(() => {
25135
- import_node_server_utils126.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
25315
+ import_node_server_utils126.logger.info(
25316
+ `Cache cleared for namespace: ${facility_bookings_namespace_collection}`
25317
+ );
25136
25318
  }).catch((err) => {
25137
25319
  import_node_server_utils126.logger.error(
25138
- `Failed to clear cache for namespace: ${namespace_collection}`,
25320
+ `Failed to clear cache for namespace: ${facility_bookings_namespace_collection}`,
25139
25321
  err
25140
25322
  );
25141
25323
  });
@@ -25163,10 +25345,12 @@ function useSiteFacilityBookingRepo() {
25163
25345
  );
25164
25346
  }
25165
25347
  delNamespace().then(() => {
25166
- import_node_server_utils126.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
25348
+ import_node_server_utils126.logger.info(
25349
+ `Cache cleared for namespace: ${facility_bookings_namespace_collection}`
25350
+ );
25167
25351
  }).catch((err) => {
25168
25352
  import_node_server_utils126.logger.error(
25169
- `Failed to clear cache for namespace: ${namespace_collection}`,
25353
+ `Failed to clear cache for namespace: ${facility_bookings_namespace_collection}`,
25170
25354
  err
25171
25355
  );
25172
25356
  });
@@ -26084,14 +26268,16 @@ function MBulletinBoard(value) {
26084
26268
  // src/repositories/bulletin-board.repo.ts
26085
26269
  var import_node_server_utils132 = require("@7365admin1/node-server-utils");
26086
26270
  var import_mongodb73 = require("mongodb");
26271
+ var bulletin_boards_namespace_collection = "bulletin-boards";
26087
26272
  function useBulletinBoardRepo() {
26088
26273
  const db = import_node_server_utils132.useAtlas.getDb();
26089
26274
  if (!db) {
26090
26275
  throw new import_node_server_utils132.InternalServerError("Unable to connect to server.");
26091
26276
  }
26092
- const namespace_collection = "bulletin-boards";
26093
- const collection = db.collection(namespace_collection);
26094
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils132.useCache)(namespace_collection);
26277
+ const collection = db.collection(bulletin_boards_namespace_collection);
26278
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils132.useCache)(
26279
+ bulletin_boards_namespace_collection
26280
+ );
26095
26281
  async function createIndexes() {
26096
26282
  try {
26097
26283
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
@@ -26104,10 +26290,12 @@ function useBulletinBoardRepo() {
26104
26290
  value = MBulletinBoard(value);
26105
26291
  const res = await collection.insertOne(value, { session });
26106
26292
  delNamespace().then(() => {
26107
- import_node_server_utils132.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
26293
+ import_node_server_utils132.logger.info(
26294
+ `Cache cleared for namespace: ${bulletin_boards_namespace_collection}`
26295
+ );
26108
26296
  }).catch((err) => {
26109
26297
  import_node_server_utils132.logger.error(
26110
- `Failed to clear cache for namespace: ${namespace_collection}`,
26298
+ `Failed to clear cache for namespace: ${bulletin_boards_namespace_collection}`,
26111
26299
  err
26112
26300
  );
26113
26301
  });
@@ -26151,7 +26339,10 @@ function useBulletinBoardRepo() {
26151
26339
  ...search && { search },
26152
26340
  ...recipients?.length && { recipients: recipients.sort().join(",") }
26153
26341
  };
26154
- const cacheKey = (0, import_node_server_utils132.makeCacheKey)(namespace_collection, cacheOptions);
26342
+ const cacheKey = (0, import_node_server_utils132.makeCacheKey)(
26343
+ bulletin_boards_namespace_collection,
26344
+ cacheOptions
26345
+ );
26155
26346
  const cachedData = await getCache(cacheKey);
26156
26347
  if (cachedData) {
26157
26348
  import_node_server_utils132.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -26185,7 +26376,9 @@ function useBulletinBoardRepo() {
26185
26376
  } catch (error) {
26186
26377
  throw new import_node_server_utils132.BadRequestError("Invalid bulletin board ID format.");
26187
26378
  }
26188
- const cacheKey = (0, import_node_server_utils132.makeCacheKey)(namespace_collection, { _id });
26379
+ const cacheKey = (0, import_node_server_utils132.makeCacheKey)(bulletin_boards_namespace_collection, {
26380
+ _id
26381
+ });
26189
26382
  const cachedData = await getCache(cacheKey);
26190
26383
  if (cachedData) {
26191
26384
  import_node_server_utils132.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -26230,10 +26423,12 @@ function useBulletinBoardRepo() {
26230
26423
  throw new import_node_server_utils132.InternalServerError("Unable to update bulletin board.");
26231
26424
  }
26232
26425
  delNamespace().then(() => {
26233
- import_node_server_utils132.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
26426
+ import_node_server_utils132.logger.info(
26427
+ `Cache cleared for namespace: ${bulletin_boards_namespace_collection}`
26428
+ );
26234
26429
  }).catch((err) => {
26235
26430
  import_node_server_utils132.logger.error(
26236
- `Failed to clear cache for namespace: ${namespace_collection}`,
26431
+ `Failed to clear cache for namespace: ${bulletin_boards_namespace_collection}`,
26237
26432
  err
26238
26433
  );
26239
26434
  });
@@ -26263,10 +26458,12 @@ function useBulletinBoardRepo() {
26263
26458
  throw new import_node_server_utils132.InternalServerError("Unable to delete bulletin board.");
26264
26459
  }
26265
26460
  delNamespace().then(() => {
26266
- import_node_server_utils132.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
26461
+ import_node_server_utils132.logger.info(
26462
+ `Cache cleared for namespace: ${bulletin_boards_namespace_collection}`
26463
+ );
26267
26464
  }).catch((err) => {
26268
26465
  import_node_server_utils132.logger.error(
26269
- `Failed to clear cache for namespace: ${namespace_collection}`,
26466
+ `Failed to clear cache for namespace: ${bulletin_boards_namespace_collection}`,
26270
26467
  err
26271
26468
  );
26272
26469
  });
@@ -26295,10 +26492,12 @@ function useBulletinBoardRepo() {
26295
26492
  throw new import_node_server_utils132.NotFoundError("No bulletin boards found to update.");
26296
26493
  }
26297
26494
  delNamespace().then(() => {
26298
- import_node_server_utils132.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
26495
+ import_node_server_utils132.logger.info(
26496
+ `Cache cleared for namespace: ${bulletin_boards_namespace_collection}`
26497
+ );
26299
26498
  }).catch((err) => {
26300
26499
  import_node_server_utils132.logger.error(
26301
- `Failed to clear cache for namespace: ${namespace_collection}`,
26500
+ `Failed to clear cache for namespace: ${bulletin_boards_namespace_collection}`,
26302
26501
  err
26303
26502
  );
26304
26503
  });
@@ -26438,7 +26637,32 @@ function useBulletinBoardController() {
26438
26637
  order: import_joi76.default.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */),
26439
26638
  site: import_joi76.default.string().hex().length(24).required(),
26440
26639
  status: import_joi76.default.string().valid(...Object.values(BuildingStatus)).optional().default("active" /* ACTIVE */),
26441
- recipients: import_joi76.default.array().items(import_joi76.default.string().valid(...Object.values(BulletinRecipient))).optional()
26640
+ recipients: import_joi76.default.alternatives().try(
26641
+ import_joi76.default.array().items(
26642
+ import_joi76.default.string().valid(...Object.values(BulletinRecipient))
26643
+ ),
26644
+ import_joi76.default.string().allow("")
26645
+ ).optional().allow(null).custom((value2, helpers) => {
26646
+ if (!value2 || value2 === "") {
26647
+ return [];
26648
+ }
26649
+ let parsed = [];
26650
+ if (Array.isArray(value2)) {
26651
+ parsed = value2;
26652
+ } else if (typeof value2 === "string") {
26653
+ parsed = value2.split(",").map((v) => v.trim()).filter(Boolean);
26654
+ }
26655
+ for (const r of parsed) {
26656
+ if (!Object.values(BulletinRecipient).includes(r)) {
26657
+ return helpers.error("any.only");
26658
+ }
26659
+ }
26660
+ return parsed;
26661
+ }).messages({
26662
+ "any.only": `Recipients must be one of: ${Object.values(
26663
+ BulletinRecipient
26664
+ ).join(", ")}`
26665
+ })
26442
26666
  });
26443
26667
  const { error, value } = validation.validate(req.query, {
26444
26668
  abortEarly: false
@@ -27836,14 +28060,16 @@ function MEventManagement(value) {
27836
28060
  // src/repositories/event-management.repo.ts
27837
28061
  var import_node_server_utils143 = require("@7365admin1/node-server-utils");
27838
28062
  var import_mongodb79 = require("mongodb");
28063
+ var events_namespace_collection = "event-management";
27839
28064
  function useEventManagementRepo() {
27840
28065
  const db = import_node_server_utils143.useAtlas.getDb();
27841
28066
  if (!db) {
27842
28067
  throw new import_node_server_utils143.InternalServerError("Unable to connect to server.");
27843
28068
  }
27844
- const namespace_collection = "event-management";
27845
- const collection = db.collection(namespace_collection);
27846
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils143.useCache)(namespace_collection);
28069
+ const collection = db.collection(events_namespace_collection);
28070
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils143.useCache)(
28071
+ events_namespace_collection
28072
+ );
27847
28073
  async function createIndexes() {
27848
28074
  try {
27849
28075
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
@@ -27870,10 +28096,12 @@ function useEventManagementRepo() {
27870
28096
  value = MEventManagement(value);
27871
28097
  const res = await collection.insertOne(value, { session });
27872
28098
  delNamespace().then(() => {
27873
- import_node_server_utils143.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28099
+ import_node_server_utils143.logger.info(
28100
+ `Cache cleared for namespace: ${events_namespace_collection}`
28101
+ );
27874
28102
  }).catch((err) => {
27875
28103
  import_node_server_utils143.logger.error(
27876
- `Failed to clear cache for namespace: ${namespace_collection}`,
28104
+ `Failed to clear cache for namespace: ${events_namespace_collection}`,
27877
28105
  err
27878
28106
  );
27879
28107
  });
@@ -27927,7 +28155,7 @@ function useEventManagementRepo() {
27927
28155
  query.$text = { $search: search };
27928
28156
  cacheOptions.search = search;
27929
28157
  }
27930
- const cacheKey = (0, import_node_server_utils143.makeCacheKey)(namespace_collection, cacheOptions);
28158
+ const cacheKey = (0, import_node_server_utils143.makeCacheKey)(events_namespace_collection, cacheOptions);
27931
28159
  const cachedData = await getCache(cacheKey);
27932
28160
  if (cachedData) {
27933
28161
  import_node_server_utils143.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -27979,7 +28207,7 @@ function useEventManagementRepo() {
27979
28207
  } catch (error) {
27980
28208
  throw new import_node_server_utils143.BadRequestError("Invalid event ID format.");
27981
28209
  }
27982
- const cacheKey = (0, import_node_server_utils143.makeCacheKey)(namespace_collection, { _id });
28210
+ const cacheKey = (0, import_node_server_utils143.makeCacheKey)(events_namespace_collection, { _id });
27983
28211
  const cachedData = await getCache(cacheKey);
27984
28212
  if (cachedData) {
27985
28213
  import_node_server_utils143.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -28024,10 +28252,12 @@ function useEventManagementRepo() {
28024
28252
  throw new import_node_server_utils143.InternalServerError("Unable to update event.");
28025
28253
  }
28026
28254
  delNamespace().then(() => {
28027
- import_node_server_utils143.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28255
+ import_node_server_utils143.logger.info(
28256
+ `Cache cleared for namespace: ${events_namespace_collection}`
28257
+ );
28028
28258
  }).catch((err) => {
28029
28259
  import_node_server_utils143.logger.error(
28030
- `Failed to clear cache for namespace: ${namespace_collection}`,
28260
+ `Failed to clear cache for namespace: ${events_namespace_collection}`,
28031
28261
  err
28032
28262
  );
28033
28263
  });
@@ -28053,10 +28283,12 @@ function useEventManagementRepo() {
28053
28283
  throw new import_node_server_utils143.InternalServerError("Unable to delete event.");
28054
28284
  }
28055
28285
  delNamespace().then(() => {
28056
- import_node_server_utils143.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28286
+ import_node_server_utils143.logger.info(
28287
+ `Cache cleared for namespace: ${events_namespace_collection}`
28288
+ );
28057
28289
  }).catch((err) => {
28058
28290
  import_node_server_utils143.logger.error(
28059
- `Failed to clear cache for namespace: ${namespace_collection}`,
28291
+ `Failed to clear cache for namespace: ${events_namespace_collection}`,
28060
28292
  err
28061
28293
  );
28062
28294
  });
@@ -28085,10 +28317,12 @@ function useEventManagementRepo() {
28085
28317
  throw new import_node_server_utils143.NotFoundError("No bulletin boards found to update.");
28086
28318
  }
28087
28319
  delNamespace().then(() => {
28088
- import_node_server_utils143.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
28320
+ import_node_server_utils143.logger.info(
28321
+ `Cache cleared for namespace: ${events_namespace_collection}`
28322
+ );
28089
28323
  }).catch((err) => {
28090
28324
  import_node_server_utils143.logger.error(
28091
- `Failed to clear cache for namespace: ${namespace_collection}`,
28325
+ `Failed to clear cache for namespace: ${events_namespace_collection}`,
28092
28326
  err
28093
28327
  );
28094
28328
  });
@@ -31326,6 +31560,21 @@ function UseAccessManagementRepo() {
31326
31560
  throw new Error(error.message);
31327
31561
  }
31328
31562
  }
31563
+ async function checkoutVisitorRepo(params) {
31564
+ const session = import_node_server_utils150.useAtlas.getClient()?.startSession();
31565
+ try {
31566
+ await session?.startTransaction();
31567
+ const userId = new import_mongodb84.ObjectId(params.userId);
31568
+ const result = await collection().updateMany({ userId }, { $set: { userId: null, status: "Available", updatedAt: /* @__PURE__ */ new Date() } });
31569
+ await session?.commitTransaction();
31570
+ return result;
31571
+ } catch (error) {
31572
+ await session?.abortTransaction();
31573
+ throw new Error(error.message);
31574
+ } finally {
31575
+ await session?.endSession();
31576
+ }
31577
+ }
31329
31578
  return {
31330
31579
  createIndexes,
31331
31580
  createIndexForEntrypass,
@@ -31354,7 +31603,8 @@ function UseAccessManagementRepo() {
31354
31603
  availableCardContractorsRepo,
31355
31604
  vmsgenerateQrCodesRepo,
31356
31605
  addVisitorAccessCardRepo,
31357
- signQrCodeRepo
31606
+ signQrCodeRepo,
31607
+ checkoutVisitorRepo
31358
31608
  };
31359
31609
  }
31360
31610
 
@@ -31392,7 +31642,8 @@ function useAccessManagementSvc() {
31392
31642
  availableCardContractorsRepo,
31393
31643
  vmsgenerateQrCodesRepo,
31394
31644
  addVisitorAccessCardRepo,
31395
- signQrCodeRepo
31645
+ signQrCodeRepo,
31646
+ checkoutVisitorRepo
31396
31647
  } = UseAccessManagementRepo();
31397
31648
  const addPhysicalCardSvc = async (payload) => {
31398
31649
  try {
@@ -31668,6 +31919,14 @@ function useAccessManagementSvc() {
31668
31919
  throw new Error(err.message);
31669
31920
  }
31670
31921
  };
31922
+ const checkoutVisitorSvc = async (params) => {
31923
+ try {
31924
+ const response = await checkoutVisitorRepo({ ...params });
31925
+ return response;
31926
+ } catch (err) {
31927
+ throw new Error(err.message);
31928
+ }
31929
+ };
31671
31930
  return {
31672
31931
  addPhysicalCardSvc,
31673
31932
  addNonPhysicalCardSvc,
@@ -31700,7 +31959,8 @@ function useAccessManagementSvc() {
31700
31959
  availableCardContractorsSvc,
31701
31960
  vmsgenerateQrCodesSvc,
31702
31961
  addVisitorAccessCardSvc,
31703
- signQrCodeSvc
31962
+ signQrCodeSvc,
31963
+ checkoutVisitorSvc
31704
31964
  };
31705
31965
  }
31706
31966
 
@@ -31738,7 +31998,8 @@ function useAccessManagementController() {
31738
31998
  availableCardContractorsSvc,
31739
31999
  vmsgenerateQrCodesSvc,
31740
32000
  addVisitorAccessCardSvc,
31741
- signQrCodeSvc
32001
+ signQrCodeSvc,
32002
+ checkoutVisitorSvc
31742
32003
  } = useAccessManagementSvc();
31743
32004
  const addPhysicalCard = async (req, res) => {
31744
32005
  try {
@@ -32463,6 +32724,25 @@ function useAccessManagementController() {
32463
32724
  });
32464
32725
  }
32465
32726
  };
32727
+ const checkoutVisitor = async (req, res) => {
32728
+ try {
32729
+ const { userId } = req.body;
32730
+ const schema2 = import_joi85.default.object({
32731
+ userId: import_joi85.default.string().hex().length(24).required()
32732
+ });
32733
+ const { error } = schema2.validate({ userId });
32734
+ if (error) {
32735
+ return res.status(400).json({ message: error.message });
32736
+ }
32737
+ const result = await checkoutVisitorSvc({ userId });
32738
+ return res.status(200).json({ message: "Success", data: result });
32739
+ } catch (error) {
32740
+ return res.status(500).json({
32741
+ data: null,
32742
+ message: error.message
32743
+ });
32744
+ }
32745
+ };
32466
32746
  return {
32467
32747
  addPhysicalCard,
32468
32748
  addNonPhysicalCard,
@@ -32492,7 +32772,8 @@ function useAccessManagementController() {
32492
32772
  availableCardContractors,
32493
32773
  vmsgenerateQrCodes,
32494
32774
  addVisitorAccessCard,
32495
- signQrCode
32775
+ signQrCode,
32776
+ checkoutVisitor
32496
32777
  };
32497
32778
  }
32498
32779
 
@@ -36378,6 +36659,7 @@ var import_node_server_utils175 = require("@7365admin1/node-server-utils");
36378
36659
  // src/repositories/incident-report.repo.ts
36379
36660
  var import_node_server_utils174 = require("@7365admin1/node-server-utils");
36380
36661
  var import_mongodb98 = require("mongodb");
36662
+ var incidents_namespace_collection = "incident-reports";
36381
36663
  function useIncidentReportRepo() {
36382
36664
  const db = import_node_server_utils174.useAtlas.getDb();
36383
36665
  if (!db) {
@@ -36404,18 +36686,21 @@ function useIncidentReportRepo() {
36404
36686
  );
36405
36687
  }
36406
36688
  }
36407
- const namespace_collection = "incident-reports";
36408
- const collection = db.collection(namespace_collection);
36409
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils174.useCache)(namespace_collection);
36689
+ const collection = db.collection(incidents_namespace_collection);
36690
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils174.useCache)(
36691
+ incidents_namespace_collection
36692
+ );
36410
36693
  async function add(value, session) {
36411
36694
  try {
36412
36695
  value = MIncidentReport(value);
36413
36696
  const res = await collection.insertOne(value, { session });
36414
36697
  delNamespace().then(() => {
36415
- import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
36698
+ import_node_server_utils174.logger.info(
36699
+ `Cache cleared for namespace: ${incidents_namespace_collection}`
36700
+ );
36416
36701
  }).catch((err) => {
36417
36702
  import_node_server_utils174.logger.error(
36418
- `Failed to clear cache for namespace: ${namespace_collection}`,
36703
+ `Failed to clear cache for namespace: ${incidents_namespace_collection}`,
36419
36704
  err
36420
36705
  );
36421
36706
  });
@@ -36501,7 +36786,7 @@ function useIncidentReportRepo() {
36501
36786
  if (search) {
36502
36787
  cacheOptions.search = search;
36503
36788
  }
36504
- const cacheKey = (0, import_node_server_utils174.makeCacheKey)(namespace_collection, cacheOptions);
36789
+ const cacheKey = (0, import_node_server_utils174.makeCacheKey)(incidents_namespace_collection, cacheOptions);
36505
36790
  const cachedData = await getCache(cacheKey);
36506
36791
  if (cachedData) {
36507
36792
  import_node_server_utils174.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -36614,7 +36899,7 @@ function useIncidentReportRepo() {
36614
36899
  } catch (error) {
36615
36900
  throw new import_node_server_utils174.BadRequestError("Invalid incident report ID format.");
36616
36901
  }
36617
- const cacheKey = (0, import_node_server_utils174.makeCacheKey)(namespace_collection, { _id });
36902
+ const cacheKey = (0, import_node_server_utils174.makeCacheKey)(incidents_namespace_collection, { _id });
36618
36903
  const cachedData = await getCache(cacheKey);
36619
36904
  if (cachedData) {
36620
36905
  import_node_server_utils174.logger.info(`Cache hit for key: ${cacheKey}`);
@@ -36688,10 +36973,12 @@ function useIncidentReportRepo() {
36688
36973
  );
36689
36974
  }
36690
36975
  delNamespace().then(() => {
36691
- import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
36976
+ import_node_server_utils174.logger.info(
36977
+ `Cache cleared for namespace: ${incidents_namespace_collection}`
36978
+ );
36692
36979
  }).catch((err) => {
36693
36980
  import_node_server_utils174.logger.error(
36694
- `Failed to clear cache for namespace: ${namespace_collection}`,
36981
+ `Failed to clear cache for namespace: ${incidents_namespace_collection}`,
36695
36982
  err
36696
36983
  );
36697
36984
  });
@@ -36717,10 +37004,12 @@ function useIncidentReportRepo() {
36717
37004
  throw new import_node_server_utils174.InternalServerError("Unable to delete occurrence subject.");
36718
37005
  }
36719
37006
  delNamespace().then(() => {
36720
- import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
37007
+ import_node_server_utils174.logger.info(
37008
+ `Cache cleared for namespace: ${incidents_namespace_collection}`
37009
+ );
36721
37010
  }).catch((err) => {
36722
37011
  import_node_server_utils174.logger.error(
36723
- `Failed to clear cache for namespace: ${namespace_collection}`,
37012
+ `Failed to clear cache for namespace: ${incidents_namespace_collection}`,
36724
37013
  err
36725
37014
  );
36726
37015
  });
@@ -36748,10 +37037,12 @@ function useIncidentReportRepo() {
36748
37037
  );
36749
37038
  }
36750
37039
  delNamespace().then(() => {
36751
- import_node_server_utils174.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
37040
+ import_node_server_utils174.logger.info(
37041
+ `Cache cleared for namespace: ${incidents_namespace_collection}`
37042
+ );
36752
37043
  }).catch((err) => {
36753
37044
  import_node_server_utils174.logger.error(
36754
- `Failed to clear cache for namespace: ${namespace_collection}`,
37045
+ `Failed to clear cache for namespace: ${incidents_namespace_collection}`,
36755
37046
  err
36756
37047
  );
36757
37048
  });
@@ -39133,6 +39424,1634 @@ function useNfcPatrolLogController() {
39133
39424
  getAllBySite
39134
39425
  };
39135
39426
  }
39427
+
39428
+ // src/repositories/new-dashboard.repo.ts
39429
+ var import_node_server_utils192 = require("@7365admin1/node-server-utils");
39430
+ var Period = /* @__PURE__ */ ((Period2) => {
39431
+ Period2["TODAY"] = "today";
39432
+ Period2["THIS_WEEK"] = "thisWeek";
39433
+ Period2["THIS_MONTH"] = "thisMonth";
39434
+ return Period2;
39435
+ })(Period || {});
39436
+ var securityDashboardCollection = "security-dashboard";
39437
+ var PMDashboardCollection = "PM-dashboard";
39438
+ var pestDashboardCollection = "pest-dashboard";
39439
+ var poolDashboardCollection = "pool-dashboard";
39440
+ var mAndEDashboardCollection = "M&E-dashboard";
39441
+ var landscapeDashboardCollection = "landscape-dashboard";
39442
+ function getPeriodRangeWithPrevious(period) {
39443
+ const now = /* @__PURE__ */ new Date();
39444
+ let currentStart = /* @__PURE__ */ new Date();
39445
+ let currentEnd = /* @__PURE__ */ new Date();
39446
+ let previousStart = /* @__PURE__ */ new Date();
39447
+ let previousEnd = /* @__PURE__ */ new Date();
39448
+ if (period === "today" /* TODAY */) {
39449
+ currentStart.setHours(0, 0, 0, 0);
39450
+ currentEnd.setHours(23, 59, 59, 999);
39451
+ previousStart = new Date(currentStart);
39452
+ previousStart.setDate(previousStart.getDate() - 1);
39453
+ previousEnd = new Date(currentEnd);
39454
+ previousEnd.setDate(previousEnd.getDate() - 1);
39455
+ } else if (period === "thisWeek" /* THIS_WEEK */) {
39456
+ const day = now.getDay();
39457
+ const diffToMonday = day === 0 ? -6 : 1 - day;
39458
+ currentStart = new Date(now);
39459
+ currentStart.setDate(now.getDate() + diffToMonday);
39460
+ currentStart.setHours(0, 0, 0, 0);
39461
+ currentEnd = new Date(currentStart);
39462
+ currentEnd.setDate(currentStart.getDate() + 6);
39463
+ currentEnd.setHours(23, 59, 59, 999);
39464
+ previousStart = new Date(currentStart);
39465
+ previousStart.setDate(previousStart.getDate() - 7);
39466
+ previousEnd = new Date(currentEnd);
39467
+ previousEnd.setDate(previousEnd.getDate() - 7);
39468
+ } else if (period === "thisMonth" /* THIS_MONTH */) {
39469
+ currentStart = new Date(now.getFullYear(), now.getMonth(), 1);
39470
+ currentEnd = new Date(
39471
+ now.getFullYear(),
39472
+ now.getMonth() + 1,
39473
+ 0,
39474
+ 23,
39475
+ 59,
39476
+ 59,
39477
+ 999
39478
+ );
39479
+ previousStart = new Date(now.getFullYear(), now.getMonth() - 1, 1);
39480
+ previousEnd = new Date(
39481
+ now.getFullYear(),
39482
+ now.getMonth(),
39483
+ 0,
39484
+ 23,
39485
+ 59,
39486
+ 59,
39487
+ 999
39488
+ );
39489
+ } else {
39490
+ throw new import_node_server_utils192.BadRequestError("Invalid period.");
39491
+ }
39492
+ return {
39493
+ current: {
39494
+ start: currentStart.toISOString(),
39495
+ end: currentEnd.toISOString()
39496
+ },
39497
+ previous: {
39498
+ start: previousStart.toISOString(),
39499
+ end: previousEnd.toISOString()
39500
+ }
39501
+ };
39502
+ }
39503
+ function calculatePercentage(current, previous) {
39504
+ if (previous === 0) {
39505
+ return current === 0 ? 0 : 100;
39506
+ }
39507
+ return Number(((current - previous) / previous * 100).toFixed(2));
39508
+ }
39509
+ function useNewDashboardRepo() {
39510
+ const db = import_node_server_utils192.useAtlas.getDb();
39511
+ if (!db) {
39512
+ throw new import_node_server_utils192.InternalServerError("Unable to connect to server.");
39513
+ }
39514
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils192.useCache)(
39515
+ securityDashboardCollection
39516
+ );
39517
+ async function getMetric(collectionString, siteId, period) {
39518
+ const site = (0, import_node_server_utils192.toObjectId)(siteId);
39519
+ const range = getPeriodRangeWithPrevious(period);
39520
+ const collection = db.collection(collectionString);
39521
+ const current = await collection.countDocuments({
39522
+ site,
39523
+ createdAt: {
39524
+ $gte: range.current.start,
39525
+ $lte: range.current.end
39526
+ }
39527
+ });
39528
+ const previous = await collection.countDocuments({
39529
+ site,
39530
+ createdAt: {
39531
+ $gte: range.previous.start,
39532
+ $lte: range.previous.end
39533
+ }
39534
+ });
39535
+ return {
39536
+ count: current,
39537
+ percentage: calculatePercentage(current, previous)
39538
+ };
39539
+ }
39540
+ async function getSecurityDashboard({
39541
+ siteId = "",
39542
+ feedback = "today" /* TODAY */,
39543
+ workOrder = "today" /* TODAY */,
39544
+ vehicle = "today" /* TODAY */,
39545
+ building = "today" /* TODAY */,
39546
+ visitor = "today" /* TODAY */,
39547
+ incident = "today" /* TODAY */,
39548
+ guest = "today" /* TODAY */
39549
+ }) {
39550
+ const cacheOptions = {
39551
+ siteId,
39552
+ feedback,
39553
+ workOrder,
39554
+ vehicle,
39555
+ building,
39556
+ visitor,
39557
+ incident
39558
+ };
39559
+ const cacheKey = (0, import_node_server_utils192.makeCacheKey)(securityDashboardCollection, cacheOptions);
39560
+ const cachedData = await getCache(cacheKey);
39561
+ if (cachedData) {
39562
+ import_node_server_utils192.logger.info(`Cache hit for key: ${cacheKey}`);
39563
+ return cachedData;
39564
+ }
39565
+ const feedbacks = await getMetric(
39566
+ feedbacks_namespace_collection,
39567
+ siteId,
39568
+ feedback
39569
+ );
39570
+ const workOrders = await getMetric(
39571
+ work_orders_namespace_collection,
39572
+ siteId,
39573
+ workOrder
39574
+ );
39575
+ const vehicles = await getMetric(
39576
+ vehicles_namespace_collection,
39577
+ siteId,
39578
+ vehicle
39579
+ );
39580
+ const buildings = await getMetric(
39581
+ buildings_namespace_collection,
39582
+ siteId,
39583
+ building
39584
+ );
39585
+ const visitors = await getMetric(
39586
+ visitors_namespace_collection,
39587
+ siteId,
39588
+ visitor
39589
+ );
39590
+ const incidents = await getMetric(
39591
+ incidents_namespace_collection,
39592
+ siteId,
39593
+ incident
39594
+ );
39595
+ const guests = await getMetric(guests_namespace_collection, siteId, guest);
39596
+ const data = {
39597
+ feedbacks,
39598
+ workOrders,
39599
+ vehicles,
39600
+ buildings,
39601
+ visitors,
39602
+ incidents,
39603
+ guests
39604
+ };
39605
+ setCache(cacheKey, data, 15 * 60).then(() => {
39606
+ import_node_server_utils192.logger.info(`Cache set for key: ${cacheKey}`);
39607
+ }).catch((err) => {
39608
+ import_node_server_utils192.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
39609
+ });
39610
+ return data;
39611
+ }
39612
+ async function getPropertyManagementDashboard({
39613
+ siteId = "",
39614
+ feedback = "today" /* TODAY */,
39615
+ workOrder = "today" /* TODAY */,
39616
+ sitePeople = "today" /* TODAY */,
39617
+ facilityBooking = "today" /* TODAY */,
39618
+ bulletinBoard = "today" /* TODAY */,
39619
+ event = "today" /* TODAY */,
39620
+ vehicle = "today" /* TODAY */,
39621
+ building = "today" /* TODAY */,
39622
+ visitor = "today" /* TODAY */,
39623
+ incident = "today" /* TODAY */
39624
+ }) {
39625
+ const cacheOptions = {
39626
+ siteId,
39627
+ feedback,
39628
+ workOrder,
39629
+ sitePeople,
39630
+ facilityBooking,
39631
+ bulletinBoard,
39632
+ event,
39633
+ vehicle,
39634
+ building,
39635
+ visitor,
39636
+ incident
39637
+ };
39638
+ const cacheKey = (0, import_node_server_utils192.makeCacheKey)(PMDashboardCollection, cacheOptions);
39639
+ const cachedData = await getCache(cacheKey);
39640
+ if (cachedData) {
39641
+ import_node_server_utils192.logger.info(`Cache hit for key: ${cacheKey}`);
39642
+ return cachedData;
39643
+ }
39644
+ const feedbacks = await getMetric(
39645
+ feedbacks_namespace_collection,
39646
+ siteId,
39647
+ feedback
39648
+ );
39649
+ const workOrders = await getMetric(
39650
+ work_orders_namespace_collection,
39651
+ siteId,
39652
+ workOrder
39653
+ );
39654
+ const vehicles = await getMetric(
39655
+ vehicles_namespace_collection,
39656
+ siteId,
39657
+ vehicle
39658
+ );
39659
+ const buildings = await getMetric(
39660
+ buildings_namespace_collection,
39661
+ siteId,
39662
+ building
39663
+ );
39664
+ const visitors = await getMetric(
39665
+ visitors_namespace_collection,
39666
+ siteId,
39667
+ visitor
39668
+ );
39669
+ const incidents = await getMetric(
39670
+ incidents_namespace_collection,
39671
+ siteId,
39672
+ incident
39673
+ );
39674
+ const _sitePeople = await getMetric(
39675
+ site_people_namespace_collection,
39676
+ siteId,
39677
+ sitePeople
39678
+ );
39679
+ const bulletinBoards = await getMetric(
39680
+ bulletin_boards_namespace_collection,
39681
+ siteId,
39682
+ bulletinBoard
39683
+ );
39684
+ const events = await getMetric(events_namespace_collection, siteId, event);
39685
+ const facilityBookings = await getMetric(
39686
+ facility_bookings_namespace_collection,
39687
+ siteId,
39688
+ facilityBooking
39689
+ );
39690
+ const data = {
39691
+ feedbacks,
39692
+ workOrders,
39693
+ vehicles,
39694
+ buildings,
39695
+ visitors,
39696
+ incidents,
39697
+ sitePeople: _sitePeople,
39698
+ bulletinBoards,
39699
+ events,
39700
+ facilityBookings
39701
+ };
39702
+ setCache(cacheKey, data, 15 * 60).then(() => {
39703
+ import_node_server_utils192.logger.info(`Cache set for key: ${cacheKey}`);
39704
+ }).catch((err) => {
39705
+ import_node_server_utils192.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
39706
+ });
39707
+ return data;
39708
+ }
39709
+ async function getPestManagementDashboard({
39710
+ siteId = "",
39711
+ feedback = "today" /* TODAY */,
39712
+ workOrder = "today" /* TODAY */
39713
+ }) {
39714
+ const cacheOptions = {
39715
+ siteId,
39716
+ feedback,
39717
+ workOrder
39718
+ };
39719
+ const cacheKey = (0, import_node_server_utils192.makeCacheKey)(pestDashboardCollection, cacheOptions);
39720
+ const cachedData = await getCache(cacheKey);
39721
+ if (cachedData) {
39722
+ import_node_server_utils192.logger.info(`Cache hit for key: ${cacheKey}`);
39723
+ return cachedData;
39724
+ }
39725
+ const feedbacks = await getMetric(
39726
+ feedbacks_namespace_collection,
39727
+ siteId,
39728
+ feedback
39729
+ );
39730
+ const workOrders = await getMetric(
39731
+ work_orders_namespace_collection,
39732
+ siteId,
39733
+ workOrder
39734
+ );
39735
+ const data = {
39736
+ feedbacks,
39737
+ workOrders
39738
+ };
39739
+ setCache(cacheKey, data, 15 * 60).then(() => {
39740
+ import_node_server_utils192.logger.info(`Cache set for key: ${cacheKey}`);
39741
+ }).catch((err) => {
39742
+ import_node_server_utils192.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
39743
+ });
39744
+ return data;
39745
+ }
39746
+ async function getPoolManagementDashboard({
39747
+ siteId = "",
39748
+ feedback = "today" /* TODAY */,
39749
+ workOrder = "today" /* TODAY */
39750
+ }) {
39751
+ const cacheOptions = {
39752
+ siteId,
39753
+ feedback,
39754
+ workOrder
39755
+ };
39756
+ const cacheKey = (0, import_node_server_utils192.makeCacheKey)(poolDashboardCollection, cacheOptions);
39757
+ const cachedData = await getCache(cacheKey);
39758
+ if (cachedData) {
39759
+ import_node_server_utils192.logger.info(`Cache hit for key: ${cacheKey}`);
39760
+ return cachedData;
39761
+ }
39762
+ const feedbacks = await getMetric(
39763
+ feedbacks_namespace_collection,
39764
+ siteId,
39765
+ feedback
39766
+ );
39767
+ const workOrders = await getMetric(
39768
+ work_orders_namespace_collection,
39769
+ siteId,
39770
+ workOrder
39771
+ );
39772
+ const data = {
39773
+ feedbacks,
39774
+ workOrders
39775
+ };
39776
+ setCache(cacheKey, data, 15 * 60).then(() => {
39777
+ import_node_server_utils192.logger.info(`Cache set for key: ${cacheKey}`);
39778
+ }).catch((err) => {
39779
+ import_node_server_utils192.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
39780
+ });
39781
+ return data;
39782
+ }
39783
+ async function getMAndEManagementDashboard({
39784
+ siteId = "",
39785
+ feedback = "today" /* TODAY */,
39786
+ workOrder = "today" /* TODAY */
39787
+ }) {
39788
+ const cacheOptions = {
39789
+ siteId,
39790
+ feedback,
39791
+ workOrder
39792
+ };
39793
+ const cacheKey = (0, import_node_server_utils192.makeCacheKey)(mAndEDashboardCollection, cacheOptions);
39794
+ const cachedData = await getCache(cacheKey);
39795
+ if (cachedData) {
39796
+ import_node_server_utils192.logger.info(`Cache hit for key: ${cacheKey}`);
39797
+ return cachedData;
39798
+ }
39799
+ const feedbacks = await getMetric(
39800
+ feedbacks_namespace_collection,
39801
+ siteId,
39802
+ feedback
39803
+ );
39804
+ const workOrders = await getMetric(
39805
+ work_orders_namespace_collection,
39806
+ siteId,
39807
+ workOrder
39808
+ );
39809
+ const data = {
39810
+ feedbacks,
39811
+ workOrders
39812
+ };
39813
+ setCache(cacheKey, data, 15 * 60).then(() => {
39814
+ import_node_server_utils192.logger.info(`Cache set for key: ${cacheKey}`);
39815
+ }).catch((err) => {
39816
+ import_node_server_utils192.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
39817
+ });
39818
+ return data;
39819
+ }
39820
+ async function getLandscapeDashboard({
39821
+ siteId = "",
39822
+ feedback = "today" /* TODAY */,
39823
+ workOrder = "today" /* TODAY */
39824
+ }) {
39825
+ const cacheOptions = {
39826
+ siteId,
39827
+ feedback,
39828
+ workOrder
39829
+ };
39830
+ const cacheKey = (0, import_node_server_utils192.makeCacheKey)(landscapeDashboardCollection, cacheOptions);
39831
+ const cachedData = await getCache(cacheKey);
39832
+ if (cachedData) {
39833
+ import_node_server_utils192.logger.info(`Cache hit for key: ${cacheKey}`);
39834
+ return cachedData;
39835
+ }
39836
+ const feedbacks = await getMetric(
39837
+ feedbacks_namespace_collection,
39838
+ siteId,
39839
+ feedback
39840
+ );
39841
+ const workOrders = await getMetric(
39842
+ work_orders_namespace_collection,
39843
+ siteId,
39844
+ workOrder
39845
+ );
39846
+ const data = {
39847
+ feedbacks,
39848
+ workOrders
39849
+ };
39850
+ setCache(cacheKey, data, 15 * 60).then(() => {
39851
+ import_node_server_utils192.logger.info(`Cache set for key: ${cacheKey}`);
39852
+ }).catch((err) => {
39853
+ import_node_server_utils192.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
39854
+ });
39855
+ return data;
39856
+ }
39857
+ return {
39858
+ getSecurityDashboard,
39859
+ getPropertyManagementDashboard,
39860
+ getPestManagementDashboard,
39861
+ getPoolManagementDashboard,
39862
+ getMAndEManagementDashboard,
39863
+ getLandscapeDashboard
39864
+ };
39865
+ }
39866
+
39867
+ // src/controllers/new-dashboard.controller.ts
39868
+ var import_joi110 = __toESM(require("joi"));
39869
+ var import_node_server_utils193 = require("@7365admin1/node-server-utils");
39870
+ function useNewDashboardController() {
39871
+ const {
39872
+ getSecurityDashboard: _getSecurityDashboard,
39873
+ getPropertyManagementDashboard: _getPropertyManagementDashboard,
39874
+ getPestManagementDashboard: _getPestManagementDashboard,
39875
+ getPoolManagementDashboard: _getPoolManagementDashboard,
39876
+ getMAndEManagementDashboard: _getMAndEManagementDashboard,
39877
+ getLandscapeDashboard: _getLandscapeDashboard
39878
+ } = useNewDashboardRepo();
39879
+ const periodField = import_joi110.default.string().valid(...Object.values(Period)).default("today" /* TODAY */);
39880
+ async function getSecurityDashboard(req, res, next) {
39881
+ try {
39882
+ const schema2 = import_joi110.default.object({
39883
+ site: import_joi110.default.string().hex().length(24).required(),
39884
+ feedbackPeriod: periodField,
39885
+ workOrderPeriod: periodField,
39886
+ vehiclePeriod: periodField,
39887
+ buildingPeriod: periodField,
39888
+ visitorPeriod: periodField,
39889
+ incidentPeriod: periodField,
39890
+ guestPeriod: periodField
39891
+ });
39892
+ const { error, value } = schema2.validate({
39893
+ site: req.params.site,
39894
+ ...req.query
39895
+ });
39896
+ if (error) {
39897
+ const messages = error.details.map((d) => d.message).join(", ");
39898
+ import_node_server_utils193.logger.log({ level: "error", message: messages });
39899
+ next(new import_node_server_utils193.BadRequestError(messages));
39900
+ return;
39901
+ }
39902
+ const {
39903
+ site,
39904
+ feedbackPeriod,
39905
+ workOrderPeriod,
39906
+ vehiclePeriod,
39907
+ buildingPeriod,
39908
+ visitorPeriod,
39909
+ incidentPeriod,
39910
+ guestPeriod
39911
+ } = value;
39912
+ const data = await _getSecurityDashboard({
39913
+ siteId: site,
39914
+ feedback: feedbackPeriod,
39915
+ workOrder: workOrderPeriod,
39916
+ vehicle: vehiclePeriod,
39917
+ building: buildingPeriod,
39918
+ visitor: visitorPeriod,
39919
+ incident: incidentPeriod,
39920
+ guest: guestPeriod
39921
+ });
39922
+ res.status(200).json(data);
39923
+ return;
39924
+ } catch (error) {
39925
+ import_node_server_utils193.logger.log({ level: "error", message: error.message });
39926
+ next(error);
39927
+ return;
39928
+ }
39929
+ }
39930
+ async function getPropertyManagementDashboard(req, res, next) {
39931
+ try {
39932
+ const schema2 = import_joi110.default.object({
39933
+ site: import_joi110.default.string().hex().length(24).required(),
39934
+ feedbackPeriod: periodField,
39935
+ workOrderPeriod: periodField,
39936
+ vehiclePeriod: periodField,
39937
+ buildingPeriod: periodField,
39938
+ visitorPeriod: periodField,
39939
+ incidentPeriod: periodField,
39940
+ sitePeoplePeriod: periodField,
39941
+ bulletinBoardPeriod: periodField,
39942
+ eventPeriod: periodField,
39943
+ facilityBookingPeriod: periodField
39944
+ });
39945
+ const { error, value } = schema2.validate({
39946
+ site: req.params.site,
39947
+ ...req.query
39948
+ });
39949
+ if (error) {
39950
+ const messages = error.details.map((d) => d.message).join(", ");
39951
+ import_node_server_utils193.logger.log({ level: "error", message: messages });
39952
+ next(new import_node_server_utils193.BadRequestError(messages));
39953
+ return;
39954
+ }
39955
+ const {
39956
+ site,
39957
+ feedbackPeriod,
39958
+ workOrderPeriod,
39959
+ vehiclePeriod,
39960
+ buildingPeriod,
39961
+ visitorPeriod,
39962
+ incidentPeriod,
39963
+ sitePeoplePeriod,
39964
+ bulletinBoardPeriod,
39965
+ eventPeriod,
39966
+ facilityBookingPeriod
39967
+ } = value;
39968
+ const data = await _getPropertyManagementDashboard({
39969
+ siteId: site,
39970
+ feedback: feedbackPeriod,
39971
+ workOrder: workOrderPeriod,
39972
+ vehicle: vehiclePeriod,
39973
+ building: buildingPeriod,
39974
+ visitor: visitorPeriod,
39975
+ incident: incidentPeriod,
39976
+ sitePeople: sitePeoplePeriod,
39977
+ bulletinBoard: bulletinBoardPeriod,
39978
+ event: eventPeriod,
39979
+ facilityBooking: facilityBookingPeriod
39980
+ });
39981
+ res.status(200).json(data);
39982
+ return;
39983
+ } catch (error) {
39984
+ import_node_server_utils193.logger.log({ level: "error", message: error.message });
39985
+ next(error);
39986
+ return;
39987
+ }
39988
+ }
39989
+ async function getPestManagementDashboard(req, res, next) {
39990
+ try {
39991
+ const schema2 = import_joi110.default.object({
39992
+ site: import_joi110.default.string().hex().length(24).required(),
39993
+ feedbackPeriod: periodField,
39994
+ workOrderPeriod: periodField
39995
+ });
39996
+ const { error, value } = schema2.validate({
39997
+ site: req.params.site,
39998
+ ...req.query
39999
+ });
40000
+ if (error) {
40001
+ const messages = error.details.map((d) => d.message).join(", ");
40002
+ import_node_server_utils193.logger.log({ level: "error", message: messages });
40003
+ next(new import_node_server_utils193.BadRequestError(messages));
40004
+ return;
40005
+ }
40006
+ const { site, feedbackPeriod, workOrderPeriod } = value;
40007
+ const data = await _getPestManagementDashboard({
40008
+ siteId: site,
40009
+ feedback: feedbackPeriod,
40010
+ workOrder: workOrderPeriod
40011
+ });
40012
+ res.status(200).json(data);
40013
+ return;
40014
+ } catch (error) {
40015
+ import_node_server_utils193.logger.log({ level: "error", message: error.message });
40016
+ next(error);
40017
+ return;
40018
+ }
40019
+ }
40020
+ async function getPoolManagementDashboard(req, res, next) {
40021
+ try {
40022
+ const schema2 = import_joi110.default.object({
40023
+ site: import_joi110.default.string().hex().length(24).required(),
40024
+ feedbackPeriod: periodField,
40025
+ workOrderPeriod: periodField
40026
+ });
40027
+ const { error, value } = schema2.validate({
40028
+ site: req.params.site,
40029
+ ...req.query
40030
+ });
40031
+ if (error) {
40032
+ const messages = error.details.map((d) => d.message).join(", ");
40033
+ import_node_server_utils193.logger.log({ level: "error", message: messages });
40034
+ next(new import_node_server_utils193.BadRequestError(messages));
40035
+ return;
40036
+ }
40037
+ const { site, feedbackPeriod, workOrderPeriod } = value;
40038
+ const data = await _getPestManagementDashboard({
40039
+ siteId: site,
40040
+ feedback: feedbackPeriod,
40041
+ workOrder: workOrderPeriod
40042
+ });
40043
+ res.status(200).json(data);
40044
+ return;
40045
+ } catch (error) {
40046
+ import_node_server_utils193.logger.log({ level: "error", message: error.message });
40047
+ next(error);
40048
+ return;
40049
+ }
40050
+ }
40051
+ async function getMAndEManagementDashboard(req, res, next) {
40052
+ try {
40053
+ const schema2 = import_joi110.default.object({
40054
+ site: import_joi110.default.string().hex().length(24).required(),
40055
+ feedbackPeriod: periodField,
40056
+ workOrderPeriod: periodField
40057
+ });
40058
+ const { error, value } = schema2.validate({
40059
+ site: req.params.site,
40060
+ ...req.query
40061
+ });
40062
+ if (error) {
40063
+ const messages = error.details.map((d) => d.message).join(", ");
40064
+ import_node_server_utils193.logger.log({ level: "error", message: messages });
40065
+ next(new import_node_server_utils193.BadRequestError(messages));
40066
+ return;
40067
+ }
40068
+ const { site, feedbackPeriod, workOrderPeriod } = value;
40069
+ const data = await _getMAndEManagementDashboard({
40070
+ siteId: site,
40071
+ feedback: feedbackPeriod,
40072
+ workOrder: workOrderPeriod
40073
+ });
40074
+ res.status(200).json(data);
40075
+ return;
40076
+ } catch (error) {
40077
+ import_node_server_utils193.logger.log({ level: "error", message: error.message });
40078
+ next(error);
40079
+ return;
40080
+ }
40081
+ }
40082
+ async function getLandscapeDashboard(req, res, next) {
40083
+ try {
40084
+ const schema2 = import_joi110.default.object({
40085
+ site: import_joi110.default.string().hex().length(24).required(),
40086
+ feedbackPeriod: periodField,
40087
+ workOrderPeriod: periodField
40088
+ });
40089
+ const { error, value } = schema2.validate({
40090
+ site: req.params.site,
40091
+ ...req.query
40092
+ });
40093
+ if (error) {
40094
+ const messages = error.details.map((d) => d.message).join(", ");
40095
+ import_node_server_utils193.logger.log({ level: "error", message: messages });
40096
+ next(new import_node_server_utils193.BadRequestError(messages));
40097
+ return;
40098
+ }
40099
+ const { site, feedbackPeriod, workOrderPeriod } = value;
40100
+ const data = await _getLandscapeDashboard({
40101
+ siteId: site,
40102
+ feedback: feedbackPeriod,
40103
+ workOrder: workOrderPeriod
40104
+ });
40105
+ res.status(200).json(data);
40106
+ return;
40107
+ } catch (error) {
40108
+ import_node_server_utils193.logger.log({ level: "error", message: error.message });
40109
+ next(error);
40110
+ return;
40111
+ }
40112
+ }
40113
+ return {
40114
+ getSecurityDashboard,
40115
+ getPropertyManagementDashboard,
40116
+ getPestManagementDashboard,
40117
+ getPoolManagementDashboard,
40118
+ getMAndEManagementDashboard,
40119
+ getLandscapeDashboard
40120
+ };
40121
+ }
40122
+
40123
+ // src/models/manpower-monitoring.model.ts
40124
+ var import_joi111 = __toESM(require("joi"));
40125
+ var import_mongodb107 = require("mongodb");
40126
+ var shiftSchema = import_joi111.default.object({
40127
+ name: import_joi111.default.string().required(),
40128
+ checkIn: import_joi111.default.string().optional().allow("", null),
40129
+ checkOut: import_joi111.default.string().optional().allow("", null),
40130
+ lateCheckInAlert: import_joi111.default.string().optional().allow("", null),
40131
+ alertFrequencyMins: import_joi111.default.number().optional().allow("", null),
40132
+ earlyOutAlert: import_joi111.default.boolean().optional()
40133
+ });
40134
+ var manpowerMonitoringSchema = import_joi111.default.object({
40135
+ siteId: import_joi111.default.string().hex().required(),
40136
+ siteName: import_joi111.default.string().required(),
40137
+ shiftType: import_joi111.default.string().optional().allow("", null),
40138
+ enabled: import_joi111.default.boolean().required(),
40139
+ shifts: import_joi111.default.object({
40140
+ "2-shifts": import_joi111.default.array().items(shiftSchema).optional(),
40141
+ "3-shifts": import_joi111.default.array().items(shiftSchema).optional()
40142
+ }).optional(),
40143
+ createdBy: import_joi111.default.string().hex().required(),
40144
+ createdByName: import_joi111.default.string().optional().allow("", null),
40145
+ emails: import_joi111.default.array().items(import_joi111.default.string().email()).optional(),
40146
+ serviceProviderId: import_joi111.default.string().hex().optional()
40147
+ });
40148
+ var MManpowerMonitoring = class {
40149
+ constructor(data) {
40150
+ this._id = new import_mongodb107.ObjectId();
40151
+ this.serviceProviderId = data.serviceProviderId || "";
40152
+ this.siteId = data.siteId || "";
40153
+ this.siteName = data.siteName;
40154
+ this.shiftType = data.shiftType;
40155
+ this.enabled = data.enabled;
40156
+ this.shifts = data.shifts;
40157
+ this.createdBy = data.createdBy || "";
40158
+ this.createdByName = data.createdByName || "";
40159
+ this.createdAt = /* @__PURE__ */ new Date();
40160
+ this.updatedAt = data.updatedAt || "";
40161
+ this.emails = data.emails || [];
40162
+ }
40163
+ };
40164
+
40165
+ // src/repositories/manpower-monitoring.repo.ts
40166
+ var import_node_server_utils194 = require("@7365admin1/node-server-utils");
40167
+
40168
+ // src/utils/hrmlabs-attendance.util.ts
40169
+ var import_axios2 = __toESM(require("axios"));
40170
+ async function hrmLabsAuthentication({
40171
+ authUrl,
40172
+ username,
40173
+ password,
40174
+ domain
40175
+ }) {
40176
+ const res = await import_axios2.default.post(
40177
+ authUrl,
40178
+ {
40179
+ grant_type: "password",
40180
+ username,
40181
+ password,
40182
+ domain,
40183
+ showPassword: false
40184
+ },
40185
+ {
40186
+ headers: { "Content-Type": "application/json" }
40187
+ }
40188
+ );
40189
+ if (res.data?.success && res.data.data?.token) {
40190
+ return res.data.data.token;
40191
+ }
40192
+ throw new Error(
40193
+ "HRMLabs Authentication failed. Please check your credentials."
40194
+ );
40195
+ }
40196
+ function sleep(ms) {
40197
+ return new Promise((resolve) => setTimeout(resolve, ms));
40198
+ }
40199
+ async function fetchSites({ siteUrl, token }) {
40200
+ const maxRetries = 3;
40201
+ let attempt = 0;
40202
+ let lastError;
40203
+ do {
40204
+ try {
40205
+ attempt++;
40206
+ const res = await import_axios2.default.get(siteUrl, {
40207
+ headers: { Authorization: `Bearer ${token}` },
40208
+ timeout: 15e3
40209
+ });
40210
+ if (res.status !== 200) {
40211
+ throw new Error(`Unexpected status: ${res.status}`);
40212
+ }
40213
+ return res.data.data.locations[0] || [];
40214
+ } catch (err) {
40215
+ const error = err;
40216
+ lastError = error;
40217
+ const status = error.response?.status;
40218
+ if (status && status >= 400 && status < 500 && status !== 429) {
40219
+ throw error;
40220
+ }
40221
+ if (attempt < maxRetries) {
40222
+ const delay = 1e3 * attempt;
40223
+ await sleep(delay);
40224
+ }
40225
+ }
40226
+ } while (attempt < maxRetries);
40227
+ throw lastError;
40228
+ }
40229
+ var hrmlabs_attendance_util_default = {
40230
+ hrmLabsAuthentication,
40231
+ fetchSites
40232
+ };
40233
+
40234
+ // src/repositories/manpower-monitoring.repo.ts
40235
+ var import_mongodb108 = require("mongodb");
40236
+ var { hrmLabsAuthentication: hrmLabsAuthentication2, fetchSites: fetchSites2 } = hrmlabs_attendance_util_default;
40237
+ function useManpowerMonitoringRepo() {
40238
+ const db = import_node_server_utils194.useAtlas.getDb();
40239
+ if (!db) {
40240
+ throw new Error("Unable to connect to server.");
40241
+ }
40242
+ const namespace_collection = "manpower-monitoring";
40243
+ const collection = db.collection(namespace_collection);
40244
+ const serviceProviderCollection = db.collection("site.service-providers");
40245
+ async function createManpowerMonitoringSettings(value, session) {
40246
+ try {
40247
+ value = new MManpowerMonitoring(value);
40248
+ if (value.createdBy)
40249
+ value.createdBy = new import_mongodb108.ObjectId(value.createdBy);
40250
+ if (value.siteId)
40251
+ value.siteId = new import_mongodb108.ObjectId(value.siteId);
40252
+ if (value.serviceProviderId)
40253
+ value.serviceProviderId = new import_mongodb108.ObjectId(value.serviceProviderId);
40254
+ const result = await collection.insertOne(value, { session });
40255
+ return result;
40256
+ } catch (error) {
40257
+ throw new Error(error.message || error || "Server Internal Error");
40258
+ }
40259
+ }
40260
+ async function getAllManpowerSettings({
40261
+ page = 1,
40262
+ limit = 10,
40263
+ search
40264
+ }) {
40265
+ try {
40266
+ page = page ? page - 1 : 0;
40267
+ limit = limit || 10;
40268
+ const searchQuery = {};
40269
+ if (search) {
40270
+ searchQuery.siteName = { $regex: search, $options: "i" };
40271
+ }
40272
+ const result = await collection.aggregate([
40273
+ { $match: searchQuery },
40274
+ {
40275
+ $facet: {
40276
+ totalCount: [{ $count: "count" }],
40277
+ items: [
40278
+ { $sort: { _id: -1 } },
40279
+ { $skip: page * limit },
40280
+ { $limit: limit }
40281
+ ]
40282
+ }
40283
+ }
40284
+ ]).toArray();
40285
+ const total = result[0].totalCount[0]?.count || 0;
40286
+ const items = result[0].items;
40287
+ return (0, import_node_server_utils194.paginate)(items, page, limit, total);
40288
+ } catch (error) {
40289
+ throw new Error(error.message || "Server Internal Error");
40290
+ }
40291
+ }
40292
+ async function getManpowerSettingsBySiteId(_id, serviceProviderId) {
40293
+ try {
40294
+ _id = new import_mongodb108.ObjectId(_id);
40295
+ serviceProviderId = new import_mongodb108.ObjectId(serviceProviderId);
40296
+ } catch (error) {
40297
+ throw new Error("Invalid Site ID format.");
40298
+ }
40299
+ try {
40300
+ const data = await collection.findOne({
40301
+ siteId: _id,
40302
+ serviceProviderId
40303
+ });
40304
+ return data;
40305
+ } catch (error) {
40306
+ throw error;
40307
+ }
40308
+ }
40309
+ async function updateManpowerMonitoringSettings(_id, value) {
40310
+ try {
40311
+ _id = new import_mongodb108.ObjectId(_id);
40312
+ } catch (error) {
40313
+ throw new import_node_server_utils194.BadRequestError("Invalid ID format.");
40314
+ }
40315
+ try {
40316
+ const updateValue = {
40317
+ ...value,
40318
+ updatedAt: /* @__PURE__ */ new Date()
40319
+ };
40320
+ const res = await collection.updateOne({ _id }, { $set: updateValue });
40321
+ if (res.modifiedCount === 0) {
40322
+ throw new Error("Unable to update manpower monitoring settings.");
40323
+ }
40324
+ return res.modifiedCount;
40325
+ } catch (error) {
40326
+ throw error;
40327
+ }
40328
+ }
40329
+ async function multipleManpowerMonitoringSettings(value) {
40330
+ try {
40331
+ const results = {
40332
+ updated: 0,
40333
+ inserted: 0
40334
+ };
40335
+ for (let item of value) {
40336
+ item = new MManpowerMonitoring(item);
40337
+ const data = await collection.findOne({
40338
+ siteId: new import_mongodb108.ObjectId(item.siteId)
40339
+ });
40340
+ if (data) {
40341
+ let updateValue;
40342
+ if (item.shiftType == "2-shifts") {
40343
+ updateValue = {
40344
+ shiftType: item.shiftType,
40345
+ "shifts.2-shifts": item.shifts["2-shifts"]
40346
+ };
40347
+ }
40348
+ if (item.shiftType == "3-shifts") {
40349
+ updateValue = {
40350
+ shiftType: item.shiftType,
40351
+ "shifts.3-shifts": item.shifts["3-shifts"]
40352
+ };
40353
+ }
40354
+ const res = await collection.updateOne(
40355
+ { _id: data._id },
40356
+ { $set: updateValue }
40357
+ );
40358
+ if (res.modifiedCount > 0) {
40359
+ results.updated++;
40360
+ }
40361
+ } else {
40362
+ if (item.createdBy)
40363
+ item.createdBy = new import_mongodb108.ObjectId(item.createdBy);
40364
+ if (item.siteId)
40365
+ item.siteId = new import_mongodb108.ObjectId(item.siteId);
40366
+ if (item.serviceProviderId)
40367
+ item.serviceProviderId = new import_mongodb108.ObjectId(item.serviceProviderId);
40368
+ const result = await collection.insertOne(item);
40369
+ if (result.insertedId) {
40370
+ results.inserted++;
40371
+ }
40372
+ }
40373
+ }
40374
+ return {
40375
+ success: true,
40376
+ message: `Processed ${value.length} items.`,
40377
+ ...results
40378
+ };
40379
+ } catch (error) {
40380
+ throw new Error(error.message || error || "Server Internal Error");
40381
+ }
40382
+ }
40383
+ async function getAllSites(serviceProviderId) {
40384
+ const username = process.env.HRMLABS_USERNAME;
40385
+ const domain = process.env.HRMLABS_DOMAIN;
40386
+ const password = process.env.HRMLABS_PASSWORD;
40387
+ const authUrl = process.env.HRMLABS_AUTH_URL;
40388
+ const siteUrl = process.env.HRMLABS_SITE_URL;
40389
+ try {
40390
+ const serviceProvider = await serviceProviderCollection.findOne({
40391
+ _id: new import_mongodb108.ObjectId(serviceProviderId)
40392
+ });
40393
+ if (!serviceProvider) {
40394
+ throw new Error("Service Provider not found.");
40395
+ }
40396
+ const hasDomain = serviceProvider.name.toLowerCase().includes(domain?.toLowerCase());
40397
+ if (!hasDomain) {
40398
+ return [];
40399
+ }
40400
+ const token = await hrmLabsAuthentication2({
40401
+ authUrl,
40402
+ username,
40403
+ password,
40404
+ domain
40405
+ });
40406
+ const sites = await fetchSites2({ siteUrl, token });
40407
+ if (!sites) {
40408
+ throw new Error("Failed to fetch sites from HRMLabs.");
40409
+ }
40410
+ return sites.children;
40411
+ } catch (error) {
40412
+ throw new Error(error.message || "Server Internal Error");
40413
+ }
40414
+ }
40415
+ return {
40416
+ createManpowerMonitoringSettings,
40417
+ getAllManpowerSettings,
40418
+ getManpowerSettingsBySiteId,
40419
+ updateManpowerMonitoringSettings,
40420
+ multipleManpowerMonitoringSettings,
40421
+ getAllSites
40422
+ };
40423
+ }
40424
+
40425
+ // src/services/manpower-monitoring.service.ts
40426
+ var import_node_server_utils195 = require("@7365admin1/node-server-utils");
40427
+ var import_moment_timezone = __toESM(require("moment-timezone"));
40428
+ function useManpowerMonitoringSrvc() {
40429
+ const {
40430
+ createManpowerMonitoringSettings: _createManpowerMonitoringSettings
40431
+ } = useManpowerMonitoringRepo();
40432
+ async function createManpowerMonitoringSettings(payload) {
40433
+ console.log("Im here now at service");
40434
+ const session = import_node_server_utils195.useAtlas.getClient()?.startSession();
40435
+ if (!session) {
40436
+ throw new import_node_server_utils195.BadRequestError("Database session not available.");
40437
+ }
40438
+ await session.startTransaction();
40439
+ const morningCheckInTime = payload?.shifts?.[payload.shiftType][0]?.checkIn;
40440
+ const afternoonCheckInTime = payload.shiftType == "3-shifts" ? payload?.shifts?.[payload.shiftType][1]?.checkIn : null;
40441
+ const nightCheckInTime = payload.shiftType == "3-shifts" ? payload?.shifts?.[payload.shiftType][2]?.checkIn : payload?.shifts?.[payload.shiftType][1]?.checkIn;
40442
+ const morningAlertFrequencyMins = payload?.shifts?.[payload.shiftType][0]?.alertFrequencyMins;
40443
+ const afternoonAlertFrequencyMins = payload.shiftType == "3-shifts" ? payload?.shifts?.[payload.shiftType][1]?.alertFrequencyMins : null;
40444
+ const nightAlertFrequencyMins = payload.shiftType == "3-shifts" ? payload?.shifts?.[payload.shiftType][2]?.alertFrequencyMins : payload?.shifts?.[payload.shiftType][1]?.alertFrequencyMins;
40445
+ const morningAlertTime = import_moment_timezone.default.tz(morningCheckInTime, "HH:mm", "Asia/Singapore").add(morningAlertFrequencyMins, "minutes").format("HH:mm");
40446
+ const afternoonAlertTime = afternoonCheckInTime ? import_moment_timezone.default.tz(afternoonCheckInTime, "HH:mm", "Asia/Singapore").add(afternoonAlertFrequencyMins, "minutes").format("HH:mm") : "";
40447
+ const nightAlertTime = import_moment_timezone.default.tz(nightCheckInTime, "HH:mm", "Asia/Singapore").add(nightAlertFrequencyMins, "minutes").format("HH:mm");
40448
+ const nowSGT = (0, import_moment_timezone.default)().tz("Asia/Singapore");
40449
+ console.log("im done preparing the payload");
40450
+ try {
40451
+ const remarksPayload = {
40452
+ siteId: payload.siteId,
40453
+ siteName: payload.siteName,
40454
+ serviceProviderId: payload.serviceProviderId,
40455
+ remarks: [
40456
+ {
40457
+ name: "Morning Shift",
40458
+ remark: {
40459
+ isAcknowledged: false,
40460
+ status: "",
40461
+ acknowledgementRemarks: "",
40462
+ acknowledgedAt: ""
40463
+ }
40464
+ },
40465
+ {
40466
+ name: "Afternoon Shift",
40467
+ remark: {
40468
+ isAcknowledged: true,
40469
+ status: "",
40470
+ acknowledgementRemarks: "",
40471
+ acknowledgedAt: ""
40472
+ }
40473
+ },
40474
+ {
40475
+ name: "Night Shift",
40476
+ remark: {
40477
+ isAcknowledged: false,
40478
+ status: "",
40479
+ acknowledgementRemarks: "",
40480
+ acknowledgedAt: ""
40481
+ }
40482
+ }
40483
+ ],
40484
+ createdBy: "",
40485
+ createdByName: "",
40486
+ morningAlertTime,
40487
+ afternoonAlertTime,
40488
+ nightAlertTime,
40489
+ createdAt: /* @__PURE__ */ new Date(),
40490
+ createdAtSGT: nowSGT.format("DD-MM-YYYY"),
40491
+ updatedAt: "",
40492
+ status: "active"
40493
+ };
40494
+ console.log("im here at remarks payload");
40495
+ const result = await _createManpowerMonitoringSettings(payload, session);
40496
+ await session.commitTransaction();
40497
+ return result;
40498
+ } catch (error) {
40499
+ await session.abortTransaction();
40500
+ import_node_server_utils195.logger.error(error.message || error);
40501
+ console.error("Error creating monitoring settings:", error);
40502
+ throw new Error(error?.message || "Internal Server Error!");
40503
+ } finally {
40504
+ session.endSession();
40505
+ }
40506
+ }
40507
+ return {
40508
+ createManpowerMonitoringSettings
40509
+ };
40510
+ }
40511
+
40512
+ // src/controllers/manpower-monitoring.controller.ts
40513
+ var import_node_server_utils196 = require("@7365admin1/node-server-utils");
40514
+ var import_joi112 = __toESM(require("joi"));
40515
+ function useManpowerMonitoringCtrl() {
40516
+ const {
40517
+ getAllManpowerSettings: _getAllManpowerSettings,
40518
+ getManpowerSettingsBySiteId: _getManpowerSettingsBySiteId,
40519
+ updateManpowerMonitoringSettings: _updateManpowerMonitoringSettings,
40520
+ multipleManpowerMonitoringSettings: _multipleManpowerMonitoringSettings,
40521
+ getAllSites: _getAllSites
40522
+ } = useManpowerMonitoringRepo();
40523
+ const {
40524
+ createManpowerMonitoringSettings: _createManpowerMonitoringSettings
40525
+ } = useManpowerMonitoringSrvc();
40526
+ async function createManpowerMonitoringSettings(req, res, next) {
40527
+ try {
40528
+ const payload = { ...req.body };
40529
+ const { error } = manpowerMonitoringSchema.validate(payload);
40530
+ if (error) {
40531
+ next(new import_node_server_utils196.BadRequestError(error.message));
40532
+ return;
40533
+ }
40534
+ const result = await _createManpowerMonitoringSettings(payload);
40535
+ return res.json(result);
40536
+ } catch (error) {
40537
+ import_node_server_utils196.logger.log({ level: "error", message: error.message });
40538
+ next(error);
40539
+ return;
40540
+ }
40541
+ }
40542
+ async function getAllManpowerSettings(req, res, next) {
40543
+ try {
40544
+ const { page, search, limit } = req.query;
40545
+ const schema2 = import_joi112.default.object({
40546
+ page: import_joi112.default.number().optional().allow("", null),
40547
+ limit: import_joi112.default.number().optional().allow("", null),
40548
+ search: import_joi112.default.string().optional().allow("", null)
40549
+ });
40550
+ const { error } = schema2.validate({ page, search, limit });
40551
+ if (error) {
40552
+ next(new import_node_server_utils196.BadRequestError(error.message));
40553
+ return;
40554
+ }
40555
+ const result = await _getAllManpowerSettings({
40556
+ page: Number(page),
40557
+ limit: Number(limit),
40558
+ search
40559
+ });
40560
+ return res.json(result);
40561
+ } catch (error) {
40562
+ import_node_server_utils196.logger.log({ level: "error", message: error.message });
40563
+ next(error);
40564
+ return;
40565
+ }
40566
+ }
40567
+ async function getManpowerSettingsBySiteId(req, res, next) {
40568
+ try {
40569
+ const _id = req.params.id;
40570
+ const serviceProviderId = req.params.serviceProviderId;
40571
+ const schema2 = import_joi112.default.object({
40572
+ _id: import_joi112.default.string().hex().required(),
40573
+ serviceProviderId: import_joi112.default.string().hex().required()
40574
+ });
40575
+ const { error } = schema2.validate({ _id, serviceProviderId });
40576
+ if (error) {
40577
+ next(new import_node_server_utils196.BadRequestError(error.message));
40578
+ return;
40579
+ }
40580
+ const result = await _getManpowerSettingsBySiteId(_id, serviceProviderId);
40581
+ return res.json(result);
40582
+ } catch (error) {
40583
+ import_node_server_utils196.logger.log({ level: "error", message: error.message });
40584
+ next(error);
40585
+ return;
40586
+ }
40587
+ }
40588
+ async function updateManpowerMonitoringSettings(req, res, next) {
40589
+ try {
40590
+ const validation = import_joi112.default.object({
40591
+ _id: import_joi112.default.string().hex().required(),
40592
+ shiftType: import_joi112.default.string().optional().allow("", null),
40593
+ enabled: import_joi112.default.boolean().required(),
40594
+ shifts: import_joi112.default.object({
40595
+ "2-shifts": import_joi112.default.array().items(shiftSchema).optional(),
40596
+ "3-shifts": import_joi112.default.array().items(shiftSchema).optional()
40597
+ }).optional(),
40598
+ emails: import_joi112.default.array().items(import_joi112.default.string().email()).optional()
40599
+ });
40600
+ const _id = req.params.id;
40601
+ const payload = { ...req.body };
40602
+ console.log("_id", _id);
40603
+ const { error } = validation.validate({ _id, ...payload });
40604
+ if (error) {
40605
+ next(new import_node_server_utils196.BadRequestError(error.message));
40606
+ return;
40607
+ }
40608
+ const result = await _updateManpowerMonitoringSettings(_id, payload);
40609
+ return res.json(result);
40610
+ } catch (error) {
40611
+ import_node_server_utils196.logger.log({ level: "error", message: error.message });
40612
+ next(error);
40613
+ return;
40614
+ }
40615
+ }
40616
+ async function multipleManpowerMonitoringSettings(req, res, next) {
40617
+ try {
40618
+ const validation = import_joi112.default.array().items(manpowerMonitoringSchema);
40619
+ const payload = req.body;
40620
+ const { error } = validation.validate(payload);
40621
+ if (error) {
40622
+ next(new import_node_server_utils196.BadRequestError(error.message));
40623
+ return;
40624
+ }
40625
+ const result = await _multipleManpowerMonitoringSettings(payload);
40626
+ return res.json(result);
40627
+ } catch (error) {
40628
+ import_node_server_utils196.logger.log({ level: "error", message: error.message });
40629
+ next(error);
40630
+ return;
40631
+ }
40632
+ }
40633
+ async function getAllSites(req, res, next) {
40634
+ try {
40635
+ const serviceProviderId = req.query.serviceProviderId;
40636
+ const validation = import_joi112.default.object({
40637
+ serviceProviderId: import_joi112.default.string().hex().required()
40638
+ });
40639
+ const { error } = validation.validate({ serviceProviderId });
40640
+ if (error) {
40641
+ next(new import_node_server_utils196.BadRequestError(error.message));
40642
+ return;
40643
+ }
40644
+ const result = await _getAllSites(serviceProviderId);
40645
+ return res.json(result);
40646
+ } catch (error) {
40647
+ import_node_server_utils196.logger.log({ level: "error", message: error.message });
40648
+ next(error);
40649
+ return;
40650
+ }
40651
+ }
40652
+ return {
40653
+ createManpowerMonitoringSettings,
40654
+ getAllManpowerSettings,
40655
+ getManpowerSettingsBySiteId,
40656
+ updateManpowerMonitoringSettings,
40657
+ multipleManpowerMonitoringSettings,
40658
+ getAllSites
40659
+ };
40660
+ }
40661
+
40662
+ // src/models/manpower-designations.model.ts
40663
+ var import_joi113 = __toESM(require("joi"));
40664
+ var import_mongodb109 = require("mongodb");
40665
+ var designationsSchema = import_joi113.default.object({
40666
+ title: import_joi113.default.string().required(),
40667
+ shifts: import_joi113.default.object({
40668
+ morningShift: import_joi113.default.number().required(),
40669
+ afternoonShift: import_joi113.default.number().optional(),
40670
+ nightShift: import_joi113.default.number().required()
40671
+ }).required()
40672
+ });
40673
+ var manpowerDesignationsSchema = import_joi113.default.object({
40674
+ siteId: import_joi113.default.string().hex().required(),
40675
+ siteName: import_joi113.default.string().required(),
40676
+ serviceProviderId: import_joi113.default.string().hex().optional(),
40677
+ designations: import_joi113.default.array().items(designationsSchema).required(),
40678
+ createdBy: import_joi113.default.string().hex().required(),
40679
+ createdByName: import_joi113.default.string().optional().allow("", null)
40680
+ });
40681
+ var MManpowerDesignations = class {
40682
+ constructor(data) {
40683
+ this._id = new import_mongodb109.ObjectId();
40684
+ this.siteId = data.siteId || "";
40685
+ this.siteName = data.siteName || "";
40686
+ this.serviceProviderId = data.serviceProviderId || "";
40687
+ this.designations = data.designations || [];
40688
+ this.createdBy = data.createdBy || "";
40689
+ this.createdByName = data.createdByName || "";
40690
+ this.createdAt = /* @__PURE__ */ new Date();
40691
+ this.updatedAt = data.updatedAt || "";
40692
+ }
40693
+ };
40694
+
40695
+ // src/repositories/manpower-designations.repo.ts
40696
+ var import_node_server_utils197 = require("@7365admin1/node-server-utils");
40697
+ var import_mongodb110 = require("mongodb");
40698
+ function useManpowerDesignationRepo() {
40699
+ const db = import_node_server_utils197.useAtlas.getDb();
40700
+ if (!db) {
40701
+ throw new Error("Unable to connect to server.");
40702
+ }
40703
+ const namespace_collection = "manpower-designations";
40704
+ const collection = db.collection(namespace_collection);
40705
+ async function createManpowerDesignations(value) {
40706
+ try {
40707
+ value = new MManpowerDesignations(value);
40708
+ if (value.createdBy)
40709
+ value.createdBy = new import_mongodb110.ObjectId(value.createdBy);
40710
+ if (value.siteId)
40711
+ value.siteId = new import_mongodb110.ObjectId(value.siteId);
40712
+ if (value.serviceProviderId)
40713
+ value.serviceProviderId = new import_mongodb110.ObjectId(value.serviceProviderId);
40714
+ const result = await collection.insertOne(value);
40715
+ return result;
40716
+ } catch (error) {
40717
+ throw new Error(error.message || error || "Server Internal Error");
40718
+ }
40719
+ }
40720
+ async function getManpowerDesignationsBySiteId(_id, serviceProviderId) {
40721
+ try {
40722
+ _id = new import_mongodb110.ObjectId(_id);
40723
+ serviceProviderId = new import_mongodb110.ObjectId(serviceProviderId);
40724
+ } catch (error) {
40725
+ throw new Error("Invalid Site ID format.");
40726
+ }
40727
+ try {
40728
+ const data = await collection.findOne({
40729
+ siteId: _id,
40730
+ serviceProviderId
40731
+ });
40732
+ return data;
40733
+ } catch (error) {
40734
+ throw error;
40735
+ }
40736
+ }
40737
+ async function updateManpowerDesignations(_id, value) {
40738
+ try {
40739
+ _id = new import_mongodb110.ObjectId(_id);
40740
+ } catch (error) {
40741
+ throw new Error("Invalid ID format.");
40742
+ }
40743
+ try {
40744
+ const updateValue = {
40745
+ ...value,
40746
+ updatedAt: /* @__PURE__ */ new Date()
40747
+ };
40748
+ const res = await collection.updateOne({ _id }, { $set: updateValue });
40749
+ if (res.modifiedCount === 0) {
40750
+ throw new Error("Unable to update manpower designations.");
40751
+ }
40752
+ return res.modifiedCount;
40753
+ } catch (error) {
40754
+ throw error;
40755
+ }
40756
+ }
40757
+ return {
40758
+ createManpowerDesignations,
40759
+ getManpowerDesignationsBySiteId,
40760
+ updateManpowerDesignations
40761
+ };
40762
+ }
40763
+
40764
+ // src/controllers/manpower-designations.controller.ts
40765
+ var import_node_server_utils198 = require("@7365admin1/node-server-utils");
40766
+ var import_joi114 = __toESM(require("joi"));
40767
+ function useManpowerDesignationCtrl() {
40768
+ const {
40769
+ createManpowerDesignations: _createManpowerDesignations,
40770
+ getManpowerDesignationsBySiteId: _getManpowerDesignationsBySiteId,
40771
+ updateManpowerDesignations: _updateManpowerDesignations
40772
+ } = useManpowerDesignationRepo();
40773
+ async function createManpowerDesignations(req, res, next) {
40774
+ try {
40775
+ const payload = { ...req.body };
40776
+ const { error } = manpowerDesignationsSchema.validate(payload);
40777
+ if (error) {
40778
+ next(new import_node_server_utils198.BadRequestError(error.message));
40779
+ return;
40780
+ }
40781
+ const result = await _createManpowerDesignations(payload);
40782
+ return res.json(result);
40783
+ } catch (error) {
40784
+ import_node_server_utils198.logger.log({ level: "error", message: error.message });
40785
+ next(error);
40786
+ return;
40787
+ }
40788
+ }
40789
+ async function getManpowerSettingsBySiteId(req, res, next) {
40790
+ try {
40791
+ const { id, serviceProviderId } = req.params;
40792
+ const schema2 = import_joi114.default.object({
40793
+ id: import_joi114.default.string().hex().required(),
40794
+ serviceProviderId: import_joi114.default.string().hex().required()
40795
+ });
40796
+ const { error } = schema2.validate({ id, serviceProviderId });
40797
+ if (error) {
40798
+ next(new import_node_server_utils198.BadRequestError(error.message));
40799
+ return;
40800
+ }
40801
+ const result = await _getManpowerDesignationsBySiteId(
40802
+ id,
40803
+ serviceProviderId
40804
+ );
40805
+ return res.json(result);
40806
+ } catch (error) {
40807
+ import_node_server_utils198.logger.log({ level: "error", message: error.message });
40808
+ next(error);
40809
+ return;
40810
+ }
40811
+ }
40812
+ async function updateManpowerDesignations(req, res, next) {
40813
+ try {
40814
+ const validation = import_joi114.default.object({
40815
+ _id: import_joi114.default.string().hex().required(),
40816
+ designations: import_joi114.default.array().items(designationsSchema).required()
40817
+ });
40818
+ const _id = req.params.id;
40819
+ const payload = { ...req.body };
40820
+ const { error } = validation.validate({ _id, ...payload });
40821
+ if (error) {
40822
+ next(new import_node_server_utils198.BadRequestError(error.message));
40823
+ return;
40824
+ }
40825
+ const result = await _updateManpowerDesignations(_id, payload);
40826
+ return res.json(result);
40827
+ } catch (error) {
40828
+ import_node_server_utils198.logger.log({ level: "error", message: error.message });
40829
+ next(error);
40830
+ return;
40831
+ }
40832
+ }
40833
+ return {
40834
+ createManpowerDesignations,
40835
+ getManpowerSettingsBySiteId,
40836
+ updateManpowerDesignations
40837
+ };
40838
+ }
40839
+
40840
+ // src/models/overnight-parking.model.ts
40841
+ var import_joi115 = __toESM(require("joi"));
40842
+ var import_mongodb111 = require("mongodb");
40843
+ var dayScheduleSchema = import_joi115.default.object({
40844
+ isEnabled: import_joi115.default.boolean().required(),
40845
+ startTime: import_joi115.default.string().pattern(/^([01]\d|2[0-3]):([0-5]\d)$/).required().messages({
40846
+ "string.pattern.base": "startTime must be in HH:mm format"
40847
+ }),
40848
+ endTime: import_joi115.default.string().pattern(/^([01]\d|2[0-3]):([0-5]\d)$/).required().messages({
40849
+ "string.pattern.base": "endTime must be in HH:mm format"
40850
+ })
40851
+ }).required();
40852
+ var schemaOvernightParkingApprovalHours = import_joi115.default.object({
40853
+ _id: import_joi115.default.string().hex().length(24).optional(),
40854
+ site: import_joi115.default.string().hex().length(24).required(),
40855
+ monday: dayScheduleSchema,
40856
+ tuesday: dayScheduleSchema,
40857
+ wednesday: dayScheduleSchema,
40858
+ thursday: dayScheduleSchema,
40859
+ friday: dayScheduleSchema,
40860
+ saturday: dayScheduleSchema,
40861
+ sunday: dayScheduleSchema,
40862
+ createdAt: import_joi115.default.date().optional(),
40863
+ updatedAt: import_joi115.default.date().optional(),
40864
+ deletedAt: import_joi115.default.date().optional().allow(null)
40865
+ });
40866
+ function MOvernightParkingApprovalHours(value) {
40867
+ const { error } = schemaOvernightParkingApprovalHours.validate(value);
40868
+ if (error) {
40869
+ throw new Error(error.details[0].message);
40870
+ }
40871
+ if (value.site && typeof value.site === "string") {
40872
+ try {
40873
+ value.site = new import_mongodb111.ObjectId(value.site);
40874
+ } catch {
40875
+ throw new Error("Invalid site ID.");
40876
+ }
40877
+ }
40878
+ const now = (/* @__PURE__ */ new Date()).toISOString();
40879
+ return {
40880
+ ...value,
40881
+ createdAt: value.createdAt ?? now,
40882
+ updatedAt: value.updatedAt ?? now
40883
+ };
40884
+ }
40885
+
40886
+ // src/repositories/overnight-parking.repo.ts
40887
+ var import_node_server_utils199 = require("@7365admin1/node-server-utils");
40888
+ var overnight_parking_namespace_collection = "site.overnight-parking";
40889
+ function useOvernightParkingRepo() {
40890
+ const db = import_node_server_utils199.useAtlas.getDb();
40891
+ if (!db) {
40892
+ throw new import_node_server_utils199.InternalServerError("Unable to connect to server.");
40893
+ }
40894
+ const collection = db.collection(overnight_parking_namespace_collection);
40895
+ const { delNamespace, setCache, getCache } = (0, import_node_server_utils199.useCache)(
40896
+ overnight_parking_namespace_collection
40897
+ );
40898
+ async function createIndexes() {
40899
+ try {
40900
+ const existingIndexes = await collection.indexes();
40901
+ const existingNames = new Set(existingIndexes.map((i) => i.name));
40902
+ const indexesToEnsure = [
40903
+ {
40904
+ key: { site: 1 },
40905
+ name: "site-index"
40906
+ },
40907
+ {
40908
+ key: { status: 1 },
40909
+ name: "status-index"
40910
+ }
40911
+ ];
40912
+ const indexesToCreate = indexesToEnsure.filter(
40913
+ (index) => index.name && !existingNames.has(index.name)
40914
+ );
40915
+ if (indexesToCreate.length > 0) {
40916
+ await collection.createIndexes(indexesToCreate);
40917
+ }
40918
+ } catch (error) {
40919
+ throw new import_node_server_utils199.InternalServerError("Failed to create collection indexes.");
40920
+ }
40921
+ }
40922
+ async function upsert(value, session) {
40923
+ try {
40924
+ value = MOvernightParkingApprovalHours(value);
40925
+ const now = (/* @__PURE__ */ new Date()).toISOString();
40926
+ const res = await collection.updateOne(
40927
+ { site: value.site },
40928
+ {
40929
+ $set: {
40930
+ monday: value.monday,
40931
+ tuesday: value.tuesday,
40932
+ wednesday: value.wednesday,
40933
+ thursday: value.thursday,
40934
+ friday: value.friday,
40935
+ saturday: value.saturday,
40936
+ sunday: value.sunday,
40937
+ updatedAt: now
40938
+ },
40939
+ $setOnInsert: {
40940
+ site: value.site,
40941
+ createdAt: value.createdAt ?? now
40942
+ }
40943
+ },
40944
+ { upsert: true, session }
40945
+ );
40946
+ delNamespace().then(() => {
40947
+ import_node_server_utils199.logger.info(
40948
+ `Cache cleared for namespace: ${overnight_parking_namespace_collection}`
40949
+ );
40950
+ }).catch((err) => {
40951
+ import_node_server_utils199.logger.error(
40952
+ `Failed to clear cache for namespace: ${overnight_parking_namespace_collection}`,
40953
+ err
40954
+ );
40955
+ });
40956
+ return res;
40957
+ } catch (error) {
40958
+ throw error;
40959
+ }
40960
+ }
40961
+ async function getSiteOvernightParking(site) {
40962
+ const siteId = (0, import_node_server_utils199.toObjectId)(site);
40963
+ const cacheKey = (0, import_node_server_utils199.makeCacheKey)(overnight_parking_namespace_collection, {
40964
+ site
40965
+ });
40966
+ const cachedData = await getCache(cacheKey);
40967
+ if (cachedData) {
40968
+ import_node_server_utils199.logger.info(`Cache hit for key: ${cacheKey}`);
40969
+ return cachedData;
40970
+ }
40971
+ try {
40972
+ const data = await collection.findOne({
40973
+ site: siteId,
40974
+ deletedAt: null
40975
+ });
40976
+ setCache(cacheKey, data, 15 * 60).then(() => {
40977
+ import_node_server_utils199.logger.info(`Cache set for key: ${cacheKey}`);
40978
+ }).catch((err) => {
40979
+ import_node_server_utils199.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
40980
+ });
40981
+ return data;
40982
+ } catch (error) {
40983
+ throw error;
40984
+ }
40985
+ }
40986
+ return {
40987
+ upsert,
40988
+ getSiteOvernightParking,
40989
+ createIndexes
40990
+ };
40991
+ }
40992
+
40993
+ // src/controllers/overnight-parking.controller.ts
40994
+ var import_joi116 = __toESM(require("joi"));
40995
+ var import_node_server_utils200 = require("@7365admin1/node-server-utils");
40996
+ function useOvernightParkingController() {
40997
+ const { upsert: _upsert, getSiteOvernightParking: _getSiteOvernightParking } = useOvernightParkingRepo();
40998
+ async function upsert(req, res, next) {
40999
+ const site = req.params.site;
41000
+ req.body.site = site;
41001
+ try {
41002
+ const { error, value } = schemaOvernightParkingApprovalHours.validate(
41003
+ req.body,
41004
+ {
41005
+ abortEarly: false
41006
+ }
41007
+ );
41008
+ if (error) {
41009
+ const messages = error.details.map((d) => d.message).join(", ");
41010
+ import_node_server_utils200.logger.log({ level: "error", message: messages });
41011
+ next(new import_node_server_utils200.BadRequestError(messages));
41012
+ return;
41013
+ }
41014
+ const data = await _upsert(value);
41015
+ res.status(201).json(data);
41016
+ return;
41017
+ } catch (error) {
41018
+ import_node_server_utils200.logger.log({ level: "error", message: error.message });
41019
+ next(error);
41020
+ return;
41021
+ }
41022
+ }
41023
+ async function getSiteOvernightParking(req, res, next) {
41024
+ const schema2 = import_joi116.default.object({
41025
+ site: import_joi116.default.string().hex().length(24).required()
41026
+ });
41027
+ try {
41028
+ const { error, value } = schema2.validate(
41029
+ { site: req.params.site },
41030
+ {
41031
+ abortEarly: false
41032
+ }
41033
+ );
41034
+ if (error) {
41035
+ const messages = error.details.map((d) => d.message).join(", ");
41036
+ import_node_server_utils200.logger.log({ level: "error", message: messages });
41037
+ next(new import_node_server_utils200.BadRequestError(messages));
41038
+ return;
41039
+ }
41040
+ const { site } = value;
41041
+ const data = await _getSiteOvernightParking(site);
41042
+ res.status(201).json(data);
41043
+ return;
41044
+ } catch (error) {
41045
+ import_node_server_utils200.logger.log({ level: "error", message: error.message });
41046
+ next(error);
41047
+ return;
41048
+ }
41049
+ }
41050
+ return {
41051
+ upsert,
41052
+ getSiteOvernightParking
41053
+ };
41054
+ }
39136
41055
  // Annotate the CommonJS export names for ESM import in node:
39137
41056
  0 && (module.exports = {
39138
41057
  ANPRMode,
@@ -39170,6 +41089,8 @@ function useNfcPatrolLogController() {
39170
41089
  MFile,
39171
41090
  MGuestManagement,
39172
41091
  MIncidentReport,
41092
+ MManpowerDesignations,
41093
+ MManpowerMonitoring,
39173
41094
  MMember,
39174
41095
  MNfcPatrolLog,
39175
41096
  MNfcPatrolRoute,
@@ -39181,6 +41102,7 @@ function useNfcPatrolLogController() {
39181
41102
  MOccurrenceSubject,
39182
41103
  MOnlineForm,
39183
41104
  MOrg,
41105
+ MOvernightParkingApprovalHours,
39184
41106
  MPatrolLog,
39185
41107
  MPatrolQuestion,
39186
41108
  MPatrolRoute,
@@ -39206,6 +41128,8 @@ function useNfcPatrolLogController() {
39206
41128
  MWorkOrder,
39207
41129
  OrgNature,
39208
41130
  PERSON_TYPES,
41131
+ PMDashboardCollection,
41132
+ Period,
39209
41133
  PersonTypes,
39210
41134
  SiteCategories,
39211
41135
  SiteStatus,
@@ -39223,14 +41147,30 @@ function useNfcPatrolLogController() {
39223
41147
  allowedNatures,
39224
41148
  attendanceSchema,
39225
41149
  attendanceSettingsSchema,
41150
+ buildings_namespace_collection,
41151
+ bulletin_boards_namespace_collection,
41152
+ calculatePercentage,
39226
41153
  chatSchema,
39227
41154
  customerSchema,
41155
+ designationsSchema,
41156
+ events_namespace_collection,
41157
+ facility_bookings_namespace_collection,
39228
41158
  feedbackSchema,
41159
+ feedbacks_namespace_collection,
39229
41160
  formatDahuaDate,
41161
+ getPeriodRangeWithPrevious,
41162
+ guests_namespace_collection,
39230
41163
  incidentReportLog,
41164
+ incidents_namespace_collection,
41165
+ landscapeDashboardCollection,
41166
+ mAndEDashboardCollection,
41167
+ manpowerDesignationsSchema,
41168
+ manpowerMonitoringSchema,
39231
41169
  nfcPatrolSettingsSchema,
39232
41170
  nfcPatrolSettingsSchemaUpdate,
39233
41171
  orgSchema,
41172
+ pestDashboardCollection,
41173
+ poolDashboardCollection,
39234
41174
  promoCodeSchema,
39235
41175
  robotSchema,
39236
41176
  schema,
@@ -39257,6 +41197,7 @@ function useNfcPatrolLogController() {
39257
41197
  schemaOccurrenceEntry,
39258
41198
  schemaOccurrenceSubject,
39259
41199
  schemaOnlineForm,
41200
+ schemaOvernightParkingApprovalHours,
39260
41201
  schemaPatrolLog,
39261
41202
  schemaPatrolQuestion,
39262
41203
  schemaPatrolRoute,
@@ -39298,7 +41239,10 @@ function useNfcPatrolLogController() {
39298
41239
  schemaVisitorTransaction,
39299
41240
  schemeCamera,
39300
41241
  schemeLogCamera,
41242
+ securityDashboardCollection,
41243
+ shiftSchema,
39301
41244
  siteSchema,
41245
+ site_people_namespace_collection,
39302
41246
  tokenSchema,
39303
41247
  updateSiteSchema,
39304
41248
  useAccessManagementController,
@@ -39357,8 +41301,15 @@ function useNfcPatrolLogController() {
39357
41301
  useInvoiceController,
39358
41302
  useInvoiceModel,
39359
41303
  useInvoiceRepo,
41304
+ useManpowerDesignationCtrl,
41305
+ useManpowerDesignationRepo,
41306
+ useManpowerMonitoringCtrl,
41307
+ useManpowerMonitoringRepo,
41308
+ useManpowerMonitoringSrvc,
39360
41309
  useMemberController,
39361
41310
  useMemberRepo,
41311
+ useNewDashboardController,
41312
+ useNewDashboardRepo,
39362
41313
  useNfcPatrolLogController,
39363
41314
  useNfcPatrolLogRepo,
39364
41315
  useNfcPatrolLogService,
@@ -39384,6 +41335,8 @@ function useNfcPatrolLogController() {
39384
41335
  useOnlineFormRepo,
39385
41336
  useOrgController,
39386
41337
  useOrgRepo,
41338
+ useOvernightParkingController,
41339
+ useOvernightParkingRepo,
39387
41340
  usePatrolLogController,
39388
41341
  usePatrolLogRepo,
39389
41342
  usePatrolQuestionController,
@@ -39449,6 +41402,9 @@ function useNfcPatrolLogController() {
39449
41402
  useWorkOrderService,
39450
41403
  userSchema,
39451
41404
  vehicleSchema,
39452
- workOrderSchema
41405
+ vehicles_namespace_collection,
41406
+ visitors_namespace_collection,
41407
+ workOrderSchema,
41408
+ work_orders_namespace_collection
39453
41409
  });
39454
41410
  //# sourceMappingURL=index.js.map