@7365admin1/core 2.31.2 → 2.33.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
@@ -13094,6 +13094,7 @@ var VisitorStatus = /* @__PURE__ */ ((VisitorStatus2) => {
13094
13094
  VisitorStatus2["REGISTERED"] = "registered";
13095
13095
  VisitorStatus2["UNREGISTERED"] = "unregistered";
13096
13096
  VisitorStatus2["PENDING"] = "pending";
13097
+ VisitorStatus2["APPROVED"] = "approved";
13097
13098
  return VisitorStatus2;
13098
13099
  })(VisitorStatus || {});
13099
13100
  var schemaVisitorTransaction = Joi36.object({
@@ -13455,7 +13456,8 @@ function useVisitorTransactionRepo() {
13455
13456
  $project: {
13456
13457
  _id: 1,
13457
13458
  prefixPass: 1,
13458
- name: 1
13459
+ name: 1,
13460
+ remarks: 1
13459
13461
  }
13460
13462
  }
13461
13463
  ],
@@ -13468,6 +13470,9 @@ function useVisitorTransactionRepo() {
13468
13470
  keyId: "$_id",
13469
13471
  status: 1,
13470
13472
  description: 1,
13473
+ remarks: {
13474
+ $arrayElemAt: ["$template.remarks", 0]
13475
+ },
13471
13476
  templatePrefixPass: {
13472
13477
  $arrayElemAt: ["$template.prefixPass", 0]
13473
13478
  },
@@ -13504,7 +13509,8 @@ function useVisitorTransactionRepo() {
13504
13509
  $project: {
13505
13510
  _id: 1,
13506
13511
  prefixPass: 1,
13507
- name: 1
13512
+ name: 1,
13513
+ remarks: 1
13508
13514
  }
13509
13515
  }
13510
13516
  ],
@@ -13517,6 +13523,9 @@ function useVisitorTransactionRepo() {
13517
13523
  keyId: "$_id",
13518
13524
  status: 1,
13519
13525
  description: 1,
13526
+ remarks: {
13527
+ $arrayElemAt: ["$template.remarks", 0]
13528
+ },
13520
13529
  templatePrefixPass: {
13521
13530
  $arrayElemAt: ["$template.prefixPass", 0]
13522
13531
  },
@@ -17496,6 +17505,9 @@ function useBuildingUnitRepo() {
17496
17505
  return billing;
17497
17506
  });
17498
17507
  }
17508
+ if (value.owner) {
17509
+ value.owner = new ObjectId48(value.owner);
17510
+ }
17499
17511
  try {
17500
17512
  const res = await collection.updateOne(
17501
17513
  { _id },
@@ -22054,7 +22066,7 @@ function useVisitorTransactionService() {
22054
22066
  unitName: unit?.name,
22055
22067
  org: inviter?.org.toString(),
22056
22068
  site: inviter?.site.toString(),
22057
- status: "pending" /* PENDING */,
22069
+ status: "approved" /* APPROVED */,
22058
22070
  invitedId: inviter?._id
22059
22071
  };
22060
22072
  const result = await _add(payload);
@@ -22871,6 +22883,14 @@ function usePersonService() {
22871
22883
  );
22872
22884
  }
22873
22885
  }
22886
+ if (value.isOwner && value.unit) {
22887
+ const unit = await _getUnitById(value.unit.toString());
22888
+ await updateUnitById(
22889
+ unit?._id?.toString() || "",
22890
+ { ownerName: value.name, owner: value._id },
22891
+ session
22892
+ );
22893
+ }
22874
22894
  await _add(value, session);
22875
22895
  await session.commitTransaction();
22876
22896
  return "People added successfully.";
@@ -22894,18 +22914,33 @@ function usePersonService() {
22894
22914
  throw new BadRequestError100("Person not found.");
22895
22915
  }
22896
22916
  const isNameUpdated = typeof value.name === "string" && value.name.trim() !== person.name;
22897
- let unit;
22898
- if (isNameUpdated && value.unit) {
22899
- unit = await _getUnitById(value.unit.toString());
22900
- }
22901
- if (unit && unit.owner?.toString() === _id.toString()) {
22902
- await updateUnitById(
22903
- unit?._id?.toString() || "",
22904
- { ownerName: value.name },
22905
- session
22906
- );
22907
- }
22917
+ const isOwnerChanged = value.isOwner !== person.isOwner;
22908
22918
  await _updateById(_id, value, session);
22919
+ if (value.unit && (isNameUpdated || isOwnerChanged || value.isOwner)) {
22920
+ const unit = await _getUnitById(value.unit.toString());
22921
+ if (unit) {
22922
+ let updatePayload = {};
22923
+ if (isOwnerChanged) {
22924
+ if (value.isOwner) {
22925
+ updatePayload.owner = _id;
22926
+ updatePayload.ownerName = value.name || "";
22927
+ } else {
22928
+ updatePayload.owner = "";
22929
+ updatePayload.ownerName = "";
22930
+ }
22931
+ }
22932
+ if (isNameUpdated && value.isOwner && unit.owner?.toString() === _id.toString()) {
22933
+ updatePayload.ownerName = value.name;
22934
+ }
22935
+ if (value.isOwner && (!unit.owner || !unit.ownerName)) {
22936
+ updatePayload.owner = _id;
22937
+ updatePayload.ownerName = value.name || "";
22938
+ }
22939
+ if (Object.keys(updatePayload).length > 0 && unit && unit._id) {
22940
+ await updateUnitById(unit._id.toString(), updatePayload, session);
22941
+ }
22942
+ }
22943
+ }
22909
22944
  await session.commitTransaction();
