@7365admin1/core 3.30.0 → 3.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -36319,7 +36319,6 @@ function usePersonService() {
36319
36319
  }
36320
36320
  return "People added successfully.";
36321
36321
  } catch (error) {
36322
- console.log("error message service", error);
36323
36322
  logger84.error("Error in people service add:", error);
36324
36323
  await session.abortTransaction();
36325
36324
  throw error;
@@ -36476,8 +36475,8 @@ function usePersonService() {
36476
36475
  phoneNumber: person.contact,
36477
36476
  org: person.org.toString(),
36478
36477
  site: person.site.toString(),
36479
- block: person.block ?? void 0,
36480
- level: person.level ?? void 0,
36478
+ block: person.block?.toString() ?? void 0,
36479
+ level: person.level?.toString() ?? void 0,
36481
36480
  unit: person.unit?.toString() ?? void 0,
36482
36481
  nric: person.nric,
36483
36482
  status: "active",
@@ -51474,6 +51473,11 @@ var schemaCreateNfcPatrolLog = Joi89.object({
51474
51473
  startTime: Joi89.string().required(),
51475
51474
  createdBy: Joi89.string().length(24).hex().optional().allow("", null)
51476
51475
  });
51476
+ var schemaSignNfcPatrolLog = Joi89.object({
51477
+ guardName: Joi89.string().required(),
51478
+ guardSignatureFileId: Joi89.string().length(24).hex().required(),
51479
+ signedAt: Joi89.date().optional()
51480
+ });
51477
51481
  var schemaNfcPatrolLog = Joi89.object({
51478
51482
  _id: Joi89.string().length(24).hex().optional().allow(null, ""),
51479
51483
  site: Joi89.string().length(24).hex().required(),
@@ -51512,6 +51516,7 @@ var schemaNfcPatrolLog = Joi89.object({
51512
51516
  skippedRemarks: Joi89.string().required()
51513
51517
  })
51514
51518
  ).min(0).required(),
51519
+ sign: schemaSignNfcPatrolLog.optional(),
51515
51520
  createdBy: Joi89.string().length(24).hex().optional().allow(null, ""),
51516
51521
  createdAt: Joi89.date().optional()
51517
51522
  });
@@ -51547,6 +51552,15 @@ function MNfcPatrolLog(valueArg) {
51547
51552
  throw new BadRequestError149("Invalid route _id format");
51548
51553
  }
51549
51554
  }
