@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/dist/index.mjs CHANGED
@@ -7415,6 +7415,34 @@ function useOrgController() {
7415
7415
  return;
7416
7416
  }
7417
7417
  }
7418
+ async function addOnboardingOrg(req, res, next) {
7419
+ const validation = Joi18.object({
7420
+ name: Joi18.string().required(),
7421
+ type: Joi18.string().required(),
7422
+ nature: Joi18.string().valid(...allowedNatures).required(),
7423
+ email: Joi18.string().email().optional().allow("", null),
7424
+ contact: Joi18.string().optional().allow("", null)
7425
+ });
7426
+ const { error } = validation.validate(req.body);
7427
+ if (error) {
7428
+ logger24.log({ level: "error", message: error.message });
7429
+ next(new BadRequestError32(error.message));
7430
+ return;
7431
+ }
7432
+ try {
7433
+ const _id = await _add(req.body);
7434
+ const data = await _getById(_id);
7435
+ res.status(201).json({
7436
+ message: "Successfully created organization.",
7437
+ data
7438
+ });
7439
+ return;
7440
+ } catch (error2) {
7441
+ logger24.log({ level: "error", message: error2.message });
7442
+ next(error2);
7443
+ return;
7444
+ }
7445
+ }
7418
7446
  async function getOrgsByUserId(req, res, next) {
7419
7447
  const validation = Joi18.object({
7420
7448
  search: Joi18.string().optional().allow("", null),
@@ -7513,6 +7541,7 @@ function useOrgController() {
7513
7541
  }
7514
7542
  return {
7515
7543
  add,
7544
+ addOnboardingOrg,
7516
7545
  getAll,
7517
7546
  getOrgsByUserId,
7518
7547
  getByName,
@@ -36807,6 +36836,81 @@ function useStatementOfAccountRepo() {
36807
36836
  throw new InternalServerError50("Failed to update soa request.");
36808
36837
  }
36809
36838
  }
36839
+ async function getResidentUserSoa({
36840
+ search = "",
36841
+ page = 1,
36842
+ limit = 10,
36843
+ sort = {},
36844
+ status = "pending",
36845
+ site = "",
36846
+ dateFrom,
36847
+ dateTo,
36848
+ unitId,
36849
+ category
36850
+ }, session) {
36851
+ page = page > 0 ? page - 1 : 0;
36852
+ let dateExpr = {};
36853
+ if (dateFrom && dateTo) {
36854
+ let startDate = new Date(dateFrom);
36855
+ startDate.setHours(0, 0, 0, 0);
36856
+ let endDate = new Date(dateTo);
36857
+ endDate.setHours(23, 59, 59, 999);
36858
+ dateExpr = {
36859
+ $expr: {
36860
+ $and: [
36861
+ { $gte: ["$createdAt", startDate] },
36862
+ { $lte: ["$createdAt", endDate] }
36863
+ ]
36864
+ }
36865
+ };
36866
+ }
36867
+ const unitSearchRegex = search ? search.trim().replace(/\s+/g, "").replace(/\//g, "\\s*/\\s*") : null;
36868
+ const query = {
36869
+ ...status && status !== "all" && { status },
36870
+ ...search && {
36871
+ $or: [
36872
+ { unitOwner: { $regex: search, $options: "i" } },
36873
+ { unit: { $regex: unitSearchRegex, $options: "i" } },
36874
+ { email: { $regex: search, $options: "i" } },
36875
+ { category: { $regex: search, $options: "i" } }
36876
+ ]
36877
+ },
36878
+ ...ObjectId97.isValid(site) && { site: new ObjectId97(site) },
36879
+ ...dateExpr,
36880
+ ...ObjectId97.isValid(unitId) && { unitId: new ObjectId97(unitId) },
36881
+ ...category && { category }
36882
+ };
36883
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
36884
+ try {
36885
+ const basePipeline = [
36886
+ { $match: query },
36887
+ {
36888
+ $addFields: {
36889
+ sortPriority: {
36890
+ $cond: [{ $eq: ["$status", "pending"] }, 1, 2]
36891
+ }
36892
+ }
36893
+ },
36894
+ {
36895
+ $sort: {
36896
+ sortPriority: 1,
36897
+ ...sort
36898
+ }
36899
+ },
36900
+ { $skip: page * limit },
36901
+ { $limit: limit }
36902
+ ];
36903
+ const [items, countResult] = await Promise.all([
36904
+ collection.aggregate(basePipeline, { session }).toArray(),
36905
+ collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
36906
+ ]);
36907
+ const totalCount = countResult[0]?.total || 0;
36908
+ const data = paginate42(items, page, limit, totalCount);
36909
+ return data;
36910
+ } catch (error) {
36911
+ throw error;
36912
+ }
36913
+ }
36810
36914
  function delCachedData() {
36811
36915
  delNamespace().then(() => {
36812
36916
  logger128.log({
@@ -36827,7 +36931,8 @@ function useStatementOfAccountRepo() {
36827
36931
  getById,
36828
36932
  updateById,
36829
36933
  deleteById,
36830
- updateStatusById
36934
+ updateStatusById,
36935
+ getResidentUserSoa
36831
36936
  };
36832
36937
  }
36833
36938
 
@@ -36984,7 +37089,8 @@ function useStatementOfAccountController() {
36984
37089
  getById: _getById,
36985
37090
  updateById: _updateById,
36986
37091
  deleteById: _deleteById,
36987
- updateStatusById: _updateStatusById
37092
+ updateStatusById: _updateStatusById,
37093
+ getResidentUserSoa: _getResidentUserSoa
36988
37094
  } = useStatementOfAccountRepo();
36989
37095
  const { add: _add, generatePDF: _generatePDF } = useStatementOfAccountService();
36990
37096
  async function add(req, res, next) {
@@ -37235,6 +37341,57 @@ function useStatementOfAccountController() {
37235
37341
  return;
37236
37342
  }
37237
37343
  }
37344
+ async function getResidentUserSoa(req, res, next) {
37345
+ const validation = Joi93.object({
37346
+ page: Joi93.number().integer().min(1).allow("", null).default(1),
37347
+ limit: Joi93.number().integer().min(1).max(100).allow("", null).default(10),
37348
+ status: Joi93.string().optional().allow(null, ""),
37349
+ search: Joi93.string().optional().allow(null, ""),
37350
+ site: Joi93.string().required(),
37351
+ dateFrom: Joi93.string().optional().allow(null, ""),
37352
+ dateTo: Joi93.string().optional().allow(null, ""),
37353
+ unitId: Joi93.string().required(),
37354
+ category: Joi93.string().optional().allow(null, "")
37355
+ });
37356
+ const query = { ...req.query };
37357
+ const { error } = validation.validate(query, {
37358
+ abortEarly: false
37359
+ });
37360
+ if (error) {
37361
+ const messages = error.details.map((d) => d.message).join(", ");
37362
+ logger130.log({ level: "error", message: messages });
37363
+ next(new BadRequestError153(messages));
37364
+ return;
37365
+ }
37366
+ const search = req.query.search ?? "";
37367
+ const page = parseInt(req.query.page ?? "1");
37368
+ const limit = parseInt(req.query.limit ?? "10");
37369
+ const status = req.query.status ?? "active";
37370
+ const site = req.query.site;
37371
+ const dateFrom = req.query.dateFrom ?? "";
37372
+ const dateTo = req.query.dateTo ?? "";
37373
+ const unitId = req.query.unitId;
37374
+ const category = req.query.category ?? "";
37375
+ try {
37376
+ const data = await _getResidentUserSoa({
37377
+ search,
37378
+ page,
37379
+ limit,
37380
+ status,
37381
+ site,
37382
+ dateFrom,
37383
+ dateTo,
37384
+ unitId,
37385
+ category
37386
+ });
37387
+ res.status(200).json(data);
37388
+ return;
37389
+ } catch (error2) {
37390
+ logger130.log({ level: "error", message: error2.message });
37391
+ next(error2);
37392
+ return;
37393
+ }
37394
+ }
37238
37395
  return {
37239
37396
  add,
37240
37397
  getAll,
@@ -37242,7 +37399,8 @@ function useStatementOfAccountController() {
37242
37399
  updateById,
37243
37400
  deleteById,
37244
37401
  generatePDF,
37245
- updateStatusById
37402
+ updateStatusById,
37403
+ getResidentUserSoa
37246
37404
  };
37247
37405
  }
37248
37406
 
@@ -40391,7 +40549,7 @@ function useOccurrenceEntryService() {
40391
40549
  value.signature = value.signature ? new ObjectId108(value.signature) : occurrenceEntry.signature._id;
40392
40550
  value.eSignature = value.eSignature ? new ObjectId108(value.eSignature) : occurrenceEntry.eSignature;
40393
40551
  value.createdAt = /* @__PURE__ */ new Date();
40394
- value.date = /* @__PURE__ */ new Date();
40552
+ value.date = value.date ? value.date : occurrenceEntry.date;
40395
40553
  value.userName = value.userName ? value.userName : occurrenceEntry.signature.name;
40396
40554
  value.createdByName = value.createdByName ? value.createdByName : occurrenceEntry.createdByName;
40397
40555
  await _updateOccurrenceBookById(dobId, {
@@ -46762,6 +46920,7 @@ import {
46762
46920
  InternalServerError as InternalServerError68,
46763
46921
  logger as logger175,
46764
46922
  makeCacheKey as makeCacheKey64,
46923
+ paginate as paginate57,
46765
46924
  toObjectId as toObjectId17,
46766
46925
  useAtlas as useAtlas112,
46767
46926
  useCache as useCache66
@@ -46889,13 +47048,85 @@ function useVerificationRepoV2() {
46889
47048
  );
46890
47049
  }
46891
47050
  }
47051
+ async function getVerifications({
47052
+ search = "",
47053
+ page = 1,
47054
+ limit = 10,
47055
+ sort = {},
47056
+ status = "active",
47057
+ app = "",
47058
+ type = {},
47059
+ email = ""
47060
+ }) {
47061
+ page = page > 0 ? page - 1 : 0;
47062
+ const query = { status };
47063
+ const cacheOptions = {
47064
+ page,
47065
+ limit,
47066
+ status
47067
+ };
47068
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
47069
+ cacheOptions.sort = JSON.stringify(sort);
47070
+ if (search) {
47071
+ query.$text = { $search: search };
47072
+ cacheOptions.search = search;
47073
+ }
47074
+ if (app) {
47075
+ query["metadata.app"] = app;
47076
+ cacheOptions["metadata.app"] = app;
47077
+ }
47078
+ if (type && Object.keys(type).length > 0) {
47079
+ query.type = { $in: Object.keys(type) };
47080
+ cacheOptions.type = JSON.stringify(type);
47081
+ }
47082
+ if (email) {
47083
+ query.email = email;
47084
+ cacheOptions.email = email;
47085
+ }
47086
+ const cacheKey = makeCacheKey64(namespace_collection, cacheOptions);
47087
+ const cachedData = await getCache(cacheKey);
47088
+ if (cachedData) {
47089
+ logger175.info(`Cache hit for key: ${cacheKey}`);
47090
+ return cachedData;
47091
+ }
47092
+ try {
47093
+ const items = await collection.aggregate([
47094
+ { $match: query },
47095
+ { $sort: sort },
47096
+ { $skip: page * limit },
47097
+ { $limit: limit },
47098
+ {
47099
+ $project: {
47100
+ _id: 1,
47101
+ createdAt: 1,
47102
+ email: 1,
47103
+ type: 1,
47104
+ metadata: 1,
47105
+ status: 1
47106
+ }
47107
+ }
47108
+ ]).toArray();
47109
+ const length = await collection.countDocuments(query);
47110
+ const data = paginate57(items, page, limit, length);
47111
+ setCache(cacheKey, data, 15 * 60).then(() => {
47112
+ logger175.info(`Cache set for key: ${cacheKey}`);
47113
+ }).catch((err) => {
47114
+ logger175.error(`Failed to set cache for key: ${cacheKey}`, err);
47115
+ });
47116
+ return data;
47117
+ } catch (error) {
47118
+ logger175.log({ level: "error", message: `${error}` });
47119
+ throw error;
47120
+ }
47121
+ }
46892
47122
  return {
46893
47123
  createIndex,
46894
47124
  createTextIndex,
46895
47125
  add,
46896
47126
  updateVerificationStatusById,
46897
47127
  getByVerificationCode,
46898
- getVerificationById
47128
+ getVerificationById,
47129
+ getVerifications
46899
47130
  };
46900
47131
  }
46901
47132
 
@@ -47249,6 +47480,7 @@ function useVerificationControllerV2() {
47249
47480
  createServiceProviderInvite: _createServiceProviderInvite,
47250
47481
  createForgetPassword: _createForgetPassword
47251
47482
  } = useVerificationServiceV2();
47483
+ const { getVerifications: _getVerifications } = useVerificationRepoV2();
47252
47484
  async function verify(req, res, next) {
47253
47485
  try {
47254
47486
  const schema2 = Joi126.object({ verificationCode: Joi126.string().required() });
@@ -47364,11 +47596,49 @@ function useVerificationControllerV2() {
47364
47596
  return;
47365
47597
  }
47366
47598
  }
47599
+ async function getVerifications(req, res, next) {
47600
+ const schema2 = Joi126.object({
47601
+ search: Joi126.string().optional().allow("", null),
47602
+ page: Joi126.number().integer().min(1).allow("", null).default(1),
47603
+ status: Joi126.string().required(),
47604
+ app: Joi126.string().optional().allow("", null),
47605
+ type: Joi126.alternatives().try(
47606
+ Joi126.array().items(Joi126.string()),
47607
+ Joi126.string().custom((value2) => value2.split(","))
47608
+ ).optional().allow("", null),
47609
+ email: Joi126.string().optional().allow("", null)
47610
+ });
47611
+ const { error, value } = schema2.validate(req.query);
47612
+ if (error) {
47613
+ const messages = error.details.map((d) => d.message).join(", ");
47614
+ logger177.log({ level: "error", message: messages });
47615
+ next(new BadRequestError197(messages));
47616
+ return;
47617
+ }
47618
+ const { search, page, status, app, email, type } = value;
47619
+ try {
47620
+ const data = await _getVerifications({
47621
+ search,
47622
+ page,
47623
+ status,
47624
+ app,
47625
+ type,
47626
+ email
47627
+ });
47628
+ res.json(data);
47629
+ return;
47630
+ } catch (error2) {
47631
+ logger177.log({ level: "error", message: `${error2.message}` });
47632
+ next(error2);
47633
+ return;
47634
+ }
47635
+ }
47367
47636
  return {
47368
47637
  verify,
47369
47638
  createUserInvite,
47370
47639
  createServiceProviderInvite,
47371
- createForgetPassword
47640
+ createForgetPassword,
47641
+ getVerifications
47372
47642
  };
47373
47643
  }
47374
47644