@7365admin1/core 2.43.0 → 2.45.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
@@ -37,6 +37,8 @@ __export(src_exports, {
37
37
  BulletinRecipient: () => BulletinRecipient,
38
38
  BulletinSort: () => BulletinSort,
39
39
  BulletinStatus: () => BulletinStatus,
40
+ BulletinVideoOrder: () => BulletinVideoOrder,
41
+ BulletinVideoSort: () => BulletinVideoSort,
40
42
  CameraType: () => CameraType,
41
43
  DEVICE_STATUS: () => DEVICE_STATUS,
42
44
  DOBStatus: () => DOBStatus,
@@ -44,6 +46,8 @@ __export(src_exports, {
44
46
  EAccessCardTypes: () => EAccessCardTypes,
45
47
  EAccessCardUserTypes: () => EAccessCardUserTypes,
46
48
  EmailSender: () => EmailSender,
49
+ EntryOrder: () => EntryOrder,
50
+ EntrySort: () => EntrySort,
47
51
  FacilitySort: () => FacilitySort,
48
52
  FacilityStatus: () => FacilityStatus,
49
53
  GuestSort: () => GuestSort,
@@ -125,6 +129,8 @@ __export(src_exports, {
125
129
  SortFields: () => SortFields,
126
130
  SortOrder: () => SortOrder,
127
131
  Status: () => Status,
132
+ SubjectOrder: () => SubjectOrder,
133
+ SubjectSort: () => SubjectSort,
128
134
  SubscriptionType: () => SubscriptionType,
129
135
  UseAccessManagementRepo: () => UseAccessManagementRepo,
130
136
  UserStatus: () => UserStatus,
@@ -180,6 +186,7 @@ __export(src_exports, {
180
186
  robotSchema: () => robotSchema,
181
187
  schema: () => schema,
182
188
  schemaApprovedBy: () => schemaApprovedBy,
189
+ schemaApprover: () => schemaApprover,
183
190
  schemaBilling: () => schemaBilling,
184
191
  schemaBillingConfiguration: () => schemaBillingConfiguration,
185
192
  schemaBillingItem: () => schemaBillingItem,
@@ -1832,6 +1839,17 @@ var import_node_server_utils8 = require("@7365admin1/node-server-utils");
1832
1839
  // src/models/occurrence-entry.model.ts
1833
1840
  var import_mongodb6 = require("mongodb");
1834
1841
  var import_joi5 = __toESM(require("joi"));
1842
+ var EntrySort = /* @__PURE__ */ ((EntrySort2) => {
1843
+ EntrySort2["CREATED_AT"] = "createdAt";
1844
+ EntrySort2["NAME"] = "name";
1845
+ EntrySort2["ID"] = "_id";
1846
+ return EntrySort2;
1847
+ })(EntrySort || {});
1848
+ var EntryOrder = /* @__PURE__ */ ((EntryOrder2) => {
1849
+ EntryOrder2["ASC"] = "asc";
1850
+ EntryOrder2["DESC"] = "desc";
1851
+ return EntryOrder2;
1852
+ })(EntryOrder || {});
1835
1853
  var schemaOccurrenceEntry = import_joi5.default.object({
1836
1854
  site: import_joi5.default.string().hex().length(24).required(),
1837
1855
  dailyOccurrenceBookId: import_joi5.default.string().hex().optional().allow(null, ""),
@@ -2996,7 +3014,8 @@ function useUserRepo() {
2996
3014
  "dateOfBirth",
2997
3015
  "profile",
2998
3016
  "gender",
2999
- "defaultOrg"
3017
+ "defaultOrg",
3018
+ "status"
3000
3019
  ];
3001
3020
  if (!allowedFields.includes(field)) {
3002
3021
  throw new import_node_server_utils10.BadRequestError(
@@ -13519,6 +13538,10 @@ var schemaFiles = import_joi35.default.object({
13519
13538
  id: import_joi35.default.string().hex().required(),
13520
13539
  name: import_joi35.default.string().optional().allow(null, "")
13521
13540
  });
13541
+ var schemaApprover = import_joi35.default.object({
13542
+ id: import_joi35.default.string().hex().required(),
13543
+ name: import_joi35.default.string().optional().allow(null, "")
13544
+ });
13522
13545
  var schemaPerson = import_joi35.default.object({
13523
13546
  _id: import_joi35.default.string().hex().optional().allow("", null),
13524
13547
  user: import_joi35.default.string().hex().length(24).optional().allow(null, ""),
@@ -13543,7 +13566,8 @@ var schemaPerson = import_joi35.default.object({
13543
13566
  files: import_joi35.default.array().items(schemaFiles).optional().allow(null),
13544
13567
  password: import_joi35.default.string().optional().allow(null, ""),
13545
13568
  plateNumber: import_joi35.default.string().optional().allow(null, ""),
13546
- platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, "")
13569
+ platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, ""),
13570
+ approvedBy: schemaApprover.optional().allow(null, "")
13547
13571
  });
13548
13572
  var schemaUpdatePerson = import_joi35.default.object({
13549
13573
  _id: import_joi35.default.string().hex().required(),
@@ -13565,7 +13589,8 @@ var schemaUpdatePerson = import_joi35.default.object({
13565
13589
  files: import_joi35.default.array().items(schemaFiles).optional().allow(null),
13566
13590
  password: import_joi35.default.string().optional().allow(null, ""),
13567
13591
  plateNumber: import_joi35.default.string().optional().allow(null, ""),
13568
- platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, "")
13592
+ platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, ""),
13593
+ approvedBy: schemaApprover.optional().allow(null, "")
13569
13594
  });
13570
13595
  function MPerson(value) {
13571
13596
  const { error } = schemaPerson.validate(value);
@@ -13637,6 +13662,7 @@ function MPerson(value) {
13637
13662
  files: value.files ?? [],
13638
13663
  plateNumber: value.plateNumber ?? "",
13639
13664
  platForm: value.platform ?? "",
13665
+ approvedBy: value.approvedBy ?? { id: "", name: "" },
13640
13666
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
13641
13667
  updatedAt: value.updatedAt,
13642
13668
  deletedAt: value.deletedAt
@@ -15827,6 +15853,37 @@ function usePersonRepo() {
15827
15853
  }
15828
15854
  }
15829
15855
  }
15856
+ async function reviewResidentPerson(_id, value, session) {
15857
+ value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
15858
+ try {
15859
+ _id = new import_mongodb44.ObjectId(_id);
15860
+ } catch (error) {
15861
+ throw new import_node_server_utils72.BadRequestError("Invalid ID format.");
15862
+ }
15863
+ try {
15864
+ const res = await collection.updateOne(
15865
+ { _id },
15866
+ { $set: value },
15867
+ { session }
15868
+ );
15869
+ if (res.modifiedCount === 0) {
15870
+ throw new import_node_server_utils72.InternalServerError(`Unable to ${value.status} person.`);
15871
+ }
15872
+ delNamespace().then(() => {
15873
+ import_node_server_utils72.logger.info(
15874
+ `Cache cleared for namespace: ${site_people_namespace_collection}`
15875
+ );
15876
+ }).catch((err) => {
15877
+ import_node_server_utils72.logger.error(
15878
+ `Failed to clear cache for namespace: ${site_people_namespace_collection}`,
15879
+ err
15880
+ );
15881
+ });
15882
+ return res;
15883
+ } catch (error) {
15884
+ throw error;
15885
+ }
15886
+ }
15830
15887
  return {
15831
15888
  add,
15832
15889
  getAll,
@@ -15844,7 +15901,8 @@ function usePersonRepo() {
15844
15901
  getPeopleByNRIC,
15845
15902
  pushVehicleById,
15846
15903
  pullVehicleByRecNo,
15847
- getByUserId
15904
+ getByUserId,
15905
+ reviewResidentPerson
15848
15906
  };
15849
15907
  }
15850
15908
 
@@ -16675,10 +16733,13 @@ function useVehicleService() {
16675
16733
  pullVehicleByRecNo: _pullVehicleByRecNo
16676
16734
  } = usePersonRepo();
16677
16735
  const { getUnitByBlockLevelUnitNumber: _getUnitByBlockLevelUnitNumber } = useBuildingUnitRepo();
16678
- async function add(value) {
16679
- const session = import_node_server_utils75.useAtlas.getClient()?.startSession();
16736
+ async function add(value, session) {
16737
+ const isExternalSession = !!session;
16680
16738
  if (!session) {
16681
- throw new Error("Unable to start session for vehicle service.");
16739
+ session = await import_node_server_utils75.useAtlas.getClient()?.startSession();
16740
+ if (!session) {
16741
+ throw new Error("Unable to start session for vehicle service.");
16742
+ }
16682
16743
  }
16683
16744
  const [_vehiclePlateNumber] = value.plateNumber;
16684
16745
  const [existingPlateNumber, org] = await Promise.all([
@@ -16735,7 +16796,9 @@ function useVehicleService() {
16735
16796
  const owner = value.name;
16736
16797
  const plateNumbers = value.plateNumber;
16737
16798
  try {
16738
- session.startTransaction();
16799
+ if (!isExternalSession) {
16800
+ session.startTransaction();
16801
+ }
16739
16802
  let message = "Vehicle plate number needs approval from property management.";
16740
16803
  let siteCameras = [];
16741
16804
  if (value.status && value.status !== "pending" /* PENDING */) {
@@ -16833,14 +16896,20 @@ function useVehicleService() {
16833
16896
  }
16834
16897
  await _add(vehicleValue, session);
16835
16898
  }
16836
- await session.commitTransaction();
16899
+ if (!isExternalSession) {
16900
+ await session.commitTransaction();
16901
+ }
16837
16902
  return message;
16838
16903
  } catch (error) {
16839
16904
  import_node_server_utils75.logger.error("Error in vehicle service add:", error);
16840
- await session.abortTransaction();
16905
+ if (!isExternalSession) {
16906
+ await session.abortTransaction();
16907
+ }
16841
16908
  throw error;
16842
16909
  } finally {
16843
- session.endSession();
16910
+ if (!isExternalSession) {
16911
+ session.endSession();
16912
+ }
16844
16913
  }
16845
16914
  }
16846
16915
  async function deleteVehicle(_id, recno, site, type, bypass = false) {
@@ -22671,6 +22740,7 @@ function useVisitorTransactionService() {
22671
22740
  const { getAllSites: _getAllSites } = useSiteRepo();
22672
22741
  const { getByUserId: _getByUserId } = usePersonRepo();
22673
22742
  const { add: addVehicle } = useVehicleRepo();
22743
+ const { getById: _getUnitById } = useBuildingUnitRepo();
22674
22744
  function extractKeyId(item) {
22675
22745
  if (!item)
22676
22746
  return null;
@@ -22755,6 +22825,10 @@ function useVisitorTransactionService() {
22755
22825
  _getSiteById(value.site)
22756
22826
  ]);
22757
22827
  }
22828
+ if (!value.unitName && value.unit) {
22829
+ const unit = await _getUnitById(value.unit);
22830
+ value.unitName = unit?.name;
22831
+ }
22758
22832
  const hourExpiration = site?.dahuaTimeExpiration ? site?.dahuaTimeExpiration : 24 * 60;
22759
22833
  const end = value.checkOut ? new Date(value.checkOut) : new Date(start.getTime() + hourExpiration * 60 * 1e3);
22760
22834
  const startDahuaDate = formatDahuaDate(start);
@@ -24009,13 +24083,15 @@ function usePersonService() {
24009
24083
  add: _add,
24010
24084
  getById: _getById,
24011
24085
  updateById: _updateById,
24012
- getByUserId: _getByUserId
24086
+ getByUserId: _getByUserId,
24087
+ reviewResidentPerson: _reviewResidentPerson
24013
24088
  } = usePersonRepo();
24014
24089
  const { addPlateNumber: _addPlateNumber } = useDahuaService();
24015
24090
  const {
24016
24091
  createUser: addUser,
24017
24092
  getUserByEmail,
24018
- updateUserFieldById: _updateUserFieldById
24093
+ updateUserFieldById: _updateUserFieldById,
24094
+ getUserById
24019
24095
  } = useUserRepo();
24020
24096
  const { add: addMember } = useMemberRepo();
24021
24097
  const { getById: _getUnitById, updateById: updateUnitById } = useBuildingUnitRepo();
@@ -24023,6 +24099,7 @@ function usePersonService() {
24023
24099
  const { updateStatusById } = useFileRepo();
24024
24100
  const { getById: getOrgById } = useOrgRepo();
24025
24101
  const { getSiteById } = useSiteRepo();
24102
+ const { add: addVehicle } = useVehicleService();
24026
24103
  async function add(value) {
24027
24104
  const session = import_node_server_utils107.useAtlas.getClient()?.startSession();
24028
24105
  if (!session) {
@@ -24056,7 +24133,7 @@ function usePersonService() {
24056
24133
  email: value.email,
24057
24134
  password: hashedPassword,
24058
24135
  name: value.name,
24059
- status: value.platform == "mobile" ? "deleted" : "active",
24136
+ status: value.platform == "mobile" ? "pending" : "active",
24060
24137
  defaultOrg: value.org?.toString() || ""
24061
24138
  };
24062
24139
  const userId = await addUser(user, session);
@@ -24173,9 +24250,76 @@ function usePersonService() {
24173
24250
  }
24174
24251
  return { start: "", end: "" };
24175
24252
  }
24253
+ async function reviewResidentPerson(id, value) {
24254
+ const session = import_node_server_utils107.useAtlas.getClient()?.startSession();
24255
+ session?.startTransaction();
24256
+ try {
24257
+ const person = await _getById(id.toString());
24258
+ if (!person)
24259
+ throw new import_node_server_utils107.BadRequestError("Person not found.");
24260
+ if (value.approvedBy) {
24261
+ const approvedBy = await getUserById(value.approvedBy.id);
24262
+ if (!approvedBy || !approvedBy.name)
24263
+ throw new import_node_server_utils107.BadRequestError("Created by not found.");
24264
+ value.approvedBy.name = approvedBy.name;
24265
+ value.approvedBy.id = approvedBy._id;
24266
+ }
24267
+ const vehicle = {
24268
+ plateNumber: person.plateNumber || "",
24269
+ type: "whitelist",
24270
+ category: person.type || "",
24271
+ name: person.name,
24272
+ phoneNumber: person.contact,
24273
+ org: person.org.toString(),
24274
+ site: person.site.toString(),
24275
+ block: person.block,
24276
+ level: person.level,
24277
+ unit: person.unit.toString(),
24278
+ nric: person.nric,
24279
+ status: "active",
24280
+ peopleId: person._id?.toString()
24281
+ };
24282
+ const reviewStatus = value.status;
24283
+ if (reviewStatus === "approved") {
24284
+ value.status = "active";
24285
+ }
24286
+ await _reviewResidentPerson(id, value, session);
24287
+ if (person.user) {
24288
+ let userStatus;
24289
+ switch (reviewStatus) {
24290
+ case "approved":
24291
+ userStatus = "active";
24292
+ if (person.plateNumber && person.plateNumber.trim() !== "") {
24293
+ await addVehicle(vehicle, session);
24294
+ }
24295
+ break;
24296
+ case "resubmit":
24297
+ userStatus = "resubmit";
24298
+ break;
24299
+ case "rejected":
24300
+ userStatus = "rejected";
24301
+ break;
24302
+ default:
24303
+ throw new Error("Invalid review status");
24304
+ }
24305
+ await _updateUserFieldById(
24306
+ { _id: person.user.toString(), field: "status", value: userStatus },
24307
+ session
24308
+ );
24309
+ }
24310
+ await session?.commitTransaction();
24311
+ return `Successfully ${reviewStatus} person`;
24312
+ } catch (error) {
24313
+ await session?.abortTransaction();
24314
+ throw error;
24315
+ } finally {
24316
+ session?.endSession();
24317
+ }
24318
+ }
24176
24319
  return {
24177
24320
  add,
24178
- updateById
24321
+ updateById,
24322
+ reviewResidentPerson
24179
24323
  };
24180
24324
  }
24181
24325
 
@@ -24192,7 +24336,11 @@ function usePersonController() {
24192
24336
  getPeopleByNRIC: _getPeopleByNRIC,
24193
24337
  getByUserId: _getByUserId
24194
24338
  } = usePersonRepo();
24195
- const { add: _add, updateById: _updateById } = usePersonService();
24339
+ const {
24340
+ add: _add,
24341
+ updateById: _updateById,
24342
+ reviewResidentPerson: _reviewResidentPerson
24343
+ } = usePersonService();
24196
24344
  async function add(req, res, next) {
24197
24345
  const payload = { ...req.body };
24198
24346
  const { error } = schemaPerson.validate(payload, {
@@ -24507,6 +24655,38 @@ function usePersonController() {
24507
24655
  return;
24508
24656
  }
24509
24657
  }
24658
+ async function reviewResidentPerson(req, res, next) {
24659
+ const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
24660
+ (acc, [key, value]) => ({ ...acc, [key]: value }),
24661
+ {}
24662
+ );
24663
+ req.body.approvedBy = cookies?.["user"] ? cookies["user"].toString() : req.body.approvedBy;
24664
+ const _id = req.params.id;
24665
+ const payload = { _id, ...req.body };
24666
+ const schema2 = import_joi58.default.object({
24667
+ _id: import_joi58.default.string().hex().required(),
24668
+ status: import_joi58.default.string().valid("approved", "rejected", "resubmit").required(),
24669
+ approvedBy: import_joi58.default.string().required(),
24670
+ remarks: import_joi58.default.string().optional().allow("", null)
24671
+ });
24672
+ const { error } = schema2.validate(payload);
24673
+ if (error) {
24674
+ const messages = error.details.map((d) => d.message).join(", ");
24675
+ import_node_server_utils108.logger.log({ level: "error", message: messages });
24676
+ next(new import_node_server_utils108.BadRequestError(messages));
24677
+ return;
24678
+ }
24679
+ try {
24680
+ req.body.approvedBy = { id: req.body.approvedBy, name: "" };
24681
+ const result = await _reviewResidentPerson(_id, req.body);
24682
+ res.status(200).json({ message: result });
24683
+ return;
24684
+ } catch (error2) {
24685
+ import_node_server_utils108.logger.log({ level: "error", message: error2.message });
24686
+ next(error2);
24687
+ return;
24688
+ }
24689
+ }
24510
24690
  return {
24511
24691
  add,
24512
24692
  getAll,
@@ -24518,7 +24698,8 @@ function usePersonController() {
24518
24698
  getCompany,
24519
24699
  getPeopleByPlateNumber,
24520
24700
  getPeopleByNRIC,
24521
- getPersonByUserId
24701
+ getPersonByUserId,
24702
+ reviewResidentPerson
24522
24703
  };
24523
24704
  }
24524
24705
 
@@ -29703,21 +29884,23 @@ function useBulletinBoardController() {
29703
29884
  }
29704
29885
  }
29705
29886
  async function getBulletinBoardById(req, res, next) {
29706
- const validation = import_joi76.default.string().hex().required();
29707
- const _id = req.params.id;
29708
- const { error } = validation.validate(_id);
29709
- if (error) {
29710
- import_node_server_utils137.logger.log({ level: "error", message: error.message });
29711
- next(new import_node_server_utils137.BadRequestError(error.message));
29712
- return;
29713
- }
29714
29887
  try {
29888
+ const schema2 = import_joi76.default.object({
29889
+ _id: import_joi76.default.string().hex().length(24).required()
29890
+ });
29891
+ const { error, value } = schema2.validate({ _id: req.params.id });
29892
+ if (error) {
29893
+ import_node_server_utils137.logger.log({ level: "error", message: error.message });
29894
+ next(new import_node_server_utils137.BadRequestError(error.message));
29895
+ return;
29896
+ }
29897
+ const { _id } = value;
29715
29898
  const data = await _getBulletinBoardById(_id);
29716
29899
  res.status(200).json(data);
29717
29900
  return;
29718
- } catch (error2) {
29719
- import_node_server_utils137.logger.log({ level: "error", message: error2.message });
29720
- next(error2);
29901
+ } catch (error) {
29902
+ import_node_server_utils137.logger.log({ level: "error", message: error.message });
29903
+ next(error);
29721
29904
  return;
29722
29905
  }
29723
29906
  }
@@ -31025,7 +31208,7 @@ var schemaEventManagement = import_joi81.default.object({
31025
31208
  site: import_joi81.default.string().required(),
31026
31209
  title: import_joi81.default.string().required(),
31027
31210
  description: import_joi81.default.string().optional().allow(""),
31028
- dateTime: import_joi81.default.alternatives().try(import_joi81.default.string(), import_joi81.default.date()).required(),
31211
+ dateTime: import_joi81.default.date().iso().required(),
31029
31212
  status: import_joi81.default.string().optional().default("planned"),
31030
31213
  type: import_joi81.default.string().optional().default("TASK")
31031
31214
  });
@@ -31033,7 +31216,7 @@ var schemaUpdateEventManagement = import_joi81.default.object({
31033
31216
  _id: import_joi81.default.string().hex().required(),
31034
31217
  title: import_joi81.default.string().optional().allow(null, ""),
31035
31218
  description: import_joi81.default.string().optional().allow(null, ""),
31036
- dateTime: import_joi81.default.alternatives().try(import_joi81.default.string(), import_joi81.default.date()).optional().allow(null, ""),
31219
+ dateTime: import_joi81.default.date().iso().optional().allow(null, ""),
31037
31220
  status: import_joi81.default.string().optional().allow(null, ""),
31038
31221
  type: import_joi81.default.string().optional().allow(null, "")
31039
31222
  });
@@ -31057,10 +31240,10 @@ function MEventManagement(value) {
31057
31240
  site: value.site,
31058
31241
  title: value.title,
31059
31242
  description: value.description ?? "",
31060
- dateTime: value.dateTime,
31243
+ dateTime: new Date(value.dateTime),
31061
31244
  status: value.status ?? "planned",
31062
31245
  type: value.type ?? "TASK",
31063
- createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
31246
+ createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
31064
31247
  updatedAt: value.updatedAt,
31065
31248
  deletedAt: value.deletedAt
31066
31249
  };
@@ -31238,7 +31421,7 @@ function useEventManagementRepo() {
31238
31421
  }
31239
31422
  }
31240
31423
  async function updateEventManagementById(_id, value, session) {
31241
- value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
31424
+ value.updatedAt = /* @__PURE__ */ new Date();
31242
31425
  try {
31243
31426
  _id = new import_mongodb85.ObjectId(_id);
31244
31427
  } catch (error) {
@@ -31284,8 +31467,7 @@ function useEventManagementRepo() {
31284
31467
  try {
31285
31468
  const updateValue = {
31286
31469
  status: "deleted",
31287
- updatedAt: (/* @__PURE__ */ new Date()).toISOString(),
31288
- deletedAt: (/* @__PURE__ */ new Date()).toISOString()
31470
+ deletedAt: /* @__PURE__ */ new Date()
31289
31471
  };
31290
31472
  const res = await collection.updateOne({ _id }, { $set: updateValue });
31291
31473
  if (res.modifiedCount === 0) {
@@ -31378,7 +31560,12 @@ function useEventManagementService() {
31378
31560
  const session = import_node_server_utils147.useAtlas.getClient()?.startSession();
31379
31561
  session?.startTransaction();
31380
31562
  try {
31381
- await _updateEventManagementById(id, value, session);
31563
+ const updatedValue = {
31564
+ ...value.dateTime && { dateTime: new Date(value.dateTime) },
31565
+ ...value.title && { title: value.title },
31566
+ ...value.description && { description: value.description }
31567
+ };
31568
+ await _updateEventManagementById(id, updatedValue, session);
31382
31569
  await session?.commitTransaction();
31383
31570
  return "Successfully updated event.";
31384
31571
  } catch (error) {
@@ -32808,7 +32995,7 @@ var MAccessCard = class {
32808
32995
  accessType = "Normal" /* NORMAL */,
32809
32996
  cardNo,
32810
32997
  pin,
32811
- qrData,
32998
+ qrData = null,
32812
32999
  startDate,
32813
33000
  endDate,
32814
33001
  isActivated,
@@ -32890,7 +33077,7 @@ var minifyXml = (xml) => {
32890
33077
  };
32891
33078
  var readTemplate = (name, params) => {
32892
33079
  const template = import_fs3.default.readFileSync(
32893
- import_path.default.join(__dirname, `../src/public/xml-templates/${name}.xml`),
33080
+ import_path.default.join(__dirname, `../dist/public/xml-templates/${name}.xml`),
32894
33081
  "utf-8"
32895
33082
  );
32896
33083
  if (!params)
@@ -33141,10 +33328,6 @@ function UseAccessManagementRepo() {
33141
33328
  payload.updatedAt = new Date(payload.updatedAt);
33142
33329
  payload.assignedUnit = payload.unit?.map((id) => new import_mongodb90.ObjectId(id));
33143
33330
  delete payload.unit;
33144
- payload.qrData = await createQrData({
33145
- cardNumber: payload.cardNo,
33146
- facilityCode: parseInt(payload.cardNo.slice(0, 4), 10)
33147
- });
33148
33331
  const accessCardObj = new MAccessCard(payload);
33149
33332
  const result = await collection().insertOne(accessCardObj);
33150
33333
  return result.insertedId;
@@ -33206,10 +33389,6 @@ function UseAccessManagementRepo() {
33206
33389
  cardNo,
33207
33390
  accessType: "Normal" /* NORMAL */,
33208
33391
  pin: "123456",
33209
- qrData: await createQrData({
33210
- cardNumber: cardNo,
33211
- facilityCode: parseInt(cardNo.slice(0, 4), 10)
33212
- }),
33213
33392
  startDate: /* @__PURE__ */ new Date(),
33214
33393
  endDate,
33215
33394
  isActivated: true,
@@ -33259,10 +33438,6 @@ function UseAccessManagementRepo() {
33259
33438
  cardNo,
33260
33439
  accessType: "Normal" /* NORMAL */,
33261
33440
  pin: "123456",
33262
- qrData: await createQrData({
33263
- cardNumber: cardNo,
33264
- facilityCode: parseInt(cardNo.slice(0, 4), 10)
33265
- }),
33266
33441
  startDate: /* @__PURE__ */ new Date(),
33267
33442
  endDate,
33268
33443
  isActivated: true,
@@ -34404,7 +34579,6 @@ function UseAccessManagementRepo() {
34404
34579
  accessType: "Normal" /* NORMAL */,
34405
34580
  cardNo: `${facilityCode}${cardNumber}`,
34406
34581
  pin,
34407
- qrData: await createQrData({ cardNumber: `${facilityCode}${cardNumber}` }),
34408
34582
  startDate: new Date(item["startDate (format MM/DD/YYYY)"]),
34409
34583
  endDate: new Date(item["endDate (format MM/DD/YYYY)"] || endDate),
34410
34584
  isActivated: true,
@@ -37323,6 +37497,17 @@ function useOccurrenceBookController() {
37323
37497
  // src/models/bulletin-video.model.ts
37324
37498
  var import_mongodb95 = require("mongodb");
37325
37499
  var import_joi90 = __toESM(require("joi"));
37500
+ var BulletinVideoSort = /* @__PURE__ */ ((BulletinVideoSort2) => {
37501
+ BulletinVideoSort2["CREATED_AT"] = "createdAt";
37502
+ BulletinVideoSort2["NAME"] = "name";
37503
+ BulletinVideoSort2["ID"] = "_id";
37504
+ return BulletinVideoSort2;
37505
+ })(BulletinVideoSort || {});
37506
+ var BulletinVideoOrder = /* @__PURE__ */ ((BulletinVideoOrder2) => {
37507
+ BulletinVideoOrder2["ASC"] = "asc";
37508
+ BulletinVideoOrder2["DESC"] = "desc";
37509
+ return BulletinVideoOrder2;
37510
+ })(BulletinVideoOrder || {});
37326
37511
  var schemaBulletinVideo = import_joi90.default.object({
37327
37512
  site: import_joi90.default.string().hex().required(),
37328
37513
  title: import_joi90.default.string().optional().allow(null, ""),
@@ -37651,39 +37836,35 @@ function useBulletinVideoController() {
37651
37836
  deleteBulletinVideoById: _deleteBulletinVideoById
37652
37837
  } = useBulletinVideoRepo();
37653
37838
  async function add(req, res, next) {
37654
- const payload = { ...req.body };
37655
- const { error } = schemaBulletinVideo.validate(payload, {
37656
- abortEarly: false
37657
- });
37658
- if (error) {
37659
- const messages = error.details.map((d) => d.message).join(", ");
37660
- import_node_server_utils163.logger.log({ level: "error", message: messages });
37661
- next(new import_node_server_utils163.BadRequestError(messages));
37662
- return;
37663
- }
37664
37839
  try {
37665
- const data = await _add(payload);
37840
+ const { error, value } = schemaBulletinVideo.validate(req.body, {
37841
+ abortEarly: false
37842
+ });
37843
+ if (error) {
37844
+ const messages = error.details.map((d) => d.message).join(", ");
37845
+ import_node_server_utils163.logger.log({ level: "error", message: messages });
37846
+ next(new import_node_server_utils163.BadRequestError(messages));
37847
+ return;
37848
+ }
37849
+ const data = await _add(value);
37666
37850
  res.status(201).json(data);
37667
37851
  return;
37668
- } catch (error2) {
37669
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
37670
- next(error2);
37852
+ } catch (error) {
37853
+ import_node_server_utils163.logger.log({ level: "error", message: error.message });
37854
+ next(error);
37671
37855
  return;
37672
37856
  }
37673
37857
  }
37674
37858
  async function getAll(req, res, next) {
37675
- const allowedFields = ["createdAt", "name"];
37676
- const allowedOrder = ["asc", "desc"];
37677
37859
  const validation = import_joi91.default.object({
37678
37860
  search: import_joi91.default.string().optional().allow("", null),
37679
37861
  page: import_joi91.default.number().integer().min(1).allow("", null).default(1),
37680
37862
  limit: import_joi91.default.number().integer().min(1).max(100).allow("", null).default(10),
37681
- sort: import_joi91.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
37682
- order: import_joi91.default.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
37683
- site: import_joi91.default.string().hex().required()
37863
+ sort: import_joi91.default.string().valid(...Object.values(BulletinVideoSort)).default("_id" /* ID */),
37864
+ order: import_joi91.default.string().valid(...Object.values(BulletinVideoOrder)).default("desc" /* DESC */),
37865
+ site: import_joi91.default.string().hex().length(24).required()
37684
37866
  });
37685
- const query = { ...req.query };
37686
- const { error } = validation.validate(query, {
37867
+ const { error, value } = validation.validate(req.query, {
37687
37868
  abortEarly: false
37688
37869
  });
37689
37870
  if (error) {
@@ -37692,19 +37873,10 @@ function useBulletinVideoController() {
37692
37873
  next(new import_node_server_utils163.BadRequestError(messages));
37693
37874
  return;
37694
37875
  }
37695
- const search = req.query.search ?? "";
37696
- const page = parseInt(req.query.page ?? "1");
37697
- const limit = parseInt(req.query.limit ?? "10");
37698
- const site = req.query.site ?? "";
37699
- const sortObj = {};
37700
- const sortFields = String(req.query.sort).split(",");
37701
- const sortOrders = String(req.query.order).split(",");
37702
- sortFields.forEach((field, index) => {
37703
- if (allowedFields.includes(field)) {
37704
- const order = sortOrders[index] === "asc" ? 1 : -1;
37705
- sortObj[field] = order;
37706
- }
37707
- });
37876
+ const { search, page, limit, site, sort, order } = value;
37877
+ const sortObj = {
37878
+ [sort ?? "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
37879
+ };
37708
37880
  try {
37709
37881
  const data = await _getAll({
37710
37882
  search,
@@ -37722,21 +37894,23 @@ function useBulletinVideoController() {
37722
37894
  }
37723
37895
  }
37724
37896
  async function getBulletinVideoById(req, res, next) {
37725
- const validation = import_joi91.default.string().hex().required();
37726
- const _id = req.params.id;
37727
- const { error } = validation.validate(_id);
37728
- if (error) {
37729
- import_node_server_utils163.logger.log({ level: "error", message: error.message });
37730
- next(new import_node_server_utils163.BadRequestError(error.message));
37731
- return;
37732
- }
37733
37897
  try {
37898
+ const schema2 = import_joi91.default.object({
37899
+ _id: import_joi91.default.string().hex().length(24).required()
37900
+ });
37901
+ const { error, value } = schema2.validate({ _id: req.params.id });
37902
+ if (error) {
37903
+ import_node_server_utils163.logger.log({ level: "error", message: error.message });
37904
+ next(new import_node_server_utils163.BadRequestError(error.message));
37905
+ return;
37906
+ }
37907
+ const { _id } = value;
37734
37908
  const data = await _getBulletinVideoById(_id);
37735
37909
  res.status(200).json(data);
37736
37910
  return;
37737
- } catch (error2) {
37738
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
37739
- next(error2);
37911
+ } catch (error) {
37912
+ import_node_server_utils163.logger.log({ level: "error", message: error.message });
37913
+ next(error);
37740
37914
  return;
37741
37915
  }
37742
37916
  }
@@ -37763,21 +37937,23 @@ function useBulletinVideoController() {
37763
37937
  }
37764
37938
  }
37765
37939
  async function deleteBulletinVideoById(req, res, next) {
37766
- const validation = import_joi91.default.string().hex().required();
37767
- const _id = req.params.id;
37768
- const { error } = validation.validate(_id);
37769
- if (error) {
37770
- import_node_server_utils163.logger.log({ level: "error", message: error.message });
37771
- next(new import_node_server_utils163.BadRequestError(error.message));
37772
- return;
37773
- }
37774
37940
  try {
37941
+ const schema2 = import_joi91.default.object({
37942
+ _id: import_joi91.default.string().hex().length(24).required()
37943
+ });
37944
+ const { error, value } = schema2.validate({ _id: req.params.id });
37945
+ if (error) {
37946
+ import_node_server_utils163.logger.log({ level: "error", message: error.message });
37947
+ next(new import_node_server_utils163.BadRequestError(error.message));
37948
+ return;
37949
+ }
37950
+ const { _id } = value;
37775
37951
  await _deleteBulletinVideoById(_id);
37776
37952
  res.status(200).json({ message: "Successfully deleted bulletin video." });
37777
37953
  return;
37778
- } catch (error2) {
37779
- import_node_server_utils163.logger.log({ level: "error", message: error2.message });
37780
- next(error2);
37954
+ } catch (error) {
37955
+ import_node_server_utils163.logger.log({ level: "error", message: error.message });
37956
+ next(error);
37781
37957
  return;
37782
37958
  }
37783
37959
  }
@@ -41527,6 +41703,17 @@ var import_node_server_utils184 = require("@7365admin1/node-server-utils");
41527
41703
  // src/models/occurrence-subject.model.ts
41528
41704
  var import_mongodb108 = require("mongodb");
41529
41705
  var import_joi103 = __toESM(require("joi"));
41706
+ var SubjectSort = /* @__PURE__ */ ((SubjectSort2) => {
41707
+ SubjectSort2["CREATED_AT"] = "createdAt";
41708
+ SubjectSort2["NAME"] = "name";
41709
+ SubjectSort2["ID"] = "_id";
41710
+ return SubjectSort2;
41711
+ })(SubjectSort || {});
41712
+ var SubjectOrder = /* @__PURE__ */ ((SubjectOrder2) => {
41713
+ SubjectOrder2["ASC"] = "asc";
41714
+ SubjectOrder2["DESC"] = "desc";
41715
+ return SubjectOrder2;
41716
+ })(SubjectOrder || {});
41530
41717
  var schemaOccurrenceSubject = import_joi103.default.object({
41531
41718
  site: import_joi103.default.string().hex().required(),
41532
41719
  subject: import_joi103.default.string().required(),
@@ -41635,7 +41822,8 @@ function useOccurrenceSubjectRepo() {
41635
41822
  }
41636
41823
  const baseQuery = {
41637
41824
  site,
41638
- status: { $ne: "deleted" }
41825
+ status: { $ne: "deleted" },
41826
+ ...search && { $text: { $search: search } }
41639
41827
  };
41640
41828
  let query = { ...baseQuery };
41641
41829
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
@@ -41644,12 +41832,9 @@ function useOccurrenceSubjectRepo() {
41644
41832
  sort: JSON.stringify(sort),
41645
41833
  page,
41646
41834
  limit,
41647
- status: { $ne: "deleted" }
41835
+ status: { $ne: "deleted" },
41836
+ ...search && { search }
41648
41837
  };
41649
- if (search) {
41650
- query.$text = { $search: search };
41651
- cacheOptions.search = search;
41652
- }
41653
41838
  const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, cacheOptions);
41654
41839
  const cachedData = await getCache(cacheKey);
41655
41840
  if (cachedData) {
@@ -41728,11 +41913,22 @@ function useOccurrenceSubjectRepo() {
41728
41913
  } catch (error) {
41729
41914
  throw new import_node_server_utils184.BadRequestError("Invalid occurrence subject ID format.");
41730
41915
  }
41916
+ const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, { _id });
41917
+ const cachedData = await getCache(cacheKey);
41918
+ if (cachedData) {
41919
+ import_node_server_utils184.logger.info(`Cache hit for key: ${cacheKey}`);
41920
+ return cachedData;
41921
+ }
41731
41922
  try {
41732
41923
  const data = await collection.findOne({ _id }, { session });
41733
41924
  if (!data) {
41734
41925
  throw new import_node_server_utils184.NotFoundError("Occurrence subject not found.");
41735
41926
  }
41927
+ setCache(cacheKey, data, 15 * 60).then(() => {
41928
+ import_node_server_utils184.logger.info(`Cache set for key: ${cacheKey}`);
41929
+ }).catch((err) => {
41930
+ import_node_server_utils184.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
41931
+ });
41736
41932
  return data;
41737
41933
  } catch (error) {
41738
41934
  throw error;
@@ -41919,62 +42115,49 @@ function useOccurrenceEntryController() {
41919
42115
  getLatestSerialNumber: _getLatestSerialNumber
41920
42116
  } = useOccurrenceEntryRepo();
41921
42117
  async function add(req, res, next) {
41922
- const { error, value } = schemaOccurrenceEntry.validate(req.body, {
41923
- abortEarly: false
41924
- });
41925
- if (error) {
41926
- const messages = error.details.map((d) => d.message).join(", ");
41927
- import_node_server_utils186.logger.log({ level: "error", message: messages });
41928
- next(new import_node_server_utils186.BadRequestError(messages));
41929
- return;
41930
- }
41931
42118
  try {
42119
+ const { error, value } = schemaOccurrenceEntry.validate(req.body, {
42120
+ abortEarly: false
42121
+ });
42122
+ if (error) {
42123
+ const messages = error.details.map((d) => d.message).join(", ");
42124
+ import_node_server_utils186.logger.log({ level: "error", message: messages });
42125
+ next(new import_node_server_utils186.BadRequestError(messages));
42126
+ return;
42127
+ }
41932
42128
  const data = await _add(value);
41933
42129
  res.status(201).json(data);
41934
42130
  return;
41935
- } catch (error2) {
41936
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
41937
- next(error2);
42131
+ } catch (error) {
42132
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42133
+ next(error);
41938
42134
  return;
41939
42135
  }
41940
42136
  }
41941
42137
  async function getAll(req, res, next) {
41942
- const allowedFields = ["createdAt", "name"];
41943
- const allowedOrder = ["asc", "desc"];
41944
- const validation = import_joi104.default.object({
41945
- search: import_joi104.default.string().optional().allow("", null),
41946
- page: import_joi104.default.number().integer().min(1).allow("", null).default(1),
41947
- limit: import_joi104.default.number().integer().min(1).max(100).allow("", null).default(10),
41948
- sort: import_joi104.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
41949
- order: import_joi104.default.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
41950
- site: import_joi104.default.string().hex().required(),
41951
- dailyOccurrenceBookId: import_joi104.default.string().optional().allow("", null)
41952
- });
41953
- const query = { ...req.query };
41954
- const { error } = validation.validate(query, {
41955
- abortEarly: false
41956
- });
41957
- if (error) {
41958
- const messages = error.details.map((d) => d.message).join(", ");
41959
- import_node_server_utils186.logger.log({ level: "error", message: messages });
41960
- next(new import_node_server_utils186.BadRequestError(messages));
41961
- return;
41962
- }
41963
- const search = req.query.search ?? "";
41964
- const page = parseInt(req.query.page ?? "1");
41965
- const limit = parseInt(req.query.limit ?? "10");
41966
- const site = req.query.site ?? "";
41967
- const dailyOccurrenceBookId = req.query.dailyOccurrenceBookId ?? "";
41968
- const sortObj = {};
41969
- const sortFields = String(req.query.sort).split(",");
41970
- const sortOrders = String(req.query.order).split(",");
41971
- sortFields.forEach((field, index) => {
41972
- if (allowedFields.includes(field)) {
41973
- const order = sortOrders[index] === "asc" ? 1 : -1;
41974
- sortObj[field] = order;
41975
- }
41976
- });
41977
42138
  try {
42139
+ const schema2 = import_joi104.default.object({
42140
+ search: import_joi104.default.string().optional().allow("", null),
42141
+ page: import_joi104.default.number().integer().min(1).allow("", null).default(1),
42142
+ limit: import_joi104.default.number().integer().min(1).max(100).allow("", null).default(10),
42143
+ sort: import_joi104.default.string().valid(...Object.values(EntrySort)).default("_id" /* ID */),
42144
+ order: import_joi104.default.string().valid(...Object.values(EntryOrder)).default("desc" /* DESC */),
42145
+ site: import_joi104.default.string().hex().required(),
42146
+ dailyOccurrenceBookId: import_joi104.default.string().hex().length(24).optional().allow("", null)
42147
+ });
42148
+ const { error, value } = schema2.validate(req.query, {
42149
+ abortEarly: false
42150
+ });
42151
+ if (error) {
42152
+ const messages = error.details.map((d) => d.message).join(", ");
42153
+ import_node_server_utils186.logger.log({ level: "error", message: messages });
42154
+ next(new import_node_server_utils186.BadRequestError(messages));
42155
+ return;
42156
+ }
42157
+ const { search, page, limit, site, dailyOccurrenceBookId, sort, order } = value;
42158
+ const sortObj = {
42159
+ [sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
42160
+ };
41978
42161
  const data = await _getAll({
41979
42162
  search,
41980
42163
  page,
@@ -41985,69 +42168,73 @@ function useOccurrenceEntryController() {
41985
42168
  });
41986
42169
  res.status(200).json(data);
41987
42170
  return;
41988
- } catch (error2) {
41989
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
41990
- next(error2);
42171
+ } catch (error) {
42172
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42173
+ next(error);
41991
42174
  return;
41992
42175
  }
41993
42176
  }
41994
42177
  async function getOccurrenceEntryById(req, res, next) {
41995
- const validation = import_joi104.default.string().hex().required();
41996
- const _id = req.params.id;
41997
- const { error } = validation.validate(_id);
41998
- if (error) {
41999
- import_node_server_utils186.logger.log({ level: "error", message: error.message });
42000
- next(new import_node_server_utils186.BadRequestError(error.message));
42001
- return;
42002
- }
42003
42178
  try {
42179
+ const schema2 = import_joi104.default.object({
42180
+ _id: import_joi104.default.string().hex().length(24).required()
42181
+ });
42182
+ const { error, value } = schema2.validate({ _id: req.params.id });
42183
+ if (error) {
42184
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42185
+ next(new import_node_server_utils186.BadRequestError(error.message));
42186
+ return;
42187
+ }
42188
+ const { _id } = value;
42004
42189
  const data = await _getOccurrenceEntryById(_id);
42005
42190
  res.status(200).json(data);
42006
42191
  return;
42007
- } catch (error2) {
42008
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
42009
- next(error2);
42192
+ } catch (error) {
42193
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42194
+ next(error);
42010
42195
  return;
42011
42196
  }
42012
42197
  }
42013
42198
  async function updateOccurrenceEntryById(req, res, next) {
42014
- const payload = { _id: req.params.id, ...req.body };
42015
- const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
42016
- abortEarly: false
42017
- });
42018
- if (error) {
42019
- const messages = error.details.map((d) => d.message).join(", ");
42020
- import_node_server_utils186.logger.log({ level: "error", message: messages });
42021
- next(new import_node_server_utils186.BadRequestError(messages));
42022
- return;
42023
- }
42024
- const { _id, ...rest } = value;
42025
42199
  try {
42200
+ const payload = { _id: req.params.id, ...req.body };
42201
+ const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
42202
+ abortEarly: false
42203
+ });
42204
+ if (error) {
42205
+ const messages = error.details.map((d) => d.message).join(", ");
42206
+ import_node_server_utils186.logger.log({ level: "error", message: messages });
42207
+ next(new import_node_server_utils186.BadRequestError(messages));
42208
+ return;
42209
+ }
42210
+ const { _id, ...rest } = value;
42026
42211
  const result = await _updateOccurrenceEntryById(_id, rest);
42027
42212
  res.status(200).json({ message: result });
42028
42213
  return;
42029
- } catch (error2) {
42030
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
42031
- next(error2);
42214
+ } catch (error) {
42215
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42216
+ next(error);
42032
42217
  return;
42033
42218
  }
42034
42219
  }
42035
42220
  async function deleteOccurrenceEntryById(req, res, next) {
42036
- const validation = import_joi104.default.string().hex().required();
42037
- const _id = req.params.id;
42038
- const { error } = validation.validate(_id);
42039
- if (error) {
42040
- import_node_server_utils186.logger.log({ level: "error", message: error.message });
42041
- next(new import_node_server_utils186.BadRequestError(error.message));
42042
- return;
42043
- }
42044
42221
  try {
42222
+ const schema2 = import_joi104.default.object({
42223
+ _id: import_joi104.default.string().hex().length(24).required()
42224
+ });
42225
+ const { error, value } = schema2.validate({ _id: req.params.id });
42226
+ if (error) {
42227
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42228
+ next(new import_node_server_utils186.BadRequestError(error.message));
42229
+ return;
42230
+ }
42231
+ const { _id } = value;
42045
42232
  await _deleteOccurrenceEntryById(_id);
42046
42233
  res.status(200).json({ message: "Successfully deleted occurrence entry." });
42047
42234
  return;
42048
- } catch (error2) {
42049
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
42050
- next(error2);
42235
+ } catch (error) {
42236
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42237
+ next(error);
42051
42238
  return;
42052
42239
  }
42053
42240
  }
@@ -42684,61 +42871,48 @@ function useOccurrenceSubjectController() {
42684
42871
  deleteOccurrenceSubjectById: _deleteOccurrenceSubjectById
42685
42872
  } = useOccurrenceSubjectRepo();
42686
42873
  async function add(req, res, next) {
42687
- const payload = { ...req.body };
42688
- const { error } = schemaOccurrenceSubject.validate(payload, {
42689
- abortEarly: false
42690
- });
42691
- if (error) {
42692
- const messages = error.details.map((d) => d.message).join(", ");
42693
- import_node_server_utils190.logger.log({ level: "error", message: messages });
42694
- next(new import_node_server_utils190.BadRequestError(messages));
42695
- return;
42696
- }
42697
42874
  try {
42698
- const data = await _add(payload);
42875
+ const { error, value } = schemaOccurrenceSubject.validate(req.body, {
42876
+ abortEarly: false
42877
+ });
42878
+ if (error) {
42879
+ const messages = error.details.map((d) => d.message).join(", ");
42880
+ import_node_server_utils190.logger.log({ level: "error", message: messages });
42881
+ next(new import_node_server_utils190.BadRequestError(messages));
42882
+ return;
42883
+ }
42884
+ const data = await _add(value);
42699
42885
  res.status(201).json(data);
42700
42886
  return;
42701
- } catch (error2) {
42702
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
42703
- next(error2);
42887
+ } catch (error) {
42888
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42889
+ next(error);
42704
42890
  return;
42705
42891
  }
42706
42892
  }
42707
42893
  async function getAll(req, res, next) {
42708
- const allowedFields = ["createdAt", "name"];
42709
- const allowedOrder = ["asc", "desc"];
42710
- const validation = import_joi107.default.object({
42711
- search: import_joi107.default.string().optional().allow("", null),
42712
- page: import_joi107.default.number().integer().min(1).allow("", null).default(1),
42713
- limit: import_joi107.default.number().integer().min(1).max(100).allow("", null).default(10),
42714
- sort: import_joi107.default.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
42715
- order: import_joi107.default.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
42716
- site: import_joi107.default.string().hex().required()
42717
- });
42718
- const query = { ...req.query };
42719
- const { error } = validation.validate(query, {
42720
- abortEarly: false
42721
- });
42722
- if (error) {
42723
- const messages = error.details.map((d) => d.message).join(", ");
42724
- import_node_server_utils190.logger.log({ level: "error", message: messages });
42725
- next(new import_node_server_utils190.BadRequestError(messages));
42726
- return;
42727
- }
42728
- const search = req.query.search ?? "";
42729
- const page = parseInt(req.query.page ?? "1");
42730
- const limit = parseInt(req.query.limit ?? "10");
42731
- const site = req.query.site ?? "";
42732
- const sortObj = {};
42733
- const sortFields = String(req.query.sort).split(",");
42734
- const sortOrders = String(req.query.order).split(",");
42735
- sortFields.forEach((field, index) => {
42736
- if (allowedFields.includes(field)) {
42737
- const order = sortOrders[index] === "asc" ? 1 : -1;
42738
- sortObj[field] = order;
42739
- }
42740
- });
42741
42894
  try {
42895
+ const validation = import_joi107.default.object({
42896
+ search: import_joi107.default.string().optional().allow("", null),
42897
+ page: import_joi107.default.number().integer().min(1).allow("", null).default(1),
42898
+ limit: import_joi107.default.number().integer().min(1).max(100).allow("", null).default(10),
42899
+ sort: import_joi107.default.string().valid(...Object.values(SubjectSort)).default("_id" /* ID */),
42900
+ order: import_joi107.default.string().valid(...Object.values(SubjectOrder)).default("desc" /* DESC */),
42901
+ site: import_joi107.default.string().hex().length(24).required()
42902
+ });
42903
+ const { error, value } = validation.validate(req.query, {
42904
+ abortEarly: false
42905
+ });
42906
+ if (error) {
42907
+ const messages = error.details.map((d) => d.message).join(", ");
42908
+ import_node_server_utils190.logger.log({ level: "error", message: messages });
42909
+ next(new import_node_server_utils190.BadRequestError(messages));
42910
+ return;
42911
+ }
42912
+ const { search, page, limit, site, sort, order } = value;
42913
+ const sortObj = {
42914
+ [sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
42915
+ };
42742
42916
  const data = await _getAll({
42743
42917
  search,
42744
42918
  page,
@@ -42748,50 +42922,54 @@ function useOccurrenceSubjectController() {
42748
42922
  });
42749
42923
  res.status(200).json(data);
42750
42924
  return;
42751
- } catch (error2) {
42752
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
42753
- next(error2);
42925
+ } catch (error) {
42926
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42927
+ next(error);
42754
42928
  return;
42755
42929
  }
42756
42930
  }
42757
42931
  async function getOccurrenceSubjectById(req, res, next) {
42758
- const validation = import_joi107.default.string().hex().required();
42759
- const _id = req.params.id;
42760
- const { error } = validation.validate(_id);
42761
- if (error) {
42762
- import_node_server_utils190.logger.log({ level: "error", message: error.message });
42763
- next(new import_node_server_utils190.BadRequestError(error.message));
42764
- return;
42765
- }
42766
42932
  try {
42933
+ const schema2 = import_joi107.default.object({
42934
+ _id: import_joi107.default.string().hex().length(24).required()
42935
+ });
42936
+ const { error, value } = schema2.validate({ _id: req.params.id });
42937
+ if (error) {
42938
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42939
+ next(new import_node_server_utils190.BadRequestError(error.message));
42940
+ return;
42941
+ }
42942
+ const { _id } = value;
42767
42943
  const data = await _getOccurrenceSubjectById(_id);
42768
42944
  res.status(200).json(data);
42769
42945
  return;
42770
- } catch (error2) {
42771
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
42772
- next(error2);
42946
+ } catch (error) {
42947
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42948
+ next(error);
42773
42949
  return;
42774
42950
  }
42775
42951
  }
42776
42952
  async function updateOccurrenceSubjectById(req, res, next) {
42777
- const _id = req.params.id;
42778
- const payload = { _id, ...req.body };
42779
- const { error } = schemaUpdateOccurrenceSubject.validate(payload, {
42780
- abortEarly: false
42781
- });
42782
- if (error) {
42783
- const messages = error.details.map((d) => d.message).join(", ");
42784
- import_node_server_utils190.logger.log({ level: "error", message: messages });
42785
- next(new import_node_server_utils190.BadRequestError(messages));
42786
- return;
42787
- }
42788
42953
  try {
42789
- const result = await _updateOccurrenceSubjectById(_id, req.body);
42954
+ const { error, value } = schemaUpdateOccurrenceSubject.validate(
42955
+ { _id: req.params.id, ...req.body },
42956
+ {
42957
+ abortEarly: false
42958
+ }
42959
+ );
42960
+ if (error) {
42961
+ const messages = error.details.map((d) => d.message).join(", ");
42962
+ import_node_server_utils190.logger.log({ level: "error", message: messages });
42963
+ next(new import_node_server_utils190.BadRequestError(messages));
42964
+ return;
42965
+ }
42966
+ const { _id, ...rest } = value;
42967
+ const result = await _updateOccurrenceSubjectById(_id, rest);
42790
42968
  res.status(200).json({ message: result });
42791
42969
  return;
42792
- } catch (error2) {
42793
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
42794
- next(error2);
42970
+ } catch (error) {
42971
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42972
+ next(error);
42795
42973
  return;
42796
42974
  }
42797
42975
  }
@@ -49992,6 +50170,8 @@ function useRoleControllerV2() {
49992
50170
  BulletinRecipient,
49993
50171
  BulletinSort,
49994
50172
  BulletinStatus,
50173
+ BulletinVideoOrder,
50174
+ BulletinVideoSort,
49995
50175
  CameraType,
49996
50176
  DEVICE_STATUS,
49997
50177
  DOBStatus,
@@ -49999,6 +50179,8 @@ function useRoleControllerV2() {
49999
50179
  EAccessCardTypes,
50000
50180
  EAccessCardUserTypes,
50001
50181
  EmailSender,
50182
+ EntryOrder,
50183
+ EntrySort,
50002
50184
  FacilitySort,
50003
50185
  FacilityStatus,
50004
50186
  GuestSort,
@@ -50080,6 +50262,8 @@ function useRoleControllerV2() {
50080
50262
  SortFields,
50081
50263
  SortOrder,
50082
50264
  Status,
50265
+ SubjectOrder,
50266
+ SubjectSort,
50083
50267
  SubscriptionType,
50084
50268
  UseAccessManagementRepo,
50085
50269
  UserStatus,
@@ -50135,6 +50319,7 @@ function useRoleControllerV2() {
50135
50319
  robotSchema,
50136
50320
  schema,
50137
50321
  schemaApprovedBy,
50322
+ schemaApprover,
50138
50323
  schemaBilling,
50139
50324
  schemaBillingConfiguration,
50140
50325
  schemaBillingItem,