@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.mjs CHANGED
@@ -269,14 +269,16 @@ import {
269
269
  makeCacheKey as makeCacheKey2,
270
270
  logger as logger3
271
271
  } from "@7365admin1/node-server-utils";
272
+ var feedbacks_namespace_collection = "feedbacks";
272
273
  function useFeedbackRepo() {
273
274
  const db = useAtlas2.getDb();
274
275
  if (!db) {
275
276
  throw new InternalServerError2("Unable to connect to server.");
276
277
  }
277
- const namespace_collection = "feedbacks";
278
- const collection = db.collection(namespace_collection);
279
- const { delNamespace, getCache, setCache } = useCache2(namespace_collection);
278
+ const collection = db.collection(feedbacks_namespace_collection);
279
+ const { delNamespace, getCache, setCache } = useCache2(
280
+ feedbacks_namespace_collection
281
+ );
280
282
  const { delNamespace: _delDashboardNameSpace } = useCache2("dashboard");
281
283
  async function createIndex() {
282
284
  try {
@@ -310,10 +312,12 @@ function useFeedbackRepo() {
310
312
  value = MFeedback(value);
311
313
  const res = await collection.insertOne(value, { session });
312
314
  delNamespace().then(() => {
313
- logger3.info(`Cache cleared for namespace: ${namespace_collection}`);
315
+ logger3.info(
316
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
317
+ );
314
318
  }).catch((err) => {
315
319
  logger3.error(
316
- `Failed to clear cache for namespace: ${namespace_collection}`,
320
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
317
321
  err
318
322
  );
319
323
  });
@@ -401,7 +405,7 @@ function useFeedbackRepo() {
401
405
  cacheOptions.to = to;
402
406
  }
403
407
  console.log("query", JSON.stringify(query));
404
- const cacheKey = makeCacheKey2(namespace_collection, cacheOptions);
408
+ const cacheKey = makeCacheKey2(feedbacks_namespace_collection, cacheOptions);
405
409
  const cachedData = await getCache(cacheKey);
406
410
  if (cachedData) {
407
411
  logger3.info(`Cache hit for key: ${cacheKey}`);
@@ -457,7 +461,7 @@ function useFeedbackRepo() {
457
461
  } catch (error) {
458
462
  throw new BadRequestError4("Invalid feedback ID format.");
459
463
  }
460
- const cacheKey = makeCacheKey2(namespace_collection, { _id });
464
+ const cacheKey = makeCacheKey2(feedbacks_namespace_collection, { _id });
461
465
  const cachedData = await getCache(cacheKey);
462
466
  if (cachedData) {
463
467
  logger3.info(`Cache hit for key: ${cacheKey}`);
@@ -567,10 +571,12 @@ function useFeedbackRepo() {
567
571
  throw new InternalServerError2("Unable to update feedback.");
568
572
  }
569
573
  delNamespace().then(() => {
570
- logger3.info(`Cache cleared for namespace: ${namespace_collection}`);
574
+ logger3.info(
575
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
576
+ );
571
577
  }).catch((err) => {
572
578
  logger3.error(
573
- `Failed to clear cache for namespace: ${namespace_collection}`,
579
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
574
580
  err
575
581
  );
576
582
  });
@@ -601,10 +607,12 @@ function useFeedbackRepo() {
601
607
  throw new InternalServerError2("Unable to update feedback status.");
602
608
  }
603
609
  delNamespace().then(() => {
604
- logger3.info(`Cache cleared for namespace: ${namespace_collection}`);
610
+ logger3.info(
611
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
612
+ );
605
613
  }).catch((err) => {
606
614
  logger3.error(
607
- `Failed to clear cache for namespace: ${namespace_collection}`,
615
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
608
616
  err
609
617
  );
610
618
  });
@@ -625,10 +633,12 @@ function useFeedbackRepo() {
625
633
  session
626
634
  );
627
635
  delNamespace().then(() => {
628
- logger3.info(`Cache cleared for namespace: ${namespace_collection}`);
636
+ logger3.info(
637
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
638
+ );
629
639
  }).catch((err) => {
630
640
  logger3.error(
631
- `Failed to clear cache for namespace: ${namespace_collection}`,
641
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
632
642
  err
633
643
  );
634
644
  });
@@ -660,10 +670,12 @@ function useFeedbackRepo() {
660
670
  throw new InternalServerError2("Unable to update feedback category.");
661
671
  }
662
672
  delNamespace().then(() => {
663
- logger3.info(`Cache cleared for namespace: ${namespace_collection}`);
673
+ logger3.info(
674
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
675
+ );
664
676
  }).catch((err) => {
665
677
  logger3.error(
666
- `Failed to clear cache for namespace: ${namespace_collection}`,
678
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
667
679
  err
668
680
  );
669
681
  });
@@ -697,10 +709,12 @@ function useFeedbackRepo() {
697
709
  throw new InternalServerError2("Unable to mark feedback as completed.");
698
710
  }
699
711
  delNamespace().then(() => {
700
- logger3.info(`Cache cleared for namespace: ${namespace_collection}`);
712
+ logger3.info(
713
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
714
+ );
701
715
  }).catch((err) => {
702
716
  logger3.error(
703
- `Failed to clear cache for namespace: ${namespace_collection}`,
717
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
704
718
  err
705
719
  );
706
720
  });
@@ -735,10 +749,12 @@ function useFeedbackRepo() {
735
749
  throw new InternalServerError2("Unable to delete feedback.");
736
750
  }
737
751
  delNamespace().then(() => {
738
- logger3.info(`Cache cleared for namespace: ${namespace_collection}`);
752
+ logger3.info(
753
+ `Cache cleared for namespace: ${feedbacks_namespace_collection}`
754
+ );
739
755
  }).catch((err) => {
740
756
  logger3.error(
741
- `Failed to clear cache for namespace: ${namespace_collection}`,
757
+ `Failed to clear cache for namespace: ${feedbacks_namespace_collection}`,
742
758
  err
743
759
  );
744
760
  });
@@ -898,13 +914,13 @@ import {
898
914
  logger as logger5,
899
915
  makeCacheKey as makeCacheKey3
900
916
  } from "@7365admin1/node-server-utils";
917
+ var work_orders_namespace_collection = "work-orders";
901
918
  function useWorkOrderRepo() {
902
919
  const db = useAtlas3.getDb();
903
920
  if (!db) {
904
921
  throw new InternalServerError3("Unable to connect to server.");
905
922
  }
906
- const namespace_collection = "work-orders";
907
- const collection = db.collection(namespace_collection);
923
+ const collection = db.collection(work_orders_namespace_collection);
908
924
  async function createIndex() {
909
925
  try {
910
926
  await collection.createIndexes([
@@ -933,17 +949,21 @@ function useWorkOrderRepo() {
933
949
  );
934
950
  }
935
951
  }
936
- const { delNamespace, setCache, getCache, delCache } = useCache3(namespace_collection);
952
+ const { delNamespace, setCache, getCache, delCache } = useCache3(
953
+ work_orders_namespace_collection
954
+ );
937
955
  const { delNamespace: _delDashboardNameSpace } = useCache3("dashboard");
938
956
  async function createWorkOrder(value, session) {
939
957
  try {
940
958
  value = MWorkOrder(value);
941
959
  const res = await collection.insertOne(value, { session });
942
960
  delNamespace().then(() => {
943
- logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
961
+ logger5.info(
962
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
963
+ );
944
964
  }).catch((err) => {
945
965
  logger5.error(
946
- `Failed to clear cache for namespace: ${namespace_collection}`,
966
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
947
967
  err
948
968
  );
949
969
  });
@@ -1010,7 +1030,10 @@ function useWorkOrderRepo() {
1010
1030
  query["metadata.serviceProvider"] = serviceProvider;
1011
1031
  cacheOptions["metadata.serviceProvider"] = serviceProvider;
1012
1032
  }
1013
- const cacheKey = makeCacheKey3(namespace_collection, cacheOptions);
1033
+ const cacheKey = makeCacheKey3(
1034
+ work_orders_namespace_collection,
1035
+ cacheOptions
1036
+ );
1014
1037
  const cachedData = await getCache(cacheKey);
1015
1038
  if (cachedData) {
1016
1039
  logger5.info(`Cache hit for key: ${cacheKey}`);
@@ -1067,7 +1090,7 @@ function useWorkOrderRepo() {
1067
1090
  throw new BadRequestError6("Invalid work order ID format.");
1068
1091
  }
1069
1092
  try {
1070
- const cacheKey = makeCacheKey3(namespace_collection, {
1093
+ const cacheKey = makeCacheKey3(work_orders_namespace_collection, {
1071
1094
  _id,
1072
1095
  status: { $ne: "deleted" }
1073
1096
  });
@@ -1189,10 +1212,12 @@ function useWorkOrderRepo() {
1189
1212
  throw new InternalServerError3("Unable to update work order.");
1190
1213
  }
1191
1214
  delNamespace().then(() => {
1192
- logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
1215
+ logger5.info(
1216
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1217
+ );
1193
1218
  }).catch((err) => {
1194
1219
  logger5.error(
1195
- `Failed to clear cache for namespace: ${namespace_collection}`,
1220
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1196
1221
  err
1197
1222
  );
1198
1223
  });
@@ -1223,10 +1248,12 @@ function useWorkOrderRepo() {
1223
1248
  throw new InternalServerError3("Unable to update work order status.");
1224
1249
  }
1225
1250
  delNamespace().then(() => {
1226
- logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
1251
+ logger5.info(
1252
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1253
+ );
1227
1254
  }).catch((err) => {
1228
1255
  logger5.error(
1229
- `Failed to clear cache for namespace: ${namespace_collection}`,
1256
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1230
1257
  err
1231
1258
  );
1232
1259
  });
@@ -1252,10 +1279,12 @@ function useWorkOrderRepo() {
1252
1279
  session
1253
1280
  );
1254
1281
  delNamespace().then(() => {
1255
- logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
1282
+ logger5.info(
1283
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1284
+ );
1256
1285
  }).catch((err) => {
1257
1286
  logger5.error(
1258
- `Failed to clear cache for namespace: ${namespace_collection}`,
1287
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1259
1288
  err
1260
1289
  );
1261
1290
  });
@@ -1293,10 +1322,12 @@ function useWorkOrderRepo() {
1293
1322
  );
1294
1323
  }
1295
1324
  delNamespace().then(() => {
1296
- logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
1325
+ logger5.info(
1326
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1327
+ );
1297
1328
  }).catch((err) => {
1298
1329
  logger5.error(
1299
- `Failed to clear cache for namespace: ${namespace_collection}`,
1330
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1300
1331
  err
1301
1332
  );
1302
1333
  });
@@ -1331,10 +1362,12 @@ function useWorkOrderRepo() {
1331
1362
  throw new InternalServerError3("Unable to delete work order.");
1332
1363
  }
1333
1364
  delNamespace().then(() => {
1334
- logger5.info(`Cache cleared for namespace: ${namespace_collection}`);
1365
+ logger5.info(
1366
+ `Cache cleared for namespace: ${work_orders_namespace_collection}`
1367
+ );
1335
1368
  }).catch((err) => {
1336
1369
  logger5.error(
1337
- `Failed to clear cache for namespace: ${namespace_collection}`,
1370
+ `Failed to clear cache for namespace: ${work_orders_namespace_collection}`,
1338
1371
  err
1339
1372
  );
1340
1373
  });
@@ -2192,7 +2225,32 @@ function useUserRepo() {
2192
2225
  logger7.info(`Cache hit for key: ${cacheKey}`);
2193
2226
  return cachedData;
2194
2227
  }
2195
- const data = await collection.findOne({ _id });
2228
+ const results = await collection.aggregate([
2229
+ { $match: { _id } },
2230
+ {
2231
+ $lookup: {
2232
+ from: "site.service-providers",
2233
+ let: { userOrgId: "$defaultOrg" },
2234
+ pipeline: [
2235
+ {
2236
+ $match: {
2237
+ $expr: { $eq: ["$orgId", "$$userOrgId"] }
2238
+ }
2239
+ },
2240
+ {
2241
+ $project: {
2242
+ _id: 1,
2243
+ name: 1,
2244
+ type: 1,
2245
+ siteId: 1
2246
+ }
2247
+ }
2248
+ ],
2249
+ as: "serviceProviders"
2250
+ }
2251
+ }
2252
+ ]).toArray();
2253
+ const data = results.length > 0 ? results[0] : null;
2196
2254
  if (!data) {
2197
2255
  throw new NotFoundError4("User not found.");
2198
2256
  }
@@ -12878,8 +12936,7 @@ var schemaVisitorTransaction = Joi36.object({
12878
12936
  ).optional().allow(null),
12879
12937
  visitorPass: Joi36.string().optional().allow(null, ""),
12880
12938
  unitName: Joi36.string().optional().allow(null, ""),
12881
- expiredAt: Joi36.date().iso().optional().allow(null, ""),
12882
- visitorId: Joi36.string().hex().length(24).required()
12939
+ expiredAt: Joi36.date().iso().optional().allow(null, "")
12883
12940
  });
12884
12941
  var schemaUpdateVisTrans = Joi36.object({
12885
12942
  _id: Joi36.string().hex().length(24).required(),
@@ -12905,8 +12962,7 @@ var schemaUpdateVisTrans = Joi36.object({
12905
12962
  status: Joi36.string().optional().allow(null, ""),
12906
12963
  remarks: Joi36.string().optional().allow(null, ""),
12907
12964
  manualCheckout: Joi36.boolean().optional().allow(null),
12908
- expiredAt: Joi36.date().iso().optional().allow(null, ""),
12909
- visitorId: Joi36.string().hex().length(24).optional().allow(null)
12965
+ expiredAt: Joi36.date().iso().optional().allow(null, "")
12910
12966
  });
12911
12967
  function MVisitorTransaction(value) {
12912
12968
  const { error } = schemaVisitorTransaction.validate(value);
@@ -12977,7 +13033,6 @@ function MVisitorTransaction(value) {
12977
13033
  visitorPass: value.visitorPass,
12978
13034
  unitName: value.unitName,
12979
13035
  expiredAt: value.expiredAt ?? null,
12980
- visitorId: value.visitorId ?? "",
12981
13036
  createdAt: value.createdAt ?? newDate,
12982
13037
  updatedAt: value.updatedAt ?? "",
12983
13038
  deletedAt: value.deletedAt ?? ""
@@ -12986,14 +13041,16 @@ function MVisitorTransaction(value) {
12986
13041
 
12987
13042
  // src/repositories/visitor-transaction.repo.ts
12988
13043
  import { ObjectId as ObjectId39 } from "mongodb";
13044
+ var visitors_namespace_collection = "visitor.transactions";
12989
13045
  function useVisitorTransactionRepo() {
12990
13046
  const db = useAtlas30.getDb();
12991
13047
  if (!db) {
12992
13048
  throw new InternalServerError23("Unable to connect to server.");
12993
13049
  }
12994
- const namespace_collection = "visitor.transactions";
12995
- const collection = db.collection(namespace_collection);
12996
- const { delNamespace, getCache, setCache } = useCache23(namespace_collection);
13050
+ const collection = db.collection(visitors_namespace_collection);
13051
+ const { delNamespace, getCache, setCache } = useCache23(
13052
+ visitors_namespace_collection
13053
+ );
12997
13054
  async function createTextIndex() {
12998
13055
  try {
12999
13056
  await collection.createIndex({
@@ -13015,10 +13072,12 @@ function useVisitorTransactionRepo() {
13015
13072
  value = MVisitorTransaction(value);
13016
13073
  const res = await collection.insertOne(value, { session });
13017
13074
  delNamespace().then(() => {
13018
- logger47.info(`Cache cleared for namespace: ${namespace_collection}`);
13075
+ logger47.info(
13076
+ `Cache cleared for namespace: ${visitors_namespace_collection}`
13077
+ );
13019
13078
  }).catch((err) => {
13020
13079
  logger47.error(
13021
- `Failed to clear cache for namespace: ${namespace_collection}`,
13080
+ `Failed to clear cache for namespace: ${visitors_namespace_collection}`,
13022
13081
  err
13023
13082
  );
13024
13083
  });
@@ -13093,7 +13152,7 @@ function useVisitorTransactionRepo() {
13093
13152
  ...checkedOut !== void 0 && { checkedOut },
13094
13153
  ...plateNumber && { plateNumber }
13095
13154
  };
13096
- const cacheKey = makeCacheKey22(namespace_collection, cacheOptions);
13155
+ const cacheKey = makeCacheKey22(visitors_namespace_collection, cacheOptions);
13097
13156
  const cachedData = await getCache(cacheKey);
13098
13157
  if (cachedData) {
13099
13158
  logger47.info(`Cache hit for key: ${cacheKey}`);
@@ -13105,6 +13164,36 @@ function useVisitorTransactionRepo() {
13105
13164
  collection.aggregate(
13106
13165
  [
13107
13166
  ...basePipeline,
13167
+ {
13168
+ $lookup: {
13169
+ from: "access-cards",
13170
+ localField: "_id",
13171
+ foreignField: "userId",
13172
+ let: { userId: "$_id" },
13173
+ pipeline: [
13174
+ {
13175
+ $match: {
13176
+ $expr: {
13177
+ $eq: ["$userId", "$$userId"]
13178
+ }
13179
+ }
13180
+ },
13181
+ {
13182
+ $project: {
13183
+ cardNo: 1,
13184
+ type: 1
13185
+ }
13186
+ }
13187
+ ],
13188
+ as: "accessCards"
13189
+ }
13190
+ },
13191
+ {
13192
+ $unwind: {
13193
+ path: "$accessCards",
13194
+ preserveNullAndEmptyArrays: true
13195
+ }
13196
+ },
13108
13197
  { $sort: sort },
13109
13198
  { $skip: skip },
13110
13199
  { $limit: limit }
@@ -13127,7 +13216,7 @@ function useVisitorTransactionRepo() {
13127
13216
  }
13128
13217
  async function getOpenByPlateNumber(plateNumber, site) {
13129
13218
  const _site = typeof site === "string" ? site : toObjectId5(site);
13130
- const cacheKey = makeCacheKey22(namespace_collection, {
13219
+ const cacheKey = makeCacheKey22(visitors_namespace_collection, {
13131
13220
  plateNumber,
13132
13221
  key: "get-open-transaction-plate-number",
13133
13222
  site
@@ -13171,10 +13260,12 @@ function useVisitorTransactionRepo() {
13171
13260
  { session }
13172
13261
  );
13173
13262
  delNamespace().then(() => {
13174
- logger47.info(`Cache cleared for namespace: ${namespace_collection}`);
13263
+ logger47.info(
13264
+ `Cache cleared for namespace: ${visitors_namespace_collection}`
13265
+ );
13175
13266
  }).catch((err) => {
13176
13267
  logger47.error(
13177
- `Failed to clear cache for namespace: ${namespace_collection}`,
13268
+ `Failed to clear cache for namespace: ${visitors_namespace_collection}`,
13178
13269
  err
13179
13270
  );
13180
13271
  });
@@ -13200,10 +13291,12 @@ function useVisitorTransactionRepo() {
13200
13291
  throw new InternalServerError23("Unable to delete visitor transaction.");
13201
13292
  }
13202
13293
  delNamespace().then(() => {
13203
- logger47.info(`Cache cleared for namespace: ${namespace_collection}`);
13294
+ logger47.info(
13295
+ `Cache cleared for namespace: ${visitors_namespace_collection}`
13296
+ );
13204
13297
  }).catch((err) => {
13205
13298
  logger47.error(
13206
- `Failed to clear cache for namespace: ${namespace_collection}`,
13299
+ `Failed to clear cache for namespace: ${visitors_namespace_collection}`,
13207
13300
  err
13208
13301
  );
13209
13302
  });
@@ -13273,10 +13366,12 @@ function useVisitorTransactionRepo() {
13273
13366
  { session }
13274
13367
  );
13275
13368
  delNamespace().then(() => {
13276
- logger47.info(`Cache cleared for namespace: ${namespace_collection}`);
13369
+ logger47.info(
13370
+ `Cache cleared for namespace: ${visitors_namespace_collection}`
13371
+ );
13277
13372
  }).catch((err) => {
13278
13373
  logger47.error(
13279
- `Failed to clear cache for namespace: ${namespace_collection}`,
13374
+ `Failed to clear cache for namespace: ${visitors_namespace_collection}`,
13280
13375
  err
13281
13376
  );
13282
13377
  });
@@ -13489,14 +13584,16 @@ import {
13489
13584
  } from "@7365admin1/node-server-utils";
13490
13585
  import { ObjectId as ObjectId41 } from "mongodb";
13491
13586
  import Joi38 from "joi";
13587
+ var vehicles_namespace_collection = "vehicles";
13492
13588
  function useVehicleRepo() {
13493
13589
  const db = useAtlas31.getDb();
13494
13590
  if (!db) {
13495
13591
  throw new InternalServerError24("Unable to connect to server.");
13496
13592
  }
13497
- const namespace_collection = "vehicles";
13498
- const collection = db.collection(namespace_collection);
13499
- const { delNamespace, setCache, getCache } = useCache24(namespace_collection);
13593
+ const collection = db.collection(vehicles_namespace_collection);
13594
+ const { delNamespace, setCache, getCache } = useCache24(
13595
+ vehicles_namespace_collection
13596
+ );
13500
13597
  async function createIndex() {
13501
13598
  try {
13502
13599
  await collection.createIndexes([
@@ -13529,10 +13626,12 @@ function useVehicleRepo() {
13529
13626
  value = MVehicle(value);
13530
13627
  const res = await collection.insertOne(value, { session });
13531
13628
  delNamespace().then(() => {
13532
- logger49.info(`Cache cleared for namespace: ${namespace_collection}`);
13629
+ logger49.info(
13630
+ `Cache cleared for namespace: ${vehicles_namespace_collection}`
13631
+ );
13533
13632
  }).catch((err) => {
13534
13633
  logger49.error(
13535
- `Failed to clear cache for namespace: ${namespace_collection}`,
13634
+ `Failed to clear cache for namespace: ${vehicles_namespace_collection}`,
13536
13635
  err
13537
13636
  );
13538
13637
  });
@@ -13578,7 +13677,7 @@ function useVehicleRepo() {
13578
13677
  query.$text = { $search: search };
13579
13678
  cacheOptions.search = search;
13580
13679
  }
13581
- const cacheKey = makeCacheKey23(namespace_collection, cacheOptions);
13680
+ const cacheKey = makeCacheKey23(vehicles_namespace_collection, cacheOptions);
13582
13681
  const cachedData = await getCache(cacheKey);
13583
13682
  if (cachedData) {
13584
13683
  logger49.info(`Cache hit for key: ${cacheKey}`);
@@ -13742,7 +13841,7 @@ function useVehicleRepo() {
13742
13841
  } catch (error) {
13743
13842
  throw new BadRequestError67("Invalid site ID format.");
13744
13843
  }
13745
- const cacheKey = makeCacheKey23(namespace_collection, {
13844
+ const cacheKey = makeCacheKey23(vehicles_namespace_collection, {
13746
13845
  site,
13747
13846
  type: "season-pass-type-as-options"
13748
13847
  });
@@ -13795,7 +13894,7 @@ function useVehicleRepo() {
13795
13894
  throw new BadRequestError67("Invalid vehicle ID format.");
13796
13895
  }
13797
13896
  try {
13798
- const cacheKey = makeCacheKey23(namespace_collection, { _id });
13897
+ const cacheKey = makeCacheKey23(vehicles_namespace_collection, { _id });
13799
13898
  const cachedData = await getCache(cacheKey);
13800
13899
  if (cachedData) {
13801
13900
  logger49.info(`Cache hit for key: ${cacheKey}`);
@@ -13986,7 +14085,7 @@ function useVehicleRepo() {
13986
14085
  throw new BadRequestError67(error.details[0].message);
13987
14086
  }
13988
14087
  try {
13989
- const cacheKey = makeCacheKey23(namespace_collection, {
14088
+ const cacheKey = makeCacheKey23(vehicles_namespace_collection, {
13990
14089
  plateNumber: value,
13991
14090
  status: "active"
13992
14091
  });
@@ -14032,10 +14131,12 @@ function useVehicleRepo() {
14032
14131
  throw new InternalServerError24("Unable to update vehicle.");
14033
14132
  }
14034
14133
  delNamespace().then(() => {
14035
- logger49.info(`Cache cleared for namespace: ${namespace_collection}`);
14134
+ logger49.info(
14135
+ `Cache cleared for namespace: ${vehicles_namespace_collection}`
14136
+ );
14036
14137
  }).catch((err) => {
14037
14138
  logger49.error(
14038
- `Failed to clear cache for namespace: ${namespace_collection}`,
14139
+ `Failed to clear cache for namespace: ${vehicles_namespace_collection}`,
14039
14140
  err
14040
14141
  );
14041
14142
  });
@@ -14063,10 +14164,12 @@ function useVehicleRepo() {
14063
14164
  if (res.modifiedCount === 0)
14064
14165
  throw new InternalServerError24("Unable to delete vehicle.");
14065
14166
  delNamespace().then(() => {
14066
- logger49.info(`Cache cleared for namespace: ${namespace_collection}`);
14167
+ logger49.info(
14168
+ `Cache cleared for namespace: ${vehicles_namespace_collection}`
14169
+ );
14067
14170
  }).catch((err) => {
14068
14171
  logger49.error(
14069
- `Failed to clear cache for namespace: ${namespace_collection}`,
14172
+ `Failed to clear cache for namespace: ${vehicles_namespace_collection}`,
14070
14173
  err
14071
14174
  );
14072
14175
  });
@@ -14080,7 +14183,7 @@ function useVehicleRepo() {
14080
14183
  if (error) {
14081
14184
  throw new BadRequestError67(error.details[0].message);
14082
14185
  }
14083
- const cacheKey = makeCacheKey23(namespace_collection, {
14186
+ const cacheKey = makeCacheKey23(vehicles_namespace_collection, {
14084
14187
  plateNumber,
14085
14188
  status: "active"
14086
14189
  });
@@ -14129,7 +14232,7 @@ function useVehicleRepo() {
14129
14232
  limit: String(limit),
14130
14233
  sort: JSON.stringify(sort)
14131
14234
  };
14132
- const cacheKey = makeCacheKey23(namespace_collection, cacheOptions);
14235
+ const cacheKey = makeCacheKey23(vehicles_namespace_collection, cacheOptions);
14133
14236
  const cachedData = await getCache(cacheKey);
14134
14237
  if (cachedData) {
14135
14238
  logger49.info(`Cache hit for key: ${cacheKey}`);
@@ -14176,10 +14279,12 @@ function useVehicleRepo() {
14176
14279
  { session }
14177
14280
  );
14178
14281
  delNamespace().then(() => {
14179
- logger49.info(`Cache cleared for namespace: ${namespace_collection}`);
14282
+ logger49.info(
14283
+ `Cache cleared for namespace: ${vehicles_namespace_collection}`
14284
+ );
14180
14285
  }).catch((err) => {
14181
14286
  logger49.error(
14182
- `Failed to clear cache for namespace: ${namespace_collection}`,
14287
+ `Failed to clear cache for namespace: ${vehicles_namespace_collection}`,
14183
14288
  err
14184
14289
  );
14185
14290
  });
@@ -14207,7 +14312,10 @@ function useVehicleRepo() {
14207
14312
  limit,
14208
14313
  sort: JSON.stringify(sort)
14209
14314
  };
14210
- const cacheKey = makeCacheKey23(namespace_collection, cacheOptions);
14315
+ const cacheKey = makeCacheKey23(
14316
+ vehicles_namespace_collection,
14317
+ cacheOptions
14318
+ );
14211
14319
  const cachedData = await getCache(cacheKey);
14212
14320
  if (cachedData) {
14213
14321
  logger49.info(`Cache hit for key: ${cacheKey}`);
@@ -14269,14 +14377,16 @@ import {
14269
14377
  AppError as AppError10
14270
14378
  } from "@7365admin1/node-server-utils";
14271
14379
  import { ObjectId as ObjectId42 } from "mongodb";
14380
+ var site_people_namespace_collection = "site.people";
14272
14381
  function usePersonRepo() {
14273
14382
  const db = useAtlas32.getDb();
14274
14383
  if (!db) {
14275
14384
  throw new InternalServerError25("Unable to connect to server.");
14276
14385
  }
14277
- const namespace_collection = "site.people";
14278
- const collection = db.collection(namespace_collection);
14279
- const { delNamespace, getCache, setCache } = useCache25(namespace_collection);
14386
+ const collection = db.collection(site_people_namespace_collection);
14387
+ const { delNamespace, getCache, setCache } = useCache25(
14388
+ site_people_namespace_collection
14389
+ );
14280
14390
  async function createIndexes() {
14281
14391
  try {
14282
14392
  await collection.createIndexes([
@@ -14308,10 +14418,12 @@ function usePersonRepo() {
14308
14418
  value = MPerson(value);
14309
14419
  const res = await collection.insertOne(value, { session });
14310
14420
  delNamespace().then(() => {
14311
- logger50.info(`Cache cleared for namespace: ${namespace_collection}`);
14421
+ logger50.info(
14422
+ `Cache cleared for namespace: ${site_people_namespace_collection}`
14423
+ );
14312
14424
  }).catch((err) => {
14313
14425
  logger50.error(
14314
- `Failed to clear cache for namespace: ${namespace_collection}`,
14426
+ `Failed to clear cache for namespace: ${site_people_namespace_collection}`,
14315
14427
  err
14316
14428
  );
14317
14429
  });
@@ -14373,7 +14485,10 @@ function usePersonRepo() {
14373
14485
  ...query.site && { site: query.site.toString() },
14374
14486
  ...PERSON_TYPES.includes(type) && { type }
14375
14487
  };
14376
- const cacheKey = makeCacheKey24(namespace_collection, cacheOptions);
14488
+ const cacheKey = makeCacheKey24(
14489
+ site_people_namespace_collection,
14490
+ cacheOptions
14491
+ );
14377
14492
  const cachedData = await getCache(cacheKey);
14378
14493
  if (cachedData) {
14379
14494
  logger50.info(`Cache hit for key: ${cacheKey}`);
@@ -14414,10 +14529,12 @@ function usePersonRepo() {
14414
14529
  { session }
14415
14530
  );
14416
14531
  delNamespace().then(() => {
14417
- logger50.info(`Cache cleared for namespace: ${namespace_collection}`);
14532
+ logger50.info(
14533
+ `Cache cleared for namespace: ${site_people_namespace_collection}`
14534
+ );
14418
14535
  }).catch((err) => {
14419
14536
  logger50.error(
14420
- `Failed to clear cache for namespace: ${namespace_collection}`,
14537
+ `Failed to clear cache for namespace: ${site_people_namespace_collection}`,
14421
14538
  err
14422
14539
  );
14423
14540
  });
@@ -14443,10 +14560,12 @@ function usePersonRepo() {
14443
14560
  throw new InternalServerError25("Unable to delete visitor transaction.");
14444
14561
  }
14445
14562
  delNamespace().then(() => {
14446
- logger50.info(`Cache cleared for namespace: ${namespace_collection}`);
14563
+ logger50.info(
14564
+ `Cache cleared for namespace: ${site_people_namespace_collection}`
14565
+ );
14447
14566
  }).catch((err) => {
14448
14567
  logger50.error(
14449
- `Failed to clear cache for namespace: ${namespace_collection}`,
14568
+ `Failed to clear cache for namespace: ${site_people_namespace_collection}`,
14450
14569
  err
14451
14570
  );
14452
14571
  });
@@ -14461,7 +14580,7 @@ function usePersonRepo() {
14461
14580
  } catch (error) {
14462
14581
  throw new BadRequestError68("Invalid person ID.");
14463
14582
  }
14464
- const cacheKey = makeCacheKey24(namespace_collection, {
14583
+ const cacheKey = makeCacheKey24(site_people_namespace_collection, {
14465
14584
  _id: String(_id)
14466
14585
  });
14467
14586
  try {
@@ -14497,7 +14616,7 @@ function usePersonRepo() {
14497
14616
  }
14498
14617
  }
14499
14618
  async function getPersonByPlateNumber(plateNumber) {
14500
- const cacheKey = makeCacheKey24(namespace_collection, {
14619
+ const cacheKey = makeCacheKey24(site_people_namespace_collection, {
14501
14620
  plateNumber,
14502
14621
  key: "get-person-plate-number"
14503
14622
  });
@@ -14525,7 +14644,7 @@ function usePersonRepo() {
14525
14644
  }
14526
14645
  async function getByNRIC(value) {
14527
14646
  try {
14528
- const cacheKey = makeCacheKey24(namespace_collection, {
14647
+ const cacheKey = makeCacheKey24(site_people_namespace_collection, {
14529
14648
  nric: value
14530
14649
  });
14531
14650
  const cachedData = await getCache(cacheKey);
@@ -14546,7 +14665,7 @@ function usePersonRepo() {
14546
14665
  }
14547
14666
  async function getPersonByPhoneNumber(value) {
14548
14667
  try {
14549
- const cacheKey = makeCacheKey24(namespace_collection, {
14668
+ const cacheKey = makeCacheKey24(site_people_namespace_collection, {
14550
14669
  contact: value
14551
14670
  });
14552
14671
  const cachedData = await getCache(cacheKey);
@@ -14572,7 +14691,7 @@ function usePersonRepo() {
14572
14691
  type,
14573
14692
  unit
14574
14693
  }, session) {
14575
- const cacheKey = makeCacheKey24(namespace_collection, {
14694
+ const cacheKey = makeCacheKey24(site_people_namespace_collection, {
14576
14695
  unit: JSON.stringify(unit),
14577
14696
  status,
14578
14697
  type,
@@ -14599,7 +14718,7 @@ function usePersonRepo() {
14599
14718
  }
14600
14719
  async function getCompany(search) {
14601
14720
  try {
14602
- const cacheKey = makeCacheKey24(namespace_collection, {
14721
+ const cacheKey = makeCacheKey24(site_people_namespace_collection, {
14603
14722
  company: search
14604
14723
  });
14605
14724
  const cachedData = await getCache(cacheKey);
@@ -14658,7 +14777,7 @@ function usePersonRepo() {
14658
14777
  }
14659
14778
  }
14660
14779
  async function getPeopleByPlateNumber(plateNumber) {
14661
- const cacheKey = makeCacheKey24(namespace_collection, {
14780
+ const cacheKey = makeCacheKey24(site_people_namespace_collection, {
14662
14781
  plateNumber,
14663
14782
  key: "get-people-plate-number"
14664
14783
  });
@@ -14704,7 +14823,10 @@ function usePersonRepo() {
14704
14823
  sort: JSON.stringify(sort)
14705
14824
  };
14706
14825
  try {
14707
- const cacheKey = makeCacheKey24(namespace_collection, cacheOptions);
14826
+ const cacheKey = makeCacheKey24(
14827
+ site_people_namespace_collection,
14828
+ cacheOptions
14829
+ );
14708
14830
  const cachedData = await getCache(cacheKey);
14709
14831
  if (cachedData) {
14710
14832
  logger50.info(`Cache hit for key: ${cacheKey}`);
@@ -16510,14 +16632,16 @@ import {
16510
16632
  useCache as useCache27
16511
16633
  } from "@7365admin1/node-server-utils";
16512
16634
  import { ObjectId as ObjectId46 } from "mongodb";
16635
+ var buildings_namespace_collection = "buildings";
16513
16636
  function useBuildingRepo() {
16514
16637
  const db = useAtlas36.getDb();
16515
16638
  if (!db) {
16516
16639
  throw new Error("Unable to connect to server.");
16517
16640
  }
16518
- const namespace_collection = "buildings";
16519
- const collection = db.collection(namespace_collection);
16520
- const { getCache, setCache, delNamespace } = useCache27(namespace_collection);
16641
+ const collection = db.collection(buildings_namespace_collection);
16642
+ const { getCache, setCache, delNamespace } = useCache27(
16643
+ buildings_namespace_collection
16644
+ );
16521
16645
  async function createIndexes() {
16522
16646
  try {
16523
16647
  await collection.createIndexes([
@@ -16626,7 +16750,7 @@ function useBuildingRepo() {
16626
16750
  ...site && { site },
16627
16751
  ...status && { status }
16628
16752
  };
16629
- const cacheKey = makeCacheKey25(namespace_collection, cacheParams);
16753
+ const cacheKey = makeCacheKey25(buildings_namespace_collection, cacheParams);
16630
16754
  logger59.log({
16631
16755
  level: "info",
16632
16756
  message: `Cache key for getAll buildings: ${cacheKey}`
@@ -16671,7 +16795,9 @@ function useBuildingRepo() {
16671
16795
  } catch (error) {
16672
16796
  throw new BadRequestError76("Invalid ID.");
16673
16797
  }
16674
- const cacheKey = makeCacheKey25(namespace_collection, { _id: String(_id) });
16798
+ const cacheKey = makeCacheKey25(buildings_namespace_collection, {
16799
+ _id: String(_id)
16800
+ });
16675
16801
  try {
16676
16802
  const cached = await getCache(cacheKey);
16677
16803
  if (cached) {
@@ -16740,7 +16866,7 @@ function useBuildingRepo() {
16740
16866
  block
16741
16867
  };
16742
16868
  const cacheOptions = { ...query };
16743
- const cacheKey = makeCacheKey25(namespace_collection, cacheOptions);
16869
+ const cacheKey = makeCacheKey25(buildings_namespace_collection, cacheOptions);
16744
16870
  try {
16745
16871
  const cached = await getCache(cacheKey);
16746
16872
  if (cached) {
@@ -16775,12 +16901,12 @@ function useBuildingRepo() {
16775
16901
  delNamespace().then(() => {
16776
16902
  logger59.log({
16777
16903
  level: "info",
16778
- message: `Cache namespace cleared for ${namespace_collection}`
16904
+ message: `Cache namespace cleared for ${buildings_namespace_collection}`
16779
16905
  });
16780
16906
  }).catch((err) => {
16781
16907
  logger59.log({
16782
16908
  level: "error",
16783
- message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
16909
+ message: `Failed to clear cache namespace for ${buildings_namespace_collection}: ${err.message}`
16784
16910
  });
16785
16911
  });
16786
16912
  }
@@ -20244,9 +20370,9 @@ function useVisitorTransactionService() {
20244
20370
  value.checkIn = startString;
20245
20371
  value.expiredAt = endString;
20246
20372
  }
20247
- await _add(value, session);
20373
+ const result = await _add(value, session);
20248
20374
  await session?.commitTransaction();
20249
- return "Successfully added visitor transaction.";
20375
+ return result;
20250
20376
  } catch (error) {
20251
20377
  await session?.abortTransaction();
20252
20378
  throw error;
@@ -20599,14 +20725,16 @@ import {
20599
20725
  useCache as useCache32
20600
20726
  } from "@7365admin1/node-server-utils";
20601
20727
  import { ObjectId as ObjectId55 } from "mongodb";
20728
+ var guests_namespace_collection = "visitor.guests";
20602
20729
  function useGuestManagementRepo() {
20603
20730
  const db = useAtlas48.getDb();
20604
20731
  if (!db) {
20605
20732
  throw new InternalServerError33("Unable to connect to server.");
20606
20733
  }
20607
- const namespace_collection = "visitor.guests";
20608
- const collection = db.collection(namespace_collection);
20609
- const { delNamespace, getCache, setCache } = useCache32(namespace_collection);
20734
+ const collection = db.collection(guests_namespace_collection);
20735
+ const { delNamespace, getCache, setCache } = useCache32(
20736
+ guests_namespace_collection
20737
+ );
20610
20738
  async function createTextIndex() {
20611
20739
  try {
20612
20740
  await collection.createIndex({
@@ -20626,10 +20754,12 @@ function useGuestManagementRepo() {
20626
20754
  value = MGuestManagement(value);
20627
20755
  const res = await collection.insertOne(value, { session });
20628
20756
  delNamespace().then(() => {
20629
- logger79.info(`Cache cleared for namespace: ${namespace_collection}`);
20757
+ logger79.info(
20758
+ `Cache cleared for namespace: ${guests_namespace_collection}`
20759
+ );
20630
20760
  }).catch((err) => {
20631
20761
  logger79.error(
20632
- `Failed to clear cache for namespace: ${namespace_collection}`,
20762
+ `Failed to clear cache for namespace: ${guests_namespace_collection}`,
20633
20763
  err
20634
20764
  );
20635
20765
  });
@@ -20681,7 +20811,7 @@ function useGuestManagementRepo() {
20681
20811
  ...query.org && { org: query.org.toString() },
20682
20812
  ...query.site && { site: query.site.toString() }
20683
20813
  };
20684
- const cacheKey = makeCacheKey30(namespace_collection, cacheOptions);
20814
+ const cacheKey = makeCacheKey30(guests_namespace_collection, cacheOptions);
20685
20815
  const cachedData = await getCache(cacheKey);
20686
20816
  if (cachedData) {
20687
20817
  logger79.info(`Cache hit for key: ${cacheKey}`);
@@ -20722,10 +20852,12 @@ function useGuestManagementRepo() {
20722
20852
  { session }
20723
20853
  );
20724
20854
  delNamespace().then(() => {
20725
- logger79.info(`Cache cleared for namespace: ${namespace_collection}`);
20855
+ logger79.info(
20856
+ `Cache cleared for namespace: ${guests_namespace_collection}`
20857
+ );
20726
20858
  }).catch((err) => {
20727
20859
  logger79.error(
20728
- `Failed to clear cache for namespace: ${namespace_collection}`,
20860
+ `Failed to clear cache for namespace: ${guests_namespace_collection}`,
20729
20861
  err
20730
20862
  );
20731
20863
  });
@@ -20751,10 +20883,12 @@ function useGuestManagementRepo() {
20751
20883
  throw new InternalServerError33("Unable to delete visitor transaction.");
20752
20884
  }
20753
20885
  delNamespace().then(() => {
20754
- logger79.info(`Cache cleared for namespace: ${namespace_collection}`);
20886
+ logger79.info(
20887
+ `Cache cleared for namespace: ${guests_namespace_collection}`
20888
+ );
20755
20889
  }).catch((err) => {
20756
20890
  logger79.error(
20757
- `Failed to clear cache for namespace: ${namespace_collection}`,
20891
+ `Failed to clear cache for namespace: ${guests_namespace_collection}`,
20758
20892
  err
20759
20893
  );
20760
20894
  });
@@ -25058,14 +25192,16 @@ import {
25058
25192
  useCache as useCache39
25059
25193
  } from "@7365admin1/node-server-utils";
25060
25194
  import { ObjectId as ObjectId69 } from "mongodb";
25195
+ var facility_bookings_namespace_collection = "site.facilty-booking";
25061
25196
  function useSiteFacilityBookingRepo() {
25062
25197
  const db = useAtlas60.getDb();
25063
25198
  if (!db) {
25064
25199
  throw new InternalServerError40("Unable to connect to server.");
25065
25200
  }
25066
- const namespace_collection = "site.facilty-booking";
25067
- const collection = db.collection(namespace_collection);
25068
- const { delNamespace, getCache, setCache } = useCache39(namespace_collection);
25201
+ const collection = db.collection(facility_bookings_namespace_collection);
25202
+ const { delNamespace, getCache, setCache } = useCache39(
25203
+ facility_bookings_namespace_collection
25204
+ );
25069
25205
  async function createIndexes() {
25070
25206
  try {
25071
25207
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
@@ -25078,10 +25214,12 @@ function useSiteFacilityBookingRepo() {
25078
25214
  value = MSiteFacilityBooking(value);
25079
25215
  const res = await collection.insertOne(value, { session });
25080
25216
  delNamespace().then(() => {
25081
- logger100.info(`Cache cleared for namespace: ${namespace_collection}`);
25217
+ logger100.info(
25218
+ `Cache cleared for namespace: ${facility_bookings_namespace_collection}`
25219
+ );
25082
25220
  }).catch((err) => {
25083
25221
  logger100.error(
25084
- `Failed to clear cache for namespace: ${namespace_collection}`,
25222
+ `Failed to clear cache for namespace: ${facility_bookings_namespace_collection}`,
25085
25223
  err
25086
25224
  );
25087
25225
  });
@@ -25119,7 +25257,10 @@ function useSiteFacilityBookingRepo() {
25119
25257
  limit,
25120
25258
  ...search && { search }
25121
25259
  };
25122
- const cacheKey = makeCacheKey37(namespace_collection, cacheOptions);
25260
+ const cacheKey = makeCacheKey37(
25261
+ facility_bookings_namespace_collection,
25262
+ cacheOptions
25263
+ );
25123
25264
  const cachedData = await getCache(cacheKey);
25124
25265
  if (cachedData) {
25125
25266
  logger100.info(`Cache hit for key: ${cacheKey}`);
@@ -25149,7 +25290,9 @@ function useSiteFacilityBookingRepo() {
25149
25290
  }
25150
25291
  async function getSiteFacilityBookingById(id, session) {
25151
25292
  const _id = toObjectId7(id);
25152
- const cacheKey = makeCacheKey37(namespace_collection, { id });
25293
+ const cacheKey = makeCacheKey37(facility_bookings_namespace_collection, {
25294
+ id
25295
+ });
25153
25296
  const cachedData = await getCache(cacheKey);
25154
25297
  if (cachedData) {
25155
25298
  logger100.info(`Cache hit for key: ${cacheKey}`);
@@ -25195,10 +25338,12 @@ function useSiteFacilityBookingRepo() {
25195
25338
  );
25196
25339
  }
25197
25340
  delNamespace().then(() => {
25198
- logger100.info(`Cache cleared for namespace: ${namespace_collection}`);
25341
+ logger100.info(
25342
+ `Cache cleared for namespace: ${facility_bookings_namespace_collection}`
25343
+ );
25199
25344
  }).catch((err) => {
25200
25345
  logger100.error(
25201
- `Failed to clear cache for namespace: ${namespace_collection}`,
25346
+ `Failed to clear cache for namespace: ${facility_bookings_namespace_collection}`,
25202
25347
  err
25203
25348
  );
25204
25349
  });
@@ -25226,10 +25371,12 @@ function useSiteFacilityBookingRepo() {
25226
25371
  );
25227
25372
  }
25228
25373
  delNamespace().then(() => {
25229
- logger100.info(`Cache cleared for namespace: ${namespace_collection}`);
25374
+ logger100.info(
25375
+ `Cache cleared for namespace: ${facility_bookings_namespace_collection}`
25376
+ );
25230
25377
  }).catch((err) => {
25231
25378
  logger100.error(
25232
- `Failed to clear cache for namespace: ${namespace_collection}`,
25379
+ `Failed to clear cache for namespace: ${facility_bookings_namespace_collection}`,
25233
25380
  err
25234
25381
  );
25235
25382
  });
@@ -26169,14 +26316,16 @@ import {
26169
26316
  useCache as useCache41
26170
26317
  } from "@7365admin1/node-server-utils";
26171
26318
  import { ObjectId as ObjectId73 } from "mongodb";
26319
+ var bulletin_boards_namespace_collection = "bulletin-boards";
26172
26320
  function useBulletinBoardRepo() {
26173
26321
  const db = useAtlas64.getDb();
26174
26322
  if (!db) {
26175
26323
  throw new InternalServerError42("Unable to connect to server.");
26176
26324
  }
26177
- const namespace_collection = "bulletin-boards";
26178
- const collection = db.collection(namespace_collection);
26179
- const { delNamespace, getCache, setCache } = useCache41(namespace_collection);
26325
+ const collection = db.collection(bulletin_boards_namespace_collection);
26326
+ const { delNamespace, getCache, setCache } = useCache41(
26327
+ bulletin_boards_namespace_collection
26328
+ );
26180
26329
  async function createIndexes() {
26181
26330
  try {
26182
26331
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
@@ -26189,10 +26338,12 @@ function useBulletinBoardRepo() {
26189
26338
  value = MBulletinBoard(value);
26190
26339
  const res = await collection.insertOne(value, { session });
26191
26340
  delNamespace().then(() => {
26192
- logger104.info(`Cache cleared for namespace: ${namespace_collection}`);
26341
+ logger104.info(
26342
+ `Cache cleared for namespace: ${bulletin_boards_namespace_collection}`
26343
+ );
26193
26344
  }).catch((err) => {
26194
26345
  logger104.error(
26195
- `Failed to clear cache for namespace: ${namespace_collection}`,
26346
+ `Failed to clear cache for namespace: ${bulletin_boards_namespace_collection}`,
26196
26347
  err
26197
26348
  );
26198
26349
  });
@@ -26236,7 +26387,10 @@ function useBulletinBoardRepo() {
26236
26387
  ...search && { search },
26237
26388
  ...recipients?.length && { recipients: recipients.sort().join(",") }
26238
26389
  };
26239
- const cacheKey = makeCacheKey39(namespace_collection, cacheOptions);
26390
+ const cacheKey = makeCacheKey39(
26391
+ bulletin_boards_namespace_collection,
26392
+ cacheOptions
26393
+ );
26240
26394
  const cachedData = await getCache(cacheKey);
26241
26395
  if (cachedData) {
26242
26396
  logger104.info(`Cache hit for key: ${cacheKey}`);
@@ -26270,7 +26424,9 @@ function useBulletinBoardRepo() {
26270
26424
  } catch (error) {
26271
26425
  throw new BadRequestError124("Invalid bulletin board ID format.");
26272
26426
  }
26273
- const cacheKey = makeCacheKey39(namespace_collection, { _id });
26427
+ const cacheKey = makeCacheKey39(bulletin_boards_namespace_collection, {
26428
+ _id
26429
+ });
26274
26430
  const cachedData = await getCache(cacheKey);
26275
26431
  if (cachedData) {
26276
26432
  logger104.info(`Cache hit for key: ${cacheKey}`);
@@ -26315,10 +26471,12 @@ function useBulletinBoardRepo() {
26315
26471
  throw new InternalServerError42("Unable to update bulletin board.");
26316
26472
  }
26317
26473
  delNamespace().then(() => {
26318
- logger104.info(`Cache cleared for namespace: ${namespace_collection}`);
26474
+ logger104.info(
26475
+ `Cache cleared for namespace: ${bulletin_boards_namespace_collection}`
26476
+ );
26319
26477
  }).catch((err) => {
26320
26478
  logger104.error(
26321
- `Failed to clear cache for namespace: ${namespace_collection}`,
26479
+ `Failed to clear cache for namespace: ${bulletin_boards_namespace_collection}`,
26322
26480
  err
26323
26481
  );
26324
26482
  });
@@ -26348,10 +26506,12 @@ function useBulletinBoardRepo() {
26348
26506
  throw new InternalServerError42("Unable to delete bulletin board.");
26349
26507
  }
26350
26508
  delNamespace().then(() => {
26351
- logger104.info(`Cache cleared for namespace: ${namespace_collection}`);
26509
+ logger104.info(
26510
+ `Cache cleared for namespace: ${bulletin_boards_namespace_collection}`
26511
+ );
26352
26512
  }).catch((err) => {
26353
26513
  logger104.error(
26354
- `Failed to clear cache for namespace: ${namespace_collection}`,
26514
+ `Failed to clear cache for namespace: ${bulletin_boards_namespace_collection}`,
26355
26515
  err
26356
26516
  );
26357
26517
  });
@@ -26380,10 +26540,12 @@ function useBulletinBoardRepo() {
26380
26540
  throw new NotFoundError30("No bulletin boards found to update.");
26381
26541
  }
26382
26542
  delNamespace().then(() => {
26383
- logger104.info(`Cache cleared for namespace: ${namespace_collection}`);
26543
+ logger104.info(
26544
+ `Cache cleared for namespace: ${bulletin_boards_namespace_collection}`
26545
+ );
26384
26546
  }).catch((err) => {
26385
26547
  logger104.error(
26386
- `Failed to clear cache for namespace: ${namespace_collection}`,
26548
+ `Failed to clear cache for namespace: ${bulletin_boards_namespace_collection}`,
26387
26549
  err
26388
26550
  );
26389
26551
  });
@@ -26523,7 +26685,32 @@ function useBulletinBoardController() {
26523
26685
  order: Joi76.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */),
26524
26686
  site: Joi76.string().hex().length(24).required(),
26525
26687
  status: Joi76.string().valid(...Object.values(BuildingStatus)).optional().default("active" /* ACTIVE */),
26526
- recipients: Joi76.array().items(Joi76.string().valid(...Object.values(BulletinRecipient))).optional()
26688
+ recipients: Joi76.alternatives().try(
26689
+ Joi76.array().items(
26690
+ Joi76.string().valid(...Object.values(BulletinRecipient))
26691
+ ),
26692
+ Joi76.string().allow("")
26693
+ ).optional().allow(null).custom((value2, helpers) => {
26694
+ if (!value2 || value2 === "") {
26695
+ return [];
26696
+ }
26697
+ let parsed = [];
26698
+ if (Array.isArray(value2)) {
26699
+ parsed = value2;
26700
+ } else if (typeof value2 === "string") {
26701
+ parsed = value2.split(",").map((v) => v.trim()).filter(Boolean);
26702
+ }
26703
+ for (const r of parsed) {
26704
+ if (!Object.values(BulletinRecipient).includes(r)) {
26705
+ return helpers.error("any.only");
26706
+ }
26707
+ }
26708
+ return parsed;
26709
+ }).messages({
26710
+ "any.only": `Recipients must be one of: ${Object.values(
26711
+ BulletinRecipient
26712
+ ).join(", ")}`
26713
+ })
26527
26714
  });
26528
26715
  const { error, value } = validation.validate(req.query, {
26529
26716
  abortEarly: false
@@ -27956,14 +28143,16 @@ import {
27956
28143
  useCache as useCache44
27957
28144
  } from "@7365admin1/node-server-utils";
27958
28145
  import { ObjectId as ObjectId79 } from "mongodb";
28146
+ var events_namespace_collection = "event-management";
27959
28147
  function useEventManagementRepo() {
27960
28148
  const db = useAtlas70.getDb();
27961
28149
  if (!db) {
27962
28150
  throw new InternalServerError45("Unable to connect to server.");
27963
28151
  }
27964
- const namespace_collection = "event-management";
27965
- const collection = db.collection(namespace_collection);
27966
- const { delNamespace, getCache, setCache } = useCache44(namespace_collection);
28152
+ const collection = db.collection(events_namespace_collection);
28153
+ const { delNamespace, getCache, setCache } = useCache44(
28154
+ events_namespace_collection
28155
+ );
27967
28156
  async function createIndexes() {
27968
28157
  try {
27969
28158
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
@@ -27990,10 +28179,12 @@ function useEventManagementRepo() {
27990
28179
  value = MEventManagement(value);
27991
28180
  const res = await collection.insertOne(value, { session });
27992
28181
  delNamespace().then(() => {
27993
- logger114.info(`Cache cleared for namespace: ${namespace_collection}`);
28182
+ logger114.info(
28183
+ `Cache cleared for namespace: ${events_namespace_collection}`
28184
+ );
27994
28185
  }).catch((err) => {
27995
28186
  logger114.error(
27996
- `Failed to clear cache for namespace: ${namespace_collection}`,
28187
+ `Failed to clear cache for namespace: ${events_namespace_collection}`,
27997
28188
  err
27998
28189
  );
27999
28190
  });
@@ -28047,7 +28238,7 @@ function useEventManagementRepo() {
28047
28238
  query.$text = { $search: search };
28048
28239
  cacheOptions.search = search;
28049
28240
  }
28050
- const cacheKey = makeCacheKey42(namespace_collection, cacheOptions);
28241
+ const cacheKey = makeCacheKey42(events_namespace_collection, cacheOptions);
28051
28242
  const cachedData = await getCache(cacheKey);
28052
28243
  if (cachedData) {
28053
28244
  logger114.info(`Cache hit for key: ${cacheKey}`);
@@ -28099,7 +28290,7 @@ function useEventManagementRepo() {
28099
28290
  } catch (error) {
28100
28291
  throw new BadRequestError134("Invalid event ID format.");
28101
28292
  }
28102
- const cacheKey = makeCacheKey42(namespace_collection, { _id });
28293
+ const cacheKey = makeCacheKey42(events_namespace_collection, { _id });
28103
28294
  const cachedData = await getCache(cacheKey);
28104
28295
  if (cachedData) {
28105
28296
  logger114.info(`Cache hit for key: ${cacheKey}`);
@@ -28144,10 +28335,12 @@ function useEventManagementRepo() {
28144
28335
  throw new InternalServerError45("Unable to update event.");
28145
28336
  }
28146
28337
  delNamespace().then(() => {
28147
- logger114.info(`Cache cleared for namespace: ${namespace_collection}`);
28338
+ logger114.info(
28339
+ `Cache cleared for namespace: ${events_namespace_collection}`
28340
+ );
28148
28341
  }).catch((err) => {
28149
28342
  logger114.error(
28150
- `Failed to clear cache for namespace: ${namespace_collection}`,
28343
+ `Failed to clear cache for namespace: ${events_namespace_collection}`,
28151
28344
  err
28152
28345
  );
28153
28346
  });
@@ -28173,10 +28366,12 @@ function useEventManagementRepo() {
28173
28366
  throw new InternalServerError45("Unable to delete event.");
28174
28367
  }
28175
28368
  delNamespace().then(() => {
28176
- logger114.info(`Cache cleared for namespace: ${namespace_collection}`);
28369
+ logger114.info(
28370
+ `Cache cleared for namespace: ${events_namespace_collection}`
28371
+ );
28177
28372
  }).catch((err) => {
28178
28373
  logger114.error(
28179
- `Failed to clear cache for namespace: ${namespace_collection}`,
28374
+ `Failed to clear cache for namespace: ${events_namespace_collection}`,
28180
28375
  err
28181
28376
  );
28182
28377
  });
@@ -28205,10 +28400,12 @@ function useEventManagementRepo() {
28205
28400
  throw new NotFoundError33("No bulletin boards found to update.");
28206
28401
  }
28207
28402
  delNamespace().then(() => {
28208
- logger114.info(`Cache cleared for namespace: ${namespace_collection}`);
28403
+ logger114.info(
28404
+ `Cache cleared for namespace: ${events_namespace_collection}`
28405
+ );
28209
28406
  }).catch((err) => {
28210
28407
  logger114.error(
28211
- `Failed to clear cache for namespace: ${namespace_collection}`,
28408
+ `Failed to clear cache for namespace: ${events_namespace_collection}`,
28212
28409
  err
28213
28410
  );
28214
28411
  });
@@ -31463,6 +31660,21 @@ function UseAccessManagementRepo() {
31463
31660
  throw new Error(error.message);
31464
31661
  }
31465
31662
  }
31663
+ async function checkoutVisitorRepo(params) {
31664
+ const session = useAtlas74.getClient()?.startSession();
31665
+ try {
31666
+ await session?.startTransaction();
31667
+ const userId = new ObjectId84(params.userId);
31668
+ const result = await collection().updateMany({ userId }, { $set: { userId: null, status: "Available", updatedAt: /* @__PURE__ */ new Date() } });
31669
+ await session?.commitTransaction();
31670
+ return result;
31671
+ } catch (error) {
31672
+ await session?.abortTransaction();
31673
+ throw new Error(error.message);
31674
+ } finally {
31675
+ await session?.endSession();
31676
+ }
31677
+ }
31466
31678
  return {
31467
31679
  createIndexes,
31468
31680
  createIndexForEntrypass,
@@ -31491,7 +31703,8 @@ function UseAccessManagementRepo() {
31491
31703
  availableCardContractorsRepo,
31492
31704
  vmsgenerateQrCodesRepo,
31493
31705
  addVisitorAccessCardRepo,
31494
- signQrCodeRepo
31706
+ signQrCodeRepo,
31707
+ checkoutVisitorRepo
31495
31708
  };
31496
31709
  }
31497
31710
 
@@ -31529,7 +31742,8 @@ function useAccessManagementSvc() {
31529
31742
  availableCardContractorsRepo,
31530
31743
  vmsgenerateQrCodesRepo,
31531
31744
  addVisitorAccessCardRepo,
31532
- signQrCodeRepo
31745
+ signQrCodeRepo,
31746
+ checkoutVisitorRepo
31533
31747
  } = UseAccessManagementRepo();
31534
31748
  const addPhysicalCardSvc = async (payload) => {
31535
31749
  try {
@@ -31805,6 +32019,14 @@ function useAccessManagementSvc() {
31805
32019
  throw new Error(err.message);
31806
32020
  }
31807
32021
  };
32022
+ const checkoutVisitorSvc = async (params) => {
32023
+ try {
32024
+ const response = await checkoutVisitorRepo({ ...params });
32025
+ return response;
32026
+ } catch (err) {
32027
+ throw new Error(err.message);
32028
+ }
32029
+ };
31808
32030
  return {
31809
32031
  addPhysicalCardSvc,
31810
32032
  addNonPhysicalCardSvc,
@@ -31837,7 +32059,8 @@ function useAccessManagementSvc() {
31837
32059
  availableCardContractorsSvc,
31838
32060
  vmsgenerateQrCodesSvc,
31839
32061
  addVisitorAccessCardSvc,
31840
- signQrCodeSvc
32062
+ signQrCodeSvc,
32063
+ checkoutVisitorSvc
31841
32064
  };
31842
32065
  }
31843
32066
 
@@ -31875,7 +32098,8 @@ function useAccessManagementController() {
31875
32098
  availableCardContractorsSvc,
31876
32099
  vmsgenerateQrCodesSvc,
31877
32100
  addVisitorAccessCardSvc,
31878
- signQrCodeSvc
32101
+ signQrCodeSvc,
32102
+ checkoutVisitorSvc
31879
32103
  } = useAccessManagementSvc();
31880
32104
  const addPhysicalCard = async (req, res) => {
31881
32105
  try {
@@ -32600,6 +32824,25 @@ function useAccessManagementController() {
32600
32824
  });
32601
32825
  }
32602
32826
  };
32827
+ const checkoutVisitor = async (req, res) => {
32828
+ try {
32829
+ const { userId } = req.body;
32830
+ const schema2 = Joi85.object({
32831
+ userId: Joi85.string().hex().length(24).required()
32832
+ });
32833
+ const { error } = schema2.validate({ userId });
32834
+ if (error) {
32835
+ return res.status(400).json({ message: error.message });
32836
+ }
32837
+ const result = await checkoutVisitorSvc({ userId });
32838
+ return res.status(200).json({ message: "Success", data: result });
32839
+ } catch (error) {
32840
+ return res.status(500).json({
32841
+ data: null,
32842
+ message: error.message
32843
+ });
32844
+ }
32845
+ };
32603
32846
  return {
32604
32847
  addPhysicalCard,
32605
32848
  addNonPhysicalCard,
@@ -32629,7 +32872,8 @@ function useAccessManagementController() {
32629
32872
  availableCardContractors,
32630
32873
  vmsgenerateQrCodes,
32631
32874
  addVisitorAccessCard,
32632
- signQrCode
32875
+ signQrCode,
32876
+ checkoutVisitor
32633
32877
  };
32634
32878
  }
32635
32879
 
@@ -36599,6 +36843,7 @@ import {
36599
36843
  useCache as useCache54
36600
36844
  } from "@7365admin1/node-server-utils";
36601
36845
  import { ObjectId as ObjectId98 } from "mongodb";
36846
+ var incidents_namespace_collection = "incident-reports";
36602
36847
  function useIncidentReportRepo() {
36603
36848
  const db = useAtlas87.getDb();
36604
36849
  if (!db) {
@@ -36625,18 +36870,21 @@ function useIncidentReportRepo() {
36625
36870
  );
36626
36871
  }
36627
36872
  }
36628
- const namespace_collection = "incident-reports";
36629
- const collection = db.collection(namespace_collection);
36630
- const { delNamespace, getCache, setCache } = useCache54(namespace_collection);
36873
+ const collection = db.collection(incidents_namespace_collection);
36874
+ const { delNamespace, getCache, setCache } = useCache54(
36875
+ incidents_namespace_collection
36876
+ );
36631
36877
  async function add(value, session) {
36632
36878
  try {
36633
36879
  value = MIncidentReport(value);
36634
36880
  const res = await collection.insertOne(value, { session });
36635
36881
  delNamespace().then(() => {
36636
- logger140.info(`Cache cleared for namespace: ${namespace_collection}`);
36882
+ logger140.info(
36883
+ `Cache cleared for namespace: ${incidents_namespace_collection}`
36884
+ );
36637
36885
  }).catch((err) => {
36638
36886
  logger140.error(
36639
- `Failed to clear cache for namespace: ${namespace_collection}`,
36887
+ `Failed to clear cache for namespace: ${incidents_namespace_collection}`,
36640
36888
  err
36641
36889
  );
36642
36890
  });
@@ -36722,7 +36970,7 @@ function useIncidentReportRepo() {
36722
36970
  if (search) {
36723
36971
  cacheOptions.search = search;
36724
36972
  }
36725
- const cacheKey = makeCacheKey52(namespace_collection, cacheOptions);
36973
+ const cacheKey = makeCacheKey52(incidents_namespace_collection, cacheOptions);
36726
36974
  const cachedData = await getCache(cacheKey);
36727
36975
  if (cachedData) {
36728
36976
  logger140.info(`Cache hit for key: ${cacheKey}`);
@@ -36835,7 +37083,7 @@ function useIncidentReportRepo() {
36835
37083
  } catch (error) {
36836
37084
  throw new BadRequestError161("Invalid incident report ID format.");
36837
37085
  }
36838
- const cacheKey = makeCacheKey52(namespace_collection, { _id });
37086
+ const cacheKey = makeCacheKey52(incidents_namespace_collection, { _id });
36839
37087
  const cachedData = await getCache(cacheKey);
36840
37088
  if (cachedData) {
36841
37089
  logger140.info(`Cache hit for key: ${cacheKey}`);
@@ -36909,10 +37157,12 @@ function useIncidentReportRepo() {
36909
37157
  );
36910
37158
  }
36911
37159
  delNamespace().then(() => {
36912
- logger140.info(`Cache cleared for namespace: ${namespace_collection}`);
37160
+ logger140.info(
37161
+ `Cache cleared for namespace: ${incidents_namespace_collection}`
37162
+ );
36913
37163
  }).catch((err) => {
36914
37164
  logger140.error(
36915
- `Failed to clear cache for namespace: ${namespace_collection}`,
37165
+ `Failed to clear cache for namespace: ${incidents_namespace_collection}`,
36916
37166
  err
36917
37167
  );
36918
37168
  });
@@ -36938,10 +37188,12 @@ function useIncidentReportRepo() {
36938
37188
  throw new InternalServerError55("Unable to delete occurrence subject.");
36939
37189
  }
36940
37190
  delNamespace().then(() => {
36941
- logger140.info(`Cache cleared for namespace: ${namespace_collection}`);
37191
+ logger140.info(
37192
+ `Cache cleared for namespace: ${incidents_namespace_collection}`
37193
+ );
36942
37194
  }).catch((err) => {
36943
37195
  logger140.error(
36944
- `Failed to clear cache for namespace: ${namespace_collection}`,
37196
+ `Failed to clear cache for namespace: ${incidents_namespace_collection}`,
36945
37197
  err
36946
37198
  );
36947
37199
  });
@@ -36969,10 +37221,12 @@ function useIncidentReportRepo() {
36969
37221
  );
36970
37222
  }
36971
37223
  delNamespace().then(() => {
36972
- logger140.info(`Cache cleared for namespace: ${namespace_collection}`);
37224
+ logger140.info(
37225
+ `Cache cleared for namespace: ${incidents_namespace_collection}`
37226
+ );
36973
37227
  }).catch((err) => {
36974
37228
  logger140.error(
36975
- `Failed to clear cache for namespace: ${namespace_collection}`,
37229
+ `Failed to clear cache for namespace: ${incidents_namespace_collection}`,
36976
37230
  err
36977
37231
  );
36978
37232
  });
@@ -39397,6 +39651,1659 @@ function useNfcPatrolLogController() {
39397
39651
  getAllBySite
39398
39652
  };
39399
39653
  }
39654
+
39655
+ // src/repositories/new-dashboard.repo.ts
39656
+ import {
39657
+ BadRequestError as BadRequestError177,
39658
+ InternalServerError as InternalServerError60,
39659
+ logger as logger155,
39660
+ makeCacheKey as makeCacheKey57,
39661
+ toObjectId as toObjectId8,
39662
+ useAtlas as useAtlas97,
39663
+ useCache as useCache59
39664
+ } from "@7365admin1/node-server-utils";
39665
+ var Period = /* @__PURE__ */ ((Period2) => {
39666
+ Period2["TODAY"] = "today";
39667
+ Period2["THIS_WEEK"] = "thisWeek";
39668
+ Period2["THIS_MONTH"] = "thisMonth";
39669
+ return Period2;
39670
+ })(Period || {});
39671
+ var securityDashboardCollection = "security-dashboard";
39672
+ var PMDashboardCollection = "PM-dashboard";
39673
+ var pestDashboardCollection = "pest-dashboard";
39674
+ var poolDashboardCollection = "pool-dashboard";
39675
+ var mAndEDashboardCollection = "M&E-dashboard";
39676
+ var landscapeDashboardCollection = "landscape-dashboard";
39677
+ function getPeriodRangeWithPrevious(period) {
39678
+ const now = /* @__PURE__ */ new Date();
39679
+ let currentStart = /* @__PURE__ */ new Date();
39680
+ let currentEnd = /* @__PURE__ */ new Date();
39681
+ let previousStart = /* @__PURE__ */ new Date();
39682
+ let previousEnd = /* @__PURE__ */ new Date();
39683
+ if (period === "today" /* TODAY */) {
39684
+ currentStart.setHours(0, 0, 0, 0);
39685
+ currentEnd.setHours(23, 59, 59, 999);
39686
+ previousStart = new Date(currentStart);
39687
+ previousStart.setDate(previousStart.getDate() - 1);
39688
+ previousEnd = new Date(currentEnd);
39689
+ previousEnd.setDate(previousEnd.getDate() - 1);
39690
+ } else if (period === "thisWeek" /* THIS_WEEK */) {
39691
+ const day = now.getDay();
39692
+ const diffToMonday = day === 0 ? -6 : 1 - day;
39693
+ currentStart = new Date(now);
39694
+ currentStart.setDate(now.getDate() + diffToMonday);
39695
+ currentStart.setHours(0, 0, 0, 0);
39696
+ currentEnd = new Date(currentStart);
39697
+ currentEnd.setDate(currentStart.getDate() + 6);
39698
+ currentEnd.setHours(23, 59, 59, 999);
39699
+ previousStart = new Date(currentStart);
39700
+ previousStart.setDate(previousStart.getDate() - 7);
39701
+ previousEnd = new Date(currentEnd);
39702
+ previousEnd.setDate(previousEnd.getDate() - 7);
39703
+ } else if (period === "thisMonth" /* THIS_MONTH */) {
39704
+ currentStart = new Date(now.getFullYear(), now.getMonth(), 1);
39705
+ currentEnd = new Date(
39706
+ now.getFullYear(),
39707
+ now.getMonth() + 1,
39708
+ 0,
39709
+ 23,
39710
+ 59,
39711
+ 59,
39712
+ 999
39713
+ );
39714
+ previousStart = new Date(now.getFullYear(), now.getMonth() - 1, 1);
39715
+ previousEnd = new Date(
39716
+ now.getFullYear(),
39717
+ now.getMonth(),
39718
+ 0,
39719
+ 23,
39720
+ 59,
39721
+ 59,
39722
+ 999
39723
+ );
39724
+ } else {
39725
+ throw new BadRequestError177("Invalid period.");
39726
+ }
39727
+ return {
39728
+ current: {
39729
+ start: currentStart.toISOString(),
39730
+ end: currentEnd.toISOString()
39731
+ },
39732
+ previous: {
39733
+ start: previousStart.toISOString(),
39734
+ end: previousEnd.toISOString()
39735
+ }
39736
+ };
39737
+ }
39738
+ function calculatePercentage(current, previous) {
39739
+ if (previous === 0) {
39740
+ return current === 0 ? 0 : 100;
39741
+ }
39742
+ return Number(((current - previous) / previous * 100).toFixed(2));
39743
+ }
39744
+ function useNewDashboardRepo() {
39745
+ const db = useAtlas97.getDb();
39746
+ if (!db) {
39747
+ throw new InternalServerError60("Unable to connect to server.");
39748
+ }
39749
+ const { delNamespace, getCache, setCache } = useCache59(
39750
+ securityDashboardCollection
39751
+ );
39752
+ async function getMetric(collectionString, siteId, period) {
39753
+ const site = toObjectId8(siteId);
39754
+ const range = getPeriodRangeWithPrevious(period);
39755
+ const collection = db.collection(collectionString);
39756
+ const current = await collection.countDocuments({
39757
+ site,
39758
+ createdAt: {
39759
+ $gte: range.current.start,
39760
+ $lte: range.current.end
39761
+ }
39762
+ });
39763
+ const previous = await collection.countDocuments({
39764
+ site,
39765
+ createdAt: {
39766
+ $gte: range.previous.start,
39767
+ $lte: range.previous.end
39768
+ }
39769
+ });
39770
+ return {
39771
+ count: current,
39772
+ percentage: calculatePercentage(current, previous)
39773
+ };
39774
+ }
39775
+ async function getSecurityDashboard({
39776
+ siteId = "",
39777
+ feedback = "today" /* TODAY */,
39778
+ workOrder = "today" /* TODAY */,
39779
+ vehicle = "today" /* TODAY */,
39780
+ building = "today" /* TODAY */,
39781
+ visitor = "today" /* TODAY */,
39782
+ incident = "today" /* TODAY */,
39783
+ guest = "today" /* TODAY */
39784
+ }) {
39785
+ const cacheOptions = {
39786
+ siteId,
39787
+ feedback,
39788
+ workOrder,
39789
+ vehicle,
39790
+ building,
39791
+ visitor,
39792
+ incident
39793
+ };
39794
+ const cacheKey = makeCacheKey57(securityDashboardCollection, cacheOptions);
39795
+ const cachedData = await getCache(cacheKey);
39796
+ if (cachedData) {
39797
+ logger155.info(`Cache hit for key: ${cacheKey}`);
39798
+ return cachedData;
39799
+ }
39800
+ const feedbacks = await getMetric(
39801
+ feedbacks_namespace_collection,
39802
+ siteId,
39803
+ feedback
39804
+ );
39805
+ const workOrders = await getMetric(
39806
+ work_orders_namespace_collection,
39807
+ siteId,
39808
+ workOrder
39809
+ );
39810
+ const vehicles = await getMetric(
39811
+ vehicles_namespace_collection,
39812
+ siteId,
39813
+ vehicle
39814
+ );
39815
+ const buildings = await getMetric(
39816
+ buildings_namespace_collection,
39817
+ siteId,
39818
+ building
39819
+ );
39820
+ const visitors = await getMetric(
39821
+ visitors_namespace_collection,
39822
+ siteId,
39823
+ visitor
39824
+ );
39825
+ const incidents = await getMetric(
39826
+ incidents_namespace_collection,
39827
+ siteId,
39828
+ incident
39829
+ );
39830
+ const guests = await getMetric(guests_namespace_collection, siteId, guest);
39831
+ const data = {
39832
+ feedbacks,
39833
+ workOrders,
39834
+ vehicles,
39835
+ buildings,
39836
+ visitors,
39837
+ incidents,
39838
+ guests
39839
+ };
39840
+ setCache(cacheKey, data, 15 * 60).then(() => {
39841
+ logger155.info(`Cache set for key: ${cacheKey}`);
39842
+ }).catch((err) => {
39843
+ logger155.error(`Failed to set cache for key: ${cacheKey}`, err);
39844
+ });
39845
+ return data;
39846
+ }
39847
+ async function getPropertyManagementDashboard({
39848
+ siteId = "",
39849
+ feedback = "today" /* TODAY */,
39850
+ workOrder = "today" /* TODAY */,
39851
+ sitePeople = "today" /* TODAY */,
39852
+ facilityBooking = "today" /* TODAY */,
39853
+ bulletinBoard = "today" /* TODAY */,
39854
+ event = "today" /* TODAY */,
39855
+ vehicle = "today" /* TODAY */,
39856
+ building = "today" /* TODAY */,
39857
+ visitor = "today" /* TODAY */,
39858
+ incident = "today" /* TODAY */
39859
+ }) {
39860
+ const cacheOptions = {
39861
+ siteId,
39862
+ feedback,
39863
+ workOrder,
39864
+ sitePeople,
39865
+ facilityBooking,
39866
+ bulletinBoard,
39867
+ event,
39868
+ vehicle,
39869
+ building,
39870
+ visitor,
39871
+ incident
39872
+ };
39873
+ const cacheKey = makeCacheKey57(PMDashboardCollection, cacheOptions);
39874
+ const cachedData = await getCache(cacheKey);
39875
+ if (cachedData) {
39876
+ logger155.info(`Cache hit for key: ${cacheKey}`);
39877
+ return cachedData;
39878
+ }
39879
+ const feedbacks = await getMetric(
39880
+ feedbacks_namespace_collection,
39881
+ siteId,
39882
+ feedback
39883
+ );
39884
+ const workOrders = await getMetric(
39885
+ work_orders_namespace_collection,
39886
+ siteId,
39887
+ workOrder
39888
+ );
39889
+ const vehicles = await getMetric(
39890
+ vehicles_namespace_collection,
39891
+ siteId,
39892
+ vehicle
39893
+ );
39894
+ const buildings = await getMetric(
39895
+ buildings_namespace_collection,
39896
+ siteId,
39897
+ building
39898
+ );
39899
+ const visitors = await getMetric(
39900
+ visitors_namespace_collection,
39901
+ siteId,
39902
+ visitor
39903
+ );
39904
+ const incidents = await getMetric(
39905
+ incidents_namespace_collection,
39906
+ siteId,
39907
+ incident
39908
+ );
39909
+ const _sitePeople = await getMetric(
39910
+ site_people_namespace_collection,
39911
+ siteId,
39912
+ sitePeople
39913
+ );
39914
+ const bulletinBoards = await getMetric(
39915
+ bulletin_boards_namespace_collection,
39916
+ siteId,
39917
+ bulletinBoard
39918
+ );
39919
+ const events = await getMetric(events_namespace_collection, siteId, event);
39920
+ const facilityBookings = await getMetric(
39921
+ facility_bookings_namespace_collection,
39922
+ siteId,
39923
+ facilityBooking
39924
+ );
39925
+ const data = {
39926
+ feedbacks,
39927
+ workOrders,
39928
+ vehicles,
39929
+ buildings,
39930
+ visitors,
39931
+ incidents,
39932
+ sitePeople: _sitePeople,
39933
+ bulletinBoards,
39934
+ events,
39935
+ facilityBookings
39936
+ };
39937
+ setCache(cacheKey, data, 15 * 60).then(() => {
39938
+ logger155.info(`Cache set for key: ${cacheKey}`);
39939
+ }).catch((err) => {
39940
+ logger155.error(`Failed to set cache for key: ${cacheKey}`, err);
39941
+ });
39942
+ return data;
39943
+ }
39944
+ async function getPestManagementDashboard({
39945
+ siteId = "",
39946
+ feedback = "today" /* TODAY */,
39947
+ workOrder = "today" /* TODAY */
39948
+ }) {
39949
+ const cacheOptions = {
39950
+ siteId,
39951
+ feedback,
39952
+ workOrder
39953
+ };
39954
+ const cacheKey = makeCacheKey57(pestDashboardCollection, cacheOptions);
39955
+ const cachedData = await getCache(cacheKey);
39956
+ if (cachedData) {
39957
+ logger155.info(`Cache hit for key: ${cacheKey}`);
39958
+ return cachedData;
39959
+ }
39960
+ const feedbacks = await getMetric(
39961
+ feedbacks_namespace_collection,
39962
+ siteId,
39963
+ feedback
39964
+ );
39965
+ const workOrders = await getMetric(
39966
+ work_orders_namespace_collection,
39967
+ siteId,
39968
+ workOrder
39969
+ );
39970
+ const data = {
39971
+ feedbacks,
39972
+ workOrders
39973
+ };
39974
+ setCache(cacheKey, data, 15 * 60).then(() => {
39975
+ logger155.info(`Cache set for key: ${cacheKey}`);
39976
+ }).catch((err) => {
39977
+ logger155.error(`Failed to set cache for key: ${cacheKey}`, err);
39978
+ });
39979
+ return data;
39980
+ }
39981
+ async function getPoolManagementDashboard({
39982
+ siteId = "",
39983
+ feedback = "today" /* TODAY */,
39984
+ workOrder = "today" /* TODAY */
39985
+ }) {
39986
+ const cacheOptions = {
39987
+ siteId,
39988
+ feedback,
39989
+ workOrder
39990
+ };
39991
+ const cacheKey = makeCacheKey57(poolDashboardCollection, cacheOptions);
39992
+ const cachedData = await getCache(cacheKey);
39993
+ if (cachedData) {
39994
+ logger155.info(`Cache hit for key: ${cacheKey}`);
39995
+ return cachedData;
39996
+ }
39997
+ const feedbacks = await getMetric(
39998
+ feedbacks_namespace_collection,
39999
+ siteId,
40000
+ feedback
40001
+ );
40002
+ const workOrders = await getMetric(
40003
+ work_orders_namespace_collection,
40004
+ siteId,
40005
+ workOrder
40006
+ );
40007
+ const data = {
40008
+ feedbacks,
40009
+ workOrders
40010
+ };
40011
+ setCache(cacheKey, data, 15 * 60).then(() => {
40012
+ logger155.info(`Cache set for key: ${cacheKey}`);
40013
+ }).catch((err) => {
40014
+ logger155.error(`Failed to set cache for key: ${cacheKey}`, err);
40015
+ });
40016
+ return data;
40017
+ }
40018
+ async function getMAndEManagementDashboard({
40019
+ siteId = "",
40020
+ feedback = "today" /* TODAY */,
40021
+ workOrder = "today" /* TODAY */
40022
+ }) {
40023
+ const cacheOptions = {
40024
+ siteId,
40025
+ feedback,
40026
+ workOrder
40027
+ };
40028
+ const cacheKey = makeCacheKey57(mAndEDashboardCollection, cacheOptions);
40029
+ const cachedData = await getCache(cacheKey);
40030
+ if (cachedData) {
40031
+ logger155.info(`Cache hit for key: ${cacheKey}`);
40032
+ return cachedData;
40033
+ }
40034
+ const feedbacks = await getMetric(
40035
+ feedbacks_namespace_collection,
40036
+ siteId,
40037
+ feedback
40038
+ );
40039
+ const workOrders = await getMetric(
40040
+ work_orders_namespace_collection,
40041
+ siteId,
40042
+ workOrder
40043
+ );
40044
+ const data = {
40045
+ feedbacks,
40046
+ workOrders
40047
+ };
40048
+ setCache(cacheKey, data, 15 * 60).then(() => {
40049
+ logger155.info(`Cache set for key: ${cacheKey}`);
40050
+ }).catch((err) => {
40051
+ logger155.error(`Failed to set cache for key: ${cacheKey}`, err);
40052
+ });
40053
+ return data;
40054
+ }
40055
+ async function getLandscapeDashboard({
40056
+ siteId = "",
40057
+ feedback = "today" /* TODAY */,
40058
+ workOrder = "today" /* TODAY */
40059
+ }) {
40060
+ const cacheOptions = {
40061
+ siteId,
40062
+ feedback,
40063
+ workOrder
40064
+ };
40065
+ const cacheKey = makeCacheKey57(landscapeDashboardCollection, cacheOptions);
40066
+ const cachedData = await getCache(cacheKey);
40067
+ if (cachedData) {
40068
+ logger155.info(`Cache hit for key: ${cacheKey}`);
40069
+ return cachedData;
40070
+ }
40071
+ const feedbacks = await getMetric(
40072
+ feedbacks_namespace_collection,
40073
+ siteId,
40074
+ feedback
40075
+ );
40076
+ const workOrders = await getMetric(
40077
+ work_orders_namespace_collection,
40078
+ siteId,
40079
+ workOrder
40080
+ );
40081
+ const data = {
40082
+ feedbacks,
40083
+ workOrders
40084
+ };
40085
+ setCache(cacheKey, data, 15 * 60).then(() => {
40086
+ logger155.info(`Cache set for key: ${cacheKey}`);
40087
+ }).catch((err) => {
40088
+ logger155.error(`Failed to set cache for key: ${cacheKey}`, err);
40089
+ });
40090
+ return data;
40091
+ }
40092
+ return {
40093
+ getSecurityDashboard,
40094
+ getPropertyManagementDashboard,
40095
+ getPestManagementDashboard,
40096
+ getPoolManagementDashboard,
40097
+ getMAndEManagementDashboard,
40098
+ getLandscapeDashboard
40099
+ };
40100
+ }
40101
+
40102
+ // src/controllers/new-dashboard.controller.ts
40103
+ import Joi110 from "joi";
40104
+ import { BadRequestError as BadRequestError178, logger as logger156 } from "@7365admin1/node-server-utils";
40105
+ function useNewDashboardController() {
40106
+ const {
40107
+ getSecurityDashboard: _getSecurityDashboard,
40108
+ getPropertyManagementDashboard: _getPropertyManagementDashboard,
40109
+ getPestManagementDashboard: _getPestManagementDashboard,
40110
+ getPoolManagementDashboard: _getPoolManagementDashboard,
40111
+ getMAndEManagementDashboard: _getMAndEManagementDashboard,
40112
+ getLandscapeDashboard: _getLandscapeDashboard
40113
+ } = useNewDashboardRepo();
40114
+ const periodField = Joi110.string().valid(...Object.values(Period)).default("today" /* TODAY */);
40115
+ async function getSecurityDashboard(req, res, next) {
40116
+ try {
40117
+ const schema2 = Joi110.object({
40118
+ site: Joi110.string().hex().length(24).required(),
40119
+ feedbackPeriod: periodField,
40120
+ workOrderPeriod: periodField,
40121
+ vehiclePeriod: periodField,
40122
+ buildingPeriod: periodField,
40123
+ visitorPeriod: periodField,
40124
+ incidentPeriod: periodField,
40125
+ guestPeriod: periodField
40126
+ });
40127
+ const { error, value } = schema2.validate({
40128
+ site: req.params.site,
40129
+ ...req.query
40130
+ });
40131
+ if (error) {
40132
+ const messages = error.details.map((d) => d.message).join(", ");
40133
+ logger156.log({ level: "error", message: messages });
40134
+ next(new BadRequestError178(messages));
40135
+ return;
40136
+ }
40137
+ const {
40138
+ site,
40139
+ feedbackPeriod,
40140
+ workOrderPeriod,
40141
+ vehiclePeriod,
40142
+ buildingPeriod,
40143
+ visitorPeriod,
40144
+ incidentPeriod,
40145
+ guestPeriod
40146
+ } = value;
40147
+ const data = await _getSecurityDashboard({
40148
+ siteId: site,
40149
+ feedback: feedbackPeriod,
40150
+ workOrder: workOrderPeriod,
40151
+ vehicle: vehiclePeriod,
40152
+ building: buildingPeriod,
40153
+ visitor: visitorPeriod,
40154
+ incident: incidentPeriod,
40155
+ guest: guestPeriod
40156
+ });
40157
+ res.status(200).json(data);
40158
+ return;
40159
+ } catch (error) {
40160
+ logger156.log({ level: "error", message: error.message });
40161
+ next(error);
40162
+ return;
40163
+ }
40164
+ }
40165
+ async function getPropertyManagementDashboard(req, res, next) {
40166
+ try {
40167
+ const schema2 = Joi110.object({
40168
+ site: Joi110.string().hex().length(24).required(),
40169
+ feedbackPeriod: periodField,
40170
+ workOrderPeriod: periodField,
40171
+ vehiclePeriod: periodField,
40172
+ buildingPeriod: periodField,
40173
+ visitorPeriod: periodField,
40174
+ incidentPeriod: periodField,
40175
+ sitePeoplePeriod: periodField,
40176
+ bulletinBoardPeriod: periodField,
40177
+ eventPeriod: periodField,
40178
+ facilityBookingPeriod: periodField
40179
+ });
40180
+ const { error, value } = schema2.validate({
40181
+ site: req.params.site,
40182
+ ...req.query
40183
+ });
40184
+ if (error) {
40185
+ const messages = error.details.map((d) => d.message).join(", ");
40186
+ logger156.log({ level: "error", message: messages });
40187
+ next(new BadRequestError178(messages));
40188
+ return;
40189
+ }
40190
+ const {
40191
+ site,
40192
+ feedbackPeriod,
40193
+ workOrderPeriod,
40194
+ vehiclePeriod,
40195
+ buildingPeriod,
40196
+ visitorPeriod,
40197
+ incidentPeriod,
40198
+ sitePeoplePeriod,
40199
+ bulletinBoardPeriod,
40200
+ eventPeriod,
40201
+ facilityBookingPeriod
40202
+ } = value;
40203
+ const data = await _getPropertyManagementDashboard({
40204
+ siteId: site,
40205
+ feedback: feedbackPeriod,
40206
+ workOrder: workOrderPeriod,
40207
+ vehicle: vehiclePeriod,
40208
+ building: buildingPeriod,
40209
+ visitor: visitorPeriod,
40210
+ incident: incidentPeriod,
40211
+ sitePeople: sitePeoplePeriod,
40212
+ bulletinBoard: bulletinBoardPeriod,
40213
+ event: eventPeriod,
40214
+ facilityBooking: facilityBookingPeriod
40215
+ });
40216
+ res.status(200).json(data);
40217
+ return;
40218
+ } catch (error) {
40219
+ logger156.log({ level: "error", message: error.message });
40220
+ next(error);
40221
+ return;
40222
+ }
40223
+ }
40224
+ async function getPestManagementDashboard(req, res, next) {
40225
+ try {
40226
+ const schema2 = Joi110.object({
40227
+ site: Joi110.string().hex().length(24).required(),
40228
+ feedbackPeriod: periodField,
40229
+ workOrderPeriod: periodField
40230
+ });
40231
+ const { error, value } = schema2.validate({
40232
+ site: req.params.site,
40233
+ ...req.query
40234
+ });
40235
+ if (error) {
40236
+ const messages = error.details.map((d) => d.message).join(", ");
40237
+ logger156.log({ level: "error", message: messages });
40238
+ next(new BadRequestError178(messages));
40239
+ return;
40240
+ }
40241
+ const { site, feedbackPeriod, workOrderPeriod } = value;
40242
+ const data = await _getPestManagementDashboard({
40243
+ siteId: site,
40244
+ feedback: feedbackPeriod,
40245
+ workOrder: workOrderPeriod
40246
+ });
40247
+ res.status(200).json(data);
40248
+ return;
40249
+ } catch (error) {
40250
+ logger156.log({ level: "error", message: error.message });
40251
+ next(error);
40252
+ return;
40253
+ }
40254
+ }
40255
+ async function getPoolManagementDashboard(req, res, next) {
40256
+ try {
40257
+ const schema2 = Joi110.object({
40258
+ site: Joi110.string().hex().length(24).required(),
40259
+ feedbackPeriod: periodField,
40260
+ workOrderPeriod: periodField
40261
+ });
40262
+ const { error, value } = schema2.validate({
40263
+ site: req.params.site,
40264
+ ...req.query
40265
+ });
40266
+ if (error) {
40267
+ const messages = error.details.map((d) => d.message).join(", ");
40268
+ logger156.log({ level: "error", message: messages });
40269
+ next(new BadRequestError178(messages));
40270
+ return;
40271
+ }
40272
+ const { site, feedbackPeriod, workOrderPeriod } = value;
40273
+ const data = await _getPestManagementDashboard({
40274
+ siteId: site,
40275
+ feedback: feedbackPeriod,
40276
+ workOrder: workOrderPeriod
40277
+ });
40278
+ res.status(200).json(data);
40279
+ return;
40280
+ } catch (error) {
40281
+ logger156.log({ level: "error", message: error.message });
40282
+ next(error);
40283
+ return;
40284
+ }
40285
+ }
40286
+ async function getMAndEManagementDashboard(req, res, next) {
40287
+ try {
40288
+ const schema2 = Joi110.object({
40289
+ site: Joi110.string().hex().length(24).required(),
40290
+ feedbackPeriod: periodField,
40291
+ workOrderPeriod: periodField
40292
+ });
40293
+ const { error, value } = schema2.validate({
40294
+ site: req.params.site,
40295
+ ...req.query
40296
+ });
40297
+ if (error) {
40298
+ const messages = error.details.map((d) => d.message).join(", ");
40299
+ logger156.log({ level: "error", message: messages });
40300
+ next(new BadRequestError178(messages));
40301
+ return;
40302
+ }
40303
+ const { site, feedbackPeriod, workOrderPeriod } = value;
40304
+ const data = await _getMAndEManagementDashboard({
40305
+ siteId: site,
40306
+ feedback: feedbackPeriod,
40307
+ workOrder: workOrderPeriod
40308
+ });
40309
+ res.status(200).json(data);
40310
+ return;
40311
+ } catch (error) {
40312
+ logger156.log({ level: "error", message: error.message });
40313
+ next(error);
40314
+ return;
40315
+ }
40316
+ }
40317
+ async function getLandscapeDashboard(req, res, next) {
40318
+ try {
40319
+ const schema2 = Joi110.object({
40320
+ site: Joi110.string().hex().length(24).required(),
40321
+ feedbackPeriod: periodField,
40322
+ workOrderPeriod: periodField
40323
+ });
40324
+ const { error, value } = schema2.validate({
40325
+ site: req.params.site,
40326
+ ...req.query
40327
+ });
40328
+ if (error) {
40329
+ const messages = error.details.map((d) => d.message).join(", ");
40330
+ logger156.log({ level: "error", message: messages });
40331
+ next(new BadRequestError178(messages));
40332
+ return;
40333
+ }
40334
+ const { site, feedbackPeriod, workOrderPeriod } = value;
40335
+ const data = await _getLandscapeDashboard({
40336
+ siteId: site,
40337
+ feedback: feedbackPeriod,
40338
+ workOrder: workOrderPeriod
40339
+ });
40340
+ res.status(200).json(data);
40341
+ return;
40342
+ } catch (error) {
40343
+ logger156.log({ level: "error", message: error.message });
40344
+ next(error);
40345
+ return;
40346
+ }
40347
+ }
40348
+ return {
40349
+ getSecurityDashboard,
40350
+ getPropertyManagementDashboard,
40351
+ getPestManagementDashboard,
40352
+ getPoolManagementDashboard,
40353
+ getMAndEManagementDashboard,
40354
+ getLandscapeDashboard
40355
+ };
40356
+ }
40357
+
40358
+ // src/models/manpower-monitoring.model.ts
40359
+ import Joi111 from "joi";
40360
+ import { ObjectId as ObjectId107 } from "mongodb";
40361
+ var shiftSchema = Joi111.object({
40362
+ name: Joi111.string().required(),
40363
+ checkIn: Joi111.string().optional().allow("", null),
40364
+ checkOut: Joi111.string().optional().allow("", null),
40365
+ lateCheckInAlert: Joi111.string().optional().allow("", null),
40366
+ alertFrequencyMins: Joi111.number().optional().allow("", null),
40367
+ earlyOutAlert: Joi111.boolean().optional()
40368
+ });
40369
+ var manpowerMonitoringSchema = Joi111.object({
40370
+ siteId: Joi111.string().hex().required(),
40371
+ siteName: Joi111.string().required(),
40372
+ shiftType: Joi111.string().optional().allow("", null),
40373
+ enabled: Joi111.boolean().required(),
40374
+ shifts: Joi111.object({
40375
+ "2-shifts": Joi111.array().items(shiftSchema).optional(),
40376
+ "3-shifts": Joi111.array().items(shiftSchema).optional()
40377
+ }).optional(),
40378
+ createdBy: Joi111.string().hex().required(),
40379
+ createdByName: Joi111.string().optional().allow("", null),
40380
+ emails: Joi111.array().items(Joi111.string().email()).optional(),
40381
+ serviceProviderId: Joi111.string().hex().optional()
40382
+ });
40383
+ var MManpowerMonitoring = class {
40384
+ constructor(data) {
40385
+ this._id = new ObjectId107();
40386
+ this.serviceProviderId = data.serviceProviderId || "";
40387
+ this.siteId = data.siteId || "";
40388
+ this.siteName = data.siteName;
40389
+ this.shiftType = data.shiftType;
40390
+ this.enabled = data.enabled;
40391
+ this.shifts = data.shifts;
40392
+ this.createdBy = data.createdBy || "";
40393
+ this.createdByName = data.createdByName || "";
40394
+ this.createdAt = /* @__PURE__ */ new Date();
40395
+ this.updatedAt = data.updatedAt || "";
40396
+ this.emails = data.emails || [];
40397
+ }
40398
+ };
40399
+
40400
+ // src/repositories/manpower-monitoring.repo.ts
40401
+ import {
40402
+ BadRequestError as BadRequestError179,
40403
+ paginate as paginate49,
40404
+ useAtlas as useAtlas98
40405
+ } from "@7365admin1/node-server-utils";
40406
+
40407
+ // src/utils/hrmlabs-attendance.util.ts
40408
+ import axios2 from "axios";
40409
+ async function hrmLabsAuthentication({
40410
+ authUrl,
40411
+ username,
40412
+ password,
40413
+ domain
40414
+ }) {
40415
+ const res = await axios2.post(
40416
+ authUrl,
40417
+ {
40418
+ grant_type: "password",
40419
+ username,
40420
+ password,
40421
+ domain,
40422
+ showPassword: false
40423
+ },
40424
+ {
40425
+ headers: { "Content-Type": "application/json" }
40426
+ }
40427
+ );
40428
+ if (res.data?.success && res.data.data?.token) {
40429
+ return res.data.data.token;
40430
+ }
40431
+ throw new Error(
40432
+ "HRMLabs Authentication failed. Please check your credentials."
40433
+ );
40434
+ }
40435
+ function sleep(ms) {
40436
+ return new Promise((resolve) => setTimeout(resolve, ms));
40437
+ }
40438
+ async function fetchSites({ siteUrl, token }) {
40439
+ const maxRetries = 3;
40440
+ let attempt = 0;
40441
+ let lastError;
40442
+ do {
40443
+ try {
40444
+ attempt++;
40445
+ const res = await axios2.get(siteUrl, {
40446
+ headers: { Authorization: `Bearer ${token}` },
40447
+ timeout: 15e3
40448
+ });
40449
+ if (res.status !== 200) {
40450
+ throw new Error(`Unexpected status: ${res.status}`);
40451
+ }
40452
+ return res.data.data.locations[0] || [];
40453
+ } catch (err) {
40454
+ const error = err;
40455
+ lastError = error;
40456
+ const status = error.response?.status;
40457
+ if (status && status >= 400 && status < 500 && status !== 429) {
40458
+ throw error;
40459
+ }
40460
+ if (attempt < maxRetries) {
40461
+ const delay = 1e3 * attempt;
40462
+ await sleep(delay);
40463
+ }
40464
+ }
40465
+ } while (attempt < maxRetries);
40466
+ throw lastError;
40467
+ }
40468
+ var hrmlabs_attendance_util_default = {
40469
+ hrmLabsAuthentication,
40470
+ fetchSites
40471
+ };
40472
+
40473
+ // src/repositories/manpower-monitoring.repo.ts
40474
+ import { ObjectId as ObjectId108 } from "mongodb";
40475
+ var { hrmLabsAuthentication: hrmLabsAuthentication2, fetchSites: fetchSites2 } = hrmlabs_attendance_util_default;
40476
+ function useManpowerMonitoringRepo() {
40477
+ const db = useAtlas98.getDb();
40478
+ if (!db) {
40479
+ throw new Error("Unable to connect to server.");
40480
+ }
40481
+ const namespace_collection = "manpower-monitoring";
40482
+ const collection = db.collection(namespace_collection);
40483
+ const serviceProviderCollection = db.collection("site.service-providers");
40484
+ async function createManpowerMonitoringSettings(value, session) {
40485
+ try {
40486
+ value = new MManpowerMonitoring(value);
40487
+ if (value.createdBy)
40488
+ value.createdBy = new ObjectId108(value.createdBy);
40489
+ if (value.siteId)
40490
+ value.siteId = new ObjectId108(value.siteId);
40491
+ if (value.serviceProviderId)
40492
+ value.serviceProviderId = new ObjectId108(value.serviceProviderId);
40493
+ const result = await collection.insertOne(value, { session });
40494
+ return result;
40495
+ } catch (error) {
40496
+ throw new Error(error.message || error || "Server Internal Error");
40497
+ }
40498
+ }
40499
+ async function getAllManpowerSettings({
40500
+ page = 1,
40501
+ limit = 10,
40502
+ search
40503
+ }) {
40504
+ try {
40505
+ page = page ? page - 1 : 0;
40506
+ limit = limit || 10;
40507
+ const searchQuery = {};
40508
+ if (search) {
40509
+ searchQuery.siteName = { $regex: search, $options: "i" };
40510
+ }
40511
+ const result = await collection.aggregate([
40512
+ { $match: searchQuery },
40513
+ {
40514
+ $facet: {
40515
+ totalCount: [{ $count: "count" }],
40516
+ items: [
40517
+ { $sort: { _id: -1 } },
40518
+ { $skip: page * limit },
40519
+ { $limit: limit }
40520
+ ]
40521
+ }
40522
+ }
40523
+ ]).toArray();
40524
+ const total = result[0].totalCount[0]?.count || 0;
40525
+ const items = result[0].items;
40526
+ return paginate49(items, page, limit, total);
40527
+ } catch (error) {
40528
+ throw new Error(error.message || "Server Internal Error");
40529
+ }
40530
+ }
40531
+ async function getManpowerSettingsBySiteId(_id, serviceProviderId) {
40532
+ try {
40533
+ _id = new ObjectId108(_id);
40534
+ serviceProviderId = new ObjectId108(serviceProviderId);
40535
+ } catch (error) {
40536
+ throw new Error("Invalid Site ID format.");
40537
+ }
40538
+ try {
40539
+ const data = await collection.findOne({
40540
+ siteId: _id,
40541
+ serviceProviderId
40542
+ });
40543
+ return data;
40544
+ } catch (error) {
40545
+ throw error;
40546
+ }
40547
+ }
40548
+ async function updateManpowerMonitoringSettings(_id, value) {
40549
+ try {
40550
+ _id = new ObjectId108(_id);
40551
+ } catch (error) {
40552
+ throw new BadRequestError179("Invalid ID format.");
40553
+ }
40554
+ try {
40555
+ const updateValue = {
40556
+ ...value,
40557
+ updatedAt: /* @__PURE__ */ new Date()
40558
+ };
40559
+ const res = await collection.updateOne({ _id }, { $set: updateValue });
40560
+ if (res.modifiedCount === 0) {
40561
+ throw new Error("Unable to update manpower monitoring settings.");
40562
+ }
40563
+ return res.modifiedCount;
40564
+ } catch (error) {
40565
+ throw error;
40566
+ }
40567
+ }
40568
+ async function multipleManpowerMonitoringSettings(value) {
40569
+ try {
40570
+ const results = {
40571
+ updated: 0,
40572
+ inserted: 0
40573
+ };
40574
+ for (let item of value) {
40575
+ item = new MManpowerMonitoring(item);
40576
+ const data = await collection.findOne({
40577
+ siteId: new ObjectId108(item.siteId)
40578
+ });
40579
+ if (data) {
40580
+ let updateValue;
40581
+ if (item.shiftType == "2-shifts") {
40582
+ updateValue = {
40583
+ shiftType: item.shiftType,
40584
+ "shifts.2-shifts": item.shifts["2-shifts"]
40585
+ };
40586
+ }
40587
+ if (item.shiftType == "3-shifts") {
40588
+ updateValue = {
40589
+ shiftType: item.shiftType,
40590
+ "shifts.3-shifts": item.shifts["3-shifts"]
40591
+ };
40592
+ }
40593
+ const res = await collection.updateOne(
40594
+ { _id: data._id },
40595
+ { $set: updateValue }
40596
+ );
40597
+ if (res.modifiedCount > 0) {
40598
+ results.updated++;
40599
+ }
40600
+ } else {
40601
+ if (item.createdBy)
40602
+ item.createdBy = new ObjectId108(item.createdBy);
40603
+ if (item.siteId)
40604
+ item.siteId = new ObjectId108(item.siteId);
40605
+ if (item.serviceProviderId)
40606
+ item.serviceProviderId = new ObjectId108(item.serviceProviderId);
40607
+ const result = await collection.insertOne(item);
40608
+ if (result.insertedId) {
40609
+ results.inserted++;
40610
+ }
40611
+ }
40612
+ }
40613
+ return {
40614
+ success: true,
40615
+ message: `Processed ${value.length} items.`,
40616
+ ...results
40617
+ };
40618
+ } catch (error) {
40619
+ throw new Error(error.message || error || "Server Internal Error");
40620
+ }
40621
+ }
40622
+ async function getAllSites(serviceProviderId) {
40623
+ const username = process.env.HRMLABS_USERNAME;
40624
+ const domain = process.env.HRMLABS_DOMAIN;
40625
+ const password = process.env.HRMLABS_PASSWORD;
40626
+ const authUrl = process.env.HRMLABS_AUTH_URL;
40627
+ const siteUrl = process.env.HRMLABS_SITE_URL;
40628
+ try {
40629
+ const serviceProvider = await serviceProviderCollection.findOne({
40630
+ _id: new ObjectId108(serviceProviderId)
40631
+ });
40632
+ if (!serviceProvider) {
40633
+ throw new Error("Service Provider not found.");
40634
+ }
40635
+ const hasDomain = serviceProvider.name.toLowerCase().includes(domain?.toLowerCase());
40636
+ if (!hasDomain) {
40637
+ return [];
40638
+ }
40639
+ const token = await hrmLabsAuthentication2({
40640
+ authUrl,
40641
+ username,
40642
+ password,
40643
+ domain
40644
+ });
40645
+ const sites = await fetchSites2({ siteUrl, token });
40646
+ if (!sites) {
40647
+ throw new Error("Failed to fetch sites from HRMLabs.");
40648
+ }
40649
+ return sites.children;
40650
+ } catch (error) {
40651
+ throw new Error(error.message || "Server Internal Error");
40652
+ }
40653
+ }
40654
+ return {
40655
+ createManpowerMonitoringSettings,
40656
+ getAllManpowerSettings,
40657
+ getManpowerSettingsBySiteId,
40658
+ updateManpowerMonitoringSettings,
40659
+ multipleManpowerMonitoringSettings,
40660
+ getAllSites
40661
+ };
40662
+ }
40663
+
40664
+ // src/services/manpower-monitoring.service.ts
40665
+ import {
40666
+ BadRequestError as BadRequestError180,
40667
+ logger as logger158,
40668
+ useAtlas as useAtlas99
40669
+ } from "@7365admin1/node-server-utils";
40670
+ import moment from "moment-timezone";
40671
+ function useManpowerMonitoringSrvc() {
40672
+ const {
40673
+ createManpowerMonitoringSettings: _createManpowerMonitoringSettings
40674
+ } = useManpowerMonitoringRepo();
40675
+ async function createManpowerMonitoringSettings(payload) {
40676
+ console.log("Im here now at service");
40677
+ const session = useAtlas99.getClient()?.startSession();
40678
+ if (!session) {
40679
+ throw new BadRequestError180("Database session not available.");
40680
+ }
40681
+ await session.startTransaction();
40682
+ const morningCheckInTime = payload?.shifts?.[payload.shiftType][0]?.checkIn;
40683
+ const afternoonCheckInTime = payload.shiftType == "3-shifts" ? payload?.shifts?.[payload.shiftType][1]?.checkIn : null;
40684
+ const nightCheckInTime = payload.shiftType == "3-shifts" ? payload?.shifts?.[payload.shiftType][2]?.checkIn : payload?.shifts?.[payload.shiftType][1]?.checkIn;
40685
+ const morningAlertFrequencyMins = payload?.shifts?.[payload.shiftType][0]?.alertFrequencyMins;
40686
+ const afternoonAlertFrequencyMins = payload.shiftType == "3-shifts" ? payload?.shifts?.[payload.shiftType][1]?.alertFrequencyMins : null;
40687
+ const nightAlertFrequencyMins = payload.shiftType == "3-shifts" ? payload?.shifts?.[payload.shiftType][2]?.alertFrequencyMins : payload?.shifts?.[payload.shiftType][1]?.alertFrequencyMins;
40688
+ const morningAlertTime = moment.tz(morningCheckInTime, "HH:mm", "Asia/Singapore").add(morningAlertFrequencyMins, "minutes").format("HH:mm");
40689
+ const afternoonAlertTime = afternoonCheckInTime ? moment.tz(afternoonCheckInTime, "HH:mm", "Asia/Singapore").add(afternoonAlertFrequencyMins, "minutes").format("HH:mm") : "";
40690
+ const nightAlertTime = moment.tz(nightCheckInTime, "HH:mm", "Asia/Singapore").add(nightAlertFrequencyMins, "minutes").format("HH:mm");
40691
+ const nowSGT = moment().tz("Asia/Singapore");
40692
+ console.log("im done preparing the payload");
40693
+ try {
40694
+ const remarksPayload = {
40695
+ siteId: payload.siteId,
40696
+ siteName: payload.siteName,
40697
+ serviceProviderId: payload.serviceProviderId,
40698
+ remarks: [
40699
+ {
40700
+ name: "Morning Shift",
40701
+ remark: {
40702
+ isAcknowledged: false,
40703
+ status: "",
40704
+ acknowledgementRemarks: "",
40705
+ acknowledgedAt: ""
40706
+ }
40707
+ },
40708
+ {
40709
+ name: "Afternoon Shift",
40710
+ remark: {
40711
+ isAcknowledged: true,
40712
+ status: "",
40713
+ acknowledgementRemarks: "",
40714
+ acknowledgedAt: ""
40715
+ }
40716
+ },
40717
+ {
40718
+ name: "Night Shift",
40719
+ remark: {
40720
+ isAcknowledged: false,
40721
+ status: "",
40722
+ acknowledgementRemarks: "",
40723
+ acknowledgedAt: ""
40724
+ }
40725
+ }
40726
+ ],
40727
+ createdBy: "",
40728
+ createdByName: "",
40729
+ morningAlertTime,
40730
+ afternoonAlertTime,
40731
+ nightAlertTime,
40732
+ createdAt: /* @__PURE__ */ new Date(),
40733
+ createdAtSGT: nowSGT.format("DD-MM-YYYY"),
40734
+ updatedAt: "",
40735
+ status: "active"
40736
+ };
40737
+ console.log("im here at remarks payload");
40738
+ const result = await _createManpowerMonitoringSettings(payload, session);
40739
+ await session.commitTransaction();
40740
+ return result;
40741
+ } catch (error) {
40742
+ await session.abortTransaction();
40743
+ logger158.error(error.message || error);
40744
+ console.error("Error creating monitoring settings:", error);
40745
+ throw new Error(error?.message || "Internal Server Error!");
40746
+ } finally {
40747
+ session.endSession();
40748
+ }
40749
+ }
40750
+ return {
40751
+ createManpowerMonitoringSettings
40752
+ };
40753
+ }
40754
+
40755
+ // src/controllers/manpower-monitoring.controller.ts
40756
+ import { BadRequestError as BadRequestError181, logger as logger159 } from "@7365admin1/node-server-utils";
40757
+ import Joi112 from "joi";
40758
+ function useManpowerMonitoringCtrl() {
40759
+ const {
40760
+ getAllManpowerSettings: _getAllManpowerSettings,
40761
+ getManpowerSettingsBySiteId: _getManpowerSettingsBySiteId,
40762
+ updateManpowerMonitoringSettings: _updateManpowerMonitoringSettings,
40763
+ multipleManpowerMonitoringSettings: _multipleManpowerMonitoringSettings,
40764
+ getAllSites: _getAllSites
40765
+ } = useManpowerMonitoringRepo();
40766
+ const {
40767
+ createManpowerMonitoringSettings: _createManpowerMonitoringSettings
40768
+ } = useManpowerMonitoringSrvc();
40769
+ async function createManpowerMonitoringSettings(req, res, next) {
40770
+ try {
40771
+ const payload = { ...req.body };
40772
+ const { error } = manpowerMonitoringSchema.validate(payload);
40773
+ if (error) {
40774
+ next(new BadRequestError181(error.message));
40775
+ return;
40776
+ }
40777
+ const result = await _createManpowerMonitoringSettings(payload);
40778
+ return res.json(result);
40779
+ } catch (error) {
40780
+ logger159.log({ level: "error", message: error.message });
40781
+ next(error);
40782
+ return;
40783
+ }
40784
+ }
40785
+ async function getAllManpowerSettings(req, res, next) {
40786
+ try {
40787
+ const { page, search, limit } = req.query;
40788
+ const schema2 = Joi112.object({
40789
+ page: Joi112.number().optional().allow("", null),
40790
+ limit: Joi112.number().optional().allow("", null),
40791
+ search: Joi112.string().optional().allow("", null)
40792
+ });
40793
+ const { error } = schema2.validate({ page, search, limit });
40794
+ if (error) {
40795
+ next(new BadRequestError181(error.message));
40796
+ return;
40797
+ }
40798
+ const result = await _getAllManpowerSettings({
40799
+ page: Number(page),
40800
+ limit: Number(limit),
40801
+ search
40802
+ });
40803
+ return res.json(result);
40804
+ } catch (error) {
40805
+ logger159.log({ level: "error", message: error.message });
40806
+ next(error);
40807
+ return;
40808
+ }
40809
+ }
40810
+ async function getManpowerSettingsBySiteId(req, res, next) {
40811
+ try {
40812
+ const _id = req.params.id;
40813
+ const serviceProviderId = req.params.serviceProviderId;
40814
+ const schema2 = Joi112.object({
40815
+ _id: Joi112.string().hex().required(),
40816
+ serviceProviderId: Joi112.string().hex().required()
40817
+ });
40818
+ const { error } = schema2.validate({ _id, serviceProviderId });
40819
+ if (error) {
40820
+ next(new BadRequestError181(error.message));
40821
+ return;
40822
+ }
40823
+ const result = await _getManpowerSettingsBySiteId(_id, serviceProviderId);
40824
+ return res.json(result);
40825
+ } catch (error) {
40826
+ logger159.log({ level: "error", message: error.message });
40827
+ next(error);
40828
+ return;
40829
+ }
40830
+ }
40831
+ async function updateManpowerMonitoringSettings(req, res, next) {
40832
+ try {
40833
+ const validation = Joi112.object({
40834
+ _id: Joi112.string().hex().required(),
40835
+ shiftType: Joi112.string().optional().allow("", null),
40836
+ enabled: Joi112.boolean().required(),
40837
+ shifts: Joi112.object({
40838
+ "2-shifts": Joi112.array().items(shiftSchema).optional(),
40839
+ "3-shifts": Joi112.array().items(shiftSchema).optional()
40840
+ }).optional(),
40841
+ emails: Joi112.array().items(Joi112.string().email()).optional()
40842
+ });
40843
+ const _id = req.params.id;
40844
+ const payload = { ...req.body };
40845
+ console.log("_id", _id);
40846
+ const { error } = validation.validate({ _id, ...payload });
40847
+ if (error) {
40848
+ next(new BadRequestError181(error.message));
40849
+ return;
40850
+ }
40851
+ const result = await _updateManpowerMonitoringSettings(_id, payload);
40852
+ return res.json(result);
40853
+ } catch (error) {
40854
+ logger159.log({ level: "error", message: error.message });
40855
+ next(error);
40856
+ return;
40857
+ }
40858
+ }
40859
+ async function multipleManpowerMonitoringSettings(req, res, next) {
40860
+ try {
40861
+ const validation = Joi112.array().items(manpowerMonitoringSchema);
40862
+ const payload = req.body;
40863
+ const { error } = validation.validate(payload);
40864
+ if (error) {
40865
+ next(new BadRequestError181(error.message));
40866
+ return;
40867
+ }
40868
+ const result = await _multipleManpowerMonitoringSettings(payload);
40869
+ return res.json(result);
40870
+ } catch (error) {
40871
+ logger159.log({ level: "error", message: error.message });
40872
+ next(error);
40873
+ return;
40874
+ }
40875
+ }
40876
+ async function getAllSites(req, res, next) {
40877
+ try {
40878
+ const serviceProviderId = req.query.serviceProviderId;
40879
+ const validation = Joi112.object({
40880
+ serviceProviderId: Joi112.string().hex().required()
40881
+ });
40882
+ const { error } = validation.validate({ serviceProviderId });
40883
+ if (error) {
40884
+ next(new BadRequestError181(error.message));
40885
+ return;
40886
+ }
40887
+ const result = await _getAllSites(serviceProviderId);
40888
+ return res.json(result);
40889
+ } catch (error) {
40890
+ logger159.log({ level: "error", message: error.message });
40891
+ next(error);
40892
+ return;
40893
+ }
40894
+ }
40895
+ return {
40896
+ createManpowerMonitoringSettings,
40897
+ getAllManpowerSettings,
40898
+ getManpowerSettingsBySiteId,
40899
+ updateManpowerMonitoringSettings,
40900
+ multipleManpowerMonitoringSettings,
40901
+ getAllSites
40902
+ };
40903
+ }
40904
+
40905
+ // src/models/manpower-designations.model.ts
40906
+ import Joi113 from "joi";
40907
+ import { ObjectId as ObjectId109 } from "mongodb";
40908
+ var designationsSchema = Joi113.object({
40909
+ title: Joi113.string().required(),
40910
+ shifts: Joi113.object({
40911
+ morningShift: Joi113.number().required(),
40912
+ afternoonShift: Joi113.number().optional(),
40913
+ nightShift: Joi113.number().required()
40914
+ }).required()
40915
+ });
40916
+ var manpowerDesignationsSchema = Joi113.object({
40917
+ siteId: Joi113.string().hex().required(),
40918
+ siteName: Joi113.string().required(),
40919
+ serviceProviderId: Joi113.string().hex().optional(),
40920
+ designations: Joi113.array().items(designationsSchema).required(),
40921
+ createdBy: Joi113.string().hex().required(),
40922
+ createdByName: Joi113.string().optional().allow("", null)
40923
+ });
40924
+ var MManpowerDesignations = class {
40925
+ constructor(data) {
40926
+ this._id = new ObjectId109();
40927
+ this.siteId = data.siteId || "";
40928
+ this.siteName = data.siteName || "";
40929
+ this.serviceProviderId = data.serviceProviderId || "";
40930
+ this.designations = data.designations || [];
40931
+ this.createdBy = data.createdBy || "";
40932
+ this.createdByName = data.createdByName || "";
40933
+ this.createdAt = /* @__PURE__ */ new Date();
40934
+ this.updatedAt = data.updatedAt || "";
40935
+ }
40936
+ };
40937
+
40938
+ // src/repositories/manpower-designations.repo.ts
40939
+ import {
40940
+ useAtlas as useAtlas100
40941
+ } from "@7365admin1/node-server-utils";
40942
+ import { ObjectId as ObjectId110 } from "mongodb";
40943
+ function useManpowerDesignationRepo() {
40944
+ const db = useAtlas100.getDb();
40945
+ if (!db) {
40946
+ throw new Error("Unable to connect to server.");
40947
+ }
40948
+ const namespace_collection = "manpower-designations";
40949
+ const collection = db.collection(namespace_collection);
40950
+ async function createManpowerDesignations(value) {
40951
+ try {
40952
+ value = new MManpowerDesignations(value);
40953
+ if (value.createdBy)
40954
+ value.createdBy = new ObjectId110(value.createdBy);
40955
+ if (value.siteId)
40956
+ value.siteId = new ObjectId110(value.siteId);
40957
+ if (value.serviceProviderId)
40958
+ value.serviceProviderId = new ObjectId110(value.serviceProviderId);
40959
+ const result = await collection.insertOne(value);
40960
+ return result;
40961
+ } catch (error) {
40962
+ throw new Error(error.message || error || "Server Internal Error");
40963
+ }
40964
+ }
40965
+ async function getManpowerDesignationsBySiteId(_id, serviceProviderId) {
40966
+ try {
40967
+ _id = new ObjectId110(_id);
40968
+ serviceProviderId = new ObjectId110(serviceProviderId);
40969
+ } catch (error) {
40970
+ throw new Error("Invalid Site ID format.");
40971
+ }
40972
+ try {
40973
+ const data = await collection.findOne({
40974
+ siteId: _id,
40975
+ serviceProviderId
40976
+ });
40977
+ return data;
40978
+ } catch (error) {
40979
+ throw error;
40980
+ }
40981
+ }
40982
+ async function updateManpowerDesignations(_id, value) {
40983
+ try {
40984
+ _id = new ObjectId110(_id);
40985
+ } catch (error) {
40986
+ throw new Error("Invalid ID format.");
40987
+ }
40988
+ try {
40989
+ const updateValue = {
40990
+ ...value,
40991
+ updatedAt: /* @__PURE__ */ new Date()
40992
+ };
40993
+ const res = await collection.updateOne({ _id }, { $set: updateValue });
40994
+ if (res.modifiedCount === 0) {
40995
+ throw new Error("Unable to update manpower designations.");
40996
+ }
40997
+ return res.modifiedCount;
40998
+ } catch (error) {
40999
+ throw error;
41000
+ }
41001
+ }
41002
+ return {
41003
+ createManpowerDesignations,
41004
+ getManpowerDesignationsBySiteId,
41005
+ updateManpowerDesignations
41006
+ };
41007
+ }
41008
+
41009
+ // src/controllers/manpower-designations.controller.ts
41010
+ import { BadRequestError as BadRequestError183, logger as logger161 } from "@7365admin1/node-server-utils";
41011
+ import Joi114 from "joi";
41012
+ function useManpowerDesignationCtrl() {
41013
+ const {
41014
+ createManpowerDesignations: _createManpowerDesignations,
41015
+ getManpowerDesignationsBySiteId: _getManpowerDesignationsBySiteId,
41016
+ updateManpowerDesignations: _updateManpowerDesignations
41017
+ } = useManpowerDesignationRepo();
41018
+ async function createManpowerDesignations(req, res, next) {
41019
+ try {
41020
+ const payload = { ...req.body };
41021
+ const { error } = manpowerDesignationsSchema.validate(payload);
41022
+ if (error) {
41023
+ next(new BadRequestError183(error.message));
41024
+ return;
41025
+ }
41026
+ const result = await _createManpowerDesignations(payload);
41027
+ return res.json(result);
41028
+ } catch (error) {
41029
+ logger161.log({ level: "error", message: error.message });
41030
+ next(error);
41031
+ return;
41032
+ }
41033
+ }
41034
+ async function getManpowerSettingsBySiteId(req, res, next) {
41035
+ try {
41036
+ const { id, serviceProviderId } = req.params;
41037
+ const schema2 = Joi114.object({
41038
+ id: Joi114.string().hex().required(),
41039
+ serviceProviderId: Joi114.string().hex().required()
41040
+ });
41041
+ const { error } = schema2.validate({ id, serviceProviderId });
41042
+ if (error) {
41043
+ next(new BadRequestError183(error.message));
41044
+ return;
41045
+ }
41046
+ const result = await _getManpowerDesignationsBySiteId(
41047
+ id,
41048
+ serviceProviderId
41049
+ );
41050
+ return res.json(result);
41051
+ } catch (error) {
41052
+ logger161.log({ level: "error", message: error.message });
41053
+ next(error);
41054
+ return;
41055
+ }
41056
+ }
41057
+ async function updateManpowerDesignations(req, res, next) {
41058
+ try {
41059
+ const validation = Joi114.object({
41060
+ _id: Joi114.string().hex().required(),
41061
+ designations: Joi114.array().items(designationsSchema).required()
41062
+ });
41063
+ const _id = req.params.id;
41064
+ const payload = { ...req.body };
41065
+ const { error } = validation.validate({ _id, ...payload });
41066
+ if (error) {
41067
+ next(new BadRequestError183(error.message));
41068
+ return;
41069
+ }
41070
+ const result = await _updateManpowerDesignations(_id, payload);
41071
+ return res.json(result);
41072
+ } catch (error) {
41073
+ logger161.log({ level: "error", message: error.message });
41074
+ next(error);
41075
+ return;
41076
+ }
41077
+ }
41078
+ return {
41079
+ createManpowerDesignations,
41080
+ getManpowerSettingsBySiteId,
41081
+ updateManpowerDesignations
41082
+ };
41083
+ }
41084
+
41085
+ // src/models/overnight-parking.model.ts
41086
+ import Joi115 from "joi";
41087
+ import { ObjectId as ObjectId111 } from "mongodb";
41088
+ var dayScheduleSchema = Joi115.object({
41089
+ isEnabled: Joi115.boolean().required(),
41090
+ startTime: Joi115.string().pattern(/^([01]\d|2[0-3]):([0-5]\d)$/).required().messages({
41091
+ "string.pattern.base": "startTime must be in HH:mm format"
41092
+ }),
41093
+ endTime: Joi115.string().pattern(/^([01]\d|2[0-3]):([0-5]\d)$/).required().messages({
41094
+ "string.pattern.base": "endTime must be in HH:mm format"
41095
+ })
41096
+ }).required();
41097
+ var schemaOvernightParkingApprovalHours = Joi115.object({
41098
+ _id: Joi115.string().hex().length(24).optional(),
41099
+ site: Joi115.string().hex().length(24).required(),
41100
+ monday: dayScheduleSchema,
41101
+ tuesday: dayScheduleSchema,
41102
+ wednesday: dayScheduleSchema,
41103
+ thursday: dayScheduleSchema,
41104
+ friday: dayScheduleSchema,
41105
+ saturday: dayScheduleSchema,
41106
+ sunday: dayScheduleSchema,
41107
+ createdAt: Joi115.date().optional(),
41108
+ updatedAt: Joi115.date().optional(),
41109
+ deletedAt: Joi115.date().optional().allow(null)
41110
+ });
41111
+ function MOvernightParkingApprovalHours(value) {
41112
+ const { error } = schemaOvernightParkingApprovalHours.validate(value);
41113
+ if (error) {
41114
+ throw new Error(error.details[0].message);
41115
+ }
41116
+ if (value.site && typeof value.site === "string") {
41117
+ try {
41118
+ value.site = new ObjectId111(value.site);
41119
+ } catch {
41120
+ throw new Error("Invalid site ID.");
41121
+ }
41122
+ }
41123
+ const now = (/* @__PURE__ */ new Date()).toISOString();
41124
+ return {
41125
+ ...value,
41126
+ createdAt: value.createdAt ?? now,
41127
+ updatedAt: value.updatedAt ?? now
41128
+ };
41129
+ }
41130
+
41131
+ // src/repositories/overnight-parking.repo.ts
41132
+ import {
41133
+ InternalServerError as InternalServerError63,
41134
+ logger as logger162,
41135
+ makeCacheKey as makeCacheKey60,
41136
+ toObjectId as toObjectId9,
41137
+ useAtlas as useAtlas101,
41138
+ useCache as useCache62
41139
+ } from "@7365admin1/node-server-utils";
41140
+ var overnight_parking_namespace_collection = "site.overnight-parking";
41141
+ function useOvernightParkingRepo() {
41142
+ const db = useAtlas101.getDb();
41143
+ if (!db) {
41144
+ throw new InternalServerError63("Unable to connect to server.");
41145
+ }
41146
+ const collection = db.collection(overnight_parking_namespace_collection);
41147
+ const { delNamespace, setCache, getCache } = useCache62(
41148
+ overnight_parking_namespace_collection
41149
+ );
41150
+ async function createIndexes() {
41151
+ try {
41152
+ const existingIndexes = await collection.indexes();
41153
+ const existingNames = new Set(existingIndexes.map((i) => i.name));
41154
+ const indexesToEnsure = [
41155
+ {
41156
+ key: { site: 1 },
41157
+ name: "site-index"
41158
+ },
41159
+ {
41160
+ key: { status: 1 },
41161
+ name: "status-index"
41162
+ }
41163
+ ];
41164
+ const indexesToCreate = indexesToEnsure.filter(
41165
+ (index) => index.name && !existingNames.has(index.name)
41166
+ );
41167
+ if (indexesToCreate.length > 0) {
41168
+ await collection.createIndexes(indexesToCreate);
41169
+ }
41170
+ } catch (error) {
41171
+ throw new InternalServerError63("Failed to create collection indexes.");
41172
+ }
41173
+ }
41174
+ async function upsert(value, session) {
41175
+ try {
41176
+ value = MOvernightParkingApprovalHours(value);
41177
+ const now = (/* @__PURE__ */ new Date()).toISOString();
41178
+ const res = await collection.updateOne(
41179
+ { site: value.site },
41180
+ {
41181
+ $set: {
41182
+ monday: value.monday,
41183
+ tuesday: value.tuesday,
41184
+ wednesday: value.wednesday,
41185
+ thursday: value.thursday,
41186
+ friday: value.friday,
41187
+ saturday: value.saturday,
41188
+ sunday: value.sunday,
41189
+ updatedAt: now
41190
+ },
41191
+ $setOnInsert: {
41192
+ site: value.site,
41193
+ createdAt: value.createdAt ?? now
41194
+ }
41195
+ },
41196
+ { upsert: true, session }
41197
+ );
41198
+ delNamespace().then(() => {
41199
+ logger162.info(
41200
+ `Cache cleared for namespace: ${overnight_parking_namespace_collection}`
41201
+ );
41202
+ }).catch((err) => {
41203
+ logger162.error(
41204
+ `Failed to clear cache for namespace: ${overnight_parking_namespace_collection}`,
41205
+ err
41206
+ );
41207
+ });
41208
+ return res;
41209
+ } catch (error) {
41210
+ throw error;
41211
+ }
41212
+ }
41213
+ async function getSiteOvernightParking(site) {
41214
+ const siteId = toObjectId9(site);
41215
+ const cacheKey = makeCacheKey60(overnight_parking_namespace_collection, {
41216
+ site
41217
+ });
41218
+ const cachedData = await getCache(cacheKey);
41219
+ if (cachedData) {
41220
+ logger162.info(`Cache hit for key: ${cacheKey}`);
41221
+ return cachedData;
41222
+ }
41223
+ try {
41224
+ const data = await collection.findOne({
41225
+ site: siteId,
41226
+ deletedAt: null
41227
+ });
41228
+ setCache(cacheKey, data, 15 * 60).then(() => {
41229
+ logger162.info(`Cache set for key: ${cacheKey}`);
41230
+ }).catch((err) => {
41231
+ logger162.error(`Failed to set cache for key: ${cacheKey}`, err);
41232
+ });
41233
+ return data;
41234
+ } catch (error) {
41235
+ throw error;
41236
+ }
41237
+ }
41238
+ return {
41239
+ upsert,
41240
+ getSiteOvernightParking,
41241
+ createIndexes
41242
+ };
41243
+ }
41244
+
41245
+ // src/controllers/overnight-parking.controller.ts
41246
+ import Joi116 from "joi";
41247
+ import { BadRequestError as BadRequestError185, logger as logger163 } from "@7365admin1/node-server-utils";
41248
+ function useOvernightParkingController() {
41249
+ const { upsert: _upsert, getSiteOvernightParking: _getSiteOvernightParking } = useOvernightParkingRepo();
41250
+ async function upsert(req, res, next) {
41251
+ const site = req.params.site;
41252
+ req.body.site = site;
41253
+ try {
41254
+ const { error, value } = schemaOvernightParkingApprovalHours.validate(
41255
+ req.body,
41256
+ {
41257
+ abortEarly: false
41258
+ }
41259
+ );
41260
+ if (error) {
41261
+ const messages = error.details.map((d) => d.message).join(", ");
41262
+ logger163.log({ level: "error", message: messages });
41263
+ next(new BadRequestError185(messages));
41264
+ return;
41265
+ }
41266
+ const data = await _upsert(value);
41267
+ res.status(201).json(data);
41268
+ return;
41269
+ } catch (error) {
41270
+ logger163.log({ level: "error", message: error.message });
41271
+ next(error);
41272
+ return;
41273
+ }
41274
+ }
41275
+ async function getSiteOvernightParking(req, res, next) {
41276
+ const schema2 = Joi116.object({
41277
+ site: Joi116.string().hex().length(24).required()
41278
+ });
41279
+ try {
41280
+ const { error, value } = schema2.validate(
41281
+ { site: req.params.site },
41282
+ {
41283
+ abortEarly: false
41284
+ }
41285
+ );
41286
+ if (error) {
41287
+ const messages = error.details.map((d) => d.message).join(", ");
41288
+ logger163.log({ level: "error", message: messages });
41289
+ next(new BadRequestError185(messages));
41290
+ return;
41291
+ }
41292
+ const { site } = value;
41293
+ const data = await _getSiteOvernightParking(site);
41294
+ res.status(201).json(data);
41295
+ return;
41296
+ } catch (error) {
41297
+ logger163.log({ level: "error", message: error.message });
41298
+ next(error);
41299
+ return;
41300
+ }
41301
+ }
41302
+ return {
41303
+ upsert,
41304
+ getSiteOvernightParking
41305
+ };
41306
+ }
39400
41307
  export {
39401
41308
  ANPRMode,
39402
41309
  AccessTypeProps,
@@ -39433,6 +41340,8 @@ export {
39433
41340
  MFile,
39434
41341
  MGuestManagement,
39435
41342
  MIncidentReport,
41343
+ MManpowerDesignations,
41344
+ MManpowerMonitoring,
39436
41345
  MMember,
39437
41346
  MNfcPatrolLog,
39438
41347
  MNfcPatrolRoute,
@@ -39444,6 +41353,7 @@ export {
39444
41353
  MOccurrenceSubject,
39445
41354
  MOnlineForm,
39446
41355
  MOrg,
41356
+ MOvernightParkingApprovalHours,
39447
41357
  MPatrolLog,
39448
41358
  MPatrolQuestion,
39449
41359
  MPatrolRoute,
@@ -39469,6 +41379,8 @@ export {
39469
41379
  MWorkOrder,
39470
41380
  OrgNature,
39471
41381
  PERSON_TYPES,
41382
+ PMDashboardCollection,
41383
+ Period,
39472
41384
  PersonTypes,
39473
41385
  SiteCategories,
39474
41386
  SiteStatus,
@@ -39486,14 +41398,30 @@ export {
39486
41398
  allowedNatures,
39487
41399
  attendanceSchema,
39488
41400
  attendanceSettingsSchema,
41401
+ buildings_namespace_collection,
41402
+ bulletin_boards_namespace_collection,
41403
+ calculatePercentage,
39489
41404
  chatSchema,
39490
41405
  customerSchema,
41406
+ designationsSchema,
41407
+ events_namespace_collection,
41408
+ facility_bookings_namespace_collection,
39491
41409
  feedbackSchema,
41410
+ feedbacks_namespace_collection,
39492
41411
  formatDahuaDate,
41412
+ getPeriodRangeWithPrevious,
41413
+ guests_namespace_collection,
39493
41414
  incidentReportLog,
41415
+ incidents_namespace_collection,
41416
+ landscapeDashboardCollection,
41417
+ mAndEDashboardCollection,
41418
+ manpowerDesignationsSchema,
41419
+ manpowerMonitoringSchema,
39494
41420
  nfcPatrolSettingsSchema,
39495
41421
  nfcPatrolSettingsSchemaUpdate,
39496
41422
  orgSchema,
41423
+ pestDashboardCollection,
41424
+ poolDashboardCollection,
39497
41425
  promoCodeSchema,
39498
41426
  robotSchema,
39499
41427
  schema,
@@ -39520,6 +41448,7 @@ export {
39520
41448
  schemaOccurrenceEntry,
39521
41449
  schemaOccurrenceSubject,
39522
41450
  schemaOnlineForm,
41451
+ schemaOvernightParkingApprovalHours,
39523
41452
  schemaPatrolLog,
39524
41453
  schemaPatrolQuestion,
39525
41454
  schemaPatrolRoute,
@@ -39561,7 +41490,10 @@ export {
39561
41490
  schemaVisitorTransaction,
39562
41491
  schemeCamera,
39563
41492
  schemeLogCamera,
41493
+ securityDashboardCollection,
41494
+ shiftSchema,
39564
41495
  siteSchema,
41496
+ site_people_namespace_collection,
39565
41497
  tokenSchema,
39566
41498
  updateSiteSchema,
39567
41499
  useAccessManagementController,
@@ -39620,8 +41552,15 @@ export {
39620
41552
  useInvoiceController,
39621
41553
  useInvoiceModel,
39622
41554
  useInvoiceRepo,
41555
+ useManpowerDesignationCtrl,
41556
+ useManpowerDesignationRepo,
41557
+ useManpowerMonitoringCtrl,
41558
+ useManpowerMonitoringRepo,
41559
+ useManpowerMonitoringSrvc,
39623
41560
  useMemberController,
39624
41561
  useMemberRepo,
41562
+ useNewDashboardController,
41563
+ useNewDashboardRepo,
39625
41564
  useNfcPatrolLogController,
39626
41565
  useNfcPatrolLogRepo,
39627
41566
  useNfcPatrolLogService,
@@ -39647,6 +41586,8 @@ export {
39647
41586
  useOnlineFormRepo,
39648
41587
  useOrgController,
39649
41588
  useOrgRepo,
41589
+ useOvernightParkingController,
41590
+ useOvernightParkingRepo,
39650
41591
  usePatrolLogController,
39651
41592
  usePatrolLogRepo,
39652
41593
  usePatrolQuestionController,
@@ -39712,6 +41653,9 @@ export {
39712
41653
  useWorkOrderService,
39713
41654
  userSchema,
39714
41655
  vehicleSchema,
39715
- workOrderSchema
41656
+ vehicles_namespace_collection,
41657
+ visitors_namespace_collection,
41658
+ workOrderSchema,
41659
+ work_orders_namespace_collection
39716
41660
  };
39717
41661
  //# sourceMappingURL=index.mjs.map