@7365admin1/core 2.31.2 → 2.32.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({
@@ -17496,6 +17497,9 @@ function useBuildingUnitRepo() {
17496
17497
  return billing;
17497
17498
  });
17498
17499
  }
17500
+ if (value.owner) {
17501
+ value.owner = new ObjectId48(value.owner);
17502
+ }
17499
17503
  try {
17500
17504
  const res = await collection.updateOne(
17501
17505
  { _id },
@@ -22054,7 +22058,7 @@ function useVisitorTransactionService() {
22054
22058
  unitName: unit?.name,
22055
22059
  org: inviter?.org.toString(),
22056
22060
  site: inviter?.site.toString(),
22057
- status: "pending" /* PENDING */,
22061
+ status: "approved" /* APPROVED */,
22058
22062
  invitedId: inviter?._id
22059
22063
  };
22060
22064
  const result = await _add(payload);
@@ -22871,6 +22875,14 @@ function usePersonService() {
22871
22875
  );
22872
22876
  }
22873
22877
  }
22878
+ if (value.isOwner && value.unit) {
22879
+ const unit = await _getUnitById(value.unit.toString());
22880
+ await updateUnitById(
22881
+ unit?._id?.toString() || "",
22882
+ { ownerName: value.name, owner: value._id },
22883
+ session
22884
+ );
22885
+ }
22874
22886
  await _add(value, session);
22875
22887
  await session.commitTransaction();
22876
22888
  return "People added successfully.";
@@ -22894,18 +22906,33 @@ function usePersonService() {
22894
22906
  throw new BadRequestError100("Person not found.");
22895
22907
  }
22896
22908
  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
- }
22909
+ const isOwnerChanged = value.isOwner !== person.isOwner;
22908
22910
  await _updateById(_id, value, session);
22911
+ if (value.unit && (isNameUpdated || isOwnerChanged || value.isOwner)) {
22912
+ const unit = await _getUnitById(value.unit.toString());
22913
+ if (unit) {
22914
+ let updatePayload = {};
22915
+ if (isOwnerChanged) {
22916
+ if (value.isOwner) {
22917
+ updatePayload.owner = _id;
22918
+ updatePayload.ownerName = value.name || "";
22919
+ } else {
22920
+ updatePayload.owner = "";
22921
+ updatePayload.ownerName = "";
22922
+ }
22923
+ }
22924
+ if (isNameUpdated && value.isOwner && unit.owner?.toString() === _id.toString()) {
22925
+ updatePayload.ownerName = value.name;
22926
+ }
22927
+ if (value.isOwner && (!unit.owner || !unit.ownerName)) {
22928
+ updatePayload.owner = _id;
22929
+ updatePayload.ownerName = value.name || "";
22930
+ }
22931
+ if (Object.keys(updatePayload).length > 0 && unit && unit._id) {
22932
+ await updateUnitById(unit._id.toString(), updatePayload, session);
22933
+ }
22934
+ }
22935
+ }
22909
22936
  await session.commitTransaction();
22910
22937
  return "Person updated successfully.";
22911
22938
  } catch (error) {
@@ -47119,6 +47146,37 @@ function useVerificationRepoV2() {
47119
47146
  throw error;
47120
47147
  }
47121
47148
  }
