@7365admin1/core 2.53.0 → 2.54.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
@@ -4114,12 +4114,13 @@ function useOrgRepo() {
4114
4114
  status = "active",
4115
4115
  nature = ""
4116
4116
  }) {
4117
- page = page > 0 ? page - 1 : 0;
4118
4117
  const query = { status };
4119
4118
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
4120
4119
  const cacheOptions = {
4121
4120
  status,
4122
- sort
4121
+ sort,
4122
+ page,
4123
+ limit
4123
4124
  };
4124
4125
  if (search) {
4125
4126
  query.$text = { $search: search };
@@ -4135,11 +4136,12 @@ function useOrgRepo() {
4135
4136
  logger10.info(`Cache hit for key: ${cacheKey}`);
4136
4137
  return cachedData;
4137
4138
  }
4139
+ const normalizedPage = page > 0 ? page - 1 : 0;
4138
4140
  try {
4139
4141
  const items = await collection.aggregate([
4140
4142
  { $match: query },
4141
4143
  { $sort: sort },
4142
- { $skip: page * limit },
4144
+ { $skip: normalizedPage * limit },
4143
4145
  { $limit: limit },
4144
4146
  {
4145
4147
  $project: {
@@ -4153,7 +4155,7 @@ function useOrgRepo() {
4153
4155
  }
4154
4156
  ]).toArray();
4155
4157
  const length = await collection.countDocuments(query);
4156
- const data = paginate7(items, page, limit, length);
4158
+ const data = paginate7(items, normalizedPage, limit, length);
4157
4159
  setCache(cacheKey, data, 15 * 60).then(() => {
4158
4160
  logger10.info(`Cache set for key: ${cacheKey}`);
4159
4161
  }).catch((err) => {
@@ -5310,11 +5312,16 @@ function useVerificationService() {
5310
5312
  const existing = await useVerificationRepo().findOne({
5311
5313
  type,
5312
5314
  email,
5313
- "metadata.org": metadata?.org,
5314
- "metadata.siteId": metadata?.siteId
5315
+ "metadata.app": metadata.app
5315
5316
  });
5316
- if (existing)
5317
+ if (existing) {
5318
+ if (existing.status === "complete") {
5319
+ throw new BadRequestError20(
5320
+ `User already completed invite for app: ${metadata.app}`
5321
+ );
5322
+ }
5317
5323
  return existing._id;
5324
+ }
5318
5325
  const value = {
5319
5326
  type,
5320
5327
  email,
@@ -7571,6 +7578,7 @@ function useVerificationController() {
7571
7578
  createServiceProviderInvite: _createServiceProviderInvite,
7572
7579
  createForgetPassword: _createForgetPassword,
7573
7580
  verify: _verify,
7581
+ updateStatusById: _updateStatusById,
7574
7582
  cancelUserInvitation: _cancelUserInvitation
7575
7583
  } = useVerificationService();
7576
7584
  const { getVerifications: _getVerifications } = useVerificationRepo();
@@ -7784,6 +7792,28 @@ function useVerificationController() {
7784
7792
  return;
7785
7793
  }
7786
7794
  }
7795
+ async function updateVerificationStatus(req, res, next) {
7796
+ const validation = Joi16.object({
7797
+ id: Joi16.string().hex().required(),
7798
+ status: Joi16.string().valid("pending", "complete", "expired", "cancelled").required()
7799
+ });
7800
+ const { error } = validation.validate(req.body);
7801
+ if (error) {
7802
+ logger22.log({ level: "error", message: error.message });
7803
+ next(new BadRequestError31(error.message));
7804
+ return;
7805
+ }
7806
+ try {
7807
+ const { id, status } = req.body;
7808
+ const result = await _updateStatusById(id, status);
7809
+ res.json({ message: result });
7810
+ return;
7811
+ } catch (error2) {
7812
+ logger22.log({ level: "error", message: error2.message });
7813
+ next(error2);
7814
+ return;
7815
+ }
7816
+ }
7787
7817
  async function cancelUserInvitation(req, res, next) {
7788
7818
  const validation = Joi16.string().hex().required();
7789
7819
  const otpId = req.params.id;
@@ -7811,6 +7841,7 @@ function useVerificationController() {
7811
7841
  createServiceProviderInvite,
7812
7842
  createForgetPassword,
7813
7843
  verify,
7844
+ updateVerificationStatus,
7814
7845
  cancelUserInvitation,
7815
7846
  createSimpleUserInvite
7816
7847
  };
@@ -13708,9 +13739,26 @@ function useVisitorTransactionRepo() {
13708
13739
  ...status && { status },
13709
13740
  ...tab == "Overnight Parking" && { isOvernightParking: true }
13710
13741
  };
13711
- sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
13742
+ sort = Object.keys(sort).length > 0 ? sort : { latestDate: -1 };
13712
13743
  try {
13713
- const basePipeline = [{ $match: query }];
13744
+ const basePipeline = [
13745
+ { $match: query },
13746
+ {
13747
+ $addFields: {
13748
+ latestDate: {
13749
+ $max: ["$createdAt", "$updatedAt"]
13750
+ }
13751
+ }
13752
+ },
13753
+ { $sort: { latestDate: -1 } },
13754
+ { $skip: skip },
13755
+ { $limit: limit },
13756
+ {
13757
+ $project: {
13758
+ latestDate: 0
13759
+ }
13760
+ }
13761
+ ];
13714
13762
  const [items, countResult] = await Promise.all([
13715
13763
  collection.aggregate([
13716
13764
  ...basePipeline,
@@ -13850,9 +13898,6 @@ function useVisitorTransactionRepo() {
13850
13898
  as: "passKeys"
13851
13899
  }
13852
13900
  },
13853
- { $sort: sort },
13854
- { $skip: skip },
13855
- { $limit: limit },
13856
13901
  {
13857
13902
  $lookup: {
13858
13903
  from: "users",
@@ -15863,14 +15908,16 @@ function MBuildingUnit(value) {
15863
15908
 
15864
15909
  // src/repositories/building-unit.repository.ts
15865
15910
  import { ObjectId as ObjectId45 } from "mongodb";
15911
+ var building_units_namespace_collection = "building-units";
15866
15912
  function useBuildingUnitRepo() {
15867
15913
  const db = useAtlas33.getDb();
15868
15914
  if (!db) {
15869
15915
  throw new Error("Unable to connect to server.");
15870
15916
  }
15871
- const namespace_collection = "building-units";
15872
- const collection = db.collection(namespace_collection);
15873
- const { getCache, setCache, delNamespace, delCache } = useCache25(namespace_collection);
15917
+ const collection = db.collection(building_units_namespace_collection);
15918
+ const { getCache, setCache, delNamespace, delCache } = useCache25(
15919
+ building_units_namespace_collection
15920
+ );
15874
15921
  async function createIndexes() {
15875
15922
  try {
15876
15923
  await collection.createIndexes([
@@ -15896,12 +15943,12 @@ function useBuildingUnitRepo() {
15896
15943
  delNamespace().then(() => {
15897
15944
  logger52.log({
15898
15945
  level: "info",
15899
- message: `Cache namespace cleared for ${namespace_collection}`
15946
+ message: `Cache namespace cleared for ${building_units_namespace_collection}`
15900
15947
  });
15901
15948
  }).catch((err) => {
15902
15949
  logger52.log({
15903
15950
  level: "error",
15904
- message: `Failed to clear cache namespace for ${namespace_collection}: ${err.message}`
15951
+ message: `Failed to clear cache namespace for ${building_units_namespace_collection}: ${err.message}`
15905
15952
  });
15906
15953
  });
15907
15954
  }
@@ -16048,7 +16095,10 @@ function useBuildingUnitRepo() {
16048
16095
  ...building && { building },
16049
16096
  ...status && { status }
16050
16097
  };
16051
- const cacheKey = makeCacheKey24(namespace_collection, cacheParams);
16098
+ const cacheKey = makeCacheKey24(
16099
+ building_units_namespace_collection,
16100
+ cacheParams
16101
+ );
16052
16102
  logger52.log({
16053
16103
  level: "info",
16054
16104
  message: `Cache key for getAll building units: ${cacheKey}`
@@ -16119,7 +16169,9 @@ function useBuildingUnitRepo() {
16119
16169
  } catch (error) {
16120
16170
  throw new BadRequestError71("Invalid ID.");
16121
16171
  }
16122
- const cacheKey = makeCacheKey24(namespace_collection, { _id: String(_id) });
16172
+ const cacheKey = makeCacheKey24(building_units_namespace_collection, {
16173
+ _id: String(_id)
16174
+ });
16123
16175
  try {
16124
16176
  const cached = await getCache(cacheKey);
16125
16177
  if (cached) {
@@ -16162,7 +16214,7 @@ function useBuildingUnitRepo() {
16162
16214
  } catch (error) {
16163
16215
  throw new BadRequestError71("Invalid building ID.");
16164
16216
  }
16165
- const cacheKey = makeCacheKey24(namespace_collection, {
16217
+ const cacheKey = makeCacheKey24(building_units_namespace_collection, {
16166
16218
  building: String(building),
16167
16219
  level
16168
16220
  });
@@ -16236,7 +16288,7 @@ function useBuildingUnitRepo() {
16236
16288
  } catch (error) {
16237
16289
  throw new BadRequestError71("Invalid building ID.");
16238
16290
  }
16239
- const cacheKey = makeCacheKey24(namespace_collection, {
16291
+ const cacheKey = makeCacheKey24(building_units_namespace_collection, {
16240
16292
  building: String(building)
16241
16293
  });
16242
16294
  try {
@@ -16310,7 +16362,10 @@ function useBuildingUnitRepo() {
16310
16362
  block,
16311
16363
  level
16312
16364
  };
16313
- const cacheKey = makeCacheKey24(namespace_collection, cacheOptions);
16365
+ const cacheKey = makeCacheKey24(
16366
+ building_units_namespace_collection,
16367
+ cacheOptions
16368
+ );
16314
16369
  const cachedData = await getCache(cacheKey);
16315
16370
  if (cachedData) {
16316
16371
  logger52.info(`Cache hit for key: ${cacheKey}`);
@@ -16348,7 +16403,10 @@ function useBuildingUnitRepo() {
16348
16403
  const cacheOptions = {
16349
16404
  site: site.toString()
16350
16405
  };
16351
- const cacheKey = makeCacheKey24(namespace_collection, cacheOptions);
16406
+ const cacheKey = makeCacheKey24(
16407
+ building_units_namespace_collection,
16408
+ cacheOptions
16409
+ );
16352
16410
  const cachedData = await getCache(cacheKey);
16353
16411
  if (cachedData) {
16354
16412
  logger52.info(`Cache hit for key: ${cacheKey}`);
@@ -16396,7 +16454,10 @@ function useBuildingUnitRepo() {
16396
16454
  { deletedAt: "" }
16397
16455
  ]
16398
16456
  };
16399
- const cacheKey = makeCacheKey24(namespace_collection, cacheOptions);
16457
+ const cacheKey = makeCacheKey24(
16458
+ building_units_namespace_collection,
16459
+ cacheOptions
16460
+ );
16400
16461
  try {
16401
16462
  const cached = await getCache(cacheKey);
16402
16463
  if (cached) {
@@ -16432,6 +16493,54 @@ function useBuildingUnitRepo() {
16432
16493
  }
16433
16494
  }
16434
16495
  }
16496
+ async function getBySiteBuildingLevel(site, block, level) {
16497
+ try {
16498
+ site = new ObjectId45(site);
16499
+ } catch (error) {
16500
+ throw new BadRequestError71("Invalid site ID.");
16501
+ }
16502
+ const cacheKey = makeCacheKey24(building_units_namespace_collection, {
16503
+ site: site.toString(),
16504
+ block,
16505
+ level
16506
+ });
16507
+ try {
16508
+ const cached = await getCache(cacheKey);
16509
+ if (cached) {
16510
+ logger52.log({
16511
+ level: "info",
16512
+ message: `Cache hit for getById building unit: ${cacheKey}`
16513
+ });
16514
+ return cached;
16515
+ }
16516
+ const query = {
16517
+ site,
16518
+ block,
16519
+ level,
16520
+ status: "active"
16521
+ };
16522
+ console.log(query);
16523
+ const result = await collection.findOne(query);
16524
+ setCache(cacheKey, result, 300).then(() => {
16525
+ logger52.log({
16526
+ level: "info",
16527
+ message: `Cache set for building unit by id: ${cacheKey}`
16528
+ });
16529
+ }).catch((err) => {
16530
+ logger52.log({
16531
+ level: "error",
16532
+ message: `Failed to set cache for building unit by id: ${err.message}`
16533
+ });
16534
+ });
16535
+ return result;
16536
+ } catch (error) {
16537
+ if (error instanceof AppError10) {
16538
+ throw error;
16539
+ } else {
16540
+ throw new InternalServerError27("Failed to get building unit.");
16541
+ }
16542
+ }
16543
+ }
16435
16544
  return {
16436
16545
  createIndexes,
16437
16546
  add,
@@ -16445,7 +16554,8 @@ function useBuildingUnitRepo() {
16445
16554
  updateByBuildingId,
16446
16555
  getBuildingUnits,
16447
16556
  getBuildingUnitsWithOwner,
16448
- getUnitByBlockLevelUnitNumber
16557
+ getUnitByBlockLevelUnitNumber,
16558
+ getBySiteBuildingLevel
16449
16559
  };
16450
16560
  }
16451
16561
 
@@ -19121,6 +19231,7 @@ function useBuildingRepo() {
19121
19231
  throw new Error("Failed to create index on buildings. " + error.message);
19122
19232
  }
19123
19233
  }
19234
+ const { getBySiteBuildingLevel: _getBySiteBuildingLevel } = useBuildingUnitRepo();
19124
19235
  async function add(value, session) {
19125
19236
  try {
19126
19237
  value = MBuilding(value);
@@ -19356,6 +19467,64 @@ function useBuildingRepo() {
19356
19467
  }
19357
19468
  }
19358
19469
  }
19470
+ async function getBuildingLevelWithUnits(site, block) {
19471
+ try {
19472
+ site = new ObjectId49(site);
19473
+ } catch (error) {
19474
+ throw new BadRequestError79("Invalid ID.");
19475
+ }
19476
+ const query = {
19477
+ site,
19478
+ block
19479
+ };
19480
+ const cacheOptions = { ...query };
19481
+ const cacheKey = makeCacheKey26(buildings_namespace_collection, cacheOptions);
19482
+ try {
19483
+ const cached = await getCache(cacheKey);
19484
+ if (cached) {
19485
+ logger60.log({
19486
+ level: "info",
19487
+ message: `Cache hit for getById building: ${cacheKey}`
19488
+ });
19489
+ return cached;
19490
+ }
19491
+ const result = await collection.findOne(query);
19492
+ if (!result) {
19493
+ throw new BadRequestError79("Building not found.");
19494
+ }
19495
+ const validLevels = [];
19496
+ for (const level of result.levels ?? []) {
19497
+ const units = await _getBySiteBuildingLevel(
19498
+ result.site,
19499
+ result.block,
19500
+ level
19501
+ );
19502
+ if (units) {
19503
+ validLevels.push(level);
19504
+ }
19505
+ }
19506
+ result.levels = validLevels;
19507
+ console.log(result);
19508
+ setCache(cacheKey, result, 300).then(() => {
19509
+ logger60.log({
19510
+ level: "info",
19511
+ message: `Cache set for building by id: ${cacheKey}`
19512
+ });
19513
+ }).catch((err) => {
19514
+ logger60.log({
19515
+ level: "error",
19516
+ message: `Failed to set cache for building by id: ${err.message}`
19517
+ });
19518
+ });
19519
+ return result;
19520
+ } catch (error) {
19521
+ if (error instanceof AppError13) {
19522
+ throw error;
19523
+ } else {
19524
+ throw new InternalServerError29("Failed to get building.");
19525
+ }
19526
+ }
19527
+ }
19359
19528
  function delCachedData() {
19360
19529
  delNamespace().then(() => {
19361
19530
  logger60.log({
@@ -19376,7 +19545,8 @@ function useBuildingRepo() {
19376
19545
  getById,
19377
19546
  updateById,
19378
19547
  deleteById,
19379
- getBuildingLevel
19548
+ getBuildingLevel,
19549
+ getBuildingLevelWithUnits
19380
19550
  };
19381
19551
  }
19382
19552
 
@@ -19535,7 +19705,8 @@ function useBuildingController() {
19535
19705
  const {
19536
19706
  getAll: _getAll,
19537
19707
  getById: _getById,
19538
- getBuildingLevel: _getBuildingLevel
19708
+ getBuildingLevel: _getBuildingLevel,
19709
+ getBuildingLevelWithUnits: _getBuildingLevelWithUnits
19539
19710
  } = useBuildingRepo();
19540
19711
  const {
19541
19712
  updateById: _updateById,
@@ -19804,6 +19975,27 @@ function useBuildingController() {
19804
19975
  next(error);
19805
19976
  }
19806
19977
  }
19978
+ async function getBuildingLevelWithUnits(req, res, next) {
19979
+ const site = req.params.site ?? "";
19980
+ let block = req.query.block;
19981
+ const validation = Joi44.object({
19982
+ site: Joi44.string().hex().required(),
19983
+ block: Joi44.number().required()
19984
+ });
19985
+ const { error } = validation.validate({ site, block });
19986
+ if (error) {
19987
+ next(new BadRequestError81(error.message));
19988
+ return;
19989
+ }
19990
+ block = parseInt(block) ?? 0;
19991
+ try {
19992
+ const siteBlock = await _getBuildingLevelWithUnits(site, block);
19993
+ res.json(siteBlock);
19994
+ return;
19995
+ } catch (error2) {
19996
+ next(error2);
19997
+ }
19998
+ }
19807
19999
  return {
19808
20000
  createBuilding,
19809
20001
  getAll,
@@ -19811,7 +20003,8 @@ function useBuildingController() {
19811
20003
  updateById,
19812
20004
  deleteById,
19813
20005
  getBuildingLevel,
19814
- uploadSpreadsheetBuilding
20006
+ uploadSpreadsheetBuilding,
20007
+ getBuildingLevelWithUnits
19815
20008
  };
19816
20009
  }
19817
20010
 
@@ -23850,6 +24043,8 @@ function useVisitorTransactionService() {
23850
24043
  }
23851
24044
  if (value.unit) {
23852
24045
  value.unit = typeof value.unit === "string" ? new ObjectId59(value.unit) : value.unit;
24046
+ const unit = await _getUnitById(value.unit);
24047
+ value.unitName = unit?.name;
23853
24048
  }
23854
24049
  await _updateVisitorTansactionById(id, value, session);
23855
24050
  await session?.commitTransaction();
@@ -51850,6 +52045,7 @@ export {
51850
52045
  allowedNatures,
51851
52046
  attendanceSchema,
51852
52047
  attendanceSettingsSchema,
52048
+ building_units_namespace_collection,
51853
52049
  buildings_namespace_collection,
51854
52050
  bulletin_boards_namespace_collection,
51855
52051
  calculatePercentage,