@7365admin1/core 2.43.0 → 2.44.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
@@ -44,6 +44,8 @@ __export(src_exports, {
44
44
  EAccessCardTypes: () => EAccessCardTypes,
45
45
  EAccessCardUserTypes: () => EAccessCardUserTypes,
46
46
  EmailSender: () => EmailSender,
47
+ EntryOrder: () => EntryOrder,
48
+ EntrySort: () => EntrySort,
47
49
  FacilitySort: () => FacilitySort,
48
50
  FacilityStatus: () => FacilityStatus,
49
51
  GuestSort: () => GuestSort,
@@ -125,6 +127,8 @@ __export(src_exports, {
125
127
  SortFields: () => SortFields,
126
128
  SortOrder: () => SortOrder,
127
129
  Status: () => Status,
130
+ SubjectOrder: () => SubjectOrder,
131
+ SubjectSort: () => SubjectSort,
128
132
  SubscriptionType: () => SubscriptionType,
129
133
  UseAccessManagementRepo: () => UseAccessManagementRepo,
130
134
  UserStatus: () => UserStatus,
@@ -180,6 +184,7 @@ __export(src_exports, {
180
184
  robotSchema: () => robotSchema,
181
185
  schema: () => schema,
182
186
  schemaApprovedBy: () => schemaApprovedBy,
187
+ schemaApprover: () => schemaApprover,
183
188
  schemaBilling: () => schemaBilling,
184
189
  schemaBillingConfiguration: () => schemaBillingConfiguration,
185
190
  schemaBillingItem: () => schemaBillingItem,
@@ -1832,6 +1837,17 @@ var import_node_server_utils8 = require("@7365admin1/node-server-utils");
1832
1837
  // src/models/occurrence-entry.model.ts
1833
1838
  var import_mongodb6 = require("mongodb");
1834
1839
  var import_joi5 = __toESM(require("joi"));
1840
+ var EntrySort = /* @__PURE__ */ ((EntrySort2) => {
1841
+ EntrySort2["CREATED_AT"] = "createdAt";
1842
+ EntrySort2["NAME"] = "name";
1843
+ EntrySort2["ID"] = "_id";
1844
+ return EntrySort2;
1845
+ })(EntrySort || {});
1846
+ var EntryOrder = /* @__PURE__ */ ((EntryOrder2) => {
1847
+ EntryOrder2["ASC"] = "asc";
1848
+ EntryOrder2["DESC"] = "desc";
1849
+ return EntryOrder2;
1850
+ })(EntryOrder || {});
1835
1851
  var schemaOccurrenceEntry = import_joi5.default.object({
1836
1852
  site: import_joi5.default.string().hex().length(24).required(),
1837
1853
  dailyOccurrenceBookId: import_joi5.default.string().hex().optional().allow(null, ""),
@@ -13519,6 +13535,10 @@ var schemaFiles = import_joi35.default.object({
13519
13535
  id: import_joi35.default.string().hex().required(),
13520
13536
  name: import_joi35.default.string().optional().allow(null, "")
13521
13537
  });
13538
+ var schemaApprover = import_joi35.default.object({
13539
+ id: import_joi35.default.string().hex().required(),
13540
+ name: import_joi35.default.string().optional().allow(null, "")
13541
+ });
13522
13542
  var schemaPerson = import_joi35.default.object({
13523
13543
  _id: import_joi35.default.string().hex().optional().allow("", null),
13524
13544
  user: import_joi35.default.string().hex().length(24).optional().allow(null, ""),
@@ -13543,7 +13563,8 @@ var schemaPerson = import_joi35.default.object({
13543
13563
  files: import_joi35.default.array().items(schemaFiles).optional().allow(null),
13544
13564
  password: import_joi35.default.string().optional().allow(null, ""),
13545
13565
  plateNumber: import_joi35.default.string().optional().allow(null, ""),
13546
- platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, "")
13566
+ platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, ""),
13567
+ approvedBy: schemaApprover.optional().allow(null, "")
13547
13568
  });
13548
13569
  var schemaUpdatePerson = import_joi35.default.object({
13549
13570
  _id: import_joi35.default.string().hex().required(),
@@ -13565,7 +13586,8 @@ var schemaUpdatePerson = import_joi35.default.object({
13565
13586
  files: import_joi35.default.array().items(schemaFiles).optional().allow(null),
13566
13587
  password: import_joi35.default.string().optional().allow(null, ""),
13567
13588
  plateNumber: import_joi35.default.string().optional().allow(null, ""),
13568
- platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, "")
13589
+ platform: import_joi35.default.string().valid("web", "mobile").optional().allow(null, ""),
13590
+ approvedBy: schemaApprover.optional().allow(null, "")
13569
13591
  });
13570
13592
  function MPerson(value) {
13571
13593
  const { error } = schemaPerson.validate(value);
@@ -13637,6 +13659,7 @@ function MPerson(value) {
13637
13659
  files: value.files ?? [],
13638
13660
  plateNumber: value.plateNumber ?? "",
13639
13661
  platForm: value.platform ?? "",
13662
+ approvedBy: value.approvedBy ?? { id: "", name: "" },
13640
13663
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
13641
13664
  updatedAt: value.updatedAt,
13642
13665
  deletedAt: value.deletedAt
@@ -15827,6 +15850,37 @@ function usePersonRepo() {
15827
15850
  }
15828
15851
  }
15829
15852
  }
15853
+ async function reviewResidentPerson(_id, value, session) {
15854
+ value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
15855
+ try {
15856
+ _id = new import_mongodb44.ObjectId(_id);
15857
+ } catch (error) {
15858
+ throw new import_node_server_utils72.BadRequestError("Invalid ID format.");
15859
+ }
15860
+ try {
15861
+ const res = await collection.updateOne(
15862
+ { _id },
15863
+ { $set: value },
15864
+ { session }
15865
+ );
15866
+ if (res.modifiedCount === 0) {
15867
+ throw new import_node_server_utils72.InternalServerError(`Unable to ${value.status} person.`);
15868
+ }
15869
+ delNamespace().then(() => {
15870
+ import_node_server_utils72.logger.info(
15871
+ `Cache cleared for namespace: ${site_people_namespace_collection}`
15872
+ );
15873
+ }).catch((err) => {
15874
+ import_node_server_utils72.logger.error(
15875
+ `Failed to clear cache for namespace: ${site_people_namespace_collection}`,
15876
+ err
15877
+ );
15878
+ });
15879
+ return res;
15880
+ } catch (error) {
15881
+ throw error;
15882
+ }
15883
+ }
15830
15884
  return {
15831
15885
  add,
15832
15886
  getAll,
@@ -15844,7 +15898,8 @@ function usePersonRepo() {
15844
15898
  getPeopleByNRIC,
15845
15899
  pushVehicleById,
15846
15900
  pullVehicleByRecNo,
15847
- getByUserId
15901
+ getByUserId,
15902
+ reviewResidentPerson
15848
15903
  };
15849
15904
  }
15850
15905
 
@@ -22671,6 +22726,7 @@ function useVisitorTransactionService() {
22671
22726
  const { getAllSites: _getAllSites } = useSiteRepo();
22672
22727
  const { getByUserId: _getByUserId } = usePersonRepo();
22673
22728
  const { add: addVehicle } = useVehicleRepo();
22729
+ const { getById: _getUnitById } = useBuildingUnitRepo();
22674
22730
  function extractKeyId(item) {
22675
22731
  if (!item)
22676
22732
  return null;
@@ -22755,6 +22811,10 @@ function useVisitorTransactionService() {
22755
22811
  _getSiteById(value.site)
22756
22812
  ]);
22757
22813
  }
22814
+ if (!value.unitName && value.unit) {
22815
+ const unit = await _getUnitById(value.unit);
22816
+ value.unitName = unit?.name;
22817
+ }
22758
22818
  const hourExpiration = site?.dahuaTimeExpiration ? site?.dahuaTimeExpiration : 24 * 60;
22759
22819
  const end = value.checkOut ? new Date(value.checkOut) : new Date(start.getTime() + hourExpiration * 60 * 1e3);
22760
22820
  const startDahuaDate = formatDahuaDate(start);
@@ -24009,13 +24069,15 @@ function usePersonService() {
24009
24069
  add: _add,
24010
24070
  getById: _getById,
24011
24071
  updateById: _updateById,
24012
- getByUserId: _getByUserId
24072
+ getByUserId: _getByUserId,
24073
+ reviewResidentPerson: _reviewResidentPerson
24013
24074
  } = usePersonRepo();
24014
24075
  const { addPlateNumber: _addPlateNumber } = useDahuaService();
24015
24076
  const {
24016
24077
  createUser: addUser,
24017
24078
  getUserByEmail,
24018
- updateUserFieldById: _updateUserFieldById
24079
+ updateUserFieldById: _updateUserFieldById,
24080
+ getUserById
24019
24081
  } = useUserRepo();
24020
24082
  const { add: addMember } = useMemberRepo();
24021
24083
  const { getById: _getUnitById, updateById: updateUnitById } = useBuildingUnitRepo();
@@ -24173,9 +24235,31 @@ function usePersonService() {
24173
24235
  }
24174
24236
  return { start: "", end: "" };
24175
24237
  }
24238
+ async function reviewResidentPerson(id, value) {
24239
+ const session = import_node_server_utils107.useAtlas.getClient()?.startSession();
24240
+ session?.startTransaction();
24241
+ try {
24242
+ if (value.approvedBy) {
24243
+ const approvedBy = await getUserById(value.approvedBy.id);
24244
+ if (!approvedBy || !approvedBy.name)
24245
+ throw new import_node_server_utils107.BadRequestError("Created by not found.");
24246
+ value.approvedBy.name = approvedBy.name;
24247
+ value.approvedBy.id = approvedBy._id;
24248
+ }
24249
+ await _reviewResidentPerson(id, value, session);
24250
+ await session?.commitTransaction();
24251
+ return `Successfully ${value.status} person`;
24252
+ } catch (error) {
24253
+ await session?.abortTransaction();
24254
+ throw error;
24255
+ } finally {
24256
+ session?.endSession();
24257
+ }
24258
+ }
24176
24259
  return {
24177
24260
  add,
24178
- updateById
24261
+ updateById,
24262
+ reviewResidentPerson
24179
24263
  };
24180
24264
  }
24181
24265
 
@@ -24192,7 +24276,11 @@ function usePersonController() {
24192
24276
  getPeopleByNRIC: _getPeopleByNRIC,
24193
24277
  getByUserId: _getByUserId
24194
24278
  } = usePersonRepo();
24195
- const { add: _add, updateById: _updateById } = usePersonService();
24279
+ const {
24280
+ add: _add,
24281
+ updateById: _updateById,
24282
+ reviewResidentPerson: _reviewResidentPerson
24283
+ } = usePersonService();
24196
24284
  async function add(req, res, next) {
24197
24285
  const payload = { ...req.body };
24198
24286
  const { error } = schemaPerson.validate(payload, {
@@ -24507,6 +24595,38 @@ function usePersonController() {
24507
24595
  return;
24508
24596
  }
24509
24597
  }
24598
+ async function reviewResidentPerson(req, res, next) {
24599
+ const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
24600
+ (acc, [key, value]) => ({ ...acc, [key]: value }),
24601
+ {}
24602
+ );
24603
+ req.body.approvedBy = cookies?.["user"] ? cookies["user"].toString() : req.body.approvedBy;
24604
+ const _id = req.params.id;
24605
+ const payload = { _id, ...req.body };
24606
+ const schema2 = import_joi58.default.object({
24607
+ _id: import_joi58.default.string().hex().required(),
24608
+ status: import_joi58.default.string().valid("approved", "rejected", "resubmit").required(),
24609
+ approvedBy: import_joi58.default.string().required(),
24610
+ remarks: import_joi58.default.string().optional().allow("", null)
24611
+ });
24612
+ const { error } = schema2.validate(payload);
24613
+ if (error) {
24614
+ const messages = error.details.map((d) => d.message).join(", ");
24615
+ import_node_server_utils108.logger.log({ level: "error", message: messages });
24616
+ next(new import_node_server_utils108.BadRequestError(messages));
24617
+ return;
24618
+ }
24619
+ try {
24620
+ req.body.approvedBy = { id: req.body.approvedBy, name: "" };
24621
+ const result = await _reviewResidentPerson(_id, req.body);
24622
+ res.status(200).json({ message: result });
24623
+ return;
24624
+ } catch (error2) {
24625
+ import_node_server_utils108.logger.log({ level: "error", message: error2.message });
24626
+ next(error2);
24627
+ return;
24628
+ }
24629
+ }
24510
24630
  return {
24511
24631
  add,
24512
24632
  getAll,
@@ -24518,7 +24638,8 @@ function usePersonController() {
24518
24638
  getCompany,
24519
24639
  getPeopleByPlateNumber,
24520
24640
  getPeopleByNRIC,
24521
- getPersonByUserId
24641
+ getPersonByUserId,
24642
+ reviewResidentPerson
24522
24643
  };
24523
24644
  }
24524
24645
 
@@ -32808,7 +32929,7 @@ var MAccessCard = class {
32808
32929
  accessType = "Normal" /* NORMAL */,
32809
32930
  cardNo,
32810
32931
  pin,
32811
- qrData,
32932
+ qrData = null,
32812
32933
  startDate,
32813
32934
  endDate,
32814
32935
  isActivated,
@@ -33141,10 +33262,6 @@ function UseAccessManagementRepo() {
33141
33262
  payload.updatedAt = new Date(payload.updatedAt);
33142
33263
  payload.assignedUnit = payload.unit?.map((id) => new import_mongodb90.ObjectId(id));
33143
33264
  delete payload.unit;
33144
- payload.qrData = await createQrData({
33145
- cardNumber: payload.cardNo,
33146
- facilityCode: parseInt(payload.cardNo.slice(0, 4), 10)
33147
- });
33148
33265
  const accessCardObj = new MAccessCard(payload);
33149
33266
  const result = await collection().insertOne(accessCardObj);
33150
33267
  return result.insertedId;
@@ -33206,10 +33323,6 @@ function UseAccessManagementRepo() {
33206
33323
  cardNo,
33207
33324
  accessType: "Normal" /* NORMAL */,
33208
33325
  pin: "123456",
33209
- qrData: await createQrData({
33210
- cardNumber: cardNo,
33211
- facilityCode: parseInt(cardNo.slice(0, 4), 10)
33212
- }),
33213
33326
  startDate: /* @__PURE__ */ new Date(),
33214
33327
  endDate,
33215
33328
  isActivated: true,
@@ -33259,10 +33372,6 @@ function UseAccessManagementRepo() {
33259
33372
  cardNo,
33260
33373
  accessType: "Normal" /* NORMAL */,
33261
33374
  pin: "123456",
33262
- qrData: await createQrData({
33263
- cardNumber: cardNo,
33264
- facilityCode: parseInt(cardNo.slice(0, 4), 10)
33265
- }),
33266
33375
  startDate: /* @__PURE__ */ new Date(),
33267
33376
  endDate,
33268
33377
  isActivated: true,
@@ -34404,7 +34513,6 @@ function UseAccessManagementRepo() {
34404
34513
  accessType: "Normal" /* NORMAL */,
34405
34514
  cardNo: `${facilityCode}${cardNumber}`,
34406
34515
  pin,
34407
- qrData: await createQrData({ cardNumber: `${facilityCode}${cardNumber}` }),
34408
34516
  startDate: new Date(item["startDate (format MM/DD/YYYY)"]),
34409
34517
  endDate: new Date(item["endDate (format MM/DD/YYYY)"] || endDate),
34410
34518
  isActivated: true,
@@ -41527,6 +41635,17 @@ var import_node_server_utils184 = require("@7365admin1/node-server-utils");
41527
41635
  // src/models/occurrence-subject.model.ts
41528
41636
  var import_mongodb108 = require("mongodb");
41529
41637
  var import_joi103 = __toESM(require("joi"));
41638
+ var SubjectSort = /* @__PURE__ */ ((SubjectSort2) => {
41639
+ SubjectSort2["CREATED_AT"] = "createdAt";
41640
+ SubjectSort2["NAME"] = "name";
41641
+ SubjectSort2["ID"] = "_id";
41642
+ return SubjectSort2;
41643
+ })(SubjectSort || {});
41644
+ var SubjectOrder = /* @__PURE__ */ ((SubjectOrder2) => {
41645
+ SubjectOrder2["ASC"] = "asc";
41646
+ SubjectOrder2["DESC"] = "desc";
41647
+ return SubjectOrder2;
41648
+ })(SubjectOrder || {});
41530
41649
  var schemaOccurrenceSubject = import_joi103.default.object({
41531
41650
  site: import_joi103.default.string().hex().required(),
41532
41651
  subject: import_joi103.default.string().required(),
@@ -41635,7 +41754,8 @@ function useOccurrenceSubjectRepo() {
41635
41754
  }
41636
41755
  const baseQuery = {
41637
41756
  site,
41638
- status: { $ne: "deleted" }
41757
+ status: { $ne: "deleted" },
41758
+ ...search && { $text: { $search: search } }
41639
41759
  };
41640
41760
  let query = { ...baseQuery };
41641
41761
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
@@ -41644,12 +41764,9 @@ function useOccurrenceSubjectRepo() {
41644
41764
  sort: JSON.stringify(sort),
41645
41765
  page,
41646
41766
  limit,
41647
- status: { $ne: "deleted" }
41767
+ status: { $ne: "deleted" },
41768
+ ...search && { search }
41648
41769
  };
41649
- if (search) {
41650
- query.$text = { $search: search };
41651
- cacheOptions.search = search;
41652
- }
41653
41770
  const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, cacheOptions);
41654
41771
  const cachedData = await getCache(cacheKey);
41655
41772
  if (cachedData) {
@@ -41728,11 +41845,22 @@ function useOccurrenceSubjectRepo() {
41728
41845
  } catch (error) {
41729
41846
  throw new import_node_server_utils184.BadRequestError("Invalid occurrence subject ID format.");
41730
41847
  }
41848
+ const cacheKey = (0, import_node_server_utils184.makeCacheKey)(namespace_collection, { _id });
41849
+ const cachedData = await getCache(cacheKey);
41850
+ if (cachedData) {
41851
+ import_node_server_utils184.logger.info(`Cache hit for key: ${cacheKey}`);
41852
+ return cachedData;
41853
+ }
41731
41854
  try {
41732
41855
  const data = await collection.findOne({ _id }, { session });
41733
41856
  if (!data) {
41734
41857
  throw new import_node_server_utils184.NotFoundError("Occurrence subject not found.");
41735
41858
  }
41859
+ setCache(cacheKey, data, 15 * 60).then(() => {
41860
+ import_node_server_utils184.logger.info(`Cache set for key: ${cacheKey}`);
41861
+ }).catch((err) => {
41862
+ import_node_server_utils184.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
41863
+ });
41736
41864
  return data;
41737
41865
  } catch (error) {
41738
41866
  throw error;
@@ -41919,62 +42047,49 @@ function useOccurrenceEntryController() {
41919
42047
  getLatestSerialNumber: _getLatestSerialNumber
41920
42048
  } = useOccurrenceEntryRepo();
41921
42049
  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
42050
  try {
42051
+ const { error, value } = schemaOccurrenceEntry.validate(req.body, {
42052
+ abortEarly: false
42053
+ });
42054
+ if (error) {
42055
+ const messages = error.details.map((d) => d.message).join(", ");
42056
+ import_node_server_utils186.logger.log({ level: "error", message: messages });
42057
+ next(new import_node_server_utils186.BadRequestError(messages));
42058
+ return;
42059
+ }
41932
42060
  const data = await _add(value);
41933
42061
  res.status(201).json(data);
41934
42062
  return;
41935
- } catch (error2) {
41936
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
41937
- next(error2);
42063
+ } catch (error) {
42064
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42065
+ next(error);
41938
42066
  return;
41939
42067
  }
41940
42068
  }
41941
42069
  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
42070
  try {
42071
+ const schema2 = import_joi104.default.object({
42072
+ search: import_joi104.default.string().optional().allow("", null),
42073
+ page: import_joi104.default.number().integer().min(1).allow("", null).default(1),
42074
+ limit: import_joi104.default.number().integer().min(1).max(100).allow("", null).default(10),
42075
+ sort: import_joi104.default.string().valid(...Object.values(EntrySort)).default("_id" /* ID */),
42076
+ order: import_joi104.default.string().valid(...Object.values(EntryOrder)).default("desc" /* DESC */),
42077
+ site: import_joi104.default.string().hex().required(),
42078
+ dailyOccurrenceBookId: import_joi104.default.string().hex().length(24).optional().allow("", null)
42079
+ });
42080
+ const { error, value } = schema2.validate(req.query, {
42081
+ abortEarly: false
42082
+ });
42083
+ if (error) {
42084
+ const messages = error.details.map((d) => d.message).join(", ");
42085
+ import_node_server_utils186.logger.log({ level: "error", message: messages });
42086
+ next(new import_node_server_utils186.BadRequestError(messages));
42087
+ return;
42088
+ }
42089
+ const { search, page, limit, site, dailyOccurrenceBookId, sort, order } = value;
42090
+ const sortObj = {
42091
+ [sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
42092
+ };
41978
42093
  const data = await _getAll({
41979
42094
  search,
41980
42095
  page,
@@ -41985,69 +42100,73 @@ function useOccurrenceEntryController() {
41985
42100
  });
41986
42101
  res.status(200).json(data);
41987
42102
  return;
41988
- } catch (error2) {
41989
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
41990
- next(error2);
42103
+ } catch (error) {
42104
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42105
+ next(error);
41991
42106
  return;
41992
42107
  }
41993
42108
  }
41994
42109
  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
42110
  try {
42111
+ const schema2 = import_joi104.default.object({
42112
+ _id: import_joi104.default.string().hex().length(24).required()
42113
+ });
42114
+ const { error, value } = schema2.validate({ _id: req.params.id });
42115
+ if (error) {
42116
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42117
+ next(new import_node_server_utils186.BadRequestError(error.message));
42118
+ return;
42119
+ }
42120
+ const { _id } = value;
42004
42121
  const data = await _getOccurrenceEntryById(_id);
42005
42122
  res.status(200).json(data);
42006
42123
  return;
42007
- } catch (error2) {
42008
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
42009
- next(error2);
42124
+ } catch (error) {
42125
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42126
+ next(error);
42010
42127
  return;
42011
42128
  }
42012
42129
  }
42013
42130
  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
42131
  try {
42132
+ const payload = { _id: req.params.id, ...req.body };
42133
+ const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
42134
+ abortEarly: false
42135
+ });
42136
+ if (error) {
42137
+ const messages = error.details.map((d) => d.message).join(", ");
42138
+ import_node_server_utils186.logger.log({ level: "error", message: messages });
42139
+ next(new import_node_server_utils186.BadRequestError(messages));
42140
+ return;
42141
+ }
42142
+ const { _id, ...rest } = value;
42026
42143
  const result = await _updateOccurrenceEntryById(_id, rest);
42027
42144
  res.status(200).json({ message: result });
42028
42145
  return;
42029
- } catch (error2) {
42030
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
42031
- next(error2);
42146
+ } catch (error) {
42147
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42148
+ next(error);
42032
42149
  return;
42033
42150
  }
42034
42151
  }
42035
42152
  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
42153
  try {
42154
+ const schema2 = import_joi104.default.object({
42155
+ _id: import_joi104.default.string().hex().length(24).required()
42156
+ });
42157
+ const { error, value } = schema2.validate({ _id: req.params.id });
42158
+ if (error) {
42159
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42160
+ next(new import_node_server_utils186.BadRequestError(error.message));
42161
+ return;
42162
+ }
42163
+ const { _id } = value;
42045
42164
  await _deleteOccurrenceEntryById(_id);
42046
42165
  res.status(200).json({ message: "Successfully deleted occurrence entry." });
42047
42166
  return;
42048
- } catch (error2) {
42049
- import_node_server_utils186.logger.log({ level: "error", message: error2.message });
42050
- next(error2);
42167
+ } catch (error) {
42168
+ import_node_server_utils186.logger.log({ level: "error", message: error.message });
42169
+ next(error);
42051
42170
  return;
42052
42171
  }
42053
42172
  }
@@ -42684,61 +42803,48 @@ function useOccurrenceSubjectController() {
42684
42803
  deleteOccurrenceSubjectById: _deleteOccurrenceSubjectById
42685
42804
  } = useOccurrenceSubjectRepo();
42686
42805
  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
42806
  try {
42698
- const data = await _add(payload);
42807
+ const { error, value } = schemaOccurrenceSubject.validate(req.body, {
42808
+ abortEarly: false
42809
+ });
42810
+ if (error) {
42811
+ const messages = error.details.map((d) => d.message).join(", ");
42812
+ import_node_server_utils190.logger.log({ level: "error", message: messages });
42813
+ next(new import_node_server_utils190.BadRequestError(messages));
42814
+ return;
42815
+ }
42816
+ const data = await _add(value);
42699
42817
  res.status(201).json(data);
42700
42818
  return;
42701
- } catch (error2) {
42702
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
42703
- next(error2);
42819
+ } catch (error) {
42820
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42821
+ next(error);
42704
42822
  return;
42705
42823
  }
42706
42824
  }
42707
42825
  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
42826
  try {
42827
+ const validation = import_joi107.default.object({
42828
+ search: import_joi107.default.string().optional().allow("", null),
42829
+ page: import_joi107.default.number().integer().min(1).allow("", null).default(1),
42830
+ limit: import_joi107.default.number().integer().min(1).max(100).allow("", null).default(10),
42831
+ sort: import_joi107.default.string().valid(...Object.values(SubjectSort)).default("_id" /* ID */),
42832
+ order: import_joi107.default.string().valid(...Object.values(SubjectOrder)).default("desc" /* DESC */),
42833
+ site: import_joi107.default.string().hex().length(24).required()
42834
+ });
42835
+ const { error, value } = validation.validate(req.query, {
42836
+ abortEarly: false
42837
+ });
42838
+ if (error) {
42839
+ const messages = error.details.map((d) => d.message).join(", ");
42840
+ import_node_server_utils190.logger.log({ level: "error", message: messages });
42841
+ next(new import_node_server_utils190.BadRequestError(messages));
42842
+ return;
42843
+ }
42844
+ const { search, page, limit, site, sort, order } = value;
42845
+ const sortObj = {
42846
+ [sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
42847
+ };
42742
42848
  const data = await _getAll({
42743
42849
  search,
42744
42850
  page,
@@ -42748,50 +42854,54 @@ function useOccurrenceSubjectController() {
42748
42854
  });
42749
42855
  res.status(200).json(data);
42750
42856
  return;
42751
- } catch (error2) {
42752
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
42753
- next(error2);
42857
+ } catch (error) {
42858
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42859
+ next(error);
42754
42860
  return;
42755
42861
  }
42756
42862
  }
42757
42863
  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
42864
  try {
42865
+ const schema2 = import_joi107.default.object({
42866
+ _id: import_joi107.default.string().hex().length(24).required()
42867
+ });
42868
+ const { error, value } = schema2.validate({ _id: req.params.id });
42869
+ if (error) {
42870
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42871
+ next(new import_node_server_utils190.BadRequestError(error.message));
42872
+ return;
42873
+ }
42874
+ const { _id } = value;
42767
42875
  const data = await _getOccurrenceSubjectById(_id);
42768
42876
  res.status(200).json(data);
42769
42877
  return;
42770
- } catch (error2) {
42771
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
42772
- next(error2);
42878
+ } catch (error) {
42879
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42880
+ next(error);
42773
42881
  return;
42774
42882
  }
42775
42883
  }
42776
42884
  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
42885
  try {
42789
- const result = await _updateOccurrenceSubjectById(_id, req.body);
42886
+ const { error, value } = schemaUpdateOccurrenceSubject.validate(
42887
+ { _id: req.params.id, ...req.body },
42888
+ {
42889
+ abortEarly: false
42890
+ }
42891
+ );
42892
+ if (error) {
42893
+ const messages = error.details.map((d) => d.message).join(", ");
42894
+ import_node_server_utils190.logger.log({ level: "error", message: messages });
42895
+ next(new import_node_server_utils190.BadRequestError(messages));
42896
+ return;
42897
+ }
42898
+ const { _id, ...rest } = value;
42899
+ const result = await _updateOccurrenceSubjectById(_id, rest);
42790
42900
  res.status(200).json({ message: result });
42791
42901
  return;
42792
- } catch (error2) {
42793
- import_node_server_utils190.logger.log({ level: "error", message: error2.message });
42794
- next(error2);
42902
+ } catch (error) {
42903
+ import_node_server_utils190.logger.log({ level: "error", message: error.message });
42904
+ next(error);
42795
42905
  return;
42796
42906
  }
42797
42907
  }
@@ -49999,6 +50109,8 @@ function useRoleControllerV2() {
49999
50109
  EAccessCardTypes,
50000
50110
  EAccessCardUserTypes,
50001
50111
  EmailSender,
50112
+ EntryOrder,
50113
+ EntrySort,
50002
50114
  FacilitySort,
50003
50115
  FacilityStatus,
50004
50116
  GuestSort,
@@ -50080,6 +50192,8 @@ function useRoleControllerV2() {
50080
50192
  SortFields,
50081
50193
  SortOrder,
50082
50194
  Status,
50195
+ SubjectOrder,
50196
+ SubjectSort,
50083
50197
  SubscriptionType,
50084
50198
  UseAccessManagementRepo,
50085
50199
  UserStatus,
@@ -50135,6 +50249,7 @@ function useRoleControllerV2() {
50135
50249
  robotSchema,
50136
50250
  schema,
50137
50251
  schemaApprovedBy,
50252
+ schemaApprover,
50138
50253
  schemaBilling,
50139
50254
  schemaBillingConfiguration,
50140
50255
  schemaBillingItem,