@7365admin1/core 3.10.0 → 3.11.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
@@ -20897,7 +20897,8 @@ var schemaUpdateVisTrans = Joi37.object({
20897
20897
  ).optional().allow(null),
20898
20898
  contact: Joi37.string().optional().allow(null, "")
20899
20899
  })
20900
- ).optional().allow(null)
20900
+ ).optional().allow(null),
20901
+ updatedBy: Joi37.string().hex().length(24).optional()
20901
20902
  });
20902
20903
  function MVisitorTransaction(value) {
20903
20904
  const { error } = schemaVisitorTransaction.validate(value, {
@@ -21547,10 +21548,44 @@ function useVisitorTransactionRepo() {
21547
21548
  value.manualCheckout = true;
21548
21549
  }
21549
21550
  try {
21551
+ const updateFields = {};
21552
+ const arrayFilters = [];
21553
+ Object.keys(value).forEach((key) => {
21554
+ if (key !== "visitorPass" && key !== "passKeys") {
21555
+ const typedKey = key;
21556
+ updateFields[key] = value[typedKey];
21557
+ }
21558
+ });
21559
+ if (Array.isArray(value.visitorPass)) {
21560
+ value.visitorPass.forEach((item, index) => {
21561
+ const elementKey = `vElem${index}`;
21562
+ Object.keys(item).forEach((itemKey) => {
21563
+ if (itemKey !== "keyId") {
21564
+ const typedItemKey = itemKey;
21565
+ let itemValue = item[typedItemKey];
21566
+ updateFields[`visitorPass.$[${elementKey}].${itemKey}`] = itemValue;
21567
+ }
21568
+ });
21569
+ arrayFilters.push({ [`${elementKey}.keyId`]: new ObjectId41(item.keyId) });
21570
+ });
21571
+ }
21572
+ if (Array.isArray(value.passKeys)) {
21573
+ value.passKeys.forEach((item, index) => {
21574
+ const elementKey = `pElem${index}`;
21575
+ Object.keys(item).forEach((itemKey) => {
21576
+ if (itemKey !== "keyId") {
21577
+ const typedItemKey = itemKey;
21578
+ let itemValue = item[typedItemKey];
21579
+ updateFields[`passKeys.$[${elementKey}].${itemKey}`] = itemValue;
21580
+ }
21581
+ });
21582
+ arrayFilters.push({ [`${elementKey}.keyId`]: new ObjectId41(item.keyId) });
21583
+ });
21584
+ }
21550
21585
  const result = await collection.updateOne(
21551
- { _id },
21552
- { $set: value },
21553
- { session }
21586
+ { _id: new ObjectId41(_id) },
21587
+ { $set: updateFields },
21588
+ { arrayFilters, session }
21554
21589
  );
21555
21590
  return result;
21556
21591
  } catch (error) {
@@ -33351,10 +33386,12 @@ var KeyRepo = class {
33351
33386
  return Promise.reject("Server internal error.");
33352
33387
  }
33353
33388
  }
33354
- static async updateKeyById(keyId, key, site, session, isChild) {
33389
+ static async updateKeyById(keyId, key, site, session, isChild, visitorId) {
33355
33390
  keyId = await convertObjectIdUtil2(keyId, "keyId");
33356
33391
  if (site)
33357
33392
  site = await convertObjectIdUtil2(site, "Site");
33393
+ if (visitorId)
33394
+ visitorId = await convertObjectIdUtil2(visitorId, "visitor Id");
33358
33395
  if (key.updatedBy)
33359
33396
  key.updatedBy = await convertObjectIdUtil2(key.updatedBy, "Updated By");
33360
33397
  if (!key.status)
@@ -33371,7 +33408,6 @@ var KeyRepo = class {
33371
33408
  { session }
33372
33409
  );
33373
33410
  let setKeys = [];
33374
- console.log("updateKeyById result", result);
33375
33411
  if (result.modifiedCount > 0) {
33376
33412
  const updatedDocs = await this.collection().find(find).toArray();
33377
33413
  if (Array.isArray(updatedDocs) && updatedDocs.length > 0) {
@@ -33380,6 +33416,10 @@ var KeyRepo = class {
33380
33416
  keyItem["passOrKeyId"] = item?._id;
33381
33417
  keyItem["_id"] = new ObjectId61();
33382
33418
  keyItem["previousStatus"] = item?.status;
33419
+ if (visitorId) {
33420
+ console.log("visitorId true key.repo");
33421
+ keyItem["visitorId"] = visitorId;
33422
+ }
33383
33423
  setKeys.push(keyItem);
33384
33424
  });
33385
33425
  }
@@ -33614,7 +33654,7 @@ var NotificationService = class {
33614
33654
  status: payload.status,
33615
33655
  module: "onlineForm",
33616
33656
  screen,
33617
- params: JSON.stringify(params)
33657
+ params
33618
33658
  },
33619
33659
  false,
33620
33660
  "iservice365-resident-mobile-app"
@@ -33675,6 +33715,14 @@ var NotificationService = class {
33675
33715
  }
33676
33716
  };
33677
33717
 
33718
+ // src/utils/valid-values.ts
33719
+ var VALID_STATUSES = /* @__PURE__ */ new Set([
33720
+ "In Use",
33721
+ "Available",
33722
+ "Damaged",
33723
+ "Lost"
33724
+ ]);
33725
+
33678
33726
  // src/services/visitor-transaction.service.ts
33679
33727
  function useVisitorTransactionService() {
33680
33728
  const MailerConfig = {
@@ -33863,48 +33911,26 @@ function useVisitorTransactionService() {
33863
33911
  const chunk = value.members.slice(i, i + chunkSize);
33864
33912
  for (const member of chunk) {
33865
33913
  await KeyRepo.checkPassKeyAvailability(member.visitorPass, member.passKeys);
33866
- if (Array.isArray(member.visitorPass)) {
33867
- for (const item of member.visitorPass) {
33868
- console.log("Type of keyId:", typeof item.keyId);
33869
- console.log("item visitorPass", item);
33870
- await KeyRepo.updateKeyById(
33871
- item.keyId,
33872
- {
33873
- status: "In Use" /* IN_USE */,
33874
- updatedBy: value.createdBy
33875
- },
33876
- value.site,
33877
- session
33878
- );
33879
- item.receivedDate = /* @__PURE__ */ new Date();
33880
- item.status = "Not Returned" /* NOT_RETURNED */;
33881
- item.lastUpdate = null;
33882
- item.remarks = "";
33883
- }
33884
- }
33885
- if (Array.isArray(member.passKeys)) {
33886
- for (const item of member.passKeys) {
33887
- await KeyRepo.updateKeyById(
33888
- item.keyId,
33889
- {
33890
- status: "In Use" /* IN_USE */,
33891
- updatedBy: value.createdBy
33892
- },
33893
- value.site,
33894
- session
33895
- );
33896
- item.receivedDate = /* @__PURE__ */ new Date();
33897
- item.status = "Not Returned" /* NOT_RETURNED */;
33898
- item.lastUpdate = null;
33899
- item.remarks = "";
33900
- }
33901
- }
33902
33914
  }
33903
33915
  await Promise.all(
33904
- chunk.map((member) => {
33916
+ chunk.map(async (member) => {
33905
33917
  const clonedMember = structuredClone(member);
33906
33918
  const { visitorPass, passKeys } = clonedMember;
33907
- return _add(
33919
+ const preparedVisitorPass = Array.isArray(visitorPass) ? visitorPass.map((item) => ({
33920
+ ...item,
33921
+ receivedDate: /* @__PURE__ */ new Date(),
33922
+ status: "Not Returned" /* NOT_RETURNED */,
33923
+ lastUpdate: null,
33924
+ remarks: ""
33925
+ })) : [];
33926
+ const preparedPassKeys = Array.isArray(passKeys) ? passKeys.map((item) => ({
33927
+ ...item,
33928
+ receivedDate: /* @__PURE__ */ new Date(),
33929
+ status: "Not Returned" /* NOT_RETURNED */,
33930
+ lastUpdate: null,
33931
+ remarks: ""
33932
+ })) : [];
33933
+ const visitorId = await _add(
33908
33934
  {
33909
33935
  ...clonedMember,
33910
33936
  block,
@@ -33918,13 +33944,38 @@ function useVisitorTransactionService() {
33918
33944
  remarks,
33919
33945
  contractorType,
33920
33946
  checkIn: start,
33921
- // expiredAt: end,
33922
- visitorPass: visitorPass ?? [],
33923
- passKeys: passKeys ?? [],
33947
+ visitorPass: preparedVisitorPass,
33948
+ passKeys: preparedPassKeys,
33924
33949
  status: "registered" /* REGISTERED */
33925
33950
  },
33926
33951
  session
33927
33952
  );
33953
+ console.log("visitorId service", visitorId);
33954
+ for (const item of preparedVisitorPass) {
33955
+ await KeyRepo.updateKeyById(
33956
+ item.keyId,
33957
+ {
33958
+ status: "In Use" /* IN_USE */,
33959
+ updatedBy: value.createdBy
33960
+ },
33961
+ value.site,
33962
+ session,
33963
+ void 0,
33964
+ visitorId
33965
+ );
33966
+ }
33967
+ for (const item of preparedPassKeys) {
33968
+ await KeyRepo.updateKeyById(
33969
+ item.keyId,
33970
+ {
33971
+ status: "In Use" /* IN_USE */,
33972
+ updatedBy: value.createdBy,
33973
+ visitorId
33974
+ },
33975
+ value.site,
33976
+ session
33977
+ );
33978
+ }
33928
33979
  })
33929
33980
  );
33930
33981
  }
@@ -33953,6 +34004,7 @@ function useVisitorTransactionService() {
33953
34004
  throw new BadRequestError100("This plate number is blocklisted");
33954
34005
  }
33955
34006
  await KeyRepo.checkPassKeyAvailability(value.visitorPass, value.passKeys);
34007
+ const result = await _add(value, session);
33956
34008
  if (Array.isArray(value.visitorPass)) {
33957
34009
  for (const item of value.visitorPass) {
33958
34010
  await KeyRepo.updateKeyById(
@@ -33962,7 +34014,9 @@ function useVisitorTransactionService() {
33962
34014
  updatedBy: value.createdBy
33963
34015
  },
33964
34016
  value.site,
33965
- session
34017
+ session,
34018
+ void 0,
34019
+ result
33966
34020
  );
33967
34021
  item.receivedDate = /* @__PURE__ */ new Date();
33968
34022
  item.status = "Not Returned" /* NOT_RETURNED */;
@@ -33979,7 +34033,9 @@ function useVisitorTransactionService() {
33979
34033
  updatedBy: value.createdBy
33980
34034
  },
33981
34035
  value.site,
33982
- session
34036
+ session,
34037
+ void 0,
34038
+ result
33983
34039
  );
33984
34040
  item.receivedDate = /* @__PURE__ */ new Date();
33985
34041
  item.status = "Not Returned" /* NOT_RETURNED */;
@@ -33987,7 +34043,6 @@ function useVisitorTransactionService() {
33987
34043
  item.remarks = "";
33988
34044
  }
33989
34045
  }
33990
- const result = await _add(value, session);
33991
34046
  await session?.commitTransaction();
33992
34047
  let openBarrier = null;
33993
34048
  const isOpenBarrier = allowedPersonTypes.includes(value?.type) || camera?.ANPRSwitches?.openBarrierPickUpDropOff == true;
@@ -34061,52 +34116,6 @@ function useVisitorTransactionService() {
34061
34116
  if (found === 1)
34062
34117
  throw new BadRequestError100("This plate number is blocklisted");
34063
34118
  }
34064
- if (Array.isArray(value.visitorPass) && value.visitorPass.length > 0) {
34065
- const keptVisitorPass = [];
34066
- for (const vp of value.visitorPass) {
34067
- const updatePayload = {
34068
- ...vp.status && { status: vp.status },
34069
- ...vp.remarks && { remarks: vp.remarks }
34070
- };
34071
- const visitorPassId = typeof vp === "string" || vp instanceof ObjectId62 ? vp : vp.keyId;
34072
- await KeyRepo.updateKeyById(
34073
- visitorPassId,
34074
- updatePayload,
34075
- value.site
34076
- );
34077
- if (typeof vp !== "string" && !(vp instanceof ObjectId62)) {
34078
- keptVisitorPass.push({
34079
- keyId: new ObjectId62(visitorPassId)
34080
- });
34081
- }
34082
- }
34083
- value.visitorPass = keptVisitorPass;
34084
- }
34085
- if (value.passKeys && Array.isArray(value.passKeys) && value.passKeys.length > 0) {
34086
- const keptPassKeys = [];
34087
- for (const pk of value.passKeys) {
34088
- try {
34089
- const updatePayload = {
34090
- ...pk.status && { status: pk.status },
34091
- ...pk.remarks && { remarks: pk.remarks }
34092
- };
34093
- const passKeyId = typeof pk === "string" || pk instanceof ObjectId62 ? pk : pk.keyId;
34094
- await KeyRepo.updateKeyById(
34095
- passKeyId,
34096
- updatePayload,
34097
- value.site
34098
- );
34099
- if (typeof pk !== "string" && !(pk instanceof ObjectId62)) {
34100
- keptPassKeys.push({
34101
- keyId: new ObjectId62(passKeyId)
34102
- });
34103
- }
34104
- } catch (error) {
34105
- throw error;
34106
- }
34107
- }
34108
- value.passKeys = keptPassKeys;
34109
- }
34110
34119
  if (value.checkIn) {
34111
34120
  const parsed = new Date(value.checkIn);
34112
34121
  value.checkIn = isNaN(parsed.getTime()) ? null : parsed;
@@ -34123,6 +34132,61 @@ function useVisitorTransactionService() {
34123
34132
  const unit = await _getUnitById(value.unit);
34124
34133
  value.unitName = unit?.name;
34125
34134
  }
34135
+ if (value.updatedBy) {
34136
+ value.updatedBy = await convertObjectIdUtil2(value.updatedBy, "updatedBy Id");
34137
+ }
34138
+ if (Array.isArray(value.visitorPass)) {
34139
+ for (const item of value.visitorPass) {
34140
+ let status = "Invalid";
34141
+ if (item?.status == "Returned" /* RETURNED */) {
34142
+ status = "Available" /* AVAILABLE */;
34143
+ } else if (item?.status == "Not Returned" /* NOT_RETURNED */) {
34144
+ status = "In Use" /* IN_USE */;
34145
+ } else if (item?.status && VALID_STATUSES.has(item.status)) {
34146
+ status = item.status;
34147
+ } else {
34148
+ throw new Error("Invalid Visitor Pass Status");
34149
+ }
34150
+ await KeyRepo.updateKeyById(
34151
+ item.keyId,
34152
+ {
34153
+ status,
34154
+ updatedBy: value.updatedBy
34155
+ },
34156
+ value.site,
34157
+ session,
34158
+ void 0,
34159
+ id
34160
+ );
34161
+ item.lastUpdate = /* @__PURE__ */ new Date();
34162
+ }
34163
+ }
34164
+ if (Array.isArray(value.passKeys)) {
34165
+ for (const item of value.passKeys) {
34166
+ let status = "Invalid";
34167
+ if (item?.status == "Returned" /* RETURNED */) {
34168
+ status = "Available" /* AVAILABLE */;
34169
+ } else if (item?.status == "Not Returned" /* NOT_RETURNED */) {
34170
+ status = "In Use" /* IN_USE */;
34171
+ } else if (item?.status && VALID_STATUSES.has(item.status)) {
34172
+ status = item.status;
34173
+ } else {
34174
+ throw new Error("Invalid Visitor Pass Status");
34175
+ }
34176
+ await KeyRepo.updateKeyById(
34177
+ item.keyId,
34178
+ {
34179
+ status,
34180
+ updatedBy: value.updatedBy
34181
+ },
34182
+ value.site,
34183
+ session,
34184
+ void 0,
34185
+ id
34186
+ );
34187
+ item.lastUpdate = /* @__PURE__ */ new Date();
34188
+ }
34189
+ }
34126
34190
  await _updateVisitorTansactionById(id, value, session);
34127
34191
  const allowedPersonTypes = [
34128
34192
  "contractor" /* CONTRACTOR */,
@@ -60782,7 +60846,6 @@ function useHrmLabsAttendanceSrvc() {
60782
60846
  };
60783
60847
  } catch (error) {
60784
60848
  logger171.error(error.message || error);
60785
- console.log("Error fetching attendance data:", error);
60786
60849
  return { success: false, message: error?.message || "Internal Server Error!", items: [], pages: 0, pageRange: "0-0 of 0", count: {} };
60787
60850
  }
60788
60851
  }
@@ -60896,7 +60959,6 @@ function useHrmLabsAttendanceSrvc() {
60896
60959
  return { totalCount };
60897
60960
  } catch (error) {
60898
60961
  logger171.error(error.message || error);
60899
- console.log("Error fetching attendance data count:", error);
60900
60962
  return { success: false, message: error?.message || "Internal Server Error!", totalCount: null };
60901
60963
  }
60902
60964
  }
@@ -61068,7 +61130,6 @@ function useHrmLabsAttendanceSrvc() {
61068
61130
  };
61069
61131
  } catch (error) {
61070
61132
  logger171.error(error.message || error);
61071
- console.log("Error fetching attendance data:", error);
61072
61133
  return { success: false, message: error?.message || "Internal Server Error!", items: [], count: {}, countPerJobTitle: {}, totalCount: null, countPerStatus: {} };
61073
61134
  }
61074
61135
  }
@@ -61175,7 +61236,6 @@ function useHrmLabsAttendanceSrvc() {
61175
61236
  };
61176
61237
  } catch (error) {
61177
61238
  logger171.error(error.message || error);
61178
- console.log("Error fetching attendance data:", error);
61179
61239
  return { success: false, message: error?.message || "Internal Server Error!", chartCount: null };
61180
61240
  }
61181
61241
  }
@@ -67050,13 +67110,14 @@ var BidStatus = /* @__PURE__ */ ((BidStatus3) => {
67050
67110
  var schemaBidPreloved = Joi145.object({
67051
67111
  type: Joi145.string().valid(...Object.values(BidType)).required(),
67052
67112
  postId: Joi145.string().hex().length(24).required(),
67113
+ receiverId: Joi145.string().hex().length(24).required(),
67114
+ buyerId: Joi145.string().hex().length(24).required(),
67053
67115
  price: Joi145.when("type", {
67054
67116
  is: "bid" /* BID */,
67055
67117
  then: Joi145.number().required(),
67056
67118
  otherwise: Joi145.number().optional().allow(null)
67057
67119
  }),
67058
67120
  message: Joi145.string().optional().allow("", null),
67059
- buyerId: Joi145.string().hex().length(24).optional().allow("", null),
67060
67121
  status: Joi145.string().valid(...Object.values(BidStatus)).optional().default("pending" /* PENDING */)
67061
67122
  });
67062
67123
  var schemaUpdateBidPreloved = Joi145.object({
@@ -67131,12 +67192,74 @@ function useBidPrelovedRepo() {
67131
67192
  // src/controllers/bid-preloved.controller.ts
67132
67193
  import { BadRequestError as BadRequestError224, logger as logger194 } from "@7365admin1/node-server-utils";
67133
67194
  import Joi146 from "joi";
67195
+
67196
+ // src/services/bid-preloved.service.ts
67197
+ import { InternalServerError as InternalServerError83, useAtlas as useAtlas128 } from "@7365admin1/node-server-utils";
67198
+ function useBidPrelovedService() {
67199
+ const { add: _addBid } = useBidPrelovedRepo();
67200
+ const { add: _addChannel, getByParticipants: _getByParticipants } = useChannelPrelovedRepo();
67201
+ const { add: _addChat } = useChatPrelovedRepo();
67202
+ async function createBid(value) {
67203
+ const client = useAtlas128.getClient();
67204
+ if (!client)
67205
+ throw new InternalServerError83("Unable to connect to server.");
67206
+ const buyerId = value.buyerId;
67207
+ const receiverId = value.receiverId;
67208
+ const postId = value.postId;
67209
+ const messageText = value.message || "";
67210
+ const session = client.startSession();
67211
+ session.startTransaction();
67212
+ try {
67213
+ const bidId = await _addBid(value, session);
67214
+ const existingChannel = await _getByParticipants(
67215
+ buyerId,
67216
+ receiverId,
67217
+ postId
67218
+ );
67219
+ let channelId;
67220
+ if (existingChannel) {
67221
+ channelId = existingChannel._id.toString();
67222
+ } else {
67223
+ const newChannelId = await _addChannel(
67224
+ {
67225
+ senderId: buyerId,
67226
+ receiverId,
67227
+ postId
67228
+ },
67229
+ session
67230
+ );
67231
+ channelId = newChannelId.toString();
67232
+ }
67233
+ await _addChat(
67234
+ {
67235
+ channelId,
67236
+ senderId: buyerId,
67237
+ postId,
67238
+ bidId: bidId.toString(),
67239
+ message: {
67240
+ text: messageText,
67241
+ date: (/* @__PURE__ */ new Date()).toISOString(),
67242
+ senderId: buyerId
67243
+ }
67244
+ },
67245
+ session
67246
+ );
67247
+ await session.commitTransaction();
67248
+ return { bidId };
67249
+ } catch (error) {
67250
+ await session.abortTransaction();
67251
+ throw error;
67252
+ } finally {
67253
+ session.endSession();
67254
+ }
67255
+ }
67256
+ return { createBid };
67257
+ }
67258
+
67259
+ // src/controllers/bid-preloved.controller.ts
67134
67260
  function useBidPrelovedController() {
67135
- const {
67136
- add: _add,
67137
- getById: _getById,
67138
- updateStatus: _updateStatus
67139
- } = useBidPrelovedRepo();
67261
+ const { createBid: _createBid } = useBidPrelovedService();
67262
+ const { getById: _getById, updateStatus: _updateStatus } = useBidPrelovedRepo();
67140
67263
  async function add(req, res, next) {
67141
67264
  const { error, value } = schemaBidPreloved.validate(req.body, {
67142
67265
  abortEarly: false
@@ -67148,9 +67271,10 @@ function useBidPrelovedController() {
67148
67271
  return;
67149
67272
  }
67150
67273
  try {
67151
- const data = await _add(value);
67274
+ const data = await _createBid(value);
67152
67275
  res.status(201).json(data);
67153
67276
  } catch (error2) {
67277
+ console.log("error", error2);
67154
67278
  logger194.log({ level: "error", message: error2.message });
67155
67279
  next(error2);
67156
67280
  }
@@ -67335,20 +67459,20 @@ var residentFormEntry = Joi147.object({
67335
67459
  // src/repositories/online-forms-v2.repository.ts
67336
67460
  import {
67337
67461
  BadRequestError as BadRequestError225,
67338
- InternalServerError as InternalServerError83,
67462
+ InternalServerError as InternalServerError84,
67339
67463
  logger as logger195,
67340
67464
  makeCacheKey as makeCacheKey65,
67341
67465
  NotFoundError as NotFoundError62,
67342
67466
  paginate as paginate64,
67343
- useAtlas as useAtlas128,
67467
+ useAtlas as useAtlas129,
67344
67468
  useCache as useCache69
67345
67469
  } from "@7365admin1/node-server-utils";
67346
67470
  import { ObjectId as ObjectId152 } from "mongodb";
67347
67471
  var online_forms_namespace_collection = "online-forms";
67348
67472
  function useFormEntryRepo() {
67349
- const db = useAtlas128.getDb();
67473
+ const db = useAtlas129.getDb();
67350
67474
  if (!db) {
67351
- throw new InternalServerError83("Unable to connect to server.");
67475
+ throw new InternalServerError84("Unable to connect to server.");
67352
67476
  }
67353
67477
  const collection = db.collection(online_forms_namespace_collection);
67354
67478
  const { delNamespace, getCache, setCache } = useCache69(
@@ -67361,7 +67485,7 @@ function useFormEntryRepo() {
67361
67485
  name: "text"
67362
67486
  });
67363
67487
  } catch (error) {
67364
- throw new InternalServerError83(
67488
+ throw new InternalServerError84(
67365
67489
  "Failed to create text index on online form."
67366
67490
  );
67367
67491
  }
@@ -67370,16 +67494,6 @@ function useFormEntryRepo() {
67370
67494
  try {
67371
67495
  value = MFormEntry(value);
67372
67496
  const res = await collection.insertOne(value, { session });
67373
- delNamespace().then(() => {
67374
- logger195.info(
67375
- `Cache cleared for namespace: ${online_forms_namespace_collection}`
67376
- );
67377
- }).catch((err) => {
67378
- logger195.error(
67379
- `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
67380
- err
67381
- );
67382
- });
67383
67497
  return res.insertedId;
67384
67498
  } catch (error) {
67385
67499
  const isDuplicated = error.message.includes("duplicate");
@@ -67402,18 +67516,10 @@ function useFormEntryRepo() {
67402
67516
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
67403
67517
  site = new ObjectId152(site);
67404
67518
  org = new ObjectId152(org);
67405
- const cacheOptions = {
67406
- page,
67407
- limit,
67408
- status,
67409
- sort: JSON.stringify(sort),
67410
- site,
67411
- ...search && { search }
67412
- };
67413
67519
  const query = {
67414
67520
  site,
67415
- status,
67416
- org
67521
+ status
67522
+ // org,
67417
67523
  };
67418
67524
  if (search && search !== "") {
67419
67525
  query.$or = [
@@ -67421,15 +67527,6 @@ function useFormEntryRepo() {
67421
67527
  { unitNumber: { $regex: search, $options: "i" } }
67422
67528
  ];
67423
67529
  }
67424
- const cacheKey = makeCacheKey65(
67425
- online_forms_namespace_collection,
67426
- cacheOptions
67427
- );
67428
- const cachedData = await getCache(cacheKey);
67429
- if (cachedData) {
67430
- logger195.info(`Cache hit for key: ${cacheKey}`);
67431
- return cachedData;
67432
- }
67433
67530
  try {
67434
67531
  const items = await collection.aggregate([
67435
67532
  { $match: query },
@@ -67455,23 +67552,12 @@ function useFormEntryRepo() {
67455
67552
  ]).toArray();
67456
67553
  const length = await collection.countDocuments(query);
67457
67554
  const data = paginate64(items, page, limit, length);
67458
- setCache(cacheKey, data, 15 * 60).then(() => {
67459
- logger195.info(`Cache set for key: ${cacheKey}`);
67460
- }).catch((err) => {
67461
- logger195.error(`Failed to set cache for key: ${cacheKey}`, err);
67462
- });
67463
67555
  return data;
67464
67556
  } catch (error) {
67465
67557
  throw error;
67466
67558
  }
67467
67559
  }
67468
67560
  async function getFormEntryById(_id) {
67469
- const cacheKey = makeCacheKey65(online_forms_namespace_collection, { _id });
67470
- const cachedData = await getCache(cacheKey);
67471
- if (cachedData) {
67472
- logger195.info(`Cache hit for key: ${cacheKey}`);
67473
- return cachedData;
67474
- }
67475
67561
  try {
67476
67562
  _id = new ObjectId152(_id);
67477
67563
  } catch (error) {
@@ -67483,11 +67569,6 @@ function useFormEntryRepo() {
67483
67569
  if (!data) {
67484
67570
  throw new NotFoundError62("Document not found.");
67485
67571
  }
67486
- setCache(cacheKey, data, 15 * 60).then(() => {
67487
- logger195.info(`Cache set for key: ${cacheKey}`);
67488
- }).catch((err) => {
67489
- logger195.error(`Failed to set cache for key: ${cacheKey}`, err);
67490
- });
67491
67572
  return data;
67492
67573
  } catch (error) {
67493
67574
  throw error;
@@ -67506,7 +67587,7 @@ function useFormEntryRepo() {
67506
67587
  };
67507
67588
  const res = await collection.updateOne({ _id }, { $set: updateValue });
67508
67589
  if (res.modifiedCount === 0) {
67509
- throw new InternalServerError83("Unable to update online form.");
67590
+ throw new InternalServerError84("Unable to update online form.");
67510
67591
  }
67511
67592
  const onlineFormRequest = await collection.findOne({ _id });
67512
67593
  if (!onlineFormRequest) {
@@ -67520,23 +67601,7 @@ function useFormEntryRepo() {
67520
67601
  await NotificationService.onlineFormRequestStatusUpdated({
67521
67602
  to: userId,
67522
67603
  onlineFormId: onlineFormRequest._id,
67523
- // typeOfForm: onlineFormRequest.typeOfForm,
67524
- // unitNumber: onlineFormRequest.unitNumber,
67525
67604
  status: onlineFormRequest.status
67526
- // createdAt: onlineFormRequest.createdAt ?? "",
67527
- // fields: onlineFormRequest.fields ?? {},
67528
- // remarks: onlineFormRequest.remarks ?? "",
67529
- // managementValuesJson: onlineFormRequest.managementValues ?? {},
67530
- });
67531
- delNamespace().then(() => {
67532
- logger195.info(
67533
- `Cache cleared for namespace: ${online_forms_namespace_collection}`
67534
- );
67535
- }).catch((err) => {
67536
- logger195.error(
67537
- `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
67538
- err
67539
- );
67540
67605
  });
67541
67606
  return res.modifiedCount;
67542
67607
  } catch (error) {
@@ -67561,18 +67626,8 @@ function useFormEntryRepo() {
67561
67626
  { session }
67562
67627
  );
67563
67628
  if (res.modifiedCount === 0) {
67564
- throw new InternalServerError83("Unable to delete online form.");
67629
+ throw new InternalServerError84("Unable to delete online form.");
67565
67630
  }
67566
- delNamespace().then(() => {
67567
- logger195.info(
67568
- `Cache cleared for namespace: ${online_forms_namespace_collection}`
67569
- );
67570
- }).catch((err) => {
67571
- logger195.error(
67572
- `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
67573
- err
67574
- );
67575
- });
67576
67631
  return res.modifiedCount;
67577
67632
  } catch (error) {
67578
67633
  throw new Error(error.message);
@@ -67584,16 +67639,6 @@ function useFormEntryRepo() {
67584
67639
  value.org = new ObjectId152(value.org);
67585
67640
  value.userId = new ObjectId152(value.userId);
67586
67641
  const res = await collection.insertOne(value, { session });
67587
- delNamespace().then(() => {
67588
- logger195.info(
67589
- `Cache cleared for namespace: ${online_forms_namespace_collection}`
67590
- );
67591
- }).catch((err) => {
67592
- logger195.error(
67593
- `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
67594
- err
67595
- );
67596
- });
67597
67642
  return res.insertedId;
67598
67643
  } catch (error) {
67599
67644
  const isDuplicated = error.message.includes("duplicate");
@@ -67606,22 +67651,61 @@ function useFormEntryRepo() {
67606
67651
  async function residentForm({
67607
67652
  userId,
67608
67653
  site,
67609
- org
67654
+ org,
67655
+ search = "",
67656
+ page = 1,
67657
+ limit = 10,
67658
+ sort = {}
67610
67659
  }) {
67660
+ page = page > 0 ? page - 1 : 0;
67661
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
67662
+ const user = new ObjectId152(userId);
67663
+ const siteId = new ObjectId152(site);
67664
+ const orgId = new ObjectId152(org);
67665
+ const cacheOptions = {
67666
+ page,
67667
+ limit,
67668
+ sort: JSON.stringify(sort),
67669
+ userId: user,
67670
+ site: siteId,
67671
+ org: orgId,
67672
+ ...search && { search }
67673
+ };
67674
+ const query = {
67675
+ userId: user,
67676
+ site: siteId,
67677
+ org: orgId
67678
+ };
67679
+ if (search && search !== "") {
67680
+ query.$or = [
67681
+ { typeOfForm: { $regex: search, $options: "i" } },
67682
+ { unitNumber: { $regex: search, $options: "i" } }
67683
+ ];
67684
+ }
67685
+ const cacheKey = makeCacheKey65(
67686
+ online_forms_namespace_collection,
67687
+ cacheOptions
67688
+ );
67689
+ const cachedData = await getCache(cacheKey);
67690
+ if (cachedData) {
67691
+ logger195.info(`Cache hit for key: ${cacheKey}`);
67692
+ return cachedData;
67693
+ }
67611
67694
  try {
67612
- const user = new ObjectId152(userId);
67613
- const siteId = new ObjectId152(site);
67614
- const orgId = new ObjectId152(org);
67615
- const res = await collection.aggregate([
67616
- {
67617
- $match: {
67618
- userId: user,
67619
- site: siteId,
67620
- org: orgId
67621
- }
67622
- }
67695
+ const items = await collection.aggregate([
67696
+ { $match: query },
67697
+ { $sort: sort },
67698
+ { $skip: page * limit },
67699
+ { $limit: limit }
67623
67700
  ]).toArray();
67624
- return res;
67701
+ const length = await collection.countDocuments(query);
67702
+ const data = paginate64(items, page, limit, length);
67703
+ setCache(cacheKey, data, 15 * 60).then(() => {
67704
+ logger195.info(`Cache set for key: ${cacheKey}`);
67705
+ }).catch((err) => {
67706
+ logger195.error(`Failed to set cache for key: ${cacheKey}`, err);
67707
+ });
67708
+ return data;
67625
67709
  } catch (error) {
67626
67710
  throw error;
67627
67711
  }
@@ -67853,20 +67937,25 @@ function useFormEntryController() {
67853
67937
  }
67854
67938
  async function residentForm(req, res, next) {
67855
67939
  try {
67856
- const { site, userId, org } = req.query;
67857
67940
  const residentFormPayload = Joi148.object({
67858
67941
  org: Joi148.string().hex().required(),
67859
67942
  site: Joi148.string().hex().required(),
67860
- userId: Joi148.string().hex().required()
67943
+ userId: Joi148.string().hex().required(),
67944
+ search: Joi148.string().optional().allow("", null),
67945
+ page: Joi148.number().integer().min(1).allow("", null).default(1),
67946
+ limit: Joi148.number().integer().min(1).max(100).allow("", null).default(10)
67947
+ });
67948
+ const { error, value } = residentFormPayload.validate(req.query, {
67949
+ abortEarly: true
67861
67950
  });
67862
- const { error } = residentFormPayload.validate({ site, userId, org }, { abortEarly: true });
67863
67951
  if (error) {
67864
67952
  const messages = error.details.map((d) => d.message).join(", ");
67865
67953
  logger196.log({ level: "error", message: messages });
67866
67954
  next(new BadRequestError226(messages));
67867
67955
  return;
67868
67956
  }
67869
- const result = await _residentForm({ userId, site, org });
67957
+ const { site, userId, org, search, page, limit } = value;
67958
+ const result = await _residentForm({ userId, site, org, search, page, limit });
67870
67959
  res.json(result);
67871
67960
  } catch (error) {
67872
67961
  logger196.log({ level: "error", message: error.message });
@@ -67887,11 +67976,11 @@ function useFormEntryController() {
67887
67976
  }
67888
67977
 
67889
67978
  // src/services/building-level.service.ts
67890
- import { useAtlas as useAtlas129 } from "@7365admin1/node-server-utils";
67979
+ import { useAtlas as useAtlas130 } from "@7365admin1/node-server-utils";
67891
67980
  function useBuildingLevelService() {
67892
67981
  const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
67893
67982
  async function add(value) {
67894
- const session = useAtlas129.getClient()?.startSession();
67983
+ const session = useAtlas130.getClient()?.startSession();
67895
67984
  try {
67896
67985
  session?.startTransaction();
67897
67986
  await _add(value, session);
@@ -67905,7 +67994,7 @@ function useBuildingLevelService() {
67905
67994
  }
67906
67995
  }
67907
67996
  async function updateLevelById(_id, value) {
67908
- const session = useAtlas129.getClient()?.startSession();
67997
+ const session = useAtlas130.getClient()?.startSession();
67909
67998
  try {
67910
67999
  session?.startTransaction();
67911
68000
  await _updateLevelById(_id, value, session);
@@ -68391,17 +68480,17 @@ function MHidAmicoIdentity(value) {
68391
68480
  // src/repositories/hid-amico.repo.ts
68392
68481
  import {
68393
68482
  BadRequestError as BadRequestError229,
68394
- InternalServerError as InternalServerError84,
68483
+ InternalServerError as InternalServerError85,
68395
68484
  logger as logger199,
68396
68485
  paginate as paginate65,
68397
- useAtlas as useAtlas130
68486
+ useAtlas as useAtlas131
68398
68487
  } from "@7365admin1/node-server-utils";
68399
68488
  import { ObjectId as ObjectId154 } from "mongodb";
68400
68489
  function useHidAmicoRepo() {
68401
68490
  function db() {
68402
- const instance = useAtlas130.getDb();
68491
+ const instance = useAtlas131.getDb();
68403
68492
  if (!instance) {
68404
- throw new InternalServerError84("Unable to connect to server.");
68493
+ throw new InternalServerError85("Unable to connect to server.");
68405
68494
  }
68406
68495
  return instance;
68407
68496
  }