22910
22945
  return "Person updated successfully.";
22911
22946
  } catch (error) {
@@ -47119,6 +47154,37 @@ function useVerificationRepoV2() {
47119
47154
  throw error;
47120
47155
  }
47121
47156
  }
47157
+ async function updateStatusById(_id, status, session) {
47158
+ try {
47159
+ _id = new ObjectId127(_id);
47160
+ } catch (error) {
47161
+ throw new BadRequestError195("Invalid verification ID format.");
47162
+ }
47163
+ try {
47164
+ const result = await collection.updateOne(
47165
+ { _id },
47166
+ { $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
47167
+ { session }
47168
+ );
47169
+ delNamespace().then(() => {
47170
+ logger175.info(`Cache cleared for namespace: ${namespace_collection}`);
47171
+ }).catch((err) => {
47172
+ logger175.error(
47173
+ `Failed to clear cache for namespace: ${namespace_collection}`,
47174
+ err
47175
+ );
47176
+ });
47177
+ const cacheKey = makeCacheKey64(namespace_collection, { _id });
47178
+ delCache(cacheKey).then(() => {
47179
+ logger175.info(`Cache deleted for key: ${cacheKey}`);
47180
+ }).catch((err) => {
47181
+ logger175.error(`Failed to delete cache for key: ${cacheKey}`, err);
47182
+ });
47183
+ return result;
47184
+ } catch (error) {
47185
+ throw new InternalServerError68("Error updating verification status.");
47186
+ }
47187
+ }
47122
47188
  return {
47123
47189
  createIndex,
47124
47190
  createTextIndex,
@@ -47126,7 +47192,8 @@ function useVerificationRepoV2() {
47126
47192
  updateVerificationStatusById,
47127
47193
  getByVerificationCode,
47128
47194
  getVerificationById,
47129
- getVerifications
47195
+ getVerifications,
47196
+ updateStatusById
47130
47197
  };
47131
47198
  }
47132
47199
 
@@ -47156,7 +47223,8 @@ function useVerificationServiceV2() {
47156
47223
  const {
47157
47224
  add: _add,
47158
47225
  updateVerificationStatusById: _updateVerificationStatusById,
47159
- getByVerificationCode: _getByVerificationCode
47226
+ getByVerificationCode: _getByVerificationCode,
47227
+ updateStatusById: _updateStatusById
47160
47228
  } = useVerificationRepoV2();
47161
47229
  const {
47162
47230
  getUserByEmailStatus: _getUserByEmailStatus,
@@ -47461,12 +47529,22 @@ function useVerificationServiceV2() {
47461
47529
  throw new InternalServerError69("Failed to create forget password link.");
47462
47530
  }
47463
47531
  }
47532
+ async function cancelUserInvitation(id) {
47533
+ try {
47534
+ await _updateStatusById(id, "cancelled");
47535
+ } catch (error) {
47536
+ throw new InternalServerError69(
47537
+ `Error cancelling user invitation: ${error}`
47538
+ );
47539
+ }
47540
+ }
47464
47541
  return {
47465
47542
  signUp,
47466
47543
  verify,
47467
47544
  createUserInvite,
47468
47545
  createServiceProviderInvite,
47469
- createForgetPassword
47546
+ createForgetPassword,
47547
+ cancelUserInvitation
47470
47548
  };
47471
47549
  }
47472
47550
 
@@ -47478,7 +47556,8 @@ function useVerificationControllerV2() {
47478
47556
  verify: _verify,
47479
47557
  createUserInvite: _createUserInvite,
47480
47558
  createServiceProviderInvite: _createServiceProviderInvite,
47481
- createForgetPassword: _createForgetPassword
47559
+ createForgetPassword: _createForgetPassword,
47560
+ cancelUserInvitation: _cancelUserInvitation
47482
47561
  } = useVerificationServiceV2();
47483
47562
  const { getVerifications: _getVerifications } = useVerificationRepoV2();
47484
47563
  async function verify(req, res, next) {
@@ -47633,12 +47712,34 @@ function useVerificationControllerV2() {
47633
47712
  return;
47634
47713
  }
47635
47714
  }
47715
+ async function cancelUserInvitation(req, res, next) {
47716
+ const validation = Joi126.string().hex().required();
47717
+ const otpId = req.params.id;
47718
+ const { error } = validation.validate(otpId);
47719
+ if (error) {
47720
+ logger177.log({ level: "error", message: `${error.message}` });
47721
+ next(new BadRequestError197(error.message));
47722
+ return;
47723
+ }
47724
+ try {
47725
+ await _cancelUserInvitation(otpId);
47726
+ res.json({
47727
+ message: "User invite has been cancelled."
47728
+ });
47729
+ return;
47730
+ } catch (error2) {
47731
+ logger177.log({ level: "error", message: `${error2.message}` });
47732
+ next(error2);
47733
+ return;
47734
+ }
47735
+ }
47636
47736
  return {
47637
47737
  verify,
47638
47738
  createUserInvite,
47639
47739
  createServiceProviderInvite,
47640
47740
  createForgetPassword,
47641
- getVerifications
47741
+ getVerifications,
47742
+ cancelUserInvitation
47642
47743
  };
47643
47744
  }
47644
47745