@7365admin1/core 2.31.1 → 2.31.2

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.31.2
4
+
5
+ ### Patch Changes
6
+
7
+ - 6f8eaf7: Update package core due to missing function
8
+
3
9
  ## 2.31.1
4
10
 
5
11
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -475,6 +475,7 @@ declare function useOrgRepo(): {
475
475
 
476
476
  declare function useOrgController(): {
477
477
  add: (req: Request, res: Response, next: NextFunction) => Promise<void>;
478
+ addOnboardingOrg: (req: Request, res: Response, next: NextFunction) => Promise<void>;
478
479
  getAll: (req: Request, res: Response, next: NextFunction) => Promise<void>;
479
480
  getOrgsByUserId: (req: Request, res: Response, next: NextFunction) => Promise<void>;
480
481
  getByName: (req: Request, res: Response, next: NextFunction) => Promise<void>;
@@ -4795,6 +4796,22 @@ declare function useStatementOfAccountRepo(): {
4795
4796
  updateById: (_id: string | ObjectId, value: Partial<TStatementOfAccount>, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
4796
4797
  deleteById: (_id: string | ObjectId) => Promise<number>;
4797
4798
  updateStatusById: (_id: string | ObjectId, value: Pick<TStatementOfAccount, "status">, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
4799
+ getResidentUserSoa: ({ search, page, limit, sort, status, site, dateFrom, dateTo, unitId, category, }: {
4800
+ search?: string | undefined;
4801
+ page?: number | undefined;
4802
+ limit?: number | undefined;
4803
+ sort?: Record<string, any> | undefined;
4804
+ status: string;
4805
+ site?: string | undefined;
4806
+ dateFrom?: string | undefined;
4807
+ dateTo?: string | undefined;
4808
+ unitId: string;
4809
+ category: string;
4810
+ }, session?: ClientSession) => Promise<{
4811
+ items: any[];
4812
+ pages: number;
4813
+ pageRange: string;
4814
+ }>;
4798
4815
  };
4799
4816
 
4800
4817
  declare function useStatementOfAccountController(): {
@@ -4805,6 +4822,7 @@ declare function useStatementOfAccountController(): {
4805
4822
  deleteById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
4806
4823
  generatePDF: (req: Request, res: Response, next: NextFunction) => Promise<void>;
4807
4824
  updateStatusById: (req: Request, res: Response, next: NextFunction) => Promise<void>;
4825
+ getResidentUserSoa: (req: Request, res: Response, next: NextFunction) => Promise<void>;
4808
4826
  };
4809
4827
 
4810
4828
  type TEntryPassSettings = {
@@ -6276,6 +6294,16 @@ declare function useVerificationRepoV2(): {
6276
6294
  updateVerificationStatusById: (_id: string | ObjectId, status: string, session?: ClientSession) => Promise<mongodb.UpdateResult<bson.Document>>;
6277
6295
  getByVerificationCode: (verificationCode: string) => Promise<TVerification | null>;
6278
6296
  getVerificationById: (id: string | ObjectId) => Promise<TVerificationV2 | null>;
6297
+ getVerifications: ({ search, page, limit, sort, status, app, type, email, }: {
6298
+ search?: string | undefined;
6299
+ page?: number | undefined;
6300
+ limit?: number | undefined;
6301
+ sort?: Record<string, any> | undefined;
6302
+ status: string;
6303
+ app?: string | undefined;
6304
+ type?: Record<string, any> | undefined;
6305
+ email?: string | undefined;
6306
+ }) => Promise<{}>;
6279
6307
  };
6280
6308
 
6281
6309
  declare function useVerificationServiceV2(): {
@@ -6311,6 +6339,7 @@ declare function useVerificationControllerV2(): {
6311
6339
  createUserInvite: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6312
6340
  createServiceProviderInvite: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6313
6341
  createForgetPassword: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6342
+ getVerifications: (req: Request, res: Response, next: NextFunction) => Promise<void>;
6314
6343
  };
6315
6344
 
6316
6345
  declare function useAuthControllerV2(): {
package/dist/index.js CHANGED
@@ -7722,6 +7722,34 @@ function useOrgController() {
7722
7722
  return;
7723
7723
  }
7724
7724
  }
7725
+ async function addOnboardingOrg(req, res, next) {
7726
+ const validation = import_joi18.default.object({
7727
+ name: import_joi18.default.string().required(),
7728
+ type: import_joi18.default.string().required(),
7729
+ nature: import_joi18.default.string().valid(...allowedNatures).required(),
7730
+ email: import_joi18.default.string().email().optional().allow("", null),
7731
+ contact: import_joi18.default.string().optional().allow("", null)
7732
+ });
7733
+ const { error } = validation.validate(req.body);
7734
+ if (error) {
7735
+ import_node_server_utils34.logger.log({ level: "error", message: error.message });
7736
+ next(new import_node_server_utils34.BadRequestError(error.message));
7737
+ return;
7738
+ }
7739
+ try {
7740
+ const _id = await _add(req.body);
7741
+ const data = await _getById(_id);
7742
+ res.status(201).json({
7743
+ message: "Successfully created organization.",
7744
+ data
7745
+ });
7746
+ return;
7747
+ } catch (error2) {
7748
+ import_node_server_utils34.logger.log({ level: "error", message: error2.message });
7749
+ next(error2);
7750
+ return;
7751
+ }
7752
+ }
7725
7753
  async function getOrgsByUserId(req, res, next) {
7726
7754
  const validation = import_joi18.default.object({
7727
7755
  search: import_joi18.default.string().optional().allow("", null),
@@ -7820,6 +7848,7 @@ function useOrgController() {
7820
7848
  }
7821
7849
  return {
7822
7850
  add,
7851
+ addOnboardingOrg,
7823
7852
  getAll,
7824
7853
  getOrgsByUserId,
7825
7854
  getByName,
@@ -36717,6 +36746,81 @@ function useStatementOfAccountRepo() {
36717
36746
  throw new import_node_server_utils164.InternalServerError("Failed to update soa request.");
36718
36747
  }
36719
36748
  }
36749
+ async function getResidentUserSoa({
36750
+ search = "",
36751
+ page = 1,
36752
+ limit = 10,
36753
+ sort = {},
36754
+ status = "pending",
36755
+ site = "",
36756
+ dateFrom,
36757
+ dateTo,
36758
+ unitId,
36759
+ category
36760
+ }, session) {
36761
+ page = page > 0 ? page - 1 : 0;
36762
+ let dateExpr = {};
36763
+ if (dateFrom && dateTo) {
36764
+ let startDate = new Date(dateFrom);
36765
+ startDate.setHours(0, 0, 0, 0);
36766
+ let endDate = new Date(dateTo);
36767
+ endDate.setHours(23, 59, 59, 999);
36768
+ dateExpr = {
36769
+ $expr: {
36770
+ $and: [
36771
+ { $gte: ["$createdAt", startDate] },
36772
+ { $lte: ["$createdAt", endDate] }
36773
+ ]
36774
+ }
36775
+ };
36776
+ }
36777
+ const unitSearchRegex = search ? search.trim().replace(/\s+/g, "").replace(/\//g, "\\s*/\\s*") : null;
36778
+ const query = {
36779
+ ...status && status !== "all" && { status },
36780
+ ...search && {
36781
+ $or: [
36782
+ { unitOwner: { $regex: search, $options: "i" } },
36783
+ { unit: { $regex: unitSearchRegex, $options: "i" } },
36784
+ { email: { $regex: search, $options: "i" } },
36785
+ { category: { $regex: search, $options: "i" } }
36786
+ ]
36787
+ },
36788
+ ...import_mongodb97.ObjectId.isValid(site) && { site: new import_mongodb97.ObjectId(site) },
36789
+ ...dateExpr,
36790
+ ...import_mongodb97.ObjectId.isValid(unitId) && { unitId: new import_mongodb97.ObjectId(unitId) },
36791
+ ...category && { category }
36792
+ };
36793
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
36794
+ try {
36795
+ const basePipeline = [
36796
+ { $match: query },
36797
+ {
36798
+ $addFields: {
36799
+ sortPriority: {
36800
+ $cond: [{ $eq: ["$status", "pending"] }, 1, 2]
36801
+ }
36802
+ }
36803
+ },
36804
+ {
36805
+ $sort: {
36806
+ sortPriority: 1,
36807
+ ...sort
36808
+ }
36809
+ },
36810
+ { $skip: page * limit },
36811
+ { $limit: limit }
36812
+ ];
36813
+ const [items, countResult] = await Promise.all([
36814
+ collection.aggregate(basePipeline, { session }).toArray(),
36815
+ collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
36816
+ ]);
36817
+ const totalCount = countResult[0]?.total || 0;
36818
+ const data = (0, import_node_server_utils164.paginate)(items, page, limit, totalCount);
36819
+ return data;
36820
+ } catch (error) {
36821
+ throw error;
36822
+ }
36823
+ }
36720
36824
  function delCachedData() {
36721
36825
  delNamespace().then(() => {
36722
36826
  import_node_server_utils164.logger.log({
@@ -36737,7 +36841,8 @@ function useStatementOfAccountRepo() {
36737
36841
  getById,
36738
36842
  updateById,
36739
36843
  deleteById,
36740
- updateStatusById
36844
+ updateStatusById,
36845
+ getResidentUserSoa
36741
36846
  };
36742
36847
  }
36743
36848
 
@@ -36890,7 +36995,8 @@ function useStatementOfAccountController() {
36890
36995
  getById: _getById,
36891
36996
  updateById: _updateById,
36892
36997
  deleteById: _deleteById,
36893
- updateStatusById: _updateStatusById
36998
+ updateStatusById: _updateStatusById,
36999
+ getResidentUserSoa: _getResidentUserSoa
36894
37000
  } = useStatementOfAccountRepo();
36895
37001
  const { add: _add, generatePDF: _generatePDF } = useStatementOfAccountService();
36896
37002
  async function add(req, res, next) {
@@ -37141,6 +37247,57 @@ function useStatementOfAccountController() {
37141
37247
  return;
37142
37248
  }
37143
37249
  }
37250
+ async function getResidentUserSoa(req, res, next) {
37251
+ const validation = import_joi93.default.object({
37252
+ page: import_joi93.default.number().integer().min(1).allow("", null).default(1),
37253
+ limit: import_joi93.default.number().integer().min(1).max(100).allow("", null).default(10),
37254
+ status: import_joi93.default.string().optional().allow(null, ""),
37255
+ search: import_joi93.default.string().optional().allow(null, ""),
37256
+ site: import_joi93.default.string().required(),
37257
+ dateFrom: import_joi93.default.string().optional().allow(null, ""),
37258
+ dateTo: import_joi93.default.string().optional().allow(null, ""),
37259
+ unitId: import_joi93.default.string().required(),
37260
+ category: import_joi93.default.string().optional().allow(null, "")
37261
+ });
37262
+ const query = { ...req.query };
37263
+ const { error } = validation.validate(query, {
37264
+ abortEarly: false
37265
+ });
37266
+ if (error) {
37267
+ const messages = error.details.map((d) => d.message).join(", ");
37268
+ import_node_server_utils166.logger.log({ level: "error", message: messages });
37269
+ next(new import_node_server_utils166.BadRequestError(messages));
37270
+ return;
37271
+ }
37272
+ const search = req.query.search ?? "";
37273
+ const page = parseInt(req.query.page ?? "1");
37274
+ const limit = parseInt(req.query.limit ?? "10");
37275
+ const status = req.query.status ?? "active";
37276
+ const site = req.query.site;
37277
+ const dateFrom = req.query.dateFrom ?? "";
37278
+ const dateTo = req.query.dateTo ?? "";
37279
+ const unitId = req.query.unitId;
37280
+ const category = req.query.category ?? "";
37281
+ try {
37282
+ const data = await _getResidentUserSoa({
37283
+ search,
37284
+ page,
37285
+ limit,
37286
+ status,
37287
+ site,
37288
+ dateFrom,
37289
+ dateTo,
37290
+ unitId,
37291
+ category
37292
+ });
37293
+ res.status(200).json(data);
37294
+ return;
37295
+ } catch (error2) {
37296
+ import_node_server_utils166.logger.log({ level: "error", message: error2.message });
37297
+ next(error2);
37298
+ return;
37299
+ }
37300
+ }
37144
37301
  return {
37145
37302
  add,
37146
37303
  getAll,
@@ -37148,7 +37305,8 @@ function useStatementOfAccountController() {
37148
37305
  updateById,
37149
37306
  deleteById,
37150
37307
  generatePDF,
37151
- updateStatusById
37308
+ updateStatusById,
37309
+ getResidentUserSoa
37152
37310
  };
37153
37311
  }
37154
37312
 
@@ -40231,7 +40389,7 @@ function useOccurrenceEntryService() {
40231
40389
  value.signature = value.signature ? new import_mongodb108.ObjectId(value.signature) : occurrenceEntry.signature._id;
40232
40390
  value.eSignature = value.eSignature ? new import_mongodb108.ObjectId(value.eSignature) : occurrenceEntry.eSignature;
40233
40391
  value.createdAt = /* @__PURE__ */ new Date();
40234
- value.date = /* @__PURE__ */ new Date();
40392
+ value.date = value.date ? value.date : occurrenceEntry.date;
40235
40393
  value.userName = value.userName ? value.userName : occurrenceEntry.signature.name;
40236
40394
  value.createdByName = value.createdByName ? value.createdByName : occurrenceEntry.createdByName;
40237
40395
  await _updateOccurrenceBookById(dobId, {
@@ -46640,13 +46798,85 @@ function useVerificationRepoV2() {
46640
46798
  );
46641
46799
  }
46642
46800
  }
46801
+ async function getVerifications({
46802
+ search = "",
46803
+ page = 1,
46804
+ limit = 10,
46805
+ sort = {},
46806
+ status = "active",
46807
+ app = "",
46808
+ type = {},
46809
+ email = ""
46810
+ }) {
46811
+ page = page > 0 ? page - 1 : 0;
46812
+ const query = { status };
46813
+ const cacheOptions = {
46814
+ page,
46815
+ limit,
46816
+ status
46817
+ };
46818
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
46819
+ cacheOptions.sort = JSON.stringify(sort);
46820
+ if (search) {
46821
+ query.$text = { $search: search };
46822
+ cacheOptions.search = search;
46823
+ }
46824
+ if (app) {
46825
+ query["metadata.app"] = app;
46826
+ cacheOptions["metadata.app"] = app;
46827
+ }
46828
+ if (type && Object.keys(type).length > 0) {
46829
+ query.type = { $in: Object.keys(type) };
46830
+ cacheOptions.type = JSON.stringify(type);
46831
+ }
46832
+ if (email) {
46833
+ query.email = email;
46834
+ cacheOptions.email = email;
46835
+ }
46836
+ const cacheKey = (0, import_node_server_utils218.makeCacheKey)(namespace_collection, cacheOptions);
46837
+ const cachedData = await getCache(cacheKey);
46838
+ if (cachedData) {
46839
+ import_node_server_utils218.logger.info(`Cache hit for key: ${cacheKey}`);
46840
+ return cachedData;
46841
+ }
46842
+ try {
46843
+ const items = await collection.aggregate([
46844
+ { $match: query },
46845
+ { $sort: sort },
46846
+ { $skip: page * limit },
46847
+ { $limit: limit },
46848
+ {
46849
+ $project: {
46850
+ _id: 1,
46851
+ createdAt: 1,
46852
+ email: 1,
46853
+ type: 1,
46854
+ metadata: 1,
46855
+ status: 1
46856
+ }
46857
+ }
46858
+ ]).toArray();
46859
+ const length = await collection.countDocuments(query);
46860
+ const data = (0, import_node_server_utils218.paginate)(items, page, limit, length);
46861
+ setCache(cacheKey, data, 15 * 60).then(() => {
46862
+ import_node_server_utils218.logger.info(`Cache set for key: ${cacheKey}`);
46863
+ }).catch((err) => {
46864
+ import_node_server_utils218.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
46865
+ });
46866
+ return data;
46867
+ } catch (error) {
46868
+ import_node_server_utils218.logger.log({ level: "error", message: `${error}` });
46869
+ throw error;
46870
+ }
46871
+ }
46643
46872
  return {
46644
46873
  createIndex,
46645
46874
  createTextIndex,
46646
46875
  add,
46647
46876
  updateVerificationStatusById,
46648
46877
  getByVerificationCode,
46649
- getVerificationById
46878
+ getVerificationById,
46879
+ getVerifications
46650
46880
  };
46651
46881
  }
46652
46882
 
@@ -46990,6 +47220,7 @@ function useVerificationControllerV2() {
46990
47220
  createServiceProviderInvite: _createServiceProviderInvite,
46991
47221
  createForgetPassword: _createForgetPassword
46992
47222
  } = useVerificationServiceV2();
47223
+ const { getVerifications: _getVerifications } = useVerificationRepoV2();
46993
47224
  async function verify(req, res, next) {
46994
47225
  try {
46995
47226
  const schema2 = import_joi126.default.object({ verificationCode: import_joi126.default.string().required() });
@@ -47105,11 +47336,49 @@ function useVerificationControllerV2() {
47105
47336
  return;
47106
47337
  }
47107
47338
  }
47339
+ async function getVerifications(req, res, next) {
47340
+ const schema2 = import_joi126.default.object({
47341
+ search: import_joi126.default.string().optional().allow("", null),
47342
+ page: import_joi126.default.number().integer().min(1).allow("", null).default(1),
47343
+ status: import_joi126.default.string().required(),
47344
+ app: import_joi126.default.string().optional().allow("", null),
47345
+ type: import_joi126.default.alternatives().try(
47346
+ import_joi126.default.array().items(import_joi126.default.string()),
47347
+ import_joi126.default.string().custom((value2) => value2.split(","))
47348
+ ).optional().allow("", null),
47349
+ email: import_joi126.default.string().optional().allow("", null)
47350
+ });
47351
+ const { error, value } = schema2.validate(req.query);
47352
+ if (error) {
47353
+ const messages = error.details.map((d) => d.message).join(", ");
47354
+ import_node_server_utils220.logger.log({ level: "error", message: messages });
47355
+ next(new import_node_server_utils220.BadRequestError(messages));
47356
+ return;
47357
+ }
47358
+ const { search, page, status, app, email, type } = value;
47359
+ try {
47360
+ const data = await _getVerifications({
47361
+ search,
47362
+ page,
47363
+ status,
47364
+ app,
47365
+ type,
47366
+ email
47367
+ });
47368
+ res.json(data);
47369
+ return;
47370
+ } catch (error2) {
47371
+ import_node_server_utils220.logger.log({ level: "error", message: `${error2.message}` });
47372
+ next(error2);
47373
+ return;
47374
+ }
47375
+ }
47108
47376
  return {
47109
47377
  verify,
47110
47378
  createUserInvite,
47111
47379
  createServiceProviderInvite,
47112
- createForgetPassword
47380
+ createForgetPassword,
47381
+ getVerifications
47113
47382
  };
47114
47383
  }
47115
47384