@7365admin1/core 2.77.0 → 2.79.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -225,6 +225,7 @@ __export(src_exports, {
225
225
  schemaFormEntry: () => schemaFormEntry,
226
226
  schemaGuestManagement: () => schemaGuestManagement,
227
227
  schemaIncidentReport: () => schemaIncidentReport,
228
+ schemaMultipleDocumentManagement: () => schemaMultipleDocumentManagement,
228
229
  schemaNfcPatrolLog: () => schemaNfcPatrolLog,
229
230
  schemaNfcPatrolRoute: () => schemaNfcPatrolRoute,
230
231
  schemaNfcPatrolTag: () => schemaNfcPatrolTag,
@@ -416,7 +417,7 @@ __export(src_exports, {
416
417
  usePersonRepo: () => usePersonRepo,
417
418
  usePostFavoriteController: () => usePostFavoriteController,
418
419
  usePostFavoriteRepo: () => usePostFavoriteRepo,
419
- usePostFavoriteService: () => usePostFavoriteService,
420
+ usePostFavoriteService: () => usePostFavoriteService2,
420
421
  usePostPrelovedController: () => usePostPrelovedController,
421
422
  usePostPrelovedRepo: () => usePostPrelovedRepo,
422
423
  usePriceController: () => usePriceController,
@@ -5196,6 +5197,38 @@ function useOrgRepo() {
5196
5197
  throw new import_node_server_utils17.NotFoundError("Organization not found.");
5197
5198
  return org;
5198
5199
  }
5200
+ async function completeOnboardingById(_id, session) {
5201
+ try {
5202
+ _id = new import_mongodb15.ObjectId(_id);
5203
+ } catch (error) {
5204
+ throw new import_node_server_utils17.BadRequestError("Invalid organization ID format.");
5205
+ }
5206
+ try {
5207
+ const result = await collection.updateOne(
5208
+ { _id },
5209
+ {
5210
+ $set: {
5211
+ onboardingCompleted: true,
5212
+ onboardingCompletedAt: /* @__PURE__ */ new Date(),
5213
+ updatedAt: /* @__PURE__ */ new Date()
5214
+ }
5215
+ },
5216
+ { session }
5217
+ );
5218
+ if (result.matchedCount === 0) {
5219
+ throw new import_node_server_utils17.NotFoundError("Organization not found.");
5220
+ }
5221
+ await delNamespace();
5222
+ return "Successfully completed organization onboarding.";
5223
+ } catch (error) {
5224
+ if (error instanceof import_node_server_utils17.AppError) {
5225
+ throw error;
5226
+ }
5227
+ throw new import_node_server_utils17.InternalServerError(
5228
+ "Failed to complete organization onboarding."
5229
+ );
5230
+ }
5231
+ }
5199
5232
  return {
5200
5233
  createIndex,
5201
5234
  createTextIndex,
@@ -5211,7 +5244,8 @@ function useOrgRepo() {
5211
5244
  deleteById,
5212
5245
  getOrgsByEmail,
5213
5246
  getOrganizationsWithSubscription,
5214
- getAdminOrgForResident
5247
+ getAdminOrgForResident,
5248
+ completeOnboardingById
5215
5249
  };
5216
5250
  }
5217
5251
 
@@ -9303,7 +9337,8 @@ function useOrgController() {
9303
9337
  add: _add,
9304
9338
  update: _update,
9305
9339
  getOrgsByEmail: _getOrgsByEmail,
9306
- getAdminOrgForResident: _getAdminOrgForResident
9340
+ getAdminOrgForResident: _getAdminOrgForResident,
9341
+ completeOnboardingById: _completeOnboardingById
9307
9342
  } = useOrgRepo();
9308
9343
  async function add(req, res, next) {
9309
9344
  const validation = import_joi18.default.object({
@@ -9549,6 +9584,35 @@ function useOrgController() {
9549
9584
  next(error);
9550
9585
  }
9551
9586
  }
9587
+ async function completeOnboarding(req, res, next) {
9588
+ const validation = import_joi18.default.string().hex().required();
9589
+ const id = req.params.id;
9590
+ const { error } = validation.validate(id);
9591
+ if (error) {
9592
+ import_node_server_utils35.logger.log({
9593
+ level: "error",
9594
+ message: error.message
9595
+ });
9596
+ next(new import_node_server_utils35.BadRequestError(error.message));
9597
+ return;
9598
+ }
9599
+ try {
9600
+ await _completeOnboardingById(id);
9601
+ const data = await _getById(id);
9602
+ res.json({
9603
+ message: "Organization onboarding completed successfully",
9604
+ data
9605
+ });
9606
+ return;
9607
+ } catch (error2) {
9608
+ import_node_server_utils35.logger.log({
9609
+ level: "error",
9610
+ message: error2.message
9611
+ });
9612
+ next(error2);
9613
+ return;
9614
+ }
9615
+ }
9552
9616
  return {
9553
9617
  add,
9554
9618
  addOnboardingOrg,
@@ -9559,7 +9623,8 @@ function useOrgController() {
9559
9623
  getByEmail,
9560
9624
  update,
9561
9625
  getOrgsByEmail,
9562
- getAdminOrgForResident
9626
+ getAdminOrgForResident,
9627
+ completeOnboarding
9563
9628
  };
9564
9629
  }
9565
9630
 
@@ -15267,29 +15332,23 @@ function useVisitorTransactionRepo() {
15267
15332
  ...status && { status },
15268
15333
  ...tab == "Overnight Parking" && { isOvernightParking: true }
15269
15334
  };
15270
- sort = Object.keys(sort).length > 0 ? sort : { latestDate: -1 };
15335
+ const finalSort = Object.keys(sort).length > 0 ? sort : { latestDate: -1 };
15271
15336
  try {
15272
15337
  const basePipeline = [
15273
15338
  { $match: query },
15274
15339
  {
15275
15340
  $addFields: {
15276
- latestDate: {
15277
- $max: ["$createdAt", "$updatedAt"]
15278
- }
15341
+ latestDate: { $max: ["$createdAt", "$updatedAt"] }
15279
15342
  }
15280
15343
  },
15281
- { $sort: { latestDate: -1 } },
15282
- { $skip: skip },
15283
- { $limit: limit },
15284
- {
15285
- $project: {
15286
- latestDate: 0
15287
- }
15288
- }
15344
+ { $sort: finalSort }
15289
15345
  ];
15290
15346
  const [items, countResult] = await Promise.all([
15291
15347
  collection.aggregate([
15292
15348
  ...basePipeline,
15349
+ { $skip: skip },
15350
+ { $limit: limit },
15351
+ { $project: { latestDate: 0 } },
15293
15352
  {
15294
15353
  $lookup: {
15295
15354
  from: "access-cards",
@@ -15913,13 +15972,15 @@ function useVehicleRepo() {
15913
15972
  sort = {},
15914
15973
  type = "",
15915
15974
  category = "",
15916
- status = ""
15975
+ status = "",
15976
+ site = ""
15917
15977
  }) {
15918
15978
  page = page > 0 ? page - 1 : 0;
15919
15979
  const baseQuery = {
15920
15980
  ...status && { status },
15921
15981
  ...type && { type },
15922
- ...category && { category }
15982
+ ...category && { category },
15983
+ ...site && { site: new import_mongodb42.ObjectId(site) }
15923
15984
  };
15924
15985
  let query = { ...baseQuery };
15925
15986
  if (search)
@@ -15952,6 +16013,7 @@ function useVehicleRepo() {
15952
16013
  recNo: 1,
15953
16014
  nric: 1,
15954
16015
  plateNumber: 1,
16016
+ site: 1,
15955
16017
  createdAt: 1,
15956
16018
  updatedAt: 1
15957
16019
  }
@@ -15981,6 +16043,7 @@ function useVehicleRepo() {
15981
16043
  unit: { $first: "$unit" },
15982
16044
  unitName: { $first: "$unitName" },
15983
16045
  nric: { $first: "$nric" },
16046
+ site: { $first: "$site" },
15984
16047
  createdAt: { $min: "$createdAt" },
15985
16048
  updatedAt: { $max: "$updatedAt" },
15986
16049
  plates: {
@@ -16007,6 +16070,7 @@ function useVehicleRepo() {
16007
16070
  unit: 1,
16008
16071
  unitName: 1,
16009
16072
  nric: 1,
16073
+ site: 1,
16010
16074
  plates: {
16011
16075
  $filter: {
16012
16076
  input: "$plates",
@@ -23165,7 +23229,8 @@ function useVehicleController() {
23165
23229
  order: import_joi48.default.string().optional().valid(...Object.values(SortOrder)),
23166
23230
  type: import_joi48.default.string().optional().valid(...Object.values(VehicleType)).allow(null, ""),
23167
23231
  category: import_joi48.default.string().optional().valid(...Object.values(VehicleCategory)).allow(null, ""),
23168
- status: import_joi48.default.string().optional().valid(...Object.values(VehicleStatus)).allow(null, "")
23232
+ status: import_joi48.default.string().optional().valid(...Object.values(VehicleStatus)).allow(null, ""),
23233
+ site: import_joi48.default.string().hex().length(24).optional().allow(null, "")
23169
23234
  });
23170
23235
  const { error, value } = schema2.validate(req.query, {
23171
23236
  abortEarly: false
@@ -23176,7 +23241,7 @@ function useVehicleController() {
23176
23241
  next(new import_node_server_utils91.BadRequestError(messages));
23177
23242
  return;
23178
23243
  }
23179
- const { search, page, limit, type, category, status, sort, order } = value;
23244
+ const { search, page, limit, type, category, status, sort, order, site } = value;
23180
23245
  let sortObj;
23181
23246
  if (sort === "updatedAt" /* UPDATED_AT */) {
23182
23247
  sortObj = order === "asc" /* ASC */ ? { updatedAt: 1, createdAt: 1, _id: 1 } : { updatedAt: -1, createdAt: -1, _id: -1 };
@@ -23193,7 +23258,8 @@ function useVehicleController() {
23193
23258
  // sort: sortObj,
23194
23259
  type,
23195
23260
  category,
23196
- status
23261
+ status,
23262
+ site
23197
23263
  });
23198
23264
  res.json(data);
23199
23265
  return;
@@ -32452,12 +32518,51 @@ function useSiteFacilityBookingController() {
32452
32518
  // src/models/document-management.model.ts
32453
32519
  var import_joi75 = __toESM(require("joi"));
32454
32520
  var import_mongodb79 = require("mongodb");
32521
+ var schemaMultipleDocumentManagement = import_joi75.default.object({
32522
+ _id: import_joi75.default.string().hex().optional().allow("", null),
32523
+ name: import_joi75.default.string().required(),
32524
+ type: import_joi75.default.string().optional().allow("", null),
32525
+ size: import_joi75.default.number().optional().allow(null, "").default(0),
32526
+ items: import_joi75.default.when("type", {
32527
+ is: "folder",
32528
+ then: import_joi75.default.forbidden(),
32529
+ otherwise: import_joi75.default.array().items(
32530
+ import_joi75.default.object({
32531
+ id: import_joi75.default.string().hex().required(),
32532
+ name: import_joi75.default.string().optional().allow("", null),
32533
+ type: import_joi75.default.string().optional().allow("", null),
32534
+ size: import_joi75.default.number().optional().allow(null, "").default(0),
32535
+ attachment: import_joi75.default.alternatives().try(
32536
+ import_joi75.default.string().optional().allow("", null),
32537
+ import_joi75.default.array().items(import_joi75.default.string()).optional()
32538
+ ),
32539
+ remarks: import_joi75.default.string().optional().allow("", null)
32540
+ })
32541
+ )
32542
+ }),
32543
+ remarks: import_joi75.default.string().optional().allow("", null),
32544
+ org: import_joi75.default.string().hex().optional().allow("", null),
32545
+ site: import_joi75.default.string().hex().optional().allow("", null),
32546
+ parentId: import_joi75.default.string().hex().optional().allow("", null),
32547
+ createdBy: import_joi75.default.string().hex().required(),
32548
+ updatedBy: import_joi75.default.string().hex().optional().allow("", null),
32549
+ createdAt: import_joi75.default.date().optional().allow("", null),
32550
+ updatedAt: import_joi75.default.date().optional().allow("", null),
32551
+ status: import_joi75.default.string().optional().allow("", null).default("active")
32552
+ });
32455
32553
  var schemaDocumentManagement = import_joi75.default.object({
32456
32554
  _id: import_joi75.default.string().hex().optional().allow("", null),
32457
32555
  name: import_joi75.default.string().required(),
32458
32556
  type: import_joi75.default.string().optional().allow("", null),
32459
32557
  size: import_joi75.default.number().optional().allow(null, "").default(0),
32460
- attachment: import_joi75.default.when("type", { is: "folder", then: import_joi75.default.forbidden(), otherwise: import_joi75.default.string().optional().allow("", null) }),
32558
+ attachment: import_joi75.default.when("type", {
32559
+ is: "folder",
32560
+ then: import_joi75.default.forbidden(),
32561
+ otherwise: import_joi75.default.alternatives().try(
32562
+ import_joi75.default.string().optional().allow("", null),
32563
+ import_joi75.default.array().items(import_joi75.default.string()).optional()
32564
+ )
32565
+ }),
32461
32566
  remarks: import_joi75.default.string().optional().allow("", null),
32462
32567
  org: import_joi75.default.string().hex().optional().allow("", null),
32463
32568
  site: import_joi75.default.string().hex().optional().allow("", null),
@@ -32473,14 +32578,19 @@ var schemaUpdateDocumentManagement = import_joi75.default.object({
32473
32578
  name: import_joi75.default.string().optional().allow("", null),
32474
32579
  type: import_joi75.default.string().optional().allow("", null),
32475
32580
  size: import_joi75.default.number().optional().allow(null, ""),
32476
- attachment: import_joi75.default.when("type", { is: "folder", then: import_joi75.default.forbidden(), otherwise: import_joi75.default.string().optional().allow("", null) }),
32581
+ attachment: import_joi75.default.when("type", {
32582
+ is: "folder",
32583
+ then: import_joi75.default.forbidden(),
32584
+ otherwise: import_joi75.default.alternatives().try(
32585
+ import_joi75.default.string().optional().allow("", null),
32586
+ import_joi75.default.array().items(import_joi75.default.string()).optional()
32587
+ )
32588
+ }),
32477
32589
  remarks: import_joi75.default.string().optional().allow("", null),
32478
32590
  org: import_joi75.default.string().hex().optional().allow("", null),
32479
32591
  site: import_joi75.default.string().hex().optional().allow("", null),
32480
32592
  parentId: import_joi75.default.string().hex().optional().allow("", null),
32481
- updatedBy: import_joi75.default.string().hex().optional().allow("", null),
32482
- updatedAt: import_joi75.default.date().optional().allow("", null),
32483
- status: import_joi75.default.string().optional().allow("", null)
32593
+ updatedBy: import_joi75.default.string().hex().optional().allow("", null)
32484
32594
  });
32485
32595
  function MDocumentManagement(value) {
32486
32596
  const { error } = schemaDocumentManagement.validate(value);
@@ -32827,9 +32937,37 @@ function useDocumentManagementRepo() {
32827
32937
 
32828
32938
  // src/services/document-management.service.ts
32829
32939
  var import_node_server_utils137 = require("@7365admin1/node-server-utils");
32940
+ var import_mongodb81 = require("mongodb");
32830
32941
  function useDocumentManagementService() {
32831
32942
  const { add: _add, updateDocumentById: _updateDocumentById } = useDocumentManagementRepo();
32832
32943
  const { updateStatusById, getFileById } = useFileRepo();
32944
+ function normalizeAttachments(input) {
32945
+ if (!input)
32946
+ return [];
32947
+ if (typeof input === "string")
32948
+ return [{ id: input }];
32949
+ if (Array.isArray(input))
32950
+ return input.map(
32951
+ (it) => typeof it === "string" ? { id: it } : { id: it.id, name: it.name }
32952
+ );
32953
+ if (typeof input === "object")
32954
+ return [{ id: input.id, name: input.name }];
32955
+ return [];
32956
+ }
32957
+ function inferTypeFromName(name) {
32958
+ if (!name)
32959
+ return void 0;
32960
+ const lower = name.toLowerCase();
32961
+ if (lower.endsWith(".pdf"))
32962
+ return "pdf";
32963
+ if (lower.endsWith(".csv"))
32964
+ return "csv";
32965
+ if (lower.endsWith(".doc") || lower.endsWith(".docx"))
32966
+ return "doc";
32967
+ if (lower.endsWith(".xls") || lower.endsWith(".xlsx"))
32968
+ return "csv";
32969
+ return void 0;
32970
+ }
32833
32971
  async function createDocument(value) {
32834
32972
  const session = import_node_server_utils137.useAtlas.getClient()?.startSession();
32835
32973
  if (!session) {
@@ -32837,21 +32975,97 @@ function useDocumentManagementService() {
32837
32975
  }
32838
32976
  try {
32839
32977
  await session.startTransaction();
32840
- const document2 = value?.attachment ?? "";
32841
- if (document2) {
32842
- const file = await updateStatusById(
32843
- document2,
32844
- { status: "active" },
32845
- session
32846
- );
32847
- if (!file) {
32848
- throw new import_node_server_utils137.NotFoundError("File not found.");
32978
+ if ("items" in value && Array.isArray(value.items)) {
32979
+ for (const item of value.items) {
32980
+ const attachments = normalizeAttachments(item.attachment);
32981
+ let itemType = item.type;
32982
+ let itemSize = item.size ?? 0;
32983
+ if (attachments.length) {
32984
+ let totalSize = 0;
32985
+ for (const att of attachments) {
32986
+ await updateStatusById(att.id, { status: "active" }, session);
32987
+ try {
32988
+ const storedFile = await getFileById(att.id);
32989
+ if (storedFile) {
32990
+ totalSize += storedFile?.size ?? storedFile?.file_size ?? 0;
32991
+ if (!att.name) {
32992
+ att.name = storedFile?.name ?? att.id;
32993
+ }
32994
+ if (!att.type) {
32995
+ att.type = storedFile?.type ?? inferTypeFromName(att.name);
32996
+ }
32997
+ }
32998
+ } catch (err) {
32999
+ import_node_server_utils137.logger.log({
33000
+ level: "error",
33001
+ message: `Failed to retrieve file ${att.id}: ${err}`
33002
+ });
33003
+ }
33004
+ }
33005
+ item.attachment = attachments;
33006
+ itemSize = totalSize;
33007
+ const types = Array.from(
33008
+ new Set(attachments.map((a) => a.type).filter(Boolean))
33009
+ );
33010
+ if (types.length === 1) {
33011
+ itemType = types[0];
33012
+ } else if (types.length > 1) {
33013
+ itemType = "mixed";
33014
+ }
33015
+ }
33016
+ const doc = {
33017
+ _id: typeof item.id === "string" ? new import_mongodb81.ObjectId(item.id) : item.id,
33018
+ name: item.name || value.name,
33019
+ remarks: item.remarks || value.remarks,
33020
+ org: value.org,
33021
+ site: value.site,
33022
+ parentId: value.parentId,
33023
+ createdBy: value.createdBy,
33024
+ status: value.status || "active",
33025
+ attachment: item.attachment,
33026
+ type: itemType,
33027
+ size: itemSize
33028
+ };
33029
+ await _add(doc, session);
33030
+ }
33031
+ } else {
33032
+ const val = value;
33033
+ const attachments = normalizeAttachments(val.attachment);
33034
+ if (attachments.length) {
33035
+ let totalSize = 0;
33036
+ for (const att of attachments) {
33037
+ await updateStatusById(att.id, { status: "active" }, session);
33038
+ try {
33039
+ const storedFile = await getFileById(att.id);
33040
+ if (storedFile) {
33041
+ totalSize += storedFile?.size ?? storedFile?.file_size ?? 0;
33042
+ if (!att.name) {
33043
+ att.name = storedFile?.name ?? att.id;
33044
+ }
33045
+ if (!att.type) {
33046
+ att.type = storedFile?.type ?? inferTypeFromName(att.name);
33047
+ }
33048
+ }
33049
+ } catch (err) {
33050
+ import_node_server_utils137.logger.log({
33051
+ level: "error",
33052
+ message: `Failed to retrieve file ${att.id}: ${err}`
33053
+ });
33054
+ }
33055
+ }
33056
+ val.attachment = attachments;
33057
+ val.size = totalSize;
33058
+ const types = Array.from(
33059
+ new Set(attachments.map((a) => a.type).filter(Boolean))
33060
+ );
33061
+ if (types.length === 1) {
33062
+ val.type = types[0];
33063
+ } else if (types.length > 1) {
33064
+ val.type = "mixed";
33065
+ }
32849
33066
  }
32850
- const { getFileById: getFileById2 } = useFileRepo();
32851
- const storedFile = await getFileById2(document2);
32852
- value.size = storedFile?.size ?? storedFile?.file_size ?? 0;
33067
+ await _add(val, session);
32853
33068
  }
32854
- await _add(value, session);
32855
33069
  await session?.commitTransaction();
32856
33070
  return "Successfully added document.";
32857
33071
  } catch (error) {
@@ -32869,20 +33083,40 @@ function useDocumentManagementService() {
32869
33083
  delete value.attachment;
32870
33084
  delete value.size;
32871
33085
  } else {
32872
- if (Array.isArray(value.attachment)) {
32873
- value.attachment = value.attachment[0];
32874
- } else if (!value.attachment) {
32875
- value.attachment = "";
32876
- }
32877
- if (value.attachment) {
32878
- try {
32879
- const f = await getFileById(value.attachment);
32880
- value.size = f?.size ?? f?.file_size ?? 0;
32881
- } catch (err) {
32882
- value.size = 0;
32883
- }
32884
- } else {
33086
+ const attachments = normalizeAttachments(value.attachment);
33087
+ if (!attachments.length) {
33088
+ value.attachment = [];
32885
33089
  value.size = 0;
33090
+ } else {
33091
+ let totalSize = 0;
33092
+ for (const att of attachments) {
33093
+ try {
33094
+ const f = await getFileById(att.id);
33095
+ if (f) {
33096
+ totalSize += f?.size ?? f?.file_size ?? 0;
33097
+ if (!att.name)
33098
+ att.name = f?.name ?? att.id;
33099
+ if (!att.type) {
33100
+ att.type = f?.type ?? inferTypeFromName(att.name);
33101
+ }
33102
+ }
33103
+ } catch (err) {
33104
+ import_node_server_utils137.logger.log({
33105
+ level: "error",
33106
+ message: `Failed to retrieve file ${att.id}: ${err}`
33107
+ });
33108
+ }
33109
+ }
33110
+ value.attachment = attachments;
33111
+ value.size = totalSize;
33112
+ const types = Array.from(
33113
+ new Set(attachments.map((a) => a.type).filter(Boolean))
33114
+ );
33115
+ if (types.length === 1) {
33116
+ value.type = types[0];
33117
+ } else if (types.length > 1) {
33118
+ value.type = "mixed";
33119
+ }
32886
33120
  }
32887
33121
  }
32888
33122
  return await _updateDocumentById(_id, value);
@@ -32922,13 +33156,10 @@ function useDocumentManagementController() {
32922
33156
  if (payload.type === "folder") {
32923
33157
  delete payload.attachment;
32924
33158
  } else {
32925
- if (Array.isArray(payload.attachment)) {
32926
- payload.attachment = payload.attachment[0];
32927
- } else if (!payload.attachment) {
32928
- payload.attachment = "";
32929
- }
32930
33159
  }
32931
- const { error } = schemaDocumentManagement.validate(payload, {
33160
+ const hasItems = Array.isArray(payload.items);
33161
+ const schema2 = hasItems ? schemaMultipleDocumentManagement : schemaDocumentManagement;
33162
+ const { error } = schema2.validate(payload, {
32932
33163
  abortEarly: false
32933
33164
  });
32934
33165
  if (error) {
@@ -33009,14 +33240,6 @@ function useDocumentManagementController() {
33009
33240
  }
33010
33241
  }
33011
33242
  async function updateDocumentById(req, res, next) {
33012
- const validation = import_joi76.default.object({
33013
- _id: import_joi76.default.string().hex().required(),
33014
- attachment: import_joi76.default.string().optional(),
33015
- name: import_joi76.default.string().required(),
33016
- type: import_joi76.default.string().optional().allow("", null),
33017
- status: import_joi76.default.string().optional().allow("", null),
33018
- updatedBy: import_joi76.default.string().hex().optional().allow("", null)
33019
- });
33020
33243
  const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
33021
33244
  (acc, [key, value]) => ({ ...acc, [key]: value }),
33022
33245
  {}
@@ -33038,7 +33261,10 @@ function useDocumentManagementController() {
33038
33261
  if (payload.size !== void 0) {
33039
33262
  delete payload.size;
33040
33263
  }
33041
- const { error } = validation.validate({ _id, ...payload });
33264
+ const { error } = schemaUpdateDocumentManagement.validate(
33265
+ { _id, ...payload },
33266
+ { abortEarly: false }
33267
+ );
33042
33268
  if (error) {
33043
33269
  import_node_server_utils138.logger.log({ level: "error", message: error.message });
33044
33270
  next(new import_node_server_utils138.BadRequestError(error.message));
@@ -33105,7 +33331,7 @@ function useDocumentManagementController() {
33105
33331
 
33106
33332
  // src/models/bulletin-board.model.ts
33107
33333
  var import_joi77 = __toESM(require("joi"));
33108
- var import_mongodb81 = require("mongodb");
33334
+ var import_mongodb82 = require("mongodb");
33109
33335
  var BulletinRecipient = /* @__PURE__ */ ((BulletinRecipient2) => {
33110
33336
  BulletinRecipient2["RESIDENT"] = "resident";
33111
33337
  BulletinRecipient2["SECURITY_AGENCY"] = "security_agency";
@@ -33185,21 +33411,21 @@ function MBulletinBoard(value) {
33185
33411
  }
33186
33412
  if (value._id && typeof value._id === "string") {
33187
33413
  try {
33188
- value._id = new import_mongodb81.ObjectId(value._id);
33414
+ value._id = new import_mongodb82.ObjectId(value._id);
33189
33415
  } catch {
33190
33416
  throw new Error("Invalid ID.");
33191
33417
  }
33192
33418
  }
33193
33419
  if (value.site && typeof value.site === "string") {
33194
33420
  try {
33195
- value.site = new import_mongodb81.ObjectId(value.site);
33421
+ value.site = new import_mongodb82.ObjectId(value.site);
33196
33422
  } catch {
33197
33423
  throw new Error("Invalid site ID.");
33198
33424
  }
33199
33425
  }
33200
33426
  if (value.orgId && typeof value.orgId === "string") {
33201
33427
  try {
33202
- value.orgId = new import_mongodb81.ObjectId(value.orgId);
33428
+ value.orgId = new import_mongodb82.ObjectId(value.orgId);
33203
33429
  } catch {
33204
33430
  throw new Error("Invalid org ID.");
33205
33431
  }
@@ -33208,7 +33434,7 @@ function MBulletinBoard(value) {
33208
33434
  value.file = value.file.map((f) => {
33209
33435
  if (f._id && typeof f._id === "string") {
33210
33436
  try {
33211
- return { ...f, _id: new import_mongodb81.ObjectId(f._id) };
33437
+ return { ...f, _id: new import_mongodb82.ObjectId(f._id) };
33212
33438
  } catch {
33213
33439
  throw new Error("Invalid file ID.");
33214
33440
  }
@@ -33217,7 +33443,7 @@ function MBulletinBoard(value) {
33217
33443
  });
33218
33444
  }
33219
33445
  return {
33220
- _id: value._id ?? new import_mongodb81.ObjectId(),
33446
+ _id: value._id ?? new import_mongodb82.ObjectId(),
33221
33447
  site: value.site ?? "",
33222
33448
  orgId: value.orgId ?? "",
33223
33449
  recipients: value.recipients ?? [],
@@ -33236,7 +33462,7 @@ function MBulletinBoard(value) {
33236
33462
 
33237
33463
  // src/repositories/bulletin-board.repo.ts
33238
33464
  var import_node_server_utils139 = require("@7365admin1/node-server-utils");
33239
- var import_mongodb82 = require("mongodb");
33465
+ var import_mongodb83 = require("mongodb");
33240
33466
  var bulletin_boards_namespace_collection = "bulletin-boards";
33241
33467
  function useBulletinBoardRepo() {
33242
33468
  const db = import_node_server_utils139.useAtlas.getDb();
@@ -33289,7 +33515,7 @@ function useBulletinBoardRepo() {
33289
33515
  }, session) {
33290
33516
  page = page > 0 ? page - 1 : 0;
33291
33517
  try {
33292
- site = new import_mongodb82.ObjectId(site);
33518
+ site = new import_mongodb83.ObjectId(site);
33293
33519
  } catch (error) {
33294
33520
  throw new import_node_server_utils139.BadRequestError("Invalid site ID format.");
33295
33521
  }
@@ -33348,7 +33574,7 @@ function useBulletinBoardRepo() {
33348
33574
  }
33349
33575
  async function getBulletinBoardById(_id, session) {
33350
33576
  try {
33351
- _id = new import_mongodb82.ObjectId(_id);
33577
+ _id = new import_mongodb83.ObjectId(_id);
33352
33578
  } catch (error) {
33353
33579
  throw new import_node_server_utils139.BadRequestError("Invalid bulletin board ID format.");
33354
33580
  }
@@ -33378,13 +33604,13 @@ function useBulletinBoardRepo() {
33378
33604
  async function updateBulletinBoardById(_id, value, session) {
33379
33605
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
33380
33606
  try {
33381
- _id = new import_mongodb82.ObjectId(_id);
33607
+ _id = new import_mongodb83.ObjectId(_id);
33382
33608
  } catch (error) {
33383
33609
  throw new import_node_server_utils139.BadRequestError("Invalid ID format.");
33384
33610
  }
33385
33611
  if (value.site && typeof value.site === "string") {
33386
33612
  try {
33387
- value.site = new import_mongodb82.ObjectId(value.site);
33613
+ value.site = new import_mongodb83.ObjectId(value.site);
33388
33614
  } catch {
33389
33615
  throw new Error("Invalid site ID.");
33390
33616
  }
@@ -33415,7 +33641,7 @@ function useBulletinBoardRepo() {
33415
33641
  }
33416
33642
  async function deleteBulletinBoardById(_id, session) {
33417
33643
  try {
33418
- _id = new import_mongodb82.ObjectId(_id);
33644
+ _id = new import_mongodb83.ObjectId(_id);
33419
33645
  } catch (error) {
33420
33646
  throw new import_node_server_utils139.BadRequestError("Invalid bulletin board ID format.");
33421
33647
  }
@@ -33849,7 +34075,7 @@ function useBulletinBoardController() {
33849
34075
 
33850
34076
  // src/models/site-billing-item.model.ts
33851
34077
  var import_node_server_utils142 = require("@7365admin1/node-server-utils");
33852
- var import_mongodb83 = require("mongodb");
34078
+ var import_mongodb84 = require("mongodb");
33853
34079
  var import_joi79 = __toESM(require("joi"));
33854
34080
 
33855
34081
  // src/types/enums/billing-frequency.enum.ts
@@ -33920,21 +34146,21 @@ function MBillingItem(value) {
33920
34146
  }
33921
34147
  if (value._id && typeof value._id === "string") {
33922
34148
  try {
33923
- value._id = new import_mongodb83.ObjectId(value._id);
34149
+ value._id = new import_mongodb84.ObjectId(value._id);
33924
34150
  } catch {
33925
34151
  throw new import_node_server_utils142.BadRequestError("Invalid _id format");
33926
34152
  }
33927
34153
  }
33928
34154
  if (value.site && typeof value.site === "string") {
33929
34155
  try {
33930
- value.site = new import_mongodb83.ObjectId(value.site);
34156
+ value.site = new import_mongodb84.ObjectId(value.site);
33931
34157
  } catch {
33932
34158
  throw new import_node_server_utils142.BadRequestError("Invalid site id format");
33933
34159
  }
33934
34160
  }
33935
34161
  if (value.org && typeof value.org === "string") {
33936
34162
  try {
33937
- value.org = new import_mongodb83.ObjectId(value.org);
34163
+ value.org = new import_mongodb84.ObjectId(value.org);
33938
34164
  } catch {
33939
34165
  throw new import_node_server_utils142.BadRequestError("Invalid org id format");
33940
34166
  }
@@ -33943,7 +34169,7 @@ function MBillingItem(value) {
33943
34169
  value.units = value.units.map((unit) => {
33944
34170
  if (unit._id && typeof unit._id === "string") {
33945
34171
  try {
33946
- unit._id = new import_mongodb83.ObjectId(unit._id);
34172
+ unit._id = new import_mongodb84.ObjectId(unit._id);
33947
34173
  } catch {
33948
34174
  throw new import_node_server_utils142.BadRequestError("Invalid unit id format");
33949
34175
  }
@@ -33952,7 +34178,7 @@ function MBillingItem(value) {
33952
34178
  });
33953
34179
  }
33954
34180
  return {
33955
- _id: value._id ?? new import_mongodb83.ObjectId(),
34181
+ _id: value._id ?? new import_mongodb84.ObjectId(),
33956
34182
  site: value.site,
33957
34183
  org: value.org,
33958
34184
  name: value.name,
@@ -33980,7 +34206,7 @@ function MBillingItem(value) {
33980
34206
 
33981
34207
  // src/repositories/site-billing-item.repo.ts
33982
34208
  var import_node_server_utils143 = require("@7365admin1/node-server-utils");
33983
- var import_mongodb84 = require("mongodb");
34209
+ var import_mongodb85 = require("mongodb");
33984
34210
  function useSiteBillingItemRepo() {
33985
34211
  const db = import_node_server_utils143.useAtlas.getDb();
33986
34212
  if (!db) {
@@ -34067,7 +34293,7 @@ function useSiteBillingItemRepo() {
34067
34293
  }
34068
34294
  ]
34069
34295
  },
34070
- ...import_mongodb84.ObjectId.isValid(site) && { site: new import_mongodb84.ObjectId(site) }
34296
+ ...import_mongodb85.ObjectId.isValid(site) && { site: new import_mongodb85.ObjectId(site) }
34071
34297
  };
34072
34298
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
34073
34299
  const cacheOptions = {
@@ -34107,7 +34333,7 @@ function useSiteBillingItemRepo() {
34107
34333
  }
34108
34334
  async function getById(_id, session) {
34109
34335
  try {
34110
- _id = new import_mongodb84.ObjectId(_id);
34336
+ _id = new import_mongodb85.ObjectId(_id);
34111
34337
  } catch (error) {
34112
34338
  throw new import_node_server_utils143.BadRequestError("Invalid ID.");
34113
34339
  }
@@ -34146,22 +34372,22 @@ function useSiteBillingItemRepo() {
34146
34372
  }
34147
34373
  async function updateById(_id, value, session) {
34148
34374
  try {
34149
- _id = new import_mongodb84.ObjectId(_id);
34375
+ _id = new import_mongodb85.ObjectId(_id);
34150
34376
  } catch (error) {
34151
34377
  throw new import_node_server_utils143.BadRequestError(
34152
34378
  "Invalid site billing item transaction ID format."
34153
34379
  );
34154
34380
  }
34155
- if (value.site && import_mongodb84.ObjectId.isValid(value.site.toString())) {
34381
+ if (value.site && import_mongodb85.ObjectId.isValid(value.site.toString())) {
34156
34382
  try {
34157
- value.site = new import_mongodb84.ObjectId(value.site.toString());
34383
+ value.site = new import_mongodb85.ObjectId(value.site.toString());
34158
34384
  } catch {
34159
34385
  throw new import_node_server_utils143.BadRequestError("Invalid _id format");
34160
34386
  }
34161
34387
  }
34162
- if (value.org && import_mongodb84.ObjectId.isValid(value.org.toString())) {
34388
+ if (value.org && import_mongodb85.ObjectId.isValid(value.org.toString())) {
34163
34389
  try {
34164
- value.org = new import_mongodb84.ObjectId(value.org.toString());
34390
+ value.org = new import_mongodb85.ObjectId(value.org.toString());
34165
34391
  } catch {
34166
34392
  throw new import_node_server_utils143.BadRequestError("Invalid _id format");
34167
34393
  }
@@ -34181,7 +34407,7 @@ function useSiteBillingItemRepo() {
34181
34407
  }
34182
34408
  async function deleteById(_id) {
34183
34409
  try {
34184
- _id = new import_mongodb84.ObjectId(_id);
34410
+ _id = new import_mongodb85.ObjectId(_id);
34185
34411
  } catch (error) {
34186
34412
  throw new import_node_server_utils143.BadRequestError(
34187
34413
  "Invalid site billing item transaction ID format."
@@ -34238,7 +34464,7 @@ var import_node_server_utils145 = require("@7365admin1/node-server-utils");
34238
34464
 
34239
34465
  // src/models/site-billing-configuration.model.ts
34240
34466
  var import_node_server_utils144 = require("@7365admin1/node-server-utils");
34241
- var import_mongodb85 = require("mongodb");
34467
+ var import_mongodb86 = require("mongodb");
34242
34468
  var import_joi80 = __toESM(require("joi"));
34243
34469
  var schemaBillingConfiguration = import_joi80.default.object({
34244
34470
  _id: import_joi80.default.string().hex().optional(),
@@ -34299,34 +34525,34 @@ function MBillingConfiguration(value) {
34299
34525
  }
34300
34526
  if (value._id && typeof value._id === "string") {
34301
34527
  try {
34302
- value._id = new import_mongodb85.ObjectId(value._id);
34528
+ value._id = new import_mongodb86.ObjectId(value._id);
34303
34529
  } catch {
34304
34530
  throw new import_node_server_utils144.BadRequestError("Invalid _id format");
34305
34531
  }
34306
34532
  }
34307
34533
  if (value.site && typeof value.site === "string") {
34308
34534
  try {
34309
- value.site = new import_mongodb85.ObjectId(value.site);
34535
+ value.site = new import_mongodb86.ObjectId(value.site);
34310
34536
  } catch {
34311
34537
  throw new import_node_server_utils144.BadRequestError("Invalid site id format");
34312
34538
  }
34313
34539
  }
34314
34540
  if (value.org && typeof value.org === "string") {
34315
34541
  try {
34316
- value.org = new import_mongodb85.ObjectId(value.org);
34542
+ value.org = new import_mongodb86.ObjectId(value.org);
34317
34543
  } catch {
34318
34544
  throw new import_node_server_utils144.BadRequestError("Invalid org id format");
34319
34545
  }
34320
34546
  }
34321
34547
  if (value.createdBy && typeof value.createdBy === "string") {
34322
34548
  try {
34323
- value.createdBy = new import_mongodb85.ObjectId(value.createdBy);
34549
+ value.createdBy = new import_mongodb86.ObjectId(value.createdBy);
34324
34550
  } catch {
34325
34551
  throw new import_node_server_utils144.BadRequestError("Invalid createdBy id format");
34326
34552
  }
34327
34553
  }
34328
34554
  return {
34329
- _id: value._id ?? new import_mongodb85.ObjectId(),
34555
+ _id: value._id ?? new import_mongodb86.ObjectId(),
34330
34556
  site: value.site,
34331
34557
  org: value.org,
34332
34558
  siteName: value.siteName,
@@ -34355,7 +34581,7 @@ function MBillingConfiguration(value) {
34355
34581
  }
34356
34582
 
34357
34583
  // src/repositories/site-billing-configuration.repo.ts
34358
- var import_mongodb86 = require("mongodb");
34584
+ var import_mongodb87 = require("mongodb");
34359
34585
  function useSiteBillingConfigurationRepo() {
34360
34586
  const db = import_node_server_utils145.useAtlas.getDb();
34361
34587
  if (!db) {
@@ -34428,7 +34654,7 @@ function useSiteBillingConfigurationRepo() {
34428
34654
  const query = {
34429
34655
  status,
34430
34656
  ...search && { $text: { $search: search } },
34431
- ...import_mongodb86.ObjectId.isValid(site) && { site: new import_mongodb86.ObjectId(site) }
34657
+ ...import_mongodb87.ObjectId.isValid(site) && { site: new import_mongodb87.ObjectId(site) }
34432
34658
  };
34433
34659
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
34434
34660
  const cacheOptions = {
@@ -34468,7 +34694,7 @@ function useSiteBillingConfigurationRepo() {
34468
34694
  }
34469
34695
  async function getById(_id) {
34470
34696
  try {
34471
- _id = new import_mongodb86.ObjectId(_id);
34697
+ _id = new import_mongodb87.ObjectId(_id);
34472
34698
  } catch (error) {
34473
34699
  throw new import_node_server_utils145.BadRequestError("Invalid ID.");
34474
34700
  }
@@ -34509,22 +34735,22 @@ function useSiteBillingConfigurationRepo() {
34509
34735
  }
34510
34736
  async function updateById(_id, value, session) {
34511
34737
  try {
34512
- _id = new import_mongodb86.ObjectId(_id);
34738
+ _id = new import_mongodb87.ObjectId(_id);
34513
34739
  } catch (error) {
34514
34740
  throw new import_node_server_utils145.BadRequestError(
34515
34741
  "Invalid site billing configuration transaction ID format."
34516
34742
  );
34517
34743
  }
34518
- if (value.site && import_mongodb86.ObjectId.isValid(value.site.toString())) {
34744
+ if (value.site && import_mongodb87.ObjectId.isValid(value.site.toString())) {
34519
34745
  try {
34520
- value.site = new import_mongodb86.ObjectId(value.site.toString());
34746
+ value.site = new import_mongodb87.ObjectId(value.site.toString());
34521
34747
  } catch {
34522
34748
  throw new import_node_server_utils145.BadRequestError("Invalid _id format");
34523
34749
  }
34524
34750
  }
34525
- if (value.org && import_mongodb86.ObjectId.isValid(value.org.toString())) {
34751
+ if (value.org && import_mongodb87.ObjectId.isValid(value.org.toString())) {
34526
34752
  try {
34527
- value.org = new import_mongodb86.ObjectId(value.org.toString());
34753
+ value.org = new import_mongodb87.ObjectId(value.org.toString());
34528
34754
  } catch {
34529
34755
  throw new import_node_server_utils145.BadRequestError("Invalid _id format");
34530
34756
  }
@@ -34544,7 +34770,7 @@ function useSiteBillingConfigurationRepo() {
34544
34770
  }
34545
34771
  async function deleteById(_id) {
34546
34772
  try {
34547
- _id = new import_mongodb86.ObjectId(_id);
34773
+ _id = new import_mongodb87.ObjectId(_id);
34548
34774
  } catch (error) {
34549
34775
  throw new import_node_server_utils145.BadRequestError(
34550
34776
  "Invalid site billing configuration transaction ID format."
@@ -35122,7 +35348,7 @@ function useSiteBillingConfigurationController() {
35122
35348
  }
35123
35349
 
35124
35350
  // src/models/event-management.model.ts
35125
- var import_mongodb87 = require("mongodb");
35351
+ var import_mongodb88 = require("mongodb");
35126
35352
  var import_joi83 = __toESM(require("joi"));
35127
35353
  var EventStatus = /* @__PURE__ */ ((EventStatus2) => {
35128
35354
  EventStatus2["PLANNED"] = "planned";
@@ -35166,20 +35392,20 @@ var schemaUpdateEventManagement = import_joi83.default.object({
35166
35392
  function MEventManagement(value) {
35167
35393
  if (value._id && typeof value._id === "string") {
35168
35394
  try {
35169
- value._id = new import_mongodb87.ObjectId(value._id);
35395
+ value._id = new import_mongodb88.ObjectId(value._id);
35170
35396
  } catch {
35171
35397
  throw new Error("Invalid ID.");
35172
35398
  }
35173
35399
  }
35174
35400
  if (value.site && typeof value.site === "string") {
35175
35401
  try {
35176
- value.site = new import_mongodb87.ObjectId(value.site);
35402
+ value.site = new import_mongodb88.ObjectId(value.site);
35177
35403
  } catch {
35178
35404
  throw new Error("Invalid site ID.");
35179
35405
  }
35180
35406
  }
35181
35407
  return {
35182
- _id: value._id ?? new import_mongodb87.ObjectId(),
35408
+ _id: value._id ?? new import_mongodb88.ObjectId(),
35183
35409
  site: value.site,
35184
35410
  title: value.title,
35185
35411
  description: value.description ?? "",
@@ -35194,7 +35420,7 @@ function MEventManagement(value) {
35194
35420
 
35195
35421
  // src/repositories/event-management.repo.ts
35196
35422
  var import_node_server_utils150 = require("@7365admin1/node-server-utils");
35197
- var import_mongodb88 = require("mongodb");
35423
+ var import_mongodb89 = require("mongodb");
35198
35424
  var events_namespace_collection = "event-management";
35199
35425
  function useEventManagementRepo() {
35200
35426
  const db = import_node_server_utils150.useAtlas.getDb();
@@ -35262,7 +35488,7 @@ function useEventManagementRepo() {
35262
35488
  }, session) {
35263
35489
  page = page > 0 ? page - 1 : 0;
35264
35490
  try {
35265
- site = new import_mongodb88.ObjectId(site);
35491
+ site = new import_mongodb89.ObjectId(site);
35266
35492
  } catch (error) {
35267
35493
  throw new import_node_server_utils150.BadRequestError("Invalid site ID format.");
35268
35494
  }
@@ -35350,7 +35576,7 @@ function useEventManagementRepo() {
35350
35576
  }
35351
35577
  async function getEventManagementById(_id, session) {
35352
35578
  try {
35353
- _id = new import_mongodb88.ObjectId(_id);
35579
+ _id = new import_mongodb89.ObjectId(_id);
35354
35580
  } catch (error) {
35355
35581
  throw new import_node_server_utils150.BadRequestError("Invalid event ID format.");
35356
35582
  }
@@ -35378,13 +35604,13 @@ function useEventManagementRepo() {
35378
35604
  async function updateEventManagementById(_id, value, session) {
35379
35605
  value.updatedAt = /* @__PURE__ */ new Date();
35380
35606
  try {
35381
- _id = new import_mongodb88.ObjectId(_id);
35607
+ _id = new import_mongodb89.ObjectId(_id);
35382
35608
  } catch (error) {
35383
35609
  throw new import_node_server_utils150.BadRequestError("Invalid ID format.");
35384
35610
  }
35385
35611
  if (value.site && typeof value.site === "string") {
35386
35612
  try {
35387
- value.site = new import_mongodb88.ObjectId(value.site);
35613
+ value.site = new import_mongodb89.ObjectId(value.site);
35388
35614
  } catch {
35389
35615
  throw new Error("Invalid site ID.");
35390
35616
  }
@@ -35415,7 +35641,7 @@ function useEventManagementRepo() {
35415
35641
  }
35416
35642
  async function deleteEventManagementById(_id) {
35417
35643
  try {
35418
- _id = new import_mongodb88.ObjectId(_id);
35644
+ _id = new import_mongodb89.ObjectId(_id);
35419
35645
  } catch (error) {
35420
35646
  throw new import_node_server_utils150.BadRequestError("Invalid event ID format.");
35421
35647
  }
@@ -35703,7 +35929,7 @@ function useEventManagementController() {
35703
35929
 
35704
35930
  // src/models/site-unit-billing.model.ts
35705
35931
  var import_node_server_utils153 = require("@7365admin1/node-server-utils");
35706
- var import_mongodb89 = require("mongodb");
35932
+ var import_mongodb90 = require("mongodb");
35707
35933
  var import_joi85 = __toESM(require("joi"));
35708
35934
  var Status = /* @__PURE__ */ ((Status2) => {
35709
35935
  Status2["PENDING"] = "pending";
@@ -35798,48 +36024,48 @@ function MUnitBilling(value) {
35798
36024
  }
35799
36025
  if (value._id && typeof value._id === "string") {
35800
36026
  try {
35801
- value._id = new import_mongodb89.ObjectId(value._id);
36027
+ value._id = new import_mongodb90.ObjectId(value._id);
35802
36028
  } catch {
35803
36029
  throw new import_node_server_utils153.BadRequestError("Invalid _id format");
35804
36030
  }
35805
36031
  }
35806
36032
  if (value.site && typeof value.site === "string") {
35807
36033
  try {
35808
- value.site = new import_mongodb89.ObjectId(value.site);
36034
+ value.site = new import_mongodb90.ObjectId(value.site);
35809
36035
  } catch {
35810
36036
  throw new import_node_server_utils153.BadRequestError("Invalid site id format");
35811
36037
  }
35812
36038
  }
35813
36039
  if (value.org && typeof value.org === "string") {
35814
36040
  try {
35815
- value.org = new import_mongodb89.ObjectId(value.org);
36041
+ value.org = new import_mongodb90.ObjectId(value.org);
35816
36042
  } catch {
35817
36043
  throw new import_node_server_utils153.BadRequestError("Invalid org id format");
35818
36044
  }
35819
36045
  }
35820
36046
  if (value.paidBy && typeof value.paidBy === "string") {
35821
36047
  try {
35822
- value.paidBy = new import_mongodb89.ObjectId(value.paidBy);
36048
+ value.paidBy = new import_mongodb90.ObjectId(value.paidBy);
35823
36049
  } catch {
35824
36050
  throw new import_node_server_utils153.BadRequestError("Invalid paidBy id format");
35825
36051
  }
35826
36052
  }
35827
36053
  if (value.billItem && typeof value.billItem === "string") {
35828
36054
  try {
35829
- value.billItem = new import_mongodb89.ObjectId(value.billItem);
36055
+ value.billItem = new import_mongodb90.ObjectId(value.billItem);
35830
36056
  } catch {
35831
36057
  throw new import_node_server_utils153.BadRequestError("Invalid billItem id format");
35832
36058
  }
35833
36059
  }
35834
36060
  if (value.unitId && typeof value.unitId === "string") {
35835
36061
  try {
35836
- value.unitId = new import_mongodb89.ObjectId(value.unitId);
36062
+ value.unitId = new import_mongodb90.ObjectId(value.unitId);
35837
36063
  } catch {
35838
36064
  throw new import_node_server_utils153.BadRequestError("Invalid unitId id format");
35839
36065
  }
35840
36066
  }
35841
36067
  return {
35842
- _id: value._id ?? new import_mongodb89.ObjectId(),
36068
+ _id: value._id ?? new import_mongodb90.ObjectId(),
35843
36069
  site: value.site ?? "",
35844
36070
  org: value.org ?? "",
35845
36071
  billItem: value.billItem ?? "",
@@ -35875,7 +36101,7 @@ function MUnitBilling(value) {
35875
36101
 
35876
36102
  // src/repositories/site-unit-billing.repo.ts
35877
36103
  var import_node_server_utils154 = require("@7365admin1/node-server-utils");
35878
- var import_mongodb90 = require("mongodb");
36104
+ var import_mongodb91 = require("mongodb");
35879
36105
  function useSiteUnitBillingRepo() {
35880
36106
  const db = import_node_server_utils154.useAtlas.getDb();
35881
36107
  if (!db) {
@@ -35925,7 +36151,7 @@ function useSiteUnitBillingRepo() {
35925
36151
  const res = await collection.insertOne(value, { session });
35926
36152
  const acronym = createAcronym(value.billName || "NA");
35927
36153
  const dateFormatted = formatDateString(/* @__PURE__ */ new Date());
35928
- const newId = new import_mongodb90.ObjectId(res.insertedId).toString().slice(-6);
36154
+ const newId = new import_mongodb91.ObjectId(res.insertedId).toString().slice(-6);
35929
36155
  const referenceNumber = `${acronym}${newId}${dateFormatted}`;
35930
36156
  await collection.updateOne(
35931
36157
  { _id: res.insertedId },
@@ -36003,7 +36229,7 @@ function useSiteUnitBillingRepo() {
36003
36229
  }
36004
36230
  ]
36005
36231
  },
36006
- ...import_mongodb90.ObjectId.isValid(site) && { site: new import_mongodb90.ObjectId(site) },
36232
+ ...import_mongodb91.ObjectId.isValid(site) && { site: new import_mongodb91.ObjectId(site) },
36007
36233
  ...dateExpr
36008
36234
  };
36009
36235
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
@@ -36069,7 +36295,7 @@ function useSiteUnitBillingRepo() {
36069
36295
  }
36070
36296
  async function getById(_id) {
36071
36297
  try {
36072
- _id = new import_mongodb90.ObjectId(_id);
36298
+ _id = new import_mongodb91.ObjectId(_id);
36073
36299
  } catch (error) {
36074
36300
  throw new import_node_server_utils154.BadRequestError("Invalid ID.");
36075
36301
  }
@@ -36128,8 +36354,8 @@ function useSiteUnitBillingRepo() {
36128
36354
  }
36129
36355
  const query = {
36130
36356
  status,
36131
- ...unitId && import_mongodb90.ObjectId.isValid(unitId) && { unitId: new import_mongodb90.ObjectId(unitId) },
36132
- ...site && import_mongodb90.ObjectId.isValid(site) && { site: new import_mongodb90.ObjectId(site) },
36357
+ ...unitId && import_mongodb91.ObjectId.isValid(unitId) && { unitId: new import_mongodb91.ObjectId(unitId) },
36358
+ ...site && import_mongodb91.ObjectId.isValid(site) && { site: new import_mongodb91.ObjectId(site) },
36133
36359
  ...dateExpr
36134
36360
  };
36135
36361
  try {
@@ -36167,43 +36393,43 @@ function useSiteUnitBillingRepo() {
36167
36393
  }
36168
36394
  async function updateById(_id, value, session) {
36169
36395
  try {
36170
- _id = new import_mongodb90.ObjectId(_id);
36396
+ _id = new import_mongodb91.ObjectId(_id);
36171
36397
  } catch (error) {
36172
36398
  throw new import_node_server_utils154.BadRequestError(
36173
36399
  "Invalid site unit billing transaction ID format."
36174
36400
  );
36175
36401
  }
36176
- if (value.site && import_mongodb90.ObjectId.isValid(value.site.toString())) {
36402
+ if (value.site && import_mongodb91.ObjectId.isValid(value.site.toString())) {
36177
36403
  try {
36178
- value.site = new import_mongodb90.ObjectId(value.site.toString());
36404
+ value.site = new import_mongodb91.ObjectId(value.site.toString());
36179
36405
  } catch {
36180
36406
  throw new import_node_server_utils154.BadRequestError("Invalid _id format");
36181
36407
  }
36182
36408
  }
36183
- if (value.org && import_mongodb90.ObjectId.isValid(value.org.toString())) {
36409
+ if (value.org && import_mongodb91.ObjectId.isValid(value.org.toString())) {
36184
36410
  try {
36185
- value.org = new import_mongodb90.ObjectId(value.org.toString());
36411
+ value.org = new import_mongodb91.ObjectId(value.org.toString());
36186
36412
  } catch {
36187
36413
  throw new import_node_server_utils154.BadRequestError("Invalid _id format");
36188
36414
  }
36189
36415
  }
36190
- if (value.paidBy && import_mongodb90.ObjectId.isValid(value.paidBy.toString())) {
36416
+ if (value.paidBy && import_mongodb91.ObjectId.isValid(value.paidBy.toString())) {
36191
36417
  try {
36192
- value.org = new import_mongodb90.ObjectId(value.paidBy.toString());
36418
+ value.org = new import_mongodb91.ObjectId(value.paidBy.toString());
36193
36419
  } catch {
36194
36420
  throw new import_node_server_utils154.BadRequestError("Invalid _id format");
36195
36421
  }
36196
36422
  }
36197
- if (value.billItem && import_mongodb90.ObjectId.isValid(value.billItem.toString())) {
36423
+ if (value.billItem && import_mongodb91.ObjectId.isValid(value.billItem.toString())) {
36198
36424
  try {
36199
- value.billItem = new import_mongodb90.ObjectId(value.billItem.toString());
36425
+ value.billItem = new import_mongodb91.ObjectId(value.billItem.toString());
36200
36426
  } catch {
36201
36427
  throw new import_node_server_utils154.BadRequestError("Invalid _id format");
36202
36428
  }
36203
36429
  }
36204
- if (value.unitId && import_mongodb90.ObjectId.isValid(value.unitId.toString())) {
36430
+ if (value.unitId && import_mongodb91.ObjectId.isValid(value.unitId.toString())) {
36205
36431
  try {
36206
- value.unitId = new import_mongodb90.ObjectId(value.unitId.toString());
36432
+ value.unitId = new import_mongodb91.ObjectId(value.unitId.toString());
36207
36433
  } catch {
36208
36434
  throw new import_node_server_utils154.BadRequestError("Invalid _id format");
36209
36435
  }
@@ -36223,7 +36449,7 @@ function useSiteUnitBillingRepo() {
36223
36449
  }
36224
36450
  async function deleteById(_id) {
36225
36451
  try {
36226
- _id = new import_mongodb90.ObjectId(_id);
36452
+ _id = new import_mongodb91.ObjectId(_id);
36227
36453
  } catch (error) {
36228
36454
  throw new import_node_server_utils154.BadRequestError(
36229
36455
  "Invalid site unit billing transaction ID format."
@@ -36289,9 +36515,9 @@ function useSiteUnitBillingRepo() {
36289
36515
  }
36290
36516
  ]
36291
36517
  },
36292
- ...import_mongodb90.ObjectId.isValid(site) && { site: new import_mongodb90.ObjectId(site) },
36518
+ ...import_mongodb91.ObjectId.isValid(site) && { site: new import_mongodb91.ObjectId(site) },
36293
36519
  ...dateExpr,
36294
- ...import_mongodb90.ObjectId.isValid(unitId) && { unitId: new import_mongodb90.ObjectId(unitId) }
36520
+ ...import_mongodb91.ObjectId.isValid(unitId) && { unitId: new import_mongodb91.ObjectId(unitId) }
36295
36521
  };
36296
36522
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
36297
36523
  try {
@@ -36378,9 +36604,9 @@ function useSiteUnitBillingRepo() {
36378
36604
  }
36379
36605
  ]
36380
36606
  },
36381
- ...import_mongodb90.ObjectId.isValid(site) && { site: new import_mongodb90.ObjectId(site) },
36607
+ ...import_mongodb91.ObjectId.isValid(site) && { site: new import_mongodb91.ObjectId(site) },
36382
36608
  ...dateExpr,
36383
- ...import_mongodb90.ObjectId.isValid(unitId) && { unitId: new import_mongodb90.ObjectId(unitId) }
36609
+ ...import_mongodb91.ObjectId.isValid(unitId) && { unitId: new import_mongodb91.ObjectId(unitId) }
36384
36610
  };
36385
36611
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
36386
36612
  try {
@@ -36463,7 +36689,7 @@ function useSiteUnitBillingRepo() {
36463
36689
 
36464
36690
  // src/services/site-unit-billing.service.ts
36465
36691
  var import_node_server_utils155 = require("@7365admin1/node-server-utils");
36466
- var import_mongodb91 = require("mongodb");
36692
+ var import_mongodb92 = require("mongodb");
36467
36693
  function useSiteUnitBillingService() {
36468
36694
  const {
36469
36695
  add: _add,
@@ -36620,7 +36846,7 @@ function useSiteUnitBillingService() {
36620
36846
  return unitsWithOwner || [];
36621
36847
  } else {
36622
36848
  if (units && units.length > 0) {
36623
- const unitIds = units.map((unit) => new import_mongodb91.ObjectId(unit._id));
36849
+ const unitIds = units.map((unit) => new import_mongodb92.ObjectId(unit._id));
36624
36850
  const specificUnitsWithOwner = await _getBuildingUnitsWithOwner(
36625
36851
  site || "",
36626
36852
  unitIds
@@ -36901,7 +37127,7 @@ function useSiteUnitBillingController() {
36901
37127
  }
36902
37128
 
36903
37129
  // src/models/access-management.model.ts
36904
- var import_mongodb92 = require("mongodb");
37130
+ var import_mongodb93 = require("mongodb");
36905
37131
  var EAccessCardTypes = /* @__PURE__ */ ((EAccessCardTypes2) => {
36906
37132
  EAccessCardTypes2["NFC"] = "NFC";
36907
37133
  EAccessCardTypes2["QR"] = "QRCODE";
@@ -36923,7 +37149,7 @@ var AccessTypeProps = /* @__PURE__ */ ((AccessTypeProps2) => {
36923
37149
  })(AccessTypeProps || {});
36924
37150
  var MAccessCardTransaction = class {
36925
37151
  constructor({
36926
- _id = new import_mongodb92.ObjectId(),
37152
+ _id = new import_mongodb93.ObjectId(),
36927
37153
  index,
36928
37154
  site,
36929
37155
  cardNo,
@@ -36950,7 +37176,7 @@ var MAccessCardTransaction = class {
36950
37176
  };
36951
37177
  var MAccessCard = class {
36952
37178
  constructor({
36953
- _id = new import_mongodb92.ObjectId(),
37179
+ _id = new import_mongodb93.ObjectId(),
36954
37180
  userId,
36955
37181
  site,
36956
37182
  staffNo = null,
@@ -37008,7 +37234,7 @@ var MAccessCard = class {
37008
37234
 
37009
37235
  // src/repositories/access-management.repo.ts
37010
37236
  var import_node_server_utils157 = require("@7365admin1/node-server-utils");
37011
- var import_mongodb93 = require("mongodb");
37237
+ var import_mongodb94 = require("mongodb");
37012
37238
 
37013
37239
  // src/utils/access-management.ts
37014
37240
  var import_fs4 = __toESM(require("fs"));
@@ -37318,12 +37544,12 @@ function UseAccessManagementRepo() {
37318
37544
  payload
37319
37545
  }) {
37320
37546
  try {
37321
- payload.site = new import_mongodb93.ObjectId(payload.site);
37547
+ payload.site = new import_mongodb94.ObjectId(payload.site);
37322
37548
  payload.startDate = new Date(payload.startDate);
37323
37549
  payload.endDate = new Date(payload.endDate);
37324
37550
  payload.createdAt = new Date(payload.createdAt);
37325
37551
  payload.updatedAt = new Date(payload.updatedAt);
37326
- payload.assignedUnit = payload.unit?.map((id) => new import_mongodb93.ObjectId(id));
37552
+ payload.assignedUnit = payload.unit?.map((id) => new import_mongodb94.ObjectId(id));
37327
37553
  delete payload.unit;
37328
37554
  const accessCardObj = new MAccessCard(payload);
37329
37555
  const result = await collection().insertOne(accessCardObj);
@@ -37362,7 +37588,7 @@ function UseAccessManagementRepo() {
37362
37588
  async function addNonPhysicalCardRepo(params) {
37363
37589
  try {
37364
37590
  const MAX_RETRIES = 3;
37365
- const site = new import_mongodb93.ObjectId(params.site);
37591
+ const site = new import_mongodb94.ObjectId(params.site);
37366
37592
  const date = /* @__PURE__ */ new Date();
37367
37593
  const endDate = new Date(date.setFullYear(date.getFullYear() + 10));
37368
37594
  const countPerUnit = params.quantity;
@@ -37394,7 +37620,7 @@ function UseAccessManagementRepo() {
37394
37620
  userType: params.userType,
37395
37621
  doorName: params.doorName,
37396
37622
  liftName: params.liftName,
37397
- assignedUnit: new import_mongodb93.ObjectId(units[i]),
37623
+ assignedUnit: new import_mongodb94.ObjectId(units[i]),
37398
37624
  createdAt: new Date(params.createdAt),
37399
37625
  updatedAt: new Date(params.updatedAt),
37400
37626
  isWinsland: params.isWinsland
@@ -37480,7 +37706,7 @@ function UseAccessManagementRepo() {
37480
37706
  }
37481
37707
  async function accessManagementSettingsRepo(params) {
37482
37708
  try {
37483
- params.site = new import_mongodb93.ObjectId(params.site);
37709
+ params.site = new import_mongodb94.ObjectId(params.site);
37484
37710
  const result = collectionName("entrypass-settings").updateOne(
37485
37711
  { site: params.site },
37486
37712
  {
@@ -37502,7 +37728,7 @@ function UseAccessManagementRepo() {
37502
37728
  }
37503
37729
  async function allAccessCardsCountsRepo(params) {
37504
37730
  try {
37505
- const site = new import_mongodb93.ObjectId(params.site);
37731
+ const site = new import_mongodb94.ObjectId(params.site);
37506
37732
  const userType = params.userType;
37507
37733
  const result = await collection().aggregate([
37508
37734
  {
@@ -37562,7 +37788,7 @@ function UseAccessManagementRepo() {
37562
37788
  }
37563
37789
  async function availableAccessCardsRepo(params) {
37564
37790
  try {
37565
- const site = new import_mongodb93.ObjectId(params.site);
37791
+ const site = new import_mongodb94.ObjectId(params.site);
37566
37792
  const userType = params.userType;
37567
37793
  const type = params.type;
37568
37794
  const query = {
@@ -37677,7 +37903,7 @@ function UseAccessManagementRepo() {
37677
37903
  }
37678
37904
  async function userTypeAccessCardsRepo(params) {
37679
37905
  try {
37680
- const site = new import_mongodb93.ObjectId(params.site);
37906
+ const site = new import_mongodb94.ObjectId(params.site);
37681
37907
  const userType = params.userType;
37682
37908
  const page = params.page ? Number(params.page) - 1 : 0;
37683
37909
  const limit = Number(params.limit) || 10;
@@ -38076,7 +38302,7 @@ function UseAccessManagementRepo() {
38076
38302
  }
38077
38303
  async function assignedAccessCardsRepo(params) {
38078
38304
  try {
38079
- const site = new import_mongodb93.ObjectId(params.site);
38305
+ const site = new import_mongodb94.ObjectId(params.site);
38080
38306
  const userType = params.userType;
38081
38307
  const type = params.type;
38082
38308
  const search = params.search;
@@ -38251,12 +38477,12 @@ function UseAccessManagementRepo() {
38251
38477
  session?.startTransaction();
38252
38478
  const { userId, cardId, site } = params;
38253
38479
  const allUserId = await Promise.all(
38254
- userId.map(async (id) => new import_mongodb93.ObjectId(id))
38480
+ userId.map(async (id) => new import_mongodb94.ObjectId(id))
38255
38481
  );
38256
38482
  const allCardId = await Promise.all(
38257
- cardId.map(async (id) => new import_mongodb93.ObjectId(id))
38483
+ cardId.map(async (id) => new import_mongodb94.ObjectId(id))
38258
38484
  );
38259
- const siteId = new import_mongodb93.ObjectId(site);
38485
+ const siteId = new import_mongodb94.ObjectId(site);
38260
38486
  const result = await collection().updateMany(
38261
38487
  {
38262
38488
  $or: [
@@ -38287,7 +38513,7 @@ function UseAccessManagementRepo() {
38287
38513
  async function accessandLiftCardsRepo(params) {
38288
38514
  try {
38289
38515
  const { accessLevel, liftAccessLevel, site, userType, type } = params;
38290
- const siteId = new import_mongodb93.ObjectId(site);
38516
+ const siteId = new import_mongodb94.ObjectId(site);
38291
38517
  const query = {
38292
38518
  site: { $in: [siteId] },
38293
38519
  userType,
@@ -38320,9 +38546,9 @@ function UseAccessManagementRepo() {
38320
38546
  const session = import_node_server_utils157.useAtlas.getClient()?.startSession();
38321
38547
  try {
38322
38548
  session?.startTransaction();
38323
- const siteId = new import_mongodb93.ObjectId(params.site);
38324
- const userId = new import_mongodb93.ObjectId(params.userId);
38325
- const cardId = new import_mongodb93.ObjectId(params.cardId);
38549
+ const siteId = new import_mongodb94.ObjectId(params.site);
38550
+ const userId = new import_mongodb94.ObjectId(params.userId);
38551
+ const cardId = new import_mongodb94.ObjectId(params.cardId);
38326
38552
  const quantity = 1;
38327
38553
  const cardCredentials = await collection().findOneAndUpdate(
38328
38554
  { _id: cardId },
@@ -38348,7 +38574,7 @@ function UseAccessManagementRepo() {
38348
38574
  (no) => no.toString().padStart(10, "0")
38349
38575
  );
38350
38576
  const accessCards = [];
38351
- const convertedUnits = unit.map((obj) => new import_mongodb93.ObjectId(obj));
38577
+ const convertedUnits = unit.map((obj) => new import_mongodb94.ObjectId(obj));
38352
38578
  for (let j = 0; j < (unit.length > 0 ? unit.length : quantity); j++) {
38353
38579
  accessCards.push(
38354
38580
  new MAccessCard({
@@ -38437,7 +38663,7 @@ function UseAccessManagementRepo() {
38437
38663
  session?.startTransaction();
38438
38664
  const results = [];
38439
38665
  for (let nfc of params.nfcList) {
38440
- nfc._id = new import_mongodb93.ObjectId(nfc._id);
38666
+ nfc._id = new import_mongodb94.ObjectId(nfc._id);
38441
38667
  const card = await collection().findOne({ _id: nfc._id }, { session });
38442
38668
  if (card) {
38443
38669
  const updateFields = {
@@ -38471,7 +38697,7 @@ function UseAccessManagementRepo() {
38471
38697
  async function doorAndLiftDropdownRepo(params) {
38472
38698
  try {
38473
38699
  const { site, type, userType } = params;
38474
- const id = new import_mongodb93.ObjectId(site);
38700
+ const id = new import_mongodb94.ObjectId(site);
38475
38701
  const res = collection().aggregate([
38476
38702
  {
38477
38703
  $match: {
@@ -38558,10 +38784,10 @@ function UseAccessManagementRepo() {
38558
38784
  const session = import_node_server_utils157.useAtlas.getClient()?.startSession();
38559
38785
  try {
38560
38786
  const { cardId, remarks, issuedCardId, unitId, userId } = params;
38561
- const id = new import_mongodb93.ObjectId(cardId);
38562
- const newCardId = new import_mongodb93.ObjectId(issuedCardId);
38563
- const unit = new import_mongodb93.ObjectId(unitId);
38564
- const user = new import_mongodb93.ObjectId(userId);
38787
+ const id = new import_mongodb94.ObjectId(cardId);
38788
+ const newCardId = new import_mongodb94.ObjectId(issuedCardId);
38789
+ const unit = new import_mongodb94.ObjectId(unitId);
38790
+ const user = new import_mongodb94.ObjectId(userId);
38565
38791
  session?.startTransaction();
38566
38792
  const sessionResult = await Promise.all([
38567
38793
  await collection().findOneAndUpdate(
@@ -38594,7 +38820,7 @@ function UseAccessManagementRepo() {
38594
38820
  async function visitorAccessCardsRepo(params) {
38595
38821
  try {
38596
38822
  const page = params.page ? params.page - 1 : 0;
38597
- const siteId = new import_mongodb93.ObjectId(params.site);
38823
+ const siteId = new import_mongodb94.ObjectId(params.site);
38598
38824
  const search = params.search;
38599
38825
  const type = params.type;
38600
38826
  const limit = Number(params.limit);
@@ -38662,7 +38888,7 @@ function UseAccessManagementRepo() {
38662
38888
  }
38663
38889
  async function getCardReplacementRepo(params) {
38664
38890
  try {
38665
- const site = new import_mongodb93.ObjectId(params.site);
38891
+ const site = new import_mongodb94.ObjectId(params.site);
38666
38892
  const search = params.search;
38667
38893
  const statusFilter = params.statusFilter;
38668
38894
  const dateFrom = params.dateFrom;
@@ -38834,7 +39060,7 @@ function UseAccessManagementRepo() {
38834
39060
  async function getAccessManagementSettingsRepo(params) {
38835
39061
  try {
38836
39062
  const { site } = params;
38837
- const siteId = new import_mongodb93.ObjectId(site);
39063
+ const siteId = new import_mongodb94.ObjectId(site);
38838
39064
  const res = await collectionName("entrypass-settings").findOne(
38839
39065
  { site: siteId },
38840
39066
  { allowDiskUse: true }
@@ -38868,7 +39094,7 @@ function UseAccessManagementRepo() {
38868
39094
  const rawAccessGroup = item["accessGroup (value ex. Full Access, No Access)"];
38869
39095
  const accessGroup = typeof rawAccessGroup === "string" ? rawAccessGroup.split(",").map((v) => v.trim()).filter((v) => v !== "") : [];
38870
39096
  return new MAccessCard({
38871
- site: new import_mongodb93.ObjectId(site),
39097
+ site: new import_mongodb94.ObjectId(site),
38872
39098
  type: "NFC" /* NFC */,
38873
39099
  staffNo: null,
38874
39100
  accessLevel,
@@ -38919,8 +39145,8 @@ function UseAccessManagementRepo() {
38919
39145
  liftAccessLevel
38920
39146
  } = params;
38921
39147
  const [convertedUnits, convertedSite] = await Promise.all([
38922
- Promise.all(units.map((id) => new import_mongodb93.ObjectId(id))),
38923
- new import_mongodb93.ObjectId(site)
39148
+ Promise.all(units.map((id) => new import_mongodb94.ObjectId(id))),
39149
+ new import_mongodb94.ObjectId(site)
38924
39150
  ]);
38925
39151
  const totalRequired = quantity * convertedUnits.length;
38926
39152
  const availableCards = await collection().find({
@@ -38972,7 +39198,7 @@ function UseAccessManagementRepo() {
38972
39198
  async function deleteCardRepo(params) {
38973
39199
  try {
38974
39200
  const { cardId, remarks } = params;
38975
- const id = new import_mongodb93.ObjectId(cardId);
39201
+ const id = new import_mongodb94.ObjectId(cardId);
38976
39202
  const result = await collection().findOneAndUpdate(
38977
39203
  { _id: id },
38978
39204
  {
@@ -38993,8 +39219,8 @@ function UseAccessManagementRepo() {
38993
39219
  async function getCardDetailsRepo(params) {
38994
39220
  try {
38995
39221
  const { siteId, cardId } = params;
38996
- const convertedSiteId = new import_mongodb93.ObjectId(siteId);
38997
- const convertedCardId = new import_mongodb93.ObjectId(cardId);
39222
+ const convertedSiteId = new import_mongodb94.ObjectId(siteId);
39223
+ const convertedCardId = new import_mongodb94.ObjectId(cardId);
38998
39224
  const card = await collection().findOne(
38999
39225
  {
39000
39226
  _id: convertedCardId,
@@ -39043,7 +39269,7 @@ function UseAccessManagementRepo() {
39043
39269
  async function addQrTagRepo(params) {
39044
39270
  try {
39045
39271
  const { site, payload } = params;
39046
- const id = new import_mongodb93.ObjectId(site);
39272
+ const id = new import_mongodb94.ObjectId(site);
39047
39273
  const highestCardNo = await collection().aggregate([
39048
39274
  {
39049
39275
  $match: {
@@ -39077,7 +39303,7 @@ function UseAccessManagementRepo() {
39077
39303
  );
39078
39304
  const bulkOps = await Promise.all(
39079
39305
  payload.map(async (doc, index) => {
39080
- const id2 = new import_mongodb93.ObjectId(doc._id);
39306
+ const id2 = new import_mongodb94.ObjectId(doc._id);
39081
39307
  return {
39082
39308
  updateOne: {
39083
39309
  filter: { _id: id2 },
@@ -39100,7 +39326,7 @@ function UseAccessManagementRepo() {
39100
39326
  async function allQrTagRepo(params) {
39101
39327
  try {
39102
39328
  const { site } = params;
39103
- const siteId = new import_mongodb93.ObjectId(site);
39329
+ const siteId = new import_mongodb94.ObjectId(site);
39104
39330
  const query = {
39105
39331
  site: siteId,
39106
39332
  assignedUnit: { $ne: null },
@@ -39149,8 +39375,8 @@ function UseAccessManagementRepo() {
39149
39375
  }
39150
39376
  async function availableCardContractorsRepo(params) {
39151
39377
  try {
39152
- const siteId = new import_mongodb93.ObjectId(params.siteId);
39153
- const unitId = new import_mongodb93.ObjectId(params.unitId);
39378
+ const siteId = new import_mongodb94.ObjectId(params.siteId);
39379
+ const unitId = new import_mongodb94.ObjectId(params.unitId);
39154
39380
  const page = Number(params.page) - 1;
39155
39381
  const limit = Number(params.limit) || 10;
39156
39382
  const type = params.type;
@@ -39251,8 +39477,8 @@ function UseAccessManagementRepo() {
39251
39477
  }
39252
39478
  async function vmsgenerateQrCodesRepo(params) {
39253
39479
  try {
39254
- const site = new import_mongodb93.ObjectId(params.site);
39255
- const unitId = new import_mongodb93.ObjectId(params.unitId);
39480
+ const site = new import_mongodb94.ObjectId(params.site);
39481
+ const unitId = new import_mongodb94.ObjectId(params.unitId);
39256
39482
  const quantity = Number(params.quantity);
39257
39483
  const normalizedUnitId = params.normalizedUnitId;
39258
39484
  const date = /* @__PURE__ */ new Date();
@@ -39307,11 +39533,11 @@ function UseAccessManagementRepo() {
39307
39533
  let isAborted = false;
39308
39534
  try {
39309
39535
  await session?.startTransaction();
39310
- const siteId = new import_mongodb93.ObjectId(params.site);
39311
- const unitId = new import_mongodb93.ObjectId(params.unitId);
39536
+ const siteId = new import_mongodb94.ObjectId(params.site);
39537
+ const unitId = new import_mongodb94.ObjectId(params.unitId);
39312
39538
  const quantity = params.quantity;
39313
39539
  const type = params.type;
39314
- const visitorId = new import_mongodb93.ObjectId(params.visitorId);
39540
+ const visitorId = new import_mongodb94.ObjectId(params.visitorId);
39315
39541
  const nfcCards = params.nfcCards;
39316
39542
  const acm_url = params.acm_url;
39317
39543
  let cards = [];
@@ -39333,7 +39559,7 @@ function UseAccessManagementRepo() {
39333
39559
  } else if (type === "NFC" /* NFC */) {
39334
39560
  if (nfcCards && nfcCards.length > 0) {
39335
39561
  const objectIds = nfcCards.map(
39336
- (card) => new import_mongodb93.ObjectId(card._id)
39562
+ (card) => new import_mongodb94.ObjectId(card._id)
39337
39563
  );
39338
39564
  cards = await collection().find({ _id: { $in: objectIds } }).toArray();
39339
39565
  const nfcList = objectIds.map((card) => ({
@@ -39440,7 +39666,7 @@ function UseAccessManagementRepo() {
39440
39666
  }
39441
39667
  async function signQrCodeRepo(params) {
39442
39668
  try {
39443
- const cardId = new import_mongodb93.ObjectId(params.cardId);
39669
+ const cardId = new import_mongodb94.ObjectId(params.cardId);
39444
39670
  const purpose = params.purpose;
39445
39671
  let validity = 5;
39446
39672
  const card = await collection().findOne({ _id: cardId });
@@ -39465,7 +39691,7 @@ function UseAccessManagementRepo() {
39465
39691
  const session = import_node_server_utils157.useAtlas.getClient()?.startSession();
39466
39692
  try {
39467
39693
  await session?.startTransaction();
39468
- const userId = new import_mongodb93.ObjectId(params.userId);
39694
+ const userId = new import_mongodb94.ObjectId(params.userId);
39469
39695
  const result = await collection().updateMany(
39470
39696
  { userId },
39471
39697
  { $set: { userId: null, status: "Available", updatedAt: /* @__PURE__ */ new Date() } }
@@ -39480,7 +39706,7 @@ function UseAccessManagementRepo() {
39480
39706
  }
39481
39707
  }
39482
39708
  async function getBlockLevelAndUnitListRepo(params) {
39483
- const site = new import_mongodb93.ObjectId(params.site);
39709
+ const site = new import_mongodb94.ObjectId(params.site);
39484
39710
  try {
39485
39711
  const blocks = await collectionName("buildings").aggregate([
39486
39712
  {
@@ -39550,7 +39776,7 @@ function UseAccessManagementRepo() {
39550
39776
  url
39551
39777
  }) {
39552
39778
  page = page ? page - 1 : 0;
39553
- site = new import_mongodb93.ObjectId(site);
39779
+ site = new import_mongodb94.ObjectId(site);
39554
39780
  try {
39555
39781
  let index = await collectionName("access-card-transactions").findOne(
39556
39782
  {},
@@ -39685,9 +39911,9 @@ function UseAccessManagementRepo() {
39685
39911
  throw new Error("No user to Assign.");
39686
39912
  }
39687
39913
  assignees = assignees.map(
39688
- (data) => new import_mongodb93.ObjectId(data)
39914
+ (data) => new import_mongodb94.ObjectId(data)
39689
39915
  );
39690
- unit = new import_mongodb93.ObjectId(unit);
39916
+ unit = new import_mongodb94.ObjectId(unit);
39691
39917
  let availableCards = [];
39692
39918
  let update = [];
39693
39919
  let cards = [];
@@ -39720,13 +39946,13 @@ function UseAccessManagementRepo() {
39720
39946
  throw new Error(`Not enough ${type} cards available.`);
39721
39947
  }
39722
39948
  cards = availableCards?.slice(0, assignees.length).map((card, index) => {
39723
- const userId = new import_mongodb93.ObjectId(assignees[index].toString());
39949
+ const userId = new import_mongodb94.ObjectId(assignees[index].toString());
39724
39950
  card.staffNo = userId.toString().slice(-10);
39725
39951
  return card;
39726
39952
  });
39727
39953
  update = availableCards.slice(0, assignees.length).map((card, index) => ({
39728
39954
  _id: card._id,
39729
- userId: new import_mongodb93.ObjectId(assignees[index])
39955
+ userId: new import_mongodb94.ObjectId(assignees[index])
39730
39956
  }));
39731
39957
  const commands = cards.map((item, index) => {
39732
39958
  let ag = null;
@@ -39792,7 +40018,7 @@ function UseAccessManagementRepo() {
39792
40018
  const session = import_node_server_utils157.useAtlas.getClient()?.startSession();
39793
40019
  try {
39794
40020
  session?.startTransaction();
39795
- const id = new import_mongodb93.ObjectId(userId);
40021
+ const id = new import_mongodb94.ObjectId(userId);
39796
40022
  await collection().updateMany(
39797
40023
  { userId: id },
39798
40024
  { $set: { userId: null, status: "Available" } },
@@ -39812,8 +40038,8 @@ function UseAccessManagementRepo() {
39812
40038
  id,
39813
40039
  name
39814
40040
  }) {
39815
- site = new import_mongodb93.ObjectId(site);
39816
- id = new import_mongodb93.ObjectId(id);
40041
+ site = new import_mongodb94.ObjectId(site);
40042
+ id = new import_mongodb94.ObjectId(id);
39817
40043
  try {
39818
40044
  const result = await collectionName("sites").updateOne(
39819
40045
  { _id: site },
@@ -39830,9 +40056,9 @@ function UseAccessManagementRepo() {
39830
40056
  unitId
39831
40057
  }) {
39832
40058
  try {
39833
- orgId = new import_mongodb93.ObjectId(orgId);
39834
- siteId = new import_mongodb93.ObjectId(siteId);
39835
- unitId = new import_mongodb93.ObjectId(unitId);
40059
+ orgId = new import_mongodb94.ObjectId(orgId);
40060
+ siteId = new import_mongodb94.ObjectId(siteId);
40061
+ unitId = new import_mongodb94.ObjectId(unitId);
39836
40062
  const result = await collectionName("users").aggregate([
39837
40063
  {
39838
40064
  $match: {
@@ -39867,17 +40093,23 @@ function UseAccessManagementRepo() {
39867
40093
  async function userAccessCardsRepo({
39868
40094
  userId,
39869
40095
  siteId,
39870
- isLiftCard
40096
+ isLiftCard,
40097
+ search
39871
40098
  }) {
39872
40099
  try {
39873
- siteId = new import_mongodb93.ObjectId(siteId);
39874
- userId = new import_mongodb93.ObjectId(userId);
40100
+ siteId = new import_mongodb94.ObjectId(siteId);
40101
+ userId = new import_mongodb94.ObjectId(userId);
39875
40102
  const query = {
39876
40103
  site: siteId,
39877
40104
  userId,
39878
40105
  isLiftCard,
39879
40106
  userType: "Visitor/Resident" /* DEFAULT */
39880
40107
  };
40108
+ if (search !== "") {
40109
+ query.$or = [
40110
+ { cardNo: { $regex: search, $options: "i" } }
40111
+ ];
40112
+ }
39881
40113
  console.log(query);
39882
40114
  const res = await collection().aggregate([
39883
40115
  {
@@ -39892,7 +40124,7 @@ function UseAccessManagementRepo() {
39892
40124
  }
39893
40125
  }
39894
40126
  async function removeTemplateRepo({ site }) {
39895
- site = new import_mongodb93.ObjectId(site);
40127
+ site = new import_mongodb94.ObjectId(site);
39896
40128
  try {
39897
40129
  const result = await collectionName("entrypass-settings").updateOne({ _id: site }, { $set: { "settings.template": {} } });
39898
40130
  return result;
@@ -39905,8 +40137,8 @@ function UseAccessManagementRepo() {
39905
40137
  page = page ? page - 1 : 0;
39906
40138
  let defaultQuery = {};
39907
40139
  let searchQuery = {};
39908
- site = new import_mongodb93.ObjectId(site);
39909
- userId = new import_mongodb93.ObjectId(userId);
40140
+ site = new import_mongodb94.ObjectId(site);
40141
+ userId = new import_mongodb94.ObjectId(userId);
39910
40142
  if (search) {
39911
40143
  searchQuery = {
39912
40144
  $or: [{ fullName: { $regex: search, $options: "i" } }, { cardNo: { $regex: search, $options: "i" } }]
@@ -40378,13 +40610,15 @@ function useAccessManagementSvc() {
40378
40610
  const userAccessCardsSvc = async ({
40379
40611
  userId,
40380
40612
  siteId,
40381
- isLiftCard
40613
+ isLiftCard,
40614
+ search
40382
40615
  }) => {
40383
40616
  try {
40384
40617
  const response = await userAccessCardsRepo({
40385
40618
  userId,
40386
40619
  siteId,
40387
- isLiftCard
40620
+ isLiftCard,
40621
+ search
40388
40622
  });
40389
40623
  return response;
40390
40624
  } catch (err) {
@@ -41523,13 +41757,14 @@ function useAccessManagementController() {
41523
41757
  };
41524
41758
  const userAccessCards = async (req, res) => {
41525
41759
  try {
41526
- const { userId, siteId, isLiftCard } = req.query;
41760
+ const { userId, siteId, isLiftCard, search = "" } = req.query;
41527
41761
  const schema2 = import_joi87.default.object({
41528
41762
  isLiftCard: import_joi87.default.string().valid("true", "false").required(),
41529
41763
  siteId: import_joi87.default.string().hex().required(),
41530
- userId: import_joi87.default.string().hex().required()
41764
+ userId: import_joi87.default.string().hex().required(),
41765
+ search: import_joi87.default.string().optional().allow(null, "")
41531
41766
  });
41532
- const { error } = schema2.validate({ userId, siteId, isLiftCard });
41767
+ const { error } = schema2.validate({ userId, siteId, isLiftCard, search });
41533
41768
  if (error) {
41534
41769
  return res.status(400).json({ message: error.message });
41535
41770
  }
@@ -41537,7 +41772,8 @@ function useAccessManagementController() {
41537
41772
  const result = await userAccessCardsSvc({
41538
41773
  userId,
41539
41774
  siteId,
41540
- isLiftCard: isLiftCardBool
41775
+ isLiftCard: isLiftCardBool,
41776
+ search
41541
41777
  });
41542
41778
  return res.status(200).json({ data: result });
41543
41779
  } catch (error) {
@@ -41652,7 +41888,7 @@ function useAccessManagementController() {
41652
41888
  }
41653
41889
 
41654
41890
  // src/models/nfc-patrol-tag.model.ts
41655
- var import_mongodb94 = require("mongodb");
41891
+ var import_mongodb95 = require("mongodb");
41656
41892
  var import_joi88 = __toESM(require("joi"));
41657
41893
  var import_node_server_utils158 = require("@7365admin1/node-server-utils");
41658
41894
  var DEVICE_STATUS = {
@@ -41679,27 +41915,27 @@ var schemaNfcPatrolTag = import_joi88.default.object({
41679
41915
  function MNfcPatrolTag(value) {
41680
41916
  if (value._id && typeof value._id === "string") {
41681
41917
  try {
41682
- value._id = new import_mongodb94.ObjectId(value._id);
41918
+ value._id = new import_mongodb95.ObjectId(value._id);
41683
41919
  } catch {
41684
41920
  throw new import_node_server_utils158.BadRequestError("Invalid ID.");
41685
41921
  }
41686
41922
  }
41687
41923
  if (value.site && typeof value.site === "string") {
41688
41924
  try {
41689
- value.site = new import_mongodb94.ObjectId(value.site);
41925
+ value.site = new import_mongodb95.ObjectId(value.site);
41690
41926
  } catch {
41691
41927
  throw new import_node_server_utils158.BadRequestError("Invalid site ID.");
41692
41928
  }
41693
41929
  }
41694
41930
  if (value.createdBy && typeof value.createdBy === "string") {
41695
41931
  try {
41696
- value.createdBy = new import_mongodb94.ObjectId(value.createdBy);
41932
+ value.createdBy = new import_mongodb95.ObjectId(value.createdBy);
41697
41933
  } catch {
41698
41934
  throw new import_node_server_utils158.BadRequestError("Invalid Created By ID.");
41699
41935
  }
41700
41936
  }
41701
41937
  return {
41702
- _id: value._id ?? new import_mongodb94.ObjectId(),
41938
+ _id: value._id ?? new import_mongodb95.ObjectId(),
41703
41939
  site: value.site,
41704
41940
  tagID: value.tagID,
41705
41941
  name: value.name,
@@ -41711,7 +41947,7 @@ function MNfcPatrolTag(value) {
41711
41947
 
41712
41948
  // src/repositories/nfc-patrol-tag.repository.ts
41713
41949
  var import_node_server_utils159 = require("@7365admin1/node-server-utils");
41714
- var import_mongodb95 = require("mongodb");
41950
+ var import_mongodb96 = require("mongodb");
41715
41951
  function useNfcPatrolTagRepo() {
41716
41952
  const db = import_node_server_utils159.useAtlas.getDb();
41717
41953
  if (!db) {
@@ -41765,7 +42001,7 @@ function useNfcPatrolTagRepo() {
41765
42001
  }, session) {
41766
42002
  page = page > 0 ? page - 1 : 0;
41767
42003
  try {
41768
- site = new import_mongodb95.ObjectId(site);
42004
+ site = new import_mongodb96.ObjectId(site);
41769
42005
  } catch (error) {
41770
42006
  throw new import_node_server_utils159.BadRequestError("Invalid site ID format.");
41771
42007
  }
@@ -41809,19 +42045,19 @@ function useNfcPatrolTagRepo() {
41809
42045
  const [updateType, findObject, setData, session] = args;
41810
42046
  if (findObject?.site && typeof findObject.site === "string") {
41811
42047
  try {
41812
- findObject.site = new import_mongodb95.ObjectId(findObject.site);
42048
+ findObject.site = new import_mongodb96.ObjectId(findObject.site);
41813
42049
  } catch {
41814
42050
  throw new import_node_server_utils159.BadRequestError("Invalid site ID.");
41815
42051
  }
41816
42052
  }
41817
42053
  if (updateType == "Edit" && findObject?._id && typeof findObject._id === "string") {
41818
42054
  try {
41819
- findObject._id = new import_mongodb95.ObjectId(findObject._id);
42055
+ findObject._id = new import_mongodb96.ObjectId(findObject._id);
41820
42056
  } catch {
41821
42057
  throw new import_node_server_utils159.BadRequestError("Invalid nfc patrol tag document ID.");
41822
42058
  }
41823
42059
  try {
41824
- setData.updatedBy = new import_mongodb95.ObjectId(setData.updatedBy);
42060
+ setData.updatedBy = new import_mongodb96.ObjectId(setData.updatedBy);
41825
42061
  } catch {
41826
42062
  throw new import_node_server_utils159.BadRequestError("Invalid updatedBy ID.");
41827
42063
  }
@@ -42112,7 +42348,7 @@ function useNfcPatrolTagController() {
42112
42348
  }
42113
42349
 
42114
42350
  // src/models/occurrence-book.model.ts
42115
- var import_mongodb96 = require("mongodb");
42351
+ var import_mongodb97 = require("mongodb");
42116
42352
  var import_joi90 = __toESM(require("joi"));
42117
42353
  var DOBStatus = /* @__PURE__ */ ((DOBStatus3) => {
42118
42354
  DOBStatus3["OPEN"] = "open";
@@ -42138,20 +42374,20 @@ var schemaUpdateOccurrenceBook = import_joi90.default.object({
42138
42374
  function MOccurrenceBook(value) {
42139
42375
  if (value._id && typeof value._id === "string") {
42140
42376
  try {
42141
- value._id = new import_mongodb96.ObjectId(value._id);
42377
+ value._id = new import_mongodb97.ObjectId(value._id);
42142
42378
  } catch {
42143
42379
  throw new Error("Invalid ID.");
42144
42380
  }
42145
42381
  }
42146
42382
  if (value.site && typeof value.site === "string") {
42147
42383
  try {
42148
- value.site = new import_mongodb96.ObjectId(value.site);
42384
+ value.site = new import_mongodb97.ObjectId(value.site);
42149
42385
  } catch {
42150
42386
  throw new Error("Invalid site ID.");
42151
42387
  }
42152
42388
  }
42153
42389
  return {
42154
- _id: value._id ?? new import_mongodb96.ObjectId(),
42390
+ _id: value._id ?? new import_mongodb97.ObjectId(),
42155
42391
  site: value.site,
42156
42392
  date: value.date ?? "",
42157
42393
  totalInput: value.totalInput ?? 0,
@@ -42166,7 +42402,7 @@ function MOccurrenceBook(value) {
42166
42402
 
42167
42403
  // src/repositories/occurrence-book.repo.ts
42168
42404
  var import_node_server_utils162 = require("@7365admin1/node-server-utils");
42169
- var import_mongodb97 = require("mongodb");
42405
+ var import_mongodb98 = require("mongodb");
42170
42406
  var occurrence_book_namespace_collection = "occurrence-books";
42171
42407
  function useOccurrenceBookRepo() {
42172
42408
  const db = import_node_server_utils162.useAtlas.getDb();
@@ -42310,7 +42546,7 @@ function useOccurrenceBookRepo() {
42310
42546
  }
42311
42547
  async function getOccurrenceBookById(_id, session) {
42312
42548
  try {
42313
- _id = new import_mongodb97.ObjectId(_id);
42549
+ _id = new import_mongodb98.ObjectId(_id);
42314
42550
  } catch (error) {
42315
42551
  throw new import_node_server_utils162.BadRequestError("Invalid occurrence book ID format.");
42316
42552
  }
@@ -42340,7 +42576,7 @@ function useOccurrenceBookRepo() {
42340
42576
  async function updateOccurrenceBookById(_id, value, session) {
42341
42577
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
42342
42578
  try {
42343
- _id = new import_mongodb97.ObjectId(_id);
42579
+ _id = new import_mongodb98.ObjectId(_id);
42344
42580
  } catch (error) {
42345
42581
  throw new import_node_server_utils162.BadRequestError("Invalid ID format.");
42346
42582
  }
@@ -42372,7 +42608,7 @@ function useOccurrenceBookRepo() {
42372
42608
  }
42373
42609
  async function deleteOccurrenceBookById(_id) {
42374
42610
  try {
42375
- _id = new import_mongodb97.ObjectId(_id);
42611
+ _id = new import_mongodb98.ObjectId(_id);
42376
42612
  } catch (error) {
42377
42613
  throw new import_node_server_utils162.BadRequestError("Invalid occurrence book ID format.");
42378
42614
  }
@@ -42757,7 +42993,7 @@ function useOccurrenceBookController() {
42757
42993
  }
42758
42994
 
42759
42995
  // src/models/bulletin-video.model.ts
42760
- var import_mongodb98 = require("mongodb");
42996
+ var import_mongodb99 = require("mongodb");
42761
42997
  var import_joi92 = __toESM(require("joi"));
42762
42998
  var BulletinVideoSort = /* @__PURE__ */ ((BulletinVideoSort2) => {
42763
42999
  BulletinVideoSort2["CREATED_AT"] = "createdAt";
@@ -42785,27 +43021,27 @@ var schemaUpdateBulletinVideo = import_joi92.default.object({
42785
43021
  function MBulletinVideo(value) {
42786
43022
  if (value._id && typeof value._id === "string") {
42787
43023
  try {
42788
- value._id = new import_mongodb98.ObjectId(value._id);
43024
+ value._id = new import_mongodb99.ObjectId(value._id);
42789
43025
  } catch {
42790
43026
  throw new Error("Invalid ID.");
42791
43027
  }
42792
43028
  }
42793
43029
  if (value.site && typeof value.site === "string") {
42794
43030
  try {
42795
- value.site = new import_mongodb98.ObjectId(value.site);
43031
+ value.site = new import_mongodb99.ObjectId(value.site);
42796
43032
  } catch {
42797
43033
  throw new Error("Invalid site ID.");
42798
43034
  }
42799
43035
  }
42800
43036
  if (value.file && typeof value.file === "string") {
42801
43037
  try {
42802
- value.file = new import_mongodb98.ObjectId(value.file);
43038
+ value.file = new import_mongodb99.ObjectId(value.file);
42803
43039
  } catch {
42804
43040
  throw new Error("Invalid file ID.");
42805
43041
  }
42806
43042
  }
42807
43043
  return {
42808
- _id: value._id ?? new import_mongodb98.ObjectId(),
43044
+ _id: value._id ?? new import_mongodb99.ObjectId(),
42809
43045
  site: value.site,
42810
43046
  title: value.title ?? "",
42811
43047
  description: value.description ?? "",
@@ -42818,7 +43054,7 @@ function MBulletinVideo(value) {
42818
43054
 
42819
43055
  // src/repositories/bulletin-video.repo.ts
42820
43056
  var import_node_server_utils165 = require("@7365admin1/node-server-utils");
42821
- var import_mongodb99 = require("mongodb");
43057
+ var import_mongodb100 = require("mongodb");
42822
43058
  function useBulletinVideoRepo() {
42823
43059
  const db = import_node_server_utils165.useAtlas.getDb();
42824
43060
  if (!db) {
@@ -42880,7 +43116,7 @@ function useBulletinVideoRepo() {
42880
43116
  }, session) {
42881
43117
  page = page > 0 ? page - 1 : 0;
42882
43118
  try {
42883
- site = new import_mongodb99.ObjectId(site);
43119
+ site = new import_mongodb100.ObjectId(site);
42884
43120
  } catch (error) {
42885
43121
  throw new import_node_server_utils165.BadRequestError("Invalid site ID format.");
42886
43122
  }
@@ -42960,7 +43196,7 @@ function useBulletinVideoRepo() {
42960
43196
  }
42961
43197
  async function getBulletinVideoById(_id, session) {
42962
43198
  try {
42963
- _id = new import_mongodb99.ObjectId(_id);
43199
+ _id = new import_mongodb100.ObjectId(_id);
42964
43200
  } catch (error) {
42965
43201
  throw new import_node_server_utils165.BadRequestError("Invalid bulletin video ID format.");
42966
43202
  }
@@ -42991,13 +43227,13 @@ function useBulletinVideoRepo() {
42991
43227
  async function updateBulletinVideoById(_id, value, session) {
42992
43228
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
42993
43229
  try {
42994
- _id = new import_mongodb99.ObjectId(_id);
43230
+ _id = new import_mongodb100.ObjectId(_id);
42995
43231
  } catch (error) {
42996
43232
  throw new import_node_server_utils165.BadRequestError("Invalid ID format.");
42997
43233
  }
42998
43234
  if (value.file && typeof value.file === "string") {
42999
43235
  try {
43000
- value.file = new import_mongodb99.ObjectId(value.file);
43236
+ value.file = new import_mongodb100.ObjectId(value.file);
43001
43237
  } catch {
43002
43238
  throw new Error("Invalid file ID.");
43003
43239
  }
@@ -43026,7 +43262,7 @@ function useBulletinVideoRepo() {
43026
43262
  }
43027
43263
  async function deleteBulletinVideoById(_id, session) {
43028
43264
  try {
43029
- _id = new import_mongodb99.ObjectId(_id);
43265
+ _id = new import_mongodb100.ObjectId(_id);
43030
43266
  } catch (error) {
43031
43267
  throw new import_node_server_utils165.BadRequestError("Invalid bulletin video ID format.");
43032
43268
  }
@@ -43290,7 +43526,7 @@ function useBulletinVideoController() {
43290
43526
 
43291
43527
  // src/models/site-soa.model.ts
43292
43528
  var import_node_server_utils168 = require("@7365admin1/node-server-utils");
43293
- var import_mongodb100 = require("mongodb");
43529
+ var import_mongodb101 = require("mongodb");
43294
43530
  var import_joi94 = __toESM(require("joi"));
43295
43531
  var schemaSOABillingItem = import_joi94.default.object({
43296
43532
  _id: import_joi94.default.string().required(),
@@ -43358,28 +43594,28 @@ function MStatementOfAccount(value) {
43358
43594
  }
43359
43595
  if (value._id && typeof value._id === "string") {
43360
43596
  try {
43361
- value._id = new import_mongodb100.ObjectId(value._id);
43597
+ value._id = new import_mongodb101.ObjectId(value._id);
43362
43598
  } catch {
43363
43599
  throw new import_node_server_utils168.BadRequestError("Invalid _id format");
43364
43600
  }
43365
43601
  }
43366
43602
  if (value.site && typeof value.site === "string") {
43367
43603
  try {
43368
- value.site = new import_mongodb100.ObjectId(value.site);
43604
+ value.site = new import_mongodb101.ObjectId(value.site);
43369
43605
  } catch {
43370
43606
  throw new import_node_server_utils168.BadRequestError("Invalid site format");
43371
43607
  }
43372
43608
  }
43373
43609
  if (value.createdBy && typeof value.createdBy === "string") {
43374
43610
  try {
43375
- value.createdBy = new import_mongodb100.ObjectId(value.createdBy);
43611
+ value.createdBy = new import_mongodb101.ObjectId(value.createdBy);
43376
43612
  } catch {
43377
43613
  throw new import_node_server_utils168.BadRequestError("Invalid createBy format");
43378
43614
  }
43379
43615
  }
43380
43616
  if (value.unitId && typeof value.unitId === "string") {
43381
43617
  try {
43382
- value.unitId = new import_mongodb100.ObjectId(value.unitId);
43618
+ value.unitId = new import_mongodb101.ObjectId(value.unitId);
43383
43619
  } catch {
43384
43620
  throw new import_node_server_utils168.BadRequestError("Invalid unitId format");
43385
43621
  }
@@ -43388,7 +43624,7 @@ function MStatementOfAccount(value) {
43388
43624
  value.billing = value.billing.map((bill) => {
43389
43625
  if (bill._id && typeof bill._id === "string") {
43390
43626
  try {
43391
- bill._id = new import_mongodb100.ObjectId(bill._id);
43627
+ bill._id = new import_mongodb101.ObjectId(bill._id);
43392
43628
  } catch {
43393
43629
  throw new import_node_server_utils168.BadRequestError("Invalid billing id format");
43394
43630
  }
@@ -43397,7 +43633,7 @@ function MStatementOfAccount(value) {
43397
43633
  });
43398
43634
  }
43399
43635
  return {
43400
- _id: value._id ?? new import_mongodb100.ObjectId(),
43636
+ _id: value._id ?? new import_mongodb101.ObjectId(),
43401
43637
  site: value.site,
43402
43638
  unitId: value.unitId ?? "",
43403
43639
  unit: value.unit ?? "",
@@ -43420,7 +43656,7 @@ function MStatementOfAccount(value) {
43420
43656
 
43421
43657
  // src/repositories/site-soa.repo.ts
43422
43658
  var import_node_server_utils169 = require("@7365admin1/node-server-utils");
43423
- var import_mongodb101 = require("mongodb");
43659
+ var import_mongodb102 = require("mongodb");
43424
43660
  function useStatementOfAccountRepo() {
43425
43661
  const db = import_node_server_utils169.useAtlas.getDb();
43426
43662
  if (!db) {
@@ -43518,7 +43754,7 @@ function useStatementOfAccountRepo() {
43518
43754
  { category: { $regex: search, $options: "i" } }
43519
43755
  ]
43520
43756
  },
43521
- ...import_mongodb101.ObjectId.isValid(site) && { site: new import_mongodb101.ObjectId(site) },
43757
+ ...import_mongodb102.ObjectId.isValid(site) && { site: new import_mongodb102.ObjectId(site) },
43522
43758
  ...dateExpr
43523
43759
  };
43524
43760
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
@@ -43573,7 +43809,7 @@ function useStatementOfAccountRepo() {
43573
43809
  }
43574
43810
  async function getById(_id) {
43575
43811
  try {
43576
- _id = new import_mongodb101.ObjectId(_id);
43812
+ _id = new import_mongodb102.ObjectId(_id);
43577
43813
  } catch (error) {
43578
43814
  throw new import_node_server_utils169.BadRequestError("Invalid ID.");
43579
43815
  }
@@ -43612,7 +43848,7 @@ function useStatementOfAccountRepo() {
43612
43848
  }
43613
43849
  async function updateById(_id, value, session) {
43614
43850
  try {
43615
- _id = new import_mongodb101.ObjectId(_id);
43851
+ _id = new import_mongodb102.ObjectId(_id);
43616
43852
  } catch (error) {
43617
43853
  throw new import_node_server_utils169.BadRequestError("Invalid site SOA transaction ID format.");
43618
43854
  }
@@ -43631,7 +43867,7 @@ function useStatementOfAccountRepo() {
43631
43867
  }
43632
43868
  async function deleteById(_id) {
43633
43869
  try {
43634
- _id = new import_mongodb101.ObjectId(_id);
43870
+ _id = new import_mongodb102.ObjectId(_id);
43635
43871
  } catch (error) {
43636
43872
  throw new import_node_server_utils169.BadRequestError("Invalid site SOA transaction ID format.");
43637
43873
  }
@@ -43653,7 +43889,7 @@ function useStatementOfAccountRepo() {
43653
43889
  }
43654
43890
  async function updateStatusById(_id, value, session) {
43655
43891
  try {
43656
- _id = new import_mongodb101.ObjectId(_id);
43892
+ _id = new import_mongodb102.ObjectId(_id);
43657
43893
  } catch (error) {
43658
43894
  throw new import_node_server_utils169.BadRequestError("Invalid file ID format.");
43659
43895
  }
@@ -43708,9 +43944,9 @@ function useStatementOfAccountRepo() {
43708
43944
  { category: { $regex: search, $options: "i" } }
43709
43945
  ]
43710
43946
  },
43711
- ...import_mongodb101.ObjectId.isValid(site) && { site: new import_mongodb101.ObjectId(site) },
43947
+ ...import_mongodb102.ObjectId.isValid(site) && { site: new import_mongodb102.ObjectId(site) },
43712
43948
  ...dateExpr,
43713
- ...import_mongodb101.ObjectId.isValid(unitId) && { unitId: new import_mongodb101.ObjectId(unitId) },
43949
+ ...import_mongodb102.ObjectId.isValid(unitId) && { unitId: new import_mongodb102.ObjectId(unitId) },
43714
43950
  ...category && { category }
43715
43951
  };
43716
43952
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
@@ -43760,7 +43996,7 @@ function useStatementOfAccountRepo() {
43760
43996
  async function reviewSOA(_id, value, session) {
43761
43997
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
43762
43998
  try {
43763
- _id = new import_mongodb101.ObjectId(_id);
43999
+ _id = new import_mongodb102.ObjectId(_id);
43764
44000
  } catch (error) {
43765
44001
  throw new import_node_server_utils169.BadRequestError("Invalid ID format.");
43766
44002
  }
@@ -43805,7 +44041,7 @@ var import_node_server_utils171 = require("@7365admin1/node-server-utils");
43805
44041
 
43806
44042
  // src/services/site-soa.service.ts
43807
44043
  var import_node_server_utils170 = require("@7365admin1/node-server-utils");
43808
- var import_mongodb102 = require("mongodb");
44044
+ var import_mongodb103 = require("mongodb");
43809
44045
  var import_puppeteer = require("puppeteer");
43810
44046
  function useStatementOfAccountService() {
43811
44047
  const { add: _add, reviewSOA: _reviewSOA } = useStatementOfAccountRepo();
@@ -43942,7 +44178,7 @@ function useStatementOfAccountService() {
43942
44178
  if (!approvedBy || !approvedBy.name)
43943
44179
  throw new import_node_server_utils170.BadRequestError("Created by not found.");
43944
44180
  value.approvedBy.name = approvedBy.name;
43945
- value.approvedBy._id = new import_mongodb102.ObjectId(approvedBy._id);
44181
+ value.approvedBy._id = new import_mongodb103.ObjectId(approvedBy._id);
43946
44182
  }
43947
44183
  await _reviewSOA(id, value, session);
43948
44184
  await session?.commitTransaction();
@@ -44324,7 +44560,7 @@ function useStatementOfAccountController() {
44324
44560
 
44325
44561
  // src/models/site-entrypass-settings.model.ts
44326
44562
  var import_node_server_utils172 = require("@7365admin1/node-server-utils");
44327
- var import_mongodb103 = require("mongodb");
44563
+ var import_mongodb104 = require("mongodb");
44328
44564
  var import_joi96 = __toESM(require("joi"));
44329
44565
  var schemaEntryPassSettings = import_joi96.default.object({
44330
44566
  _id: import_joi96.default.string().hex().optional().allow("", null),
@@ -44372,21 +44608,21 @@ function MEntryPassSettings(value) {
44372
44608
  }
44373
44609
  if (value._id && typeof value._id === "string") {
44374
44610
  try {
44375
- value._id = new import_mongodb103.ObjectId(value._id);
44611
+ value._id = new import_mongodb104.ObjectId(value._id);
44376
44612
  } catch {
44377
44613
  throw new import_node_server_utils172.BadRequestError("Invalid _id format");
44378
44614
  }
44379
44615
  }
44380
44616
  if (value.site && typeof value.site === "string") {
44381
44617
  try {
44382
- value.site = new import_mongodb103.ObjectId(value.site);
44618
+ value.site = new import_mongodb104.ObjectId(value.site);
44383
44619
  } catch {
44384
44620
  throw new import_node_server_utils172.BadRequestError("Invalid site format");
44385
44621
  }
44386
44622
  }
44387
44623
  if (value.org && typeof value.org === "string") {
44388
44624
  try {
44389
- value.org = new import_mongodb103.ObjectId(value.org);
44625
+ value.org = new import_mongodb104.ObjectId(value.org);
44390
44626
  } catch {
44391
44627
  throw new import_node_server_utils172.BadRequestError("Invalid org format");
44392
44628
  }
@@ -44416,7 +44652,7 @@ function MEntryPassSettings(value) {
44416
44652
 
44417
44653
  // src/repositories/site-entrypass-settings.repo.ts
44418
44654
  var import_node_server_utils173 = require("@7365admin1/node-server-utils");
44419
- var import_mongodb104 = require("mongodb");
44655
+ var import_mongodb105 = require("mongodb");
44420
44656
  function useEntryPassSettingsRepo() {
44421
44657
  const db = import_node_server_utils173.useAtlas.getDb();
44422
44658
  if (!db) {
@@ -44526,7 +44762,7 @@ function useEntryPassSettingsRepo() {
44526
44762
  }
44527
44763
  async function getEntryPassSettingsById(_id) {
44528
44764
  try {
44529
- _id = new import_mongodb104.ObjectId(_id);
44765
+ _id = new import_mongodb105.ObjectId(_id);
44530
44766
  } catch (error) {
44531
44767
  throw new import_node_server_utils173.BadRequestError("Invalid entry pass settings ID format.");
44532
44768
  }
@@ -44593,7 +44829,7 @@ function useEntryPassSettingsRepo() {
44593
44829
  }
44594
44830
  async function updateEntryPassSettingsById(_id, value) {
44595
44831
  try {
44596
- _id = new import_mongodb104.ObjectId(_id);
44832
+ _id = new import_mongodb105.ObjectId(_id);
44597
44833
  } catch (error) {
44598
44834
  throw new import_node_server_utils173.BadRequestError("Invalid entry pass settings ID format.");
44599
44835
  }
@@ -44621,7 +44857,7 @@ function useEntryPassSettingsRepo() {
44621
44857
  }
44622
44858
  async function deleteEntryPassSettingsById(_id, session) {
44623
44859
  try {
44624
- _id = new import_mongodb104.ObjectId(_id);
44860
+ _id = new import_mongodb105.ObjectId(_id);
44625
44861
  } catch (error) {
44626
44862
  throw new import_node_server_utils173.BadRequestError("Invalid card ID format.");
44627
44863
  }
@@ -44654,7 +44890,7 @@ function useEntryPassSettingsRepo() {
44654
44890
  }
44655
44891
  async function getEntryPassSettingsBySiteId(site) {
44656
44892
  try {
44657
- site = new import_mongodb104.ObjectId(site);
44893
+ site = new import_mongodb105.ObjectId(site);
44658
44894
  } catch (error) {
44659
44895
  throw new import_node_server_utils173.BadRequestError("Invalid entry pass settings ID format.");
44660
44896
  }
@@ -44721,7 +44957,7 @@ function useEntryPassSettingsRepo() {
44721
44957
  }
44722
44958
  async function updateEntryPassSettingsBySiteId(site, value) {
44723
44959
  try {
44724
- site = new import_mongodb104.ObjectId(site);
44960
+ site = new import_mongodb105.ObjectId(site);
44725
44961
  } catch (error) {
44726
44962
  throw new import_node_server_utils173.BadRequestError("Invalid entry pass settings ID format.");
44727
44963
  }
@@ -45080,7 +45316,7 @@ function useDashboardController() {
45080
45316
  }
45081
45317
 
45082
45318
  // src/models/nfc-patrol-route.model.ts
45083
- var import_mongodb105 = require("mongodb");
45319
+ var import_mongodb106 = require("mongodb");
45084
45320
  var import_joi99 = __toESM(require("joi"));
45085
45321
  var import_node_server_utils177 = require("@7365admin1/node-server-utils");
45086
45322
  var schemaNfcPatrolRoute = import_joi99.default.object({
@@ -45116,23 +45352,23 @@ function MNfcPatrolRoute(value) {
45116
45352
  }
45117
45353
  if (value._id && typeof value._id === "string") {
45118
45354
  try {
45119
- value._id = new import_mongodb105.ObjectId(value._id);
45355
+ value._id = new import_mongodb106.ObjectId(value._id);
45120
45356
  } catch (error2) {
45121
45357
  throw new import_node_server_utils177.BadRequestError("Invalid _id format");
45122
45358
  }
45123
45359
  }
45124
45360
  try {
45125
- value.site = new import_mongodb105.ObjectId(value.site);
45361
+ value.site = new import_mongodb106.ObjectId(value.site);
45126
45362
  } catch (error2) {
45127
45363
  throw new import_node_server_utils177.BadRequestError("Invalid site format");
45128
45364
  }
45129
45365
  try {
45130
- value.createdBy = new import_mongodb105.ObjectId(value.createdBy);
45366
+ value.createdBy = new import_mongodb106.ObjectId(value.createdBy);
45131
45367
  } catch (error2) {
45132
45368
  throw new import_node_server_utils177.BadRequestError("Invalid createdBy format");
45133
45369
  }
45134
45370
  return {
45135
- _id: value._id ?? new import_mongodb105.ObjectId(),
45371
+ _id: value._id ?? new import_mongodb106.ObjectId(),
45136
45372
  site: value.site,
45137
45373
  name: value.name,
45138
45374
  checkPointNumber: value.checkPointNumber,
@@ -45148,7 +45384,7 @@ function MNfcPatrolRoute(value) {
45148
45384
 
45149
45385
  // src/repositories/nfc-patrol-route.repository.ts
45150
45386
  var import_node_server_utils178 = require("@7365admin1/node-server-utils");
45151
- var import_mongodb106 = require("mongodb");
45387
+ var import_mongodb107 = require("mongodb");
45152
45388
  function useNfcPatrolRouteRepo() {
45153
45389
  const db = import_node_server_utils178.useAtlas.getDb();
45154
45390
  if (!db) {
@@ -45192,7 +45428,7 @@ function useNfcPatrolRouteRepo() {
45192
45428
  }, session) {
45193
45429
  page = page > 0 ? page - 1 : 0;
45194
45430
  try {
45195
- site = new import_mongodb106.ObjectId(site);
45431
+ site = new import_mongodb107.ObjectId(site);
45196
45432
  } catch (error) {
45197
45433
  throw new import_node_server_utils178.BadRequestError("Invalid site ID format.");
45198
45434
  }
@@ -45263,7 +45499,7 @@ function useNfcPatrolRouteRepo() {
45263
45499
  }
45264
45500
  async function getById(_id, isStart) {
45265
45501
  try {
45266
- _id = new import_mongodb106.ObjectId(_id);
45502
+ _id = new import_mongodb107.ObjectId(_id);
45267
45503
  } catch (error) {
45268
45504
  throw new import_node_server_utils178.BadRequestError("Invalid ID.");
45269
45505
  }
@@ -45373,18 +45609,18 @@ function useNfcPatrolRouteRepo() {
45373
45609
  throw new import_node_server_utils178.BadRequestError(error.message);
45374
45610
  }
45375
45611
  try {
45376
- _id = new import_mongodb106.ObjectId(_id);
45612
+ _id = new import_mongodb107.ObjectId(_id);
45377
45613
  } catch (error2) {
45378
45614
  throw new import_node_server_utils178.BadRequestError("Invalid ID.");
45379
45615
  }
45380
45616
  try {
45381
- value.site = new import_mongodb106.ObjectId(value.site);
45617
+ value.site = new import_mongodb107.ObjectId(value.site);
45382
45618
  } catch (error2) {
45383
45619
  throw new import_node_server_utils178.BadRequestError("Invalid site format");
45384
45620
  }
45385
45621
  if (value.updatedBy) {
45386
45622
  try {
45387
- value.updatedBy = new import_mongodb106.ObjectId(value.updatedBy);
45623
+ value.updatedBy = new import_mongodb107.ObjectId(value.updatedBy);
45388
45624
  } catch (error2) {
45389
45625
  throw new import_node_server_utils178.BadRequestError("Invalid createdBy format");
45390
45626
  }
@@ -45609,7 +45845,7 @@ function useNfcPatrolRouteController() {
45609
45845
  }
45610
45846
 
45611
45847
  // src/models/incident-report.model.ts
45612
- var import_mongodb107 = require("mongodb");
45848
+ var import_mongodb108 = require("mongodb");
45613
45849
  var import_joi101 = __toESM(require("joi"));
45614
45850
  var residentSchema = import_joi101.default.object({
45615
45851
  _id: import_joi101.default.string().hex().optional().allow(null, ""),
@@ -45815,28 +46051,28 @@ var schemaUpdateIncidentReport = import_joi101.default.object({
45815
46051
  function MIncidentReport(value) {
45816
46052
  if (value._id && typeof value._id === "string") {
45817
46053
  try {
45818
- value._id = new import_mongodb107.ObjectId(value._id);
46054
+ value._id = new import_mongodb108.ObjectId(value._id);
45819
46055
  } catch {
45820
46056
  throw new Error("Invalid incident report ID.");
45821
46057
  }
45822
46058
  }
45823
46059
  if (value.organization && typeof value.organization === "string") {
45824
46060
  try {
45825
- value.organization = new import_mongodb107.ObjectId(value.organization);
46061
+ value.organization = new import_mongodb108.ObjectId(value.organization);
45826
46062
  } catch {
45827
46063
  throw new Error("Invalid organization ID.");
45828
46064
  }
45829
46065
  }
45830
46066
  if (value.site && typeof value.site === "string") {
45831
46067
  try {
45832
- value.site = new import_mongodb107.ObjectId(value.site);
46068
+ value.site = new import_mongodb108.ObjectId(value.site);
45833
46069
  } catch {
45834
46070
  throw new Error("Invalid site ID.");
45835
46071
  }
45836
46072
  }
45837
46073
  if (value.approvedBy && typeof value.approvedBy === "string") {
45838
46074
  try {
45839
- value.approvedBy = new import_mongodb107.ObjectId(value.approvedBy);
46075
+ value.approvedBy = new import_mongodb108.ObjectId(value.approvedBy);
45840
46076
  } catch {
45841
46077
  throw new Error("Invalid approvedBy ID.");
45842
46078
  }
@@ -45844,7 +46080,7 @@ function MIncidentReport(value) {
45844
46080
  const { incidentInformation } = value;
45845
46081
  if (incidentInformation?.siteInfo?.site && typeof incidentInformation.siteInfo.site === "string") {
45846
46082
  try {
45847
- incidentInformation.siteInfo.site = new import_mongodb107.ObjectId(
46083
+ incidentInformation.siteInfo.site = new import_mongodb108.ObjectId(
45848
46084
  incidentInformation.siteInfo.site
45849
46085
  );
45850
46086
  } catch {
@@ -45858,7 +46094,7 @@ function MIncidentReport(value) {
45858
46094
  incidentInformation.submissionForm.dateOfReport = incidentInformation.submissionForm.dateOfReport.toISOString();
45859
46095
  }
45860
46096
  return {
45861
- _id: value._id ?? new import_mongodb107.ObjectId(),
46097
+ _id: value._id ?? new import_mongodb108.ObjectId(),
45862
46098
  reportId: value.reportId,
45863
46099
  incidentInformation: value.incidentInformation,
45864
46100
  affectedEntities: value.affectedEntities,
@@ -45883,7 +46119,7 @@ var import_node_server_utils182 = require("@7365admin1/node-server-utils");
45883
46119
 
45884
46120
  // src/repositories/incident-report.repo.ts
45885
46121
  var import_node_server_utils181 = require("@7365admin1/node-server-utils");
45886
- var import_mongodb108 = require("mongodb");
46122
+ var import_mongodb109 = require("mongodb");
45887
46123
  var incidents_namespace_collection = "incident-reports";
45888
46124
  function useIncidentReportRepo() {
45889
46125
  const db = import_node_server_utils181.useAtlas.getDb();
@@ -45950,7 +46186,7 @@ function useIncidentReportRepo() {
45950
46186
  page = page > 0 ? page - 1 : 0;
45951
46187
  let dateExpr = {};
45952
46188
  try {
45953
- site = new import_mongodb108.ObjectId(site);
46189
+ site = new import_mongodb109.ObjectId(site);
45954
46190
  } catch (error) {
45955
46191
  throw new import_node_server_utils181.BadRequestError("Invalid site ID format.");
45956
46192
  }
@@ -46051,7 +46287,7 @@ function useIncidentReportRepo() {
46051
46287
  page = page > 0 ? page - 1 : 0;
46052
46288
  let dateExpr = {};
46053
46289
  try {
46054
- site = new import_mongodb108.ObjectId(site);
46290
+ site = new import_mongodb109.ObjectId(site);
46055
46291
  } catch (error) {
46056
46292
  throw new import_node_server_utils181.BadRequestError("Invalid site ID format.");
46057
46293
  }
@@ -46120,7 +46356,7 @@ function useIncidentReportRepo() {
46120
46356
  }
46121
46357
  async function getIncidentReportById(_id, session) {
46122
46358
  try {
46123
- _id = new import_mongodb108.ObjectId(_id);
46359
+ _id = new import_mongodb109.ObjectId(_id);
46124
46360
  } catch (error) {
46125
46361
  throw new import_node_server_utils181.BadRequestError("Invalid incident report ID format.");
46126
46362
  }
@@ -46151,27 +46387,27 @@ function useIncidentReportRepo() {
46151
46387
  async function updateIncidentReportById(_id, value, session) {
46152
46388
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
46153
46389
  try {
46154
- _id = new import_mongodb108.ObjectId(_id);
46390
+ _id = new import_mongodb109.ObjectId(_id);
46155
46391
  } catch (error) {
46156
46392
  throw new import_node_server_utils181.BadRequestError("Invalid ID format.");
46157
46393
  }
46158
46394
  if (value.organization && typeof value.organization === "string") {
46159
46395
  try {
46160
- value.organization = new import_mongodb108.ObjectId(value.organization);
46396
+ value.organization = new import_mongodb109.ObjectId(value.organization);
46161
46397
  } catch {
46162
46398
  throw new Error("Invalid organization ID.");
46163
46399
  }
46164
46400
  }
46165
46401
  if (value.site && typeof value.site === "string") {
46166
46402
  try {
46167
- value.site = new import_mongodb108.ObjectId(value.site);
46403
+ value.site = new import_mongodb109.ObjectId(value.site);
46168
46404
  } catch {
46169
46405
  throw new Error("Invalid site ID.");
46170
46406
  }
46171
46407
  }
46172
46408
  if (value.approvedBy && typeof value.approvedBy === "string") {
46173
46409
  try {
46174
- value.approvedBy = new import_mongodb108.ObjectId(value.approvedBy);
46410
+ value.approvedBy = new import_mongodb109.ObjectId(value.approvedBy);
46175
46411
  } catch {
46176
46412
  throw new Error("Invalid approvedBy ID.");
46177
46413
  }
@@ -46179,7 +46415,7 @@ function useIncidentReportRepo() {
46179
46415
  const { incidentInformation } = value;
46180
46416
  if (incidentInformation?.siteInfo?.site && typeof incidentInformation.siteInfo.site === "string") {
46181
46417
  try {
46182
- incidentInformation.siteInfo.site = new import_mongodb108.ObjectId(
46418
+ incidentInformation.siteInfo.site = new import_mongodb109.ObjectId(
46183
46419
  incidentInformation.siteInfo.site
46184
46420
  );
46185
46421
  } catch {
@@ -46214,7 +46450,7 @@ function useIncidentReportRepo() {
46214
46450
  }
46215
46451
  async function deleteIncidentReportById(_id) {
46216
46452
  try {
46217
- _id = new import_mongodb108.ObjectId(_id);
46453
+ _id = new import_mongodb109.ObjectId(_id);
46218
46454
  } catch (error) {
46219
46455
  throw new import_node_server_utils181.BadRequestError("Invalid occurrence subject ID format.");
46220
46456
  }
@@ -46246,7 +46482,7 @@ function useIncidentReportRepo() {
46246
46482
  async function reviewIncidentReport(_id, value, session) {
46247
46483
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
46248
46484
  try {
46249
- _id = new import_mongodb108.ObjectId(_id);
46485
+ _id = new import_mongodb109.ObjectId(_id);
46250
46486
  } catch (error) {
46251
46487
  throw new import_node_server_utils181.BadRequestError("Invalid ID format.");
46252
46488
  }
@@ -46739,7 +46975,7 @@ function useIncidentReportController() {
46739
46975
  }
46740
46976
 
46741
46977
  // src/models/nfc-patrol-settings.model.ts
46742
- var import_mongodb109 = require("mongodb");
46978
+ var import_mongodb110 = require("mongodb");
46743
46979
  var import_joi103 = __toESM(require("joi"));
46744
46980
  var import_node_server_utils184 = require("@7365admin1/node-server-utils");
46745
46981
  var objectId = import_joi103.default.string().hex().length(24);
@@ -46765,7 +47001,7 @@ function MNfcPatrolSettings(value) {
46765
47001
  }
46766
47002
  if (value.site) {
46767
47003
  try {
46768
- value.site = new import_mongodb109.ObjectId(value.site);
47004
+ value.site = new import_mongodb110.ObjectId(value.site);
46769
47005
  } catch (error2) {
46770
47006
  throw new import_node_server_utils184.BadRequestError("Invalid site ID format.");
46771
47007
  }
@@ -46785,7 +47021,7 @@ function MNfcPatrolSettingsUpdate(value) {
46785
47021
  }
46786
47022
  if (value.updatedBy) {
46787
47023
  try {
46788
- value.updatedBy = new import_mongodb109.ObjectId(value.updatedBy);
47024
+ value.updatedBy = new import_mongodb110.ObjectId(value.updatedBy);
46789
47025
  } catch (error2) {
46790
47026
  throw new import_node_server_utils184.BadRequestError("Invalid updatedBy ID format.");
46791
47027
  }
@@ -46799,7 +47035,7 @@ function MNfcPatrolSettingsUpdate(value) {
46799
47035
 
46800
47036
  // src/repositories/nfc-patrol-settings.repository.ts
46801
47037
  var import_node_server_utils185 = require("@7365admin1/node-server-utils");
46802
- var import_mongodb110 = require("mongodb");
47038
+ var import_mongodb111 = require("mongodb");
46803
47039
  function useNfcPatrolSettingsRepository() {
46804
47040
  const db = import_node_server_utils185.useAtlas.getDb();
46805
47041
  if (!db) {
@@ -46829,7 +47065,7 @@ function useNfcPatrolSettingsRepository() {
46829
47065
  }
46830
47066
  async function getNfcPatrolSettingsBySite(site, session) {
46831
47067
  try {
46832
- site = new import_mongodb110.ObjectId(site);
47068
+ site = new import_mongodb111.ObjectId(site);
46833
47069
  } catch (error) {
46834
47070
  throw new import_node_server_utils185.BadRequestError("Invalid nfc patrol settings site ID format.");
46835
47071
  }
@@ -46873,7 +47109,7 @@ function useNfcPatrolSettingsRepository() {
46873
47109
  }
46874
47110
  async function updateNfcPatrolSettings(site, value, session) {
46875
47111
  try {
46876
- site = new import_mongodb110.ObjectId(site);
47112
+ site = new import_mongodb111.ObjectId(site);
46877
47113
  } catch (error) {
46878
47114
  throw new import_node_server_utils185.BadRequestError("Invalid attendance settings ID format.");
46879
47115
  }
@@ -47038,13 +47274,13 @@ function useNfcPatrolSettingsController() {
47038
47274
 
47039
47275
  // src/services/occurrence-entry.service.ts
47040
47276
  var import_node_server_utils189 = require("@7365admin1/node-server-utils");
47041
- var import_mongodb113 = require("mongodb");
47277
+ var import_mongodb114 = require("mongodb");
47042
47278
 
47043
47279
  // src/repositories/occurrence-subject.repo.ts
47044
47280
  var import_node_server_utils188 = require("@7365admin1/node-server-utils");
47045
47281
 
47046
47282
  // src/models/occurrence-subject.model.ts
47047
- var import_mongodb111 = require("mongodb");
47283
+ var import_mongodb112 = require("mongodb");
47048
47284
  var import_joi105 = __toESM(require("joi"));
47049
47285
  var SubjectSort = /* @__PURE__ */ ((SubjectSort2) => {
47050
47286
  SubjectSort2["CREATED_AT"] = "createdAt";
@@ -47069,27 +47305,27 @@ var schemaUpdateOccurrenceSubject = import_joi105.default.object({
47069
47305
  function MOccurrenceSubject(value) {
47070
47306
  if (value._id && typeof value._id === "string") {
47071
47307
  try {
47072
- value._id = new import_mongodb111.ObjectId(value._id);
47308
+ value._id = new import_mongodb112.ObjectId(value._id);
47073
47309
  } catch {
47074
47310
  throw new Error("Invalid ID.");
47075
47311
  }
47076
47312
  }
47077
47313
  if (value.site && typeof value.site === "string") {
47078
47314
  try {
47079
- value.site = new import_mongodb111.ObjectId(value.site);
47315
+ value.site = new import_mongodb112.ObjectId(value.site);
47080
47316
  } catch {
47081
47317
  throw new Error("Invalid site ID.");
47082
47318
  }
47083
47319
  }
47084
47320
  if (value.addedBy && typeof value.addedBy === "string") {
47085
47321
  try {
47086
- value.addedBy = new import_mongodb111.ObjectId(value.addedBy);
47322
+ value.addedBy = new import_mongodb112.ObjectId(value.addedBy);
47087
47323
  } catch {
47088
47324
  throw new Error("Invalid addedBy ID.");
47089
47325
  }
47090
47326
  }
47091
47327
  return {
47092
- _id: value._id ?? new import_mongodb111.ObjectId(),
47328
+ _id: value._id ?? new import_mongodb112.ObjectId(),
47093
47329
  site: value.site,
47094
47330
  subject: value.subject,
47095
47331
  addedBy: value.addedBy ?? "",
@@ -47100,7 +47336,7 @@ function MOccurrenceSubject(value) {
47100
47336
  }
47101
47337
 
47102
47338
  // src/repositories/occurrence-subject.repo.ts
47103
- var import_mongodb112 = require("mongodb");
47339
+ var import_mongodb113 = require("mongodb");
47104
47340
  function useOccurrenceSubjectRepo() {
47105
47341
  const db = import_node_server_utils188.useAtlas.getDb();
47106
47342
  if (!db) {
@@ -47159,7 +47395,7 @@ function useOccurrenceSubjectRepo() {
47159
47395
  }, session) {
47160
47396
  page = page > 0 ? page - 1 : 0;
47161
47397
  try {
47162
- site = new import_mongodb112.ObjectId(site);
47398
+ site = new import_mongodb113.ObjectId(site);
47163
47399
  } catch (error) {
47164
47400
  throw new import_node_server_utils188.BadRequestError("Invalid site ID format.");
47165
47401
  }
@@ -47252,7 +47488,7 @@ function useOccurrenceSubjectRepo() {
47252
47488
  }
47253
47489
  async function getOccurrenceSubjectById(_id, session) {
47254
47490
  try {
47255
- _id = new import_mongodb112.ObjectId(_id);
47491
+ _id = new import_mongodb113.ObjectId(_id);
47256
47492
  } catch (error) {
47257
47493
  throw new import_node_server_utils188.BadRequestError("Invalid occurrence subject ID format.");
47258
47494
  }
@@ -47280,7 +47516,7 @@ function useOccurrenceSubjectRepo() {
47280
47516
  async function updateOccurrenceSubjectById(_id, value, session) {
47281
47517
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
47282
47518
  try {
47283
- _id = new import_mongodb112.ObjectId(_id);
47519
+ _id = new import_mongodb113.ObjectId(_id);
47284
47520
  } catch (error) {
47285
47521
  throw new import_node_server_utils188.BadRequestError("Invalid ID format.");
47286
47522
  }
@@ -47310,7 +47546,7 @@ function useOccurrenceSubjectRepo() {
47310
47546
  }
47311
47547
  async function deleteOccurrenceSubjectById(_id) {
47312
47548
  try {
47313
- _id = new import_mongodb112.ObjectId(_id);
47549
+ _id = new import_mongodb113.ObjectId(_id);
47314
47550
  } catch (error) {
47315
47551
  throw new import_node_server_utils188.BadRequestError("Invalid occurrence subject ID format.");
47316
47552
  }
@@ -47441,8 +47677,8 @@ function useOccurrenceEntryService() {
47441
47677
  value.dailyOccurrenceBookId = occurrenceEntry.dailyOccurrenceBookId;
47442
47678
  value.bookEntryCount = value.bookEntryCount ? value.bookEntryCount : occurrenceEntry.bookEntryCount;
47443
47679
  value.occurrence = value.occurrence ? value.occurrence : occurrenceEntry.occurrence;
47444
- value.signature = value.signature ? new import_mongodb113.ObjectId(value.signature) : occurrenceEntry.signature._id;
47445
- value.eSignature = value.eSignature ? new import_mongodb113.ObjectId(value.eSignature) : occurrenceEntry.eSignature;
47680
+ value.signature = value.signature ? new import_mongodb114.ObjectId(value.signature) : occurrenceEntry.signature._id;
47681
+ value.eSignature = value.eSignature ? new import_mongodb114.ObjectId(value.eSignature) : occurrenceEntry.eSignature;
47446
47682
  value.createdAt = /* @__PURE__ */ new Date();
47447
47683
  value.date = value.date ? value.date : occurrenceEntry.date;
47448
47684
  value.userName = value.userName ? value.userName : occurrenceEntry.signature.name;
@@ -47634,7 +47870,7 @@ function useOccurrenceEntryController() {
47634
47870
 
47635
47871
  // src/models/online-form.model.ts
47636
47872
  var import_joi107 = __toESM(require("joi"));
47637
- var import_mongodb114 = require("mongodb");
47873
+ var import_mongodb115 = require("mongodb");
47638
47874
  var schemaOnlineForm = import_joi107.default.object({
47639
47875
  _id: import_joi107.default.string().hex().optional().allow("", null),
47640
47876
  name: import_joi107.default.string().required(),
@@ -47682,21 +47918,21 @@ function MOnlineForm(value) {
47682
47918
  }
47683
47919
  if (value._id && typeof value._id === "string") {
47684
47920
  try {
47685
- value._id = new import_mongodb114.ObjectId(value._id);
47921
+ value._id = new import_mongodb115.ObjectId(value._id);
47686
47922
  } catch (error2) {
47687
47923
  throw new Error("Invalid ID.");
47688
47924
  }
47689
47925
  }
47690
47926
  if (value.org && typeof value.org === "string") {
47691
47927
  try {
47692
- value.org = new import_mongodb114.ObjectId(value.org);
47928
+ value.org = new import_mongodb115.ObjectId(value.org);
47693
47929
  } catch (error2) {
47694
47930
  throw new Error("Invalid org ID.");
47695
47931
  }
47696
47932
  }
47697
47933
  if (value.site && typeof value.site === "string") {
47698
47934
  try {
47699
- value.site = new import_mongodb114.ObjectId(value.site);
47935
+ value.site = new import_mongodb115.ObjectId(value.site);
47700
47936
  } catch (error2) {
47701
47937
  throw new Error("Invalid site ID.");
47702
47938
  }
@@ -47719,7 +47955,7 @@ function MOnlineForm(value) {
47719
47955
 
47720
47956
  // src/repositories/online-form.repo.ts
47721
47957
  var import_node_server_utils191 = require("@7365admin1/node-server-utils");
47722
- var import_mongodb115 = require("mongodb");
47958
+ var import_mongodb116 = require("mongodb");
47723
47959
  function useOnlineFormRepo() {
47724
47960
  const db = import_node_server_utils191.useAtlas.getDb();
47725
47961
  if (!db) {
@@ -47771,7 +48007,7 @@ function useOnlineFormRepo() {
47771
48007
  }) {
47772
48008
  page = page > 0 ? page - 1 : 0;
47773
48009
  try {
47774
- site = new import_mongodb115.ObjectId(site);
48010
+ site = new import_mongodb116.ObjectId(site);
47775
48011
  } catch (error) {
47776
48012
  throw new import_node_server_utils191.BadRequestError("Invalid site ID format.");
47777
48013
  }
@@ -47831,7 +48067,7 @@ function useOnlineFormRepo() {
47831
48067
  }
47832
48068
  async function getOnlineFormById(_id) {
47833
48069
  try {
47834
- _id = new import_mongodb115.ObjectId(_id);
48070
+ _id = new import_mongodb116.ObjectId(_id);
47835
48071
  } catch (error) {
47836
48072
  throw new import_node_server_utils191.BadRequestError("Invalid online form ID format.");
47837
48073
  }
@@ -47874,7 +48110,7 @@ function useOnlineFormRepo() {
47874
48110
  }
47875
48111
  async function updateOnlineFormById(_id, value) {
47876
48112
  try {
47877
- _id = new import_mongodb115.ObjectId(_id);
48113
+ _id = new import_mongodb116.ObjectId(_id);
47878
48114
  } catch (error) {
47879
48115
  throw new import_node_server_utils191.BadRequestError("Invalid online form ID format.");
47880
48116
  }
@@ -47902,7 +48138,7 @@ function useOnlineFormRepo() {
47902
48138
  }
47903
48139
  async function deleteOnlineFormById(_id, session) {
47904
48140
  try {
47905
- _id = new import_mongodb115.ObjectId(_id);
48141
+ _id = new import_mongodb116.ObjectId(_id);
47906
48142
  } catch (error) {
47907
48143
  throw new import_node_server_utils191.BadRequestError("Invalid online form ID format.");
47908
48144
  }
@@ -47935,7 +48171,7 @@ function useOnlineFormRepo() {
47935
48171
  }
47936
48172
  async function getOnlineFormsBySiteId(site, { search = "", page = 1, limit = 10, status = "active" }) {
47937
48173
  try {
47938
- site = new import_mongodb115.ObjectId(site);
48174
+ site = new import_mongodb116.ObjectId(site);
47939
48175
  } catch (error) {
47940
48176
  throw new import_node_server_utils191.BadRequestError(
47941
48177
  "Invalid online form configuration site ID format."
@@ -48367,7 +48603,7 @@ function useOccurrenceSubjectController() {
48367
48603
  }
48368
48604
 
48369
48605
  // src/models/nfc-patrol-log.model.ts
48370
- var import_mongodb116 = require("mongodb");
48606
+ var import_mongodb117 = require("mongodb");
48371
48607
  var import_joi110 = __toESM(require("joi"));
48372
48608
  var import_node_server_utils195 = require("@7365admin1/node-server-utils");
48373
48609
  var schemaNfcPatrolLog = import_joi110.default.object({
@@ -48419,32 +48655,32 @@ function MNfcPatrolLog(valueArg) {
48419
48655
  }
48420
48656
  if (value._id && typeof value._id === "string") {
48421
48657
  try {
48422
- value._id = new import_mongodb116.ObjectId(value._id);
48658
+ value._id = new import_mongodb117.ObjectId(value._id);
48423
48659
  } catch (error2) {
48424
48660
  throw new import_node_server_utils195.BadRequestError("Invalid _id format");
48425
48661
  }
48426
48662
  }
48427
48663
  try {
48428
- value.site = new import_mongodb116.ObjectId(value.site);
48664
+ value.site = new import_mongodb117.ObjectId(value.site);
48429
48665
  } catch (error2) {
48430
48666
  throw new import_node_server_utils195.BadRequestError("Invalid site format");
48431
48667
  }
48432
48668
  if (value?.createdBy) {
48433
48669
  try {
48434
- value.createdBy = new import_mongodb116.ObjectId(value.createdBy);
48670
+ value.createdBy = new import_mongodb117.ObjectId(value.createdBy);
48435
48671
  } catch (error2) {
48436
48672
  throw new import_node_server_utils195.BadRequestError("Invalid createdBy format");
48437
48673
  }
48438
48674
  }
48439
48675
  if (value?.route?._id) {
48440
48676
  try {
48441
- value.route._id = new import_mongodb116.ObjectId(value.route._id);
48677
+ value.route._id = new import_mongodb117.ObjectId(value.route._id);
48442
48678
  } catch (error2) {
48443
48679
  throw new import_node_server_utils195.BadRequestError("Invalid route _id format");
48444
48680
  }
48445
48681
  }
48446
48682
  return {
48447
- _id: value._id ?? new import_mongodb116.ObjectId(),
48683
+ _id: value._id ?? new import_mongodb117.ObjectId(),
48448
48684
  site: value.site,
48449
48685
  route: value.route,
48450
48686
  date: value.date,
@@ -48458,7 +48694,7 @@ function MNfcPatrolLog(valueArg) {
48458
48694
 
48459
48695
  // src/repositories/nfc-patrol-log.repository.ts
48460
48696
  var import_node_server_utils196 = require("@7365admin1/node-server-utils");
48461
- var import_mongodb117 = require("mongodb");
48697
+ var import_mongodb118 = require("mongodb");
48462
48698
  function useNfcPatrolLogRepo() {
48463
48699
  const db = import_node_server_utils196.useAtlas.getDb();
48464
48700
  if (!db) {
@@ -48511,7 +48747,7 @@ function useNfcPatrolLogRepo() {
48511
48747
  const pageIndex = page > 0 ? page - 1 : 0;
48512
48748
  let siteId;
48513
48749
  try {
48514
- siteId = typeof site === "string" ? new import_mongodb117.ObjectId(site) : site;
48750
+ siteId = typeof site === "string" ? new import_mongodb118.ObjectId(site) : site;
48515
48751
  } catch {
48516
48752
  throw new import_node_server_utils196.BadRequestError("Invalid site ID format.");
48517
48753
  }
@@ -48522,7 +48758,7 @@ function useNfcPatrolLogRepo() {
48522
48758
  query.date = date;
48523
48759
  }
48524
48760
  if (route?._id) {
48525
- query["route._id"] = typeof route._id === "string" ? new import_mongodb117.ObjectId(route._id) : route._id;
48761
+ query["route._id"] = typeof route._id === "string" ? new import_mongodb118.ObjectId(route._id) : route._id;
48526
48762
  }
48527
48763
  if (route?.startTime) {
48528
48764
  query["route.startTime"] = route.startTime;
@@ -49381,7 +49617,7 @@ function useNewDashboardController() {
49381
49617
 
49382
49618
  // src/models/manpower-monitoring.model.ts
49383
49619
  var import_joi113 = __toESM(require("joi"));
49384
- var import_mongodb118 = require("mongodb");
49620
+ var import_mongodb119 = require("mongodb");
49385
49621
  var shiftSchema = import_joi113.default.object({
49386
49622
  name: import_joi113.default.string().required(),
49387
49623
  checkIn: import_joi113.default.string().optional().allow("", null),
@@ -49406,7 +49642,7 @@ var manpowerMonitoringSchema = import_joi113.default.object({
49406
49642
  });
49407
49643
  var MManpowerMonitoring = class {
49408
49644
  constructor(data) {
49409
- this._id = new import_mongodb118.ObjectId();
49645
+ this._id = new import_mongodb119.ObjectId();
49410
49646
  this.serviceProviderId = data.serviceProviderId || "";
49411
49647
  this.siteId = data.siteId || "";
49412
49648
  this.siteName = data.siteName;
@@ -49873,7 +50109,7 @@ var hrmlabs_attendance_util_default = {
49873
50109
  };
49874
50110
 
49875
50111
  // src/repositories/manpower-monitoring.repo.ts
49876
- var import_mongodb119 = require("mongodb");
50112
+ var import_mongodb120 = require("mongodb");
49877
50113
  var { hrmLabsAuthentication: hrmLabsAuthentication2, fetchSites: fetchSites2 } = hrmlabs_attendance_util_default;
49878
50114
  function useManpowerMonitoringRepo() {
49879
50115
  const db = import_node_server_utils201.useAtlas.getDb();
@@ -49908,11 +50144,11 @@ function useManpowerMonitoringRepo() {
49908
50144
  try {
49909
50145
  value = new MManpowerMonitoring(value);
49910
50146
  if (value.createdBy)
49911
- value.createdBy = new import_mongodb119.ObjectId(value.createdBy);
50147
+ value.createdBy = new import_mongodb120.ObjectId(value.createdBy);
49912
50148
  if (value.siteId)
49913
- value.siteId = new import_mongodb119.ObjectId(value.siteId);
50149
+ value.siteId = new import_mongodb120.ObjectId(value.siteId);
49914
50150
  if (value.serviceProviderId)
49915
- value.serviceProviderId = new import_mongodb119.ObjectId(value.serviceProviderId);
50151
+ value.serviceProviderId = new import_mongodb120.ObjectId(value.serviceProviderId);
49916
50152
  const result = await collection.insertOne(value, { session });
49917
50153
  return result;
49918
50154
  } catch (error) {
@@ -49953,8 +50189,8 @@ function useManpowerMonitoringRepo() {
49953
50189
  }
49954
50190
  async function getManpowerSettingsBySiteId(_id, serviceProviderId) {
49955
50191
  try {
49956
- _id = new import_mongodb119.ObjectId(_id);
49957
- serviceProviderId = new import_mongodb119.ObjectId(serviceProviderId);
50192
+ _id = new import_mongodb120.ObjectId(_id);
50193
+ serviceProviderId = new import_mongodb120.ObjectId(serviceProviderId);
49958
50194
  } catch (error) {
49959
50195
  throw new Error("Invalid Site ID format.");
49960
50196
  }
@@ -49970,7 +50206,7 @@ function useManpowerMonitoringRepo() {
49970
50206
  }
49971
50207
  async function updateManpowerMonitoringSettings(_id, value) {
49972
50208
  try {
49973
- _id = new import_mongodb119.ObjectId(_id);
50209
+ _id = new import_mongodb120.ObjectId(_id);
49974
50210
  } catch (error) {
49975
50211
  throw new import_node_server_utils201.BadRequestError("Invalid ID format.");
49976
50212
  }
@@ -49997,7 +50233,7 @@ function useManpowerMonitoringRepo() {
49997
50233
  for (let item of value) {
49998
50234
  item = new MManpowerMonitoring(item);
49999
50235
  const data = await collection.findOne({
50000
- siteId: new import_mongodb119.ObjectId(item.siteId)
50236
+ siteId: new import_mongodb120.ObjectId(item.siteId)
50001
50237
  });
50002
50238
  if (data) {
50003
50239
  let updateValue;
@@ -50022,11 +50258,11 @@ function useManpowerMonitoringRepo() {
50022
50258
  }
50023
50259
  } else {
50024
50260
  if (item.createdBy)
50025
- item.createdBy = new import_mongodb119.ObjectId(item.createdBy);
50261
+ item.createdBy = new import_mongodb120.ObjectId(item.createdBy);
50026
50262
  if (item.siteId)
50027
- item.siteId = new import_mongodb119.ObjectId(item.siteId);
50263
+ item.siteId = new import_mongodb120.ObjectId(item.siteId);
50028
50264
  if (item.serviceProviderId)
50029
- item.serviceProviderId = new import_mongodb119.ObjectId(item.serviceProviderId);
50265
+ item.serviceProviderId = new import_mongodb120.ObjectId(item.serviceProviderId);
50030
50266
  const result = await collection.insertOne(item);
50031
50267
  if (result.insertedId) {
50032
50268
  results.inserted++;
@@ -50050,7 +50286,7 @@ function useManpowerMonitoringRepo() {
50050
50286
  const siteUrl = process.env.HRMLABS_SITE_URL;
50051
50287
  try {
50052
50288
  const serviceProvider = await serviceProviderCollection.findOne({
50053
- _id: new import_mongodb119.ObjectId(serviceProviderId)
50289
+ _id: new import_mongodb120.ObjectId(serviceProviderId)
50054
50290
  });
50055
50291
  if (!serviceProvider) {
50056
50292
  throw new Error("Service Provider not found.");
@@ -50093,7 +50329,7 @@ var import_node_server_utils202 = require("@7365admin1/node-server-utils");
50093
50329
 
50094
50330
  // src/models/manpower-remarks.model.ts
50095
50331
  var import_joi114 = __toESM(require("joi"));
50096
- var import_mongodb120 = require("mongodb");
50332
+ var import_mongodb121 = require("mongodb");
50097
50333
  var remarksSchema = import_joi114.default.object({
50098
50334
  name: import_joi114.default.string().required(),
50099
50335
  remark: import_joi114.default.object({
@@ -50117,7 +50353,7 @@ var manpowerRemarksSchema = import_joi114.default.object({
50117
50353
  });
50118
50354
  var MManpowerRemarks = class {
50119
50355
  constructor(data) {
50120
- this._id = new import_mongodb120.ObjectId();
50356
+ this._id = new import_mongodb121.ObjectId();
50121
50357
  this.serviceProviderId = data.serviceProviderId || "";
50122
50358
  this.siteId = data.siteId || "";
50123
50359
  this.siteName = data.siteName || "";
@@ -50135,7 +50371,7 @@ var MManpowerRemarks = class {
50135
50371
  };
50136
50372
 
50137
50373
  // src/repositories/manpower-remarks.repo.ts
50138
- var import_mongodb121 = require("mongodb");
50374
+ var import_mongodb122 = require("mongodb");
50139
50375
  var import_moment_timezone2 = __toESM(require("moment-timezone"));
50140
50376
  function useManpowerRemarksRepo() {
50141
50377
  const db = import_node_server_utils202.useAtlas.getDb();
@@ -50169,9 +50405,9 @@ function useManpowerRemarksRepo() {
50169
50405
  try {
50170
50406
  value = new MManpowerRemarks(value);
50171
50407
  if (value.siteId)
50172
- value.siteId = new import_mongodb121.ObjectId(value.siteId);
50408
+ value.siteId = new import_mongodb122.ObjectId(value.siteId);
50173
50409
  if (value.serviceProviderId)
50174
- value.serviceProviderId = new import_mongodb121.ObjectId(value.serviceProviderId);
50410
+ value.serviceProviderId = new import_mongodb122.ObjectId(value.serviceProviderId);
50175
50411
  const result = await collection.insertOne(value, { session });
50176
50412
  return result;
50177
50413
  } catch (error) {
@@ -50191,7 +50427,7 @@ function useManpowerRemarksRepo() {
50191
50427
  limit = limit || 10;
50192
50428
  const searchQuery = {};
50193
50429
  const nowSGT = (0, import_moment_timezone2.default)().tz("Asia/Singapore");
50194
- searchQuery.serviceProviderId = new import_mongodb121.ObjectId(serviceProviderId);
50430
+ searchQuery.serviceProviderId = new import_mongodb122.ObjectId(serviceProviderId);
50195
50431
  if (search != "") {
50196
50432
  searchQuery.siteName = { $regex: search, $options: "i" };
50197
50433
  }
@@ -50223,8 +50459,8 @@ function useManpowerRemarksRepo() {
50223
50459
  }
50224
50460
  async function getManpowerRemarksBySiteId(_id, date, serviceProviderId) {
50225
50461
  try {
50226
- _id = new import_mongodb121.ObjectId(_id);
50227
- serviceProviderId = new import_mongodb121.ObjectId(serviceProviderId);
50462
+ _id = new import_mongodb122.ObjectId(_id);
50463
+ serviceProviderId = new import_mongodb122.ObjectId(serviceProviderId);
50228
50464
  } catch (error) {
50229
50465
  throw new Error("Invalid Site ID format.");
50230
50466
  }
@@ -50241,13 +50477,13 @@ function useManpowerRemarksRepo() {
50241
50477
  }
50242
50478
  async function updateManpowerRemarks(_id, value) {
50243
50479
  try {
50244
- _id = new import_mongodb121.ObjectId(_id);
50480
+ _id = new import_mongodb122.ObjectId(_id);
50245
50481
  } catch (error) {
50246
50482
  throw new import_node_server_utils202.BadRequestError("Invalid ID format.");
50247
50483
  }
50248
50484
  try {
50249
50485
  if (value.createdBy) {
50250
- value.createdBy = new import_mongodb121.ObjectId(value.createdBy);
50486
+ value.createdBy = new import_mongodb122.ObjectId(value.createdBy);
50251
50487
  }
50252
50488
  const updateValue = {
50253
50489
  ...value,
@@ -50264,7 +50500,7 @@ function useManpowerRemarksRepo() {
50264
50500
  }
50265
50501
  async function updateRemarksStatus(_id, value) {
50266
50502
  try {
50267
- _id = new import_mongodb121.ObjectId(_id);
50503
+ _id = new import_mongodb122.ObjectId(_id);
50268
50504
  } catch (error) {
50269
50505
  throw new import_node_server_utils202.BadRequestError("Invalid ID format.");
50270
50506
  }
@@ -50534,7 +50770,7 @@ function useManpowerMonitoringCtrl() {
50534
50770
 
50535
50771
  // src/models/manpower-designations.model.ts
50536
50772
  var import_joi116 = __toESM(require("joi"));
50537
- var import_mongodb122 = require("mongodb");
50773
+ var import_mongodb123 = require("mongodb");
50538
50774
  var designationsSchema = import_joi116.default.object({
50539
50775
  title: import_joi116.default.string().required(),
50540
50776
  shifts: import_joi116.default.object({
@@ -50553,7 +50789,7 @@ var manpowerDesignationsSchema = import_joi116.default.object({
50553
50789
  });
50554
50790
  var MManpowerDesignations = class {
50555
50791
  constructor(data) {
50556
- this._id = new import_mongodb122.ObjectId();
50792
+ this._id = new import_mongodb123.ObjectId();
50557
50793
  this.siteId = data.siteId || "";
50558
50794
  this.siteName = data.siteName || "";
50559
50795
  this.serviceProviderId = data.serviceProviderId || "";
@@ -50567,7 +50803,7 @@ var MManpowerDesignations = class {
50567
50803
 
50568
50804
  // src/repositories/manpower-designations.repo.ts
50569
50805
  var import_node_server_utils205 = require("@7365admin1/node-server-utils");
50570
- var import_mongodb123 = require("mongodb");
50806
+ var import_mongodb124 = require("mongodb");
50571
50807
  function useManpowerDesignationRepo() {
50572
50808
  const db = import_node_server_utils205.useAtlas.getDb();
50573
50809
  if (!db) {
@@ -50599,11 +50835,11 @@ function useManpowerDesignationRepo() {
50599
50835
  try {
50600
50836
  value = new MManpowerDesignations(value);
50601
50837
  if (value.createdBy)
50602
- value.createdBy = new import_mongodb123.ObjectId(value.createdBy);
50838
+ value.createdBy = new import_mongodb124.ObjectId(value.createdBy);
50603
50839
  if (value.siteId)
50604
- value.siteId = new import_mongodb123.ObjectId(value.siteId);
50840
+ value.siteId = new import_mongodb124.ObjectId(value.siteId);
50605
50841
  if (value.serviceProviderId)
50606
- value.serviceProviderId = new import_mongodb123.ObjectId(value.serviceProviderId);
50842
+ value.serviceProviderId = new import_mongodb124.ObjectId(value.serviceProviderId);
50607
50843
  const result = await collection.insertOne(value);
50608
50844
  return result;
50609
50845
  } catch (error) {
@@ -50612,8 +50848,8 @@ function useManpowerDesignationRepo() {
50612
50848
  }
50613
50849
  async function getManpowerDesignationsBySiteId(_id, serviceProviderId) {
50614
50850
  try {
50615
- _id = new import_mongodb123.ObjectId(_id);
50616
- serviceProviderId = new import_mongodb123.ObjectId(serviceProviderId);
50851
+ _id = new import_mongodb124.ObjectId(_id);
50852
+ serviceProviderId = new import_mongodb124.ObjectId(serviceProviderId);
50617
50853
  } catch (error) {
50618
50854
  throw new Error("Invalid Site ID format.");
50619
50855
  }
@@ -50629,7 +50865,7 @@ function useManpowerDesignationRepo() {
50629
50865
  }
50630
50866
  async function updateManpowerDesignations(_id, value) {
50631
50867
  try {
50632
- _id = new import_mongodb123.ObjectId(_id);
50868
+ _id = new import_mongodb124.ObjectId(_id);
50633
50869
  } catch (error) {
50634
50870
  throw new Error("Invalid ID format.");
50635
50871
  }
@@ -50733,7 +50969,7 @@ function useManpowerDesignationCtrl() {
50733
50969
 
50734
50970
  // src/models/overnight-parking.model.ts
50735
50971
  var import_joi118 = __toESM(require("joi"));
50736
- var import_mongodb124 = require("mongodb");
50972
+ var import_mongodb125 = require("mongodb");
50737
50973
  var dayScheduleSchema = import_joi118.default.object({
50738
50974
  isEnabled: import_joi118.default.boolean().required(),
50739
50975
  startTime: import_joi118.default.string().pattern(/^([01]\d|2[0-3]):([0-5]\d)$/).optional().allow(null, "").messages({
@@ -50775,7 +51011,7 @@ function MOvernightParkingApprovalHours(value) {
50775
51011
  }
50776
51012
  if (value.site && typeof value.site === "string") {
50777
51013
  try {
50778
- value.site = new import_mongodb124.ObjectId(value.site);
51014
+ value.site = new import_mongodb125.ObjectId(value.site);
50779
51015
  } catch {
50780
51016
  throw new Error("Invalid site ID.");
50781
51017
  }
@@ -52380,7 +52616,7 @@ function useManpowerRemarkCtrl() {
52380
52616
 
52381
52617
  // src/models/manpower-sites.model.ts
52382
52618
  var import_joi124 = __toESM(require("joi"));
52383
- var import_mongodb125 = require("mongodb");
52619
+ var import_mongodb126 = require("mongodb");
52384
52620
  var manpowerSitesSchema = import_joi124.default.object({
52385
52621
  id: import_joi124.default.string().hex().required(),
52386
52622
  text: import_joi124.default.string().hex().optional().allow("", null),
@@ -52391,7 +52627,7 @@ var manpowerSitesSchema = import_joi124.default.object({
52391
52627
  });
52392
52628
  var MManpowerSites = class {
52393
52629
  constructor(data) {
52394
- this._id = new import_mongodb125.ObjectId();
52630
+ this._id = new import_mongodb126.ObjectId();
52395
52631
  this.id = data.id || "";
52396
52632
  this.text = data.text || "";
52397
52633
  this.contractID = data.contractID || "";
@@ -52601,7 +52837,7 @@ function useManpowerSitesCtrl() {
52601
52837
 
52602
52838
  // src/utils/cron.util.ts
52603
52839
  var import_node_server_utils219 = require("@7365admin1/node-server-utils");
52604
- var import_mongodb126 = require("mongodb");
52840
+ var import_mongodb127 = require("mongodb");
52605
52841
  var import_moment_timezone4 = __toESM(require("moment-timezone"));
52606
52842
  var createManpowerRemarksDaily = async () => {
52607
52843
  const db = import_node_server_utils219.useAtlas.getDb();
@@ -52761,7 +52997,7 @@ var updateRemarksisAcknowledged = async () => {
52761
52997
  for (const id of updatedIds) {
52762
52998
  const doc = await remarks.findOne({ _id: id });
52763
52999
  const setting = await settings.findOne(
52764
- { siteId: new import_mongodb126.ObjectId(doc?.siteId) },
53000
+ { siteId: new import_mongodb127.ObjectId(doc?.siteId) },
52765
53001
  { projection: { emails: 1 } }
52766
53002
  );
52767
53003
  const payload = {
@@ -52847,7 +53083,7 @@ var updateRemarksStatusEod = async () => {
52847
53083
  for (const doc of docs) {
52848
53084
  let shiftsToCheck = [];
52849
53085
  const endShiftTime = await settings.findOne(
52850
- { siteId: new import_mongodb126.ObjectId(doc.siteId) },
53086
+ { siteId: new import_mongodb127.ObjectId(doc.siteId) },
52851
53087
  { projection: { shifts: 1, shiftType: 1 } }
52852
53088
  );
52853
53089
  if (doc.createdAtSGT === nowSGT) {
@@ -52953,7 +53189,7 @@ var isWithinHour = (alertTime, timeNow) => {
52953
53189
 
52954
53190
  // src/events/manpower.event.ts
52955
53191
  var import_node_server_utils220 = require("@7365admin1/node-server-utils");
52956
- var import_mongodb127 = require("mongodb");
53192
+ var import_mongodb128 = require("mongodb");
52957
53193
  var import_moment_timezone5 = __toESM(require("moment-timezone"));
52958
53194
  async function manpowerEvents(io) {
52959
53195
  let intervalId = null;
@@ -52979,7 +53215,7 @@ async function manpowerEvents(io) {
52979
53215
  }).toArray();
52980
53216
  for (const doc of docs) {
52981
53217
  const siteSettings = await settings.findOne(
52982
- { siteId: new import_mongodb127.ObjectId(doc.siteId), enabled: true },
53218
+ { siteId: new import_mongodb128.ObjectId(doc.siteId), enabled: true },
52983
53219
  { projection: { shifts: 1, shiftType: 1 } }
52984
53220
  );
52985
53221
  const shiftType = siteSettings?.shiftType || "2-shifts";
@@ -53098,11 +53334,11 @@ function genericSignature(params, secretKey) {
53098
53334
  }
53099
53335
 
53100
53336
  // src/repositories/reddot-payment.repository.ts
53101
- var import_mongodb129 = require("mongodb");
53337
+ var import_mongodb130 = require("mongodb");
53102
53338
 
53103
53339
  // src/models/billing-payments.model.ts
53104
53340
  var import_node_server_utils221 = require("@7365admin1/node-server-utils");
53105
- var import_mongodb128 = require("mongodb");
53341
+ var import_mongodb129 = require("mongodb");
53106
53342
  var import_joi126 = __toESM(require("joi"));
53107
53343
  var schemaBillingItems = import_joi126.default.object({
53108
53344
  _id: import_joi126.default.string().hex().optional(),
@@ -53136,21 +53372,21 @@ function MBillingItems(value) {
53136
53372
  }
53137
53373
  if (value._id && typeof value._id === "string") {
53138
53374
  try {
53139
- value._id = new import_mongodb128.ObjectId(value._id);
53375
+ value._id = new import_mongodb129.ObjectId(value._id);
53140
53376
  } catch {
53141
53377
  throw new import_node_server_utils221.BadRequestError("Invalid _id format");
53142
53378
  }
53143
53379
  }
53144
53380
  if (value.unitId && typeof value.unitId === "string") {
53145
53381
  try {
53146
- value.unitId = new import_mongodb128.ObjectId(value.unitId);
53382
+ value.unitId = new import_mongodb129.ObjectId(value.unitId);
53147
53383
  } catch {
53148
53384
  throw new import_node_server_utils221.BadRequestError("Invalid unitId id format");
53149
53385
  }
53150
53386
  }
53151
53387
  if (value.paidBy && typeof value.paidBy === "string") {
53152
53388
  try {
53153
- value.paidBy = new import_mongodb128.ObjectId(value.paidBy);
53389
+ value.paidBy = new import_mongodb129.ObjectId(value.paidBy);
53154
53390
  } catch {
53155
53391
  throw new import_node_server_utils221.BadRequestError("Invalid paidBy id format");
53156
53392
  }
@@ -53160,7 +53396,7 @@ function MBillingItems(value) {
53160
53396
  value.unitBillingItems = value.unitBillingItems.map((unitBillingItem) => {
53161
53397
  if (typeof unitBillingItem._id === "string") {
53162
53398
  try {
53163
- unitBillingItem._id = new import_mongodb128.ObjectId(unitBillingItem._id);
53399
+ unitBillingItem._id = new import_mongodb129.ObjectId(unitBillingItem._id);
53164
53400
  } catch {
53165
53401
  throw new import_node_server_utils221.BadRequestError("Invalid unit billing id format");
53166
53402
  }
@@ -53172,7 +53408,7 @@ function MBillingItems(value) {
53172
53408
  }
53173
53409
  }
53174
53410
  return {
53175
- _id: value._id ?? new import_mongodb128.ObjectId(),
53411
+ _id: value._id ?? new import_mongodb129.ObjectId(),
53176
53412
  unitBillingItems: value.unitBillingItems ?? [],
53177
53413
  unitId: value.unitId ?? "",
53178
53414
  unitOwner: value.unitOwner ?? "",
@@ -53240,7 +53476,7 @@ var useRedDotPaymentRepo = () => {
53240
53476
  const res = await paymentCollection().insertOne(payload, { session });
53241
53477
  const unit = payload.unitId?.toString().slice(-4);
53242
53478
  const dateFormatted = formatDateString(/* @__PURE__ */ new Date());
53243
- const newId = new import_mongodb129.ObjectId(res.insertedId).toString().slice(-6);
53479
+ const newId = new import_mongodb130.ObjectId(res.insertedId).toString().slice(-6);
53244
53480
  const referenceNumber = `${unit}${newId}${dateFormatted}`;
53245
53481
  await paymentCollection().updateOne(
53246
53482
  { _id: res.insertedId },
@@ -54340,7 +54576,7 @@ var import_node_server_utils228 = require("@7365admin1/node-server-utils");
54340
54576
  var import_uuid2 = require("uuid");
54341
54577
 
54342
54578
  // src/repositories/user-v2.repo.ts
54343
- var import_mongodb130 = require("mongodb");
54579
+ var import_mongodb131 = require("mongodb");
54344
54580
  var import_node_server_utils227 = require("@7365admin1/node-server-utils");
54345
54581
  function useUserRepoV2() {
54346
54582
  const { updateFeedbackCreatedByName } = useFeedbackRepo();
@@ -54541,7 +54777,7 @@ function useUserRepoV2() {
54541
54777
  }
54542
54778
  if (organization) {
54543
54779
  try {
54544
- query.defaultOrg = new import_mongodb130.ObjectId(organization);
54780
+ query.defaultOrg = new import_mongodb131.ObjectId(organization);
54545
54781
  cacheOptions.organization = organization.toString();
54546
54782
  } catch (error) {
54547
54783
  throw new import_node_server_utils227.BadRequestError("Invalid organization ID format.");
@@ -54680,13 +54916,13 @@ function useUserRepoV2() {
54680
54916
  );
54681
54917
  }
54682
54918
  try {
54683
- _id = new import_mongodb130.ObjectId(_id);
54919
+ _id = new import_mongodb131.ObjectId(_id);
54684
54920
  } catch (error) {
54685
54921
  throw new import_node_server_utils227.BadRequestError("Invalid ID.");
54686
54922
  }
54687
54923
  if (field === "defaultOrg") {
54688
54924
  try {
54689
- value = new import_mongodb130.ObjectId(value);
54925
+ value = new import_mongodb131.ObjectId(value);
54690
54926
  } catch (error) {
54691
54927
  throw new import_node_server_utils227.BadRequestError("Invalid organization ID.");
54692
54928
  }
@@ -54727,7 +54963,7 @@ function useUserRepoV2() {
54727
54963
  year
54728
54964
  }, session) {
54729
54965
  try {
54730
- _id = new import_mongodb130.ObjectId(_id);
54966
+ _id = new import_mongodb131.ObjectId(_id);
54731
54967
  } catch (error) {
54732
54968
  throw new import_node_server_utils227.BadRequestError("Invalid user ID format.");
54733
54969
  }
@@ -54757,7 +54993,7 @@ function useUserRepoV2() {
54757
54993
  }
54758
54994
  async function updatePassword({ _id, password }, session) {
54759
54995
  try {
54760
- _id = new import_mongodb130.ObjectId(_id);
54996
+ _id = new import_mongodb131.ObjectId(_id);
54761
54997
  } catch (error) {
54762
54998
  throw new import_node_server_utils227.BadRequestError("Invalid user ID format.");
54763
54999
  }
@@ -55512,38 +55748,38 @@ function useUserControllerV2() {
55512
55748
 
55513
55749
  // src/models/role-v2.model.ts
55514
55750
  var import_node_server_utils232 = require("@7365admin1/node-server-utils");
55515
- var import_mongodb131 = require("mongodb");
55751
+ var import_mongodb132 = require("mongodb");
55516
55752
  var MRoleV2 = class {
55517
55753
  constructor(value) {
55518
55754
  if (typeof value._id === "string") {
55519
55755
  try {
55520
- value._id = new import_mongodb131.ObjectId(value._id);
55756
+ value._id = new import_mongodb132.ObjectId(value._id);
55521
55757
  } catch (error) {
55522
55758
  throw new import_node_server_utils232.BadRequestError("Invalid role-v2 ID format.");
55523
55759
  }
55524
55760
  }
55525
55761
  if (typeof value.site === "string" && value.site.length === 24) {
55526
55762
  try {
55527
- value.site = new import_mongodb131.ObjectId(value.site);
55763
+ value.site = new import_mongodb132.ObjectId(value.site);
55528
55764
  } catch (error) {
55529
55765
  throw new import_node_server_utils232.BadRequestError("Invalid site ID format.");
55530
55766
  }
55531
55767
  }
55532
55768
  if (typeof value.org === "string" && value.org.length === 24) {
55533
55769
  try {
55534
- value.org = new import_mongodb131.ObjectId(value.org);
55770
+ value.org = new import_mongodb132.ObjectId(value.org);
55535
55771
  } catch (error) {
55536
55772
  throw new import_node_server_utils232.BadRequestError("Invalid org ID format.");
55537
55773
  }
55538
55774
  }
55539
55775
  if (value.createdBy) {
55540
55776
  try {
55541
- value.createdBy = new import_mongodb131.ObjectId(value.createdBy);
55777
+ value.createdBy = new import_mongodb132.ObjectId(value.createdBy);
55542
55778
  } catch (error) {
55543
55779
  throw new import_node_server_utils232.BadRequestError("Invalid created by ID format.");
55544
55780
  }
55545
55781
  }
55546
- this._id = value._id ?? new import_mongodb131.ObjectId();
55782
+ this._id = value._id ?? new import_mongodb132.ObjectId();
55547
55783
  this.name = value.name ?? "";
55548
55784
  this.permissions = value.permissions ?? [];
55549
55785
  this.site = value.site ?? "";
@@ -55678,7 +55914,7 @@ function useRoleControllerV2() {
55678
55914
 
55679
55915
  // src/models/post-preloved.model.ts
55680
55916
  var import_joi133 = __toESM(require("joi"));
55681
- var import_mongodb132 = require("mongodb");
55917
+ var import_mongodb133 = require("mongodb");
55682
55918
  var PostStatus = /* @__PURE__ */ ((PostStatus2) => {
55683
55919
  PostStatus2["PUBLISHED"] = "published";
55684
55920
  PostStatus2["RESERVED"] = "reserved";
@@ -55734,28 +55970,28 @@ function MPost(value) {
55734
55970
  }
55735
55971
  if (value._id && typeof value._id === "string") {
55736
55972
  try {
55737
- value._id = new import_mongodb132.ObjectId(value._id);
55973
+ value._id = new import_mongodb133.ObjectId(value._id);
55738
55974
  } catch {
55739
55975
  throw new Error("Invalid ID.");
55740
55976
  }
55741
55977
  }
55742
55978
  if (value.site && typeof value.site === "string") {
55743
55979
  try {
55744
- value.site = new import_mongodb132.ObjectId(value.site);
55980
+ value.site = new import_mongodb133.ObjectId(value.site);
55745
55981
  } catch {
55746
55982
  throw new Error("Invalid site ID.");
55747
55983
  }
55748
55984
  }
55749
55985
  if (value.createdBy && typeof value.createdBy === "string") {
55750
55986
  try {
55751
- value.createdBy = new import_mongodb132.ObjectId(value.createdBy);
55987
+ value.createdBy = new import_mongodb133.ObjectId(value.createdBy);
55752
55988
  } catch {
55753
55989
  throw new Error("Invalid createdBy ID.");
55754
55990
  }
55755
55991
  }
55756
55992
  if (value.reserverId && typeof value.reserverId === "string") {
55757
55993
  try {
55758
- value.reserverId = new import_mongodb132.ObjectId(value.reserverId);
55994
+ value.reserverId = new import_mongodb133.ObjectId(value.reserverId);
55759
55995
  } catch {
55760
55996
  throw new Error("Invalid reserver ID.");
55761
55997
  }
@@ -55764,7 +56000,7 @@ function MPost(value) {
55764
56000
  value.attachments = value.attachments.map((id) => {
55765
56001
  if (typeof id === "string") {
55766
56002
  try {
55767
- return new import_mongodb132.ObjectId(id);
56003
+ return new import_mongodb133.ObjectId(id);
55768
56004
  } catch {
55769
56005
  throw new Error("Invalid attachment ID.");
55770
56006
  }
@@ -55774,20 +56010,20 @@ function MPost(value) {
55774
56010
  }
55775
56011
  if (value.category && typeof value.category === "string") {
55776
56012
  try {
55777
- value.category = new import_mongodb132.ObjectId(value.category);
56013
+ value.category = new import_mongodb133.ObjectId(value.category);
55778
56014
  } catch {
55779
56015
  throw new Error("Invalid category ID.");
55780
56016
  }
55781
56017
  }
55782
56018
  if (value.subcategory && typeof value.subcategory === "string") {
55783
56019
  try {
55784
- value.subcategory = new import_mongodb132.ObjectId(value.subcategory);
56020
+ value.subcategory = new import_mongodb133.ObjectId(value.subcategory);
55785
56021
  } catch {
55786
56022
  throw new Error("Invalid subcategory ID.");
55787
56023
  }
55788
56024
  }
55789
56025
  return {
55790
- _id: value._id ?? new import_mongodb132.ObjectId(),
56026
+ _id: value._id ?? new import_mongodb133.ObjectId(),
55791
56027
  title: value.title ?? "",
55792
56028
  description: value.description ?? "",
55793
56029
  attachments: value.attachments ?? [],
@@ -55807,7 +56043,7 @@ function MPost(value) {
55807
56043
 
55808
56044
  // src/repositories/post-preloved.repo.ts
55809
56045
  var import_node_server_utils235 = require("@7365admin1/node-server-utils");
55810
- var import_mongodb133 = require("mongodb");
56046
+ var import_mongodb134 = require("mongodb");
55811
56047
  function usePostPrelovedRepo() {
55812
56048
  const db = import_node_server_utils235.useAtlas.getDb();
55813
56049
  if (!db) {
@@ -55869,18 +56105,62 @@ function usePostPrelovedRepo() {
55869
56105
  throw error;
55870
56106
  }
55871
56107
  }
55872
- async function getById(_id) {
56108
+ async function getById(_id, userId) {
55873
56109
  try {
55874
- _id = new import_mongodb133.ObjectId(_id);
56110
+ _id = new import_mongodb134.ObjectId(_id);
55875
56111
  } catch {
55876
56112
  throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
55877
56113
  }
56114
+ let userObjectId = null;
56115
+ if (userId) {
56116
+ try {
56117
+ userObjectId = new import_mongodb134.ObjectId(userId);
56118
+ } catch {
56119
+ throw new import_node_server_utils235.BadRequestError("Invalid user ID format.");
56120
+ }
56121
+ }
56122
+ const favoriteUserIds = {
56123
+ $ifNull: [{ $arrayElemAt: ["$favoriteData.userIds", 0] }, []]
56124
+ };
55878
56125
  try {
55879
56126
  const result = await collection.aggregate([
55880
56127
  { $match: { _id, status: { $ne: "deleted" /* DELETED */ } } },
55881
56128
  USER_LOOKUP,
55882
56129
  USER_UNWIND,
55883
- CATEGORY_LOOKUP
56130
+ {
56131
+ $lookup: {
56132
+ from: "category-preloved",
56133
+ localField: "category",
56134
+ foreignField: "_id",
56135
+ pipeline: [{ $project: { name: 1 } }],
56136
+ as: "category"
56137
+ }
56138
+ },
56139
+ {
56140
+ $lookup: {
56141
+ from: "subcategory-preloved",
56142
+ localField: "subcategory",
56143
+ foreignField: "_id",
56144
+ pipeline: [{ $project: { name: 1 } }],
56145
+ as: "subcategory"
56146
+ }
56147
+ },
56148
+ {
56149
+ $lookup: {
56150
+ from: "post-favorites",
56151
+ localField: "_id",
56152
+ foreignField: "postId",
56153
+ pipeline: [{ $project: { userIds: 1 } }],
56154
+ as: "favoriteData"
56155
+ }
56156
+ },
56157
+ {
56158
+ $addFields: {
56159
+ favoriteCount: { $size: favoriteUserIds },
56160
+ isFavorited: userObjectId ? { $in: [userObjectId, favoriteUserIds] } : false
56161
+ }
56162
+ },
56163
+ { $unset: "favoriteData" }
55884
56164
  ]).toArray();
55885
56165
  const data = result[0] ?? null;
55886
56166
  if (!data)
@@ -55904,7 +56184,7 @@ function usePostPrelovedRepo() {
55904
56184
  page = page > 0 ? page - 1 : 0;
55905
56185
  if (site) {
55906
56186
  try {
55907
- site = new import_mongodb133.ObjectId(site);
56187
+ site = new import_mongodb134.ObjectId(site);
55908
56188
  } catch {
55909
56189
  throw new import_node_server_utils235.BadRequestError("Invalid site ID format.");
55910
56190
  }
@@ -55913,14 +56193,14 @@ function usePostPrelovedRepo() {
55913
56193
  let subcategoryIds = null;
55914
56194
  if (category && subcategory) {
55915
56195
  try {
55916
- categoryId = new import_mongodb133.ObjectId(category);
56196
+ categoryId = new import_mongodb134.ObjectId(category);
55917
56197
  } catch {
55918
56198
  throw new import_node_server_utils235.BadRequestError("Invalid category ID format.");
55919
56199
  }
55920
56200
  if (subcategory.length > 0) {
55921
56201
  subcategoryIds = subcategory.map((id) => {
55922
56202
  try {
55923
- return new import_mongodb133.ObjectId(id);
56203
+ return new import_mongodb134.ObjectId(id);
55924
56204
  } catch {
55925
56205
  throw new import_node_server_utils235.BadRequestError("Invalid subcategory ID format.");
55926
56206
  }
@@ -55945,7 +56225,7 @@ function usePostPrelovedRepo() {
55945
56225
  let userObjectId = null;
55946
56226
  if (userId) {
55947
56227
  try {
55948
- userObjectId = new import_mongodb133.ObjectId(userId);
56228
+ userObjectId = new import_mongodb134.ObjectId(userId);
55949
56229
  } catch {
55950
56230
  throw new import_node_server_utils235.BadRequestError("Invalid user ID format.");
55951
56231
  }
@@ -55994,7 +56274,7 @@ function usePostPrelovedRepo() {
55994
56274
  }
55995
56275
  async function updateById(_id, value, session) {
55996
56276
  try {
55997
- _id = new import_mongodb133.ObjectId(_id);
56277
+ _id = new import_mongodb134.ObjectId(_id);
55998
56278
  } catch {
55999
56279
  throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
56000
56280
  }
@@ -56015,7 +56295,7 @@ function usePostPrelovedRepo() {
56015
56295
  }
56016
56296
  async function deleteById(_id, session) {
56017
56297
  try {
56018
- _id = new import_mongodb133.ObjectId(_id);
56298
+ _id = new import_mongodb134.ObjectId(_id);
56019
56299
  } catch {
56020
56300
  throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
56021
56301
  }
@@ -56041,7 +56321,7 @@ function usePostPrelovedRepo() {
56041
56321
  }
56042
56322
  async function updateStatus(_id, status, session) {
56043
56323
  try {
56044
- _id = new import_mongodb133.ObjectId(_id);
56324
+ _id = new import_mongodb134.ObjectId(_id);
56045
56325
  } catch {
56046
56326
  throw new import_node_server_utils235.BadRequestError("Invalid post ID format.");
56047
56327
  }
@@ -56069,11 +56349,181 @@ function usePostPrelovedRepo() {
56069
56349
  }
56070
56350
 
56071
56351
  // src/controllers/post-preloved.controller.ts
56352
+ var import_node_server_utils238 = require("@7365admin1/node-server-utils");
56353
+ var import_joi135 = __toESM(require("joi"));
56354
+
56355
+ // src/services/post-preloved.service.ts
56356
+ var import_node_server_utils237 = require("@7365admin1/node-server-utils");
56357
+
56358
+ // src/repositories/post-favorite.repo.ts
56072
56359
  var import_node_server_utils236 = require("@7365admin1/node-server-utils");
56360
+ var import_mongodb136 = require("mongodb");
56361
+
56362
+ // src/models/post-favorite.model.ts
56073
56363
  var import_joi134 = __toESM(require("joi"));
56364
+ var import_mongodb135 = require("mongodb");
56365
+ var schemaUpdatePostFavorite = import_joi134.default.object({
56366
+ userId: import_joi134.default.string().hex().length(24).required()
56367
+ });
56368
+ var schemaPostFavorite = import_joi134.default.object({
56369
+ _id: import_joi134.default.string().hex().optional().allow("", null),
56370
+ postId: import_joi134.default.string().hex().required(),
56371
+ userIds: import_joi134.default.array().items(import_joi134.default.string().hex().optional()).optional().allow(null),
56372
+ createdAt: import_joi134.default.date().optional().allow(null),
56373
+ updatedAt: import_joi134.default.date().optional().allow(null)
56374
+ });
56375
+ function MPostFavorite(value) {
56376
+ const { error } = schemaPostFavorite.validate(value);
56377
+ if (error) {
56378
+ throw new Error(error.details[0].message);
56379
+ }
56380
+ if (value._id && typeof value._id === "string") {
56381
+ try {
56382
+ value._id = new import_mongodb135.ObjectId(value._id);
56383
+ } catch {
56384
+ throw new Error("Invalid ID.");
56385
+ }
56386
+ }
56387
+ if (value.postId && typeof value.postId === "string") {
56388
+ try {
56389
+ value.postId = new import_mongodb135.ObjectId(value.postId);
56390
+ } catch {
56391
+ throw new Error("Invalid post ID.");
56392
+ }
56393
+ }
56394
+ if (value.userIds && Array.isArray(value.userIds)) {
56395
+ value.userIds = value.userIds.map((id) => {
56396
+ if (typeof id === "string") {
56397
+ try {
56398
+ return new import_mongodb135.ObjectId(id);
56399
+ } catch {
56400
+ throw new Error("Invalid user ID.");
56401
+ }
56402
+ }
56403
+ return id;
56404
+ });
56405
+ }
56406
+ return {
56407
+ _id: value._id ?? new import_mongodb135.ObjectId(),
56408
+ postId: value.postId ?? "",
56409
+ userIds: value.userIds ?? [],
56410
+ createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
56411
+ updatedAt: value.updatedAt ?? null
56412
+ };
56413
+ }
56414
+
56415
+ // src/repositories/post-favorite.repo.ts
56416
+ function usePostFavoriteRepo() {
56417
+ const db = import_node_server_utils236.useAtlas.getDb();
56418
+ if (!db) {
56419
+ throw new import_node_server_utils236.InternalServerError("Unable to connect to server.");
56420
+ }
56421
+ const FAVORITE_COLLECTION = "post-favorites";
56422
+ const collection = db.collection(FAVORITE_COLLECTION);
56423
+ async function addFavorite(value, session) {
56424
+ try {
56425
+ const doc = MPostFavorite(value);
56426
+ const res = await collection.insertOne(doc, { session });
56427
+ return res.insertedId;
56428
+ } catch (error) {
56429
+ const isDuplicated = error.message?.includes("duplicate");
56430
+ if (isDuplicated)
56431
+ throw new import_node_server_utils236.BadRequestError("Post Favorite already exists.");
56432
+ throw error;
56433
+ }
56434
+ }
56435
+ async function getById(_id) {
56436
+ try {
56437
+ _id = new import_mongodb136.ObjectId(_id);
56438
+ } catch {
56439
+ throw new import_node_server_utils236.BadRequestError("Invalid favorite ID format.");
56440
+ }
56441
+ const result = await collection.findOne({ _id });
56442
+ if (!result)
56443
+ throw new import_node_server_utils236.NotFoundError("Favorite not found.");
56444
+ return result;
56445
+ }
56446
+ async function getByPostId(postId) {
56447
+ try {
56448
+ postId = new import_mongodb136.ObjectId(postId);
56449
+ } catch {
56450
+ throw new import_node_server_utils236.BadRequestError("Invalid post ID format.");
56451
+ }
56452
+ const result = await collection.findOne({ postId });
56453
+ if (!result)
56454
+ throw new import_node_server_utils236.NotFoundError("Favorite not found.");
56455
+ return result;
56456
+ }
56457
+ async function updateById(_id, userId, session) {
56458
+ try {
56459
+ _id = new import_mongodb136.ObjectId(_id);
56460
+ } catch {
56461
+ throw new import_node_server_utils236.BadRequestError("Invalid favorite ID format.");
56462
+ }
56463
+ let userObjectId;
56464
+ try {
56465
+ userObjectId = new import_mongodb136.ObjectId(userId);
56466
+ } catch {
56467
+ throw new import_node_server_utils236.BadRequestError("Invalid user ID format.");
56468
+ }
56469
+ const existing = await collection.findOne(
56470
+ { postId: _id, userIds: userObjectId },
56471
+ { session }
56472
+ );
56473
+ const update = existing ? {
56474
+ $pull: { userIds: userObjectId },
56475
+ $set: { updatedAt: (/* @__PURE__ */ new Date()).toISOString() }
56476
+ } : {
56477
+ $addToSet: { userIds: userObjectId },
56478
+ $set: { updatedAt: (/* @__PURE__ */ new Date()).toISOString() }
56479
+ };
56480
+ const res = await collection.updateOne({ postId: _id }, update, {
56481
+ session
56482
+ });
56483
+ if (res.modifiedCount === 0)
56484
+ throw new import_node_server_utils236.InternalServerError("Unable to update favorite.");
56485
+ return existing ? "removed" : "added";
56486
+ }
56487
+ return {
56488
+ addFavorite,
56489
+ getById,
56490
+ getByPostId,
56491
+ updateById
56492
+ };
56493
+ }
56494
+
56495
+ // src/services/post-preloved.service.ts
56496
+ function usePostFavoriteService() {
56497
+ const { add: _addPost } = usePostPrelovedRepo();
56498
+ const { addFavorite: _addFavorite } = usePostFavoriteRepo();
56499
+ async function add(value) {
56500
+ const session = import_node_server_utils237.useAtlas.getClient()?.startSession();
56501
+ session?.startTransaction();
56502
+ try {
56503
+ const post = await _addPost(value, session);
56504
+ const payload = {
56505
+ postId: post.toString(),
56506
+ userIds: []
56507
+ };
56508
+ await _addFavorite(payload, session);
56509
+ await session?.commitTransaction();
56510
+ return "Successfully added to favorites.";
56511
+ } catch (error) {
56512
+ await session?.abortTransaction();
56513
+ throw error;
56514
+ } finally {
56515
+ session?.endSession();
56516
+ }
56517
+ }
56518
+ return {
56519
+ add
56520
+ };
56521
+ }
56522
+
56523
+ // src/controllers/post-preloved.controller.ts
56074
56524
  function usePostPrelovedController() {
56525
+ const { add: _add } = usePostFavoriteService();
56075
56526
  const {
56076
- add: _add,
56077
56527
  getById: _getById,
56078
56528
  getAll: _getAll,
56079
56529
  updateById: _updateById,
@@ -56086,8 +56536,8 @@ function usePostPrelovedController() {
56086
56536
  });
56087
56537
  if (error) {
56088
56538
  const messages = error.details.map((d) => d.message).join(", ");
56089
- import_node_server_utils236.logger.log({ level: "error", message: messages });
56090
- next(new import_node_server_utils236.BadRequestError(messages));
56539
+ import_node_server_utils238.logger.log({ level: "error", message: messages });
56540
+ next(new import_node_server_utils238.BadRequestError(messages));
56091
56541
  return;
56092
56542
  }
56093
56543
  try {
@@ -56095,53 +56545,57 @@ function usePostPrelovedController() {
56095
56545
  res.status(201).json(data);
56096
56546
  return;
56097
56547
  } catch (error2) {
56098
- import_node_server_utils236.logger.log({ level: "error", message: error2.message });
56548
+ import_node_server_utils238.logger.log({ level: "error", message: error2.message });
56099
56549
  next(error2);
56100
56550
  return;
56101
56551
  }
56102
56552
  }
56103
56553
  async function getById(req, res, next) {
56104
- const schema2 = import_joi134.default.object({
56105
- _id: import_joi134.default.string().hex().length(24).required()
56554
+ const schema2 = import_joi135.default.object({
56555
+ _id: import_joi135.default.string().hex().length(24).required(),
56556
+ userId: import_joi135.default.string().hex().length(24).optional().allow("", null)
56557
+ });
56558
+ const { error, value } = schema2.validate({
56559
+ _id: req.params.id,
56560
+ userId: req.query.userId
56106
56561
  });
56107
- const { error, value } = schema2.validate({ _id: req.params.id });
56108
56562
  if (error) {
56109
- import_node_server_utils236.logger.log({ level: "error", message: error.message });
56110
- next(new import_node_server_utils236.BadRequestError(error.message));
56563
+ import_node_server_utils238.logger.log({ level: "error", message: error.message });
56564
+ next(new import_node_server_utils238.BadRequestError(error.message));
56111
56565
  return;
56112
56566
  }
56113
56567
  try {
56114
- const data = await _getById(value._id);
56568
+ const data = await _getById(value._id, value.userId);
56115
56569
  res.status(200).json(data);
56116
56570
  return;
56117
56571
  } catch (error2) {
56118
- import_node_server_utils236.logger.log({ level: "error", message: error2.message });
56572
+ import_node_server_utils238.logger.log({ level: "error", message: error2.message });
56119
56573
  next(error2);
56120
56574
  return;
56121
56575
  }
56122
56576
  }
56123
56577
  async function getAll(req, res, next) {
56124
- const validation = import_joi134.default.object({
56125
- page: import_joi134.default.number().integer().min(1).allow("", null).default(1),
56126
- limit: import_joi134.default.number().integer().min(1).max(100).allow("", null).default(10),
56127
- search: import_joi134.default.string().optional().allow("", null),
56128
- filter: import_joi134.default.string().valid("recent", "price-low-high", "price-high-low").optional().allow("", null),
56129
- site: import_joi134.default.string().hex().length(24).optional().allow("", null),
56130
- status: import_joi134.default.alternatives().try(
56131
- import_joi134.default.array().items(import_joi134.default.string().valid(...Object.values(PostStatus))),
56132
- import_joi134.default.string().valid(...Object.values(PostStatus))
56578
+ const validation = import_joi135.default.object({
56579
+ page: import_joi135.default.number().integer().min(1).allow("", null).default(1),
56580
+ limit: import_joi135.default.number().integer().min(1).max(100).allow("", null).default(10),
56581
+ search: import_joi135.default.string().optional().allow("", null),
56582
+ filter: import_joi135.default.string().valid("recent", "price-low-high", "price-high-low").optional().allow("", null),
56583
+ site: import_joi135.default.string().hex().length(24).optional().allow("", null),
56584
+ status: import_joi135.default.alternatives().try(
56585
+ import_joi135.default.array().items(import_joi135.default.string().valid(...Object.values(PostStatus))),
56586
+ import_joi135.default.string().valid(...Object.values(PostStatus))
56133
56587
  ).optional().allow(null),
56134
- category: import_joi134.default.string().hex().length(24).optional().allow("", null),
56135
- subcategory: import_joi134.default.array().items(import_joi134.default.string()).single().optional().allow(null),
56136
- userId: import_joi134.default.string().optional().allow("", null)
56588
+ category: import_joi135.default.string().hex().length(24).optional().allow("", null),
56589
+ subcategory: import_joi135.default.array().items(import_joi135.default.string()).single().optional().allow(null),
56590
+ userId: import_joi135.default.string().optional().allow("", null)
56137
56591
  });
56138
56592
  const { error, value } = validation.validate(req.query, {
56139
56593
  abortEarly: false
56140
56594
  });
56141
56595
  if (error) {
56142
56596
  const messages = error.details.map((d) => d.message).join(", ");
56143
- import_node_server_utils236.logger.log({ level: "error", message: messages });
56144
- next(new import_node_server_utils236.BadRequestError(messages));
56597
+ import_node_server_utils238.logger.log({ level: "error", message: messages });
56598
+ next(new import_node_server_utils238.BadRequestError(messages));
56145
56599
  return;
56146
56600
  }
56147
56601
  const {
@@ -56170,7 +56624,7 @@ function usePostPrelovedController() {
56170
56624
  res.status(200).json(data);
56171
56625
  return;
56172
56626
  } catch (error2) {
56173
- import_node_server_utils236.logger.log({ level: "error", message: error2.message });
56627
+ import_node_server_utils238.logger.log({ level: "error", message: error2.message });
56174
56628
  next(error2);
56175
56629
  return;
56176
56630
  }
@@ -56183,8 +56637,8 @@ function usePostPrelovedController() {
56183
56637
  });
56184
56638
  if (error) {
56185
56639
  const messages = error.details.map((d) => d.message).join(", ");
56186
- import_node_server_utils236.logger.log({ level: "error", message: messages });
56187
- next(new import_node_server_utils236.BadRequestError(messages));
56640
+ import_node_server_utils238.logger.log({ level: "error", message: messages });
56641
+ next(new import_node_server_utils238.BadRequestError(messages));
56188
56642
  return;
56189
56643
  }
56190
56644
  try {
@@ -56192,19 +56646,19 @@ function usePostPrelovedController() {
56192
56646
  res.status(200).json(data);
56193
56647
  return;
56194
56648
  } catch (error2) {
56195
- import_node_server_utils236.logger.log({ level: "error", message: error2.message });
56649
+ import_node_server_utils238.logger.log({ level: "error", message: error2.message });
56196
56650
  next(error2);
56197
56651
  return;
56198
56652
  }
56199
56653
  }
56200
56654
  async function deleteById(req, res, next) {
56201
- const schema2 = import_joi134.default.object({
56202
- _id: import_joi134.default.string().hex().length(24).required()
56655
+ const schema2 = import_joi135.default.object({
56656
+ _id: import_joi135.default.string().hex().length(24).required()
56203
56657
  });
56204
56658
  const { error, value } = schema2.validate({ _id: req.params.id });
56205
56659
  if (error) {
56206
- import_node_server_utils236.logger.log({ level: "error", message: error.message });
56207
- next(new import_node_server_utils236.BadRequestError(error.message));
56660
+ import_node_server_utils238.logger.log({ level: "error", message: error.message });
56661
+ next(new import_node_server_utils238.BadRequestError(error.message));
56208
56662
  return;
56209
56663
  }
56210
56664
  try {
@@ -56212,23 +56666,23 @@ function usePostPrelovedController() {
56212
56666
  res.status(200).json({ message: "Successfully deleted post." });
56213
56667
  return;
56214
56668
  } catch (error2) {
56215
- import_node_server_utils236.logger.log({ level: "error", message: error2.message });
56669
+ import_node_server_utils238.logger.log({ level: "error", message: error2.message });
56216
56670
  next(error2);
56217
56671
  return;
56218
56672
  }
56219
56673
  }
56220
56674
  async function updateStatus(req, res, next) {
56221
- const schema2 = import_joi134.default.object({
56222
- _id: import_joi134.default.string().hex().length(24).required(),
56223
- status: import_joi134.default.string().valid(...Object.values(PostStatus)).required()
56675
+ const schema2 = import_joi135.default.object({
56676
+ _id: import_joi135.default.string().hex().length(24).required(),
56677
+ status: import_joi135.default.string().valid(...Object.values(PostStatus)).required()
56224
56678
  });
56225
56679
  const { error, value } = schema2.validate({
56226
56680
  _id: req.params.id,
56227
56681
  status: req.body.status
56228
56682
  });
56229
56683
  if (error) {
56230
- import_node_server_utils236.logger.log({ level: "error", message: error.message });
56231
- next(new import_node_server_utils236.BadRequestError(error.message));
56684
+ import_node_server_utils238.logger.log({ level: "error", message: error.message });
56685
+ next(new import_node_server_utils238.BadRequestError(error.message));
56232
56686
  return;
56233
56687
  }
56234
56688
  try {
@@ -56236,7 +56690,7 @@ function usePostPrelovedController() {
56236
56690
  res.status(200).json(data);
56237
56691
  return;
56238
56692
  } catch (error2) {
56239
- import_node_server_utils236.logger.log({ level: "error", message: error2.message });
56693
+ import_node_server_utils238.logger.log({ level: "error", message: error2.message });
56240
56694
  next(error2);
56241
56695
  return;
56242
56696
  }
@@ -56251,139 +56705,12 @@ function usePostPrelovedController() {
56251
56705
  };
56252
56706
  }
56253
56707
 
56254
- // src/models/post-favorite.model.ts
56255
- var import_joi135 = __toESM(require("joi"));
56256
- var import_mongodb134 = require("mongodb");
56257
- var schemaUpdatePostFavorite = import_joi135.default.object({
56258
- userId: import_joi135.default.string().hex().length(24).required()
56259
- });
56260
- var schemaPostFavorite = import_joi135.default.object({
56261
- _id: import_joi135.default.string().hex().optional().allow("", null),
56262
- postId: import_joi135.default.string().hex().required(),
56263
- userIds: import_joi135.default.array().items(import_joi135.default.string().hex().optional()).optional().allow(null),
56264
- createdAt: import_joi135.default.date().optional().allow(null),
56265
- updatedAt: import_joi135.default.date().optional().allow(null)
56266
- });
56267
- function MPostFavorite(value) {
56268
- const { error } = schemaPostFavorite.validate(value);
56269
- if (error) {
56270
- throw new Error(error.details[0].message);
56271
- }
56272
- if (value._id && typeof value._id === "string") {
56273
- try {
56274
- value._id = new import_mongodb134.ObjectId(value._id);
56275
- } catch {
56276
- throw new Error("Invalid ID.");
56277
- }
56278
- }
56279
- if (value.postId && typeof value.postId === "string") {
56280
- try {
56281
- value.postId = new import_mongodb134.ObjectId(value.postId);
56282
- } catch {
56283
- throw new Error("Invalid post ID.");
56284
- }
56285
- }
56286
- if (value.userIds && Array.isArray(value.userIds)) {
56287
- value.userIds = value.userIds.map((id) => {
56288
- if (typeof id === "string") {
56289
- try {
56290
- return new import_mongodb134.ObjectId(id);
56291
- } catch {
56292
- throw new Error("Invalid user ID.");
56293
- }
56294
- }
56295
- return id;
56296
- });
56297
- }
56298
- return {
56299
- _id: value._id ?? new import_mongodb134.ObjectId(),
56300
- postId: value.postId ?? "",
56301
- userIds: value.userIds ?? [],
56302
- createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
56303
- updatedAt: value.updatedAt ?? null
56304
- };
56305
- }
56306
-
56307
- // src/repositories/post-favorite.repo.ts
56308
- var import_node_server_utils237 = require("@7365admin1/node-server-utils");
56309
- var import_mongodb135 = require("mongodb");
56310
- function usePostFavoriteRepo() {
56311
- const db = import_node_server_utils237.useAtlas.getDb();
56312
- if (!db) {
56313
- throw new import_node_server_utils237.InternalServerError("Unable to connect to server.");
56314
- }
56315
- const FAVORITE_COLLECTION = "post-favorites";
56316
- const collection = db.collection(FAVORITE_COLLECTION);
56317
- async function addFavorite(value, session) {
56318
- try {
56319
- const doc = MPostFavorite(value);
56320
- const res = await collection.insertOne(doc, { session });
56321
- return res.insertedId;
56322
- } catch (error) {
56323
- const isDuplicated = error.message?.includes("duplicate");
56324
- if (isDuplicated)
56325
- throw new import_node_server_utils237.BadRequestError("Post Favorite already exists.");
56326
- throw error;
56327
- }
56328
- }
56329
- async function getById(_id) {
56330
- try {
56331
- _id = new import_mongodb135.ObjectId(_id);
56332
- } catch {
56333
- throw new import_node_server_utils237.BadRequestError("Invalid favorite ID format.");
56334
- }
56335
- const result = await collection.findOne({ _id });
56336
- if (!result)
56337
- throw new import_node_server_utils237.NotFoundError("Favorite not found.");
56338
- return result;
56339
- }
56340
- async function getByPostId(postId) {
56341
- try {
56342
- postId = new import_mongodb135.ObjectId(postId);
56343
- } catch {
56344
- throw new import_node_server_utils237.BadRequestError("Invalid post ID format.");
56345
- }
56346
- const result = await collection.findOne({ postId });
56347
- if (!result)
56348
- throw new import_node_server_utils237.NotFoundError("Favorite not found.");
56349
- return result;
56350
- }
56351
- async function updateById(_id, userId, session) {
56352
- try {
56353
- _id = new import_mongodb135.ObjectId(_id);
56354
- } catch {
56355
- throw new import_node_server_utils237.BadRequestError("Invalid favorite ID format.");
56356
- }
56357
- let userObjectId;
56358
- try {
56359
- userObjectId = new import_mongodb135.ObjectId(userId);
56360
- } catch {
56361
- throw new import_node_server_utils237.BadRequestError("Invalid user ID format.");
56362
- }
56363
- const existing = await collection.findOne(
56364
- { _id, userIds: userObjectId },
56365
- { session }
56366
- );
56367
- const update = existing ? { $pull: { userIds: userObjectId }, $set: { updatedAt: (/* @__PURE__ */ new Date()).toISOString() } } : { $addToSet: { userIds: userObjectId }, $set: { updatedAt: (/* @__PURE__ */ new Date()).toISOString() } };
56368
- const res = await collection.updateOne({ _id }, update, { session });
56369
- if (res.modifiedCount === 0)
56370
- throw new import_node_server_utils237.InternalServerError("Unable to update favorite.");
56371
- return existing ? "removed" : "added";
56372
- }
56373
- return {
56374
- addFavorite,
56375
- getById,
56376
- getByPostId,
56377
- updateById
56378
- };
56379
- }
56380
-
56381
56708
  // src/services/post-favorite.service.ts
56382
- var import_node_server_utils238 = require("@7365admin1/node-server-utils");
56383
- function usePostFavoriteService() {
56709
+ var import_node_server_utils239 = require("@7365admin1/node-server-utils");
56710
+ function usePostFavoriteService2() {
56384
56711
  const { addFavorite: _addFavorite, updateById: _updateById } = usePostFavoriteRepo();
56385
56712
  async function addFavorite(value) {
56386
- const session = import_node_server_utils238.useAtlas.getClient()?.startSession();
56713
+ const session = import_node_server_utils239.useAtlas.getClient()?.startSession();
56387
56714
  session?.startTransaction();
56388
56715
  try {
56389
56716
  await _addFavorite(value, session);
@@ -56397,7 +56724,7 @@ function usePostFavoriteService() {
56397
56724
  }
56398
56725
  }
56399
56726
  async function toggleFavorite(_id, userId) {
56400
- const session = import_node_server_utils238.useAtlas.getClient()?.startSession();
56727
+ const session = import_node_server_utils239.useAtlas.getClient()?.startSession();
56401
56728
  session?.startTransaction();
56402
56729
  try {
56403
56730
  const action = await _updateById(_id, userId, session);
@@ -56417,10 +56744,10 @@ function usePostFavoriteService() {
56417
56744
  }
56418
56745
 
56419
56746
  // src/controllers/post-favorite.controller.ts
56420
- var import_node_server_utils239 = require("@7365admin1/node-server-utils");
56747
+ var import_node_server_utils240 = require("@7365admin1/node-server-utils");
56421
56748
  var import_joi136 = __toESM(require("joi"));
56422
56749
  function usePostFavoriteController() {
56423
- const { addFavorite: _addFavorite, toggleFavorite: _toggleFavorite } = usePostFavoriteService();
56750
+ const { addFavorite: _addFavorite, toggleFavorite: _toggleFavorite } = usePostFavoriteService2();
56424
56751
  const { getById: _getById, getByPostId: _getByPostId } = usePostFavoriteRepo();
56425
56752
  async function addFavorite(req, res, next) {
56426
56753
  const { error, value } = schemaPostFavorite.validate(req.body, {
@@ -56428,8 +56755,8 @@ function usePostFavoriteController() {
56428
56755
  });
56429
56756
  if (error) {
56430
56757
  const messages = error.details.map((d) => d.message).join(", ");
56431
- import_node_server_utils239.logger.log({ level: "error", message: messages });
56432
- next(new import_node_server_utils239.BadRequestError(messages));
56758
+ import_node_server_utils240.logger.log({ level: "error", message: messages });
56759
+ next(new import_node_server_utils240.BadRequestError(messages));
56433
56760
  return;
56434
56761
  }
56435
56762
  try {
@@ -56437,7 +56764,7 @@ function usePostFavoriteController() {
56437
56764
  res.status(201).json(data);
56438
56765
  return;
56439
56766
  } catch (error2) {
56440
- import_node_server_utils239.logger.log({ level: "error", message: error2.message });
56767
+ import_node_server_utils240.logger.log({ level: "error", message: error2.message });
56441
56768
  next(error2);
56442
56769
  return;
56443
56770
  }
@@ -56448,8 +56775,8 @@ function usePostFavoriteController() {
56448
56775
  });
56449
56776
  const { error, value } = schema2.validate({ _id: req.params.id });
56450
56777
  if (error) {
56451
- import_node_server_utils239.logger.log({ level: "error", message: error.message });
56452
- next(new import_node_server_utils239.BadRequestError(error.message));
56778
+ import_node_server_utils240.logger.log({ level: "error", message: error.message });
56779
+ next(new import_node_server_utils240.BadRequestError(error.message));
56453
56780
  return;
56454
56781
  }
56455
56782
  try {
@@ -56457,7 +56784,7 @@ function usePostFavoriteController() {
56457
56784
  res.status(200).json(data);
56458
56785
  return;
56459
56786
  } catch (error2) {
56460
- import_node_server_utils239.logger.log({ level: "error", message: error2.message });
56787
+ import_node_server_utils240.logger.log({ level: "error", message: error2.message });
56461
56788
  next(error2);
56462
56789
  return;
56463
56790
  }
@@ -56468,8 +56795,8 @@ function usePostFavoriteController() {
56468
56795
  });
56469
56796
  const { error, value } = schema2.validate({ postId: req.params.postId });
56470
56797
  if (error) {
56471
- import_node_server_utils239.logger.log({ level: "error", message: error.message });
56472
- next(new import_node_server_utils239.BadRequestError(error.message));
56798
+ import_node_server_utils240.logger.log({ level: "error", message: error.message });
56799
+ next(new import_node_server_utils240.BadRequestError(error.message));
56473
56800
  return;
56474
56801
  }
56475
56802
  try {
@@ -56477,7 +56804,7 @@ function usePostFavoriteController() {
56477
56804
  res.status(200).json(data);
56478
56805
  return;
56479
56806
  } catch (error2) {
56480
- import_node_server_utils239.logger.log({ level: "error", message: error2.message });
56807
+ import_node_server_utils240.logger.log({ level: "error", message: error2.message });
56481
56808
  next(error2);
56482
56809
  return;
56483
56810
  }
@@ -56490,21 +56817,21 @@ function usePostFavoriteController() {
56490
56817
  _id: req.params.id
56491
56818
  });
56492
56819
  if (paramsError) {
56493
- next(new import_node_server_utils239.BadRequestError(paramsError.message));
56820
+ next(new import_node_server_utils240.BadRequestError(paramsError.message));
56494
56821
  return;
56495
56822
  }
56496
56823
  const { error: bodyError, value: bodyValue } = schemaUpdatePostFavorite.validate(req.body, { abortEarly: false });
56497
56824
  if (bodyError) {
56498
56825
  const messages = bodyError.details.map((d) => d.message).join(", ");
56499
- import_node_server_utils239.logger.log({ level: "error", message: messages });
56500
- next(new import_node_server_utils239.BadRequestError(messages));
56826
+ import_node_server_utils240.logger.log({ level: "error", message: messages });
56827
+ next(new import_node_server_utils240.BadRequestError(messages));
56501
56828
  return;
56502
56829
  }
56503
56830
  try {
56504
56831
  const data = await _toggleFavorite(paramsValue._id, bodyValue.userId);
56505
56832
  res.status(200).json(data);
56506
56833
  } catch (error) {
56507
- import_node_server_utils239.logger.log({ level: "error", message: error.message });
56834
+ import_node_server_utils240.logger.log({ level: "error", message: error.message });
56508
56835
  next(error);
56509
56836
  }
56510
56837
  }
@@ -56518,7 +56845,7 @@ function usePostFavoriteController() {
56518
56845
 
56519
56846
  // src/models/category-preloved.model.ts
56520
56847
  var import_joi137 = __toESM(require("joi"));
56521
- var import_mongodb136 = require("mongodb");
56848
+ var import_mongodb137 = require("mongodb");
56522
56849
  var schemaCategoryPreloved = import_joi137.default.object({
56523
56850
  name: import_joi137.default.string().required(),
56524
56851
  createdBy: import_joi137.default.string().hex().optional().allow("", null),
@@ -56535,14 +56862,14 @@ function MCategoryPreloved(value) {
56535
56862
  }
56536
56863
  if (value.createdBy && typeof value.createdBy === "string") {
56537
56864
  try {
56538
- value.createdBy = new import_mongodb136.ObjectId(value.createdBy);
56865
+ value.createdBy = new import_mongodb137.ObjectId(value.createdBy);
56539
56866
  } catch {
56540
56867
  throw new Error("Invalid createdBy ID.");
56541
56868
  }
56542
56869
  }
56543
56870
  if (value.site && typeof value.site === "string") {
56544
56871
  try {
56545
- value.site = new import_mongodb136.ObjectId(value.site);
56872
+ value.site = new import_mongodb137.ObjectId(value.site);
56546
56873
  } catch {
56547
56874
  throw new Error("Invalid site ID.");
56548
56875
  }
@@ -56557,12 +56884,12 @@ function MCategoryPreloved(value) {
56557
56884
  }
56558
56885
 
56559
56886
  // src/repositories/category-preloved.repo.ts
56560
- var import_node_server_utils240 = require("@7365admin1/node-server-utils");
56561
- var import_mongodb137 = require("mongodb");
56887
+ var import_node_server_utils241 = require("@7365admin1/node-server-utils");
56888
+ var import_mongodb138 = require("mongodb");
56562
56889
  function useCategoryPrelovedRepo() {
56563
- const db = import_node_server_utils240.useAtlas.getDb();
56890
+ const db = import_node_server_utils241.useAtlas.getDb();
56564
56891
  if (!db) {
56565
- throw new import_node_server_utils240.InternalServerError("Unable to connect to server.");
56892
+ throw new import_node_server_utils241.InternalServerError("Unable to connect to server.");
56566
56893
  }
56567
56894
  const CATEGORY_COLLECTION = "category-preloved";
56568
56895
  const collection = db.collection(CATEGORY_COLLECTION);
@@ -56572,9 +56899,9 @@ function useCategoryPrelovedRepo() {
56572
56899
  } = {}) {
56573
56900
  if (site) {
56574
56901
  try {
56575
- site = new import_mongodb137.ObjectId(site);
56902
+ site = new import_mongodb138.ObjectId(site);
56576
56903
  } catch {
56577
- throw new import_node_server_utils240.BadRequestError("Invalid site ID format.");
56904
+ throw new import_node_server_utils241.BadRequestError("Invalid site ID format.");
56578
56905
  }
56579
56906
  }
56580
56907
  const query = {
@@ -56591,14 +56918,14 @@ function useCategoryPrelovedRepo() {
56591
56918
  async function getById(_id) {
56592
56919
  let objectId2;
56593
56920
  try {
56594
- objectId2 = new import_mongodb137.ObjectId(_id);
56921
+ objectId2 = new import_mongodb138.ObjectId(_id);
56595
56922
  } catch {
56596
- throw new import_node_server_utils240.BadRequestError("Invalid category-preloved ID format.");
56923
+ throw new import_node_server_utils241.BadRequestError("Invalid category-preloved ID format.");
56597
56924
  }
56598
56925
  try {
56599
56926
  const data = await collection.findOne({ _id: objectId2 });
56600
56927
  if (!data) {
56601
- throw new import_node_server_utils240.NotFoundError("Category not found.");
56928
+ throw new import_node_server_utils241.NotFoundError("Category not found.");
56602
56929
  }
56603
56930
  return data;
56604
56931
  } catch (error) {
@@ -56614,18 +56941,36 @@ function useCategoryPrelovedRepo() {
56614
56941
  } catch (error) {
56615
56942
  const isDuplicated = error.message?.includes("duplicate");
56616
56943
  if (isDuplicated)
56617
- throw new import_node_server_utils240.BadRequestError("Category already exists.");
56944
+ throw new import_node_server_utils241.BadRequestError("Category already exists.");
56618
56945
  throw error;
56619
56946
  }
56620
56947
  }
56621
- return { getAll, getById, addCategory };
56948
+ async function updateById(_id, value) {
56949
+ let objectId2;
56950
+ try {
56951
+ objectId2 = new import_mongodb138.ObjectId(_id);
56952
+ } catch {
56953
+ throw new import_node_server_utils241.BadRequestError("Invalid category ID format.");
56954
+ }
56955
+ const existing = await collection.findOne({ _id: objectId2 });
56956
+ if (!existing)
56957
+ throw new import_node_server_utils241.NotFoundError("Category not found.");
56958
+ const res = await collection.updateOne(
56959
+ { _id: objectId2 },
56960
+ { $set: { ...value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
56961
+ );
56962
+ if (res.modifiedCount === 0)
56963
+ throw new import_node_server_utils241.InternalServerError("Unable to update category.");
56964
+ return "Category updated successfully.";
56965
+ }
56966
+ return { getAll, getById, addCategory, updateById };
56622
56967
  }
56623
56968
 
56624
56969
  // src/controllers/category-preloved.controller.ts
56625
- var import_node_server_utils241 = require("@7365admin1/node-server-utils");
56970
+ var import_node_server_utils242 = require("@7365admin1/node-server-utils");
56626
56971
  var import_joi138 = __toESM(require("joi"));
56627
56972
  function useCategoryPrelovedController() {
56628
- const { getAll: _getAll, getById: _getById, addCategory: _addCategory } = useCategoryPrelovedRepo();
56973
+ const { getAll: _getAll, getById: _getById, addCategory: _addCategory, updateById: _updateById } = useCategoryPrelovedRepo();
56629
56974
  async function getAll(req, res, next) {
56630
56975
  const schema2 = import_joi138.default.object({
56631
56976
  search: import_joi138.default.string().optional().allow("", null),
@@ -56634,8 +56979,8 @@ function useCategoryPrelovedController() {
56634
56979
  const { error, value } = schema2.validate(req.query, { abortEarly: false });
56635
56980
  if (error) {
56636
56981
  const messages = error.details.map((d) => d.message).join(", ");
56637
- import_node_server_utils241.logger.log({ level: "error", message: messages });
56638
- next(new import_node_server_utils241.BadRequestError(messages));
56982
+ import_node_server_utils242.logger.log({ level: "error", message: messages });
56983
+ next(new import_node_server_utils242.BadRequestError(messages));
56639
56984
  return;
56640
56985
  }
56641
56986
  try {
@@ -56643,7 +56988,7 @@ function useCategoryPrelovedController() {
56643
56988
  res.status(200).json({ data });
56644
56989
  return;
56645
56990
  } catch (error2) {
56646
- import_node_server_utils241.logger.log({ level: "error", message: error2.message });
56991
+ import_node_server_utils242.logger.log({ level: "error", message: error2.message });
56647
56992
  next(error2);
56648
56993
  return;
56649
56994
  }
@@ -56654,8 +56999,8 @@ function useCategoryPrelovedController() {
56654
56999
  });
56655
57000
  const { error, value } = schema2.validate({ _id: req.params.id });
56656
57001
  if (error) {
56657
- import_node_server_utils241.logger.log({ level: "error", message: error.message });
56658
- next(new import_node_server_utils241.BadRequestError(error.message));
57002
+ import_node_server_utils242.logger.log({ level: "error", message: error.message });
57003
+ next(new import_node_server_utils242.BadRequestError(error.message));
56659
57004
  return;
56660
57005
  }
56661
57006
  try {
@@ -56663,7 +57008,7 @@ function useCategoryPrelovedController() {
56663
57008
  res.status(200).json({ data });
56664
57009
  return;
56665
57010
  } catch (error2) {
56666
- import_node_server_utils241.logger.log({ level: "error", message: error2.message });
57011
+ import_node_server_utils242.logger.log({ level: "error", message: error2.message });
56667
57012
  next(error2);
56668
57013
  return;
56669
57014
  }
@@ -56674,24 +57019,42 @@ function useCategoryPrelovedController() {
56674
57019
  });
56675
57020
  if (error) {
56676
57021
  const messages = error.details.map((d) => d.message).join(", ");
56677
- import_node_server_utils241.logger.log({ level: "error", message: messages });
56678
- next(new import_node_server_utils241.BadRequestError(messages));
57022
+ import_node_server_utils242.logger.log({ level: "error", message: messages });
57023
+ next(new import_node_server_utils242.BadRequestError(messages));
56679
57024
  return;
56680
57025
  }
56681
57026
  try {
56682
57027
  const data = await _addCategory(value);
56683
57028
  res.status(201).json(data);
56684
57029
  } catch (error2) {
56685
- import_node_server_utils241.logger.log({ level: "error", message: error2.message });
57030
+ import_node_server_utils242.logger.log({ level: "error", message: error2.message });
56686
57031
  next(error2);
56687
57032
  }
56688
57033
  }
56689
- return { getAll, getById, addCategory };
57034
+ async function updateById(req, res, next) {
57035
+ const { error, value } = schemaUpdateCategoryPreloved.validate(req.body, {
57036
+ abortEarly: false
57037
+ });
57038
+ if (error) {
57039
+ const messages = error.details.map((d) => d.message).join(", ");
57040
+ import_node_server_utils242.logger.log({ level: "error", message: messages });
57041
+ next(new import_node_server_utils242.BadRequestError(messages));
57042
+ return;
57043
+ }
57044
+ try {
57045
+ const data = await _updateById(req.params.id, value);
57046
+ res.status(200).json(data);
57047
+ } catch (error2) {
57048
+ import_node_server_utils242.logger.log({ level: "error", message: error2.message });
57049
+ next(error2);
57050
+ }
57051
+ }
57052
+ return { getAll, getById, addCategory, updateById };
56690
57053
  }
56691
57054
 
56692
57055
  // src/models/subcategory-preloved.model.ts
56693
57056
  var import_joi139 = __toESM(require("joi"));
56694
- var import_mongodb138 = require("mongodb");
57057
+ var import_mongodb139 = require("mongodb");
56695
57058
  var schemaSubcategoryPreloved = import_joi139.default.object({
56696
57059
  name: import_joi139.default.string().required(),
56697
57060
  createdBy: import_joi139.default.string().hex().optional().allow("", null),
@@ -56710,21 +57073,21 @@ function MSubcategoryPreloved(value) {
56710
57073
  }
56711
57074
  if (value.createdBy && typeof value.createdBy === "string") {
56712
57075
  try {
56713
- value.createdBy = new import_mongodb138.ObjectId(value.createdBy);
57076
+ value.createdBy = new import_mongodb139.ObjectId(value.createdBy);
56714
57077
  } catch {
56715
57078
  throw new Error("Invalid createdBy ID.");
56716
57079
  }
56717
57080
  }
56718
57081
  if (value.site && typeof value.site === "string") {
56719
57082
  try {
56720
- value.site = new import_mongodb138.ObjectId(value.site);
57083
+ value.site = new import_mongodb139.ObjectId(value.site);
56721
57084
  } catch {
56722
57085
  throw new Error("Invalid site ID.");
56723
57086
  }
56724
57087
  }
56725
57088
  if (value.category_id && typeof value.category_id === "string") {
56726
57089
  try {
56727
- value.category_id = new import_mongodb138.ObjectId(value.category_id);
57090
+ value.category_id = new import_mongodb139.ObjectId(value.category_id);
56728
57091
  } catch {
56729
57092
  throw new Error("Invalid category ID.");
56730
57093
  }
@@ -56740,12 +57103,12 @@ function MSubcategoryPreloved(value) {
56740
57103
  }
56741
57104
 
56742
57105
  // src/repositories/subcategory-preloved.repo.ts
56743
- var import_node_server_utils242 = require("@7365admin1/node-server-utils");
56744
- var import_mongodb139 = require("mongodb");
57106
+ var import_node_server_utils243 = require("@7365admin1/node-server-utils");
57107
+ var import_mongodb140 = require("mongodb");
56745
57108
  function useSubcategoryPrelovedRepo() {
56746
- const db = import_node_server_utils242.useAtlas.getDb();
57109
+ const db = import_node_server_utils243.useAtlas.getDb();
56747
57110
  if (!db) {
56748
- throw new import_node_server_utils242.InternalServerError("Unable to connect to server.");
57111
+ throw new import_node_server_utils243.InternalServerError("Unable to connect to server.");
56749
57112
  }
56750
57113
  const SUBCATEGORY_COLLECTION = "subcategory-preloved";
56751
57114
  const collection = db.collection(SUBCATEGORY_COLLECTION);
@@ -56756,16 +57119,16 @@ function useSubcategoryPrelovedRepo() {
56756
57119
  } = {}) {
56757
57120
  if (site) {
56758
57121
  try {
56759
- site = new import_mongodb139.ObjectId(site);
57122
+ site = new import_mongodb140.ObjectId(site);
56760
57123
  } catch {
56761
- throw new import_node_server_utils242.BadRequestError("Invalid site ID format.");
57124
+ throw new import_node_server_utils243.BadRequestError("Invalid site ID format.");
56762
57125
  }
56763
57126
  }
56764
57127
  if (category_id) {
56765
57128
  try {
56766
- category_id = new import_mongodb139.ObjectId(category_id);
57129
+ category_id = new import_mongodb140.ObjectId(category_id);
56767
57130
  } catch {
56768
- throw new import_node_server_utils242.BadRequestError("Invalid category ID format.");
57131
+ throw new import_node_server_utils243.BadRequestError("Invalid category ID format.");
56769
57132
  }
56770
57133
  }
56771
57134
  const query = {
@@ -56782,14 +57145,14 @@ function useSubcategoryPrelovedRepo() {
56782
57145
  async function getById(_id) {
56783
57146
  let objectId2;
56784
57147
  try {
56785
- objectId2 = new import_mongodb139.ObjectId(_id);
57148
+ objectId2 = new import_mongodb140.ObjectId(_id);
56786
57149
  } catch {
56787
- throw new import_node_server_utils242.BadRequestError("Invalid subcategory-preloved ID format.");
57150
+ throw new import_node_server_utils243.BadRequestError("Invalid subcategory-preloved ID format.");
56788
57151
  }
56789
57152
  try {
56790
57153
  const data = await collection.findOne({ _id: objectId2 });
56791
57154
  if (!data) {
56792
- throw new import_node_server_utils242.NotFoundError("Subcategory not found.");
57155
+ throw new import_node_server_utils243.NotFoundError("Subcategory not found.");
56793
57156
  }
56794
57157
  return data;
56795
57158
  } catch (error) {
@@ -56804,29 +57167,29 @@ function useSubcategoryPrelovedRepo() {
56804
57167
  } catch (error) {
56805
57168
  const isDuplicated = error.message?.includes("duplicate");
56806
57169
  if (isDuplicated)
56807
- throw new import_node_server_utils242.BadRequestError("Subcategory already exists.");
57170
+ throw new import_node_server_utils243.BadRequestError("Subcategory already exists.");
56808
57171
  throw error;
56809
57172
  }
56810
57173
  }
56811
57174
  async function updateById(_id, value, session) {
56812
57175
  let objectId2;
56813
57176
  try {
56814
- objectId2 = new import_mongodb139.ObjectId(_id);
57177
+ objectId2 = new import_mongodb140.ObjectId(_id);
56815
57178
  } catch {
56816
- throw new import_node_server_utils242.BadRequestError("Invalid subcategory ID format.");
57179
+ throw new import_node_server_utils243.BadRequestError("Invalid subcategory ID format.");
56817
57180
  }
56818
57181
  if (value.category_id && typeof value.category_id === "string") {
56819
57182
  try {
56820
- value.category_id = new import_mongodb139.ObjectId(value.category_id);
57183
+ value.category_id = new import_mongodb140.ObjectId(value.category_id);
56821
57184
  } catch {
56822
- throw new import_node_server_utils242.BadRequestError("Invalid category ID format.");
57185
+ throw new import_node_server_utils243.BadRequestError("Invalid category ID format.");
56823
57186
  }
56824
57187
  }
56825
57188
  if (value.site && typeof value.site === "string") {
56826
57189
  try {
56827
- value.site = new import_mongodb139.ObjectId(value.site);
57190
+ value.site = new import_mongodb140.ObjectId(value.site);
56828
57191
  } catch {
56829
- throw new import_node_server_utils242.BadRequestError("Invalid site ID format.");
57192
+ throw new import_node_server_utils243.BadRequestError("Invalid site ID format.");
56830
57193
  }
56831
57194
  }
56832
57195
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
@@ -56836,26 +57199,26 @@ function useSubcategoryPrelovedRepo() {
56836
57199
  { session }
56837
57200
  );
56838
57201
  if (res.modifiedCount === 0)
56839
- throw new import_node_server_utils242.InternalServerError("Unable to update subcategory.");
57202
+ throw new import_node_server_utils243.InternalServerError("Unable to update subcategory.");
56840
57203
  return res;
56841
57204
  }
56842
57205
  async function deleteById(_id, session) {
56843
57206
  let objectId2;
56844
57207
  try {
56845
- objectId2 = new import_mongodb139.ObjectId(_id);
57208
+ objectId2 = new import_mongodb140.ObjectId(_id);
56846
57209
  } catch {
56847
- throw new import_node_server_utils242.BadRequestError("Invalid subcategory ID format.");
57210
+ throw new import_node_server_utils243.BadRequestError("Invalid subcategory ID format.");
56848
57211
  }
56849
57212
  const res = await collection.deleteOne({ _id: objectId2 }, { session });
56850
57213
  if (res.deletedCount === 0)
56851
- throw new import_node_server_utils242.InternalServerError("Unable to delete subcategory.");
57214
+ throw new import_node_server_utils243.InternalServerError("Unable to delete subcategory.");
56852
57215
  return res.deletedCount;
56853
57216
  }
56854
57217
  return { getAll, getById, addSubcategory, updateById, deleteById };
56855
57218
  }
56856
57219
 
56857
57220
  // src/controllers/subcategory-preloved.controller.ts
56858
- var import_node_server_utils243 = require("@7365admin1/node-server-utils");
57221
+ var import_node_server_utils244 = require("@7365admin1/node-server-utils");
56859
57222
  var import_joi140 = __toESM(require("joi"));
56860
57223
  function useSubcategoryPrelovedController() {
56861
57224
  const {
@@ -56874,8 +57237,8 @@ function useSubcategoryPrelovedController() {
56874
57237
  const { error, value } = schema2.validate(req.query, { abortEarly: false });
56875
57238
  if (error) {
56876
57239
  const messages = error.details.map((d) => d.message).join(", ");
56877
- import_node_server_utils243.logger.log({ level: "error", message: messages });
56878
- next(new import_node_server_utils243.BadRequestError(messages));
57240
+ import_node_server_utils244.logger.log({ level: "error", message: messages });
57241
+ next(new import_node_server_utils244.BadRequestError(messages));
56879
57242
  return;
56880
57243
  }
56881
57244
  try {
@@ -56883,7 +57246,7 @@ function useSubcategoryPrelovedController() {
56883
57246
  res.status(200).json({ data });
56884
57247
  return;
56885
57248
  } catch (error2) {
56886
- import_node_server_utils243.logger.log({ level: "error", message: error2.message });
57249
+ import_node_server_utils244.logger.log({ level: "error", message: error2.message });
56887
57250
  next(error2);
56888
57251
  return;
56889
57252
  }
@@ -56894,8 +57257,8 @@ function useSubcategoryPrelovedController() {
56894
57257
  });
56895
57258
  const { error, value } = schema2.validate({ _id: req.params.id });
56896
57259
  if (error) {
56897
- import_node_server_utils243.logger.log({ level: "error", message: error.message });
56898
- next(new import_node_server_utils243.BadRequestError(error.message));
57260
+ import_node_server_utils244.logger.log({ level: "error", message: error.message });
57261
+ next(new import_node_server_utils244.BadRequestError(error.message));
56899
57262
  return;
56900
57263
  }
56901
57264
  try {
@@ -56903,7 +57266,7 @@ function useSubcategoryPrelovedController() {
56903
57266
  res.status(200).json({ data });
56904
57267
  return;
56905
57268
  } catch (error2) {
56906
- import_node_server_utils243.logger.log({ level: "error", message: error2.message });
57269
+ import_node_server_utils244.logger.log({ level: "error", message: error2.message });
56907
57270
  next(error2);
56908
57271
  return;
56909
57272
  }
@@ -56914,15 +57277,15 @@ function useSubcategoryPrelovedController() {
56914
57277
  });
56915
57278
  if (error) {
56916
57279
  const messages = error.details.map((d) => d.message).join(", ");
56917
- import_node_server_utils243.logger.log({ level: "error", message: messages });
56918
- next(new import_node_server_utils243.BadRequestError(messages));
57280
+ import_node_server_utils244.logger.log({ level: "error", message: messages });
57281
+ next(new import_node_server_utils244.BadRequestError(messages));
56919
57282
  return;
56920
57283
  }
56921
57284
  try {
56922
57285
  const data = await _addSubcategory(value);
56923
57286
  res.status(201).json(data);
56924
57287
  } catch (error2) {
56925
- import_node_server_utils243.logger.log({ level: "error", message: error2.message });
57288
+ import_node_server_utils244.logger.log({ level: "error", message: error2.message });
56926
57289
  next(error2);
56927
57290
  }
56928
57291
  }
@@ -56934,21 +57297,21 @@ function useSubcategoryPrelovedController() {
56934
57297
  _id: req.params.id
56935
57298
  });
56936
57299
  if (paramsError) {
56937
- next(new import_node_server_utils243.BadRequestError(paramsError.message));
57300
+ next(new import_node_server_utils244.BadRequestError(paramsError.message));
56938
57301
  return;
56939
57302
  }
56940
57303
  const { error: bodyError, value: bodyValue } = schemaUpdateSubcategoryPreloved.validate(req.body, { abortEarly: false });
56941
57304
  if (bodyError) {
56942
57305
  const messages = bodyError.details.map((d) => d.message).join(", ");
56943
- import_node_server_utils243.logger.log({ level: "error", message: messages });
56944
- next(new import_node_server_utils243.BadRequestError(messages));
57306
+ import_node_server_utils244.logger.log({ level: "error", message: messages });
57307
+ next(new import_node_server_utils244.BadRequestError(messages));
56945
57308
  return;
56946
57309
  }
56947
57310
  try {
56948
57311
  const data = await _updateById(paramsValue._id, bodyValue);
56949
57312
  res.status(200).json(data);
56950
57313
  } catch (error) {
56951
- import_node_server_utils243.logger.log({ level: "error", message: error.message });
57314
+ import_node_server_utils244.logger.log({ level: "error", message: error.message });
56952
57315
  next(error);
56953
57316
  }
56954
57317
  }
@@ -56958,14 +57321,14 @@ function useSubcategoryPrelovedController() {
56958
57321
  });
56959
57322
  const { error, value } = schema2.validate({ _id: req.params.id });
56960
57323
  if (error) {
56961
- next(new import_node_server_utils243.BadRequestError(error.message));
57324
+ next(new import_node_server_utils244.BadRequestError(error.message));
56962
57325
  return;
56963
57326
  }
56964
57327
  try {
56965
57328
  const data = await _deleteById(value._id);
56966
57329
  res.status(200).json(data);
56967
57330
  } catch (error2) {
56968
- import_node_server_utils243.logger.log({ level: "error", message: error2.message });
57331
+ import_node_server_utils244.logger.log({ level: "error", message: error2.message });
56969
57332
  next(error2);
56970
57333
  }
56971
57334
  }
@@ -56974,7 +57337,7 @@ function useSubcategoryPrelovedController() {
56974
57337
 
56975
57338
  // src/models/online-forms-v2.model.ts
56976
57339
  var import_joi141 = __toESM(require("joi"));
56977
- var import_mongodb140 = require("mongodb");
57340
+ var import_mongodb141 = require("mongodb");
56978
57341
  var FormEntryStatus = /* @__PURE__ */ ((FormEntryStatus2) => {
56979
57342
  FormEntryStatus2["ACTIVE"] = "active";
56980
57343
  FormEntryStatus2["INACTIVE"] = "inactive";
@@ -57008,6 +57371,9 @@ var schemaFormEntry = import_joi141.default.object({
57008
57371
  var schemaUpdateFormEntry = import_joi141.default.object({
57009
57372
  _id: import_joi141.default.string().hex().required(),
57010
57373
  formType: import_joi141.default.string().optional().allow("", null),
57374
+ block: import_joi141.default.string().optional().allow(null, ""),
57375
+ level: import_joi141.default.string().optional().allow(null, ""),
57376
+ unit: import_joi141.default.string().optional().allow(null, ""),
57011
57377
  fields: import_joi141.default.object().pattern(
57012
57378
  import_joi141.default.string(),
57013
57379
  import_joi141.default.alternatives().try(
@@ -57018,7 +57384,6 @@ var schemaUpdateFormEntry = import_joi141.default.object({
57018
57384
  )
57019
57385
  ).optional(),
57020
57386
  status: import_joi141.default.string().optional().allow("", null),
57021
- createdAt: import_joi141.default.date().optional().allow("", null),
57022
57387
  updatedAt: import_joi141.default.date().optional().allow("", null),
57023
57388
  deletedAt: import_joi141.default.date().optional().allow("", null)
57024
57389
  });
@@ -57029,21 +57394,21 @@ function MFormEntry(value) {
57029
57394
  }
57030
57395
  if (value._id && typeof value._id === "string") {
57031
57396
  try {
57032
- value._id = new import_mongodb140.ObjectId(value._id);
57397
+ value._id = new import_mongodb141.ObjectId(value._id);
57033
57398
  } catch {
57034
57399
  throw new Error("Invalid ID.");
57035
57400
  }
57036
57401
  }
57037
57402
  if (value.org && typeof value.org === "string") {
57038
57403
  try {
57039
- value.org = new import_mongodb140.ObjectId(value.org);
57404
+ value.org = new import_mongodb141.ObjectId(value.org);
57040
57405
  } catch {
57041
57406
  throw new Error("Invalid org ID.");
57042
57407
  }
57043
57408
  }
57044
57409
  if (value.site && typeof value.site === "string") {
57045
57410
  try {
57046
- value.site = new import_mongodb140.ObjectId(value.site);
57411
+ value.site = new import_mongodb141.ObjectId(value.site);
57047
57412
  } catch {
57048
57413
  throw new Error("Invalid site ID.");
57049
57414
  }
@@ -57051,6 +57416,11 @@ function MFormEntry(value) {
57051
57416
  return {
57052
57417
  _id: value._id,
57053
57418
  formType: value.formType,
57419
+ block: value.block,
57420
+ level: value.level,
57421
+ unit: value.unit,
57422
+ name: value.name,
57423
+ phoneNumber: value.phoneNumber,
57054
57424
  fields: value.fields,
57055
57425
  status: value.status,
57056
57426
  org: value.org,
@@ -57062,16 +57432,16 @@ function MFormEntry(value) {
57062
57432
  }
57063
57433
 
57064
57434
  // src/repositories/online-forms-v2.repository.ts
57065
- var import_node_server_utils244 = require("@7365admin1/node-server-utils");
57066
- var import_mongodb141 = require("mongodb");
57435
+ var import_node_server_utils245 = require("@7365admin1/node-server-utils");
57436
+ var import_mongodb142 = require("mongodb");
57067
57437
  var online_forms_namespace_collection = "online-forms";
57068
57438
  function useFormEntryRepo() {
57069
- const db = import_node_server_utils244.useAtlas.getDb();
57439
+ const db = import_node_server_utils245.useAtlas.getDb();
57070
57440
  if (!db) {
57071
- throw new import_node_server_utils244.InternalServerError("Unable to connect to server.");
57441
+ throw new import_node_server_utils245.InternalServerError("Unable to connect to server.");
57072
57442
  }
57073
57443
  const collection = db.collection(online_forms_namespace_collection);
57074
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils244.useCache)(
57444
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils245.useCache)(
57075
57445
  online_forms_namespace_collection
57076
57446
  );
57077
57447
  async function createTextIndex() {
@@ -57080,7 +57450,7 @@ function useFormEntryRepo() {
57080
57450
  name: "text"
57081
57451
  });
57082
57452
  } catch (error) {
57083
- throw new import_node_server_utils244.InternalServerError(
57453
+ throw new import_node_server_utils245.InternalServerError(
57084
57454
  "Failed to create text index on online form."
57085
57455
  );
57086
57456
  }
@@ -57090,11 +57460,11 @@ function useFormEntryRepo() {
57090
57460
  value = MFormEntry(value);
57091
57461
  const res = await collection.insertOne(value, { session });
57092
57462
  delNamespace().then(() => {
57093
- import_node_server_utils244.logger.info(
57463
+ import_node_server_utils245.logger.info(
57094
57464
  `Cache cleared for namespace: ${online_forms_namespace_collection}`
57095
57465
  );
57096
57466
  }).catch((err) => {
57097
- import_node_server_utils244.logger.error(
57467
+ import_node_server_utils245.logger.error(
57098
57468
  `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
57099
57469
  err
57100
57470
  );
@@ -57103,7 +57473,7 @@ function useFormEntryRepo() {
57103
57473
  } catch (error) {
57104
57474
  const isDuplicated = error.message.includes("duplicate");
57105
57475
  if (isDuplicated) {
57106
- throw new import_node_server_utils244.BadRequestError("Online Form already exists.");
57476
+ throw new import_node_server_utils245.BadRequestError("Online Form already exists.");
57107
57477
  }
57108
57478
  throw error;
57109
57479
  }
@@ -57129,16 +57499,16 @@ function useFormEntryRepo() {
57129
57499
  };
57130
57500
  const query = {
57131
57501
  ...status ? { $and: [{ status }, { status: { $ne: "deleted" } }] } : { status: { $ne: "deleted" } },
57132
- ...site && { site: new import_mongodb141.ObjectId(site) },
57502
+ ...site && { site: new import_mongodb142.ObjectId(site) },
57133
57503
  ...search && { search: [{ name: { $regex: search, $options: "i" } }] }
57134
57504
  };
57135
- const cacheKey = (0, import_node_server_utils244.makeCacheKey)(
57505
+ const cacheKey = (0, import_node_server_utils245.makeCacheKey)(
57136
57506
  online_forms_namespace_collection,
57137
57507
  cacheOptions
57138
57508
  );
57139
57509
  const cachedData = await getCache(cacheKey);
57140
57510
  if (cachedData) {
57141
- import_node_server_utils244.logger.info(`Cache hit for key: ${cacheKey}`);
57511
+ import_node_server_utils245.logger.info(`Cache hit for key: ${cacheKey}`);
57142
57512
  return cachedData;
57143
57513
  }
57144
57514
  try {
@@ -57149,11 +57519,11 @@ function useFormEntryRepo() {
57149
57519
  { $limit: limit }
57150
57520
  ]).toArray();
57151
57521
  const length = await collection.countDocuments(query);
57152
- const data = (0, import_node_server_utils244.paginate)(items, page, limit, length);
57522
+ const data = (0, import_node_server_utils245.paginate)(items, page, limit, length);
57153
57523
  setCache(cacheKey, data, 15 * 60).then(() => {
57154
- import_node_server_utils244.logger.info(`Cache set for key: ${cacheKey}`);
57524
+ import_node_server_utils245.logger.info(`Cache set for key: ${cacheKey}`);
57155
57525
  }).catch((err) => {
57156
- import_node_server_utils244.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
57526
+ import_node_server_utils245.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
57157
57527
  });
57158
57528
  return data;
57159
57529
  } catch (error) {
@@ -57161,43 +57531,74 @@ function useFormEntryRepo() {
57161
57531
  }
57162
57532
  }
57163
57533
  async function getFormEntryById(_id) {
57164
- const cacheKey = (0, import_node_server_utils244.makeCacheKey)(online_forms_namespace_collection, { _id });
57534
+ const cacheKey = (0, import_node_server_utils245.makeCacheKey)(online_forms_namespace_collection, { _id });
57165
57535
  const cachedData = await getCache(cacheKey);
57166
57536
  if (cachedData) {
57167
- import_node_server_utils244.logger.info(`Cache hit for key: ${cacheKey}`);
57537
+ import_node_server_utils245.logger.info(`Cache hit for key: ${cacheKey}`);
57168
57538
  return cachedData;
57169
57539
  }
57170
57540
  try {
57171
- _id = new import_mongodb141.ObjectId(_id);
57541
+ _id = new import_mongodb142.ObjectId(_id);
57172
57542
  } catch (error) {
57173
- throw new import_node_server_utils244.BadRequestError("Invalid online form ID format.");
57543
+ throw new import_node_server_utils245.BadRequestError("Invalid online form ID format.");
57174
57544
  }
57175
57545
  const query = { _id, status: { $ne: "deleted" } };
57176
57546
  try {
57177
57547
  const [data] = await collection.aggregate([{ $match: query }]).toArray();
57178
57548
  if (!data) {
57179
- throw new import_node_server_utils244.NotFoundError("Document not found.");
57549
+ throw new import_node_server_utils245.NotFoundError("Document not found.");
57180
57550
  }
57181
57551
  setCache(cacheKey, data, 15 * 60).then(() => {
57182
- import_node_server_utils244.logger.info(`Cache set for key: ${cacheKey}`);
57552
+ import_node_server_utils245.logger.info(`Cache set for key: ${cacheKey}`);
57183
57553
  }).catch((err) => {
57184
- import_node_server_utils244.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
57554
+ import_node_server_utils245.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
57185
57555
  });
57186
57556
  return data;
57187
57557
  } catch (error) {
57188
57558
  throw error;
57189
57559
  }
57190
57560
  }
57561
+ async function updateFormEntryById(_id, value) {
57562
+ try {
57563
+ _id = new import_mongodb142.ObjectId(_id);
57564
+ } catch (error) {
57565
+ throw new import_node_server_utils245.BadRequestError("Invalid online form ID format.");
57566
+ }
57567
+ try {
57568
+ const updateValue = {
57569
+ ...value,
57570
+ updatedAt: /* @__PURE__ */ new Date()
57571
+ };
57572
+ const res = await collection.updateOne({ _id }, { $set: updateValue });
57573
+ if (res.modifiedCount === 0) {
57574
+ throw new import_node_server_utils245.InternalServerError("Unable to update online form.");
57575
+ }
57576
+ delNamespace().then(() => {
57577
+ import_node_server_utils245.logger.info(
57578
+ `Cache cleared for namespace: ${online_forms_namespace_collection}`
57579
+ );
57580
+ }).catch((err) => {
57581
+ import_node_server_utils245.logger.error(
57582
+ `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
57583
+ err
57584
+ );
57585
+ });
57586
+ return res.modifiedCount;
57587
+ } catch (error) {
57588
+ throw error;
57589
+ }
57590
+ }
57191
57591
  return {
57192
57592
  add,
57193
57593
  getAll,
57194
57594
  getFormEntryById,
57595
+ updateFormEntryById,
57195
57596
  createTextIndex
57196
57597
  };
57197
57598
  }
57198
57599
 
57199
57600
  // src/controllers/online-forms-v2.controller.ts
57200
- var import_node_server_utils245 = require("@7365admin1/node-server-utils");
57601
+ var import_node_server_utils246 = require("@7365admin1/node-server-utils");
57201
57602
  var import_joi142 = __toESM(require("joi"));
57202
57603
  var import_exceljs3 = __toESM(require("exceljs"));
57203
57604
  var import_fs6 = __toESM(require("fs"));
@@ -57205,7 +57606,8 @@ function useFormEntryController() {
57205
57606
  const {
57206
57607
  add: _add,
57207
57608
  getAll: _getAll,
57208
- getFormEntryById: _getFormEntryById
57609
+ getFormEntryById: _getFormEntryById,
57610
+ updateFormEntryById: _updateFormEntryById
57209
57611
  } = useFormEntryRepo();
57210
57612
  function toCamelCase(str) {
57211
57613
  return str.replace(/\s(.)/g, (_, char) => char.toUpperCase()).replace(/\s+/g, "").replace(/^(.)/, (_, char) => char.toLowerCase());
@@ -57220,14 +57622,14 @@ function useFormEntryController() {
57220
57622
  async function uploadFormEntrys(req, res, next) {
57221
57623
  try {
57222
57624
  if (!req.file) {
57223
- next(new import_node_server_utils245.BadRequestError("Excel file is required."));
57625
+ next(new import_node_server_utils246.BadRequestError("Excel file is required."));
57224
57626
  return;
57225
57627
  }
57226
57628
  const workbook = new import_exceljs3.default.Workbook();
57227
57629
  await workbook.xlsx.readFile(req.file.path);
57228
57630
  const worksheet = workbook.worksheets[0];
57229
57631
  if (!worksheet) {
57230
- next(new import_node_server_utils245.BadRequestError("No worksheet found in uploaded Excel file."));
57632
+ next(new import_node_server_utils246.BadRequestError("No worksheet found in uploaded Excel file."));
57231
57633
  return;
57232
57634
  }
57233
57635
  const headerRow = worksheet.getRow(1);
@@ -57255,8 +57657,8 @@ function useFormEntryController() {
57255
57657
  });
57256
57658
  if (error) {
57257
57659
  const messages = error.details.map((d) => d.message).join(", ");
57258
- import_node_server_utils245.logger.log({ level: "error", message: messages });
57259
- next(new import_node_server_utils245.BadRequestError(messages));
57660
+ import_node_server_utils246.logger.log({ level: "error", message: messages });
57661
+ next(new import_node_server_utils246.BadRequestError(messages));
57260
57662
  return;
57261
57663
  }
57262
57664
  const result = await _add(value);
@@ -57264,7 +57666,7 @@ function useFormEntryController() {
57264
57666
  import_fs6.default.unlink(req.file.path, () => {
57265
57667
  });
57266
57668
  } catch (error) {
57267
- import_node_server_utils245.logger.log({ level: "error", message: error.message });
57669
+ import_node_server_utils246.logger.log({ level: "error", message: error.message });
57268
57670
  next(error);
57269
57671
  }
57270
57672
  }
@@ -57281,8 +57683,8 @@ function useFormEntryController() {
57281
57683
  const { error, value } = schema2.validate(req.query);
57282
57684
  if (error) {
57283
57685
  const messages = error.details.map((d) => d.message).join(", ");
57284
- import_node_server_utils245.logger.log({ level: "error", message: messages });
57285
- next(new import_node_server_utils245.BadRequestError(messages));
57686
+ import_node_server_utils246.logger.log({ level: "error", message: messages });
57687
+ next(new import_node_server_utils246.BadRequestError(messages));
57286
57688
  return;
57287
57689
  }
57288
57690
  const { search, page, limit, status, org, site } = value;
@@ -57290,7 +57692,7 @@ function useFormEntryController() {
57290
57692
  res.json(data);
57291
57693
  return;
57292
57694
  } catch (error) {
57293
- import_node_server_utils245.logger.log({ level: "error", message: error.message });
57695
+ import_node_server_utils246.logger.log({ level: "error", message: error.message });
57294
57696
  next(error);
57295
57697
  return;
57296
57698
  }
@@ -57303,8 +57705,8 @@ function useFormEntryController() {
57303
57705
  const { error, value } = schema2.validate({ _id: req.params.id });
57304
57706
  if (error) {
57305
57707
  const messages = error.details.map((d) => d.message).join(", ");
57306
- import_node_server_utils245.logger.log({ level: "error", message: messages });
57307
- next(new import_node_server_utils245.BadRequestError(messages));
57708
+ import_node_server_utils246.logger.log({ level: "error", message: messages });
57709
+ next(new import_node_server_utils246.BadRequestError(messages));
57308
57710
  return;
57309
57711
  }
57310
57712
  const { _id } = value;
@@ -57312,7 +57714,29 @@ function useFormEntryController() {
57312
57714
  res.json(data);
57313
57715
  return;
57314
57716
  } catch (error) {
57315
- import_node_server_utils245.logger.log({ level: "error", message: error.message });
57717
+ import_node_server_utils246.logger.log({ level: "error", message: error.message });
57718
+ next(error);
57719
+ return;
57720
+ }
57721
+ }
57722
+ async function updateFormEntryById(req, res, next) {
57723
+ try {
57724
+ const { error, value } = schemaUpdateFormEntry.validate({
57725
+ _id: req.params.id,
57726
+ ...req.body
57727
+ });
57728
+ if (error) {
57729
+ const messages = error.details.map((d) => d.message).join(", ");
57730
+ import_node_server_utils246.logger.log({ level: "error", message: messages });
57731
+ next(new import_node_server_utils246.BadRequestError(messages));
57732
+ return;
57733
+ }
57734
+ const { _id, ...rest } = value;
57735
+ await _updateFormEntryById(_id, rest);
57736
+ res.json({ message: "Successfully updated online form." });
57737
+ return;
57738
+ } catch (error) {
57739
+ import_node_server_utils246.logger.log({ level: "error", message: error.message });
57316
57740
  next(error);
57317
57741
  return;
57318
57742
  }
@@ -57320,16 +57744,17 @@ function useFormEntryController() {
57320
57744
  return {
57321
57745
  uploadFormEntrys,
57322
57746
  getAll,
57323
- getFormEntryById
57747
+ getFormEntryById,
57748
+ updateFormEntryById
57324
57749
  };
57325
57750
  }
57326
57751
 
57327
57752
  // src/services/building-level.service.ts
57328
- var import_node_server_utils246 = require("@7365admin1/node-server-utils");
57753
+ var import_node_server_utils247 = require("@7365admin1/node-server-utils");
57329
57754
  function useBuildingLevelService() {
57330
57755
  const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
57331
57756
  async function add(value) {
57332
- const session = import_node_server_utils246.useAtlas.getClient()?.startSession();
57757
+ const session = import_node_server_utils247.useAtlas.getClient()?.startSession();
57333
57758
  try {
57334
57759
  session?.startTransaction();
57335
57760
  await _add(value, session);
@@ -57343,7 +57768,7 @@ function useBuildingLevelService() {
57343
57768
  }
57344
57769
  }
57345
57770
  async function updateLevelById(_id, value) {
57346
- const session = import_node_server_utils246.useAtlas.getClient()?.startSession();
57771
+ const session = import_node_server_utils247.useAtlas.getClient()?.startSession();
57347
57772
  try {
57348
57773
  session?.startTransaction();
57349
57774
  await _updateLevelById(_id, value, session);
@@ -57363,7 +57788,7 @@ function useBuildingLevelService() {
57363
57788
  }
57364
57789
 
57365
57790
  // src/controllers/building-level.controller.ts
57366
- var import_node_server_utils247 = require("@7365admin1/node-server-utils");
57791
+ var import_node_server_utils248 = require("@7365admin1/node-server-utils");
57367
57792
  var import_joi143 = __toESM(require("joi"));
57368
57793
  function useBuildingLevelController() {
57369
57794
  const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
@@ -57379,8 +57804,8 @@ function useBuildingLevelController() {
57379
57804
  });
57380
57805
  if (error) {
57381
57806
  const messages = error.details.map((d) => d.message).join(", ");
57382
- import_node_server_utils247.logger.log({ level: "error", message: messages });
57383
- next(new import_node_server_utils247.BadRequestError(messages));
57807
+ import_node_server_utils248.logger.log({ level: "error", message: messages });
57808
+ next(new import_node_server_utils248.BadRequestError(messages));
57384
57809
  return;
57385
57810
  }
57386
57811
  const result = await _add(value);
@@ -57403,8 +57828,8 @@ function useBuildingLevelController() {
57403
57828
  });
57404
57829
  if (error) {
57405
57830
  const messages = error.details.map((d) => d.message);
57406
- import_node_server_utils247.logger.log({ level: "error", message: messages.join(", ") });
57407
- next(new import_node_server_utils247.BadRequestError(messages.join(", ")));
57831
+ import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
57832
+ next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
57408
57833
  return;
57409
57834
  }
57410
57835
  const { page, limit, status, site, search } = value;
@@ -57429,8 +57854,8 @@ function useBuildingLevelController() {
57429
57854
  const { error, value } = schema2.validate({ id: req.params.id });
57430
57855
  if (error) {
57431
57856
  const messages = error.details.map((d) => d.message);
57432
- import_node_server_utils247.logger.log({ level: "error", message: messages.join(", ") });
57433
- next(new import_node_server_utils247.BadRequestError(messages.join(", ")));
57857
+ import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
57858
+ next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
57434
57859
  return;
57435
57860
  }
57436
57861
  const { id } = value;
@@ -57449,8 +57874,8 @@ function useBuildingLevelController() {
57449
57874
  });
57450
57875
  if (error) {
57451
57876
  const messages = error.details.map((d) => d.message);
57452
- import_node_server_utils247.logger.log({ level: "error", message: messages.join(", ") });
57453
- next(new import_node_server_utils247.BadRequestError(messages.join(", ")));
57877
+ import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
57878
+ next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
57454
57879
  return;
57455
57880
  }
57456
57881
  const { _id, ...rest } = value;
@@ -57468,8 +57893,8 @@ function useBuildingLevelController() {
57468
57893
  const { error, value } = schema2.validate({ id: req.params.id });
57469
57894
  if (error) {
57470
57895
  const messages = error.details.map((d) => d.message);
57471
- import_node_server_utils247.logger.log({ level: "error", message: messages.join(", ") });
57472
- next(new import_node_server_utils247.BadRequestError(messages.join(", ")));
57896
+ import_node_server_utils248.logger.log({ level: "error", message: messages.join(", ") });
57897
+ next(new import_node_server_utils248.BadRequestError(messages.join(", ")));
57473
57898
  return;
57474
57899
  }
57475
57900
  const { id } = value;
@@ -57685,6 +58110,7 @@ function useBuildingLevelController() {
57685
58110
  schemaFormEntry,
57686
58111
  schemaGuestManagement,
57687
58112
  schemaIncidentReport,
58113
+ schemaMultipleDocumentManagement,
57688
58114
  schemaNfcPatrolLog,
57689
58115
  schemaNfcPatrolRoute,
57690
58116
  schemaNfcPatrolTag,