@7365admin1/core 2.22.0 → 2.23.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
@@ -12280,7 +12280,7 @@ function useCustomerController() {
12280
12280
 
12281
12281
  // src/services/site.service.ts
12282
12282
  import {
12283
- AppError as AppError12,
12283
+ AppError as AppError11,
12284
12284
  BadRequestError as BadRequestError71,
12285
12285
  logger as logger53,
12286
12286
  useAtlas as useAtlas34
@@ -12819,7 +12819,8 @@ var schemaPerson = Joi35.object({
12819
12819
  companyName: Joi35.array().items(Joi35.string()).optional(),
12820
12820
  plates: Joi35.array().items(schemaPlate).optional().allow(null),
12821
12821
  isOwner: Joi35.boolean().required(),
12822
- files: Joi35.array().items(schemaFiles).optional().allow(null)
12822
+ files: Joi35.array().items(schemaFiles).optional().allow(null),
12823
+ password: Joi35.string().optional().allow(null, "")
12823
12824
  });
12824
12825
  var schemaUpdatePerson = Joi35.object({
12825
12826
  _id: Joi35.string().hex().required(),
@@ -12838,7 +12839,8 @@ var schemaUpdatePerson = Joi35.object({
12838
12839
  companyName: Joi35.array().items(Joi35.string()).optional().allow(null, ""),
12839
12840
  plates: Joi35.array().items(schemaFiles).optional().allow(null, ""),
12840
12841
  isOwner: Joi35.boolean().optional().allow(null, ""),
12841
- files: Joi35.array().items(schemaFiles).optional().allow(null)
12842
+ files: Joi35.array().items(schemaFiles).optional().allow(null),
12843
+ password: Joi35.string().optional().allow(null, "")
12842
12844
  });
12843
12845
  function MPerson(value) {
12844
12846
  const { error } = schemaPerson.validate(value);
@@ -12889,6 +12891,7 @@ function MPerson(value) {
12889
12891
  end: value.end,
12890
12892
  type: value.type,
12891
12893
  email: value.email,
12894
+ password: value.password ?? "",
12892
12895
  status: value.status ?? "active",
12893
12896
  nric: value.nric,
12894
12897
  remarks: value.remarks,
@@ -13438,6 +13441,8 @@ var VehicleSort = /* @__PURE__ */ ((VehicleSort2) => {
13438
13441
  VehicleSort2["CREATED_AT"] = "createdAt";
13439
13442
  VehicleSort2["ID"] = "_id";
13440
13443
  VehicleSort2["NAME"] = "name";
13444
+ VehicleSort2["START"] = "start";
13445
+ VehicleSort2["END"] = "end";
13441
13446
  return VehicleSort2;
13442
13447
  })(VehicleSort || {});
13443
13448
  var OrgNature = /* @__PURE__ */ ((OrgNature2) => {
@@ -13601,6 +13606,7 @@ import { ObjectId as ObjectId41 } from "mongodb";
13601
13606
  import Joi38 from "joi";
13602
13607
  var vehicles_namespace_collection = "vehicles";
13603
13608
  function useVehicleRepo() {
13609
+ vehicles_namespace_collection;
13604
13610
  const db = useAtlas31.getDb();
13605
13611
  if (!db) {
13606
13612
  throw new InternalServerError24("Unable to connect to server.");
@@ -16074,7 +16080,7 @@ function useSiteService() {
16074
16080
  });
16075
16081
  await deleteSiteCameraCache();
16076
16082
  } catch (error2) {
16077
- if (error2 instanceof AppError12) {
16083
+ if (error2 instanceof AppError11) {
16078
16084
  throw error2;
16079
16085
  }
16080
16086
  throw new BadRequestError71("Failed to update guard post.");
@@ -16402,14 +16408,14 @@ function MChat(value) {
16402
16408
  // src/repositories/chat.repo.ts
16403
16409
  import {
16404
16410
  useAtlas as useAtlas35,
16405
- InternalServerError as InternalServerError27,
16411
+ InternalServerError as InternalServerError26,
16406
16412
  useCache as useCache26,
16407
16413
  logger as logger56
16408
16414
  } from "@7365admin1/node-server-utils";
16409
16415
  function useChatRepo() {
16410
16416
  const db = useAtlas35.getDb();
16411
16417
  if (!db) {
16412
- throw new InternalServerError27("Unable to connect to server.");
16418
+ throw new InternalServerError26("Unable to connect to server.");
16413
16419
  }
16414
16420
  const namespace_collection = "chats";
16415
16421
  const collection = db.collection(namespace_collection);
@@ -16637,9 +16643,9 @@ function MBuildingUnit(value) {
16637
16643
 
16638
16644
  // src/repositories/building.repository.ts
16639
16645
  import {
16640
- AppError as AppError13,
16646
+ AppError as AppError12,
16641
16647
  BadRequestError as BadRequestError76,
16642
- InternalServerError as InternalServerError28,
16648
+ InternalServerError as InternalServerError27,
16643
16649
  logger as logger59,
16644
16650
  makeCacheKey as makeCacheKey25,
16645
16651
  paginate as paginate20,
@@ -16692,7 +16698,7 @@ function useBuildingRepo() {
16692
16698
  if (isDuplicated) {
16693
16699
  throw new BadRequestError76("Building already exists.");
16694
16700
  }
16695
- if (error instanceof AppError13) {
16701
+ if (error instanceof AppError12) {
16696
16702
  throw error;
16697
16703
  } else {
16698
16704
  throw new Error("Failed to create building.");
@@ -16727,7 +16733,7 @@ function useBuildingRepo() {
16727
16733
  if (isDuplicated) {
16728
16734
  throw new BadRequestError76("Building already exists.");
16729
16735
  }
16730
- if (error2 instanceof AppError13) {
16736
+ if (error2 instanceof AppError12) {
16731
16737
  throw error2;
16732
16738
  } else {
16733
16739
  throw new Error("Failed to update building.");
@@ -16838,10 +16844,10 @@ function useBuildingRepo() {
16838
16844
  });
16839
16845
  return result;
16840
16846
  } catch (error) {
16841
- if (error instanceof AppError13) {
16847
+ if (error instanceof AppError12) {
16842
16848
  throw error;
16843
16849
  } else {
16844
- throw new InternalServerError28("Failed to get building.");
16850
+ throw new InternalServerError27("Failed to get building.");
16845
16851
  }
16846
16852
  }
16847
16853
  }
@@ -16863,10 +16869,10 @@ function useBuildingRepo() {
16863
16869
  level: "error",
16864
16870
  message: error.message
16865
16871
  });
16866
- if (error instanceof AppError13) {
16872
+ if (error instanceof AppError12) {
16867
16873
  throw error;
16868
16874
  } else {
16869
- throw new InternalServerError28("Failed to delete building.");
16875
+ throw new InternalServerError27("Failed to delete building.");
16870
16876
  }
16871
16877
  }
16872
16878
  }
@@ -16905,10 +16911,10 @@ function useBuildingRepo() {
16905
16911
  });
16906
16912
  return result;
16907
16913
  } catch (error) {
16908
- if (error instanceof AppError13) {
16914
+ if (error instanceof AppError12) {
16909
16915
  throw error;
16910
16916
  } else {
16911
- throw new InternalServerError28("Failed to get building.");
16917
+ throw new InternalServerError27("Failed to get building.");
16912
16918
  }
16913
16919
  }
16914
16920
  }
@@ -16946,9 +16952,9 @@ import {
16946
16952
 
16947
16953
  // src/repositories/building-unit.repository.ts
16948
16954
  import {
16949
- AppError as AppError14,
16955
+ AppError as AppError13,
16950
16956
  BadRequestError as BadRequestError77,
16951
- InternalServerError as InternalServerError29,
16957
+ InternalServerError as InternalServerError28,
16952
16958
  logger as logger60,
16953
16959
  makeCacheKey as makeCacheKey26,
16954
16960
  paginate as paginate21,
@@ -17013,7 +17019,7 @@ function useBuildingUnitRepo() {
17013
17019
  if (isDuplicated) {
17014
17020
  throw new BadRequestError77("Building unit already exists.");
17015
17021
  }
17016
- if (error instanceof AppError14) {
17022
+ if (error instanceof AppError13) {
17017
17023
  throw error;
17018
17024
  } else {
17019
17025
  throw new Error("Failed to create building unit.");
@@ -17059,7 +17065,7 @@ function useBuildingUnitRepo() {
17059
17065
  if (isDuplicated) {
17060
17066
  throw new BadRequestError77("Building unit already exists.");
17061
17067
  }
17062
- if (error2 instanceof AppError14) {
17068
+ if (error2 instanceof AppError13) {
17063
17069
  throw error2;
17064
17070
  } else {
17065
17071
  throw new Error("Failed to create building unit.");
@@ -17093,7 +17099,7 @@ function useBuildingUnitRepo() {
17093
17099
  if (isDuplicated) {
17094
17100
  throw new BadRequestError77("Building unit already exists.");
17095
17101
  }
17096
- if (error2 instanceof AppError14) {
17102
+ if (error2 instanceof AppError13) {
17097
17103
  throw error2;
17098
17104
  } else {
17099
17105
  throw new Error("Failed to create building unit.");
@@ -17244,10 +17250,10 @@ function useBuildingUnitRepo() {
17244
17250
  });
17245
17251
  return result;
17246
17252
  } catch (error) {
17247
- if (error instanceof AppError14) {
17253
+ if (error instanceof AppError13) {
17248
17254
  throw error;
17249
17255
  } else {
17250
- throw new InternalServerError29("Failed to get building unit.");
17256
+ throw new InternalServerError28("Failed to get building unit.");
17251
17257
  }
17252
17258
  }
17253
17259
  }
@@ -17288,10 +17294,10 @@ function useBuildingUnitRepo() {
17288
17294
  });
17289
17295
  return result;
17290
17296
  } catch (error) {
17291
- if (error instanceof AppError14) {
17297
+ if (error instanceof AppError13) {
17292
17298
  throw error;
17293
17299
  } else {
17294
- throw new InternalServerError29("Failed to get building unit.");
17300
+ throw new InternalServerError28("Failed to get building unit.");
17295
17301
  }
17296
17302
  }
17297
17303
  }
@@ -17318,10 +17324,10 @@ function useBuildingUnitRepo() {
17318
17324
  delCachedData();
17319
17325
  return result;
17320
17326
  } catch (error) {
17321
- if (error instanceof AppError14) {
17327
+ if (error instanceof AppError13) {
17322
17328
  throw error;
17323
17329
  } else {
17324
- throw new InternalServerError29("Failed to update building unit level.");
17330
+ throw new InternalServerError28("Failed to update building unit level.");
17325
17331
  }
17326
17332
  }
17327
17333
  }
@@ -17360,10 +17366,10 @@ function useBuildingUnitRepo() {
17360
17366
  });
17361
17367
  return result;
17362
17368
  } catch (error) {
17363
- if (error instanceof AppError14) {
17369
+ if (error instanceof AppError13) {
17364
17370
  throw error;
17365
17371
  } else {
17366
- throw new InternalServerError29("Failed to get building unit.");
17372
+ throw new InternalServerError28("Failed to get building unit.");
17367
17373
  }
17368
17374
  }
17369
17375
  }
@@ -17386,7 +17392,7 @@ function useBuildingUnitRepo() {
17386
17392
  level: "error",
17387
17393
  message: error.message
17388
17394
  });
17389
- if (error instanceof AppError14) {
17395
+ if (error instanceof AppError13) {
17390
17396
  throw error;
17391
17397
  } else {
17392
17398
  throw new Error("Failed to deleted room/facility.");
@@ -17420,10 +17426,10 @@ function useBuildingUnitRepo() {
17420
17426
  });
17421
17427
  return data;
17422
17428
  } catch (error) {
17423
- if (error instanceof AppError14) {
17429
+ if (error instanceof AppError13) {
17424
17430
  throw error;
17425
17431
  } else {
17426
- throw new InternalServerError29("Failed to get building units.");
17432
+ throw new InternalServerError28("Failed to get building units.");
17427
17433
  }
17428
17434
  }
17429
17435
  }
@@ -17458,10 +17464,10 @@ function useBuildingUnitRepo() {
17458
17464
  });
17459
17465
  return data;
17460
17466
  } catch (error) {
17461
- if (error instanceof AppError14) {
17467
+ if (error instanceof AppError13) {
17462
17468
  throw error;
17463
17469
  } else {
17464
- throw new InternalServerError29(
17470
+ throw new InternalServerError28(
17465
17471
  "Failed to get building units with owner."
17466
17472
  );
17467
17473
  }
@@ -18124,11 +18130,13 @@ function useVehicleController() {
18124
18130
  getAllVehiclesByUnitId: _getAllVehiclesByUnitId
18125
18131
  } = useVehicleRepo();
18126
18132
  async function add(req, res, next) {
18127
- const payload = req.body;
18128
- const { error, value } = vehicleSchema.validate(payload);
18133
+ const { error, value } = vehicleSchema.validate(req.body, {
18134
+ abortEarly: false
18135
+ });
18129
18136
  if (error) {
18130
- logger65.log({ level: "error", message: error.message });
18131
- next(new BadRequestError82(error.message));
18137
+ const messages = error.details.map((d) => d.message).join(", ");
18138
+ logger65.log({ level: "error", message: messages });
18139
+ next(new BadRequestError82(messages));
18132
18140
  return;
18133
18141
  }
18134
18142
  try {
@@ -18144,40 +18152,29 @@ function useVehicleController() {
18144
18152
  }
18145
18153
  }
18146
18154
  async function getVehicles(req, res, next) {
18147
- const allowedFields = ["start", "end"];
18148
- const allowedOrder = ["asc", "desc"];
18149
- const validation = Joi46.object({
18155
+ const schema2 = Joi46.object({
18150
18156
  search: Joi46.string().optional().allow("", null),
18151
- page: Joi46.number().integer().min(1).allow("", null).default(1),
18152
- limit: Joi46.number().integer().min(1).max(100).allow("", null).default(10),
18153
- sort: Joi46.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
18154
- order: Joi46.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
18157
+ page: Joi46.number().integer().min(1).optional().default(1),
18158
+ limit: Joi46.number().integer().min(1).max(100).optional().default(10),
18159
+ sort: Joi46.string().optional().valid(...Object.values(VehicleSort)),
18160
+ order: Joi46.string().optional().valid(...Object.values(SortOrder)),
18155
18161
  type: Joi46.string().optional().valid(...Object.values(VehicleType)).allow(null, ""),
18156
18162
  category: Joi46.string().optional().valid(...Object.values(VehicleCategory)).allow(null, ""),
18157
18163
  status: Joi46.string().optional().valid(...Object.values(VehicleStatus)).allow(null, "")
18158
18164
  });
18159
- const query = { ...req.query };
18160
- const { error } = validation.validate(query);
18165
+ const { error, value } = schema2.validate(req.query, {
18166
+ abortEarly: false
18167
+ });
18161
18168
  if (error) {
18162
- logger65.log({ level: "error", message: error.message });
18163
- next(new BadRequestError82(error.message));
18169
+ const messages = error.details.map((d) => d.message).join(", ");
18170
+ logger65.log({ level: "error", message: messages });
18171
+ next(new BadRequestError82(messages));
18164
18172
  return;
18165
18173
  }
18166
- const search = req.query.search ?? "";
18167
- const page = parseInt(req.query.page ?? "1");
18168
- const limit = parseInt(req.query.limit ?? "10");
18169
- const type = req.query.type ?? "";
18170
- const category = req.query.category ?? "";
18171
- const status = req.query.status ?? "";
18172
- const sortObj = {};
18173
- const sortFields = String(req.query.sort).split(",");
18174
- const sortOrders = String(req.query.order).split(",");
18175
- sortFields.forEach((field, index) => {
18176
- if (allowedFields.includes(field)) {
18177
- const order = sortOrders[index] === "asc" ? 1 : -1;
18178
- sortObj[field] = order;
18179
- }
18180
- });
18174
+ const { search, page, limit, type, category, status, sort, order } = value;
18175
+ const sortObj = {
18176
+ [sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
18177
+ };
18181
18178
  try {
18182
18179
  const data = await _getVehicles({
18183
18180
  search,
@@ -18197,14 +18194,20 @@ function useVehicleController() {
18197
18194
  }
18198
18195
  }
18199
18196
  async function getSeasonPassTypes(req, res, next) {
18200
- const validation = Joi46.string().hex().required();
18201
- const site = req.params.site;
18202
- const { error } = validation.validate(site);
18197
+ const schema2 = Joi46.object({
18198
+ site: Joi46.string().hex().length(24).required()
18199
+ });
18200
+ const { error, value } = schema2.validate(
18201
+ { site: req.params.site },
18202
+ { abortEarly: false }
18203
+ );
18203
18204
  if (error) {
18204
- logger65.log({ level: "error", message: error.message });
18205
- next(new BadRequestError82(error.message));
18205
+ const messages = error.details.map((d) => d.message).join(", ");
18206
+ logger65.log({ level: "error", message: messages });
18207
+ next(new BadRequestError82(messages));
18206
18208
  return;
18207
18209
  }
18210
+ const { site } = value;
18208
18211
  try {
18209
18212
  const data = await _getSeasonPassTypes(site);
18210
18213
  res.json(data);
@@ -18216,14 +18219,20 @@ function useVehicleController() {
18216
18219
  }
18217
18220
  }
18218
18221
  async function getVehicleById(req, res, next) {
18219
- const validation = Joi46.string().hex().required();
18220
- const _id = req.params.id;
18221
- const { error } = validation.validate(_id);
18222
+ const schema2 = Joi46.object({
18223
+ _id: Joi46.string().hex().length(24).required()
18224
+ });
18225
+ const { error, value } = schema2.validate(
18226
+ { _id: req.params.id },
18227
+ { abortEarly: false }
18228
+ );
18222
18229
  if (error) {
18223
- logger65.log({ level: "error", message: error.message });
18224
- next(new BadRequestError82(error.message));
18230
+ const messages = error.details.map((d) => d.message).join(", ");
18231
+ logger65.log({ level: "error", message: messages });
18232
+ next(new BadRequestError82(messages));
18225
18233
  return;
18226
18234
  }
18235
+ const { _id } = value;
18227
18236
  try {
18228
18237
  const site = await _getVehicleById(_id);
18229
18238
  res.json(site);
@@ -18236,7 +18245,7 @@ function useVehicleController() {
18236
18245
  }
18237
18246
  async function updateVehicleById(req, res, next) {
18238
18247
  try {
18239
- const validation = Joi46.object({
18248
+ const schema2 = Joi46.object({
18240
18249
  _id: Joi46.string().hex().length(24).required(),
18241
18250
  site: Joi46.string().hex().length(24).required(),
18242
18251
  name: Joi46.string().optional().allow("", null),
@@ -18251,13 +18260,17 @@ function useVehicleController() {
18251
18260
  recNo: Joi46.string().optional().allow(null, ""),
18252
18261
  type: Joi46.string().optional().valid(...Object.values(VehicleType)).allow(null, "")
18253
18262
  });
18254
- const { error, value } = validation.validate({
18255
- _id: req.params.id,
18256
- ...req.body
18257
- });
18263
+ const { error, value } = schema2.validate(
18264
+ {
18265
+ _id: req.params.id,
18266
+ ...req.body
18267
+ },
18268
+ { abortEarly: false }
18269
+ );
18258
18270
  if (error) {
18259
- logger65.log({ level: "error", message: error.message });
18260
- next(new BadRequestError82(error.message));
18271
+ const messages = error.details.map((d) => d.message).join(", ");
18272
+ logger65.log({ level: "error", message: messages });
18273
+ next(new BadRequestError82(messages));
18261
18274
  return;
18262
18275
  }
18263
18276
  const { _id, ...rest } = value;
@@ -18271,21 +18284,24 @@ function useVehicleController() {
18271
18284
  }
18272
18285
  }
18273
18286
  async function deleteVehicle(req, res, next) {
18274
- const _id = req.params.id;
18275
18287
  const deleteVehicleSchema = Joi46.object({
18276
18288
  _id: Joi46.string().hex().length(24).required(),
18277
18289
  recno: Joi46.string().required(),
18278
18290
  site: Joi46.string().hex().length(24).required(),
18279
- type: Joi46.string().valid("whitelist", "blocklist").required(),
18291
+ type: Joi46.string().valid(...Object.values(VehicleType)).required(),
18280
18292
  bypass: Joi46.boolean().optional().default(true)
18281
18293
  });
18282
- const { error, value } = deleteVehicleSchema.validate({ _id, ...req.body });
18294
+ const { error, value } = deleteVehicleSchema.validate({
18295
+ _id: req.params.id,
18296
+ ...req.body
18297
+ });
18283
18298
  if (error) {
18284
- logger65.log({ level: "error", message: error.message });
18285
- next(new BadRequestError82(error.message));
18299
+ const messages = error.details.map((d) => d.message).join(", ");
18300
+ logger65.log({ level: "error", message: messages });
18301
+ next(new BadRequestError82(messages));
18286
18302
  return;
18287
18303
  }
18288
- const { recno, site, type, bypass } = value;
18304
+ const { recno, site, type, bypass, _id } = value;
18289
18305
  try {
18290
18306
  const data = await _deleteVehicle(_id, recno, site, type, bypass);
18291
18307
  res.json({
@@ -18685,7 +18701,7 @@ function MCustomerSite(value) {
18685
18701
  // src/repositories/customer-site.repo.ts
18686
18702
  import {
18687
18703
  BadRequestError as BadRequestError85,
18688
- InternalServerError as InternalServerError30,
18704
+ InternalServerError as InternalServerError29,
18689
18705
  logger as logger67,
18690
18706
  makeCacheKey as makeCacheKey27,
18691
18707
  paginate as paginate22,
@@ -18697,7 +18713,7 @@ import Joi49 from "joi";
18697
18713
  function useCustomerSiteRepo() {
18698
18714
  const db = useAtlas41.getDb();
18699
18715
  if (!db) {
18700
- throw new InternalServerError30("Unable to connect to server.");
18716
+ throw new InternalServerError29("Unable to connect to server.");
18701
18717
  }
18702
18718
  const namespace_collection = "customer.sites";
18703
18719
  const collection = db.collection(namespace_collection);
@@ -18715,7 +18731,7 @@ function useCustomerSiteRepo() {
18715
18731
  }
18716
18732
  ]);
18717
18733
  } catch (error) {
18718
- throw new InternalServerError30("Failed to create index on customer.");
18734
+ throw new InternalServerError29("Failed to create index on customer.");
18719
18735
  }
18720
18736
  }
18721
18737
  async function add(value, session) {
@@ -19260,7 +19276,7 @@ function MAttendanceSettings(value) {
19260
19276
  import { ObjectId as ObjectId51 } from "mongodb";
19261
19277
  import {
19262
19278
  useAtlas as useAtlas43,
19263
- InternalServerError as InternalServerError31,
19279
+ InternalServerError as InternalServerError30,
19264
19280
  BadRequestError as BadRequestError89,
19265
19281
  useCache as useCache30,
19266
19282
  logger as logger70,
@@ -19270,7 +19286,7 @@ import {
19270
19286
  function useAttendanceSettingsRepository() {
19271
19287
  const db = useAtlas43.getDb();
19272
19288
  if (!db) {
19273
- throw new InternalServerError31("Unable to connect to server.");
19289
+ throw new InternalServerError30("Unable to connect to server.");
19274
19290
  }
19275
19291
  const namespace_collection = "site.attendance-settings";
19276
19292
  const collection = db.collection(namespace_collection);
@@ -19279,7 +19295,7 @@ function useAttendanceSettingsRepository() {
19279
19295
  try {
19280
19296
  await collection.createIndexes([{ key: { site: 1 } }]);
19281
19297
  } catch (error) {
19282
- throw new InternalServerError31(
19298
+ throw new InternalServerError30(
19283
19299
  "Failed to create index on attendance settings."
19284
19300
  );
19285
19301
  }
@@ -19528,7 +19544,7 @@ function MAttendance(value) {
19528
19544
  import { ObjectId as ObjectId53 } from "mongodb";
19529
19545
  import {
19530
19546
  useAtlas as useAtlas45,
19531
- InternalServerError as InternalServerError32,
19547
+ InternalServerError as InternalServerError31,
19532
19548
  paginate as paginate23,
19533
19549
  BadRequestError as BadRequestError92,
19534
19550
  useCache as useCache31,
@@ -19539,7 +19555,7 @@ import {
19539
19555
  function useAttendanceRepository() {
19540
19556
  const db = useAtlas45.getDb();
19541
19557
  if (!db) {
19542
- throw new InternalServerError32("Unable to connect to server.");
19558
+ throw new InternalServerError31("Unable to connect to server.");
19543
19559
  }
19544
19560
  const namespace_collection = "site.attendances";
19545
19561
  const collection = db.collection(namespace_collection);
@@ -19551,7 +19567,7 @@ function useAttendanceRepository() {
19551
19567
  { key: { user: 1 } }
19552
19568
  ]);
19553
19569
  } catch (error) {
19554
- throw new InternalServerError32("Failed to create index on attendance.");
19570
+ throw new InternalServerError31("Failed to create index on attendance.");
19555
19571
  }
19556
19572
  }
19557
19573
  async function checkInAttendance(value, session) {
@@ -19872,7 +19888,7 @@ function useAttendanceRepository() {
19872
19888
  { session }
19873
19889
  );
19874
19890
  if (res.modifiedCount === 0) {
19875
- throw new InternalServerError32("Unable to update attendance.");
19891
+ throw new InternalServerError31("Unable to update attendance.");
19876
19892
  }
19877
19893
  delNamespace().then(() => {
19878
19894
  logger74.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -19905,7 +19921,7 @@ function useAttendanceRepository() {
19905
19921
  { session }
19906
19922
  );
19907
19923
  if (res.modifiedCount === 0)
19908
- throw new InternalServerError32("Unable to delete attendance.");
19924
+ throw new InternalServerError31("Unable to delete attendance.");
19909
19925
  const cacheKey = makeCacheKey29(namespace_collection, { _id });
19910
19926
  delCache(cacheKey).then(() => {
19911
19927
  logger74.info(`Cache deleted for key: ${cacheKey}`);
@@ -20731,7 +20747,7 @@ function MGuestManagement(value) {
20731
20747
  // src/repositories/guest-management.repo.ts
20732
20748
  import {
20733
20749
  BadRequestError as BadRequestError97,
20734
- InternalServerError as InternalServerError33,
20750
+ InternalServerError as InternalServerError32,
20735
20751
  logger as logger79,
20736
20752
  makeCacheKey as makeCacheKey30,
20737
20753
  paginate as paginate24,
@@ -20743,7 +20759,7 @@ var guests_namespace_collection = "visitor.guests";
20743
20759
  function useGuestManagementRepo() {
20744
20760
  const db = useAtlas48.getDb();
20745
20761
  if (!db) {
20746
- throw new InternalServerError33("Unable to connect to server.");
20762
+ throw new InternalServerError32("Unable to connect to server.");
20747
20763
  }
20748
20764
  const collection = db.collection(guests_namespace_collection);
20749
20765
  const { delNamespace, getCache, setCache } = useCache32(
@@ -20760,7 +20776,7 @@ function useGuestManagementRepo() {
20760
20776
  contact: "text"
20761
20777
  });
20762
20778
  } catch (error) {
20763
- throw new InternalServerError33("Failed to create text index on guest.");
20779
+ throw new InternalServerError32("Failed to create text index on guest.");
20764
20780
  }
20765
20781
  }
20766
20782
  async function add(value, session) {
@@ -20894,7 +20910,7 @@ function useGuestManagementRepo() {
20894
20910
  };
20895
20911
  const res = await collection.updateOne({ _id }, { $set: updateValue });
20896
20912
  if (res.modifiedCount === 0) {
20897
- throw new InternalServerError33("Unable to delete visitor transaction.");
20913
+ throw new InternalServerError32("Unable to delete visitor transaction.");
20898
20914
  }
20899
20915
  delNamespace().then(() => {
20900
20916
  logger79.info(
@@ -21103,7 +21119,8 @@ import {
21103
21119
  BadRequestError as BadRequestError99,
21104
21120
  logger as logger81,
21105
21121
  NotFoundError as NotFoundError23,
21106
- useAtlas as useAtlas50
21122
+ useAtlas as useAtlas50,
21123
+ hashPassword as hashPassword2
21107
21124
  } from "@7365admin1/node-server-utils";
21108
21125
  function usePersonService() {
21109
21126
  const {
@@ -21112,9 +21129,19 @@ function usePersonService() {
21112
21129
  updateById: _updateById
21113
21130
  } = usePersonRepo();
21114
21131
  const { addPlateNumber: _addPlateNumber } = useDahuaService();
21132
+ const {
21133
+ createUser: addUser,
21134
+ getUserById,
21135
+ getUserByEmail,
21136
+ updatePassword,
21137
+ updateUserFieldById: _updateUserFieldById
21138
+ } = useUserRepo();
21139
+ const { add: addMember } = useMemberRepo();
21115
21140
  const { getById: _getUnitById, updateById: updateUnitById } = useBuildingUnitRepo();
21116
21141
  const { getAllCameraWithPassword: _getAllSiteCameras } = useSiteCameraRepo();
21117
21142
  const { updateStatusById } = useFileRepo();
21143
+ const { getById: getOrgById } = useOrgRepo();
21144
+ const { getSiteById } = useSiteRepo();
21118
21145
  async function add(value) {
21119
21146
  const session = useAtlas50.getClient()?.startSession();
21120
21147
  if (!session) {
@@ -21135,6 +21162,49 @@ function usePersonService() {
21135
21162
  }
21136
21163
  }
21137
21164
  }
21165
+ const isValidType = ["resident" /* RESIDENT */, "tenant" /* TENANT */].includes(
21166
+ value?.type
21167
+ );
21168
+ if (value.email && value.password && value.name && isValidType) {
21169
+ const _user = await getUserByEmail(value.email);
21170
+ if (_user) {
21171
+ throw new BadRequestError99(`User already exists: ${value.email}.`);
21172
+ }
21173
+ const hashedPassword = await hashPassword2(value.password);
21174
+ const user = {
21175
+ email: value.email,
21176
+ password: hashedPassword,
21177
+ name: value.name,
21178
+ defaultOrg: value.org?.toString() || ""
21179
+ };
21180
+ const userId = await addUser(user, session);
21181
+ let org = null;
21182
+ if (userId) {
21183
+ if (value?.org) {
21184
+ org = await getOrgById(value.org);
21185
+ if (!org) {
21186
+ value.org = "";
21187
+ }
21188
+ }
21189
+ let site;
21190
+ if (value.site) {
21191
+ site = await getSiteById(value.site);
21192
+ }
21193
+ await addMember(
21194
+ {
21195
+ org: value.org?.toString() || "",
21196
+ orgName: org?.name || "",
21197
+ user: userId.toString(),
21198
+ name: value.name,
21199
+ role: "",
21200
+ type: "resident",
21201
+ siteId: value.site?.toString() || "",
21202
+ siteName: site?.name || ""
21203
+ },
21204
+ session
21205
+ );
21206
+ }
21207
+ }
21138
21208
  await _add(value, session);
21139
21209
  await session.commitTransaction();
21140
21210
  return "People added successfully.";
@@ -21588,7 +21658,7 @@ function MRobot(value) {
21588
21658
  import { ObjectId as ObjectId57 } from "mongodb";
21589
21659
  import {
21590
21660
  useAtlas as useAtlas51,
21591
- InternalServerError as InternalServerError34,
21661
+ InternalServerError as InternalServerError33,
21592
21662
  paginate as paginate25,
21593
21663
  BadRequestError as BadRequestError102,
21594
21664
  useCache as useCache33,
@@ -21598,7 +21668,7 @@ import {
21598
21668
  function useRobotRepo() {
21599
21669
  const db = useAtlas51.getDb();
21600
21670
  if (!db) {
21601
- throw new InternalServerError34("Unable to connect to server.");
21671
+ throw new InternalServerError33("Unable to connect to server.");
21602
21672
  }
21603
21673
  const namespace_collection = "robots";
21604
21674
  const collection = db.collection(namespace_collection);
@@ -21611,7 +21681,7 @@ function useRobotRepo() {
21611
21681
  { key: { "metadata.siteId": 1 } }
21612
21682
  ]);
21613
21683
  } catch (error) {
21614
- throw new InternalServerError34("Failed to create index on feedback.");
21684
+ throw new InternalServerError33("Failed to create index on feedback.");
21615
21685
  }
21616
21686
  }
21617
21687
  async function createTextIndex() {
@@ -21621,7 +21691,7 @@ function useRobotRepo() {
21621
21691
  status: "text"
21622
21692
  });
21623
21693
  } catch (error) {
21624
- throw new InternalServerError34("Failed to create text index on feedback.");
21694
+ throw new InternalServerError33("Failed to create text index on feedback.");
21625
21695
  }
21626
21696
  }
21627
21697
  async function createRobot(value, session) {
@@ -21927,9 +21997,9 @@ function MPatrolQuestion(value) {
21927
21997
 
21928
21998
  // src/repositories/patrol-question.repo.ts
21929
21999
  import {
21930
- AppError as AppError15,
22000
+ AppError as AppError14,
21931
22001
  BadRequestError as BadRequestError106,
21932
- InternalServerError as InternalServerError35,
22002
+ InternalServerError as InternalServerError34,
21933
22003
  logger as logger87,
21934
22004
  makeCacheKey as makeCacheKey32,
21935
22005
  paginate as paginate26,
@@ -21958,7 +22028,7 @@ function usePatrolQuestionRepo() {
21958
22028
  level: "error",
21959
22029
  message: error.message
21960
22030
  });
21961
- throw new InternalServerError35(
22031
+ throw new InternalServerError34(
21962
22032
  "Failed to create general indexes on patrol questions."
21963
22033
  );
21964
22034
  }
@@ -21975,7 +22045,7 @@ function usePatrolQuestionRepo() {
21975
22045
  level: "error",
21976
22046
  message: error.message
21977
22047
  });
21978
- throw new InternalServerError35(
22048
+ throw new InternalServerError34(
21979
22049
  "Failed to create text index on patrol questions."
21980
22050
  );
21981
22051
  }
@@ -21995,7 +22065,7 @@ function usePatrolQuestionRepo() {
21995
22065
  if (isDuplicated) {
21996
22066
  throw new BadRequestError106("Question already exist.");
21997
22067
  }
21998
- if (error instanceof AppError15) {
22068
+ if (error instanceof AppError14) {
21999
22069
  throw error;
22000
22070
  } else {
22001
22071
  throw new Error("Failed to create Patrol Question.");
@@ -22092,7 +22162,7 @@ function usePatrolQuestionRepo() {
22092
22162
  };
22093
22163
  const res = await collection.updateOne({ _id }, { $set: updateValue });
22094
22164
  if (res.modifiedCount === 0) {
22095
- throw new InternalServerError35("Unable to delete patrol question.");
22165
+ throw new InternalServerError34("Unable to delete patrol question.");
22096
22166
  }
22097
22167
  delCachedData();
22098
22168
  return res.modifiedCount;
@@ -22378,9 +22448,9 @@ function MPatrolRoute(value) {
22378
22448
 
22379
22449
  // src/repositories/patrol-route.repo.ts
22380
22450
  import {
22381
- AppError as AppError16,
22451
+ AppError as AppError15,
22382
22452
  BadRequestError as BadRequestError109,
22383
- InternalServerError as InternalServerError36,
22453
+ InternalServerError as InternalServerError35,
22384
22454
  logger as logger90,
22385
22455
  makeCacheKey as makeCacheKey33,
22386
22456
  paginate as paginate27,
@@ -22407,7 +22477,7 @@ function usePatrolRouteRepo() {
22407
22477
  level: "error",
22408
22478
  message: error.message
22409
22479
  });
22410
- throw new InternalServerError36(
22480
+ throw new InternalServerError35(
22411
22481
  "Failed to create text index on patrol route."
22412
22482
  );
22413
22483
  }
@@ -22427,7 +22497,7 @@ function usePatrolRouteRepo() {
22427
22497
  if (isDuplicated) {
22428
22498
  throw new BadRequestError109("Route already exist.");
22429
22499
  }
22430
- if (error instanceof AppError16) {
22500
+ if (error instanceof AppError15) {
22431
22501
  throw error;
22432
22502
  } else {
22433
22503
  throw new Error("Failed to create Patrol Route.");
@@ -22573,7 +22643,7 @@ function usePatrolRouteRepo() {
22573
22643
  };
22574
22644
  const res = await collection.updateOne({ _id }, { $set: updateValue });
22575
22645
  if (res.modifiedCount === 0) {
22576
- throw new InternalServerError36("Unable to delete patrol route.");
22646
+ throw new InternalServerError35("Unable to delete patrol route.");
22577
22647
  }
22578
22648
  delCachedData();
22579
22649
  return res.modifiedCount;
@@ -23095,9 +23165,9 @@ function MPatrolLog(value) {
23095
23165
 
23096
23166
  // src/repositories/patrol-log.repo.ts
23097
23167
  import {
23098
- AppError as AppError17,
23168
+ AppError as AppError16,
23099
23169
  BadRequestError as BadRequestError112,
23100
- InternalServerError as InternalServerError37,
23170
+ InternalServerError as InternalServerError36,
23101
23171
  logger as logger93,
23102
23172
  makeCacheKey as makeCacheKey34,
23103
23173
  paginate as paginate28,
@@ -23126,7 +23196,7 @@ function usePatrolLogRepo() {
23126
23196
  level: "error",
23127
23197
  message: error.message
23128
23198
  });
23129
- throw new InternalServerError37(
23199
+ throw new InternalServerError36(
23130
23200
  "Failed to create general indexes on patrol questions."
23131
23201
  );
23132
23202
  }
@@ -23142,7 +23212,7 @@ function usePatrolLogRepo() {
23142
23212
  level: "error",
23143
23213
  message: error.message
23144
23214
  });
23145
- throw new InternalServerError37(
23215
+ throw new InternalServerError36(
23146
23216
  "Failed to create text index on patrol questions."
23147
23217
  );
23148
23218
  }
@@ -23162,7 +23232,7 @@ function usePatrolLogRepo() {
23162
23232
  if (isDuplicated) {
23163
23233
  throw new BadRequestError112("Log already exist.");
23164
23234
  }
23165
- if (error instanceof AppError17) {
23235
+ if (error instanceof AppError16) {
23166
23236
  throw error;
23167
23237
  } else {
23168
23238
  throw new Error("Failed to create Patrol Log.");
@@ -23887,7 +23957,7 @@ function MSiteFacility(value) {
23887
23957
  // src/repositories/site-facility.repo.ts
23888
23958
  import {
23889
23959
  BadRequestError as BadRequestError115,
23890
- InternalServerError as InternalServerError38,
23960
+ InternalServerError as InternalServerError37,
23891
23961
  logger as logger96,
23892
23962
  makeCacheKey as makeCacheKey35,
23893
23963
  NotFoundError as NotFoundError25,
@@ -23899,7 +23969,7 @@ import { ObjectId as ObjectId65 } from "mongodb";
23899
23969
  function useSiteFacilityRepo() {
23900
23970
  const db = useAtlas56.getDb();
23901
23971
  if (!db) {
23902
- throw new InternalServerError38("Unable to connect to server.");
23972
+ throw new InternalServerError37("Unable to connect to server.");
23903
23973
  }
23904
23974
  const namespace_collection = "site.facilities";
23905
23975
  const collection = db.collection(namespace_collection);
@@ -23910,7 +23980,7 @@ function useSiteFacilityRepo() {
23910
23980
  name: "text"
23911
23981
  });
23912
23982
  } catch (error) {
23913
- throw new InternalServerError38(
23983
+ throw new InternalServerError37(
23914
23984
  "Failed to create text index on site facilities."
23915
23985
  );
23916
23986
  }
@@ -23921,7 +23991,7 @@ function useSiteFacilityRepo() {
23921
23991
  { key: { site: 1, orgId: 1, status: 1 } }
23922
23992
  ]);
23923
23993
  } catch (error) {
23924
- throw new InternalServerError38("Failed to create index on site.");
23994
+ throw new InternalServerError37("Failed to create index on site.");
23925
23995
  }
23926
23996
  }
23927
23997
  async function add(value, session) {
@@ -24078,7 +24148,7 @@ function useSiteFacilityRepo() {
24078
24148
  { session }
24079
24149
  );
24080
24150
  if (res.modifiedCount === 0) {
24081
- throw new InternalServerError38("Unable to update site facility.");
24151
+ throw new InternalServerError37("Unable to update site facility.");
24082
24152
  }
24083
24153
  delNamespace().then(() => {
24084
24154
  logger96.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -24107,7 +24177,7 @@ function useSiteFacilityRepo() {
24107
24177
  };
24108
24178
  const res = await collection.updateOne({ _id }, { $set: updateValue });
24109
24179
  if (res.modifiedCount === 0) {
24110
- throw new InternalServerError38("Unable to delete site facility.");
24180
+ throw new InternalServerError37("Unable to delete site facility.");
24111
24181
  }
24112
24182
  delNamespace().then(() => {
24113
24183
  logger96.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -24545,7 +24615,7 @@ function MServiceProviderBilling(value) {
24545
24615
  // src/repositories/service-provider-billing.repo.ts
24546
24616
  import {
24547
24617
  BadRequestError as BadRequestError117,
24548
- InternalServerError as InternalServerError39,
24618
+ InternalServerError as InternalServerError38,
24549
24619
  logger as logger98,
24550
24620
  makeCacheKey as makeCacheKey36,
24551
24621
  NotFoundError as NotFoundError26,
@@ -24557,7 +24627,7 @@ import { ObjectId as ObjectId67 } from "mongodb";
24557
24627
  function useServiceProviderBillingRepo() {
24558
24628
  const db = useAtlas58.getDb();
24559
24629
  if (!db) {
24560
- throw new InternalServerError39("Unable to connect to server.");
24630
+ throw new InternalServerError38("Unable to connect to server.");
24561
24631
  }
24562
24632
  const namespace_collection = "site.service-provider.billing";
24563
24633
  const collection = db.collection(namespace_collection);
@@ -24566,7 +24636,7 @@ function useServiceProviderBillingRepo() {
24566
24636
  try {
24567
24637
  await collection.createIndexes([{ key: { orgId: 1, status: 1 } }]);
24568
24638
  } catch (error) {
24569
- throw new InternalServerError39("Failed to create index on site.");
24639
+ throw new InternalServerError38("Failed to create index on site.");
24570
24640
  }
24571
24641
  }
24572
24642
  async function add(value, session) {
@@ -24701,7 +24771,7 @@ function useServiceProviderBillingRepo() {
24701
24771
  { session }
24702
24772
  );
24703
24773
  if (res.modifiedCount === 0) {
24704
- throw new InternalServerError39(
24774
+ throw new InternalServerError38(
24705
24775
  "Unable to update service provider billing facility."
24706
24776
  );
24707
24777
  }
@@ -24732,7 +24802,7 @@ function useServiceProviderBillingRepo() {
24732
24802
  };
24733
24803
  const res = await collection.updateOne({ _id }, { $set: updateValue });
24734
24804
  if (res.modifiedCount === 0) {
24735
- throw new InternalServerError39(
24805
+ throw new InternalServerError38(
24736
24806
  "Unable to delete service provider billing."
24737
24807
  );
24738
24808
  }
@@ -25196,7 +25266,7 @@ function MSiteFacilityBooking(value) {
25196
25266
  // src/repositories/site-facility-booking.repo.ts
25197
25267
  import {
25198
25268
  BadRequestError as BadRequestError119,
25199
- InternalServerError as InternalServerError40,
25269
+ InternalServerError as InternalServerError39,
25200
25270
  logger as logger100,
25201
25271
  makeCacheKey as makeCacheKey37,
25202
25272
  NotFoundError as NotFoundError27,
@@ -25210,7 +25280,7 @@ var facility_bookings_namespace_collection = "site.facilty-booking";
25210
25280
  function useSiteFacilityBookingRepo() {
25211
25281
  const db = useAtlas60.getDb();
25212
25282
  if (!db) {
25213
- throw new InternalServerError40("Unable to connect to server.");
25283
+ throw new InternalServerError39("Unable to connect to server.");
25214
25284
  }
25215
25285
  const collection = db.collection(facility_bookings_namespace_collection);
25216
25286
  const { delNamespace, getCache, setCache } = useCache39(
@@ -25220,7 +25290,7 @@ function useSiteFacilityBookingRepo() {
25220
25290
  try {
25221
25291
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
25222
25292
  } catch (error) {
25223
- throw new InternalServerError40("Failed to create index on site.");
25293
+ throw new InternalServerError39("Failed to create index on site.");
25224
25294
  }
25225
25295
  }
25226
25296
  async function add(value, session) {
@@ -25347,7 +25417,7 @@ function useSiteFacilityBookingRepo() {
25347
25417
  { session }
25348
25418
  );
25349
25419
  if (res.matchedCount === 0) {
25350
- throw new InternalServerError40(
25420
+ throw new InternalServerError39(
25351
25421
  "Unable to update site facility booking."
25352
25422
  );
25353
25423
  }
@@ -25380,7 +25450,7 @@ function useSiteFacilityBookingRepo() {
25380
25450
  };
25381
25451
  const res = await collection.updateOne({ _id }, { $set: updateValue });
25382
25452
  if (res.modifiedCount === 0) {
25383
- throw new InternalServerError40(
25453
+ throw new InternalServerError39(
25384
25454
  "Unable to delete site facility booking."
25385
25455
  );
25386
25456
  }
@@ -25573,14 +25643,17 @@ function useSiteFacilityBookingController() {
25573
25643
  }
25574
25644
  }
25575
25645
  async function deleteSiteFacilityBookingById(req, res, next) {
25576
- const validation = Joi72.string().hex().required();
25577
- const _id = req.params.id;
25578
- const { error } = validation.validate(_id);
25646
+ const schema2 = Joi72.object({
25647
+ _id: Joi72.string().hex().length(24).required()
25648
+ });
25649
+ const { error, value } = schema2.validate({ _id: req.params.id });
25579
25650
  if (error) {
25580
- logger101.log({ level: "error", message: error.message });
25581
- next(new BadRequestError120(error.message));
25651
+ const messages = error.details.map((d) => d.message).join(", ");
25652
+ logger101.log({ level: "error", message: messages });
25653
+ next(new BadRequestError120(messages));
25582
25654
  return;
25583
25655
  }
25656
+ const { _id } = value;
25584
25657
  try {
25585
25658
  await _deleteSiteFacilityBookingById(_id);
25586
25659
  res.status(200).json({ message: "Successfully deleted site facility booking." });
@@ -25672,7 +25745,7 @@ function MDocumentManagement(value) {
25672
25745
  // src/repositories/document-management.repo.ts
25673
25746
  import {
25674
25747
  BadRequestError as BadRequestError121,
25675
- InternalServerError as InternalServerError41,
25748
+ InternalServerError as InternalServerError40,
25676
25749
  logger as logger102,
25677
25750
  makeCacheKey as makeCacheKey38,
25678
25751
  NotFoundError as NotFoundError28,
@@ -25684,7 +25757,7 @@ import { ObjectId as ObjectId71 } from "mongodb";
25684
25757
  function useDocumentManagementRepo() {
25685
25758
  const db = useAtlas62.getDb();
25686
25759
  if (!db) {
25687
- throw new InternalServerError41("Unable to connect to server.");
25760
+ throw new InternalServerError40("Unable to connect to server.");
25688
25761
  }
25689
25762
  const namespace_collection = "documents";
25690
25763
  const collection = db.collection(namespace_collection);
@@ -25696,7 +25769,7 @@ function useDocumentManagementRepo() {
25696
25769
  type: "text"
25697
25770
  });
25698
25771
  } catch (error) {
25699
- throw new InternalServerError41("Failed to create text index on document.");
25772
+ throw new InternalServerError40("Failed to create text index on document.");
25700
25773
  }
25701
25774
  }
25702
25775
  async function add(value, session) {
@@ -25861,7 +25934,7 @@ function useDocumentManagementRepo() {
25861
25934
  };
25862
25935
  const res = await collection.updateOne({ _id }, { $set: updateValue });
25863
25936
  if (res.modifiedCount === 0) {
25864
- throw new InternalServerError41("Unable to update document.");
25937
+ throw new InternalServerError40("Unable to update document.");
25865
25938
  }
25866
25939
  delNamespace().then(() => {
25867
25940
  logger102.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -25894,7 +25967,7 @@ function useDocumentManagementRepo() {
25894
25967
  { session }
25895
25968
  );
25896
25969
  if (res.modifiedCount === 0) {
25897
- throw new InternalServerError41("Unable to delete document.");
25970
+ throw new InternalServerError40("Unable to delete document.");
25898
25971
  }
25899
25972
  delNamespace().then(() => {
25900
25973
  logger102.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -26321,7 +26394,7 @@ function MBulletinBoard(value) {
26321
26394
  // src/repositories/bulletin-board.repo.ts
26322
26395
  import {
26323
26396
  BadRequestError as BadRequestError124,
26324
- InternalServerError as InternalServerError42,
26397
+ InternalServerError as InternalServerError41,
26325
26398
  logger as logger104,
26326
26399
  makeCacheKey as makeCacheKey39,
26327
26400
  NotFoundError as NotFoundError30,
@@ -26334,7 +26407,7 @@ var bulletin_boards_namespace_collection = "bulletin-boards";
26334
26407
  function useBulletinBoardRepo() {
26335
26408
  const db = useAtlas64.getDb();
26336
26409
  if (!db) {
26337
- throw new InternalServerError42("Unable to connect to server.");
26410
+ throw new InternalServerError41("Unable to connect to server.");
26338
26411
  }
26339
26412
  const collection = db.collection(bulletin_boards_namespace_collection);
26340
26413
  const { delNamespace, getCache, setCache } = useCache41(
@@ -26344,7 +26417,7 @@ function useBulletinBoardRepo() {
26344
26417
  try {
26345
26418
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
26346
26419
  } catch (error) {
26347
- throw new InternalServerError42("Failed to create index on site.");
26420
+ throw new InternalServerError41("Failed to create index on site.");
26348
26421
  }
26349
26422
  }
26350
26423
  async function add(value, session) {
@@ -26482,7 +26555,7 @@ function useBulletinBoardRepo() {
26482
26555
  { session }
26483
26556
  );
26484
26557
  if (res.modifiedCount === 0) {
26485
- throw new InternalServerError42("Unable to update bulletin board.");
26558
+ throw new InternalServerError41("Unable to update bulletin board.");
26486
26559
  }
26487
26560
  delNamespace().then(() => {
26488
26561
  logger104.info(
@@ -26517,7 +26590,7 @@ function useBulletinBoardRepo() {
26517
26590
  { session }
26518
26591
  );
26519
26592
  if (res.modifiedCount === 0) {
26520
- throw new InternalServerError42("Unable to delete bulletin board.");
26593
+ throw new InternalServerError41("Unable to delete bulletin board.");
26521
26594
  }
26522
26595
  delNamespace().then(() => {
26523
26596
  logger104.info(
@@ -26964,9 +27037,9 @@ function MBillingItem(value) {
26964
27037
 
26965
27038
  // src/repositories/site-billing-item.repo.ts
26966
27039
  import {
26967
- AppError as AppError18,
27040
+ AppError as AppError17,
26968
27041
  BadRequestError as BadRequestError127,
26969
- InternalServerError as InternalServerError43,
27042
+ InternalServerError as InternalServerError42,
26970
27043
  logger as logger107,
26971
27044
  useAtlas as useAtlas66,
26972
27045
  useCache as useCache42,
@@ -26993,7 +27066,7 @@ function useSiteBillingItemRepo() {
26993
27066
  level: "error",
26994
27067
  message: error.message
26995
27068
  });
26996
- throw new InternalServerError43(
27069
+ throw new InternalServerError42(
26997
27070
  "Failed to create text index on site billing item."
26998
27071
  );
26999
27072
  }
@@ -27013,7 +27086,7 @@ function useSiteBillingItemRepo() {
27013
27086
  if (isDuplicated) {
27014
27087
  throw new BadRequestError127("Site Billing Item already exist.");
27015
27088
  }
27016
- if (error instanceof AppError18) {
27089
+ if (error instanceof AppError17) {
27017
27090
  throw error;
27018
27091
  } else {
27019
27092
  throw new Error("Failed to create Site Site Billing Item.");
@@ -27116,10 +27189,10 @@ function useSiteBillingItemRepo() {
27116
27189
  });
27117
27190
  return result;
27118
27191
  } catch (error) {
27119
- if (error instanceof AppError18) {
27192
+ if (error instanceof AppError17) {
27120
27193
  throw error;
27121
27194
  } else {
27122
- throw new InternalServerError43("Failed to get site billing item by id.");
27195
+ throw new InternalServerError42("Failed to get site billing item by id.");
27123
27196
  }
27124
27197
  }
27125
27198
  }
@@ -27174,7 +27247,7 @@ function useSiteBillingItemRepo() {
27174
27247
  };
27175
27248
  const res = await collection.updateOne({ _id }, { $set: updateValue });
27176
27249
  if (res.modifiedCount === 0) {
27177
- throw new InternalServerError43("Unable to delete site billing item.");
27250
+ throw new InternalServerError42("Unable to delete site billing item.");
27178
27251
  }
27179
27252
  delCachedData();
27180
27253
  return res.modifiedCount;
@@ -27217,9 +27290,9 @@ import {
27217
27290
 
27218
27291
  // src/repositories/site-billing-configuration.repo.ts
27219
27292
  import {
27220
- AppError as AppError19,
27293
+ AppError as AppError18,
27221
27294
  BadRequestError as BadRequestError129,
27222
- InternalServerError as InternalServerError44,
27295
+ InternalServerError as InternalServerError43,
27223
27296
  logger as logger109,
27224
27297
  useAtlas as useAtlas67,
27225
27298
  useCache as useCache43,
@@ -27366,7 +27439,7 @@ function useSiteBillingConfigurationRepo() {
27366
27439
  level: "error",
27367
27440
  message: error.message
27368
27441
  });
27369
- throw new InternalServerError44(
27442
+ throw new InternalServerError43(
27370
27443
  "Failed to create text index on site billing configuration."
27371
27444
  );
27372
27445
  }
@@ -27386,7 +27459,7 @@ function useSiteBillingConfigurationRepo() {
27386
27459
  if (isDuplicated) {
27387
27460
  throw new BadRequestError129("Site Billing Configuration already exist.");
27388
27461
  }
27389
- if (error instanceof AppError19) {
27462
+ if (error instanceof AppError18) {
27390
27463
  throw error;
27391
27464
  } else {
27392
27465
  throw new Error("Failed to create Site Site Billing Configuration.");
@@ -27475,10 +27548,10 @@ function useSiteBillingConfigurationRepo() {
27475
27548
  });
27476
27549
  return result;
27477
27550
  } catch (error) {
27478
- if (error instanceof AppError19) {
27551
+ if (error instanceof AppError18) {
27479
27552
  throw error;
27480
27553
  } else {
27481
- throw new InternalServerError44(
27554
+ throw new InternalServerError43(
27482
27555
  "Failed to get site billing configuration by id."
27483
27556
  );
27484
27557
  }
@@ -27535,7 +27608,7 @@ function useSiteBillingConfigurationRepo() {
27535
27608
  };
27536
27609
  const res = await collection.updateOne({ _id }, { $set: updateValue });
27537
27610
  if (res.modifiedCount === 0) {
27538
- throw new InternalServerError44(
27611
+ throw new InternalServerError43(
27539
27612
  "Unable to delete site billing configuration."
27540
27613
  );
27541
27614
  }
@@ -28153,7 +28226,7 @@ function MEventManagement(value) {
28153
28226
  // src/repositories/event-management.repo.ts
28154
28227
  import {
28155
28228
  BadRequestError as BadRequestError134,
28156
- InternalServerError as InternalServerError45,
28229
+ InternalServerError as InternalServerError44,
28157
28230
  logger as logger114,
28158
28231
  makeCacheKey as makeCacheKey42,
28159
28232
  NotFoundError as NotFoundError33,
@@ -28166,7 +28239,7 @@ var events_namespace_collection = "event-management";
28166
28239
  function useEventManagementRepo() {
28167
28240
  const db = useAtlas70.getDb();
28168
28241
  if (!db) {
28169
- throw new InternalServerError45("Unable to connect to server.");
28242
+ throw new InternalServerError44("Unable to connect to server.");
28170
28243
  }
28171
28244
  const collection = db.collection(events_namespace_collection);
28172
28245
  const { delNamespace, getCache, setCache } = useCache44(
@@ -28176,7 +28249,7 @@ function useEventManagementRepo() {
28176
28249
  try {
28177
28250
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
28178
28251
  } catch (error) {
28179
- throw new InternalServerError45(
28252
+ throw new InternalServerError44(
28180
28253
  "Failed to create index on event management."
28181
28254
  );
28182
28255
  }
@@ -28188,7 +28261,7 @@ function useEventManagementRepo() {
28188
28261
  description: "text"
28189
28262
  });
28190
28263
  } catch (error) {
28191
- throw new InternalServerError45(
28264
+ throw new InternalServerError44(
28192
28265
  "Failed to create text index on event management."
28193
28266
  );
28194
28267
  }
@@ -28351,7 +28424,7 @@ function useEventManagementRepo() {
28351
28424
  { session }
28352
28425
  );
28353
28426
  if (res.modifiedCount === 0) {
28354
- throw new InternalServerError45("Unable to update event.");
28427
+ throw new InternalServerError44("Unable to update event.");
28355
28428
  }
28356
28429
  delNamespace().then(() => {
28357
28430
  logger114.info(
@@ -28382,7 +28455,7 @@ function useEventManagementRepo() {
28382
28455
  };
28383
28456
  const res = await collection.updateOne({ _id }, { $set: updateValue });
28384
28457
  if (res.modifiedCount === 0) {
28385
- throw new InternalServerError45("Unable to delete event.");
28458
+ throw new InternalServerError44("Unable to delete event.");
28386
28459
  }
28387
28460
  delNamespace().then(() => {
28388
28461
  logger114.info(
@@ -28811,9 +28884,9 @@ function MUnitBilling(value) {
28811
28884
 
28812
28885
  // src/repositories/site-unit-billing.repo.ts
28813
28886
  import {
28814
- AppError as AppError20,
28887
+ AppError as AppError19,
28815
28888
  BadRequestError as BadRequestError137,
28816
- InternalServerError as InternalServerError46,
28889
+ InternalServerError as InternalServerError45,
28817
28890
  logger as logger117,
28818
28891
  useAtlas as useAtlas72,
28819
28892
  useCache as useCache45,
@@ -28840,7 +28913,7 @@ function useSiteUnitBillingRepo() {
28840
28913
  level: "error",
28841
28914
  message: error.message
28842
28915
  });
28843
- throw new InternalServerError46(
28916
+ throw new InternalServerError45(
28844
28917
  "Failed to create text index on site unit billing."
28845
28918
  );
28846
28919
  }
@@ -28869,7 +28942,7 @@ function useSiteUnitBillingRepo() {
28869
28942
  if (isDuplicated) {
28870
28943
  throw new BadRequestError137("Site Unit Billing already exist.");
28871
28944
  }
28872
- if (error instanceof AppError20) {
28945
+ if (error instanceof AppError19) {
28873
28946
  throw error;
28874
28947
  } else {
28875
28948
  throw new Error("Failed to create Site Unit Billing");
@@ -29025,10 +29098,10 @@ function useSiteUnitBillingRepo() {
29025
29098
  });
29026
29099
  return result;
29027
29100
  } catch (error) {
29028
- if (error instanceof AppError20) {
29101
+ if (error instanceof AppError19) {
29029
29102
  throw error;
29030
29103
  } else {
29031
- throw new InternalServerError46("Failed to get site unit billing by id.");
29104
+ throw new InternalServerError45("Failed to get site unit billing by id.");
29032
29105
  }
29033
29106
  }
29034
29107
  }
@@ -29165,7 +29238,7 @@ function useSiteUnitBillingRepo() {
29165
29238
  };
29166
29239
  const res = await collection.updateOne({ _id }, { $set: updateValue });
29167
29240
  if (res.modifiedCount === 0) {
29168
- throw new InternalServerError46("Unable to delete site unit billing.");
29241
+ throw new InternalServerError45("Unable to delete site unit billing.");
29169
29242
  }
29170
29243
  delCachedData();
29171
29244
  return res.modifiedCount;
@@ -29653,7 +29726,7 @@ var MAccessCard = class {
29653
29726
 
29654
29727
  // src/repositories/access-management.repo.ts
29655
29728
  import {
29656
- InternalServerError as InternalServerError47,
29729
+ InternalServerError as InternalServerError46,
29657
29730
  paginate as paginate38,
29658
29731
  useAtlas as useAtlas74
29659
29732
  } from "@7365admin1/node-server-utils";
@@ -29663,6 +29736,7 @@ import { ObjectId as ObjectId84 } from "mongodb";
29663
29736
  import fs from "fs";
29664
29737
  import path2 from "path";
29665
29738
  import axios from "axios";
29739
+ import { parseStringPromise } from "xml2js";
29666
29740
  import crypto from "crypto";
29667
29741
  var ALGORITHM = "aes-256-gcm";
29668
29742
  var SECRET_KEY = crypto.createSecretKey(
@@ -29763,9 +29837,39 @@ var formatEntryPassDate = (date) => {
29763
29837
  const day = String(newDate.getDate()).padStart(2, "0");
29764
29838
  return `${year}${month}${day}`;
29765
29839
  };
29840
+ async function removeAccessGroup({ cardNo, staffNo, url }) {
29841
+ try {
29842
+ const commands = readTemplate("delete-qr-card", {
29843
+ staffNo,
29844
+ // dateOfJoin: formatEntryPassDate(cardDetails.startDate),
29845
+ // accessLevel: cardDetails.accessLevel,
29846
+ cardNo
29847
+ // pin: cardDetails.pin,
29848
+ // startDate: formatEntryPassDate(cardDetails.startDate),
29849
+ // endDate: formatEntryPassDate(cardDetails.endDate),
29850
+ // cardType: 0,
29851
+ // isActivated: cardDetails.isActivated ? 1 : 0,
29852
+ // isAntiPassBack: cardDetails.isAntiPassBack ? 1 : 0,
29853
+ // isLiftCard: cardDetails.isLiftCard ? 1 : 0,
29854
+ // isLiftActivate: cardDetails.isLiftCard ? 1 : 0,
29855
+ // liftAccessLevel: cardDetails.liftAccessLevel || 1,
29856
+ // liftAccessStartDate: formatEntryPassDate(cardDetails.liftAccessStartDate) || "19770510",
29857
+ // liftAccessEndDate: formatEntryPassDate(cardDetails.liftAccessEndDate) || "19770510",
29858
+ });
29859
+ const response = await sendCommand(commands, url);
29860
+ const result = await parseStringPromise(response, { explicitArray: false });
29861
+ console.log(result.RESULT.$.STCODE);
29862
+ console.log(commands);
29863
+ if (result && result.RESULT.$.STCODE !== "0") {
29864
+ throw new Error("Command failed, server error.");
29865
+ }
29866
+ } catch (error) {
29867
+ console.log(error);
29868
+ }
29869
+ }
29766
29870
 
29767
29871
  // src/repositories/access-management.repo.ts
29768
- import { parseStringPromise } from "xml2js";
29872
+ import { parseStringPromise as parseStringPromise2 } from "xml2js";
29769
29873
 
29770
29874
  // src/utils/rsa-encryption.ts
29771
29875
  import * as crypto2 from "crypto";
@@ -29850,14 +29954,14 @@ function UseAccessManagementRepo() {
29850
29954
  function collection() {
29851
29955
  const db = useAtlas74.getDb();
29852
29956
  if (!db) {
29853
- throw new InternalServerError47("Unable to connect to server.");
29957
+ throw new InternalServerError46("Unable to connect to server.");
29854
29958
  }
29855
29959
  return db.collection("access-cards");
29856
29960
  }
29857
29961
  function collectionName(collectionName2) {
29858
29962
  const db = useAtlas74.getDb();
29859
29963
  if (!db) {
29860
- throw new InternalServerError47("Unable to connect to server.");
29964
+ throw new InternalServerError46("Unable to connect to server.");
29861
29965
  }
29862
29966
  return db.collection(collectionName2);
29863
29967
  }
@@ -30774,7 +30878,7 @@ function UseAccessManagementRepo() {
30774
30878
  return readTemplate(`${item.accessLevel !== null ? "add-card" : "add-card-lift"}`, { ...command });
30775
30879
  }).flat();
30776
30880
  const response = await sendCommand(commands.join("").toString(), params.acm_url);
30777
- const result = await parseStringPromise(response, { explicitArray: false });
30881
+ const result = await parseStringPromise2(response, { explicitArray: false });
30778
30882
  if (result && result.RESULT.$.STCODE !== "0") {
30779
30883
  throw new Error("Command failed, server error.");
30780
30884
  }
@@ -31635,7 +31739,7 @@ function UseAccessManagementRepo() {
31635
31739
  return readTemplate(`${item.accessLevel !== null ? "add-card" : "add-card-lift"}`, { ...command });
31636
31740
  }).flat();
31637
31741
  const response = await sendCommand(commands.join("").toString(), acm_url);
31638
- serverResult = await parseStringPromise(response, { explicitArray: false });
31742
+ serverResult = await parseStringPromise2(response, { explicitArray: false });
31639
31743
  if (result && serverResult.RESULT.$.STCODE !== "0") {
31640
31744
  throw new Error("Command failed, server error.");
31641
31745
  }
@@ -31731,7 +31835,7 @@ function UseAccessManagementRepo() {
31731
31835
  import Joi85 from "joi";
31732
31836
 
31733
31837
  // src/services/access-management.service.ts
31734
- import { parseStringPromise as parseStringPromise2 } from "xml2js";
31838
+ import { parseStringPromise as parseStringPromise3 } from "xml2js";
31735
31839
  import { Readable } from "stream";
31736
31840
  import * as xlsx from "xlsx";
31737
31841
  function useAccessManagementSvc() {
@@ -31794,7 +31898,7 @@ function useAccessManagementSvc() {
31794
31898
  try {
31795
31899
  const command = readTemplate("door-levels");
31796
31900
  const response = await sendCommand(command, params.acm_url);
31797
- const res = await parseStringPromise2(response, { explicitArray: false });
31901
+ const res = await parseStringPromise3(response, { explicitArray: false });
31798
31902
  const format = await formatDoorAccessLevels(res);
31799
31903
  return format;
31800
31904
  } catch (err) {
@@ -31805,7 +31909,7 @@ function useAccessManagementSvc() {
31805
31909
  try {
31806
31910
  const command = readTemplate("lift-levels");
31807
31911
  const response = await sendCommand(command, params.acm_url);
31808
- const res = await parseStringPromise2(response, { explicitArray: false });
31912
+ const res = await parseStringPromise3(response, { explicitArray: false });
31809
31913
  const format = await formatLiftAccessLevels(res);
31810
31914
  return format;
31811
31915
  } catch (error) {
@@ -31816,7 +31920,7 @@ function useAccessManagementSvc() {
31816
31920
  try {
31817
31921
  const command = readTemplate("access-group");
31818
31922
  const response = await sendCommand(command, params.acm_url);
31819
- const res = await parseStringPromise2(response, { explicitArray: false });
31923
+ const res = await parseStringPromise3(response, { explicitArray: false });
31820
31924
  const format = await formatAccessGroup(res);
31821
31925
  return format;
31822
31926
  } catch (err) {
@@ -32862,6 +32966,9 @@ function useAccessManagementController() {
32862
32966
  });
32863
32967
  }
32864
32968
  };
32969
+ const removeAccessCard = async ({ cardNo, staffNo, url }) => {
32970
+ return removeAccessGroup({ cardNo, staffNo, url });
32971
+ };
32865
32972
  return {
32866
32973
  addPhysicalCard,
32867
32974
  addNonPhysicalCard,
@@ -32892,7 +32999,8 @@ function useAccessManagementController() {
32892
32999
  vmsgenerateQrCodes,
32893
33000
  addVisitorAccessCard,
32894
33001
  signQrCode,
32895
- checkoutVisitor
33002
+ checkoutVisitor,
33003
+ removeAccessCard
32896
33004
  };
32897
33005
  }
32898
33006
 
@@ -32957,7 +33065,7 @@ function MNfcPatrolTag(value) {
32957
33065
  // src/repositories/nfc-patrol-tag.repository.ts
32958
33066
  import {
32959
33067
  BadRequestError as BadRequestError142,
32960
- InternalServerError as InternalServerError48,
33068
+ InternalServerError as InternalServerError47,
32961
33069
  logger as logger121,
32962
33070
  makeCacheKey as makeCacheKey45,
32963
33071
  paginate as paginate39,
@@ -32968,7 +33076,7 @@ import { ObjectId as ObjectId86 } from "mongodb";
32968
33076
  function useNfcPatrolTagRepo() {
32969
33077
  const db = useAtlas75.getDb();
32970
33078
  if (!db) {
32971
- throw new InternalServerError48("Unable to connect to server.");
33079
+ throw new InternalServerError47("Unable to connect to server.");
32972
33080
  }
32973
33081
  const namespace_collection = "nfc-patrol-tags";
32974
33082
  const namespace_collection_nfc_patrol_routes = "nfc-patrol-routes";
@@ -32990,7 +33098,7 @@ function useNfcPatrolTagRepo() {
32990
33098
  { key: { site: 1 } }
32991
33099
  ]);
32992
33100
  } catch (error) {
32993
- throw new InternalServerError48(
33101
+ throw new InternalServerError47(
32994
33102
  "Failed to create index on nfc patrol tags."
32995
33103
  );
32996
33104
  }
@@ -33102,7 +33210,7 @@ function useNfcPatrolTagRepo() {
33102
33210
  session
33103
33211
  });
33104
33212
  if (res.modifiedCount === 0) {
33105
- throw new InternalServerError48(
33213
+ throw new InternalServerError47(
33106
33214
  `Unable to ${updateType} NFC Patrol Tag.`
33107
33215
  );
33108
33216
  }
@@ -33415,7 +33523,7 @@ function MOccurrenceBook(value) {
33415
33523
  // src/repositories/occurrence-book.repo.ts
33416
33524
  import {
33417
33525
  BadRequestError as BadRequestError145,
33418
- InternalServerError as InternalServerError49,
33526
+ InternalServerError as InternalServerError48,
33419
33527
  logger as logger123,
33420
33528
  makeCacheKey as makeCacheKey46,
33421
33529
  NotFoundError as NotFoundError37,
@@ -33424,10 +33532,11 @@ import {
33424
33532
  useCache as useCache48
33425
33533
  } from "@7365admin1/node-server-utils";
33426
33534
  import { ObjectId as ObjectId88 } from "mongodb";
33535
+ var occurrence_book_namespace_collection = "occurrence-books";
33427
33536
  function useOccurrenceBookRepo() {
33428
33537
  const db = useAtlas77.getDb();
33429
33538
  if (!db) {
33430
- throw new InternalServerError49("Unable to connect to server.");
33539
+ throw new InternalServerError48("Unable to connect to server.");
33431
33540
  }
33432
33541
  async function createIndexes() {
33433
33542
  try {
@@ -33435,7 +33544,7 @@ function useOccurrenceBookRepo() {
33435
33544
  { key: { site: 1, status: 1, date: 1, closedAt: 1 } }
33436
33545
  ]);
33437
33546
  } catch (error) {
33438
- throw new InternalServerError49(
33547
+ throw new InternalServerError48(
33439
33548
  "Failed to create index on occurrence books."
33440
33549
  );
33441
33550
  }
@@ -33446,23 +33555,26 @@ function useOccurrenceBookRepo() {
33446
33555
  entryCounter: "text"
33447
33556
  });
33448
33557
  } catch (error) {
33449
- throw new InternalServerError49(
33558
+ throw new InternalServerError48(
33450
33559
  "Failed to create text index on occurrence books."
33451
33560
  );
33452
33561
  }
33453
33562
  }
33454
- const namespace_collection = "occurrence-books";
33455
- const collection = db.collection(namespace_collection);
33456
- const { delNamespace, getCache, setCache } = useCache48(namespace_collection);
33563
+ const collection = db.collection(occurrence_book_namespace_collection);
33564
+ const { delNamespace, getCache, setCache } = useCache48(
33565
+ occurrence_book_namespace_collection
33566
+ );
33457
33567
  async function add(value, session) {
33458
33568
  try {
33459
33569
  value = MOccurrenceBook(value);
33460
33570
  const res = await collection.insertOne(value, { session });
33461
33571
  delNamespace().then(() => {
33462
- logger123.info(`Cache cleared for namespace: ${namespace_collection}`);
33572
+ logger123.info(
33573
+ `Cache cleared for namespace: ${occurrence_book_namespace_collection}`
33574
+ );
33463
33575
  }).catch((err) => {
33464
33576
  logger123.error(
33465
- `Failed to clear cache for namespace: ${namespace_collection}`,
33577
+ `Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
33466
33578
  err
33467
33579
  );
33468
33580
  });
@@ -33545,7 +33657,10 @@ function useOccurrenceBookRepo() {
33545
33657
  query.$text = { $search: search };
33546
33658
  cacheOptions.search = search;
33547
33659
  }
33548
- const cacheKey = makeCacheKey46(namespace_collection, cacheOptions);
33660
+ const cacheKey = makeCacheKey46(
33661
+ occurrence_book_namespace_collection,
33662
+ cacheOptions
33663
+ );
33549
33664
  const cachedData = await getCache(cacheKey);
33550
33665
  if (cachedData) {
33551
33666
  logger123.info(`Cache hit for key: ${cacheKey}`);
@@ -33579,7 +33694,9 @@ function useOccurrenceBookRepo() {
33579
33694
  } catch (error) {
33580
33695
  throw new BadRequestError145("Invalid occurrence book ID format.");
33581
33696
  }
33582
- const cacheKey = makeCacheKey46(namespace_collection, { _id });
33697
+ const cacheKey = makeCacheKey46(occurrence_book_namespace_collection, {
33698
+ _id
33699
+ });
33583
33700
  const cachedData = await getCache(cacheKey);
33584
33701
  if (cachedData) {
33585
33702
  logger123.info(`Cache hit for key: ${cacheKey}`);
@@ -33614,15 +33731,17 @@ function useOccurrenceBookRepo() {
33614
33731
  { session }
33615
33732
  );
33616
33733
  if (res.modifiedCount === 0) {
33617
- throw new InternalServerError49(
33734
+ throw new InternalServerError48(
33618
33735
  "Unable to update daily occurrence book."
33619
33736
  );
33620
33737
  }
33621
33738
  delNamespace().then(() => {
33622
- logger123.info(`Cache cleared for namespace: ${namespace_collection}`);
33739
+ logger123.info(
33740
+ `Cache cleared for namespace: ${occurrence_book_namespace_collection}`
33741
+ );
33623
33742
  }).catch((err) => {
33624
33743
  logger123.error(
33625
- `Failed to clear cache for namespace: ${namespace_collection}`,
33744
+ `Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
33626
33745
  err
33627
33746
  );
33628
33747
  });
@@ -33645,13 +33764,15 @@ function useOccurrenceBookRepo() {
33645
33764
  };
33646
33765
  const res = await collection.updateOne({ _id }, { $set: updateValue });
33647
33766
  if (res.modifiedCount === 0) {
33648
- throw new InternalServerError49("Unable to delete occurrence book.");
33767
+ throw new InternalServerError48("Unable to delete occurrence book.");
33649
33768
  }
33650
33769
  delNamespace().then(() => {
33651
- logger123.info(`Cache cleared for namespace: ${namespace_collection}`);
33770
+ logger123.info(
33771
+ `Cache cleared for namespace: ${occurrence_book_namespace_collection}`
33772
+ );
33652
33773
  }).catch((err) => {
33653
33774
  logger123.error(
33654
- `Failed to clear cache for namespace: ${namespace_collection}`,
33775
+ `Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
33655
33776
  err
33656
33777
  );
33657
33778
  });
@@ -33670,13 +33791,15 @@ function useOccurrenceBookRepo() {
33670
33791
  { session }
33671
33792
  );
33672
33793
  if (res.modifiedCount === 0) {
33673
- throw new InternalServerError49("Unable to close daily occurrence book.");
33794
+ throw new InternalServerError48("Unable to close daily occurrence book.");
33674
33795
  }
33675
33796
  delNamespace().then(() => {
33676
- logger123.info(`Cache cleared for namespace: ${namespace_collection}`);
33797
+ logger123.info(
33798
+ `Cache cleared for namespace: ${occurrence_book_namespace_collection}`
33799
+ );
33677
33800
  }).catch((err) => {
33678
33801
  logger123.error(
33679
- `Failed to clear cache for namespace: ${namespace_collection}`,
33802
+ `Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
33680
33803
  err
33681
33804
  );
33682
33805
  });
@@ -33685,6 +33808,47 @@ function useOccurrenceBookRepo() {
33685
33808
  throw error;
33686
33809
  }
33687
33810
  }
33811
+ async function bulkCreate(payloads, session) {
33812
+ try {
33813
+ if (!payloads.length) {
33814
+ return { insertedCount: 0 };
33815
+ }
33816
+ const chunkSize = 500;
33817
+ let totalInserted = 0;
33818
+ for (let i = 0; i < payloads.length; i += chunkSize) {
33819
+ const chunk = payloads.slice(i, i + chunkSize);
33820
+ const operations = chunk.map((item) => ({
33821
+ insertOne: {
33822
+ document: {
33823
+ ...item,
33824
+ createdAt: (/* @__PURE__ */ new Date()).toISOString(),
33825
+ updatedAt: "",
33826
+ deletedAt: ""
33827
+ }
33828
+ }
33829
+ }));
33830
+ const result = await collection.bulkWrite(operations, { session });
33831
+ totalInserted += result.insertedCount || 0;
33832
+ }
33833
+ logger123.info(
33834
+ `Bulk insert successful: ${totalInserted} occurrence books created.`
33835
+ );
33836
+ delNamespace().then(() => {
33837
+ logger123.info(
33838
+ `Cache cleared for namespace: ${occurrence_book_namespace_collection}`
33839
+ );
33840
+ }).catch((err) => {
33841
+ logger123.error(
33842
+ `Failed to clear cache for namespace: ${occurrence_book_namespace_collection}`,
33843
+ err
33844
+ );
33845
+ });
33846
+ return { insertedCount: totalInserted };
33847
+ } catch (error) {
33848
+ logger123.error("Bulk insert failed for occurrence books", error);
33849
+ throw error;
33850
+ }
33851
+ }
33688
33852
  return {
33689
33853
  add,
33690
33854
  getAll,
@@ -33693,7 +33857,8 @@ function useOccurrenceBookRepo() {
33693
33857
  deleteOccurrenceBookById,
33694
33858
  closeOccurrenceBooks,
33695
33859
  createIndexes,
33696
- createTextIndex
33860
+ createTextIndex,
33861
+ bulkCreate
33697
33862
  };
33698
33863
  }
33699
33864
 
@@ -33703,14 +33868,18 @@ function useOccurrenceBookService() {
33703
33868
  const {
33704
33869
  add: _add,
33705
33870
  updateOccurrenceBookById: _updateOccurrenceBookById,
33706
- closeOccurrenceBooks: _closeOccurrenceBooks
33871
+ closeOccurrenceBooks: _closeOccurrenceBooks,
33872
+ bulkCreate: _bulkCreate
33707
33873
  } = useOccurrenceBookRepo();
33708
33874
  const {
33709
33875
  add: _addOccurrenceCounter,
33710
33876
  incrementByType: _incrementByType,
33711
33877
  getByType: _getByType
33712
33878
  } = useCounterRepo();
33713
- const { getAllSites: _getAllSites } = useSiteRepo();
33879
+ const {
33880
+ getAllSites: _getAllSites,
33881
+ getAllSitesUnpaginated: _getAllSitesUnpaginated
33882
+ } = useSiteRepo();
33714
33883
  async function add(value) {
33715
33884
  const session = useAtlas78.getClient()?.startSession();
33716
33885
  session?.startTransaction();
@@ -33748,39 +33917,31 @@ function useOccurrenceBookService() {
33748
33917
  }
33749
33918
  }
33750
33919
  async function processCreateDOB() {
33751
- const limit = 100;
33752
33920
  const counterName = "occurrence-book";
33753
- let page = 1;
33754
33921
  let entryCounter = 0;
33755
33922
  const session = useAtlas78.getClient()?.startSession();
33756
- session?.startTransaction();
33757
- const existingCounter = await _getByType(counterName);
33758
- if (!existingCounter) {
33759
- await _addOccurrenceCounter(counterName);
33760
- } else {
33761
- await _incrementByType(counterName, session);
33762
- entryCounter = existingCounter.count + 1;
33763
- }
33764
- const baseDate = /* @__PURE__ */ new Date();
33765
- baseDate.setUTCMinutes(0, 0, 0);
33766
- const closedAt = new Date(baseDate);
33767
- closedAt.setUTCDate(closedAt.getUTCDate() + 3);
33768
33923
  try {
33769
- while (true) {
33770
- const sites = await _getAllSites({ page, limit });
33771
- if (sites.items.length === 0)
33772
- break;
33773
- for (const site of sites.items) {
33774
- const occurenceBookPayload = {
33775
- site: site._id,
33776
- date: baseDate.toISOString(),
33777
- closedAt: closedAt.toISOString(),
33778
- entryCounter
33779
- };
33780
- await _add(occurenceBookPayload, session);
33781
- }
33782
- page++;
33783
- }
33924
+ session?.startTransaction();
33925
+ const existingCounter = await _getByType(counterName);
33926
+ if (!existingCounter) {
33927
+ await _addOccurrenceCounter(counterName);
33928
+ entryCounter = 1;
33929
+ } else {
33930
+ entryCounter = existingCounter.count + 1;
33931
+ await _incrementByType(counterName);
33932
+ }
33933
+ const baseDate = /* @__PURE__ */ new Date();
33934
+ baseDate.setUTCMinutes(0, 0, 0);
33935
+ const closedAt = new Date(baseDate);
33936
+ closedAt.setUTCDate(closedAt.getUTCDate() + 3);
33937
+ const sites = await _getAllSitesUnpaginated();
33938
+ const payloads = sites.map((site) => ({
33939
+ site: site._id,
33940
+ date: baseDate.toISOString(),
33941
+ closedAt: closedAt.toISOString(),
33942
+ entryCounter
33943
+ }));
33944
+ await _bulkCreate(payloads, session);
33784
33945
  await session?.commitTransaction();
33785
33946
  } catch (err) {
33786
33947
  await session?.abortTransaction();
@@ -34025,7 +34186,7 @@ function MBulletinVideo(value) {
34025
34186
  // src/repositories/bulletin-video.repo.ts
34026
34187
  import {
34027
34188
  BadRequestError as BadRequestError147,
34028
- InternalServerError as InternalServerError50,
34189
+ InternalServerError as InternalServerError49,
34029
34190
  logger as logger125,
34030
34191
  makeCacheKey as makeCacheKey47,
34031
34192
  NotFoundError as NotFoundError38,
@@ -34037,13 +34198,13 @@ import { ObjectId as ObjectId90 } from "mongodb";
34037
34198
  function useBulletinVideoRepo() {
34038
34199
  const db = useAtlas79.getDb();
34039
34200
  if (!db) {
34040
- throw new InternalServerError50("Unable to connect to server.");
34201
+ throw new InternalServerError49("Unable to connect to server.");
34041
34202
  }
34042
34203
  async function createIndexes() {
34043
34204
  try {
34044
34205
  await collection.createIndexes([{ key: { site: 1 } }]);
34045
34206
  } catch (error) {
34046
- throw new InternalServerError50(
34207
+ throw new InternalServerError49(
34047
34208
  "Failed to create index on bulletin videos."
34048
34209
  );
34049
34210
  }
@@ -34180,7 +34341,7 @@ function useBulletinVideoRepo() {
34180
34341
  { session }
34181
34342
  );
34182
34343
  if (res.modifiedCount === 0) {
34183
- throw new InternalServerError50("Unable to update bulletin board.");
34344
+ throw new InternalServerError49("Unable to update bulletin board.");
34184
34345
  }
34185
34346
  delNamespace().then(() => {
34186
34347
  logger125.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -34213,7 +34374,7 @@ function useBulletinVideoRepo() {
34213
34374
  { session }
34214
34375
  );
34215
34376
  if (res.modifiedCount === 0) {
34216
- throw new InternalServerError50("Unable to delete bulletin video.");
34377
+ throw new InternalServerError49("Unable to delete bulletin video.");
34217
34378
  }
34218
34379
  delNamespace().then(() => {
34219
34380
  logger125.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -34577,9 +34738,9 @@ function MStatementOfAccount(value) {
34577
34738
 
34578
34739
  // src/repositories/site-soa.repo.ts
34579
34740
  import {
34580
- AppError as AppError21,
34741
+ AppError as AppError20,
34581
34742
  BadRequestError as BadRequestError150,
34582
- InternalServerError as InternalServerError51,
34743
+ InternalServerError as InternalServerError50,
34583
34744
  logger as logger128,
34584
34745
  useAtlas as useAtlas81,
34585
34746
  useCache as useCache50,
@@ -34606,7 +34767,7 @@ function useStatementOfAccountRepo() {
34606
34767
  level: "error",
34607
34768
  message: error.message
34608
34769
  });
34609
- throw new InternalServerError51("Failed to create text index on site SOA.");
34770
+ throw new InternalServerError50("Failed to create text index on site SOA.");
34610
34771
  }
34611
34772
  }
34612
34773
  async function add(value, session) {
@@ -34624,7 +34785,7 @@ function useStatementOfAccountRepo() {
34624
34785
  if (isDuplicated) {
34625
34786
  throw new BadRequestError150("Site SOA already exist.");
34626
34787
  }
34627
- if (error instanceof AppError21) {
34788
+ if (error instanceof AppError20) {
34628
34789
  throw error;
34629
34790
  } else {
34630
34791
  throw new Error("Failed to create Site SOA");
@@ -34753,10 +34914,10 @@ function useStatementOfAccountRepo() {
34753
34914
  });
34754
34915
  return result;
34755
34916
  } catch (error) {
34756
- if (error instanceof AppError21) {
34917
+ if (error instanceof AppError20) {
34757
34918
  throw error;
34758
34919
  } else {
34759
- throw new InternalServerError51("Failed to get soa by id.");
34920
+ throw new InternalServerError50("Failed to get soa by id.");
34760
34921
  }
34761
34922
  }
34762
34923
  }
@@ -34793,7 +34954,7 @@ function useStatementOfAccountRepo() {
34793
34954
  };
34794
34955
  const res = await collection.updateOne({ _id }, { $set: updateValue });
34795
34956
  if (res.modifiedCount === 0) {
34796
- throw new InternalServerError51("Unable to delete site SOA.");
34957
+ throw new InternalServerError50("Unable to delete site SOA.");
34797
34958
  }
34798
34959
  delCachedData();
34799
34960
  return res.modifiedCount;
@@ -34816,7 +34977,7 @@ function useStatementOfAccountRepo() {
34816
34977
  delCachedData();
34817
34978
  return res;
34818
34979
  } catch (error) {
34819
- throw new InternalServerError51("Failed to update soa request.");
34980
+ throw new InternalServerError50("Failed to update soa request.");
34820
34981
  }
34821
34982
  }
34822
34983
  function delCachedData() {
@@ -35353,7 +35514,7 @@ function MEntryPassSettings(value) {
35353
35514
  // src/repositories/site-entrypass-settings.repo.ts
35354
35515
  import {
35355
35516
  BadRequestError as BadRequestError154,
35356
- InternalServerError as InternalServerError52,
35517
+ InternalServerError as InternalServerError51,
35357
35518
  logger as logger132,
35358
35519
  makeCacheKey as makeCacheKey49,
35359
35520
  NotFoundError as NotFoundError40,
@@ -35365,7 +35526,7 @@ import { ObjectId as ObjectId94 } from "mongodb";
35365
35526
  function useEntryPassSettingsRepo() {
35366
35527
  const db = useAtlas83.getDb();
35367
35528
  if (!db) {
35368
- throw new InternalServerError52("Unable to connect to server.");
35529
+ throw new InternalServerError51("Unable to connect to server.");
35369
35530
  }
35370
35531
  const namespace_collection = "site.entrypass-settings";
35371
35532
  const collection = db.collection(namespace_collection);
@@ -35376,7 +35537,7 @@ function useEntryPassSettingsRepo() {
35376
35537
  name: "text"
35377
35538
  });
35378
35539
  } catch (error) {
35379
- throw new InternalServerError52(
35540
+ throw new InternalServerError51(
35380
35541
  "Failed to create text index on entry pass settings."
35381
35542
  );
35382
35543
  }
@@ -35549,7 +35710,7 @@ function useEntryPassSettingsRepo() {
35549
35710
  };
35550
35711
  const res = await collection.updateOne({ _id }, { $set: updateValue });
35551
35712
  if (res.modifiedCount === 0) {
35552
- throw new InternalServerError52("Unable to update entry pass settings.");
35713
+ throw new InternalServerError51("Unable to update entry pass settings.");
35553
35714
  }
35554
35715
  delNamespace().then(() => {
35555
35716
  logger132.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -35582,7 +35743,7 @@ function useEntryPassSettingsRepo() {
35582
35743
  { session }
35583
35744
  );
35584
35745
  if (res.modifiedCount === 0) {
35585
- throw new InternalServerError52("Unable to delete entry pass settings.");
35746
+ throw new InternalServerError51("Unable to delete entry pass settings.");
35586
35747
  }
35587
35748
  delNamespace().then(() => {
35588
35749
  logger132.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -35677,7 +35838,7 @@ function useEntryPassSettingsRepo() {
35677
35838
  };
35678
35839
  const res = await collection.updateOne({ site }, { $set: updateValue });
35679
35840
  if (res.modifiedCount === 0) {
35680
- throw new InternalServerError52("Unable to update entry pass settings.");
35841
+ throw new InternalServerError51("Unable to update entry pass settings.");
35681
35842
  }
35682
35843
  delNamespace().then(() => {
35683
35844
  logger132.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -35927,7 +36088,7 @@ function useEntryPassSettingsController() {
35927
36088
 
35928
36089
  // src/repositories/dashboard.repo.ts
35929
36090
  import {
35930
- InternalServerError as InternalServerError53,
36091
+ InternalServerError as InternalServerError52,
35931
36092
  logger as logger134,
35932
36093
  makeCacheKey as makeCacheKey50,
35933
36094
  useAtlas as useAtlas84,
@@ -35936,7 +36097,7 @@ import {
35936
36097
  function useDashboardRepo() {
35937
36098
  const db = useAtlas84.getDb();
35938
36099
  if (!db) {
35939
- throw new InternalServerError53("Unable to connect to server.");
36100
+ throw new InternalServerError52("Unable to connect to server.");
35940
36101
  }
35941
36102
  const feedback_collection = db.collection("feedbacks");
35942
36103
  const work_order_collection = db.collection("work-orders");
@@ -36099,9 +36260,9 @@ function MNfcPatrolRoute(value) {
36099
36260
 
36100
36261
  // src/repositories/nfc-patrol-route.repository.ts
36101
36262
  import {
36102
- AppError as AppError22,
36263
+ AppError as AppError21,
36103
36264
  BadRequestError as BadRequestError158,
36104
- InternalServerError as InternalServerError54,
36265
+ InternalServerError as InternalServerError53,
36105
36266
  logger as logger137,
36106
36267
  makeCacheKey as makeCacheKey51,
36107
36268
  paginate as paginate44,
@@ -36112,7 +36273,7 @@ import { ObjectId as ObjectId96 } from "mongodb";
36112
36273
  function useNfcPatrolRouteRepo() {
36113
36274
  const db = useAtlas85.getDb();
36114
36275
  if (!db) {
36115
- throw new InternalServerError54("Unable to connect to server.");
36276
+ throw new InternalServerError53("Unable to connect to server.");
36116
36277
  }
36117
36278
  const namespace_collection = "nfc-patrol-routes";
36118
36279
  const collection = db.collection(namespace_collection);
@@ -36124,7 +36285,7 @@ function useNfcPatrolRouteRepo() {
36124
36285
  { key: { name: "text" }, name: "text-index" }
36125
36286
  ]);
36126
36287
  } catch (error) {
36127
- throw new InternalServerError54(
36288
+ throw new InternalServerError53(
36128
36289
  `Failed to create index on ${namespace_collection}.`
36129
36290
  );
36130
36291
  }
@@ -36317,10 +36478,10 @@ function useNfcPatrolRouteRepo() {
36317
36478
  });
36318
36479
  return result;
36319
36480
  } catch (error) {
36320
- if (error instanceof AppError22) {
36481
+ if (error instanceof AppError21) {
36321
36482
  throw error;
36322
36483
  } else {
36323
- throw new InternalServerError54(
36484
+ throw new InternalServerError53(
36324
36485
  `Failed to get ${namespace_collection} by id.`
36325
36486
  );
36326
36487
  }
@@ -36370,7 +36531,7 @@ function useNfcPatrolRouteRepo() {
36370
36531
  if (isDuplicated) {
36371
36532
  throw new BadRequestError158("NFC Patrol Route already exists.");
36372
36533
  }
36373
- if (error2 instanceof AppError22) {
36534
+ if (error2 instanceof AppError21) {
36374
36535
  throw error2;
36375
36536
  } else {
36376
36537
  throw new Error("Failed to update NFC Patrol Route.");
@@ -36853,7 +37014,7 @@ import {
36853
37014
  // src/repositories/incident-report.repo.ts
36854
37015
  import {
36855
37016
  BadRequestError as BadRequestError161,
36856
- InternalServerError as InternalServerError55,
37017
+ InternalServerError as InternalServerError54,
36857
37018
  logger as logger140,
36858
37019
  makeCacheKey as makeCacheKey52,
36859
37020
  NotFoundError as NotFoundError43,
@@ -36866,13 +37027,13 @@ var incidents_namespace_collection = "incident-reports";
36866
37027
  function useIncidentReportRepo() {
36867
37028
  const db = useAtlas87.getDb();
36868
37029
  if (!db) {
36869
- throw new InternalServerError55("Unable to connect to server.");
37030
+ throw new InternalServerError54("Unable to connect to server.");
36870
37031
  }
36871
37032
  async function createIndexes() {
36872
37033
  try {
36873
37034
  await collection.createIndexes([{ key: { site: 1, status: 1 } }]);
36874
37035
  } catch (error) {
36875
- throw new InternalServerError55(
37036
+ throw new InternalServerError54(
36876
37037
  "Failed to create index on bulletin videos."
36877
37038
  );
36878
37039
  }
@@ -36884,7 +37045,7 @@ function useIncidentReportRepo() {
36884
37045
  "incidentInformation.incidentTypeAndTime.typeOfIncident": "text"
36885
37046
  });
36886
37047
  } catch (error) {
36887
- throw new InternalServerError55(
37048
+ throw new InternalServerError54(
36888
37049
  "Failed to create text index on event management."
36889
37050
  );
36890
37051
  }
@@ -37171,7 +37332,7 @@ function useIncidentReportRepo() {
37171
37332
  { session }
37172
37333
  );
37173
37334
  if (res.modifiedCount === 0) {
37174
- throw new InternalServerError55(
37335
+ throw new InternalServerError54(
37175
37336
  "Unable to update daily occurrence Subject."
37176
37337
  );
37177
37338
  }
@@ -37204,7 +37365,7 @@ function useIncidentReportRepo() {
37204
37365
  };
37205
37366
  const res = await collection.updateOne({ _id }, { $set: updateValue });
37206
37367
  if (res.modifiedCount === 0) {
37207
- throw new InternalServerError55("Unable to delete occurrence subject.");
37368
+ throw new InternalServerError54("Unable to delete occurrence subject.");
37208
37369
  }
37209
37370
  delNamespace().then(() => {
37210
37371
  logger140.info(
@@ -37235,7 +37396,7 @@ function useIncidentReportRepo() {
37235
37396
  { session }
37236
37397
  );
37237
37398
  if (res.modifiedCount === 0) {
37238
- throw new InternalServerError55(
37399
+ throw new InternalServerError54(
37239
37400
  `Unable to ${value.status} incident report.`
37240
37401
  );
37241
37402
  }
@@ -37777,7 +37938,7 @@ function MNfcPatrolSettingsUpdate(value) {
37777
37938
  // src/repositories/nfc-patrol-settings.repository.ts
37778
37939
  import {
37779
37940
  BadRequestError as BadRequestError165,
37780
- InternalServerError as InternalServerError56,
37941
+ InternalServerError as InternalServerError55,
37781
37942
  logger as logger143,
37782
37943
  makeCacheKey as makeCacheKey53,
37783
37944
  NotFoundError as NotFoundError45,
@@ -37788,7 +37949,7 @@ import { ObjectId as ObjectId100 } from "mongodb";
37788
37949
  function useNfcPatrolSettingsRepository() {
37789
37950
  const db = useAtlas89.getDb();
37790
37951
  if (!db) {
37791
- throw new InternalServerError56("Unable to connect to server.");
37952
+ throw new InternalServerError55("Unable to connect to server.");
37792
37953
  }
37793
37954
  const namespace_collection = "site.nfc-patrol-settings";
37794
37955
  const collection = db.collection(namespace_collection);
@@ -37797,7 +37958,7 @@ function useNfcPatrolSettingsRepository() {
37797
37958
  try {
37798
37959
  await collection.createIndexes([{ key: { site: 1 }, unique: true }]);
37799
37960
  } catch (error) {
37800
- throw new InternalServerError56(
37961
+ throw new InternalServerError55(
37801
37962
  "Failed to create index on nfc patrol settings."
37802
37963
  );
37803
37964
  }
@@ -38031,7 +38192,7 @@ import { useAtlas as useAtlas92 } from "@7365admin1/node-server-utils";
38031
38192
  // src/repositories/occurrence-subject.repo.ts
38032
38193
  import {
38033
38194
  BadRequestError as BadRequestError168,
38034
- InternalServerError as InternalServerError57,
38195
+ InternalServerError as InternalServerError56,
38035
38196
  logger as logger146,
38036
38197
  makeCacheKey as makeCacheKey54,
38037
38198
  NotFoundError as NotFoundError46,
@@ -38090,13 +38251,13 @@ import { ObjectId as ObjectId102 } from "mongodb";
38090
38251
  function useOccurrenceSubjectRepo() {
38091
38252
  const db = useAtlas91.getDb();
38092
38253
  if (!db) {
38093
- throw new InternalServerError57("Unable to connect to server.");
38254
+ throw new InternalServerError56("Unable to connect to server.");
38094
38255
  }
38095
38256
  async function createIndexes() {
38096
38257
  try {
38097
38258
  await collection.createIndexes([{ key: { site: 1 } }]);
38098
38259
  } catch (error) {
38099
- throw new InternalServerError57(
38260
+ throw new InternalServerError56(
38100
38261
  "Failed to create index on occurrence subjects."
38101
38262
  );
38102
38263
  }
@@ -38107,7 +38268,7 @@ function useOccurrenceSubjectRepo() {
38107
38268
  subject: "text"
38108
38269
  });
38109
38270
  } catch (error) {
38110
- throw new InternalServerError57(
38271
+ throw new InternalServerError56(
38111
38272
  "Failed to create text index on occurrence subjects."
38112
38273
  );
38113
38274
  }
@@ -38279,7 +38440,7 @@ function useOccurrenceSubjectRepo() {
38279
38440
  { session }
38280
38441
  );
38281
38442
  if (res.modifiedCount === 0) {
38282
- throw new InternalServerError57(
38443
+ throw new InternalServerError56(
38283
38444
  "Unable to update daily occurrence Subject."
38284
38445
  );
38285
38446
  }
@@ -38310,7 +38471,7 @@ function useOccurrenceSubjectRepo() {
38310
38471
  };
38311
38472
  const res = await collection.updateOne({ _id }, { $set: updateValue });
38312
38473
  if (res.modifiedCount === 0) {
38313
- throw new InternalServerError57("Unable to delete occurrence subject.");
38474
+ throw new InternalServerError56("Unable to delete occurrence subject.");
38314
38475
  }
38315
38476
  delNamespace().then(() => {
38316
38477
  logger146.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -38676,7 +38837,7 @@ function MOnlineForm(value) {
38676
38837
  // src/repositories/online-form.repo.ts
38677
38838
  import {
38678
38839
  BadRequestError as BadRequestError170,
38679
- InternalServerError as InternalServerError58,
38840
+ InternalServerError as InternalServerError57,
38680
38841
  logger as logger148,
38681
38842
  makeCacheKey as makeCacheKey55,
38682
38843
  NotFoundError as NotFoundError47,
@@ -38688,7 +38849,7 @@ import { ObjectId as ObjectId104 } from "mongodb";
38688
38849
  function useOnlineFormRepo() {
38689
38850
  const db = useAtlas93.getDb();
38690
38851
  if (!db) {
38691
- throw new InternalServerError58("Unable to connect to server.");
38852
+ throw new InternalServerError57("Unable to connect to server.");
38692
38853
  }
38693
38854
  const namespace_collection = "online-forms";
38694
38855
  const collection = db.collection(namespace_collection);
@@ -38699,7 +38860,7 @@ function useOnlineFormRepo() {
38699
38860
  name: "text"
38700
38861
  });
38701
38862
  } catch (error) {
38702
- throw new InternalServerError58(
38863
+ throw new InternalServerError57(
38703
38864
  "Failed to create text index on online form."
38704
38865
  );
38705
38866
  }
@@ -38850,7 +39011,7 @@ function useOnlineFormRepo() {
38850
39011
  };
38851
39012
  const res = await collection.updateOne({ _id }, { $set: updateValue });
38852
39013
  if (res.modifiedCount === 0) {
38853
- throw new InternalServerError58("Unable to update online form.");
39014
+ throw new InternalServerError57("Unable to update online form.");
38854
39015
  }
38855
39016
  delNamespace().then(() => {
38856
39017
  logger148.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -38883,7 +39044,7 @@ function useOnlineFormRepo() {
38883
39044
  { session }
38884
39045
  );
38885
39046
  if (res.modifiedCount === 0) {
38886
- throw new InternalServerError58("Unable to delete online form.");
39047
+ throw new InternalServerError57("Unable to delete online form.");
38887
39048
  }
38888
39049
  delNamespace().then(() => {
38889
39050
  logger148.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -39433,7 +39594,7 @@ function MNfcPatrolLog(valueArg) {
39433
39594
  // src/repositories/nfc-patrol-log.repository.ts
39434
39595
  import {
39435
39596
  BadRequestError as BadRequestError174,
39436
- InternalServerError as InternalServerError59,
39597
+ InternalServerError as InternalServerError58,
39437
39598
  logger as logger152,
39438
39599
  makeCacheKey as makeCacheKey56,
39439
39600
  paginate as paginate48,
@@ -39444,7 +39605,7 @@ import { ObjectId as ObjectId106 } from "mongodb";
39444
39605
  function useNfcPatrolLogRepo() {
39445
39606
  const db = useAtlas95.getDb();
39446
39607
  if (!db) {
39447
- throw new InternalServerError59("Unable to connect to server.");
39608
+ throw new InternalServerError58("Unable to connect to server.");
39448
39609
  }
39449
39610
  const namespace_collection = "nfc-patrol-logs";
39450
39611
  const collection = db.collection(namespace_collection);
@@ -39464,7 +39625,7 @@ function useNfcPatrolLogRepo() {
39464
39625
  }
39465
39626
  ]);
39466
39627
  } catch (error) {
39467
- throw new InternalServerError59(
39628
+ throw new InternalServerError58(
39468
39629
  `Failed to create index on ${namespace_collection}.`
39469
39630
  );
39470
39631
  }
@@ -39674,7 +39835,7 @@ function useNfcPatrolLogController() {
39674
39835
  // src/repositories/new-dashboard.repo.ts
39675
39836
  import {
39676
39837
  BadRequestError as BadRequestError177,
39677
- InternalServerError as InternalServerError60,
39838
+ InternalServerError as InternalServerError59,
39678
39839
  logger as logger155,
39679
39840
  makeCacheKey as makeCacheKey57,
39680
39841
  toObjectId as toObjectId8,
@@ -39763,7 +39924,7 @@ function calculatePercentage(current, previous) {
39763
39924
  function useNewDashboardRepo() {
39764
39925
  const db = useAtlas97.getDb();
39765
39926
  if (!db) {
39766
- throw new InternalServerError60("Unable to connect to server.");
39927
+ throw new InternalServerError59("Unable to connect to server.");
39767
39928
  }
39768
39929
  const { delNamespace, getCache, setCache } = useCache59(
39769
39930
  securityDashboardCollection
@@ -40878,7 +41039,7 @@ function useManpowerMonitoringRepo() {
40878
41039
  if (!db) {
40879
41040
  throw new Error("Unable to connect to server.");
40880
41041
  }
40881
- const namespace_collection = "manpower-monitoring";
41042
+ const namespace_collection = "manpower-settings";
40882
41043
  const collection = db.collection(namespace_collection);
40883
41044
  const serviceProviderCollection = db.collection("site.service-providers");
40884
41045
  async function createManpowerMonitoringSettings(value, session) {
@@ -41744,7 +41905,7 @@ function MOvernightParkingApprovalHours(value) {
41744
41905
 
41745
41906
  // src/repositories/overnight-parking.repo.ts
41746
41907
  import {
41747
- InternalServerError as InternalServerError64,
41908
+ InternalServerError as InternalServerError63,
41748
41909
  logger as logger163,
41749
41910
  makeCacheKey as makeCacheKey61,
41750
41911
  toObjectId as toObjectId9,
@@ -41755,7 +41916,7 @@ var overnight_parking_namespace_collection = "site.overnight-parking";
41755
41916
  function useOvernightParkingRepo() {
41756
41917
  const db = useAtlas102.getDb();
41757
41918
  if (!db) {
41758
- throw new InternalServerError64("Unable to connect to server.");
41919
+ throw new InternalServerError63("Unable to connect to server.");
41759
41920
  }
41760
41921
  const collection = db.collection(overnight_parking_namespace_collection);
41761
41922
  const { delNamespace, setCache, getCache } = useCache63(
@@ -41782,7 +41943,7 @@ function useOvernightParkingRepo() {
41782
41943
  await collection.createIndexes(indexesToCreate);
41783
41944
  }
41784
41945
  } catch (error) {
41785
- throw new InternalServerError64("Failed to create collection indexes.");
41946
+ throw new InternalServerError63("Failed to create collection indexes.");
41786
41947
  }
41787
41948
  }
41788
41949
  async function upsert(value, session) {
@@ -41838,7 +41999,7 @@ function useOvernightParkingRepo() {
41838
41999
  try {
41839
42000
  const data = await collection.findOne({
41840
42001
  site: siteId,
41841
- deletedAt: null
42002
+ deletedAt: { $nin: ["", null] }
41842
42003
  });
41843
42004
  setCache(cacheKey, data, 15 * 60).then(() => {
41844
42005
  logger163.info(`Cache set for key: ${cacheKey}`);
@@ -41946,12 +42107,12 @@ var schemaOvernightParkingRequest = Joi118.object({
41946
42107
  numberOfPassengers: Joi118.number().integer().min(0).optional().default(0),
41947
42108
  purposeOfVisit: Joi118.string().optional().allow("", null),
41948
42109
  status: Joi118.string().valid(...Object.values(OvernightParkingRequestStatus)).optional().allow(null, "").default("pending" /* PENDING */),
41949
- comment: Joi118.string().optional().allow(null, "")
42110
+ remarks: Joi118.string().optional().allow(null, "")
41950
42111
  });
41951
42112
  var schemaUpdateOvernightParkingRequest = Joi118.object({
41952
42113
  _id: Joi118.string().hex().length(24).required(),
41953
42114
  status: Joi118.string().valid(...Object.values(OvernightParkingRequestStatus)).required(),
41954
- comment: Joi118.string().optional().allow(null, "")
42115
+ remarks: Joi118.string().optional().allow(null, "")
41955
42116
  });
41956
42117
  function MOvernightParkingRequest(value) {
41957
42118
  const { error } = schemaOvernightParkingRequest.validate(value);
@@ -41972,7 +42133,7 @@ function MOvernightParkingRequest(value) {
41972
42133
  // src/repositories/overnight-parking-request.repository.ts
41973
42134
  import {
41974
42135
  BadRequestError as BadRequestError187,
41975
- InternalServerError as InternalServerError65,
42136
+ InternalServerError as InternalServerError64,
41976
42137
  logger as logger165,
41977
42138
  makeCacheKey as makeCacheKey62,
41978
42139
  paginate as paginate54,
@@ -41984,7 +42145,7 @@ var overnight_parking_requests_namespace_collection = "site.overnight-parking-re
41984
42145
  function useOvernightParkingRequestRepo() {
41985
42146
  const db = useAtlas103.getDb();
41986
42147
  if (!db) {
41987
- throw new InternalServerError65("Unable to connect to server.");
42148
+ throw new InternalServerError64("Unable to connect to server.");
41988
42149
  }
41989
42150
  const collection = db.collection(
41990
42151
  overnight_parking_requests_namespace_collection
@@ -41992,6 +42153,30 @@ function useOvernightParkingRequestRepo() {
41992
42153
  const { delNamespace, getCache, setCache } = useCache64(
41993
42154
  overnight_parking_requests_namespace_collection
41994
42155
  );
42156
+ async function createIndexes() {
42157
+ try {
42158
+ const existingIndexes = await collection.indexes();
42159
+ const existingNames = new Set(existingIndexes.map((i) => i.name));
42160
+ const indexesToEnsure = [
42161
+ {
42162
+ key: { site: 1 },
42163
+ name: "site-index"
42164
+ },
42165
+ {
42166
+ key: { status: 1 },
42167
+ name: "status-index"
42168
+ }
42169
+ ];
42170
+ const indexesToCreate = indexesToEnsure.filter(
42171
+ (index) => index.name && !existingNames.has(index.name)
42172
+ );
42173
+ if (indexesToCreate.length > 0) {
42174
+ await collection.createIndexes(indexesToCreate);
42175
+ }
42176
+ } catch (error) {
42177
+ throw new InternalServerError64("Failed to create collection indexes.");
42178
+ }
42179
+ }
41995
42180
  async function add(value, session) {
41996
42181
  try {
41997
42182
  value = MOvernightParkingRequest(value);
@@ -42177,7 +42362,8 @@ function useOvernightParkingRequestRepo() {
42177
42362
  getOvernightParkingRequestById,
42178
42363
  updateOvernightParkingRequestById,
42179
42364
  deleteOvernightParkingRequestById,
42180
- updateExpiredRequests
42365
+ updateExpiredRequests,
42366
+ createIndexes
42181
42367
  };
42182
42368
  }
42183
42369
 
@@ -42313,7 +42499,7 @@ function useOvernightParkingRequestService() {
42313
42499
 
42314
42500
  // src/controllers/overnight-parking-request.controller.ts
42315
42501
  import Joi119 from "joi";
42316
- import { BadRequestError as BadRequestError189, logger as logger167 } from "@7365admin1/node-server-utils";
42502
+ import { BadRequestError as BadRequestError188, logger as logger167 } from "@7365admin1/node-server-utils";
42317
42503
  function useOvernightParkingRequestController() {
42318
42504
  const {
42319
42505
  add: _add,
@@ -42335,7 +42521,7 @@ function useOvernightParkingRequestController() {
42335
42521
  if (error) {
42336
42522
  const messages = error.details.map((d) => d.message).join(", ");
42337
42523
  logger167.log({ level: "error", message: messages });
42338
- next(new BadRequestError189(messages));
42524
+ next(new BadRequestError188(messages));
42339
42525
  return;
42340
42526
  }
42341
42527
  const data = await _add(value);
@@ -42363,7 +42549,7 @@ function useOvernightParkingRequestController() {
42363
42549
  if (error) {
42364
42550
  const messages = error.details.map((d) => d.message).join(", ");
42365
42551
  logger167.log({ level: "error", message: messages });
42366
- next(new BadRequestError189(messages));
42552
+ next(new BadRequestError188(messages));
42367
42553
  return;
42368
42554
  }
42369
42555
  const { site, page, limit, status, sort, order } = value;
@@ -42399,7 +42585,7 @@ function useOvernightParkingRequestController() {
42399
42585
  if (error) {
42400
42586
  const messages = error.details.map((d) => d.message).join(", ");
42401
42587
  logger167.log({ level: "error", message: messages });
42402
- next(new BadRequestError189(messages));
42588
+ next(new BadRequestError188(messages));
42403
42589
  return;
42404
42590
  }
42405
42591
  const { _id } = value;
@@ -42423,7 +42609,7 @@ function useOvernightParkingRequestController() {
42423
42609
  if (error) {
42424
42610
  const messages = error.details.map((d) => d.message).join(", ");
42425
42611
  logger167.log({ level: "error", message: messages });
42426
- next(new BadRequestError189(messages));
42612
+ next(new BadRequestError188(messages));
42427
42613
  return;
42428
42614
  }
42429
42615
  const { _id, ...rest } = value;
@@ -42450,7 +42636,7 @@ function useOvernightParkingRequestController() {
42450
42636
  if (error) {
42451
42637
  const messages = error.details.map((d) => d.message).join(", ");
42452
42638
  logger167.log({ level: "error", message: messages });
42453
- next(new BadRequestError189(messages));
42639
+ next(new BadRequestError188(messages));
42454
42640
  return;
42455
42641
  }
42456
42642
  const { _id } = value;
@@ -42993,7 +43179,7 @@ function useHrmLabsAttendanceSrvc() {
42993
43179
  }
42994
43180
 
42995
43181
  // src/controllers/hrmlabs-attendance.controller.ts
42996
- import { BadRequestError as BadRequestError190, logger as logger169 } from "@7365admin1/node-server-utils";
43182
+ import { BadRequestError as BadRequestError189, logger as logger169 } from "@7365admin1/node-server-utils";
42997
43183
  import Joi120 from "joi";
42998
43184
  function useHrmLabsAttendanceCtrl() {
42999
43185
  const hrmLabsAttendanceSrvc = useHrmLabsAttendanceSrvc();
@@ -43036,7 +43222,7 @@ function useHrmLabsAttendanceCtrl() {
43036
43222
  serviceProviderId
43037
43223
  });
43038
43224
  if (error) {
43039
- next(new BadRequestError190(error.message));
43225
+ next(new BadRequestError189(error.message));
43040
43226
  return;
43041
43227
  }
43042
43228
  const result = await hrmLabsAttendanceSrvc.getAttendanceData(req.body);
@@ -43065,7 +43251,7 @@ function useHrmLabsAttendanceCtrl() {
43065
43251
  serviceProviderId
43066
43252
  });
43067
43253
  if (error) {
43068
- next(new BadRequestError190(error.message));
43254
+ next(new BadRequestError189(error.message));
43069
43255
  return;
43070
43256
  }
43071
43257
  const result = await hrmLabsAttendanceSrvc.getAttendanceDataCount(
@@ -43108,7 +43294,7 @@ function useHrmLabsAttendanceCtrl() {
43108
43294
  serviceProviderId
43109
43295
  });
43110
43296
  if (error) {
43111
- next(new BadRequestError190(error.message));
43297
+ next(new BadRequestError189(error.message));
43112
43298
  return;
43113
43299
  }
43114
43300
  const result = await hrmLabsAttendanceSrvc.getAllAttendance(req.body);
@@ -43149,7 +43335,7 @@ function useHrmLabsAttendanceCtrl() {
43149
43335
  status
43150
43336
  });
43151
43337
  if (error) {
43152
- next(new BadRequestError190(error.message));
43338
+ next(new BadRequestError189(error.message));
43153
43339
  return;
43154
43340
  }
43155
43341
  const result = await hrmLabsAttendanceSrvc.getChartAttendanceData(
@@ -43171,7 +43357,7 @@ function useHrmLabsAttendanceCtrl() {
43171
43357
  }
43172
43358
 
43173
43359
  // src/controllers/manpower-remarks.controller.ts
43174
- import { BadRequestError as BadRequestError191, logger as logger170 } from "@7365admin1/node-server-utils";
43360
+ import { BadRequestError as BadRequestError190, logger as logger170 } from "@7365admin1/node-server-utils";
43175
43361
  import Joi121 from "joi";
43176
43362
  function useManpowerRemarkCtrl() {
43177
43363
  const {
@@ -43186,7 +43372,7 @@ function useManpowerRemarkCtrl() {
43186
43372
  const payload = { ...req.body };
43187
43373
  const { error } = manpowerRemarksSchema.validate(payload);
43188
43374
  if (error) {
43189
- next(new BadRequestError191(error.message));
43375
+ next(new BadRequestError190(error.message));
43190
43376
  return;
43191
43377
  }
43192
43378
  const result = await _createManpowerRemarks(payload);
@@ -43217,7 +43403,7 @@ function useManpowerRemarkCtrl() {
43217
43403
  date
43218
43404
  });
43219
43405
  if (error) {
43220
- next(new BadRequestError191(error.message));
43406
+ next(new BadRequestError190(error.message));
43221
43407
  return;
43222
43408
  }
43223
43409
  const result = await _getManpowerRemarksAllSite({
@@ -43250,7 +43436,7 @@ function useManpowerRemarkCtrl() {
43250
43436
  serviceProviderId
43251
43437
  });
43252
43438
  if (error) {
43253
- next(new BadRequestError191(error.message));
43439
+ next(new BadRequestError190(error.message));
43254
43440
  return;
43255
43441
  }
43256
43442
  const result = await _getManpowerRemarksBySiteId(
@@ -43277,7 +43463,7 @@ function useManpowerRemarkCtrl() {
43277
43463
  const payload = { ...req.body };
43278
43464
  const { error } = validation.validate({ _id, ...payload });
43279
43465
  if (error) {
43280
- next(new BadRequestError191(error.message));
43466
+ next(new BadRequestError190(error.message));
43281
43467
  return;
43282
43468
  }
43283
43469
  const result = await _updateManpowerRemarks(_id, payload);
@@ -43298,7 +43484,7 @@ function useManpowerRemarkCtrl() {
43298
43484
  const payload = { ...req.body };
43299
43485
  const { error } = validation.validate({ _id, ...payload });
43300
43486
  if (error) {
43301
- next(new BadRequestError191(error.message));
43487
+ next(new BadRequestError190(error.message));
43302
43488
  return;
43303
43489
  }
43304
43490
  const result = await _updateRemarksStatus(_id, payload);
@@ -43317,6 +43503,703 @@ function useManpowerRemarkCtrl() {
43317
43503
  updateRemarksStatus
43318
43504
  };
43319
43505
  }
43506
+
43507
+ // src/models/manpower-sites.model.ts
43508
+ import Joi122 from "joi";
43509
+ import { ObjectId as ObjectId114 } from "mongodb";
43510
+ var manpowerSitesSchema = Joi122.object({
43511
+ id: Joi122.string().hex().required(),
43512
+ text: Joi122.string().hex().optional().allow("", null),
43513
+ contractID: Joi122.string().optional().allow("", null),
43514
+ contractName: Joi122.string().optional().allow("", null),
43515
+ type: Joi122.string().optional().allow("", null),
43516
+ status: Joi122.number().optional().allow("", null)
43517
+ });
43518
+ var MManpowerSites = class {
43519
+ constructor(data) {
43520
+ this._id = new ObjectId114();
43521
+ this.id = data.id || "";
43522
+ this.text = data.text || "";
43523
+ this.contractID = data.contractID || "";
43524
+ this.contractName = data.contractName || "";
43525
+ this.type = data.type || "";
43526
+ this.status = data.status || "";
43527
+ }
43528
+ };
43529
+
43530
+ // src/repositories/manpower-sites.repo.ts
43531
+ import {
43532
+ useAtlas as useAtlas105
43533
+ } from "@7365admin1/node-server-utils";
43534
+ function useManpowerSitesRepo() {
43535
+ const db = useAtlas105.getDb();
43536
+ if (!db) {
43537
+ throw new Error("Unable to connect to server.");
43538
+ }
43539
+ const namespace_collection = "manpower-sites";
43540
+ const collection = db.collection(namespace_collection);
43541
+ async function createManpowerSites(value) {
43542
+ try {
43543
+ value = new MManpowerSites(value);
43544
+ const result = await collection.insertOne(value);
43545
+ return result;
43546
+ } catch (error) {
43547
+ throw new Error(error.message || error || "Server Internal Error");
43548
+ }
43549
+ }
43550
+ async function getAllManpowerSites({
43551
+ page = 1,
43552
+ limit = 10,
43553
+ search = ""
43554
+ }) {
43555
+ try {
43556
+ page = page ? page - 1 : 0;
43557
+ limit = limit || 10;
43558
+ const searchQuery = {};
43559
+ if (search) {
43560
+ searchQuery.siteName = { $regex: search, $options: "i" };
43561
+ }
43562
+ const result = await collection.aggregate([
43563
+ { $match: searchQuery },
43564
+ {
43565
+ $facet: {
43566
+ totalCount: [{ $count: "count" }],
43567
+ items: [
43568
+ { $sort: { _id: 1 } },
43569
+ {
43570
+ $project: {
43571
+ _id: 0
43572
+ }
43573
+ },
43574
+ { $skip: page * limit },
43575
+ { $limit: limit }
43576
+ ]
43577
+ }
43578
+ }
43579
+ ]).toArray();
43580
+ const items = result[0].items;
43581
+ return items;
43582
+ } catch (error) {
43583
+ throw new Error(error.message || "Server Internal Error");
43584
+ }
43585
+ }
43586
+ async function deleteManpowerSites(siteId) {
43587
+ try {
43588
+ const result = await collection.deleteOne({
43589
+ id: siteId.toString()
43590
+ });
43591
+ return result;
43592
+ } catch (error) {
43593
+ throw new Error(error.message || "Server Internal Error");
43594
+ }
43595
+ }
43596
+ return {
43597
+ createManpowerSites,
43598
+ getAllManpowerSites,
43599
+ deleteManpowerSites
43600
+ };
43601
+ }
43602
+
43603
+ // src/services/manpower-sites.service.ts
43604
+ import {
43605
+ BadRequestError as BadRequestError192,
43606
+ useAtlas as useAtlas106,
43607
+ logger as logger172
43608
+ } from "@7365admin1/node-server-utils";
43609
+ function useManpowerSitesSrvc() {
43610
+ const manpowerSitesRepo = useManpowerSitesRepo();
43611
+ const manpowerMonitoringRepo = useManpowerMonitoringRepo();
43612
+ async function createManpowerSites(payload) {
43613
+ const session = useAtlas106.getClient()?.startSession();
43614
+ if (!session) {
43615
+ throw new BadRequestError192("Database session not available.");
43616
+ }
43617
+ await session.startTransaction();
43618
+ try {
43619
+ const manpowerSites = await manpowerMonitoringRepo.getAllSites(payload);
43620
+ for (const site of manpowerSites) {
43621
+ await manpowerSitesRepo.createManpowerSites(site);
43622
+ }
43623
+ await session.commitTransaction();
43624
+ return "Created Succesfully";
43625
+ } catch (error) {
43626
+ await session.abortTransaction();
43627
+ logger172.error(error.message || error);
43628
+ console.error("Error creating monitoring settings:", error);
43629
+ throw new Error(error?.message || "Internal Server Error!");
43630
+ } finally {
43631
+ session.endSession();
43632
+ }
43633
+ }
43634
+ async function checkManpowerSites() {
43635
+ try {
43636
+ const serviceProviderId = "69bb9dbff572cf9d260d7ce3";
43637
+ const hrmLabsSites = await manpowerMonitoringRepo.getAllSites(
43638
+ serviceProviderId
43639
+ );
43640
+ const manpowerSites = await manpowerSitesRepo.getAllManpowerSites({
43641
+ page: 1,
43642
+ limit: 1e3,
43643
+ search: ""
43644
+ });
43645
+ const added = hrmLabsSites.filter(
43646
+ (hrmSite) => !manpowerSites.some((mpSite) => mpSite.id === hrmSite.id)
43647
+ );
43648
+ const deleted = manpowerSites.filter(
43649
+ (mpSite) => !hrmLabsSites.some((hrmSite) => hrmSite.id === mpSite.id)
43650
+ );
43651
+ if (added.length > 0) {
43652
+ await Promise.all(
43653
+ added.map((site) => manpowerSitesRepo.createManpowerSites(site))
43654
+ );
43655
+ }
43656
+ if (deleted.length > 0) {
43657
+ await Promise.all(
43658
+ deleted.map(
43659
+ (site) => manpowerSitesRepo.deleteManpowerSites(site.id)
43660
+ )
43661
+ );
43662
+ }
43663
+ return "Manpower Sites Updated Successfully";
43664
+ } catch (error) {
43665
+ logger172.error(error.message || error);
43666
+ console.error("Error checking manpower sites:", error);
43667
+ throw new Error(error?.message || "Internal Server Error!");
43668
+ }
43669
+ }
43670
+ return {
43671
+ createManpowerSites,
43672
+ checkManpowerSites
43673
+ };
43674
+ }
43675
+
43676
+ // src/controllers/manpower-sites.controller.ts
43677
+ import { BadRequestError as BadRequestError193, logger as logger173 } from "@7365admin1/node-server-utils";
43678
+ import Joi123 from "joi";
43679
+ function useManpowerSitesCtrl() {
43680
+ const { createManpowerSites: _createManpowerSites } = useManpowerSitesSrvc();
43681
+ const { getAllManpowerSites: _getAllManpowerSites } = useManpowerSitesRepo();
43682
+ async function createManpowerSites(req, res, next) {
43683
+ try {
43684
+ const payload = req.query.serviceProviderId;
43685
+ const schema2 = Joi123.object({
43686
+ serviceProviderId: Joi123.string().hex().required()
43687
+ });
43688
+ const { error } = schema2.validate({
43689
+ serviceProviderId: payload
43690
+ });
43691
+ if (error) {
43692
+ next(new BadRequestError193(error.message));
43693
+ return;
43694
+ }
43695
+ const result = await _createManpowerSites(payload);
43696
+ return res.json(result);
43697
+ } catch (error) {
43698
+ logger173.log({ level: "error", message: error.message });
43699
+ next(error);
43700
+ return;
43701
+ }
43702
+ }
43703
+ async function getAllManpowerSites(req, res, next) {
43704
+ try {
43705
+ const { page, search, limit } = req.query;
43706
+ const schema2 = Joi123.object({
43707
+ page: Joi123.number().optional().allow("", null),
43708
+ limit: Joi123.number().optional().allow("", null),
43709
+ search: Joi123.string().optional().allow("", null)
43710
+ });
43711
+ const { error } = schema2.validate({ page, search, limit });
43712
+ if (error) {
43713
+ next(new BadRequestError193(error.message));
43714
+ return;
43715
+ }
43716
+ const result = await _getAllManpowerSites({
43717
+ page: Number(page),
43718
+ limit: Number(limit),
43719
+ search
43720
+ });
43721
+ return res.json(result);
43722
+ } catch (error) {
43723
+ logger173.log({ level: "error", message: error.message });
43724
+ next(error);
43725
+ return;
43726
+ }
43727
+ }
43728
+ return {
43729
+ createManpowerSites,
43730
+ getAllManpowerSites
43731
+ };
43732
+ }
43733
+
43734
+ // src/utils/cron.util.ts
43735
+ import {
43736
+ useAtlas as useAtlas107,
43737
+ useMailer as useMailer2,
43738
+ compileHandlebar as compileHandlebar2,
43739
+ getDirectory as getDirectory2,
43740
+ logger as logger174
43741
+ } from "@7365admin1/node-server-utils";
43742
+ import { ObjectId as ObjectId115 } from "mongodb";
43743
+ import moment4 from "moment-timezone";
43744
+ var createManpowerRemarksDaily = async () => {
43745
+ const db = useAtlas107.getDb();
43746
+ if (!db) {
43747
+ throw new Error("Unable to connect to server.");
43748
+ }
43749
+ const namespace_collection = "manpower-settings";
43750
+ const settings = db.collection(namespace_collection);
43751
+ const remarks = db.collection("manpower-remarks");
43752
+ const serviceProviders = db.collection("site.service-providers");
43753
+ const items = [];
43754
+ const yesterday = moment4().tz("Asia/Singapore").subtract(1, "days").format("DD-MM-YYYY");
43755
+ try {
43756
+ const nowSGT = moment4().tz("Asia/Singapore");
43757
+ const servideProvider = await serviceProviders.findOne({
43758
+ name: { $regex: process.env.HRMLABS_DOMAIN, $options: "i" }
43759
+ });
43760
+ if (!servideProvider) {
43761
+ throw new Error("Servide Provider not found.");
43762
+ }
43763
+ const remark = await remarks.find({
43764
+ createdAtSGT: yesterday,
43765
+ serviceProviderId: servideProvider._id,
43766
+ status: "active"
43767
+ }).toArray();
43768
+ for (const site of remark) {
43769
+ const existingRemark = await settings.findOne({
43770
+ siteId: site.siteId,
43771
+ enabled: true
43772
+ });
43773
+ if (existingRemark) {
43774
+ const setting = await settings.findOne({
43775
+ siteId: site.siteId,
43776
+ enabled: true
43777
+ });
43778
+ const shiftType = setting?.shiftType;
43779
+ const morningCheckInTime = setting?.shifts?.[shiftType][0]?.checkIn;
43780
+ const afternoonCheckInTime = shiftType == "3-shifts" ? setting?.shifts?.[shiftType][1]?.checkIn : null;
43781
+ const nightCheckInTime = shiftType == "3-shifts" ? setting?.shifts?.[shiftType][2]?.checkIn : setting?.shifts?.[shiftType][1]?.checkIn;
43782
+ const morningAlertFrequencyMins = setting?.shifts?.[shiftType][0]?.alertFrequencyMins;
43783
+ const afternoonAlertFrequencyMins = shiftType == "3-shifts" ? setting?.shifts?.[shiftType][1]?.alertFrequencyMins : null;
43784
+ const nightAlertFrequencyMins = shiftType == "3-shifts" ? setting?.shifts?.[shiftType][2]?.alertFrequencyMins : setting?.shifts?.[shiftType][1]?.alertFrequencyMins;
43785
+ const morningAlertTime = moment4.tz(morningCheckInTime, "HH:mm", "Asia/Singapore").add(morningAlertFrequencyMins, "minutes").format("HH:mm");
43786
+ const afternoonAlertTime = afternoonCheckInTime ? moment4.tz(afternoonCheckInTime, "HH:mm", "Asia/Singapore").add(afternoonAlertFrequencyMins, "minutes").format("HH:mm") : "";
43787
+ const nightAlertTime = moment4.tz(nightCheckInTime, "HH:mm", "Asia/Singapore").add(nightAlertFrequencyMins, "minutes").format("HH:mm");
43788
+ const remark2 = {
43789
+ siteId: site.siteId,
43790
+ siteName: site.siteName,
43791
+ serviceProviderId: servideProvider._id,
43792
+ remarks: [
43793
+ {
43794
+ name: "Morning Shift",
43795
+ remark: {
43796
+ isAcknowledged: true,
43797
+ status: "",
43798
+ acknowledgementRemarks: "",
43799
+ acknowledgedAt: ""
43800
+ }
43801
+ },
43802
+ {
43803
+ name: "Afternoon Shift",
43804
+ remark: {
43805
+ isAcknowledged: true,
43806
+ status: "",
43807
+ acknowledgementRemarks: "",
43808
+ acknowledgedAt: ""
43809
+ }
43810
+ },
43811
+ {
43812
+ name: "Night Shift",
43813
+ remark: {
43814
+ isAcknowledged: true,
43815
+ status: "",
43816
+ acknowledgementRemarks: "",
43817
+ acknowledgedAt: ""
43818
+ }
43819
+ }
43820
+ ],
43821
+ createdBy: "",
43822
+ createdByName: "",
43823
+ morningAlertTime,
43824
+ afternoonAlertTime,
43825
+ nightAlertTime,
43826
+ createdAt: /* @__PURE__ */ new Date(),
43827
+ createdAtSGT: nowSGT.format("DD-MM-YYYY"),
43828
+ updatedAt: "",
43829
+ status: "active"
43830
+ };
43831
+ items.push(remark2);
43832
+ }
43833
+ }
43834
+ if (items.length > 0) {
43835
+ await remarks.insertMany(items);
43836
+ }
43837
+ console.log("Daily manpower remarks created successfully.");
43838
+ } catch (error) {
43839
+ console.error("Error creating daily manpower remarks:", error);
43840
+ }
43841
+ };
43842
+ var updateRemarksisAcknowledged = async () => {
43843
+ const { getAttendanceDataCount: _getAttendanceDataCount } = useHrmLabsAttendanceSrvc();
43844
+ const nowSGT = moment4().tz("Asia/Singapore").format("DD-MM-YYYY");
43845
+ const db = useAtlas107.getDb();
43846
+ if (!db) {
43847
+ throw new Error("Unable to connect to server.");
43848
+ }
43849
+ const namespace_collection = "manpower-remarks";
43850
+ const remarks = db.collection(namespace_collection);
43851
+ const timeNow = moment4().tz("Asia/Singapore").format("HH:mm");
43852
+ const settings = db.collection("manpower-settings");
43853
+ try {
43854
+ const matchingDocs = await remarks.find({
43855
+ createdAtSGT: nowSGT,
43856
+ $or: [
43857
+ {
43858
+ morningAlertTime: timeNow,
43859
+ "remarks.0.remark.isAcknowledged": true
43860
+ },
43861
+ {
43862
+ afternoonAlertTime: timeNow,
43863
+ "remarks.1.remark.isAcknowledged": true
43864
+ },
43865
+ { nightAlertTime: timeNow, "remarks.2.remark.isAcknowledged": true }
43866
+ ]
43867
+ }).project({ _id: 1 }).toArray();
43868
+ if (matchingDocs.length === 0) {
43869
+ return;
43870
+ }
43871
+ const updatedIds = matchingDocs.map((doc) => doc._id);
43872
+ await remarks.updateMany(
43873
+ {
43874
+ _id: { $in: updatedIds },
43875
+ morningAlertTime: timeNow,
43876
+ createdAtSGT: nowSGT,
43877
+ "remarks.0.remark.isAcknowledged": true
43878
+ },
43879
+ { $set: { "remarks.0.remark.isAcknowledged": false } }
43880
+ );
43881
+ await remarks.updateMany(
43882
+ {
43883
+ _id: { $in: updatedIds },
43884
+ afternoonAlertTime: timeNow,
43885
+ createdAtSGT: nowSGT,
43886
+ "remarks.1.remark.isAcknowledged": true
43887
+ },
43888
+ { $set: { "remarks.1.remark.isAcknowledged": false } }
43889
+ );
43890
+ await remarks.updateMany(
43891
+ {
43892
+ _id: { $in: updatedIds },
43893
+ nightAlertTime: timeNow,
43894
+ createdAtSGT: nowSGT,
43895
+ "remarks.2.remark.isAcknowledged": true
43896
+ },
43897
+ { $set: { "remarks.2.remark.isAcknowledged": false } }
43898
+ );
43899
+ for (const id of updatedIds) {
43900
+ const doc = await remarks.findOne({ _id: id });
43901
+ const setting = await settings.findOne(
43902
+ { siteId: new ObjectId115(doc?.siteId) },
43903
+ { projection: { emails: 1 } }
43904
+ );
43905
+ const payload = {
43906
+ startDate: doc?.createdAtSGT,
43907
+ endDate: doc?.createdAtSGT,
43908
+ siteName: doc?.siteName,
43909
+ siteId: doc?.siteId.toString(),
43910
+ serviceProviderId: doc?.serviceProviderId.toString()
43911
+ };
43912
+ const result = await _getAttendanceDataCount(payload);
43913
+ const shifts = [
43914
+ { key: "dayShift", alertTime: doc?.morningAlertTime },
43915
+ { key: "afternoonShift", alertTime: doc?.afternoonAlertTime },
43916
+ { key: "nightShift", alertTime: doc?.nightAlertTime }
43917
+ ];
43918
+ let shiftType;
43919
+ let actual = 0;
43920
+ let expected = 0;
43921
+ for (const shift of shifts) {
43922
+ if (shift.alertTime && isWithinHour(shift.alertTime, timeNow)) {
43923
+ shiftType = shift.key;
43924
+ actual = result?.totalCount?.[shift.key]?.actual || 0;
43925
+ expected = result?.totalCount?.[shift.key]?.expected || 0;
43926
+ break;
43927
+ }
43928
+ }
43929
+ let newStatus = "Normal";
43930
+ if (actual > expected)
43931
+ newStatus = "Over";
43932
+ else if (actual < expected)
43933
+ newStatus = "Under";
43934
+ sendEmailWithAttachmentsTo({
43935
+ email: setting?.emails,
43936
+ subject: "Manpower Alert",
43937
+ message: "",
43938
+ siteName: doc?.siteName || "",
43939
+ handlebar: "alert-email",
43940
+ date: nowSGT,
43941
+ actual,
43942
+ expected,
43943
+ status: newStatus
43944
+ });
43945
+ }
43946
+ } catch (error) {
43947
+ console.error("Error updating remarks:", error);
43948
+ }
43949
+ };
43950
+ var updateRemarksStatusEod = async () => {
43951
+ const { getAttendanceDataCount: _getAttendanceDataCount } = useHrmLabsAttendanceSrvc();
43952
+ const db = useAtlas107.getDb();
43953
+ if (!db) {
43954
+ throw new Error("Unable to connect to server.");
43955
+ }
43956
+ const remarks = db.collection("manpower-remarks");
43957
+ const settings = db.collection("manpower-settings");
43958
+ const nowSGT = moment4().tz("Asia/Singapore").format("DD-MM-YYYY");
43959
+ const yesterdaySGT = moment4().tz("Asia/Singapore").subtract(1, "days").format("DD-MM-YYYY");
43960
+ const timeNow = moment4().tz("Asia/Singapore").format("HH:mm");
43961
+ const docs = await remarks.find({
43962
+ $or: [
43963
+ // Morning & Afternoon from today
43964
+ {
43965
+ createdAtSGT: nowSGT,
43966
+ $or: [
43967
+ {
43968
+ "remarks.0.remark.status": "",
43969
+ "remarks.0.remark.isAcknowledged": false
43970
+ },
43971
+ {
43972
+ "remarks.1.remark.status": "",
43973
+ "remarks.1.remark.isAcknowledged": false
43974
+ }
43975
+ ]
43976
+ },
43977
+ // Night shift from yesterday
43978
+ {
43979
+ createdAtSGT: yesterdaySGT,
43980
+ "remarks.2.remark.status": "",
43981
+ "remarks.2.remark.isAcknowledged": false
43982
+ }
43983
+ ]
43984
+ }).toArray();
43985
+ for (const doc of docs) {
43986
+ let shiftsToCheck = [];
43987
+ const endShiftTime = await settings.findOne(
43988
+ { siteId: new ObjectId115(doc.siteId) },
43989
+ { projection: { shifts: 1, shiftType: 1 } }
43990
+ );
43991
+ if (doc.createdAtSGT === nowSGT) {
43992
+ const shiftType = endShiftTime?.shiftType || "2-shifts";
43993
+ if (timeNow >= endShiftTime?.shifts[shiftType][0]?.checkOut)
43994
+ shiftsToCheck.push({ index: 0, key: "dayShift" });
43995
+ if (shiftType == "3-shifts" && timeNow >= endShiftTime?.shifts[shiftType][1]?.checkOut)
43996
+ shiftsToCheck.push({ index: 1, key: "afternoonShift" });
43997
+ }
43998
+ if (doc.createdAtSGT === yesterdaySGT) {
43999
+ const index = endShiftTime?.shiftType === "2-shifts" ? 1 : 2;
44000
+ if (timeNow >= endShiftTime?.shifts[endShiftTime?.shiftType][index]?.checkOut)
44001
+ shiftsToCheck.push({ index: 2, key: "nightShift" });
44002
+ }
44003
+ if (shiftsToCheck.length === 0)
44004
+ continue;
44005
+ const payload = {
44006
+ startDate: doc.createdAtSGT,
44007
+ endDate: doc.createdAtSGT,
44008
+ siteName: doc.siteName,
44009
+ siteId: doc.siteId.toString(),
44010
+ serviceProviderId: doc.serviceProviderId.toString()
44011
+ };
44012
+ const result = await _getAttendanceDataCount(payload);
44013
+ if (!result?.totalCount) {
44014
+ continue;
44015
+ }
44016
+ for (const shift of shiftsToCheck) {
44017
+ const actual = result?.totalCount[shift?.key]?.actual || 0;
44018
+ const expected = result?.totalCount[shift?.key]?.expected || 0;
44019
+ if (doc.remarks[shift.index].remark.status === "") {
44020
+ let newStatus = "Normal";
44021
+ if (actual > expected)
44022
+ newStatus = "Over";
44023
+ else if (actual < expected)
44024
+ newStatus = "Under";
44025
+ await remarks.updateOne(
44026
+ { _id: doc._id },
44027
+ {
44028
+ $set: {
44029
+ [`remarks.${shift.index}.remark.status`]: newStatus,
44030
+ [`remarks.${shift.index}.remark.isAcknowledged`]: true,
44031
+ [`remarks.${shift.index}.remark.acknowledgedAt`]: (/* @__PURE__ */ new Date()).toISOString()
44032
+ }
44033
+ }
44034
+ );
44035
+ }
44036
+ }
44037
+ }
44038
+ };
44039
+ function sendEmailWithAttachmentsTo({
44040
+ email = "",
44041
+ subject = "",
44042
+ message = "",
44043
+ siteName = "",
44044
+ handlebar = "",
44045
+ date = "",
44046
+ actual = 0,
44047
+ expected = 0,
44048
+ status = ""
44049
+ }) {
44050
+ const MailerConfig = {
44051
+ host: MAILER_TRANSPORT_HOST,
44052
+ port: MAILER_TRANSPORT_PORT,
44053
+ secure: MAILER_TRANSPORT_SECURE,
44054
+ email: MAILER_EMAIL,
44055
+ password: MAILER_PASSWORD
44056
+ };
44057
+ const mailer = new useMailer2(MailerConfig);
44058
+ const dir = __dirname;
44059
+ const type = "alert-email";
44060
+ const filePath = getDirectory2(dir, `./public/handlebars/${type}`);
44061
+ const emailContent = compileHandlebar2({
44062
+ context: {
44063
+ siteName,
44064
+ date,
44065
+ actual,
44066
+ expected,
44067
+ status
44068
+ },
44069
+ filePath
44070
+ });
44071
+ mailer.sendMail({
44072
+ to: email,
44073
+ subject,
44074
+ html: emailContent,
44075
+ sender: "iService365"
44076
+ }).catch((error) => {
44077
+ logger174.log({
44078
+ level: "error",
44079
+ message: `Error sending user ${type} email: ${error}`
44080
+ });
44081
+ });
44082
+ return { message };
44083
+ }
44084
+ var isWithinHour = (alertTime, timeNow) => {
44085
+ const [ah, am] = alertTime.split(":").map(Number);
44086
+ const [nh, nm] = timeNow.split(":").map(Number);
44087
+ const alertMinutes = ah * 60 + am;
44088
+ const nowMinutes = nh * 60 + nm;
44089
+ return nowMinutes >= alertMinutes && nowMinutes <= alertMinutes + 60;
44090
+ };
44091
+
44092
+ // src/events/manpower.event.ts
44093
+ import { useAtlas as useAtlas108 } from "@7365admin1/node-server-utils";
44094
+ import { ObjectId as ObjectId116 } from "mongodb";
44095
+ import moment5 from "moment-timezone";
44096
+ async function manpowerEvents(io) {
44097
+ console.log("Manpower events initialized");
44098
+ let intervalId = null;
44099
+ let activeConnections = 0;
44100
+ const { getAttendanceDataCount: _getAttendanceDataCount } = useHrmLabsAttendanceSrvc();
44101
+ const updateRemarksStatus = async (date) => {
44102
+ const db = useAtlas108.getDb();
44103
+ if (!db) {
44104
+ throw new Error("Unable to connect to server.");
44105
+ }
44106
+ const remarks = db.collection("manpower-remarks");
44107
+ const settings = db.collection("manpower-settings");
44108
+ const selectedDateMoment = moment5.tz(date, "DD-MM-YYYY", "Asia/Singapore");
44109
+ const selectedDateSGT = selectedDateMoment.format("DD-MM-YYYY");
44110
+ const currentSGT = moment5().tz("Asia/Singapore");
44111
+ const docs = await remarks.find({
44112
+ createdAtSGT: selectedDateSGT,
44113
+ $or: [
44114
+ { "remarks.0.remark.status": "" },
44115
+ { "remarks.1.remark.status": "" },
44116
+ { "remarks.2.remark.status": "" }
44117
+ ]
44118
+ }).toArray();
44119
+ for (const doc of docs) {
44120
+ const siteSettings = await settings.findOne(
44121
+ { siteId: new ObjectId116(doc.siteId), enabled: true },
44122
+ { projection: { shifts: 1, shiftType: 1 } }
44123
+ );
44124
+ const shiftType = siteSettings?.shiftType || "2-shifts";
44125
+ const shiftsToCheck = [];
44126
+ shiftsToCheck.push({ index: 0, key: "dayShift" });
44127
+ if (shiftType === "3-shifts") {
44128
+ shiftsToCheck.push({ index: 1, key: "afternoonShift" });
44129
+ }
44130
+ if (currentSGT.isSame(selectedDateMoment, "day")) {
44131
+ if (currentSGT.isSameOrAfter(
44132
+ moment5.tz("19:55", "HH:mm", "Asia/Singapore")
44133
+ )) {
44134
+ shiftsToCheck.push({ index: 2, key: "nightShift" });
44135
+ }
44136
+ } else if (currentSGT.isAfter(selectedDateMoment, "day")) {
44137
+ shiftsToCheck.push({ index: 2, key: "nightShift" });
44138
+ }
44139
+ if (shiftsToCheck.length === 0)
44140
+ continue;
44141
+ const payload = {
44142
+ startDate: doc.createdAtSGT,
44143
+ endDate: doc.createdAtSGT,
44144
+ siteName: doc.siteName,
44145
+ siteId: doc.siteId.toString(),
44146
+ serviceProviderId: doc.serviceProviderId.toString()
44147
+ };
44148
+ const result = await _getAttendanceDataCount(payload);
44149
+ for (const shift of shiftsToCheck) {
44150
+ const actual = result?.totalCount?.[shift.key]?.actual || 0;
44151
+ const expected = result?.totalCount?.[shift.key]?.expected || 0;
44152
+ let newStatus = "Normal";
44153
+ if (actual > expected)
44154
+ newStatus = "Over";
44155
+ else if (actual < expected)
44156
+ newStatus = "Under";
44157
+ const namespace = `/manpower`;
44158
+ io.of(namespace).emit("manpower-status-update", {
44159
+ siteId: doc.siteId,
44160
+ siteName: doc.siteName,
44161
+ shift: shift.key,
44162
+ status: newStatus,
44163
+ actual,
44164
+ expected,
44165
+ selectedDateSGT
44166
+ });
44167
+ }
44168
+ }
44169
+ };
44170
+ const startInterval = (date) => {
44171
+ if (!intervalId) {
44172
+ intervalId = setInterval(
44173
+ () => updateRemarksStatus(date?.toString() || ""),
44174
+ 15 * 1e3
44175
+ );
44176
+ console.log(" Interval started.");
44177
+ }
44178
+ };
44179
+ const stopInterval = () => {
44180
+ if (intervalId) {
44181
+ clearInterval(intervalId);
44182
+ intervalId = null;
44183
+ console.log(" Interval stopped.");
44184
+ }
44185
+ };
44186
+ io.of("/manpower").on("connection", (socket) => {
44187
+ activeConnections += 1;
44188
+ const date = socket.handshake.query.date;
44189
+ if (activeConnections === 1) {
44190
+ startInterval(date?.toString() || "");
44191
+ }
44192
+ updateRemarksStatus(date?.toString() || "");
44193
+ socket.on("disconnect", () => {
44194
+ activeConnections -= 1;
44195
+ console.log(`Client disconnected: ${socket.id}`);
44196
+ console.log(`Total active connections: ${activeConnections}`);
44197
+ if (activeConnections === 0) {
44198
+ stopInterval();
44199
+ }
44200
+ });
44201
+ });
44202
+ }
43320
44203
  export {
43321
44204
  ANPRMode,
43322
44205
  AccessTypeProps,
@@ -43357,6 +44240,7 @@ export {
43357
44240
  MManpowerDesignations,
43358
44241
  MManpowerMonitoring,
43359
44242
  MManpowerRemarks,
44243
+ MManpowerSites,
43360
44244
  MMember,
43361
44245
  MNfcPatrolLog,
43362
44246
  MNfcPatrolRoute,
@@ -43422,6 +44306,7 @@ export {
43422
44306
  bulletin_boards_namespace_collection,
43423
44307
  calculatePercentage,
43424
44308
  chatSchema,
44309
+ createManpowerRemarksDaily,
43425
44310
  customerSchema,
43426
44311
  designationsSchema,
43427
44312
  events_namespace_collection,
@@ -43436,10 +44321,13 @@ export {
43436
44321
  landscapeDashboardCollection,
43437
44322
  mAndEDashboardCollection,
43438
44323
  manpowerDesignationsSchema,
44324
+ manpowerEvents,
43439
44325
  manpowerMonitoringSchema,
43440
44326
  manpowerRemarksSchema,
44327
+ manpowerSitesSchema,
43441
44328
  nfcPatrolSettingsSchema,
43442
44329
  nfcPatrolSettingsSchemaUpdate,
44330
+ occurrence_book_namespace_collection,
43443
44331
  orgSchema,
43444
44332
  overnight_parking_requests_namespace_collection,
43445
44333
  pestDashboardCollection,
@@ -43520,6 +44408,8 @@ export {
43520
44408
  siteSchema,
43521
44409
  site_people_namespace_collection,
43522
44410
  tokenSchema,
44411
+ updateRemarksStatusEod,
44412
+ updateRemarksisAcknowledged,
43523
44413
  updateSiteSchema,
43524
44414
  useAccessManagementController,
43525
44415
  useAddressRepo,
@@ -43586,6 +44476,9 @@ export {
43586
44476
  useManpowerMonitoringSrvc,
43587
44477
  useManpowerRemarkCtrl,
43588
44478
  useManpowerRemarksRepo,
44479
+ useManpowerSitesCtrl,
44480
+ useManpowerSitesRepo,
44481
+ useManpowerSitesSrvc,
43589
44482
  useMemberController,
43590
44483
  useMemberRepo,
43591
44484
  useNewDashboardController,