@7365admin1/core 3.9.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.js CHANGED
@@ -21156,7 +21156,8 @@ var schemaUpdateVisTrans = import_joi37.default.object({
21156
21156
  ).optional().allow(null),
21157
21157
  contact: import_joi37.default.string().optional().allow(null, "")
21158
21158
  })
21159
- ).optional().allow(null)
21159
+ ).optional().allow(null),
21160
+ updatedBy: import_joi37.default.string().hex().length(24).optional()
21160
21161
  });
21161
21162
  function MVisitorTransaction(value) {
21162
21163
  const { error } = schemaVisitorTransaction.validate(value, {
@@ -21806,10 +21807,44 @@ function useVisitorTransactionRepo() {
21806
21807
  value.manualCheckout = true;
21807
21808
  }
21808
21809
  try {
21810
+ const updateFields = {};
21811
+ const arrayFilters = [];
21812
+ Object.keys(value).forEach((key) => {
21813
+ if (key !== "visitorPass" && key !== "passKeys") {
21814
+ const typedKey = key;
21815
+ updateFields[key] = value[typedKey];
21816
+ }
21817
+ });
21818
+ if (Array.isArray(value.visitorPass)) {
21819
+ value.visitorPass.forEach((item, index) => {
21820
+ const elementKey = `vElem${index}`;
21821
+ Object.keys(item).forEach((itemKey) => {
21822
+ if (itemKey !== "keyId") {
21823
+ const typedItemKey = itemKey;
21824
+ let itemValue = item[typedItemKey];
21825
+ updateFields[`visitorPass.$[${elementKey}].${itemKey}`] = itemValue;
21826
+ }
21827
+ });
21828
+ arrayFilters.push({ [`${elementKey}.keyId`]: new import_mongodb41.ObjectId(item.keyId) });
21829
+ });
21830
+ }
21831
+ if (Array.isArray(value.passKeys)) {
21832
+ value.passKeys.forEach((item, index) => {
21833
+ const elementKey = `pElem${index}`;
21834
+ Object.keys(item).forEach((itemKey) => {
21835
+ if (itemKey !== "keyId") {
21836
+ const typedItemKey = itemKey;
21837
+ let itemValue = item[typedItemKey];
21838
+ updateFields[`passKeys.$[${elementKey}].${itemKey}`] = itemValue;
21839
+ }
21840
+ });
21841
+ arrayFilters.push({ [`${elementKey}.keyId`]: new import_mongodb41.ObjectId(item.keyId) });
21842
+ });
21843
+ }
21809
21844
  const result = await collection.updateOne(
21810
- { _id },
21811
- { $set: value },
21812
- { session }
21845
+ { _id: new import_mongodb41.ObjectId(_id) },
21846
+ { $set: updateFields },
21847
+ { arrayFilters, session }
21813
21848
  );
21814
21849
  return result;
21815
21850
  } catch (error) {
@@ -33502,10 +33537,12 @@ var KeyRepo = class {
33502
33537
  return Promise.reject("Server internal error.");
33503
33538
  }
33504
33539
  }
33505
- static async updateKeyById(keyId, key, site, session, isChild) {
33540
+ static async updateKeyById(keyId, key, site, session, isChild, visitorId) {
33506
33541
  keyId = await convertObjectIdUtil2(keyId, "keyId");
33507
33542
  if (site)
33508
33543
  site = await convertObjectIdUtil2(site, "Site");
33544
+ if (visitorId)
33545
+ visitorId = await convertObjectIdUtil2(visitorId, "visitor Id");
33509
33546
  if (key.updatedBy)
33510
33547
  key.updatedBy = await convertObjectIdUtil2(key.updatedBy, "Updated By");
33511
33548
  if (!key.status)
@@ -33522,7 +33559,6 @@ var KeyRepo = class {
33522
33559
  { session }
33523
33560
  );
33524
33561
  let setKeys = [];
33525
- console.log("updateKeyById result", result);
33526
33562
  if (result.modifiedCount > 0) {
33527
33563
  const updatedDocs = await this.collection().find(find).toArray();
33528
33564
  if (Array.isArray(updatedDocs) && updatedDocs.length > 0) {
@@ -33531,6 +33567,10 @@ var KeyRepo = class {
33531
33567
  keyItem["passOrKeyId"] = item?._id;
33532
33568
  keyItem["_id"] = new import_mongodb61.ObjectId();
33533
33569
  keyItem["previousStatus"] = item?.status;
33570
+ if (visitorId) {
33571
+ console.log("visitorId true key.repo");
33572
+ keyItem["visitorId"] = visitorId;
33573
+ }
33534
33574
  setKeys.push(keyItem);
33535
33575
  });
33536
33576
  }
@@ -33692,7 +33732,7 @@ async function send(userIds, title, body, data, isForMAMobileApp = false, appSlu
33692
33732
  if (isForMAMobileApp) {
33693
33733
  tokens = await PushTokenRepo.findTokensByUserIds(userIds, appSlug);
33694
33734
  } else {
33695
- tokens = await PushTokenRepo.findTokensByUserIds(userIds);
33735
+ tokens = await PushTokenRepo.findTokensByUserIds(userIds, appSlug);
33696
33736
  }
33697
33737
  if (!tokens.length)
33698
33738
  return;
@@ -33740,6 +33780,37 @@ var NotificationService = class {
33740
33780
  "iservice365-resident-mobile-app"
33741
33781
  );
33742
33782
  }
33783
+ static async onlineFormRequestStatusUpdated(payload) {
33784
+ let screen = "";
33785
+ let params = {};
33786
+ if (payload.status === "pending" || payload.status === "resubmission") {
33787
+ screen = "/(user)/(online-forms)/form-fill";
33788
+ params = {
33789
+ id: payload.onlineFormId.toString(),
33790
+ submissionStatus: payload.status ?? ""
33791
+ };
33792
+ } else {
33793
+ screen = "/(user)/(online-forms)/submission-detail";
33794
+ params = {
33795
+ id: payload.onlineFormId.toString(),
33796
+ status: payload.status ?? ""
33797
+ };
33798
+ }
33799
+ await send(
33800
+ toStringArray(payload.to),
33801
+ "Online Form",
33802
+ `Your online form has been updated to ${payload.status}.`,
33803
+ {
33804
+ onlineFormId: payload.onlineFormId.toString(),
33805
+ status: payload.status,
33806
+ module: "onlineForm",
33807
+ screen,
33808
+ params
33809
+ },
33810
+ false,
33811
+ "iservice365-resident-mobile-app"
33812
+ );
33813
+ }
33743
33814
  static async bulletinBoardCreatedForMA(payload) {
33744
33815
  await send(
33745
33816
  toStringArray(payload.to),
@@ -33795,6 +33866,14 @@ var NotificationService = class {
33795
33866
  }
33796
33867
  };
33797
33868
 
33869
+ // src/utils/valid-values.ts
33870
+ var VALID_STATUSES = /* @__PURE__ */ new Set([
33871
+ "In Use",
33872
+ "Available",
33873
+ "Damaged",
33874
+ "Lost"
33875
+ ]);
33876
+
33798
33877
  // src/services/visitor-transaction.service.ts
33799
33878
  function useVisitorTransactionService() {
33800
33879
  const MailerConfig = {
@@ -33983,48 +34062,26 @@ function useVisitorTransactionService() {
33983
34062
  const chunk = value.members.slice(i, i + chunkSize);
33984
34063
  for (const member of chunk) {
33985
34064
  await KeyRepo.checkPassKeyAvailability(member.visitorPass, member.passKeys);
33986
- if (Array.isArray(member.visitorPass)) {
33987
- for (const item of member.visitorPass) {
33988
- console.log("Type of keyId:", typeof item.keyId);
33989
- console.log("item visitorPass", item);
33990
- await KeyRepo.updateKeyById(
33991
- item.keyId,
33992
- {
33993
- status: "In Use" /* IN_USE */,
33994
- updatedBy: value.createdBy
33995
- },
33996
- value.site,
33997
- session
33998
- );
33999
- item.receivedDate = /* @__PURE__ */ new Date();
34000
- item.status = "Not Returned" /* NOT_RETURNED */;
34001
- item.lastUpdate = null;
34002
- item.remarks = "";
34003
- }
34004
- }
34005
- if (Array.isArray(member.passKeys)) {
34006
- for (const item of member.passKeys) {
34007
- await KeyRepo.updateKeyById(
34008
- item.keyId,
34009
- {
34010
- status: "In Use" /* IN_USE */,
34011
- updatedBy: value.createdBy
34012
- },
34013
- value.site,
34014
- session
34015
- );
34016
- item.receivedDate = /* @__PURE__ */ new Date();
34017
- item.status = "Not Returned" /* NOT_RETURNED */;
34018
- item.lastUpdate = null;
34019
- item.remarks = "";
34020
- }
34021
- }
34022
34065
  }
34023
34066
  await Promise.all(
34024
- chunk.map((member) => {
34067
+ chunk.map(async (member) => {
34025
34068
  const clonedMember = structuredClone(member);
34026
34069
  const { visitorPass, passKeys } = clonedMember;
34027
- return _add(
34070
+ const preparedVisitorPass = Array.isArray(visitorPass) ? visitorPass.map((item) => ({
34071
+ ...item,
34072
+ receivedDate: /* @__PURE__ */ new Date(),
34073
+ status: "Not Returned" /* NOT_RETURNED */,
34074
+ lastUpdate: null,
34075
+ remarks: ""
34076
+ })) : [];
34077
+ const preparedPassKeys = Array.isArray(passKeys) ? passKeys.map((item) => ({
34078
+ ...item,
34079
+ receivedDate: /* @__PURE__ */ new Date(),
34080
+ status: "Not Returned" /* NOT_RETURNED */,
34081
+ lastUpdate: null,
34082
+ remarks: ""
34083
+ })) : [];
34084
+ const visitorId = await _add(
34028
34085
  {
34029
34086
  ...clonedMember,
34030
34087
  block,
@@ -34038,13 +34095,38 @@ function useVisitorTransactionService() {
34038
34095
  remarks,
34039
34096
  contractorType,
34040
34097
  checkIn: start,
34041
- // expiredAt: end,
34042
- visitorPass: visitorPass ?? [],
34043
- passKeys: passKeys ?? [],
34098
+ visitorPass: preparedVisitorPass,
34099
+ passKeys: preparedPassKeys,
34044
34100
  status: "registered" /* REGISTERED */
34045
34101
  },
34046
34102
  session
34047
34103
  );
34104
+ console.log("visitorId service", visitorId);
34105
+ for (const item of preparedVisitorPass) {
34106
+ await KeyRepo.updateKeyById(
34107
+ item.keyId,
34108
+ {
34109
+ status: "In Use" /* IN_USE */,
34110
+ updatedBy: value.createdBy
34111
+ },
34112
+ value.site,
34113
+ session,
34114
+ void 0,
34115
+ visitorId
34116
+ );
34117
+ }
34118
+ for (const item of preparedPassKeys) {
34119
+ await KeyRepo.updateKeyById(
34120
+ item.keyId,
34121
+ {
34122
+ status: "In Use" /* IN_USE */,
34123
+ updatedBy: value.createdBy,
34124
+ visitorId
34125
+ },
34126
+ value.site,
34127
+ session
34128
+ );
34129
+ }
34048
34130
  })
34049
34131
  );
34050
34132
  }
@@ -34073,6 +34155,7 @@ function useVisitorTransactionService() {
34073
34155
  throw new import_node_server_utils106.BadRequestError("This plate number is blocklisted");
34074
34156
  }
34075
34157
  await KeyRepo.checkPassKeyAvailability(value.visitorPass, value.passKeys);
34158
+ const result = await _add(value, session);
34076
34159
  if (Array.isArray(value.visitorPass)) {
34077
34160
  for (const item of value.visitorPass) {
34078
34161
  await KeyRepo.updateKeyById(
@@ -34082,7 +34165,9 @@ function useVisitorTransactionService() {
34082
34165
  updatedBy: value.createdBy
34083
34166
  },
34084
34167
  value.site,
34085
- session
34168
+ session,
34169
+ void 0,
34170
+ result
34086
34171
  );
34087
34172
  item.receivedDate = /* @__PURE__ */ new Date();
34088
34173
  item.status = "Not Returned" /* NOT_RETURNED */;
@@ -34099,7 +34184,9 @@ function useVisitorTransactionService() {
34099
34184
  updatedBy: value.createdBy
34100
34185
  },
34101
34186
  value.site,
34102
- session
34187
+ session,
34188
+ void 0,
34189
+ result
34103
34190
  );
34104
34191
  item.receivedDate = /* @__PURE__ */ new Date();
34105
34192
  item.status = "Not Returned" /* NOT_RETURNED */;
@@ -34107,7 +34194,6 @@ function useVisitorTransactionService() {
34107
34194
  item.remarks = "";
34108
34195
  }
34109
34196
  }
34110
- const result = await _add(value, session);
34111
34197
  await session?.commitTransaction();
34112
34198
  let openBarrier = null;
34113
34199
  const isOpenBarrier = allowedPersonTypes.includes(value?.type) || camera?.ANPRSwitches?.openBarrierPickUpDropOff == true;
@@ -34181,52 +34267,6 @@ function useVisitorTransactionService() {
34181
34267
  if (found === 1)
34182
34268
  throw new import_node_server_utils106.BadRequestError("This plate number is blocklisted");
34183
34269
  }
34184
- if (Array.isArray(value.visitorPass) && value.visitorPass.length > 0) {
34185
- const keptVisitorPass = [];
34186
- for (const vp of value.visitorPass) {
34187
- const updatePayload = {
34188
- ...vp.status && { status: vp.status },
34189
- ...vp.remarks && { remarks: vp.remarks }
34190
- };
34191
- const visitorPassId = typeof vp === "string" || vp instanceof import_mongodb62.ObjectId ? vp : vp.keyId;
34192
- await KeyRepo.updateKeyById(
34193
- visitorPassId,
34194
- updatePayload,
34195
- value.site
34196
- );
34197
- if (typeof vp !== "string" && !(vp instanceof import_mongodb62.ObjectId)) {
34198
- keptVisitorPass.push({
34199
- keyId: new import_mongodb62.ObjectId(visitorPassId)
34200
- });
34201
- }
34202
- }
34203
- value.visitorPass = keptVisitorPass;
34204
- }
34205
- if (value.passKeys && Array.isArray(value.passKeys) && value.passKeys.length > 0) {
34206
- const keptPassKeys = [];
34207
- for (const pk of value.passKeys) {
34208
- try {
34209
- const updatePayload = {
34210
- ...pk.status && { status: pk.status },
34211
- ...pk.remarks && { remarks: pk.remarks }
34212
- };
34213
- const passKeyId = typeof pk === "string" || pk instanceof import_mongodb62.ObjectId ? pk : pk.keyId;
34214
- await KeyRepo.updateKeyById(
34215
- passKeyId,
34216
- updatePayload,
34217
- value.site
34218
- );
34219
- if (typeof pk !== "string" && !(pk instanceof import_mongodb62.ObjectId)) {
34220
- keptPassKeys.push({
34221
- keyId: new import_mongodb62.ObjectId(passKeyId)
34222
- });
34223
- }
34224
- } catch (error) {
34225
- throw error;
34226
- }
34227
- }
34228
- value.passKeys = keptPassKeys;
34229
- }
34230
34270
  if (value.checkIn) {
34231
34271
  const parsed = new Date(value.checkIn);
34232
34272
  value.checkIn = isNaN(parsed.getTime()) ? null : parsed;
@@ -34243,6 +34283,61 @@ function useVisitorTransactionService() {
34243
34283
  const unit = await _getUnitById(value.unit);
34244
34284
  value.unitName = unit?.name;
34245
34285
  }
34286
+ if (value.updatedBy) {
34287
+ value.updatedBy = await convertObjectIdUtil2(value.updatedBy, "updatedBy Id");
34288
+ }
34289
+ if (Array.isArray(value.visitorPass)) {
34290
+ for (const item of value.visitorPass) {
34291
+ let status = "Invalid";
34292
+ if (item?.status == "Returned" /* RETURNED */) {
34293
+ status = "Available" /* AVAILABLE */;
34294
+ } else if (item?.status == "Not Returned" /* NOT_RETURNED */) {
34295
+ status = "In Use" /* IN_USE */;
34296
+ } else if (item?.status && VALID_STATUSES.has(item.status)) {
34297
+ status = item.status;
34298
+ } else {
34299
+ throw new Error("Invalid Visitor Pass Status");
34300
+ }
34301
+ await KeyRepo.updateKeyById(
34302
+ item.keyId,
34303
+ {
34304
+ status,
34305
+ updatedBy: value.updatedBy
34306
+ },
34307
+ value.site,
34308
+ session,
34309
+ void 0,
34310
+ id
34311
+ );
34312
+ item.lastUpdate = /* @__PURE__ */ new Date();
34313
+ }
34314
+ }
34315
+ if (Array.isArray(value.passKeys)) {
34316
+ for (const item of value.passKeys) {
34317
+ let status = "Invalid";
34318
+ if (item?.status == "Returned" /* RETURNED */) {
34319
+ status = "Available" /* AVAILABLE */;
34320
+ } else if (item?.status == "Not Returned" /* NOT_RETURNED */) {
34321
+ status = "In Use" /* IN_USE */;
34322
+ } else if (item?.status && VALID_STATUSES.has(item.status)) {
34323
+ status = item.status;
34324
+ } else {
34325
+ throw new Error("Invalid Visitor Pass Status");
34326
+ }
34327
+ await KeyRepo.updateKeyById(
34328
+ item.keyId,
34329
+ {
34330
+ status,
34331
+ updatedBy: value.updatedBy
34332
+ },
34333
+ value.site,
34334
+ session,
34335
+ void 0,
34336
+ id
34337
+ );
34338
+ item.lastUpdate = /* @__PURE__ */ new Date();
34339
+ }
34340
+ }
34246
34341
  await _updateVisitorTansactionById(id, value, session);
34247
34342
  const allowedPersonTypes = [
34248
34343
  "contractor" /* CONTRACTOR */,
@@ -57770,7 +57865,8 @@ function useNewDashboardRepo() {
57770
57865
  site,
57771
57866
  serviceType,
57772
57867
  page = 1,
57773
- limit = 10
57868
+ limit = 10,
57869
+ period = "today" /* TODAY */
57774
57870
  }) {
57775
57871
  page = page > 0 ? page - 1 : 0;
57776
57872
  const cacheOptions = { serviceType, page, limit };
@@ -57780,9 +57876,7 @@ function useNewDashboardRepo() {
57780
57876
  } catch {
57781
57877
  throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
57782
57878
  }
57783
- const todayStart = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
57784
- const todayEnd = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
57785
- const todayRange = { $gte: todayStart, $lte: todayEnd };
57879
+ const todayRange = getDateRange(period);
57786
57880
  try {
57787
57881
  const [items, countResult] = await Promise.all([
57788
57882
  areaChecklistCollection.aggregate([
@@ -57858,7 +57952,8 @@ function useNewDashboardRepo() {
57858
57952
  site,
57859
57953
  serviceType,
57860
57954
  page = 1,
57861
- limit = 10
57955
+ limit = 10,
57956
+ period = "today" /* TODAY */
57862
57957
  }) {
57863
57958
  page = page > 0 ? page - 1 : 0;
57864
57959
  const cacheOptions = { serviceType, page, limit };
@@ -57868,8 +57963,9 @@ function useNewDashboardRepo() {
57868
57963
  } catch {
57869
57964
  throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
57870
57965
  }
57871
- const todayStart = import_moment.default.tz("Asia/Singapore").startOf("day").toDate();
57872
- const todayEnd = import_moment.default.tz("Asia/Singapore").endOf("day").toDate();
57966
+ const periodRange = getDateRange(period);
57967
+ const todayStart = periodRange.$gte;
57968
+ const todayEnd = periodRange.$lte;
57873
57969
  const todayStartStr = todayStart.toISOString();
57874
57970
  const todayEndStr = todayEnd.toISOString();
57875
57971
  try {
@@ -57986,7 +58082,8 @@ function useNewDashboardRepo() {
57986
58082
  site,
57987
58083
  serviceType,
57988
58084
  page = 1,
57989
- limit = 10
58085
+ limit = 10,
58086
+ period = "today" /* TODAY */
57990
58087
  }) {
57991
58088
  page = page > 0 ? page - 1 : 0;
57992
58089
  const cacheOptions = { serviceType, page, limit };
@@ -57997,10 +58094,14 @@ function useNewDashboardRepo() {
57997
58094
  throw new import_node_server_utils199.BadRequestError("Invalid site ID format.");
57998
58095
  }
57999
58096
  const workOrderService = workOrderServiceMap[serviceType] ?? serviceType;
58097
+ const matchQuery = { site, service: workOrderService };
58098
+ if (period) {
58099
+ matchQuery.createdAt = getDateRange(period);
58100
+ }
58000
58101
  try {
58001
58102
  const [items, length] = await Promise.all([
58002
58103
  feedbackCollection.aggregate([
58003
- { $match: { site, service: workOrderService } },
58104
+ { $match: matchQuery },
58004
58105
  { $sort: { createdAt: -1, _id: -1 } },
58005
58106
  {
58006
58107
  $lookup: {
@@ -58023,7 +58124,7 @@ function useNewDashboardRepo() {
58023
58124
  { $skip: page * limit },
58024
58125
  { $limit: limit }
58025
58126
  ]).toArray(),
58026
- feedbackCollection.countDocuments({ site, service: workOrderService })
58127
+ feedbackCollection.countDocuments(matchQuery)
58027
58128
  ]);
58028
58129
  const data = (0, import_node_server_utils199.paginate)(items, page, limit, length);
58029
58130
  return data;
@@ -58183,6 +58284,7 @@ function useNewDashboardController() {
58183
58284
  const validation = import_joi112.default.object({
58184
58285
  site: import_joi112.default.string().hex().required(),
58185
58286
  serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
58287
+ period: import_joi112.default.string().valid(...Object.values(Period)).default("today" /* TODAY */),
58186
58288
  page: import_joi112.default.number().min(1).optional().allow("", null),
58187
58289
  limit: import_joi112.default.number().min(1).optional().allow("", null)
58188
58290
  });
@@ -58194,12 +58296,14 @@ function useNewDashboardController() {
58194
58296
  }
58195
58297
  const site = req.params.site;
58196
58298
  const serviceType = req.params.serviceType;
58299
+ const period = req.query.period;
58197
58300
  const page = parseInt(req.query.page) ?? 1;
58198
58301
  const limit = parseInt(req.query.limit) ?? 10;
58199
58302
  try {
58200
58303
  const data = await _getServiceTodayTaskSchedule({
58201
58304
  site,
58202
58305
  serviceType,
58306
+ period,
58203
58307
  page,
58204
58308
  limit
58205
58309
  });
@@ -58216,6 +58320,7 @@ function useNewDashboardController() {
58216
58320
  const validation = import_joi112.default.object({
58217
58321
  site: import_joi112.default.string().hex().required(),
58218
58322
  serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
58323
+ period: import_joi112.default.string().valid(...Object.values(Period)).default("today" /* TODAY */),
58219
58324
  page: import_joi112.default.number().min(1).optional().allow("", null),
58220
58325
  limit: import_joi112.default.number().min(1).optional().allow("", null)
58221
58326
  });
@@ -58227,12 +58332,14 @@ function useNewDashboardController() {
58227
58332
  }
58228
58333
  const site = req.params.site;
58229
58334
  const serviceType = req.params.serviceType;
58335
+ const period = req.query.period;
58230
58336
  const page = parseInt(req.query.page) ?? 1;
58231
58337
  const limit = parseInt(req.query.limit) ?? 10;
58232
58338
  try {
58233
58339
  const data = await _getServiceStaffAttendance({
58234
58340
  site,
58235
58341
  serviceType,
58342
+ period,
58236
58343
  page,
58237
58344
  limit
58238
58345
  });
@@ -58249,6 +58356,7 @@ function useNewDashboardController() {
58249
58356
  const validation = import_joi112.default.object({
58250
58357
  site: import_joi112.default.string().hex().required(),
58251
58358
  serviceType: import_joi112.default.string().valid(...Object.values(AppServiceType)).required(),
58359
+ period: import_joi112.default.string().valid(...Object.values(Period)).default("today" /* TODAY */),
58252
58360
  page: import_joi112.default.number().min(1).optional().allow("", null),
58253
58361
  limit: import_joi112.default.number().min(1).optional().allow("", null)
58254
58362
  });
@@ -58260,12 +58368,14 @@ function useNewDashboardController() {
58260
58368
  }
58261
58369
  const site = req.params.site;
58262
58370
  const serviceType = req.params.serviceType;
58371
+ const period = req.query.period;
58263
58372
  const page = parseInt(req.query.page) ?? 1;
58264
58373
  const limit = parseInt(req.query.limit) ?? 10;
58265
58374
  try {
58266
58375
  const data = await _getServiceRecentFeedbacks({
58267
58376
  site,
58268
58377
  serviceType,
58378
+ period,
58269
58379
  page,
58270
58380
  limit
58271
58381
  });
@@ -60556,7 +60666,6 @@ function useHrmLabsAttendanceSrvc() {
60556
60666
  };
60557
60667
  } catch (error) {
60558
60668
  import_node_server_utils213.logger.error(error.message || error);
60559
- console.log("Error fetching attendance data:", error);
60560
60669
  return { success: false, message: error?.message || "Internal Server Error!", items: [], pages: 0, pageRange: "0-0 of 0", count: {} };
60561
60670
  }
60562
60671
  }
@@ -60670,7 +60779,6 @@ function useHrmLabsAttendanceSrvc() {
60670
60779
  return { totalCount };
60671
60780
  } catch (error) {
60672
60781
  import_node_server_utils213.logger.error(error.message || error);
60673
- console.log("Error fetching attendance data count:", error);
60674
60782
  return { success: false, message: error?.message || "Internal Server Error!", totalCount: null };
60675
60783
  }
60676
60784
  }
@@ -60842,7 +60950,6 @@ function useHrmLabsAttendanceSrvc() {
60842
60950
  };
60843
60951
  } catch (error) {
60844
60952
  import_node_server_utils213.logger.error(error.message || error);
60845
- console.log("Error fetching attendance data:", error);
60846
60953
  return { success: false, message: error?.message || "Internal Server Error!", items: [], count: {}, countPerJobTitle: {}, totalCount: null, countPerStatus: {} };
60847
60954
  }
60848
60955
  }
@@ -60949,7 +61056,6 @@ function useHrmLabsAttendanceSrvc() {
60949
61056
  };
60950
61057
  } catch (error) {
60951
61058
  import_node_server_utils213.logger.error(error.message || error);
60952
- console.log("Error fetching attendance data:", error);
60953
61059
  return { success: false, message: error?.message || "Internal Server Error!", chartCount: null };
60954
61060
  }
60955
61061
  }
@@ -66735,13 +66841,14 @@ var BidStatus = /* @__PURE__ */ ((BidStatus3) => {
66735
66841
  var schemaBidPreloved = import_joi145.default.object({
66736
66842
  type: import_joi145.default.string().valid(...Object.values(BidType)).required(),
66737
66843
  postId: import_joi145.default.string().hex().length(24).required(),
66844
+ receiverId: import_joi145.default.string().hex().length(24).required(),
66845
+ buyerId: import_joi145.default.string().hex().length(24).required(),
66738
66846
  price: import_joi145.default.when("type", {
66739
66847
  is: "bid" /* BID */,
66740
66848
  then: import_joi145.default.number().required(),
66741
66849
  otherwise: import_joi145.default.number().optional().allow(null)
66742
66850
  }),
66743
66851
  message: import_joi145.default.string().optional().allow("", null),
66744
- buyerId: import_joi145.default.string().hex().length(24).optional().allow("", null),
66745
66852
  status: import_joi145.default.string().valid(...Object.values(BidStatus)).optional().default("pending" /* PENDING */)
66746
66853
  });
66747
66854
  var schemaUpdateBidPreloved = import_joi145.default.object({
@@ -66798,29 +66905,104 @@ function useBidPrelovedRepo() {
66798
66905
  throw new import_node_server_utils250.InternalServerError("Unable to update bid.");
66799
66906
  return "Bid updated successfully.";
66800
66907
  }
66801
- return { add, updateStatus };
66908
+ async function getById(_id) {
66909
+ if (typeof _id === "string")
66910
+ _id = new import_mongodb150.ObjectId(_id);
66911
+ const result = await collection.findOne({ _id });
66912
+ if (!result)
66913
+ throw new import_node_server_utils250.NotFoundError("Bid not found.");
66914
+ return result;
66915
+ }
66916
+ return { add, getById, updateStatus };
66802
66917
  }
66803
66918
 
66804
66919
  // src/controllers/bid-preloved.controller.ts
66805
- var import_node_server_utils251 = require("@7365admin1/node-server-utils");
66920
+ var import_node_server_utils252 = require("@7365admin1/node-server-utils");
66806
66921
  var import_joi146 = __toESM(require("joi"));
66922
+
66923
+ // src/services/bid-preloved.service.ts
66924
+ var import_node_server_utils251 = require("@7365admin1/node-server-utils");
66925
+ function useBidPrelovedService() {
66926
+ const { add: _addBid } = useBidPrelovedRepo();
66927
+ const { add: _addChannel, getByParticipants: _getByParticipants } = useChannelPrelovedRepo();
66928
+ const { add: _addChat } = useChatPrelovedRepo();
66929
+ async function createBid(value) {
66930
+ const client = import_node_server_utils251.useAtlas.getClient();
66931
+ if (!client)
66932
+ throw new import_node_server_utils251.InternalServerError("Unable to connect to server.");
66933
+ const buyerId = value.buyerId;
66934
+ const receiverId = value.receiverId;
66935
+ const postId = value.postId;
66936
+ const messageText = value.message || "";
66937
+ const session = client.startSession();
66938
+ session.startTransaction();
66939
+ try {
66940
+ const bidId = await _addBid(value, session);
66941
+ const existingChannel = await _getByParticipants(
66942
+ buyerId,
66943
+ receiverId,
66944
+ postId
66945
+ );
66946
+ let channelId;
66947
+ if (existingChannel) {
66948
+ channelId = existingChannel._id.toString();
66949
+ } else {
66950
+ const newChannelId = await _addChannel(
66951
+ {
66952
+ senderId: buyerId,
66953
+ receiverId,
66954
+ postId
66955
+ },
66956
+ session
66957
+ );
66958
+ channelId = newChannelId.toString();
66959
+ }
66960
+ await _addChat(
66961
+ {
66962
+ channelId,
66963
+ senderId: buyerId,
66964
+ postId,
66965
+ bidId: bidId.toString(),
66966
+ message: {
66967
+ text: messageText,
66968
+ date: (/* @__PURE__ */ new Date()).toISOString(),
66969
+ senderId: buyerId
66970
+ }
66971
+ },
66972
+ session
66973
+ );
66974
+ await session.commitTransaction();
66975
+ return { bidId };
66976
+ } catch (error) {
66977
+ await session.abortTransaction();
66978
+ throw error;
66979
+ } finally {
66980
+ session.endSession();
66981
+ }
66982
+ }
66983
+ return { createBid };
66984
+ }
66985
+
66986
+ // src/controllers/bid-preloved.controller.ts
66807
66987
  function useBidPrelovedController() {
66808
- const { add: _add, updateStatus: _updateStatus } = useBidPrelovedRepo();
66988
+ const { createBid: _createBid } = useBidPrelovedService();
66989
+ const { getById: _getById, updateStatus: _updateStatus } = useBidPrelovedRepo();
66809
66990
  async function add(req, res, next) {
66810
66991
  const { error, value } = schemaBidPreloved.validate(req.body, {
66811
66992
  abortEarly: false
66812
66993
  });
66813
66994
  if (error) {
66814
66995
  const messages = error.details.map((d) => d.message).join(", ");
66815
- import_node_server_utils251.logger.log({ level: "error", message: messages });
66816
- next(new import_node_server_utils251.BadRequestError(messages));
66996
+ import_node_server_utils252.logger.log({ level: "error", message: messages });
66997
+ next(new import_node_server_utils252.BadRequestError(messages));
66817
66998
  return;
66818
66999
  }
66819
67000
  try {
66820
- const data = await _add(value);
67001
+ const data = await _createBid(value);
66821
67002
  res.status(201).json(data);
66822
67003
  } catch (error2) {
66823
- import_node_server_utils251.logger.log({ level: "error", message: error2.message });
67004
+ console.log("error", error2);
67005
+ import_node_server_utils252.logger.log({ level: "error", message: error2.message });
66824
67006
  next(error2);
66825
67007
  }
66826
67008
  }
@@ -66832,27 +67014,45 @@ function useBidPrelovedController() {
66832
67014
  req.params
66833
67015
  );
66834
67016
  if (paramError) {
66835
- import_node_server_utils251.logger.log({ level: "error", message: paramError.message });
66836
- next(new import_node_server_utils251.BadRequestError(paramError.message));
67017
+ import_node_server_utils252.logger.log({ level: "error", message: paramError.message });
67018
+ next(new import_node_server_utils252.BadRequestError(paramError.message));
66837
67019
  return;
66838
67020
  }
66839
67021
  const { error: bodyError, value: body } = schemaUpdateBidPreloved.validate(
66840
67022
  req.body
66841
67023
  );
66842
67024
  if (bodyError) {
66843
- import_node_server_utils251.logger.log({ level: "error", message: bodyError.message });
66844
- next(new import_node_server_utils251.BadRequestError(bodyError.message));
67025
+ import_node_server_utils252.logger.log({ level: "error", message: bodyError.message });
67026
+ next(new import_node_server_utils252.BadRequestError(bodyError.message));
66845
67027
  return;
66846
67028
  }
66847
67029
  try {
66848
67030
  const data = await _updateStatus(params.id, body.status);
66849
67031
  res.status(200).json(data);
66850
67032
  } catch (error) {
66851
- import_node_server_utils251.logger.log({ level: "error", message: error.message });
67033
+ import_node_server_utils252.logger.log({ level: "error", message: error.message });
66852
67034
  next(error);
66853
67035
  }
66854
67036
  }
66855
- return { add, updateStatus };
67037
+ async function getById(req, res, next) {
67038
+ const paramsSchema = import_joi146.default.object({
67039
+ id: import_joi146.default.string().hex().length(24).required()
67040
+ });
67041
+ const { error, value: params } = paramsSchema.validate(req.params);
67042
+ if (error) {
67043
+ import_node_server_utils252.logger.log({ level: "error", message: error.message });
67044
+ next(new import_node_server_utils252.BadRequestError(error.message));
67045
+ return;
67046
+ }
67047
+ try {
67048
+ const data = await _getById(params.id);
67049
+ res.status(200).json(data);
67050
+ } catch (error2) {
67051
+ import_node_server_utils252.logger.log({ level: "error", message: error2.message });
67052
+ next(error2);
67053
+ }
67054
+ }
67055
+ return { add, getById, updateStatus };
66856
67056
  }
66857
67057
 
66858
67058
  // src/models/online-forms-v2.model.ts
@@ -66984,25 +67184,26 @@ var residentFormEntry = import_joi147.default.object({
66984
67184
  });
66985
67185
 
66986
67186
  // src/repositories/online-forms-v2.repository.ts
66987
- var import_node_server_utils252 = require("@7365admin1/node-server-utils");
67187
+ var import_node_server_utils253 = require("@7365admin1/node-server-utils");
66988
67188
  var import_mongodb152 = require("mongodb");
66989
67189
  var online_forms_namespace_collection = "online-forms";
66990
67190
  function useFormEntryRepo() {
66991
- const db = import_node_server_utils252.useAtlas.getDb();
67191
+ const db = import_node_server_utils253.useAtlas.getDb();
66992
67192
  if (!db) {
66993
- throw new import_node_server_utils252.InternalServerError("Unable to connect to server.");
67193
+ throw new import_node_server_utils253.InternalServerError("Unable to connect to server.");
66994
67194
  }
66995
67195
  const collection = db.collection(online_forms_namespace_collection);
66996
- const { delNamespace, getCache, setCache } = (0, import_node_server_utils252.useCache)(
67196
+ const { delNamespace, getCache, setCache } = (0, import_node_server_utils253.useCache)(
66997
67197
  online_forms_namespace_collection
66998
67198
  );
67199
+ const { getUserById } = useUserRepo();
66999
67200
  async function createTextIndex() {
67000
67201
  try {
67001
67202
  await collection.createIndex({
67002
67203
  name: "text"
67003
67204
  });
67004
67205
  } catch (error) {
67005
- throw new import_node_server_utils252.InternalServerError(
67206
+ throw new import_node_server_utils253.InternalServerError(
67006
67207
  "Failed to create text index on online form."
67007
67208
  );
67008
67209
  }
@@ -67011,21 +67212,11 @@ function useFormEntryRepo() {
67011
67212
  try {
67012
67213
  value = MFormEntry(value);
67013
67214
  const res = await collection.insertOne(value, { session });
67014
- delNamespace().then(() => {
67015
- import_node_server_utils252.logger.info(
67016
- `Cache cleared for namespace: ${online_forms_namespace_collection}`
67017
- );
67018
- }).catch((err) => {
67019
- import_node_server_utils252.logger.error(
67020
- `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
67021
- err
67022
- );
67023
- });
67024
67215
  return res.insertedId;
67025
67216
  } catch (error) {
67026
67217
  const isDuplicated = error.message.includes("duplicate");
67027
67218
  if (isDuplicated) {
67028
- throw new import_node_server_utils252.BadRequestError("Online Form already exists.");
67219
+ throw new import_node_server_utils253.BadRequestError("Online Form already exists.");
67029
67220
  }
67030
67221
  throw error;
67031
67222
  }
@@ -67043,18 +67234,10 @@ function useFormEntryRepo() {
67043
67234
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
67044
67235
  site = new import_mongodb152.ObjectId(site);
67045
67236
  org = new import_mongodb152.ObjectId(org);
67046
- const cacheOptions = {
67047
- page,
67048
- limit,
67049
- status,
67050
- sort: JSON.stringify(sort),
67051
- site,
67052
- ...search && { search }
67053
- };
67054
67237
  const query = {
67055
67238
  site,
67056
- status,
67057
- org
67239
+ status
67240
+ // org,
67058
67241
  };
67059
67242
  if (search && search !== "") {
67060
67243
  query.$or = [
@@ -67062,15 +67245,6 @@ function useFormEntryRepo() {
67062
67245
  { unitNumber: { $regex: search, $options: "i" } }
67063
67246
  ];
67064
67247
  }
67065
- const cacheKey = (0, import_node_server_utils252.makeCacheKey)(
67066
- online_forms_namespace_collection,
67067
- cacheOptions
67068
- );
67069
- const cachedData = await getCache(cacheKey);
67070
- if (cachedData) {
67071
- import_node_server_utils252.logger.info(`Cache hit for key: ${cacheKey}`);
67072
- return cachedData;
67073
- }
67074
67248
  try {
67075
67249
  const items = await collection.aggregate([
67076
67250
  { $match: query },
@@ -67095,40 +67269,24 @@ function useFormEntryRepo() {
67095
67269
  { $project: { user: 0 } }
67096
67270
  ]).toArray();
67097
67271
  const length = await collection.countDocuments(query);
67098
- const data = (0, import_node_server_utils252.paginate)(items, page, limit, length);
67099
- setCache(cacheKey, data, 15 * 60).then(() => {
67100
- import_node_server_utils252.logger.info(`Cache set for key: ${cacheKey}`);
67101
- }).catch((err) => {
67102
- import_node_server_utils252.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
67103
- });
67272
+ const data = (0, import_node_server_utils253.paginate)(items, page, limit, length);
67104
67273
  return data;
67105
67274
  } catch (error) {
67106
67275
  throw error;
67107
67276
  }
67108
67277
  }
67109
67278
  async function getFormEntryById(_id) {
67110
- const cacheKey = (0, import_node_server_utils252.makeCacheKey)(online_forms_namespace_collection, { _id });
67111
- const cachedData = await getCache(cacheKey);
67112
- if (cachedData) {
67113
- import_node_server_utils252.logger.info(`Cache hit for key: ${cacheKey}`);
67114
- return cachedData;
67115
- }
67116
67279
  try {
67117
67280
  _id = new import_mongodb152.ObjectId(_id);
67118
67281
  } catch (error) {
67119
- throw new import_node_server_utils252.BadRequestError("Invalid online form ID format.");
67282
+ throw new import_node_server_utils253.BadRequestError("Invalid online form ID format.");
67120
67283
  }
67121
67284
  const query = { _id, status: { $ne: "deleted" } };
67122
67285
  try {
67123
67286
  const [data] = await collection.aggregate([{ $match: query }]).toArray();
67124
67287
  if (!data) {
67125
- throw new import_node_server_utils252.NotFoundError("Document not found.");
67288
+ throw new import_node_server_utils253.NotFoundError("Document not found.");
67126
67289
  }
67127
- setCache(cacheKey, data, 15 * 60).then(() => {
67128
- import_node_server_utils252.logger.info(`Cache set for key: ${cacheKey}`);
67129
- }).catch((err) => {
67130
- import_node_server_utils252.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
67131
- });
67132
67290
  return data;
67133
67291
  } catch (error) {
67134
67292
  throw error;
@@ -67138,7 +67296,7 @@ function useFormEntryRepo() {
67138
67296
  try {
67139
67297
  _id = new import_mongodb152.ObjectId(_id);
67140
67298
  } catch (error) {
67141
- throw new import_node_server_utils252.BadRequestError("Invalid online form ID format.");
67299
+ throw new import_node_server_utils253.BadRequestError("Invalid online form ID format.");
67142
67300
  }
67143
67301
  try {
67144
67302
  const updateValue = {
@@ -67147,17 +67305,21 @@ function useFormEntryRepo() {
67147
67305
  };
67148
67306
  const res = await collection.updateOne({ _id }, { $set: updateValue });
67149
67307
  if (res.modifiedCount === 0) {
67150
- throw new import_node_server_utils252.InternalServerError("Unable to update online form.");
67308
+ throw new import_node_server_utils253.InternalServerError("Unable to update online form.");
67151
67309
  }
67152
- delNamespace().then(() => {
67153
- import_node_server_utils252.logger.info(
67154
- `Cache cleared for namespace: ${online_forms_namespace_collection}`
67155
- );
67156
- }).catch((err) => {
67157
- import_node_server_utils252.logger.error(
67158
- `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
67159
- err
67160
- );
67310
+ const onlineFormRequest = await collection.findOne({ _id });
67311
+ if (!onlineFormRequest) {
67312
+ throw new import_node_server_utils253.NotFoundError("Online form not found.");
67313
+ }
67314
+ const user = await getUserById(onlineFormRequest.userId.toString());
67315
+ if (!user || !user._id) {
67316
+ throw new import_node_server_utils253.NotFoundError("User not found.");
67317
+ }
67318
+ const userId = user._id.toString();
67319
+ await NotificationService.onlineFormRequestStatusUpdated({
67320
+ to: userId,
67321
+ onlineFormId: onlineFormRequest._id,
67322
+ status: onlineFormRequest.status
67161
67323
  });
67162
67324
  return res.modifiedCount;
67163
67325
  } catch (error) {
@@ -67168,7 +67330,7 @@ function useFormEntryRepo() {
67168
67330
  try {
67169
67331
  _id = new import_mongodb152.ObjectId(_id);
67170
67332
  } catch (error) {
67171
- throw new import_node_server_utils252.BadRequestError("Invalid online form ID format.");
67333
+ throw new import_node_server_utils253.BadRequestError("Invalid online form ID format.");
67172
67334
  }
67173
67335
  try {
67174
67336
  const updateValue = {
@@ -67182,16 +67344,8 @@ function useFormEntryRepo() {
67182
67344
  { session }
67183
67345
  );
67184
67346
  if (res.modifiedCount === 0) {
67185
- throw new import_node_server_utils252.InternalServerError("Unable to delete online form.");
67347
+ throw new import_node_server_utils253.InternalServerError("Unable to delete online form.");
67186
67348
  }
67187
- delNamespace().then(() => {
67188
- import_node_server_utils252.logger.info(`Cache cleared for namespace: ${online_forms_namespace_collection}`);
67189
- }).catch((err) => {
67190
- import_node_server_utils252.logger.error(
67191
- `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
67192
- err
67193
- );
67194
- });
67195
67349
  return res.modifiedCount;
67196
67350
  } catch (error) {
67197
67351
  throw new Error(error.message);
@@ -67203,40 +67357,73 @@ function useFormEntryRepo() {
67203
67357
  value.org = new import_mongodb152.ObjectId(value.org);
67204
67358
  value.userId = new import_mongodb152.ObjectId(value.userId);
67205
67359
  const res = await collection.insertOne(value, { session });
67206
- delNamespace().then(() => {
67207
- import_node_server_utils252.logger.info(
67208
- `Cache cleared for namespace: ${online_forms_namespace_collection}`
67209
- );
67210
- }).catch((err) => {
67211
- import_node_server_utils252.logger.error(
67212
- `Failed to clear cache for namespace: ${online_forms_namespace_collection}`,
67213
- err
67214
- );
67215
- });
67216
67360
  return res.insertedId;
67217
67361
  } catch (error) {
67218
67362
  const isDuplicated = error.message.includes("duplicate");
67219
67363
  if (isDuplicated) {
67220
- throw new import_node_server_utils252.BadRequestError("Online Form already exists.");
67364
+ throw new import_node_server_utils253.BadRequestError("Online Form already exists.");
67221
67365
  }
67222
67366
  throw error;
67223
67367
  }
67224
67368
  }
67225
- async function residentForm({ userId, site, org }) {
67369
+ async function residentForm({
67370
+ userId,
67371
+ site,
67372
+ org,
67373
+ search = "",
67374
+ page = 1,
67375
+ limit = 10,
67376
+ sort = {}
67377
+ }) {
67378
+ page = page > 0 ? page - 1 : 0;
67379
+ sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
67380
+ const user = new import_mongodb152.ObjectId(userId);
67381
+ const siteId = new import_mongodb152.ObjectId(site);
67382
+ const orgId = new import_mongodb152.ObjectId(org);
67383
+ const cacheOptions = {
67384
+ page,
67385
+ limit,
67386
+ sort: JSON.stringify(sort),
67387
+ userId: user,
67388
+ site: siteId,
67389
+ org: orgId,
67390
+ ...search && { search }
67391
+ };
67392
+ const query = {
67393
+ userId: user,
67394
+ site: siteId,
67395
+ org: orgId
67396
+ };
67397
+ if (search && search !== "") {
67398
+ query.$or = [
67399
+ { typeOfForm: { $regex: search, $options: "i" } },
67400
+ { unitNumber: { $regex: search, $options: "i" } }
67401
+ ];
67402
+ }
67403
+ const cacheKey = (0, import_node_server_utils253.makeCacheKey)(
67404
+ online_forms_namespace_collection,
67405
+ cacheOptions
67406
+ );
67407
+ const cachedData = await getCache(cacheKey);
67408
+ if (cachedData) {
67409
+ import_node_server_utils253.logger.info(`Cache hit for key: ${cacheKey}`);
67410
+ return cachedData;
67411
+ }
67226
67412
  try {
67227
- const user = new import_mongodb152.ObjectId(userId);
67228
- const siteId = new import_mongodb152.ObjectId(site);
67229
- const orgId = new import_mongodb152.ObjectId(org);
67230
- const res = await collection.aggregate([
67231
- {
67232
- $match: {
67233
- userId: user,
67234
- site: siteId,
67235
- org: orgId
67236
- }
67237
- }
67413
+ const items = await collection.aggregate([
67414
+ { $match: query },
67415
+ { $sort: sort },
67416
+ { $skip: page * limit },
67417
+ { $limit: limit }
67238
67418
  ]).toArray();
67239
- return res;
67419
+ const length = await collection.countDocuments(query);
67420
+ const data = (0, import_node_server_utils253.paginate)(items, page, limit, length);
67421
+ setCache(cacheKey, data, 15 * 60).then(() => {
67422
+ import_node_server_utils253.logger.info(`Cache set for key: ${cacheKey}`);
67423
+ }).catch((err) => {
67424
+ import_node_server_utils253.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
67425
+ });
67426
+ return data;
67240
67427
  } catch (error) {
67241
67428
  throw error;
67242
67429
  }
@@ -67254,7 +67441,7 @@ function useFormEntryRepo() {
67254
67441
  }
67255
67442
 
67256
67443
  // src/controllers/online-forms-v2.controller.ts
67257
- var import_node_server_utils253 = require("@7365admin1/node-server-utils");
67444
+ var import_node_server_utils254 = require("@7365admin1/node-server-utils");
67258
67445
  var import_joi148 = __toESM(require("joi"));
67259
67446
  var import_exceljs3 = __toESM(require("exceljs"));
67260
67447
  var import_fs7 = __toESM(require("fs"));
@@ -67281,14 +67468,14 @@ function useFormEntryController() {
67281
67468
  async function uploadFormEntrys(req, res, next) {
67282
67469
  try {
67283
67470
  if (!req.file) {
67284
- next(new import_node_server_utils253.BadRequestError("Excel file is required."));
67471
+ next(new import_node_server_utils254.BadRequestError("Excel file is required."));
67285
67472
  return;
67286
67473
  }
67287
67474
  const workbook = new import_exceljs3.default.Workbook();
67288
67475
  await workbook.xlsx.readFile(req.file.path);
67289
67476
  const worksheet = workbook.worksheets[0];
67290
67477
  if (!worksheet) {
67291
- next(new import_node_server_utils253.BadRequestError("No worksheet found in uploaded Excel file."));
67478
+ next(new import_node_server_utils254.BadRequestError("No worksheet found in uploaded Excel file."));
67292
67479
  return;
67293
67480
  }
67294
67481
  const headerRow = worksheet.getRow(1);
@@ -67316,8 +67503,8 @@ function useFormEntryController() {
67316
67503
  });
67317
67504
  if (error) {
67318
67505
  const messages = error.details.map((d) => d.message).join(", ");
67319
- import_node_server_utils253.logger.log({ level: "error", message: messages });
67320
- next(new import_node_server_utils253.BadRequestError(messages));
67506
+ import_node_server_utils254.logger.log({ level: "error", message: messages });
67507
+ next(new import_node_server_utils254.BadRequestError(messages));
67321
67508
  return;
67322
67509
  }
67323
67510
  const result = await _add(value);
@@ -67325,7 +67512,7 @@ function useFormEntryController() {
67325
67512
  import_fs7.default.unlink(req.file.path, () => {
67326
67513
  });
67327
67514
  } catch (error) {
67328
- import_node_server_utils253.logger.log({ level: "error", message: error.message });
67515
+ import_node_server_utils254.logger.log({ level: "error", message: error.message });
67329
67516
  next(error);
67330
67517
  }
67331
67518
  }
@@ -67342,8 +67529,8 @@ function useFormEntryController() {
67342
67529
  const { error, value } = schema2.validate(req.query);
67343
67530
  if (error) {
67344
67531
  const messages = error.details.map((d) => d.message).join(", ");
67345
- import_node_server_utils253.logger.log({ level: "error", message: messages });
67346
- next(new import_node_server_utils253.BadRequestError(messages));
67532
+ import_node_server_utils254.logger.log({ level: "error", message: messages });
67533
+ next(new import_node_server_utils254.BadRequestError(messages));
67347
67534
  return;
67348
67535
  }
67349
67536
  const { search, page, limit, status, org, site } = value;
@@ -67351,7 +67538,7 @@ function useFormEntryController() {
67351
67538
  res.json(data);
67352
67539
  return;
67353
67540
  } catch (error) {
67354
- import_node_server_utils253.logger.log({ level: "error", message: error.message });
67541
+ import_node_server_utils254.logger.log({ level: "error", message: error.message });
67355
67542
  next(error);
67356
67543
  return;
67357
67544
  }
@@ -67364,8 +67551,8 @@ function useFormEntryController() {
67364
67551
  const { error, value } = schema2.validate({ _id: req.params.id });
67365
67552
  if (error) {
67366
67553
  const messages = error.details.map((d) => d.message).join(", ");
67367
- import_node_server_utils253.logger.log({ level: "error", message: messages });
67368
- next(new import_node_server_utils253.BadRequestError(messages));
67554
+ import_node_server_utils254.logger.log({ level: "error", message: messages });
67555
+ next(new import_node_server_utils254.BadRequestError(messages));
67369
67556
  return;
67370
67557
  }
67371
67558
  const { _id } = value;
@@ -67373,7 +67560,7 @@ function useFormEntryController() {
67373
67560
  res.json(data);
67374
67561
  return;
67375
67562
  } catch (error) {
67376
- import_node_server_utils253.logger.log({ level: "error", message: error.message });
67563
+ import_node_server_utils254.logger.log({ level: "error", message: error.message });
67377
67564
  next(error);
67378
67565
  return;
67379
67566
  }
@@ -67386,8 +67573,8 @@ function useFormEntryController() {
67386
67573
  });
67387
67574
  if (error) {
67388
67575
  const messages = error.details.map((d) => d.message).join(", ");
67389
- import_node_server_utils253.logger.log({ level: "error", message: messages });
67390
- next(new import_node_server_utils253.BadRequestError(messages));
67576
+ import_node_server_utils254.logger.log({ level: "error", message: messages });
67577
+ next(new import_node_server_utils254.BadRequestError(messages));
67391
67578
  return;
67392
67579
  }
67393
67580
  const { _id, ...rest } = value;
@@ -67395,7 +67582,7 @@ function useFormEntryController() {
67395
67582
  res.json({ message: "Successfully updated online form." });
67396
67583
  return;
67397
67584
  } catch (error) {
67398
- import_node_server_utils253.logger.log({ level: "error", message: error.message });
67585
+ import_node_server_utils254.logger.log({ level: "error", message: error.message });
67399
67586
  next(error);
67400
67587
  return;
67401
67588
  }
@@ -67406,15 +67593,15 @@ function useFormEntryController() {
67406
67593
  const _id = req.params.id;
67407
67594
  const { error } = validation.validate(_id);
67408
67595
  if (error) {
67409
- import_node_server_utils253.logger.log({ level: "error", message: error.message });
67410
- next(new import_node_server_utils253.BadRequestError(error.message));
67596
+ import_node_server_utils254.logger.log({ level: "error", message: error.message });
67597
+ next(new import_node_server_utils254.BadRequestError(error.message));
67411
67598
  return;
67412
67599
  }
67413
67600
  await _deleteOnlineFormById(_id);
67414
67601
  res.json({ message: "Successfully deleted online form." });
67415
67602
  return;
67416
67603
  } catch (error) {
67417
- import_node_server_utils253.logger.log({ level: "error", message: error.message });
67604
+ import_node_server_utils254.logger.log({ level: "error", message: error.message });
67418
67605
  next(error);
67419
67606
  return;
67420
67607
  }
@@ -67431,8 +67618,8 @@ function useFormEntryController() {
67431
67618
  });
67432
67619
  if (error) {
67433
67620
  const messages = error.details.map((d) => d.message).join(", ");
67434
- import_node_server_utils253.logger.log({ level: "error", message: messages });
67435
- next(new import_node_server_utils253.BadRequestError(messages));
67621
+ import_node_server_utils254.logger.log({ level: "error", message: messages });
67622
+ next(new import_node_server_utils254.BadRequestError(messages));
67436
67623
  return;
67437
67624
  }
67438
67625
  try {
@@ -67440,7 +67627,7 @@ function useFormEntryController() {
67440
67627
  res.status(201).json({ message: data });
67441
67628
  return;
67442
67629
  } catch (error2) {
67443
- import_node_server_utils253.logger.log({ level: "error", message: error2.message });
67630
+ import_node_server_utils254.logger.log({ level: "error", message: error2.message });
67444
67631
  next(error2);
67445
67632
  return;
67446
67633
  }
@@ -67452,8 +67639,8 @@ function useFormEntryController() {
67452
67639
  });
67453
67640
  if (error) {
67454
67641
  const messages = error.details.map((d) => d.message).join(", ");
67455
- import_node_server_utils253.logger.log({ level: "error", message: messages });
67456
- next(new import_node_server_utils253.BadRequestError(messages));
67642
+ import_node_server_utils254.logger.log({ level: "error", message: messages });
67643
+ next(new import_node_server_utils254.BadRequestError(messages));
67457
67644
  return;
67458
67645
  }
67459
67646
  try {
@@ -67461,30 +67648,35 @@ function useFormEntryController() {
67461
67648
  res.status(201).json({ message: data });
67462
67649
  return;
67463
67650
  } catch (error2) {
67464
- import_node_server_utils253.logger.log({ level: "error", message: error2.message });
67651
+ import_node_server_utils254.logger.log({ level: "error", message: error2.message });
67465
67652
  next(error2);
67466
67653
  return;
67467
67654
  }
67468
67655
  }
67469
67656
  async function residentForm(req, res, next) {
67470
67657
  try {
67471
- const { site, userId, org } = req.query;
67472
67658
  const residentFormPayload = import_joi148.default.object({
67473
67659
  org: import_joi148.default.string().hex().required(),
67474
67660
  site: import_joi148.default.string().hex().required(),
67475
- userId: import_joi148.default.string().hex().required()
67661
+ userId: import_joi148.default.string().hex().required(),
67662
+ search: import_joi148.default.string().optional().allow("", null),
67663
+ page: import_joi148.default.number().integer().min(1).allow("", null).default(1),
67664
+ limit: import_joi148.default.number().integer().min(1).max(100).allow("", null).default(10)
67665
+ });
67666
+ const { error, value } = residentFormPayload.validate(req.query, {
67667
+ abortEarly: true
67476
67668
  });
67477
- const { error } = residentFormPayload.validate({ site, userId, org }, { abortEarly: true });
67478
67669
  if (error) {
67479
67670
  const messages = error.details.map((d) => d.message).join(", ");
67480
- import_node_server_utils253.logger.log({ level: "error", message: messages });
67481
- next(new import_node_server_utils253.BadRequestError(messages));
67671
+ import_node_server_utils254.logger.log({ level: "error", message: messages });
67672
+ next(new import_node_server_utils254.BadRequestError(messages));
67482
67673
  return;
67483
67674
  }
67484
- const result = await _residentForm({ userId, site, org });
67675
+ const { site, userId, org, search, page, limit } = value;
67676
+ const result = await _residentForm({ userId, site, org, search, page, limit });
67485
67677
  res.json(result);
67486
67678
  } catch (error) {
67487
- import_node_server_utils253.logger.log({ level: "error", message: error.message });
67679
+ import_node_server_utils254.logger.log({ level: "error", message: error.message });
67488
67680
  next(error);
67489
67681
  return;
67490
67682
  }
@@ -67502,11 +67694,11 @@ function useFormEntryController() {
67502
67694
  }
67503
67695
 
67504
67696
  // src/services/building-level.service.ts
67505
- var import_node_server_utils254 = require("@7365admin1/node-server-utils");
67697
+ var import_node_server_utils255 = require("@7365admin1/node-server-utils");
67506
67698
  function useBuildingLevelService() {
67507
67699
  const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelRepo();
67508
67700
  async function add(value) {
67509
- const session = import_node_server_utils254.useAtlas.getClient()?.startSession();
67701
+ const session = import_node_server_utils255.useAtlas.getClient()?.startSession();
67510
67702
  try {
67511
67703
  session?.startTransaction();
67512
67704
  await _add(value, session);
@@ -67520,7 +67712,7 @@ function useBuildingLevelService() {
67520
67712
  }
67521
67713
  }
67522
67714
  async function updateLevelById(_id, value) {
67523
- const session = import_node_server_utils254.useAtlas.getClient()?.startSession();
67715
+ const session = import_node_server_utils255.useAtlas.getClient()?.startSession();
67524
67716
  try {
67525
67717
  session?.startTransaction();
67526
67718
  await _updateLevelById(_id, value, session);
@@ -67540,7 +67732,7 @@ function useBuildingLevelService() {
67540
67732
  }
67541
67733
 
67542
67734
  // src/controllers/building-level.controller.ts
67543
- var import_node_server_utils255 = require("@7365admin1/node-server-utils");
67735
+ var import_node_server_utils256 = require("@7365admin1/node-server-utils");
67544
67736
  var import_joi149 = __toESM(require("joi"));
67545
67737
  function useBuildingLevelController() {
67546
67738
  const { add: _add, updateLevelById: _updateLevelById } = useBuildingLevelService();
@@ -67558,8 +67750,8 @@ function useBuildingLevelController() {
67558
67750
  });
67559
67751
  if (error) {
67560
67752
  const messages = error.details.map((d) => d.message).join(", ");
67561
- import_node_server_utils255.logger.log({ level: "error", message: messages });
67562
- next(new import_node_server_utils255.BadRequestError(messages));
67753
+ import_node_server_utils256.logger.log({ level: "error", message: messages });
67754
+ next(new import_node_server_utils256.BadRequestError(messages));
67563
67755
  return;
67564
67756
  }
67565
67757
  const result = await _add(value);
@@ -67582,8 +67774,8 @@ function useBuildingLevelController() {
67582
67774
  });
67583
67775
  if (error) {
67584
67776
  const messages = error.details.map((d) => d.message);
67585
- import_node_server_utils255.logger.log({ level: "error", message: messages.join(", ") });
67586
- next(new import_node_server_utils255.BadRequestError(messages.join(", ")));
67777
+ import_node_server_utils256.logger.log({ level: "error", message: messages.join(", ") });
67778
+ next(new import_node_server_utils256.BadRequestError(messages.join(", ")));
67587
67779
  return;
67588
67780
  }
67589
67781
  const { page, limit, status, site, search } = value;
@@ -67608,8 +67800,8 @@ function useBuildingLevelController() {
67608
67800
  const { error, value } = schema2.validate({ id: req.params.id });
67609
67801
  if (error) {
67610
67802
  const messages = error.details.map((d) => d.message);
67611
- import_node_server_utils255.logger.log({ level: "error", message: messages.join(", ") });
67612
- next(new import_node_server_utils255.BadRequestError(messages.join(", ")));
67803
+ import_node_server_utils256.logger.log({ level: "error", message: messages.join(", ") });
67804
+ next(new import_node_server_utils256.BadRequestError(messages.join(", ")));
67613
67805
  return;
67614
67806
  }
67615
67807
  const { id } = value;
@@ -67628,8 +67820,8 @@ function useBuildingLevelController() {
67628
67820
  });
67629
67821
  if (error) {
67630
67822
  const messages = error.details.map((d) => d.message);
67631
- import_node_server_utils255.logger.log({ level: "error", message: messages.join(", ") });
67632
- next(new import_node_server_utils255.BadRequestError(messages.join(", ")));
67823
+ import_node_server_utils256.logger.log({ level: "error", message: messages.join(", ") });
67824
+ next(new import_node_server_utils256.BadRequestError(messages.join(", ")));
67633
67825
  return;
67634
67826
  }
67635
67827
  const { _id, ...rest } = value;
@@ -67647,8 +67839,8 @@ function useBuildingLevelController() {
67647
67839
  const { error, value } = schema2.validate({ id: req.params.id });
67648
67840
  if (error) {
67649
67841
  const messages = error.details.map((d) => d.message);
67650
- import_node_server_utils255.logger.log({ level: "error", message: messages.join(", ") });
67651
- next(new import_node_server_utils255.BadRequestError(messages.join(", ")));
67842
+ import_node_server_utils256.logger.log({ level: "error", message: messages.join(", ") });
67843
+ next(new import_node_server_utils256.BadRequestError(messages.join(", ")));
67652
67844
  return;
67653
67845
  }
67654
67846
  const { id } = value;
@@ -67672,8 +67864,8 @@ function useBuildingLevelController() {
67672
67864
  const { error, value } = schema2.validate(req.body);
67673
67865
  if (error) {
67674
67866
  const messages = error.details.map((d) => d.message);
67675
- import_node_server_utils255.logger.log({ level: "error", message: messages.join(", ") });
67676
- next(new import_node_server_utils255.BadRequestError(messages.join(", ")));
67867
+ import_node_server_utils256.logger.log({ level: "error", message: messages.join(", ") });
67868
+ next(new import_node_server_utils256.BadRequestError(messages.join(", ")));
67677
67869
  return;
67678
67870
  }
67679
67871
  const updates = value.map((item) => ({
@@ -67698,8 +67890,8 @@ function useBuildingLevelController() {
67698
67890
  });
67699
67891
  if (error) {
67700
67892
  const messages = error.details.map((d) => d.message).join(", ");
67701
- import_node_server_utils255.logger.log({ level: "error", message: messages });
67702
- next(new import_node_server_utils255.BadRequestError(messages));
67893
+ import_node_server_utils256.logger.log({ level: "error", message: messages });
67894
+ next(new import_node_server_utils256.BadRequestError(messages));
67703
67895
  return;
67704
67896
  }
67705
67897
  const { site, block } = value;
@@ -67722,7 +67914,7 @@ function useBuildingLevelController() {
67722
67914
  }
67723
67915
 
67724
67916
  // src/models/hid-amico.model.ts
67725
- var import_node_server_utils256 = require("@7365admin1/node-server-utils");
67917
+ var import_node_server_utils257 = require("@7365admin1/node-server-utils");
67726
67918
  var import_mongodb153 = require("mongodb");
67727
67919
  var import_joi150 = __toESM(require("joi"));
67728
67920
  function canReadObjectId(value) {
@@ -67762,7 +67954,7 @@ function toObjectId23(value, label = "ID") {
67762
67954
  return toObjectId23(text, label);
67763
67955
  }
67764
67956
  }
67765
- throw new import_node_server_utils256.BadRequestError(`Invalid ${label} format`);
67957
+ throw new import_node_server_utils257.BadRequestError(`Invalid ${label} format`);
67766
67958
  }
67767
67959
  var objectIdSchema2 = import_joi150.default.custom((value, helpers) => canReadObjectId(value) ? value : helpers.error("any.invalid"), "ObjectId").messages({
67768
67960
  "any.invalid": "{{#label}} must be a valid ObjectId"
@@ -67934,8 +68126,8 @@ var schemaHidAmicoNotificationParams = import_joi150.default.object({
67934
68126
  function MHidAmicoReader(value) {
67935
68127
  const { error } = schemaHidAmicoReader.validate(value);
67936
68128
  if (error) {
67937
- import_node_server_utils256.logger.info(`HID Amico reader: ${error.message}`);
67938
- throw new import_node_server_utils256.BadRequestError(error.message);
68129
+ import_node_server_utils257.logger.info(`HID Amico reader: ${error.message}`);
68130
+ throw new import_node_server_utils257.BadRequestError(error.message);
67939
68131
  }
67940
68132
  return {
67941
68133
  _id: value._id ? toObjectId23(value._id, "reader ID") : new import_mongodb153.ObjectId(),
@@ -67961,8 +68153,8 @@ function MHidAmicoReader(value) {
67961
68153
  function MHidAmicoEvent(value) {
67962
68154
  const { error } = schemaHidAmicoEvent.validate(value);
67963
68155
  if (error) {
67964
- import_node_server_utils256.logger.info(`HID Amico event: ${error.message}`);
67965
- throw new import_node_server_utils256.BadRequestError(error.message);
68156
+ import_node_server_utils257.logger.info(`HID Amico event: ${error.message}`);
68157
+ throw new import_node_server_utils257.BadRequestError(error.message);
67966
68158
  }
67967
68159
  return {
67968
68160
  _id: value._id ? toObjectId23(value._id, "event ID") : new import_mongodb153.ObjectId(),
@@ -67980,8 +68172,8 @@ function optionalObjectId(value) {
67980
68172
  function MHidAmicoIdentity(value) {
67981
68173
  const { error } = schemaHidAmicoIdentity.validate(value);
67982
68174
  if (error) {
67983
- import_node_server_utils256.logger.info(`HID Amico identity: ${error.message}`);
67984
- throw new import_node_server_utils256.BadRequestError(error.message);
68175
+ import_node_server_utils257.logger.info(`HID Amico identity: ${error.message}`);
68176
+ throw new import_node_server_utils257.BadRequestError(error.message);
67985
68177
  }
67986
68178
  return {
67987
68179
  _id: value._id ? toObjectId23(value._id, "identity ID") : new import_mongodb153.ObjectId(),
@@ -68004,13 +68196,13 @@ function MHidAmicoIdentity(value) {
68004
68196
  }
68005
68197
 
68006
68198
  // src/repositories/hid-amico.repo.ts
68007
- var import_node_server_utils257 = require("@7365admin1/node-server-utils");
68199
+ var import_node_server_utils258 = require("@7365admin1/node-server-utils");
68008
68200
  var import_mongodb154 = require("mongodb");
68009
68201
  function useHidAmicoRepo() {
68010
68202
  function db() {
68011
- const instance = import_node_server_utils257.useAtlas.getDb();
68203
+ const instance = import_node_server_utils258.useAtlas.getDb();
68012
68204
  if (!instance) {
68013
- throw new import_node_server_utils257.InternalServerError("Unable to connect to server.");
68205
+ throw new import_node_server_utils258.InternalServerError("Unable to connect to server.");
68014
68206
  }
68015
68207
  return instance;
68016
68208
  }
@@ -68027,7 +68219,7 @@ function useHidAmicoRepo() {
68027
68219
  try {
68028
68220
  return new import_mongodb154.ObjectId(id);
68029
68221
  } catch {
68030
- throw new import_node_server_utils257.BadRequestError(`Invalid ${label} format`);
68222
+ throw new import_node_server_utils258.BadRequestError(`Invalid ${label} format`);
68031
68223
  }
68032
68224
  }
68033
68225
  function hideSecret(reader) {
@@ -68078,7 +68270,7 @@ function useHidAmicoRepo() {
68078
68270
  ]);
68079
68271
  return "HID Amico indexes created.";
68080
68272
  } catch (error) {
68081
- import_node_server_utils257.logger.error(error.message);
68273
+ import_node_server_utils258.logger.error(error.message);
68082
68274
  throw new Error("Failed to create HID Amico indexes.");
68083
68275
  }
68084
68276
  }
@@ -68089,7 +68281,7 @@ function useHidAmicoRepo() {
68089
68281
  return hideSecret(doc);
68090
68282
  } catch (error) {
68091
68283
  if (error.message?.includes("duplicate")) {
68092
- throw new import_node_server_utils257.BadRequestError("HID Amico reader already exists for this site and URL.");
68284
+ throw new import_node_server_utils258.BadRequestError("HID Amico reader already exists for this site and URL.");
68093
68285
  }
68094
68286
  throw error;
68095
68287
  }
@@ -68103,7 +68295,7 @@ function useHidAmicoRepo() {
68103
68295
  }
68104
68296
  const items = await readers().find(query).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
68105
68297
  const total = await readers().countDocuments(query);
68106
- return (0, import_node_server_utils257.paginate)(items.map(hideSecret), page, limit, total);
68298
+ return (0, import_node_server_utils258.paginate)(items.map(hideSecret), page, limit, total);
68107
68299
  }
68108
68300
  async function getById(id, options = {}) {
68109
68301
  const _id = toId(id, "reader ID");
@@ -68111,14 +68303,14 @@ function useHidAmicoRepo() {
68111
68303
  { _id, status: { $ne: "deleted" } }
68112
68304
  );
68113
68305
  if (!reader) {
68114
- throw new import_node_server_utils257.BadRequestError("HID Amico reader not found.");
68306
+ throw new import_node_server_utils258.BadRequestError("HID Amico reader not found.");
68115
68307
  }
68116
68308
  return options.includePassword ? reader : hideSecret(reader);
68117
68309
  }
68118
68310
  async function updateById(id, value, session) {
68119
68311
  const { error } = schemaUpdateHidAmicoReader.validate(value);
68120
68312
  if (error) {
68121
- throw new import_node_server_utils257.BadRequestError(error.message);
68313
+ throw new import_node_server_utils258.BadRequestError(error.message);
68122
68314
  }
68123
68315
  const _id = toId(id, "reader ID");
68124
68316
  const payload = {
@@ -68137,7 +68329,7 @@ function useHidAmicoRepo() {
68137
68329
  { returnDocument: "after", session }
68138
68330
  );
68139
68331
  if (!updated) {
68140
- throw new import_node_server_utils257.BadRequestError("HID Amico reader not found.");
68332
+ throw new import_node_server_utils258.BadRequestError("HID Amico reader not found.");
68141
68333
  }
68142
68334
  return hideSecret(updated);
68143
68335
  }
@@ -68166,7 +68358,7 @@ function useHidAmicoRepo() {
68166
68358
  }
68167
68359
  const items = await events().find(query).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
68168
68360
  const total = await events().countDocuments(query);
68169
- return (0, import_node_server_utils257.paginate)(items, page, limit, total);
68361
+ return (0, import_node_server_utils258.paginate)(items, page, limit, total);
68170
68362
  }
68171
68363
  async function addIdentity(value, session) {
68172
68364
  try {
@@ -68178,16 +68370,16 @@ function useHidAmicoRepo() {
68178
68370
  cardNo: identity.cardNo
68179
68371
  });
68180
68372
  if (existing) {
68181
- throw new import_node_server_utils257.BadRequestError("HID Amico identity already exists for this reader.");
68373
+ throw new import_node_server_utils258.BadRequestError("HID Amico identity already exists for this reader.");
68182
68374
  }
68183
68375
  await identities().insertOne(identity, { session });
68184
68376
  return identity;
68185
68377
  } catch (error) {
68186
- if (error instanceof import_node_server_utils257.BadRequestError) {
68378
+ if (error instanceof import_node_server_utils258.BadRequestError) {
68187
68379
  throw error;
68188
68380
  }
68189
68381
  if (error.message?.includes("duplicate")) {
68190
- throw new import_node_server_utils257.BadRequestError("HID Amico identity already exists for this reader.");
68382
+ throw new import_node_server_utils258.BadRequestError("HID Amico identity already exists for this reader.");
68191
68383
  }
68192
68384
  throw error;
68193
68385
  }
@@ -68212,12 +68404,12 @@ function useHidAmicoRepo() {
68212
68404
  }
68213
68405
  const items = await identities().find(query).sort({ createdAt: -1 }).skip(page * limit).limit(limit).toArray();
68214
68406
  const total = await identities().countDocuments(query);
68215
- return (0, import_node_server_utils257.paginate)(items, page, limit, total);
68407
+ return (0, import_node_server_utils258.paginate)(items, page, limit, total);
68216
68408
  }
68217
68409
  async function updateIdentity(id, value, session) {
68218
68410
  const { error } = schemaUpdateHidAmicoIdentity.validate(value);
68219
68411
  if (error) {
68220
- throw new import_node_server_utils257.BadRequestError(error.message);
68412
+ throw new import_node_server_utils258.BadRequestError(error.message);
68221
68413
  }
68222
68414
  const payload = {
68223
68415
  ...value,
@@ -68245,7 +68437,7 @@ function useHidAmicoRepo() {
68245
68437
  { returnDocument: "after", session }
68246
68438
  );
68247
68439
  if (!updated) {
68248
- throw new import_node_server_utils257.BadRequestError("HID Amico identity not found.");
68440
+ throw new import_node_server_utils258.BadRequestError("HID Amico identity not found.");
68249
68441
  }
68250
68442
  return updated;
68251
68443
  }
@@ -68302,7 +68494,7 @@ function useHidAmicoRepo() {
68302
68494
  // src/services/hid-amico.service.ts
68303
68495
  var import_crypto3 = __toESM(require("crypto"));
68304
68496
  var import_axios4 = __toESM(require("axios"));
68305
- var import_node_server_utils258 = require("@7365admin1/node-server-utils");
68497
+ var import_node_server_utils259 = require("@7365admin1/node-server-utils");
68306
68498
  var PASSWORD_PREFIX = "v1";
68307
68499
  function getSecretKey() {
68308
68500
  const secret = process.env.HID_AMICO_SECRET || process.env.ACCESS_TOKEN_SECRET || "iservice365-hid-amico";
@@ -68346,7 +68538,7 @@ function toHidRequestError(error, path5) {
68346
68538
  status ? `status ${status}` : "",
68347
68539
  payload ? `response ${payload}` : error.message
68348
68540
  ].filter(Boolean).join(" - ");
68349
- return new import_node_server_utils258.BadRequestError(detail);
68541
+ return new import_node_server_utils259.BadRequestError(detail);
68350
68542
  }
68351
68543
  return error;
68352
68544
  }
@@ -68388,7 +68580,7 @@ var HidAmicoClient = class {
68388
68580
  password: decryptSecret(this.reader.password)
68389
68581
  });
68390
68582
  if (!res.data?.session) {
68391
- throw new import_node_server_utils258.BadRequestError("HID Amico login failed: missing session.");
68583
+ throw new import_node_server_utils259.BadRequestError("HID Amico login failed: missing session.");
68392
68584
  }
68393
68585
  this.session = res.data.session;
68394
68586
  return this.session;
@@ -68412,7 +68604,7 @@ var HidAmicoClient = class {
68412
68604
  const payload = JSON.parse(buffer.toString("utf8"));
68413
68605
  const image = payload.image || payload.photo || payload.data?.image || payload.data?.photo;
68414
68606
  if (!image) {
68415
- throw new import_node_server_utils258.BadRequestError("HID Amico user image response did not include an image.");
68607
+ throw new import_node_server_utils259.BadRequestError("HID Amico user image response did not include an image.");
68416
68608
  }
68417
68609
  return {
68418
68610
  contentType: payload.contentType || payload.mimeType || "image/jpeg",
@@ -68537,7 +68729,7 @@ function useHidAmicoService() {
68537
68729
  async function getActiveReader(id) {
68538
68730
  const reader = await repo.getById(id, { includePassword: true });
68539
68731
  if (reader.enabled === false || reader.status === "inactive" || reader.status === "deleted") {
68540
- throw new import_node_server_utils258.BadRequestError("HID Amico reader is not active.");
68732
+ throw new import_node_server_utils259.BadRequestError("HID Amico reader is not active.");
68541
68733
  }
68542
68734
  return reader;
68543
68735
  }
@@ -68792,13 +68984,13 @@ function useHidAmicoService() {
68792
68984
  }
68793
68985
 
68794
68986
  // src/controllers/hid-amico.controller.ts
68795
- var import_node_server_utils259 = require("@7365admin1/node-server-utils");
68987
+ var import_node_server_utils260 = require("@7365admin1/node-server-utils");
68796
68988
  function useHidAmicoController() {
68797
68989
  const service = useHidAmicoService();
68798
68990
  async function listReaders(req, res, next) {
68799
68991
  const { error, value } = schemaHidAmicoReaderListQuery.validate(req.query);
68800
68992
  if (error) {
68801
- next(new import_node_server_utils259.BadRequestError(error.message));
68993
+ next(new import_node_server_utils260.BadRequestError(error.message));
68802
68994
  return;
68803
68995
  }
68804
68996
  try {
@@ -68810,7 +69002,7 @@ function useHidAmicoController() {
68810
69002
  async function createReader(req, res, next) {
68811
69003
  const { error, value } = schemaHidAmicoReader.validate(req.body);
68812
69004
  if (error) {
68813
- next(new import_node_server_utils259.BadRequestError(error.message));
69005
+ next(new import_node_server_utils260.BadRequestError(error.message));
68814
69006
  return;
68815
69007
  }
68816
69008
  try {
@@ -68823,7 +69015,7 @@ function useHidAmicoController() {
68823
69015
  const params = schemaHidAmicoReaderIdParams.validate(req.params);
68824
69016
  const body = schemaUpdateHidAmicoReader.validate(req.body);
68825
69017
  if (params.error || body.error) {
68826
- next(new import_node_server_utils259.BadRequestError(params.error?.message || body.error?.message));
69018
+ next(new import_node_server_utils260.BadRequestError(params.error?.message || body.error?.message));
68827
69019
  return;
68828
69020
  }
68829
69021
  try {
@@ -68835,7 +69027,7 @@ function useHidAmicoController() {
68835
69027
  async function deleteReader(req, res, next) {
68836
69028
  const { error, value } = schemaHidAmicoReaderIdParams.validate(req.params);
68837
69029
  if (error) {
68838
- next(new import_node_server_utils259.BadRequestError(error.message));
69030
+ next(new import_node_server_utils260.BadRequestError(error.message));
68839
69031
  return;
68840
69032
  }
68841
69033
  try {
@@ -68847,7 +69039,7 @@ function useHidAmicoController() {
68847
69039
  async function testReader(req, res, next) {
68848
69040
  const { error, value } = schemaHidAmicoReaderIdParams.validate(req.params);
68849
69041
  if (error) {
68850
- next(new import_node_server_utils259.BadRequestError(error.message));
69042
+ next(new import_node_server_utils260.BadRequestError(error.message));
68851
69043
  return;
68852
69044
  }
68853
69045
  try {
@@ -68860,7 +69052,7 @@ function useHidAmicoController() {
68860
69052
  const params = schemaHidAmicoReaderIdParams.validate(req.params);
68861
69053
  const body = schemaHidAmicoSync.validate(req.body ?? {});
68862
69054
  if (params.error || body.error) {
68863
- next(new import_node_server_utils259.BadRequestError(params.error?.message || body.error?.message));
69055
+ next(new import_node_server_utils260.BadRequestError(params.error?.message || body.error?.message));
68864
69056
  return;
68865
69057
  }
68866
69058
  try {
@@ -68873,7 +69065,7 @@ function useHidAmicoController() {
68873
69065
  const params = schemaHidAmicoReaderIdParams.validate(req.params);
68874
69066
  const query = schemaHidAmicoLogQuery.validate(req.query);
68875
69067
  if (params.error || query.error) {
68876
- next(new import_node_server_utils259.BadRequestError(params.error?.message || query.error?.message));
69068
+ next(new import_node_server_utils260.BadRequestError(params.error?.message || query.error?.message));
68877
69069
  return;
68878
69070
  }
68879
69071
  try {
@@ -68886,7 +69078,7 @@ function useHidAmicoController() {
68886
69078
  const params = schemaHidAmicoReaderIdParams.validate(req.params);
68887
69079
  const query = schemaHidAmicoIdentityQuery.validate(req.query);
68888
69080
  if (params.error || query.error) {
68889
- next(new import_node_server_utils259.BadRequestError(params.error?.message || query.error?.message));
69081
+ next(new import_node_server_utils260.BadRequestError(params.error?.message || query.error?.message));
68890
69082
  return;
68891
69083
  }
68892
69084
  try {
@@ -68898,13 +69090,13 @@ function useHidAmicoController() {
68898
69090
  async function createIdentity(req, res, next) {
68899
69091
  const params = schemaHidAmicoReaderIdParams.validate(req.params);
68900
69092
  if (params.error) {
68901
- next(new import_node_server_utils259.BadRequestError(params.error.message));
69093
+ next(new import_node_server_utils260.BadRequestError(params.error.message));
68902
69094
  return;
68903
69095
  }
68904
69096
  try {
68905
69097
  const body = schemaCreateHidAmicoIdentity.validate(req.body);
68906
69098
  if (body.error) {
68907
- next(new import_node_server_utils259.BadRequestError(body.error.message));
69099
+ next(new import_node_server_utils260.BadRequestError(body.error.message));
68908
69100
  return;
68909
69101
  }
68910
69102
  res.status(201).json({ data: await service.createIdentity(params.value.readerId, body.value) });
@@ -68916,7 +69108,7 @@ function useHidAmicoController() {
68916
69108
  const params = schemaHidAmicoIdentityIdParams.validate(req.params);
68917
69109
  const body = schemaUpdateHidAmicoIdentity.validate(req.body ?? {});
68918
69110
  if (params.error || body.error) {
68919
- next(new import_node_server_utils259.BadRequestError(params.error?.message || body.error?.message));
69111
+ next(new import_node_server_utils260.BadRequestError(params.error?.message || body.error?.message));
68920
69112
  return;
68921
69113
  }
68922
69114
  try {
@@ -68928,7 +69120,7 @@ function useHidAmicoController() {
68928
69120
  async function deleteIdentity(req, res, next) {
68929
69121
  const { error, value } = schemaHidAmicoIdentityIdParams.validate(req.params);
68930
69122
  if (error) {
68931
- next(new import_node_server_utils259.BadRequestError(error.message));
69123
+ next(new import_node_server_utils260.BadRequestError(error.message));
68932
69124
  return;
68933
69125
  }
68934
69126
  try {
@@ -68940,7 +69132,7 @@ function useHidAmicoController() {
68940
69132
  async function receiveNotification(req, res, next) {
68941
69133
  const validation = schemaHidAmicoNotificationParams.validate(req.params);
68942
69134
  if (validation.error) {
68943
- next(new import_node_server_utils259.BadRequestError(validation.error.message));
69135
+ next(new import_node_server_utils260.BadRequestError(validation.error.message));
68944
69136
  return;
68945
69137
  }
68946
69138
  try {
@@ -68957,7 +69149,7 @@ function useHidAmicoController() {
68957
69149
  async function getDoorState(req, res, next) {
68958
69150
  const { error, value } = schemaHidAmicoReaderIdParams.validate(req.params);
68959
69151
  if (error) {
68960
- next(new import_node_server_utils259.BadRequestError(error.message));
69152
+ next(new import_node_server_utils260.BadRequestError(error.message));
68961
69153
  return;
68962
69154
  }
68963
69155
  try {
@@ -68969,7 +69161,7 @@ function useHidAmicoController() {
68969
69161
  async function getUserImage(req, res, next) {
68970
69162
  const { error, value } = schemaHidAmicoUserImageParams.validate(req.params);
68971
69163
  if (error) {
68972
- next(new import_node_server_utils259.BadRequestError(error.message));
69164
+ next(new import_node_server_utils260.BadRequestError(error.message));
68973
69165
  return;
68974
69166
  }
68975
69167
  try {
@@ -68983,7 +69175,7 @@ function useHidAmicoController() {
68983
69175
  const params = schemaHidAmicoReaderIdParams.validate(req.params);
68984
69176
  const body = schemaHidAmicoExecuteActions.validate(req.body ?? {});
68985
69177
  if (params.error || body.error) {
68986
- next(new import_node_server_utils259.BadRequestError(params.error?.message || body.error?.message));
69178
+ next(new import_node_server_utils260.BadRequestError(params.error?.message || body.error?.message));
68987
69179
  return;
68988
69180
  }
68989
69181
  try {
@@ -68996,7 +69188,7 @@ function useHidAmicoController() {
68996
69188
  const params = schemaHidAmicoReaderIdParams.validate(req.params);
68997
69189
  const body = schemaHidAmicoConfiguration.validate(req.body ?? {});
68998
69190
  if (params.error || body.error) {
68999
- next(new import_node_server_utils259.BadRequestError(params.error?.message || body.error?.message));
69191
+ next(new import_node_server_utils260.BadRequestError(params.error?.message || body.error?.message));
69000
69192
  return;
69001
69193
  }
69002
69194
  try {
@@ -69009,7 +69201,7 @@ function useHidAmicoController() {
69009
69201
  const params = schemaHidAmicoReaderIdParams.validate(req.params);
69010
69202
  const body = schemaHidAmicoSetConfiguration.validate(req.body ?? {});
69011
69203
  if (params.error || body.error) {
69012
- next(new import_node_server_utils259.BadRequestError(params.error?.message || body.error?.message));
69204
+ next(new import_node_server_utils260.BadRequestError(params.error?.message || body.error?.message));
69013
69205
  return;
69014
69206
  }
69015
69207
  try {
@@ -69022,20 +69214,20 @@ function useHidAmicoController() {
69022
69214
  const params = schemaHidAmicoReaderIdParams.validate(req.params);
69023
69215
  const body = schemaHidAmicoObjectOperation.validate(req.body ?? {});
69024
69216
  if (params.error || body.error) {
69025
- next(new import_node_server_utils259.BadRequestError(params.error?.message || body.error?.message));
69217
+ next(new import_node_server_utils260.BadRequestError(params.error?.message || body.error?.message));
69026
69218
  return;
69027
69219
  }
69028
69220
  const { operation, ...payload } = body.value;
69029
69221
  if (operation === "create" && !Array.isArray(payload.values)) {
69030
- next(new import_node_server_utils259.BadRequestError("values array is required for HID object create operations."));
69222
+ next(new import_node_server_utils260.BadRequestError("values array is required for HID object create operations."));
69031
69223
  return;
69032
69224
  }
69033
69225
  if (operation === "modify" && (!payload.values || Array.isArray(payload.values) || !payload.where)) {
69034
- next(new import_node_server_utils259.BadRequestError("values object and where are required for HID object modify operations."));
69226
+ next(new import_node_server_utils260.BadRequestError("values object and where are required for HID object modify operations."));
69035
69227
  return;
69036
69228
  }
69037
69229
  if (operation === "destroy" && !payload.where) {
69038
- next(new import_node_server_utils259.BadRequestError("where is required for HID object destroy operations."));
69230
+ next(new import_node_server_utils260.BadRequestError("where is required for HID object destroy operations."));
69039
69231
  return;
69040
69232
  }
69041
69233
  try {