51555
+ if (value.sign?.guardSignatureFileId) {
51556
+ try {
51557
+ value.sign.guardSignatureFileId = new ObjectId100(
51558
+ value.sign.guardSignatureFileId
51559
+ );
51560
+ } catch {
51561
+ throw new BadRequestError149("Invalid guardSignatureFileId format");
51562
+ }
51563
+ }
51550
51564
  return {
51551
51565
  _id: value._id ?? new ObjectId100(),
51552
51566
  site: value.site,
@@ -51555,6 +51569,7 @@ function MNfcPatrolLog(valueArg) {
51555
51569
  startDateTime: value.startDateTime,
51556
51570
  endDateTime: value.endDateTime,
51557
51571
  checkPoints: value.checkPoints,
51572
+ sign: value.sign,
51558
51573
  createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
51559
51574
  createdBy: value.createdBy ?? void 0
51560
51575
  };
@@ -53033,8 +53048,8 @@ function useStatementOfAccountRepo() {
53033
53048
  async function createIndexes() {
53034
53049
  try {
53035
53050
  await collection.createIndexes([
53036
- { key: { site: 1, status: 1 } },
53037
- { key: { site: 1, unitId: 1, status: 1 } },
53051
+ { key: { site: 1, status: 1, createdAt: -1 } },
53052
+ { key: { site: 1, unitId: 1, status: 1, createdAt: -1 } },
53038
53053
  { key: { createdAt: -1 } }
53039
53054
  ]);
53040
53055
  return `Successfully created indexes for ${namespace_collection}.`;
@@ -53100,12 +53115,7 @@ function useStatementOfAccountRepo() {
53100
53115
  let endDate = new Date(dateTo);
53101
53116
  endDate.setHours(23, 59, 59, 999);
53102
53117
  dateExpr = {
53103
- $expr: {
53104
- $and: [
53105
- { $gte: ["$createdAt", startDate] },
53106
- { $lte: ["$createdAt", endDate] }
53107
- ]
53108
- }
53118
+ createdAt: { $gte: startDate, $lte: endDate }
53109
53119
  };
53110
53120
  }
53111
53121
  const unitSearchRegex = search ? search.trim().replace(/\s+/g, "").replace(/\//g, "\\s*/\\s*") : null;
@@ -53290,12 +53300,7 @@ function useStatementOfAccountRepo() {
53290
53300
  let endDate = new Date(dateTo);
53291
53301
  endDate.setHours(23, 59, 59, 999);
53292
53302
  dateExpr = {
53293
- $expr: {
53294
- $and: [
53295
- { $gte: ["$createdAt", startDate] },
53296
- { $lte: ["$createdAt", endDate] }
53297
- ]
53298
- }
53303
+ createdAt: { $gte: startDate, $lte: endDate }
53299
53304
  };
53300
53305
  }
53301
53306
  const unitSearchRegex = search ? search.trim().replace(/\s+/g, "").replace(/\//g, "\\s*/\\s*") : null;
@@ -58346,18 +58351,35 @@ function useNfcPatrolLogRepo() {
58346
58351
  delCachedData();
58347
58352
  return res;
58348
58353
  }
58354
+ async function sign(id, value, session) {
58355
+ id = new ObjectId121(id);
58356
+ await collection.updateOne(
58357
+ { _id: id },
58358
+ {
58359
+ $set: {
58360
+ sign: {
58361
+ ...value,
58362
+ signedAt: /* @__PURE__ */ new Date()
58363
+ }
58364
+ }
58365
+ },
58366
+ { session }
58367
+ );
58368
+ }
58349
58369
  return {
58350
58370
  createIndexes,
58351
58371
  add,
58352
58372
  getAllBySite,
58353
58373
  getById,
58354
- updateCheckpoint
58374
+ updateCheckpoint,
58375
+ sign
58355
58376
  };
58356
58377
  }
58357
58378
 
58358
58379
  // src/services/nfc-patrol-log.service.ts
58359
58380
  import {
58360
58381
  BadRequestError as BadRequestError180,
58382
+ NotFoundError as NotFoundError50,
58361
58383
  useAtlas as useAtlas100
58362
58384
  } from "@7365admin1/node-server-utils";
58363
58385
  function useNfcPatrolLogService() {
@@ -58365,7 +58387,8 @@ function useNfcPatrolLogService() {
58365
58387
  add: _add,
58366
58388
  getById,
58367
58389
  updateCheckpoint,
58368
- getAllBySite: _getAllBySite
58390
+ getAllBySite: _getAllBySite,
58391
+ sign: repoSign
58369
58392
  } = useNfcPatrolLogRepo();
58370
58393
  const routeRepo = useNfcPatrolRouteRepo();
58371
58394
  const tagRepo = useNfcPatrolTagRepo();
@@ -58501,9 +58524,26 @@ function useNfcPatrolLogService() {
58501
58524
  await session?.endSession();
58502
58525
  }
58503
58526
  }
58527
+ async function sign(id, value) {
58528
+ const log = await getById(id);
58529
+ if (!log) {
58530
+ throw new NotFoundError50("Patrol log not found.");
58531
+ }
58532
+ const canSign = log.checkPoints.every(
58533
+ (c) => c.status === "Completed" || c.status === "Skipped"
58534
+ );
58535
+ if (!canSign) {
58536
+ throw new BadRequestError180(
58537
+ "All checkpoints must be completed or skipped before signing."
58538
+ );
58539
+ }
58540
+ await repoSign(id, value);
58541
+ return "Successfully signed patrol.";
58542
+ }
58504
58543
  return {
58505
58544
  add,
58506
- completeCheckpoint
58545
+ completeCheckpoint,
58546
+ sign
58507
58547
  };
58508
58548
  }
58509
58549
 
@@ -58514,7 +58554,7 @@ import {
58514
58554
  } from "@7365admin1/node-server-utils";
58515
58555
  import Joi111 from "joi";
58516
58556
  function useNfcPatrolLogController() {
58517
- const { add: _add, completeCheckpoint: _completeCheckpoint } = useNfcPatrolLogService();
58557
+ const { add: _add, completeCheckpoint: _completeCheckpoint, sign: _sign } = useNfcPatrolLogService();
58518
58558
  const { getAllBySite: _getAllBySite, getById: _getById } = useNfcPatrolLogRepo();
58519
58559
  async function add(req, res, next) {
58520
58560
  try {
@@ -58606,11 +58646,26 @@ function useNfcPatrolLogController() {
58606
58646
  next(error);
58607
58647
  }
58608
58648
  }
58649
+ async function sign(req, res, next) {
58650
+ try {
58651
+ const value = await schemaSignNfcPatrolLog.validateAsync(req.body);
58652
+ const result = await _sign(
58653
+ req.params.id,
58654
+ value
58655
+ );
58656
+ res.json({
58657
+ message: result
58658
+ });
58659
+ } catch (err) {
58660
+ next(err);
58661
+ }
58662
+ }
58609
58663
  return {
58610
58664
  add,
58611
58665
  getAllBySite,
58612
58666
  completeCheckpoint,
58613
- getLog
58667
+ getLog,
58668
+ sign
58614
58669
  };
58615
58670
  }
58616
58671
 
@@ -64722,7 +64777,7 @@ import {
64722
64777
  logger as logger181,
64723
64778
  getDirectory as getDirectory5,
64724
64779
  BadRequestError as BadRequestError202,
64725
- NotFoundError as NotFoundError52,
64780
+ NotFoundError as NotFoundError53,
64726
64781
  InternalServerError as InternalServerError70,
64727
64782
  useAtlas as useAtlas115,
64728
64783
  hashPassword as hashPassword4
@@ -64853,7 +64908,7 @@ function useVerificationServiceV2() {
64853
64908
  session?.startTransaction();
64854
64909
  const item = await _getByVerificationCode(verificationCode);
64855
64910
  if (!item) {
64856
- throw new NotFoundError52("Verification not found.");
64911
+ throw new NotFoundError53("Verification not found.");
64857
64912
  }
64858
64913
  switch (item.status) {
64859
64914
  case "expired" /* EXPIRED */:
@@ -65091,7 +65146,7 @@ function useVerificationServiceV2() {
65091
65146
  async function resendSignUpVerification(email) {
65092
65147
  const item = await _getPendingVerificationByEmail(email);
65093
65148
  if (!item) {
65094
- throw new NotFoundError52(
65149
+ throw new NotFoundError53(
65095
65150
  "Pending verification not found."
65096
65151
  );
65097
65152
  }
@@ -65411,7 +65466,7 @@ import {
65411
65466
  BadRequestError as BadRequestError205,
65412
65467
  comparePassword as comparePassword3,
65413
65468
  InternalServerError as InternalServerError72,
65414
- NotFoundError as NotFoundError54,
65469
+ NotFoundError as NotFoundError55,
65415
65470
  useCache as useCache68
65416
65471
  } from "@7365admin1/node-server-utils";
65417
65472
  import { v4 as uuidv42 } from "uuid";
@@ -65424,7 +65479,7 @@ import {
65424
65479
  logger as logger183,
65425
65480
  BadRequestError as BadRequestError204,
65426
65481
  paginate as paginate60,
65427
- NotFoundError as NotFoundError53,
65482
+ NotFoundError as NotFoundError54,
65428
65483
  AppError as AppError29,
65429
65484
  useCache as useCache67,
65430
65485
  makeCacheKey as makeCacheKey65,
@@ -65557,7 +65612,7 @@ function useUserRepoV2() {
65557
65612
  ]).toArray();
65558
65613
  const data = results.length > 0 ? results[0] : null;
65559
65614
  if (!data)
65560
- throw new NotFoundError53("User not found.");
65615
+ throw new NotFoundError54("User not found.");
65561
65616
  setCache(cacheKey, data, 15 * 60).then(() => logger183.info(`Cache set for key: ${cacheKey}`)).catch(
65562
65617
  (err) => logger183.error(`Failed to set cache for key: ${cacheKey}`, err)
65563
65618
  );
@@ -65898,7 +65953,7 @@ function useAuthServiceV2() {
65898
65953
  try {
65899
65954
  const user = await getUserByEmail(email);
65900
65955
  if (!user) {
65901
- throw new NotFoundError54(
65956
+ throw new NotFoundError55(
65902
65957
  "Invalid user email. Please check your email and try again."
65903
65958
  );
65904
65959
  }
@@ -65973,7 +66028,7 @@ import {
65973
66028
  comparePassword as comparePassword4,
65974
66029
  hashPassword as hashPassword5,
65975
66030
  InternalServerError as InternalServerError73,
65976
- NotFoundError as NotFoundError55,
66031
+ NotFoundError as NotFoundError56,
65977
66032
  useAtlas as useAtlas117,
65978
66033
  useS3 as useS33
65979
66034
  } from "@7365admin1/node-server-utils";
@@ -66077,14 +66132,14 @@ function useUserServiceV2() {
66077
66132
  try {
66078
66133
  const otpDoc = await _getVerificationById(id);
66079
66134
  if (!otpDoc) {
66080
- throw new NotFoundError55("You are using an invalid reset link.");
66135
+ throw new NotFoundError56("You are using an invalid reset link.");
66081
66136
  }
66082
66137
  if (otpDoc.status === "complete" /* COMPLETE */) {
66083
66138
  throw new BadRequestError206("This link has already been invalidated.");
66084
66139
  }
66085
66140
  const user = await _getUserByEmail(otpDoc.email);
66086
66141
  if (!user) {
66087
- throw new NotFoundError55("User not found.");
66142
+ throw new NotFoundError56("User not found.");
66088
66143
  }
66089
66144
  if (!user._id) {
66090
66145
  throw new InternalServerError73("Invalid user ID.");
@@ -66911,7 +66966,7 @@ function MPost(value) {
66911
66966
  import {
66912
66967
  BadRequestError as BadRequestError212,
66913
66968
  InternalServerError as InternalServerError75,
66914
- NotFoundError as NotFoundError56,
66969
+ NotFoundError as NotFoundError57,
66915
66970
  paginate as paginate61,
66916
66971
  useAtlas as useAtlas119
66917
66972
  } from "@7365admin1/node-server-utils";
@@ -67036,7 +67091,7 @@ function usePostPrelovedRepo() {
67036
67091
  ]).toArray();
67037
67092
  const data = result[0] ?? null;
67038
67093
  if (!data)
67039
- throw new NotFoundError56("Post not found.");
67094
+ throw new NotFoundError57("Post not found.");
67040
67095
  return data;
67041
67096
  } catch (error) {
67042
67097
  throw error;
@@ -67300,7 +67355,7 @@ import { useAtlas as useAtlas121 } from "@7365admin1/node-server-utils";
67300
67355
  import {
67301
67356
  BadRequestError as BadRequestError213,
67302
67357
  InternalServerError as InternalServerError76,
67303
- NotFoundError as NotFoundError57,
67358
+ NotFoundError as NotFoundError58,
67304
67359
  useAtlas as useAtlas120
67305
67360
  } from "@7365admin1/node-server-utils";
67306
67361
  import { ObjectId as ObjectId140 } from "mongodb";
@@ -67386,7 +67441,7 @@ function usePostFavoriteRepo() {
67386
67441
  }
67387
67442
  const result = await collection.findOne({ _id });
67388
67443
  if (!result)
67389
- throw new NotFoundError57("Favorite not found.");
67444
+ throw new NotFoundError58("Favorite not found.");
67390
67445
  return result;
67391
67446
  }
67392
67447
  async function getByPostId(postId) {
@@ -67397,7 +67452,7 @@ function usePostFavoriteRepo() {
67397
67452
  }
67398
67453
  const result = await collection.findOne({ postId });
67399
67454
  if (!result)
67400
- throw new NotFoundError57("Favorite not found.");
67455
+ throw new NotFoundError58("Favorite not found.");
67401
67456
  return result;
67402
67457
  }
67403
67458
  async function updateById(_id, userId, session) {
@@ -67903,7 +67958,7 @@ function MCategoryPreloved(value) {
67903
67958
  import {
67904
67959
  BadRequestError as BadRequestError216,
67905
67960
  InternalServerError as InternalServerError77,
67906
- NotFoundError as NotFoundError58,
67961
+ NotFoundError as NotFoundError59,
67907
67962
  useAtlas as useAtlas123
67908
67963
  } from "@7365admin1/node-server-utils";
67909
67964
  import { ObjectId as ObjectId143 } from "mongodb";
@@ -67946,7 +68001,7 @@ function useCategoryPrelovedRepo() {
67946
68001
  try {
67947
68002
  const data = await collection.findOne({ _id: objectId2 });
67948
68003
  if (!data) {
67949
- throw new NotFoundError58("Category not found.");
68004
+ throw new NotFoundError59("Category not found.");
67950
68005
  }
67951
68006
  return data;
67952
68007
  } catch (error) {
@@ -67975,7 +68030,7 @@ function useCategoryPrelovedRepo() {
67975
68030
  }
67976
68031
  const existing = await collection.findOne({ _id: objectId2 });
67977
68032
  if (!existing)
67978
- throw new NotFoundError58("Category not found.");
68033
+ throw new NotFoundError59("Category not found.");
67979
68034
  const res = await collection.updateOne(
67980
68035
  { _id: objectId2 },
67981
68036
  { $set: { ...value, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
@@ -67993,7 +68048,7 @@ function useCategoryPrelovedRepo() {
67993
68048
  }
67994
68049
  const existing = await collection.findOne({ _id: objectId2 });
67995
68050
  if (!existing)
67996
- throw new NotFoundError58("Category not found.");
68051
+ throw new NotFoundError59("Category not found.");
67997
68052
  const res = await collection.deleteOne({ _id: objectId2 });
67998
68053
  if (res.deletedCount === 0)
67999
68054
  throw new InternalServerError77("Unable to delete category.");
@@ -68160,7 +68215,7 @@ function MSubcategoryPreloved(value) {
68160
68215
  import {
68161
68216
  BadRequestError as BadRequestError218,
68162
68217
  InternalServerError as InternalServerError78,
68163
- NotFoundError as NotFoundError59,
68218
+ NotFoundError as NotFoundError60,
68164
68219
  useAtlas as useAtlas124
68165
68220
  } from "@7365admin1/node-server-utils";
68166
68221
  import { ObjectId as ObjectId145 } from "mongodb";
@@ -68211,7 +68266,7 @@ function useSubcategoryPrelovedRepo() {
68211
68266
  try {
68212
68267
  const data = await collection.findOne({ _id: objectId2 });
68213
68268
  if (!data) {
68214
- throw new NotFoundError59("Subcategory not found.");
68269
+ throw new NotFoundError60("Subcategory not found.");
68215
68270
  }
68216
68271
  return data;
68217
68272
  } catch (error) {
@@ -68486,7 +68541,7 @@ function MChatPreloved(value) {
68486
68541
  import {
68487
68542
  BadRequestError as BadRequestError220,
68488
68543
  InternalServerError as InternalServerError79,
68489
- NotFoundError as NotFoundError60,
68544
+ NotFoundError as NotFoundError61,
68490
68545
  useAtlas as useAtlas125
68491
68546
  } from "@7365admin1/node-server-utils";
68492
68547
  import { ObjectId as ObjectId147 } from "mongodb";
@@ -68514,7 +68569,7 @@ function useChatPrelovedRepo() {
68514
68569
  }
68515
68570
  const existing = await collection.findOne({ _id: objectId2 });
68516
68571
  if (!existing)
68517
- throw new NotFoundError60("Chat not found.");
68572
+ throw new NotFoundError61("Chat not found.");
68518
68573
  value.edited = true;
68519
68574
  value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
68520
68575
  const res = await collection.updateOne({ _id: objectId2 }, { $set: value });
@@ -68531,7 +68586,7 @@ function useChatPrelovedRepo() {
68531
68586
  }
68532
68587
  const existing = await collection.findOne({ _id: objectId2 });
68533
68588
  if (!existing)
68534
- throw new NotFoundError60("Chat not found.");
68589
+ throw new NotFoundError61("Chat not found.");
68535
68590
  const res = await collection.updateOne(
68536
68591
  { _id: objectId2 },
68537
68592
  { $set: { deletedAt: (/* @__PURE__ */ new Date()).toISOString(), updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
@@ -69212,7 +69267,7 @@ function MBidPreloved(value) {
69212
69267
  // src/repositories/bid-preloved.repo.ts
69213
69268
  import {
69214
69269
  InternalServerError as InternalServerError82,
69215
- NotFoundError as NotFoundError61,
69270
+ NotFoundError as NotFoundError62,
69216
69271
  useAtlas as useAtlas128
69217
69272
  } from "@7365admin1/node-server-utils";
69218
69273
  import { ObjectId as ObjectId151 } from "mongodb";
@@ -69234,7 +69289,7 @@ function useBidPrelovedRepo() {
69234
69289
  const objectId2 = typeof _id === "string" ? new ObjectId151(_id) : _id;
69235
69290
  const existing = await collection.findOne({ _id: objectId2 });
69236
69291
  if (!existing)
69237
- throw new NotFoundError61("Bid not found.");
69292
+ throw new NotFoundError62("Bid not found.");
69238
69293
  const res = await collection.updateOne(
69239
69294
  { _id: objectId2 },
69240
69295
  { $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } }
@@ -69248,7 +69303,7 @@ function useBidPrelovedRepo() {
69248
69303
  _id = new ObjectId151(_id);
69249
69304
  const result = await collection.findOne({ _id });
69250
69305
  if (!result)
69251
- throw new NotFoundError61("Bid not found.");
69306
+ throw new NotFoundError62("Bid not found.");
69252
69307
  return result;
69253
69308
  }
69254
69309
  return { add, getById, updateStatus };
@@ -69529,7 +69584,7 @@ import {
69529
69584
  InternalServerError as InternalServerError84,
69530
69585
  logger as logger197,
69531
69586
  makeCacheKey as makeCacheKey66,
69532
- NotFoundError as NotFoundError62,
69587
+ NotFoundError as NotFoundError63,
69533
69588
  paginate as paginate64,
69534
69589
  useAtlas as useAtlas130,
69535
69590
  useCache as useCache71
@@ -69634,7 +69689,7 @@ function useFormEntryRepo() {
69634
69689
  try {
69635
69690
  const [data] = await collection.aggregate([{ $match: query }]).toArray();
69636
69691
  if (!data) {
69637
- throw new NotFoundError62("Document not found.");
69692
+ throw new NotFoundError63("Document not found.");
69638
69693
  }
69639
69694
  return data;
69640
69695
  } catch (error) {
@@ -69658,11 +69713,11 @@ function useFormEntryRepo() {
69658
69713
  }
69659
69714
  const onlineFormRequest = await collection.findOne({ _id });
69660
69715
  if (!onlineFormRequest) {
69661
- throw new NotFoundError62("Online form not found.");
69716
+ throw new NotFoundError63("Online form not found.");
69662
69717
  }
69663
69718
  const user = await getUserById(onlineFormRequest.userId.toString());
69664
69719
  if (!user || !user._id) {
69665
- throw new NotFoundError62("User not found.");
69720
+ throw new NotFoundError63("User not found.");
69666
69721
  }
69667
69722
  const userId = user._id.toString();
69668
69723
  await NotificationService.onlineFormRequestStatusUpdated({
@@ -72043,6 +72098,7 @@ export {
72043
72098
  schemaPostFavorite,
72044
72099
  schemaServiceProvider,
72045
72100
  schemaServiceProviderBilling,
72101
+ schemaSignNfcPatrolLog,
72046
72102
  schemaSiteCamera,
72047
72103
  schemaSiteFacility,
72048
72104
  schemaSiteFacilityBooking,