@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 2.32.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 03c36fc: get latest changes
8
+
3
9
  ## 2.31.2
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -1817,7 +1817,7 @@ declare function useBuildingUnitRepo(): {
1817
1817
  }) => Promise<Record<string, any>>;
1818
1818
  getById: (_id: string | ObjectId, session?: ClientSession) => Promise<TBuildingUnit>;
1819
1819
  getByBuildingLevel: (building: string | ObjectId, level: string) => Promise<TBuildingUnit | null>;
1820
- updateById: (_id: string | ObjectId, value: Partial<Pick<TBuildingUnit, "name" | "level" | "category" | "buildingName" | "block" | "buildingUnitFiles" | "ownerName" | "billing">>, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
1820
+ updateById: (_id: string | ObjectId, value: Partial<Pick<TBuildingUnit, "name" | "level" | "category" | "buildingName" | "block" | "buildingUnitFiles" | "ownerName" | "billing" | "owner">>, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
1821
1821
  getByBuilding: (building: string | ObjectId) => Promise<TBuildingUnit | null>;
1822
1822
  deleteById: (_id: string | ObjectId, session?: ClientSession) => Promise<string>;
1823
1823
  updateLevelByBuildingLevel: (building: string | ObjectId, level: string, newLevel: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
@@ -2496,7 +2496,8 @@ declare enum VisitorSort {
2496
2496
  declare enum VisitorStatus {
2497
2497
  REGISTERED = "registered",
2498
2498
  UNREGISTERED = "unregistered",
2499
- PENDING = "pending"
2499
+ PENDING = "pending",
2500
+ APPROVED = "approved"
2500
2501
  }
2501
2502
  type TKeyRef = {
2502
2503
  keyId: string | ObjectId;
@@ -6304,6 +6305,7 @@ declare function useVerificationRepoV2(): {
6304
6305
  type?: Record<string, any> | undefined;
6305
6306
  email?: string | undefined;
6306
6307
  }) => Promise<{}>;
6308
+ updateStatusById: (_id: string | ObjectId, status: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
6307
6309
  };
6308
6310
 
6309
6311
  declare function useVerificationServiceV2(): {
@@ -6332,6 +6334,7 @@ declare function useVerificationServiceV2(): {
6332
6334
  siteName: string;
6333
6335
  }) => Promise<bson.ObjectId>;
6334
6336
  createForgetPassword: (email: string) => Promise<string>;
6337
+ cancelUserInvitation: (id: string) => Promise<void>;
6335
6338
  };
6336
6339
 
6337
6340
  declare function useVerificationControllerV2(): {
@@ -6340,6 +6343,7 @@ declare function useVerificationControllerV2(): {
6340
6343
  createServiceProviderInvite: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6341
6344
  createForgetPassword: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6342
6345
  getVerifications: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6346
+ cancelUserInvitation: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6343
6347
  };
6344
6348
 
6345
6349
  declare function useAuthControllerV2(): {
package/dist/index.js CHANGED
@@ -13296,6 +13296,7 @@ var VisitorStatus = /* @__PURE__ */ ((VisitorStatus2) => {
13296
13296
  VisitorStatus2["REGISTERED"] = "registered";
13297
13297
  VisitorStatus2["UNREGISTERED"] = "unregistered";
13298
13298
  VisitorStatus2["PENDING"] = "pending";
13299
+ VisitorStatus2["APPROVED"] = "approved";
13299
13300
  return VisitorStatus2;
13300
13301
  })(VisitorStatus || {});
13301
13302
  var schemaVisitorTransaction = import_joi36.default.object({
@@ -17646,6 +17647,9 @@ function useBuildingUnitRepo() {
17646
17647
  return billing;
17647
17648
  });
17648
17649
  }
17650
+ if (value.owner) {
17651
+ value.owner = new import_mongodb48.ObjectId(value.owner);
17652
+ }
17649
17653
  try {
17650
17654
  const res = await collection.updateOne(
17651
17655
  { _id },
@@ -22156,7 +22160,7 @@ function useVisitorTransactionService() {
22156
22160
  unitName: unit?.name,
22157
22161
  org: inviter?.org.toString(),
22158
22162
  site: inviter?.site.toString(),
22159
- status: "pending" /* PENDING */,
22163
+ status: "approved" /* APPROVED */,
22160
22164
  invitedId: inviter?._id
22161
22165
  };
22162
22166
  const result = await _add(payload);
@@ -22959,6 +22963,14 @@ function usePersonService() {
22959
22963
  );
22960
22964
  }
22961
22965
  }
22966
+ if (value.isOwner && value.unit) {
22967
+ const unit = await _getUnitById(value.unit.toString());
22968
+ await updateUnitById(
22969
+ unit?._id?.toString() || "",
22970
+ { ownerName: value.name, owner: value._id },
22971
+ session
22972
+ );
22973
+ }
22962
22974
  await _add(value, session);
22963
22975
  await session.commitTransaction();
22964
22976
  return "People added successfully.";
@@ -22982,18 +22994,33 @@ function usePersonService() {
22982
22994
  throw new import_node_server_utils106.BadRequestError("Person not found.");
22983
22995
  }
22984
22996
  const isNameUpdated = typeof value.name === "string" && value.name.trim() !== person.name;
22985
- let unit;
22986
- if (isNameUpdated && value.unit) {
22987
- unit = await _getUnitById(value.unit.toString());
22988
- }
22989
- if (unit && unit.owner?.toString() === _id.toString()) {
22990
- await updateUnitById(
22991
- unit?._id?.toString() || "",
22992
- { ownerName: value.name },
22993
- session
22994
- );
22995
- }
22997
+ const isOwnerChanged = value.isOwner !== person.isOwner;
22996
22998
  await _updateById(_id, value, session);
22999
+ if (value.unit && (isNameUpdated || isOwnerChanged || value.isOwner)) {
23000
+ const unit = await _getUnitById(value.unit.toString());
23001
+ if (unit) {
23002
+ let updatePayload = {};
23003
+ if (isOwnerChanged) {
23004
+ if (value.isOwner) {
23005
+ updatePayload.owner = _id;
23006
+ updatePayload.ownerName = value.name || "";
23007
+ } else {
23008
+ updatePayload.owner = "";
23009
+ updatePayload.ownerName = "";
23010
+ }
23011
+ }
23012
+ if (isNameUpdated && value.isOwner && unit.owner?.toString() === _id.toString()) {
23013
+ updatePayload.ownerName = value.name;
23014
+ }
23015
+ if (value.isOwner && (!unit.owner || !unit.ownerName)) {
23016
+ updatePayload.owner = _id;
23017
+ updatePayload.ownerName = value.name || "";
23018
+ }
23019
+ if (Object.keys(updatePayload).length > 0 && unit && unit._id) {
23020
+ await updateUnitById(unit._id.toString(), updatePayload, session);
23021
+ }
23022
+ }
23023
+ }
22997
23024
  await session.commitTransaction();
22998
23025
  return "Person updated successfully.";
22999
23026
  } catch (error) {
@@ -46869,6 +46896,37 @@ function useVerificationRepoV2() {
46869
46896
  throw error;
46870
46897
  }
46871
46898
  }
46899
+ async function updateStatusById(_id, status, session) {
46900
+ try {
46901
+ _id = new import_mongodb127.ObjectId(_id);
46902
+ } catch (error) {
46903
+ throw new import_node_server_utils218.BadRequestError("Invalid verification ID format.");
46904
+ }
46905
+ try {
46906
+ const result = await collection.updateOne(
46907
+ { _id },
46908
+ { $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
46909
+ { session }
46910
+ );
46911
+ delNamespace().then(() => {
46912
+ import_node_server_utils218.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
46913
+ }).catch((err) => {
46914
+ import_node_server_utils218.logger.error(
46915
+ `Failed to clear cache for namespace: ${namespace_collection}`,
46916
+ err
46917
+ );
46918
+ });
46919
+ const cacheKey = (0, import_node_server_utils218.makeCacheKey)(namespace_collection, { _id });
46920
+ delCache(cacheKey).then(() => {
46921
+ import_node_server_utils218.logger.info(`Cache deleted for key: ${cacheKey}`);
46922
+ }).catch((err) => {
46923
+ import_node_server_utils218.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
46924
+ });
46925
+ return result;
46926
+ } catch (error) {
46927
+ throw new import_node_server_utils218.InternalServerError("Error updating verification status.");
46928
+ }
46929
+ }
46872
46930
  return {
46873
46931
  createIndex,
46874
46932
  createTextIndex,
@@ -46876,7 +46934,8 @@ function useVerificationRepoV2() {
46876
46934
  updateVerificationStatusById,
46877
46935
  getByVerificationCode,
46878
46936
  getVerificationById,
46879
- getVerifications
46937
+ getVerifications,
46938
+ updateStatusById
46880
46939
  };
46881
46940
  }
46882
46941
 
@@ -46896,7 +46955,8 @@ function useVerificationServiceV2() {
46896
46955
  const {
46897
46956
  add: _add,
46898
46957
  updateVerificationStatusById: _updateVerificationStatusById,
46899
- getByVerificationCode: _getByVerificationCode
46958
+ getByVerificationCode: _getByVerificationCode,
46959
+ updateStatusById: _updateStatusById
46900
46960
  } = useVerificationRepoV2();
46901
46961
  const {
46902
46962
  getUserByEmailStatus: _getUserByEmailStatus,
@@ -47201,12 +47261,22 @@ function useVerificationServiceV2() {
47201
47261
  throw new import_node_server_utils219.InternalServerError("Failed to create forget password link.");
47202
47262
  }
47203
47263
  }
47264
+ async function cancelUserInvitation(id) {
47265
+ try {
47266
+ await _updateStatusById(id, "cancelled");
47267
+ } catch (error) {
47268
+ throw new import_node_server_utils219.InternalServerError(
47269
+ `Error cancelling user invitation: ${error}`
47270
+ );
47271
+ }
47272
+ }
47204
47273
  return {
47205
47274
  signUp,
47206
47275
  verify,
47207
47276
  createUserInvite,
47208
47277
  createServiceProviderInvite,
47209
- createForgetPassword
47278
+ createForgetPassword,
47279
+ cancelUserInvitation
47210
47280
  };
47211
47281
  }
47212
47282
 
@@ -47218,7 +47288,8 @@ function useVerificationControllerV2() {
47218
47288
  verify: _verify,
47219
47289
  createUserInvite: _createUserInvite,
47220
47290
  createServiceProviderInvite: _createServiceProviderInvite,
47221
- createForgetPassword: _createForgetPassword
47291
+ createForgetPassword: _createForgetPassword,
47292
+ cancelUserInvitation: _cancelUserInvitation
47222
47293
  } = useVerificationServiceV2();
47223
47294
  const { getVerifications: _getVerifications } = useVerificationRepoV2();
47224
47295
  async function verify(req, res, next) {
@@ -47373,12 +47444,34 @@ function useVerificationControllerV2() {
47373
47444
  return;
47374
47445
  }
47375
47446
  }
47447
+ async function cancelUserInvitation(req, res, next) {
47448
+ const validation = import_joi126.default.string().hex().required();
47449
+ const otpId = req.params.id;
47450
+ const { error } = validation.validate(otpId);
47451
+ if (error) {
47452
+ import_node_server_utils220.logger.log({ level: "error", message: `${error.message}` });
47453
+ next(new import_node_server_utils220.BadRequestError(error.message));
47454
+ return;
47455
+ }
47456
+ try {
47457
+ await _cancelUserInvitation(otpId);
47458
+ res.json({
47459
+ message: "User invite has been cancelled."
47460
+ });
47461
+ return;
47462
+ } catch (error2) {
47463
+ import_node_server_utils220.logger.log({ level: "error", message: `${error2.message}` });
47464
+ next(error2);
47465
+ return;
47466
+ }
47467
+ }
47376
47468
  return {
47377
47469
  verify,
47378
47470
  createUserInvite,
47379
47471
  createServiceProviderInvite,
47380
47472
  createForgetPassword,
47381
- getVerifications
47473
+ getVerifications,
47474
+ cancelUserInvitation
47382
47475
  };
47383
47476
  }
47384
47477