@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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 2.33.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 53508a4: get latest changes
8
+
9
+ ## 2.32.0
10
+
11
+ ### Minor Changes
12
+
13
+ - 03c36fc: get latest changes
14
+
3
15
  ## 2.31.2
4
16
 
5
17
  ### 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({
@@ -13657,7 +13658,8 @@ function useVisitorTransactionRepo() {
13657
13658
  $project: {
13658
13659
  _id: 1,
13659
13660
  prefixPass: 1,
13660
- name: 1
13661
+ name: 1,
13662
+ remarks: 1
13661
13663
  }
13662
13664
  }
13663
13665
  ],
@@ -13670,6 +13672,9 @@ function useVisitorTransactionRepo() {
13670
13672
  keyId: "$_id",
13671
13673
  status: 1,
13672
13674
  description: 1,
13675
+ remarks: {
13676
+ $arrayElemAt: ["$template.remarks", 0]
13677
+ },
13673
13678
  templatePrefixPass: {
13674
13679
  $arrayElemAt: ["$template.prefixPass", 0]
13675
13680
  },
@@ -13706,7 +13711,8 @@ function useVisitorTransactionRepo() {
13706
13711
  $project: {
13707
13712
  _id: 1,
13708
13713
  prefixPass: 1,
13709
- name: 1
13714
+ name: 1,
13715
+ remarks: 1
13710
13716
  }
13711
13717
  }
13712
13718
  ],
@@ -13719,6 +13725,9 @@ function useVisitorTransactionRepo() {
13719
13725
  keyId: "$_id",
13720
13726
  status: 1,
13721
13727
  description: 1,
13728
+ remarks: {
13729
+ $arrayElemAt: ["$template.remarks", 0]
13730
+ },
13722
13731
  templatePrefixPass: {
13723
13732
  $arrayElemAt: ["$template.prefixPass", 0]
13724
13733
  },
@@ -17646,6 +17655,9 @@ function useBuildingUnitRepo() {
17646
17655
  return billing;
17647
17656
  });
17648
17657
  }
17658
+ if (value.owner) {
17659
+ value.owner = new import_mongodb48.ObjectId(value.owner);
17660
+ }
17649
17661
  try {
17650
17662
  const res = await collection.updateOne(
17651
17663
  { _id },
@@ -22156,7 +22168,7 @@ function useVisitorTransactionService() {
22156
22168
  unitName: unit?.name,
22157
22169
  org: inviter?.org.toString(),
22158
22170
  site: inviter?.site.toString(),
22159
- status: "pending" /* PENDING */,
22171
+ status: "approved" /* APPROVED */,
22160
22172
  invitedId: inviter?._id
22161
22173
  };
22162
22174
  const result = await _add(payload);
@@ -22959,6 +22971,14 @@ function usePersonService() {
22959
22971
  );
22960
22972
  }
22961
22973
  }
22974
+ if (value.isOwner && value.unit) {
22975
+ const unit = await _getUnitById(value.unit.toString());
22976
+ await updateUnitById(
22977
+ unit?._id?.toString() || "",
22978
+ { ownerName: value.name, owner: value._id },
22979
+ session
22980
+ );
22981
+ }
22962
22982
  await _add(value, session);
22963
22983
  await session.commitTransaction();
22964
22984
  return "People added successfully.";
@@ -22982,18 +23002,33 @@ function usePersonService() {
22982
23002
  throw new import_node_server_utils106.BadRequestError("Person not found.");
22983
23003
  }
22984
23004
  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
- }
23005
+ const isOwnerChanged = value.isOwner !== person.isOwner;
22996
23006
  await _updateById(_id, value, session);
23007
+ if (value.unit && (isNameUpdated || isOwnerChanged || value.isOwner)) {
23008
+ const unit = await _getUnitById(value.unit.toString());
23009
+ if (unit) {
23010
+ let updatePayload = {};
23011
+ if (isOwnerChanged) {
23012
+ if (value.isOwner) {
23013
+ updatePayload.owner = _id;
23014
+ updatePayload.ownerName = value.name || "";
23015
+ } else {
23016
+ updatePayload.owner = "";
23017
+ updatePayload.ownerName = "";
23018
+ }
23019
+ }
23020
+ if (isNameUpdated && value.isOwner && unit.owner?.toString() === _id.toString()) {
23021
+ updatePayload.ownerName = value.name;
23022
+ }
23023
+ if (value.isOwner && (!unit.owner || !unit.ownerName)) {
23024
+ updatePayload.owner = _id;
23025
+ updatePayload.ownerName = value.name || "";
23026
+ }
23027
+ if (Object.keys(updatePayload).length > 0 && unit && unit._id) {
23028
+ await updateUnitById(unit._id.toString(), updatePayload, session);
23029
+ }
23030
+ }
23031
+ }
22997
23032
  await session.commitTransaction();
22998
23033
  return "Person updated successfully.";
22999
23034
  } catch (error) {
@@ -46869,6 +46904,37 @@ function useVerificationRepoV2() {
46869
46904
  throw error;
46870
46905
  }
46871
46906
  }
