@7365admin1/core 3.25.0 → 3.26.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
@@ -12122,19 +12122,22 @@ function useVerificationService() {
12122
12122
  orgId,
12123
12123
  siteId,
12124
12124
  siteName,
12125
+ app,
12125
12126
  inviteType
12126
12127
  }) {
12127
12128
  const schema2 = Joi11.object({
12128
12129
  email: Joi11.string().email().lowercase().required(),
12129
12130
  orgId: Joi11.string().hex().length(24).required(),
12130
12131
  siteId: Joi11.string().hex().length(24).required(),
12131
- siteName: Joi11.string().required()
12132
+ siteName: Joi11.string().required(),
12133
+ app: Joi11.string().required()
12132
12134
  });
12133
12135
  const { error } = schema2.validate({
12134
12136
  email,
12135
12137
  orgId,
12136
12138
  siteId,
12137
- siteName
12139
+ siteName,
12140
+ app
12138
12141
  });
12139
12142
  if (error) {
12140
12143
  const messages = error.details.map((d) => d.message).join(", ");
@@ -12149,7 +12152,8 @@ function useVerificationService() {
12149
12152
  metadata: {
12150
12153
  siteId,
12151
12154
  siteName,
12152
- org: orgId
12155
+ org: orgId,
12156
+ app
12153
12157
  },
12154
12158
  expireAt: new Date(
12155
12159
  (/* @__PURE__ */ new Date()).getTime() + 72 * 60 * 60 * 1e3
@@ -12169,7 +12173,7 @@ function useVerificationService() {
12169
12173
  const res = await _add(value);
12170
12174
  const dir = __dirname;
12171
12175
  const filePath = getDirectory(dir, `./public/handlebars/${value.type}`);
12172
- const link = `${APP_MAIN}/verify/${value.type}/${res}`;
12176
+ const link = `${APP_MAIN}/verify/service-provider-invite/${res}`;
12173
12177
  const emailContent = compileHandlebar({
12174
12178
  context: {
12175
12179
  email,
@@ -14763,6 +14767,7 @@ function useVerificationController() {
14763
14767
  orgId: Joi16.string().hex().required(),
14764
14768
  siteId: Joi16.string().hex().required(),
14765
14769
  siteName: Joi16.string().required(),
14770
+ app: Joi16.string().required(),
14766
14771
  inviteType: Joi16.string().valid("create-org", "organization-invite").required()
14767
14772
  });
14768
14773
  const { error } = validation.validate(payload);
@@ -14779,6 +14784,7 @@ function useVerificationController() {
14779
14784
  orgId,
14780
14785
  siteId,
14781
14786
  siteName,
14787
+ app,
14782
14788
  inviteType
14783
14789
  } = payload;
14784
14790
  try {
@@ -14787,6 +14793,7 @@ function useVerificationController() {
14787
14793
  orgId,
14788
14794
  siteId,
14789
14795
  siteName,
14796
+ app,
14790
14797
  inviteType
14791
14798
  });
14792
14799
  const cookieOptions = {
@@ -21252,7 +21259,8 @@ function MVisitorTransaction(value) {
21252
21259
  updatedBy: value.inviterId ?? ""
21253
21260
  } : null,
21254
21261
  arrivalTime: value.arrivalTime,
21255
- duration: value.duration
21262
+ duration: value.duration,
21263
+ members: value.members
21256
21264
  };
21257
21265
  }
21258
21266
 
@@ -34297,7 +34305,7 @@ var KeyRepo = class {
34297
34305
  findOptions
34298
34306
  );
34299
34307
  console.log("visitorId", visitorId.toString());
34300
- console.log("latestHistory.visitorId", latestHistory?.visitorId.toString());
34308
+ console.log("latestHistory.visitorId", latestHistory?.visitorId?.toString());
34301
34309
  if (latestHistory?.visitorId && latestHistory.visitorId?.toString() !== visitorId.toString()) {
34302
34310
  console.log("Not updating keyId", keyId);
34303
34311
  return;
@@ -34370,70 +34378,59 @@ var KeyRepo = class {
34370
34378
  return Promise.reject("Failed to delete key");
34371
34379
  }
34372
34380
  }
34373
- static async getById2(id) {
34374
- return this.collection().aggregate([
34375
- { $match: { _id: new ObjectId62(id) } },
34376
- {
34377
- $lookup: {
34378
- from: "qr-code-templates",
34379
- localField: "template",
34380
- foreignField: "_id",
34381
- as: "QRTemplateInfo"
34382
- }
34383
- },
34384
- {
34385
- $unwind: {
34386
- path: "$QRTemplateInfo",
34387
- preserveNullAndEmptyArrays: true
34388
- }
34389
- },
34390
- {
34391
- $addFields: {
34392
- prefixPass: { $toUpper: "$QRTemplateInfo.prefixPass" },
34393
- prefixKey: { $toUpper: "$QRTemplateInfo.prefixKey" },
34394
- templateName: "$QRTemplateInfo.name"
34395
- }
34396
- },
34397
- {
34398
- $addFields: {
34399
- prefixAndName: {
34400
- $cond: {
34401
- if: { $or: [{ $not: "$prefixPass" }, { $not: "$prefixKey" }] },
34402
- then: "$name",
34403
- else: {
34404
- $cond: {
34405
- if: { $eq: ["$passType", "pass-key"] },
34406
- then: { $concat: ["$prefixKey", "$name"] },
34407
- else: { $concat: ["$prefixPass", "$name"] }
34381
+ static async getById2(id, session) {
34382
+ return this.collection().aggregate(
34383
+ [
34384
+ { $match: { _id: new ObjectId62(id) } },
34385
+ {
34386
+ $lookup: {
34387
+ from: "qr-code-templates",
34388
+ localField: "template",
34389
+ foreignField: "_id",
34390
+ as: "QRTemplateInfo"
34391
+ }
34392
+ },
34393
+ {
34394
+ $unwind: {
34395
+ path: "$QRTemplateInfo",
34396
+ preserveNullAndEmptyArrays: true
34397
+ }
34398
+ },
34399
+ {
34400
+ $addFields: {
34401
+ prefixPass: { $toUpper: "$QRTemplateInfo.prefixPass" },
34402
+ prefixKey: { $toUpper: "$QRTemplateInfo.prefixKey" },
34403
+ templateName: "$QRTemplateInfo.name"
34404
+ }
34405
+ },
34406
+ {
34407
+ $addFields: {
34408
+ prefixAndName: {
34409
+ $cond: {
34410
+ if: { $or: [{ $not: "$prefixPass" }, { $not: "$prefixKey" }] },
34411
+ then: "$name",
34412
+ else: {
34413
+ $cond: {
34414
+ if: { $eq: ["$passType", "pass-key"] },
34415
+ then: { $concat: ["$prefixKey", "$name"] },
34416
+ else: { $concat: ["$prefixPass", "$name"] }
34417
+ }
34408
34418
  }
34409
34419
  }
34410
34420
  }
34411
34421
  }
34412
34422
  }
34413
- }
34414
- ]).toArray().then((results) => results.length ? results[0] : null);
34423
+ ],
34424
+ { session }
34425
+ ).toArray().then((results) => results.length ? results[0] : null);
34415
34426
  }
34416
- static async checkPassKeyAvailability(visitorPass, passKeys) {
34417
- if (Array.isArray(visitorPass) && visitorPass.length > 0) {
34418
- for (let i = 0; i < visitorPass.length; i++) {
34419
- let pass = await convertObjectIdUtil2(visitorPass[i].keyId, "Pass ID");
34420
- const getPass = await this.getById2(pass);
34421
- if (!getPass)
34422
- throw new Error("Pass not found");
34423
- if (getPass?.status && getPass?.status.toLowerCase() != "Available".toLowerCase())
34424
- throw new Error(`Pass ${getPass?.prefixAndName} is ${getPass?.status}`);
34425
- }
34426
- }
34427
- if (Array.isArray(passKeys) && passKeys.length > 0) {
34428
- for (let i = 0; i < passKeys.length; i++) {
34429
- let key = await convertObjectIdUtil2(passKeys[i].keyId, "Key ID");
34430
- const getPass = await this.getById2(key);
34431
- if (!getPass)
34432
- throw new Error(`Key not found`);
34433
- if (getPass?.status && getPass?.status.toLowerCase() != "Available".toLowerCase())
34434
- throw new Error(`Pass ${getPass?.prefixAndName} is ${getPass?.status}`);
34435
- }
34436
- }
34427
+ static async checkPassOrKeyAvailability(passOrKeyId, type, session) {
34428
+ let passOrKeyObjectId = await convertObjectIdUtil2(passOrKeyId, `${type} Id`);
34429
+ const getPassOrKey = await this.getById2(passOrKeyObjectId, session);
34430
+ if (!getPassOrKey)
34431
+ throw new Error(`${type} not found`);
34432
+ if (getPassOrKey?.status && getPassOrKey?.status.toLowerCase() != "Available".toLowerCase())
34433
+ throw new Error(`${type} ${getPassOrKey?.prefixAndName} is ${getPassOrKey?.status}`);
34437
34434
  }
34438
34435
  };
34439
34436
 
@@ -34798,9 +34795,6 @@ function useVisitorTransactionService() {
34798
34795
  } = value;
34799
34796
  for (let i = 0; i < value.members.length; i += chunkSize) {
34800
34797
  const chunk = value.members.slice(i, i + chunkSize);
34801
- for (const member of chunk) {
34802
- await KeyRepo.checkPassKeyAvailability(member.visitorPass, member.passKeys);
34803
- }
34804
34798
  await Promise.all(
34805
34799
  chunk.map(async (member) => {
34806
34800
  const clonedMember = structuredClone(member);
@@ -34841,6 +34835,7 @@ function useVisitorTransactionService() {
34841
34835
  );
34842
34836
  console.log("visitorId service", visitorId);
34843
34837
  for (const item of preparedVisitorPass) {
34838
+ await KeyRepo.checkPassOrKeyAvailability(item.keyId, "Pass", session);
34844
34839
  await KeyRepo.updateKeyById(
34845
34840
  item.keyId,
34846
34841
  {
@@ -34856,6 +34851,7 @@ function useVisitorTransactionService() {
34856
34851
  );
34857
34852
  }
34858
34853
  for (const item of preparedPassKeys) {
34854
+ await KeyRepo.checkPassOrKeyAvailability(item.keyId, "Key", session);
34859
34855
  await KeyRepo.updateKeyById(
34860
34856
  item.keyId,
34861
34857
  {
@@ -34898,7 +34894,6 @@ function useVisitorTransactionService() {
34898
34894
  if (found === 1)
34899
34895
  throw new BadRequestError100("This plate number is blocklisted");
34900
34896
  }
34901
- await KeyRepo.checkPassKeyAvailability(value.visitorPass, value.passKeys);
34902
34897
  if (Array.isArray(value.visitorPass)) {
34903
34898
  for (const item of value.visitorPass) {
34904
34899
  item.receivedDate = /* @__PURE__ */ new Date();
@@ -34918,6 +34913,7 @@ function useVisitorTransactionService() {
34918
34913
  const result = await _add(value, session);
34919
34914
  if (Array.isArray(value.visitorPass)) {
34920
34915
  for (const item of value.visitorPass) {
34916
+ await KeyRepo.checkPassOrKeyAvailability(item.keyId, "Pass", session);
34921
34917
  await KeyRepo.updateKeyById(
34922
34918
  item.keyId,
34923
34919
  { status: "In Use" /* IN_USE */, updatedBy: value.createdBy },
@@ -34932,6 +34928,7 @@ function useVisitorTransactionService() {
34932
34928
  }
34933
34929
  if (Array.isArray(value.passKeys)) {
34934
34930
  for (const item of value.passKeys) {
34931
+ await KeyRepo.checkPassOrKeyAvailability(item.keyId, "Key", session);
34935
34932
  await KeyRepo.updateKeyById(
34936
34933
  item.keyId,
34937
34934
  { status: "In Use" /* IN_USE */, updatedBy: value.createdBy },
@@ -35028,6 +35025,12 @@ function useVisitorTransactionService() {
35028
35025
  if (value.site) {
35029
35026
  value.site = typeof value.site === "string" ? new ObjectId63(value.site) : value.site;
35030
35027
  }
35028
+ if (value?.block) {
35029
+ value.block = await convertObjectIdUtil2(value.block, "block Id");
35030
+ }
35031
+ if (value?.level) {
35032
+ value.level = await convertObjectIdUtil2(value.level, "level Id");
35033
+ }
35031
35034
  if (value.unit) {
35032
35035
  value.unit = typeof value.unit === "string" ? new ObjectId63(value.unit) : value.unit;
35033
35036
  const unit = await _getUnitById(value.unit);
@@ -35039,6 +35042,7 @@ function useVisitorTransactionService() {
35039
35042
  if (Array.isArray(value.visitorPass)) {
35040
35043
  for (const item of value.visitorPass) {
35041
35044
  if (item.add) {
35045
+ await KeyRepo.checkPassOrKeyAvailability(item.keyId, "Pass", session);
35042
35046
  await KeyRepo.updateKeyById(
35043
35047
  item.keyId,
35044
35048
  {
@@ -35087,6 +35091,7 @@ function useVisitorTransactionService() {
35087
35091
  if (Array.isArray(value.passKeys)) {
35088
35092
  for (const item of value.passKeys) {
35089
35093
  if (item.add) {
35094
+ await KeyRepo.checkPassOrKeyAvailability(item.keyId, "Key", session);
35090
35095
  await KeyRepo.updateKeyById(
35091
35096
  item.keyId,
35092
35097
  {
@@ -57951,12 +57956,9 @@ function useNewDashboardRepo() {
57951
57956
  function getDateRange(p) {
57952
57957
  const now = moment2().tz("Asia/Singapore");
57953
57958
  if (p === "thisWeek" /* THIS_WEEK */) {
57954
- const rollingStart = now.clone().subtract(6, "days").startOf("day");
57955
- const monthStart = now.clone().startOf("month");
57956
- const start = moment2.max(rollingStart, monthStart);
57957
57959
  return {
57958
- $gte: start.toDate(),
57959
- $lte: now.clone().endOf("day").toDate()
57960
+ $gte: now.clone().startOf("isoWeek").toDate(),
57961
+ $lte: now.clone().endOf("isoWeek").toDate()
57960
57962
  };
57961
57963
  }
57962
57964
  if (p === "thisMonth" /* THIS_MONTH */) {
@@ -57970,6 +57972,12 @@ function useNewDashboardRepo() {
57970
57972
  $lte: now.clone().endOf("day").toDate()
57971
57973
  };
57972
57974
  }
57975
+ function getSiteDayRange(date = moment2.tz("Asia/Singapore")) {
57976
+ return {
57977
+ $gte: date.clone().startOf("day").toDate(),
57978
+ $lte: date.clone().endOf("day").toDate()
57979
+ };
57980
+ }
57973
57981
  const calculatePercentageChange = (currentCount, previousCount) => {
57974
57982
  if (previousCount === 0) {
57975
57983
  return currentCount > 0 ? 100 : 0;
@@ -58396,24 +58404,27 @@ function useNewDashboardRepo() {
58396
58404
  const siteIdObj = toObjectId16(siteId);
58397
58405
  const startOfToday = moment2.tz("Asia/Singapore").startOf("day").toDate();
58398
58406
  const endOfToday = moment2.tz("Asia/Singapore").endOf("day").toDate();
58399
- const localTodayStr = moment2.tz("Asia/Singapore").format("YYYY-MM-DD");
58400
- const facilityTodayStart = moment2.utc(`${localTodayStr}T00:00:00.000Z`).toDate();
58401
- const facilityTodayEnd = moment2.utc(`${localTodayStr}T23:59:59.999Z`).toDate();
58402
- const localYesterdayStr = moment2.tz("Asia/Singapore").subtract(1, "day").format("YYYY-MM-DD");
58403
- const facilityYesterdayStart = moment2.utc(`${localYesterdayStr}T00:00:00.000Z`).toDate();
58404
- const facilityYesterdayEnd = moment2.utc(`${localYesterdayStr}T23:59:59.999Z`).toDate();
58405
- let facilityPeriodRange = { $gte: facilityTodayStart, $lte: facilityTodayEnd };
58407
+ const facilityTodayRange = getSiteDayRange();
58408
+ const facilityYesterdayRange = getSiteDayRange(
58409
+ moment2.tz("Asia/Singapore").subtract(1, "day")
58410
+ );
58411
+ const facilityTodayStart = facilityTodayRange.$gte;
58412
+ const facilityTodayEnd = facilityTodayRange.$lte;
58413
+ const facilityYesterdayStart = facilityYesterdayRange.$gte;
58414
+ const facilityYesterdayEnd = facilityYesterdayRange.$lte;
58415
+ let facilityPeriodRange = {
58416
+ $gte: facilityTodayStart,
58417
+ $lte: facilityTodayEnd
58418
+ };
58406
58419
  if (period === "thisWeek" /* THIS_WEEK */) {
58407
- const startStr = moment2.tz("Asia/Singapore").subtract(7, "days").format("YYYY-MM-DD");
58408
58420
  facilityPeriodRange = {
58409
- $gte: moment2.utc(`${startStr}T00:00:00.000Z`).toDate(),
58410
- $lte: facilityTodayEnd
58421
+ $gte: moment2.tz("Asia/Singapore").startOf("isoWeek").toDate(),
58422
+ $lte: moment2.tz("Asia/Singapore").endOf("isoWeek").toDate()
58411
58423
  };
58412
58424
  } else if (period === "thisMonth" /* THIS_MONTH */) {
58413
- const startStr = moment2.tz("Asia/Singapore").subtract(30, "days").format("YYYY-MM-DD");
58414
58425
  facilityPeriodRange = {
58415
- $gte: moment2.utc(`${startStr}T00:00:00.000Z`).toDate(),
58416
- $lte: facilityTodayEnd
58426
+ $gte: moment2.tz("Asia/Singapore").startOf("month").toDate(),
58427
+ $lte: moment2.tz("Asia/Singapore").endOf("month").toDate()
58417
58428
  };
58418
58429
  }
58419
58430
  const upcomingEvents = await db.collection(events_namespace_collection).find({
@@ -58497,6 +58508,18 @@ function useNewDashboardRepo() {
58497
58508
  const facilityCollection = db.collection(
58498
58509
  facility_bookings_namespace_collection2
58499
58510
  );
58511
+ const facilityBookingStatuses = [
58512
+ "Pending",
58513
+ "Approved",
58514
+ "Ongoing",
58515
+ "For Review",
58516
+ "With Balance",
58517
+ "For Refund",
58518
+ "With Refund",
58519
+ "Completed",
58520
+ "Rejected",
58521
+ "Cancelled"
58522
+ ];
58500
58523
  const [
58501
58524
  workOrderReport,
58502
58525
  yesterdayWorkOrderReport,
@@ -58647,7 +58670,7 @@ function useNewDashboardRepo() {
58647
58670
  }
58648
58671
  }
58649
58672
  ],
58650
- status: { $nin: ["deleted", "Deleted"] }
58673
+ status: { $in: facilityBookingStatuses }
58651
58674
  }
58652
58675
  },
58653
58676
  {
@@ -58672,6 +58695,25 @@ function useNewDashboardRepo() {
58672
58695
  }
58673
58696
  },
58674
58697
  { $count: "count" }
58698
+ ],
58699
+ byStatus: [
58700
+ {
58701
+ $match: {
58702
+ status: { $in: facilityBookingStatuses }
58703
+ }
58704
+ },
58705
+ {
58706
+ $group: {
58707
+ _id: {
58708
+ $cond: [
58709
+ { $eq: ["$status", "For Refund"] },
58710
+ "With Refund",
58711
+ "$status"
58712
+ ]
58713
+ },
58714
+ count: { $sum: 1 }
58715
+ }
58716
+ }
58675
58717
  ]
58676
58718
  }
58677
58719
  }
@@ -58682,7 +58724,12 @@ function useNewDashboardRepo() {
58682
58724
  site: { $in: [siteIdObj, siteId] },
58683
58725
  ...facilityMatchObj,
58684
58726
  $or: [
58685
- { date: { $gte: facilityYesterdayStart, $lte: facilityYesterdayEnd } },
58727
+ {
58728
+ date: {
58729
+ $gte: facilityYesterdayStart,
58730
+ $lte: facilityYesterdayEnd
58731
+ }
58732
+ },
58686
58733
  {
58687
58734
  date: {
58688
58735
  $gte: facilityYesterdayStart.toISOString(),
@@ -58690,7 +58737,7 @@ function useNewDashboardRepo() {
58690
58737
  }
58691
58738
  }
58692
58739
  ],
58693
- status: { $nin: ["deleted", "Deleted"] }
58740
+ status: { $in: facilityBookingStatuses }
58694
58741
  }
58695
58742
  },
58696
58743
  { $count: "count" }
@@ -58709,7 +58756,7 @@ function useNewDashboardRepo() {
58709
58756
  }
58710
58757
  }
58711
58758
  ],
58712
- status: { $nin: ["deleted", "Deleted"] }
58759
+ status: { $in: facilityBookingStatuses }
58713
58760
  }
58714
58761
  },
58715
58762
  { $count: "count" }
@@ -58733,8 +58780,25 @@ function useNewDashboardRepo() {
58733
58780
  const fFacet = facilityReport[0] ?? {
58734
58781
  total: [],
58735
58782
  ongoing: [],
58736
- waitingApproval: []
58783
+ waitingApproval: [],
58784
+ byStatus: []
58785
+ };
58786
+ const facilityBookingStatusCounts = {
58787
+ Pending: 0,
58788
+ Approved: 0,
58789
+ Ongoing: 0,
58790
+ "For Review": 0,
58791
+ "With Balance": 0,
58792
+ "With Refund": 0,
58793
+ Completed: 0,
58794
+ Rejected: 0,
58795
+ Cancelled: 0
58737
58796
  };
58797
+ for (const item of fFacet.byStatus ?? []) {
58798
+ if (typeof item?._id === "string" && item._id in facilityBookingStatusCounts) {
58799
+ facilityBookingStatusCounts[item._id] = item.count ?? 0;
58800
+ }
58801
+ }
58738
58802
  const workOrderStatus = {
58739
58803
  pending: 0,
58740
58804
  inProgress: 0,
@@ -58781,6 +58845,7 @@ function useNewDashboardRepo() {
58781
58845
  count: fFacet.total[0]?.count ?? 0,
58782
58846
  ongoing: fFacet.ongoing[0]?.count ?? 0,
58783
58847
  waitingApproval: fFacet.waitingApproval[0]?.count ?? 0,
58848
+ byStatus: facilityBookingStatusCounts,
58784
58849
  percentage: calculatePercentageChange(
58785
58850
  todayFacilityReport[0]?.count ?? 0,
58786
58851
  yesterdayFacilityReport[0]?.count ?? 0
@@ -63568,9 +63633,12 @@ var useRedDotPaymentRepo = () => {
63568
63633
  }
63569
63634
  const now = /* @__PURE__ */ new Date();
63570
63635
  const unitUpdate = {
63636
+ method: payload.method,
63637
+ message: payload.message,
63571
63638
  updatedAt: now.toISOString(),
63572
63639
  paymentStatus: payload.paymentStatus,
63573
- transaction_id: payload.transaction_id
63640
+ transaction_id: payload.transaction_id,
63641
+ paidBy: paymentInfo.paidBy
63574
63642
  };
63575
63643
  const paymentUpdate = {
63576
63644
  updatedAt: now.toISOString(),