47149
+ async function updateStatusById(_id, status, session) {
47150
+ try {
47151
+ _id = new ObjectId127(_id);
47152
+ } catch (error) {
47153
+ throw new BadRequestError195("Invalid verification ID format.");
47154
+ }
47155
+ try {
47156
+ const result = await collection.updateOne(
47157
+ { _id },
47158
+ { $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
47159
+ { session }
47160
+ );
47161
+ delNamespace().then(() => {
47162
+ logger175.info(`Cache cleared for namespace: ${namespace_collection}`);
47163
+ }).catch((err) => {
47164
+ logger175.error(
47165
+ `Failed to clear cache for namespace: ${namespace_collection}`,
47166
+ err
47167
+ );
47168
+ });
47169
+ const cacheKey = makeCacheKey64(namespace_collection, { _id });
47170
+ delCache(cacheKey).then(() => {
47171
+ logger175.info(`Cache deleted for key: ${cacheKey}`);
47172
+ }).catch((err) => {
47173
+ logger175.error(`Failed to delete cache for key: ${cacheKey}`, err);
47174
+ });
47175
+ return result;
47176
+ } catch (error) {
47177
+ throw new InternalServerError68("Error updating verification status.");
47178
+ }
47179
+ }
47122
47180
  return {
47123
47181
  createIndex,
47124
47182
  createTextIndex,
@@ -47126,7 +47184,8 @@ function useVerificationRepoV2() {
47126
47184
  updateVerificationStatusById,
47127
47185
  getByVerificationCode,
47128
47186
  getVerificationById,
47129
- getVerifications
47187
+ getVerifications,
47188
+ updateStatusById
47130
47189
  };
47131
47190
  }
47132
47191
 
@@ -47156,7 +47215,8 @@ function useVerificationServiceV2() {
47156
47215
  const {
47157
47216
  add: _add,
47158
47217
  updateVerificationStatusById: _updateVerificationStatusById,
47159
- getByVerificationCode: _getByVerificationCode
47218
+ getByVerificationCode: _getByVerificationCode,
47219
+ updateStatusById: _updateStatusById
47160
47220
  } = useVerificationRepoV2();
47161
47221
  const {
47162
47222
  getUserByEmailStatus: _getUserByEmailStatus,
@@ -47461,12 +47521,22 @@ function useVerificationServiceV2() {
47461
47521
  throw new InternalServerError69("Failed to create forget password link.");
47462
47522
  }
47463
47523
  }
47524
+ async function cancelUserInvitation(id) {
47525
+ try {
47526
+ await _updateStatusById(id, "cancelled");
47527
+ } catch (error) {
47528
+ throw new InternalServerError69(
47529
+ `Error cancelling user invitation: ${error}`
47530
+ );
47531
+ }
47532
+ }
47464
47533
  return {
47465
47534
  signUp,
47466
47535
  verify,
47467
47536
  createUserInvite,
47468
47537
  createServiceProviderInvite,
47469
- createForgetPassword
47538
+ createForgetPassword,
47539
+ cancelUserInvitation
47470
47540
  };
47471
47541
  }
47472
47542
 
@@ -47478,7 +47548,8 @@ function useVerificationControllerV2() {
47478
47548
  verify: _verify,
47479
47549
  createUserInvite: _createUserInvite,
47480
47550
  createServiceProviderInvite: _createServiceProviderInvite,
47481
- createForgetPassword: _createForgetPassword
47551
+ createForgetPassword: _createForgetPassword,
47552
+ cancelUserInvitation: _cancelUserInvitation
47482
47553
  } = useVerificationServiceV2();
47483
47554
  const { getVerifications: _getVerifications } = useVerificationRepoV2();
47484
47555
  async function verify(req, res, next) {
@@ -47633,12 +47704,34 @@ function useVerificationControllerV2() {
47633
47704
  return;
47634
47705
  }
47635
47706
  }
47707
+ async function cancelUserInvitation(req, res, next) {
47708
+ const validation = Joi126.string().hex().required();
47709
+ const otpId = req.params.id;
47710
+ const { error } = validation.validate(otpId);
47711
+ if (error) {
47712
+ logger177.log({ level: "error", message: `${error.message}` });
47713
+ next(new BadRequestError197(error.message));
47714
+ return;
47715
+ }
47716
+ try {
47717
+ await _cancelUserInvitation(otpId);
47718
+ res.json({
47719
+ message: "User invite has been cancelled."
47720
+ });
47721
+ return;
47722
+ } catch (error2) {
47723
+ logger177.log({ level: "error", message: `${error2.message}` });
47724
+ next(error2);
47725
+ return;
47726
+ }
47727
+ }
47636
47728
  return {
47637
47729
  verify,
47638
47730
  createUserInvite,
47639
47731
  createServiceProviderInvite,
47640
47732
  createForgetPassword,
47641
- getVerifications
47733
+ getVerifications,
47734
+ cancelUserInvitation
47642
47735
  };
47643
47736
  }
47644
47737