46907
+ async function updateStatusById(_id, status, session) {
46908
+ try {
46909
+ _id = new import_mongodb127.ObjectId(_id);
46910
+ } catch (error) {
46911
+ throw new import_node_server_utils218.BadRequestError("Invalid verification ID format.");
46912
+ }
46913
+ try {
46914
+ const result = await collection.updateOne(
46915
+ { _id },
46916
+ { $set: { status, updatedAt: (/* @__PURE__ */ new Date()).toISOString() } },
46917
+ { session }
46918
+ );
46919
+ delNamespace().then(() => {
46920
+ import_node_server_utils218.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
46921
+ }).catch((err) => {
46922
+ import_node_server_utils218.logger.error(
46923
+ `Failed to clear cache for namespace: ${namespace_collection}`,
46924
+ err
46925
+ );
46926
+ });
46927
+ const cacheKey = (0, import_node_server_utils218.makeCacheKey)(namespace_collection, { _id });
46928
+ delCache(cacheKey).then(() => {
46929
+ import_node_server_utils218.logger.info(`Cache deleted for key: ${cacheKey}`);
46930
+ }).catch((err) => {
46931
+ import_node_server_utils218.logger.error(`Failed to delete cache for key: ${cacheKey}`, err);
46932
+ });
46933
+ return result;
46934
+ } catch (error) {
46935
+ throw new import_node_server_utils218.InternalServerError("Error updating verification status.");
46936
+ }
46937
+ }
46872
46938
  return {
46873
46939
  createIndex,
46874
46940
  createTextIndex,
@@ -46876,7 +46942,8 @@ function useVerificationRepoV2() {
46876
46942
  updateVerificationStatusById,
46877
46943
  getByVerificationCode,
46878
46944
  getVerificationById,
46879
- getVerifications
46945
+ getVerifications,
46946
+ updateStatusById
46880
46947
  };
46881
46948
  }
46882
46949
 
@@ -46896,7 +46963,8 @@ function useVerificationServiceV2() {
46896
46963
  const {
46897
46964
  add: _add,
46898
46965
  updateVerificationStatusById: _updateVerificationStatusById,
46899
- getByVerificationCode: _getByVerificationCode
46966
+ getByVerificationCode: _getByVerificationCode,
46967
+ updateStatusById: _updateStatusById
46900
46968
  } = useVerificationRepoV2();
46901
46969
  const {
46902
46970
  getUserByEmailStatus: _getUserByEmailStatus,
@@ -47201,12 +47269,22 @@ function useVerificationServiceV2() {
47201
47269
  throw new import_node_server_utils219.InternalServerError("Failed to create forget password link.");
47202
47270
  }
47203
47271
  }
47272
+ async function cancelUserInvitation(id) {
47273
+ try {
47274
+ await _updateStatusById(id, "cancelled");
47275
+ } catch (error) {
47276
+ throw new import_node_server_utils219.InternalServerError(
47277
+ `Error cancelling user invitation: ${error}`
47278
+ );
47279
+ }
47280
+ }
47204
47281
  return {
47205
47282
  signUp,
47206
47283
  verify,
47207
47284
  createUserInvite,
47208
47285
  createServiceProviderInvite,
47209
- createForgetPassword
47286
+ createForgetPassword,
47287
+ cancelUserInvitation
47210
47288
  };
47211
47289
  }
47212
47290
 
@@ -47218,7 +47296,8 @@ function useVerificationControllerV2() {
47218
47296
  verify: _verify,
47219
47297
  createUserInvite: _createUserInvite,
47220
47298
  createServiceProviderInvite: _createServiceProviderInvite,
47221
- createForgetPassword: _createForgetPassword
47299
+ createForgetPassword: _createForgetPassword,
47300
+ cancelUserInvitation: _cancelUserInvitation
47222
47301
  } = useVerificationServiceV2();
47223
47302
  const { getVerifications: _getVerifications } = useVerificationRepoV2();
47224
47303
  async function verify(req, res, next) {
@@ -47373,12 +47452,34 @@ function useVerificationControllerV2() {
47373
47452
  return;
47374
47453
  }
47375
47454
  }
47455
+ async function cancelUserInvitation(req, res, next) {
47456
+ const validation = import_joi126.default.string().hex().required();
47457
+ const otpId = req.params.id;
47458
+ const { error } = validation.validate(otpId);
47459
+ if (error) {
47460
+ import_node_server_utils220.logger.log({ level: "error", message: `${error.message}` });
47461
+ next(new import_node_server_utils220.BadRequestError(error.message));
47462
+ return;
47463
+ }
47464
+ try {
47465
+ await _cancelUserInvitation(otpId);
47466
+ res.json({
47467
+ message: "User invite has been cancelled."
47468
+ });
47469
+ return;
47470
+ } catch (error2) {
47471
+ import_node_server_utils220.logger.log({ level: "error", message: `${error2.message}` });
47472
+ next(error2);
47473
+ return;
47474
+ }
47475
+ }
47376
47476
  return {
47377
47477
  verify,
47378
47478
  createUserInvite,
47379
47479
  createServiceProviderInvite,
47380
47480
  createForgetPassword,
47381
- getVerifications
47481
+ getVerifications,
47482
+ cancelUserInvitation
47382
47483
  };
47383
47484
  }
47384
47485