@7365admin1/core 2.42.0 → 2.43.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
@@ -4813,7 +4813,10 @@ function useSiteRepo() {
4813
4813
  throw error;
4814
4814
  }
4815
4815
  }
4816
- async function siteInformation({ id, payload }) {
4816
+ async function siteInformation({
4817
+ id,
4818
+ payload
4819
+ }) {
4817
4820
  try {
4818
4821
  const siteId = new ObjectId17(id);
4819
4822
  const res = await collection.updateOne(
@@ -4833,6 +4836,48 @@ function useSiteRepo() {
4833
4836
  throw error;
4834
4837
  }
4835
4838
  }
4839
+ async function getAllSitesForResidentCreation({
4840
+ search = "",
4841
+ page = 1,
4842
+ limit = 10
4843
+ }) {
4844
+ page = page > 0 ? page - 1 : 0;
4845
+ const query = {
4846
+ status: { $ne: "deleted" }
4847
+ };
4848
+ const cacheOptions = {
4849
+ status: { $ne: "deleted" },
4850
+ page,
4851
+ limit
4852
+ };
4853
+ if (search) {
4854
+ query.$or = [{ name: { $regex: search, $options: "i" } }];
4855
+ cacheOptions.search = search;
4856
+ }
4857
+ const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
4858
+ const cachedData = await getCache(cacheKey);
4859
+ if (cachedData) {
4860
+ logger12.info(`Cache hit for key: ${cacheKey}`);
4861
+ return cachedData;
4862
+ }
4863
+ try {
4864
+ const items = await collection.aggregate([
4865
+ { $match: query },
4866
+ { $skip: page * limit },
4867
+ { $limit: limit }
4868
+ ]).toArray();
4869
+ const length = await collection.countDocuments(query);
4870
+ const data = paginate8(items, page, limit, length);
4871
+ setCache(cacheKey, data, 15 * 60).then(() => {
4872
+ logger12.info(`Cache set for key: ${cacheKey}`);
4873
+ }).catch((err) => {
4874
+ logger12.error(`Failed to set cache for key: ${cacheKey}`, err);
4875
+ });
4876
+ return data;
4877
+ } catch (error) {
4878
+ throw error;
4879
+ }
4880
+ }
4836
4881
  return {
4837
4882
  createIndexes,
4838
4883
  createSite,
@@ -4847,7 +4892,8 @@ function useSiteRepo() {
4847
4892
  updateSiteIncidentCounter,
4848
4893
  updateSiteById,
4849
4894
  getAllSitesUnpaginated,
4850
- siteInformation
4895
+ siteInformation,
4896
+ getAllSitesForResidentCreation
4851
4897
  };
4852
4898
  }
4853
4899
 
@@ -12063,7 +12109,7 @@ function useServiceProviderController() {
12063
12109
  const validation = Joi30.object({
12064
12110
  search: Joi30.string().optional().allow("", null),
12065
12111
  page: Joi30.number().integer().min(1).allow("", null).default(1),
12066
- limit: Joi30.number().integer().min(1).max(100).allow("", null).default(10),
12112
+ limit: Joi30.number().integer().min(1).max(1e3).allow("", null).default(10),
12067
12113
  orgId: Joi30.string().hex().optional().allow("", null),
12068
12114
  siteId: Joi30.string().hex().optional().allow("", null),
12069
12115
  serviceProviderOrgId: Joi30.string().hex().optional().allow("", null),
@@ -13296,7 +13342,8 @@ var schemaPerson = Joi35.object({
13296
13342
  isOwner: Joi35.boolean().required(),
13297
13343
  files: Joi35.array().items(schemaFiles).optional().allow(null),
13298
13344
  password: Joi35.string().optional().allow(null, ""),
13299
- plateNumber: Joi35.string().optional().allow(null, "")
13345
+ plateNumber: Joi35.string().optional().allow(null, ""),
13346
+ platform: Joi35.string().valid("web", "mobile").optional().allow(null, "")
13300
13347
  });
13301
13348
  var schemaUpdatePerson = Joi35.object({
13302
13349
  _id: Joi35.string().hex().required(),
@@ -13317,12 +13364,13 @@ var schemaUpdatePerson = Joi35.object({
13317
13364
  isOwner: Joi35.boolean().optional().allow(null, ""),
13318
13365
  files: Joi35.array().items(schemaFiles).optional().allow(null),
13319
13366
  password: Joi35.string().optional().allow(null, ""),
13320
- plateNumber: Joi35.string().optional().allow(null, "")
13367
+ plateNumber: Joi35.string().optional().allow(null, ""),
13368
+ platform: Joi35.string().valid("web", "mobile").optional().allow(null, "")
13321
13369
  });
13322
13370
  function MPerson(value) {
13323
13371
  const { error } = schemaPerson.validate(value);
13324
13372
  if (error) {
13325
- throw new Error(error.details[0].message);
13373
+ throw new BadRequestError66(error.details[0].message);
13326
13374
  }
13327
13375
  if (value._id && typeof value._id === "string") {
13328
13376
  try {
@@ -13388,6 +13436,7 @@ function MPerson(value) {
13388
13436
  isOwner: value.isOwner ?? false,
13389
13437
  files: value.files ?? [],
13390
13438
  plateNumber: value.plateNumber ?? "",
13439
+ platForm: value.platform ?? "",
13391
13440
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
13392
13441
  updatedAt: value.updatedAt,
13393
13442
  deletedAt: value.deletedAt
@@ -13426,8 +13475,8 @@ var schemaVisitorTransaction = Joi36.object({
13426
13475
  contact: Joi36.string().optional().allow(null, ""),
13427
13476
  plateNumber: Joi36.string().optional().allow(null, ""),
13428
13477
  recNo: Joi36.string().optional().allow(null, ""),
13429
- checkIn: Joi36.date().optional().allow(null, ""),
13430
- checkOut: Joi36.date().optional().allow(null, ""),
13478
+ checkIn: Joi36.date().iso().optional().allow(null),
13479
+ checkOut: Joi36.date().iso().optional().allow(null),
13431
13480
  deliveryType: Joi36.string().optional().allow(null, ""),
13432
13481
  status: Joi36.string().optional().valid(...Object.values(VisitorStatus)).default("registered" /* REGISTERED */),
13433
13482
  remarks: Joi36.string().optional().allow(null, ""),
@@ -13491,8 +13540,8 @@ var schemaUpdateVisTrans = Joi36.object({
13491
13540
  contact: Joi36.string().optional().allow(null, ""),
13492
13541
  plateNumber: Joi36.string().optional().allow(null, ""),
13493
13542
  recNo: Joi36.string().optional().allow(null, ""),
13494
- checkIn: Joi36.date().optional().allow(null, ""),
13495
- checkOut: Joi36.date().optional().allow(null, ""),
13543
+ checkIn: Joi36.date().iso().optional().allow(null),
13544
+ checkOut: Joi36.date().iso().optional().allow(null),
13496
13545
  deliveryType: Joi36.string().optional().allow(null, ""),
13497
13546
  status: Joi36.string().optional().allow(null, ""),
13498
13547
  remarks: Joi36.string().optional().allow(null, ""),
@@ -15092,7 +15141,7 @@ function usePersonRepo() {
15092
15141
  ]
15093
15142
  } : void 0;
15094
15143
  const query = {
15095
- status,
15144
+ ...status && status !== "all" ? { status } : { status: { $nin: ["deleted", "rejected"] } },
15096
15145
  ...start && { start },
15097
15146
  ...end,
15098
15147
  ...search && {
@@ -15130,12 +15179,29 @@ function usePersonRepo() {
15130
15179
  return cachedData;
15131
15180
  }
15132
15181
  try {
15133
- const basePipeline = [
15134
- { $match: query },
15135
- { $sort: sort },
15136
- { $skip: page * limit },
15137
- { $limit: limit }
15138
- ];
15182
+ const basePipeline = [{ $match: query }];
15183
+ if (status && status == "all") {
15184
+ basePipeline.push(
15185
+ {
15186
+ $addFields: {
15187
+ sortPriority: {
15188
+ $cond: [{ $eq: ["$status", "pending"] }, 1, 2]
15189
+ }
15190
+ }
15191
+ },
15192
+ {
15193
+ $sort: {
15194
+ sortPriority: 1,
15195
+ ...sort
15196
+ }
15197
+ }
15198
+ );
15199
+ } else {
15200
+ basePipeline.push({
15201
+ $sort: sort
15202
+ });
15203
+ }
15204
+ basePipeline.push({ $skip: page * limit }, { $limit: limit });
15139
15205
  const [items, countResult] = await Promise.all([
15140
15206
  collection.aggregate(basePipeline, { session }).toArray(),
15141
15207
  collection.aggregate([{ $match: query }, { $count: "total" }], { session }).toArray()
@@ -17915,7 +17981,8 @@ function useSiteController() {
17915
17981
  getSites: _getSites,
17916
17982
  getSiteById: _getSiteById,
17917
17983
  updateSiteBlock: _updateSiteBlock,
17918
- deleteSite: _deleteSite
17984
+ deleteSite: _deleteSite,
17985
+ getAllSitesForResidentCreation: _getAllSitesForResidentCreation
17919
17986
  } = useSiteRepo();
17920
17987
  const { updateGuardPostById, siteInformation: _siteInformation } = useSiteService();
17921
17988
  async function createSite(req, res, next) {
@@ -18100,14 +18167,13 @@ function useSiteController() {
18100
18167
  id: Joi42.string().hex().required(),
18101
18168
  bgImage: Joi42.string().optional().allow("", null),
18102
18169
  description: Joi42.string().optional().allow("", null),
18103
- docs: Joi42.array().items(Joi42.object({
18104
- id: Joi42.string().hex().optional().allow("", null),
18105
- name: Joi42.string().optional().allow("", null)
18106
- })).optional().allow("", null)
18107
- }).validate(
18108
- { id, ...payload },
18109
- { abortEarly: false }
18110
- );
18170
+ docs: Joi42.array().items(
18171
+ Joi42.object({
18172
+ id: Joi42.string().hex().optional().allow("", null),
18173
+ name: Joi42.string().optional().allow("", null)
18174
+ })
18175
+ ).optional().allow("", null)
18176
+ }).validate({ id, ...payload }, { abortEarly: false });
18111
18177
  if (error) {
18112
18178
  logger57.log({ level: "error", message: error.message });
18113
18179
  next(new BadRequestError76(error.message));
@@ -18123,6 +18189,36 @@ function useSiteController() {
18123
18189
  return;
18124
18190
  }
18125
18191
  }
18192
+ async function getAllSitesForResidentCreation(req, res, next) {
18193
+ const validation = Joi42.object({
18194
+ search: Joi42.string().optional().allow("", null),
18195
+ page: Joi42.number().integer().min(1).allow("", null).default(1),
18196
+ limit: Joi42.number().integer().min(1).max(100).allow("", null).default(10)
18197
+ });
18198
+ const query = { ...req.query };
18199
+ const { error } = validation.validate(query);
18200
+ if (error) {
18201
+ logger57.log({ level: "error", message: error.message });
18202
+ next(new BadRequestError76(error.message));
18203
+ return;
18204
+ }
18205
+ const search = req.query.search ?? "";
18206
+ const page = parseInt(req.query.page ?? "1");
18207
+ const limit = parseInt(req.query.limit ?? "10");
18208
+ try {
18209
+ const data = await _getAllSitesForResidentCreation({
18210
+ search,
18211
+ page,
18212
+ limit
18213
+ });
18214
+ res.json(data);
18215
+ return;
18216
+ } catch (error2) {
18217
+ logger57.log({ level: "error", message: error2.message });
18218
+ next(error2);
18219
+ return;
18220
+ }
18221
+ }
18126
18222
  return {
18127
18223
  createSite,
18128
18224
  getSites,
@@ -18131,7 +18227,8 @@ function useSiteController() {
18131
18227
  deleteSite,
18132
18228
  updateById,
18133
18229
  updateGuardPostsById,
18134
- siteInformation
18230
+ siteInformation,
18231
+ getAllSitesForResidentCreation
18135
18232
  };
18136
18233
  }
18137
18234
 
@@ -22852,6 +22949,14 @@ function useVisitorTransactionService() {
22852
22949
  }
22853
22950
  value.passKeys = keptPassKeys;
22854
22951
  }
22952
+ if (value.checkIn) {
22953
+ const parsed = new Date(value.checkIn);
22954
+ value.checkIn = isNaN(parsed.getTime()) ? null : parsed;
22955
+ }
22956
+ if (value.checkOut) {
22957
+ const parsed = new Date(value.checkOut);
22958
+ value.checkOut = isNaN(parsed.getTime()) ? null : parsed;
22959
+ }
22855
22960
  await _updateVisitorTansactionById(id, value, session);
22856
22961
  await session?.commitTransaction();
22857
22962
  return "Successfully updated visitor transaction.";
@@ -23865,10 +23970,11 @@ function usePersonService() {
23865
23970
  email: value.email,
23866
23971
  password: hashedPassword,
23867
23972
  name: value.name,
23973
+ status: value.platform == "mobile" ? "deleted" : "active",
23868
23974
  defaultOrg: value.org?.toString() || ""
23869
23975
  };
23870
23976
  const userId = await addUser(user, session);
23871
- value.user = userId;
23977
+ value.user = userId.toString();
23872
23978
  let org = null;
23873
23979
  if (userId) {
23874
23980
  if (value?.org) {
@@ -29539,7 +29645,7 @@ function useBulletinBoardController() {
29539
29645
  page: Joi76.number().integer().min(1).allow("", null).default(1),
29540
29646
  limit: Joi76.number().integer().min(1).max(100).allow("", null).default(10),
29541
29647
  sort: Joi76.string().valid(...Object.values(BulletinSort)).default("_id" /* ID */),
29542
- order: Joi76.string().valid(...Object.values(SortOrder)).default("asc" /* ASC */),
29648
+ order: Joi76.string().valid(...Object.values(SortOrder)).default("desc" /* DESC */),
29543
29649
  site: Joi76.string().hex().length(24).required(),
29544
29650
  status: Joi76.string().valid(...Object.values(BuildingStatus)).optional().default("active" /* ACTIVE */),
29545
29651
  recipients: Joi76.alternatives().try(