@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.mjs CHANGED
@@ -1431,6 +1431,17 @@ import {
1431
1431
  // src/models/occurrence-entry.model.ts
1432
1432
  import { ObjectId as ObjectId6 } from "mongodb";
1433
1433
  import Joi5 from "joi";
1434
+ var EntrySort = /* @__PURE__ */ ((EntrySort2) => {
1435
+ EntrySort2["CREATED_AT"] = "createdAt";
1436
+ EntrySort2["NAME"] = "name";
1437
+ EntrySort2["ID"] = "_id";
1438
+ return EntrySort2;
1439
+ })(EntrySort || {});
1440
+ var EntryOrder = /* @__PURE__ */ ((EntryOrder2) => {
1441
+ EntryOrder2["ASC"] = "asc";
1442
+ EntryOrder2["DESC"] = "desc";
1443
+ return EntryOrder2;
1444
+ })(EntryOrder || {});
1434
1445
  var schemaOccurrenceEntry = Joi5.object({
1435
1446
  site: Joi5.string().hex().length(24).required(),
1436
1447
  dailyOccurrenceBookId: Joi5.string().hex().optional().allow(null, ""),
@@ -13319,6 +13330,10 @@ var schemaFiles = Joi35.object({
13319
13330
  id: Joi35.string().hex().required(),
13320
13331
  name: Joi35.string().optional().allow(null, "")
13321
13332
  });
13333
+ var schemaApprover = Joi35.object({
13334
+ id: Joi35.string().hex().required(),
13335
+ name: Joi35.string().optional().allow(null, "")
13336
+ });
13322
13337
  var schemaPerson = Joi35.object({
13323
13338
  _id: Joi35.string().hex().optional().allow("", null),
13324
13339
  user: Joi35.string().hex().length(24).optional().allow(null, ""),
@@ -13343,7 +13358,8 @@ var schemaPerson = Joi35.object({
13343
13358
  files: Joi35.array().items(schemaFiles).optional().allow(null),
13344
13359
  password: Joi35.string().optional().allow(null, ""),
13345
13360
  plateNumber: Joi35.string().optional().allow(null, ""),
13346
- platform: Joi35.string().valid("web", "mobile").optional().allow(null, "")
13361
+ platform: Joi35.string().valid("web", "mobile").optional().allow(null, ""),
13362
+ approvedBy: schemaApprover.optional().allow(null, "")
13347
13363
  });
13348
13364
  var schemaUpdatePerson = Joi35.object({
13349
13365
  _id: Joi35.string().hex().required(),
@@ -13365,7 +13381,8 @@ var schemaUpdatePerson = Joi35.object({
13365
13381
  files: Joi35.array().items(schemaFiles).optional().allow(null),
13366
13382
  password: Joi35.string().optional().allow(null, ""),
13367
13383
  plateNumber: Joi35.string().optional().allow(null, ""),
13368
- platform: Joi35.string().valid("web", "mobile").optional().allow(null, "")
13384
+ platform: Joi35.string().valid("web", "mobile").optional().allow(null, ""),
13385
+ approvedBy: schemaApprover.optional().allow(null, "")
13369
13386
  });
13370
13387
  function MPerson(value) {
13371
13388
  const { error } = schemaPerson.validate(value);
@@ -13437,6 +13454,7 @@ function MPerson(value) {
13437
13454
  files: value.files ?? [],
13438
13455
  plateNumber: value.plateNumber ?? "",
13439
13456
  platForm: value.platform ?? "",
13457
+ approvedBy: value.approvedBy ?? { id: "", name: "" },
13440
13458
  createdAt: value.createdAt ?? (/* @__PURE__ */ new Date()).toISOString(),
13441
13459
  updatedAt: value.updatedAt,
13442
13460
  deletedAt: value.deletedAt
@@ -15650,6 +15668,37 @@ function usePersonRepo() {
15650
15668
  }
15651
15669
  }
15652
15670
  }
15671
+ async function reviewResidentPerson(_id, value, session) {
15672
+ value.updatedAt = (/* @__PURE__ */ new Date()).toISOString();
15673
+ try {
15674
+ _id = new ObjectId44(_id);
15675
+ } catch (error) {
15676
+ throw new BadRequestError70("Invalid ID format.");
15677
+ }
15678
+ try {
15679
+ const res = await collection.updateOne(
15680
+ { _id },
15681
+ { $set: value },
15682
+ { session }
15683
+ );
15684
+ if (res.modifiedCount === 0) {
15685
+ throw new InternalServerError26(`Unable to ${value.status} person.`);
15686
+ }
15687
+ delNamespace().then(() => {
15688
+ logger51.info(
15689
+ `Cache cleared for namespace: ${site_people_namespace_collection}`
15690
+ );
15691
+ }).catch((err) => {
15692
+ logger51.error(
15693
+ `Failed to clear cache for namespace: ${site_people_namespace_collection}`,
15694
+ err
15695
+ );
15696
+ });
15697
+ return res;
15698
+ } catch (error) {
15699
+ throw error;
15700
+ }
15701
+ }
15653
15702
  return {
15654
15703
  add,
15655
15704
  getAll,
@@ -15667,7 +15716,8 @@ function usePersonRepo() {
15667
15716
  getPeopleByNRIC,
15668
15717
  pushVehicleById,
15669
15718
  pullVehicleByRecNo,
15670
- getByUserId
15719
+ getByUserId,
15720
+ reviewResidentPerson
15671
15721
  };
15672
15722
  }
15673
15723
 
@@ -22571,6 +22621,7 @@ function useVisitorTransactionService() {
22571
22621
  const { getAllSites: _getAllSites } = useSiteRepo();
22572
22622
  const { getByUserId: _getByUserId } = usePersonRepo();
22573
22623
  const { add: addVehicle } = useVehicleRepo();
22624
+ const { getById: _getUnitById } = useBuildingUnitRepo();
22574
22625
  function extractKeyId(item) {
22575
22626
  if (!item)
22576
22627
  return null;
@@ -22655,6 +22706,10 @@ function useVisitorTransactionService() {
22655
22706
  _getSiteById(value.site)
22656
22707
  ]);
22657
22708
  }
22709
+ if (!value.unitName && value.unit) {
22710
+ const unit = await _getUnitById(value.unit);
22711
+ value.unitName = unit?.name;
22712
+ }
22658
22713
  const hourExpiration = site?.dahuaTimeExpiration ? site?.dahuaTimeExpiration : 24 * 60;
22659
22714
  const end = value.checkOut ? new Date(value.checkOut) : new Date(start.getTime() + hourExpiration * 60 * 1e3);
22660
22715
  const startDahuaDate = formatDahuaDate(start);
@@ -23923,13 +23978,15 @@ function usePersonService() {
23923
23978
  add: _add,
23924
23979
  getById: _getById,
23925
23980
  updateById: _updateById,
23926
- getByUserId: _getByUserId
23981
+ getByUserId: _getByUserId,
23982
+ reviewResidentPerson: _reviewResidentPerson
23927
23983
  } = usePersonRepo();
23928
23984
  const { addPlateNumber: _addPlateNumber } = useDahuaService();
23929
23985
  const {
23930
23986
  createUser: addUser,
23931
23987
  getUserByEmail,
23932
- updateUserFieldById: _updateUserFieldById
23988
+ updateUserFieldById: _updateUserFieldById,
23989
+ getUserById
23933
23990
  } = useUserRepo();
23934
23991
  const { add: addMember } = useMemberRepo();
23935
23992
  const { getById: _getUnitById, updateById: updateUnitById } = useBuildingUnitRepo();
@@ -24087,9 +24144,31 @@ function usePersonService() {
24087
24144
  }
24088
24145
  return { start: "", end: "" };
24089
24146
  }
24147
+ async function reviewResidentPerson(id, value) {
24148
+ const session = useAtlas52.getClient()?.startSession();
24149
+ session?.startTransaction();
24150
+ try {
24151
+ if (value.approvedBy) {
24152
+ const approvedBy = await getUserById(value.approvedBy.id);
24153
+ if (!approvedBy || !approvedBy.name)
24154
+ throw new BadRequestError101("Created by not found.");
24155
+ value.approvedBy.name = approvedBy.name;
24156
+ value.approvedBy.id = approvedBy._id;
24157
+ }
24158
+ await _reviewResidentPerson(id, value, session);
24159
+ await session?.commitTransaction();
24160
+ return `Successfully ${value.status} person`;
24161
+ } catch (error) {
24162
+ await session?.abortTransaction();
24163
+ throw error;
24164
+ } finally {
24165
+ session?.endSession();
24166
+ }
24167
+ }
24090
24168
  return {
24091
24169
  add,
24092
- updateById
24170
+ updateById,
24171
+ reviewResidentPerson
24093
24172
  };
24094
24173
  }
24095
24174
 
@@ -24106,7 +24185,11 @@ function usePersonController() {
24106
24185
  getPeopleByNRIC: _getPeopleByNRIC,
24107
24186
  getByUserId: _getByUserId
24108
24187
  } = usePersonRepo();
24109
- const { add: _add, updateById: _updateById } = usePersonService();
24188
+ const {
24189
+ add: _add,
24190
+ updateById: _updateById,
24191
+ reviewResidentPerson: _reviewResidentPerson
24192
+ } = usePersonService();
24110
24193
  async function add(req, res, next) {
24111
24194
  const payload = { ...req.body };
24112
24195
  const { error } = schemaPerson.validate(payload, {
@@ -24421,6 +24504,38 @@ function usePersonController() {
24421
24504
  return;
24422
24505
  }
24423
24506
  }
24507
+ async function reviewResidentPerson(req, res, next) {
24508
+ const cookies = req.headers.cookie?.split(";").map((cookie) => cookie.trim().split("=")).reduce(
24509
+ (acc, [key, value]) => ({ ...acc, [key]: value }),
24510
+ {}
24511
+ );
24512
+ req.body.approvedBy = cookies?.["user"] ? cookies["user"].toString() : req.body.approvedBy;
24513
+ const _id = req.params.id;
24514
+ const payload = { _id, ...req.body };
24515
+ const schema2 = Joi58.object({
24516
+ _id: Joi58.string().hex().required(),
24517
+ status: Joi58.string().valid("approved", "rejected", "resubmit").required(),
24518
+ approvedBy: Joi58.string().required(),
24519
+ remarks: Joi58.string().optional().allow("", null)
24520
+ });
24521
+ const { error } = schema2.validate(payload);
24522
+ if (error) {
24523
+ const messages = error.details.map((d) => d.message).join(", ");
24524
+ logger83.log({ level: "error", message: messages });
24525
+ next(new BadRequestError102(messages));
24526
+ return;
24527
+ }
24528
+ try {
24529
+ req.body.approvedBy = { id: req.body.approvedBy, name: "" };
24530
+ const result = await _reviewResidentPerson(_id, req.body);
24531
+ res.status(200).json({ message: result });
24532
+ return;
24533
+ } catch (error2) {
24534
+ logger83.log({ level: "error", message: error2.message });
24535
+ next(error2);
24536
+ return;
24537
+ }
24538
+ }
24424
24539
  return {
24425
24540
  add,
24426
24541
  getAll,
@@ -24432,7 +24547,8 @@ function usePersonController() {
24432
24547
  getCompany,
24433
24548
  getPeopleByPlateNumber,
24434
24549
  getPeopleByNRIC,
24435
- getPersonByUserId
24550
+ getPersonByUserId,
24551
+ reviewResidentPerson
24436
24552
  };
24437
24553
  }
24438
24554
 
@@ -32860,7 +32976,7 @@ var MAccessCard = class {
32860
32976
  accessType = "Normal" /* NORMAL */,
32861
32977
  cardNo,
32862
32978
  pin,
32863
- qrData,
32979
+ qrData = null,
32864
32980
  startDate,
32865
32981
  endDate,
32866
32982
  isActivated,
@@ -33197,10 +33313,6 @@ function UseAccessManagementRepo() {
33197
33313
  payload.updatedAt = new Date(payload.updatedAt);
33198
33314
  payload.assignedUnit = payload.unit?.map((id) => new ObjectId90(id));
33199
33315
  delete payload.unit;
33200
- payload.qrData = await createQrData({
33201
- cardNumber: payload.cardNo,
33202
- facilityCode: parseInt(payload.cardNo.slice(0, 4), 10)
33203
- });
33204
33316
  const accessCardObj = new MAccessCard(payload);
33205
33317
  const result = await collection().insertOne(accessCardObj);
33206
33318
  return result.insertedId;
@@ -33262,10 +33374,6 @@ function UseAccessManagementRepo() {
33262
33374
  cardNo,
33263
33375
  accessType: "Normal" /* NORMAL */,
33264
33376
  pin: "123456",
33265
- qrData: await createQrData({
33266
- cardNumber: cardNo,
33267
- facilityCode: parseInt(cardNo.slice(0, 4), 10)
33268
- }),
33269
33377
  startDate: /* @__PURE__ */ new Date(),
33270
33378
  endDate,
33271
33379
  isActivated: true,
@@ -33315,10 +33423,6 @@ function UseAccessManagementRepo() {
33315
33423
  cardNo,
33316
33424
  accessType: "Normal" /* NORMAL */,
33317
33425
  pin: "123456",
33318
- qrData: await createQrData({
33319
- cardNumber: cardNo,
33320
- facilityCode: parseInt(cardNo.slice(0, 4), 10)
33321
- }),
33322
33426
  startDate: /* @__PURE__ */ new Date(),
33323
33427
  endDate,
33324
33428
  isActivated: true,
@@ -34460,7 +34564,6 @@ function UseAccessManagementRepo() {
34460
34564
  accessType: "Normal" /* NORMAL */,
34461
34565
  cardNo: `${facilityCode}${cardNumber}`,
34462
34566
  pin,
34463
- qrData: await createQrData({ cardNumber: `${facilityCode}${cardNumber}` }),
34464
34567
  startDate: new Date(item["startDate (format MM/DD/YYYY)"]),
34465
34568
  endDate: new Date(item["endDate (format MM/DD/YYYY)"] || endDate),
34466
34569
  isActivated: true,
@@ -41689,6 +41792,17 @@ import {
41689
41792
  // src/models/occurrence-subject.model.ts
41690
41793
  import { ObjectId as ObjectId108 } from "mongodb";
41691
41794
  import Joi103 from "joi";
41795
+ var SubjectSort = /* @__PURE__ */ ((SubjectSort2) => {
41796
+ SubjectSort2["CREATED_AT"] = "createdAt";
41797
+ SubjectSort2["NAME"] = "name";
41798
+ SubjectSort2["ID"] = "_id";
41799
+ return SubjectSort2;
41800
+ })(SubjectSort || {});
41801
+ var SubjectOrder = /* @__PURE__ */ ((SubjectOrder2) => {
41802
+ SubjectOrder2["ASC"] = "asc";
41803
+ SubjectOrder2["DESC"] = "desc";
41804
+ return SubjectOrder2;
41805
+ })(SubjectOrder || {});
41692
41806
  var schemaOccurrenceSubject = Joi103.object({
41693
41807
  site: Joi103.string().hex().required(),
41694
41808
  subject: Joi103.string().required(),
@@ -41797,7 +41911,8 @@ function useOccurrenceSubjectRepo() {
41797
41911
  }
41798
41912
  const baseQuery = {
41799
41913
  site,
41800
- status: { $ne: "deleted" }
41914
+ status: { $ne: "deleted" },
41915
+ ...search && { $text: { $search: search } }
41801
41916
  };
41802
41917
  let query = { ...baseQuery };
41803
41918
  sort = Object.keys(sort).length > 0 ? sort : { _id: -1 };
@@ -41806,12 +41921,9 @@ function useOccurrenceSubjectRepo() {
41806
41921
  sort: JSON.stringify(sort),
41807
41922
  page,
41808
41923
  limit,
41809
- status: { $ne: "deleted" }
41924
+ status: { $ne: "deleted" },
41925
+ ...search && { search }
41810
41926
  };
41811
- if (search) {
41812
- query.$text = { $search: search };
41813
- cacheOptions.search = search;
41814
- }
41815
41927
  const cacheKey = makeCacheKey54(namespace_collection, cacheOptions);
41816
41928
  const cachedData = await getCache(cacheKey);
41817
41929
  if (cachedData) {
@@ -41890,11 +42002,22 @@ function useOccurrenceSubjectRepo() {
41890
42002
  } catch (error) {
41891
42003
  throw new BadRequestError170("Invalid occurrence subject ID format.");
41892
42004
  }
42005
+ const cacheKey = makeCacheKey54(namespace_collection, { _id });
42006
+ const cachedData = await getCache(cacheKey);
42007
+ if (cachedData) {
42008
+ logger147.info(`Cache hit for key: ${cacheKey}`);
42009
+ return cachedData;
42010
+ }
41893
42011
  try {
41894
42012
  const data = await collection.findOne({ _id }, { session });
41895
42013
  if (!data) {
41896
42014
  throw new NotFoundError46("Occurrence subject not found.");
41897
42015
  }
42016
+ setCache(cacheKey, data, 15 * 60).then(() => {
42017
+ logger147.info(`Cache set for key: ${cacheKey}`);
42018
+ }).catch((err) => {
42019
+ logger147.error(`Failed to set cache for key: ${cacheKey}`, err);
42020
+ });
41898
42021
  return data;
41899
42022
  } catch (error) {
41900
42023
  throw error;
@@ -42081,62 +42204,49 @@ function useOccurrenceEntryController() {
42081
42204
  getLatestSerialNumber: _getLatestSerialNumber
42082
42205
  } = useOccurrenceEntryRepo();
42083
42206
  async function add(req, res, next) {
42084
- const { error, value } = schemaOccurrenceEntry.validate(req.body, {
42085
- abortEarly: false
42086
- });
42087
- if (error) {
42088
- const messages = error.details.map((d) => d.message).join(", ");
42089
- logger148.log({ level: "error", message: messages });
42090
- next(new BadRequestError171(messages));
42091
- return;
42092
- }
42093
42207
  try {
42208
+ const { error, value } = schemaOccurrenceEntry.validate(req.body, {
42209
+ abortEarly: false
42210
+ });
42211
+ if (error) {
42212
+ const messages = error.details.map((d) => d.message).join(", ");
42213
+ logger148.log({ level: "error", message: messages });
42214
+ next(new BadRequestError171(messages));
42215
+ return;
42216
+ }
42094
42217
  const data = await _add(value);
42095
42218
  res.status(201).json(data);
42096
42219
  return;
42097
- } catch (error2) {
42098
- logger148.log({ level: "error", message: error2.message });
42099
- next(error2);
42220
+ } catch (error) {
42221
+ logger148.log({ level: "error", message: error.message });
42222
+ next(error);
42100
42223
  return;
42101
42224
  }
42102
42225
  }
42103
42226
  async function getAll(req, res, next) {
42104
- const allowedFields = ["createdAt", "name"];
42105
- const allowedOrder = ["asc", "desc"];
42106
- const validation = Joi104.object({
42107
- search: Joi104.string().optional().allow("", null),
42108
- page: Joi104.number().integer().min(1).allow("", null).default(1),
42109
- limit: Joi104.number().integer().min(1).max(100).allow("", null).default(10),
42110
- sort: Joi104.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
42111
- order: Joi104.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
42112
- site: Joi104.string().hex().required(),
42113
- dailyOccurrenceBookId: Joi104.string().optional().allow("", null)
42114
- });
42115
- const query = { ...req.query };
42116
- const { error } = validation.validate(query, {
42117
- abortEarly: false
42118
- });
42119
- if (error) {
42120
- const messages = error.details.map((d) => d.message).join(", ");
42121
- logger148.log({ level: "error", message: messages });
42122
- next(new BadRequestError171(messages));
42123
- return;
42124
- }
42125
- const search = req.query.search ?? "";
42126
- const page = parseInt(req.query.page ?? "1");
42127
- const limit = parseInt(req.query.limit ?? "10");
42128
- const site = req.query.site ?? "";
42129
- const dailyOccurrenceBookId = req.query.dailyOccurrenceBookId ?? "";
42130
- const sortObj = {};
42131
- const sortFields = String(req.query.sort).split(",");
42132
- const sortOrders = String(req.query.order).split(",");
42133
- sortFields.forEach((field, index) => {
42134
- if (allowedFields.includes(field)) {
42135
- const order = sortOrders[index] === "asc" ? 1 : -1;
42136
- sortObj[field] = order;
42137
- }
42138
- });
42139
42227
  try {
42228
+ const schema2 = Joi104.object({
42229
+ search: Joi104.string().optional().allow("", null),
42230
+ page: Joi104.number().integer().min(1).allow("", null).default(1),
42231
+ limit: Joi104.number().integer().min(1).max(100).allow("", null).default(10),
42232
+ sort: Joi104.string().valid(...Object.values(EntrySort)).default("_id" /* ID */),
42233
+ order: Joi104.string().valid(...Object.values(EntryOrder)).default("desc" /* DESC */),
42234
+ site: Joi104.string().hex().required(),
42235
+ dailyOccurrenceBookId: Joi104.string().hex().length(24).optional().allow("", null)
42236
+ });
42237
+ const { error, value } = schema2.validate(req.query, {
42238
+ abortEarly: false
42239
+ });
42240
+ if (error) {
42241
+ const messages = error.details.map((d) => d.message).join(", ");
42242
+ logger148.log({ level: "error", message: messages });
42243
+ next(new BadRequestError171(messages));
42244
+ return;
42245
+ }
42246
+ const { search, page, limit, site, dailyOccurrenceBookId, sort, order } = value;
42247
+ const sortObj = {
42248
+ [sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
42249
+ };
42140
42250
  const data = await _getAll({
42141
42251
  search,
42142
42252
  page,
@@ -42147,69 +42257,73 @@ function useOccurrenceEntryController() {
42147
42257
  });
42148
42258
  res.status(200).json(data);
42149
42259
  return;
42150
- } catch (error2) {
42151
- logger148.log({ level: "error", message: error2.message });
42152
- next(error2);
42260
+ } catch (error) {
42261
+ logger148.log({ level: "error", message: error.message });
42262
+ next(error);
42153
42263
  return;
42154
42264
  }
42155
42265
  }
42156
42266
  async function getOccurrenceEntryById(req, res, next) {
42157
- const validation = Joi104.string().hex().required();
42158
- const _id = req.params.id;
42159
- const { error } = validation.validate(_id);
42160
- if (error) {
42161
- logger148.log({ level: "error", message: error.message });
42162
- next(new BadRequestError171(error.message));
42163
- return;
42164
- }
42165
42267
  try {
42268
+ const schema2 = Joi104.object({
42269
+ _id: Joi104.string().hex().length(24).required()
42270
+ });
42271
+ const { error, value } = schema2.validate({ _id: req.params.id });
42272
+ if (error) {
42273
+ logger148.log({ level: "error", message: error.message });
42274
+ next(new BadRequestError171(error.message));
42275
+ return;
42276
+ }
42277
+ const { _id } = value;
42166
42278
  const data = await _getOccurrenceEntryById(_id);
42167
42279
  res.status(200).json(data);
42168
42280
  return;
42169
- } catch (error2) {
42170
- logger148.log({ level: "error", message: error2.message });
42171
- next(error2);
42281
+ } catch (error) {
42282
+ logger148.log({ level: "error", message: error.message });
42283
+ next(error);
42172
42284
  return;
42173
42285
  }
42174
42286
  }
42175
42287
  async function updateOccurrenceEntryById(req, res, next) {
42176
- const payload = { _id: req.params.id, ...req.body };
42177
- const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
42178
- abortEarly: false
42179
- });
42180
- if (error) {
42181
- const messages = error.details.map((d) => d.message).join(", ");
42182
- logger148.log({ level: "error", message: messages });
42183
- next(new BadRequestError171(messages));
42184
- return;
42185
- }
42186
- const { _id, ...rest } = value;
42187
42288
  try {
42289
+ const payload = { _id: req.params.id, ...req.body };
42290
+ const { error, value } = schemaUpdateOccurrenceEntry.validate(payload, {
42291
+ abortEarly: false
42292
+ });
42293
+ if (error) {
42294
+ const messages = error.details.map((d) => d.message).join(", ");
42295
+ logger148.log({ level: "error", message: messages });
42296
+ next(new BadRequestError171(messages));
42297
+ return;
42298
+ }
42299
+ const { _id, ...rest } = value;
42188
42300
  const result = await _updateOccurrenceEntryById(_id, rest);
42189
42301
  res.status(200).json({ message: result });
42190
42302
  return;
42191
- } catch (error2) {
42192
- logger148.log({ level: "error", message: error2.message });
42193
- next(error2);
42303
+ } catch (error) {
42304
+ logger148.log({ level: "error", message: error.message });
42305
+ next(error);
42194
42306
  return;
42195
42307
  }
42196
42308
  }
42197
42309
  async function deleteOccurrenceEntryById(req, res, next) {
42198
- const validation = Joi104.string().hex().required();
42199
- const _id = req.params.id;
42200
- const { error } = validation.validate(_id);
42201
- if (error) {
42202
- logger148.log({ level: "error", message: error.message });
42203
- next(new BadRequestError171(error.message));
42204
- return;
42205
- }
42206
42310
  try {
42311
+ const schema2 = Joi104.object({
42312
+ _id: Joi104.string().hex().length(24).required()
42313
+ });
42314
+ const { error, value } = schema2.validate({ _id: req.params.id });
42315
+ if (error) {
42316
+ logger148.log({ level: "error", message: error.message });
42317
+ next(new BadRequestError171(error.message));
42318
+ return;
42319
+ }
42320
+ const { _id } = value;
42207
42321
  await _deleteOccurrenceEntryById(_id);
42208
42322
  res.status(200).json({ message: "Successfully deleted occurrence entry." });
42209
42323
  return;
42210
- } catch (error2) {
42211
- logger148.log({ level: "error", message: error2.message });
42212
- next(error2);
42324
+ } catch (error) {
42325
+ logger148.log({ level: "error", message: error.message });
42326
+ next(error);
42213
42327
  return;
42214
42328
  }
42215
42329
  }
@@ -42855,61 +42969,48 @@ function useOccurrenceSubjectController() {
42855
42969
  deleteOccurrenceSubjectById: _deleteOccurrenceSubjectById
42856
42970
  } = useOccurrenceSubjectRepo();
42857
42971
  async function add(req, res, next) {
42858
- const payload = { ...req.body };
42859
- const { error } = schemaOccurrenceSubject.validate(payload, {
42860
- abortEarly: false
42861
- });
42862
- if (error) {
42863
- const messages = error.details.map((d) => d.message).join(", ");
42864
- logger151.log({ level: "error", message: messages });
42865
- next(new BadRequestError174(messages));
42866
- return;
42867
- }
42868
42972
  try {
42869
- const data = await _add(payload);
42973
+ const { error, value } = schemaOccurrenceSubject.validate(req.body, {
42974
+ abortEarly: false
42975
+ });
42976
+ if (error) {
42977
+ const messages = error.details.map((d) => d.message).join(", ");
42978
+ logger151.log({ level: "error", message: messages });
42979
+ next(new BadRequestError174(messages));
42980
+ return;
42981
+ }
42982
+ const data = await _add(value);
42870
42983
  res.status(201).json(data);
42871
42984
  return;
42872
- } catch (error2) {
42873
- logger151.log({ level: "error", message: error2.message });
42874
- next(error2);
42985
+ } catch (error) {
42986
+ logger151.log({ level: "error", message: error.message });
42987
+ next(error);
42875
42988
  return;
42876
42989
  }
42877
42990
  }
42878
42991
  async function getAll(req, res, next) {
42879
- const allowedFields = ["createdAt", "name"];
42880
- const allowedOrder = ["asc", "desc"];
42881
- const validation = Joi107.object({
42882
- search: Joi107.string().optional().allow("", null),
42883
- page: Joi107.number().integer().min(1).allow("", null).default(1),
42884
- limit: Joi107.number().integer().min(1).max(100).allow("", null).default(10),
42885
- sort: Joi107.string().pattern(/^([a-zA-Z0-9_]+)(,[a-zA-Z0-9_]+)*$/).optional().allow("", ...allowedFields),
42886
- order: Joi107.string().pattern(/^(asc|desc)(,(asc|desc))*$/).optional().allow("", ...allowedOrder),
42887
- site: Joi107.string().hex().required()
42888
- });
42889
- const query = { ...req.query };
42890
- const { error } = validation.validate(query, {
42891
- abortEarly: false
42892
- });
42893
- if (error) {
42894
- const messages = error.details.map((d) => d.message).join(", ");
42895
- logger151.log({ level: "error", message: messages });
42896
- next(new BadRequestError174(messages));
42897
- return;
42898
- }
42899
- const search = req.query.search ?? "";
42900
- const page = parseInt(req.query.page ?? "1");
42901
- const limit = parseInt(req.query.limit ?? "10");
42902
- const site = req.query.site ?? "";
42903
- const sortObj = {};
42904
- const sortFields = String(req.query.sort).split(",");
42905
- const sortOrders = String(req.query.order).split(",");
42906
- sortFields.forEach((field, index) => {
42907
- if (allowedFields.includes(field)) {
42908
- const order = sortOrders[index] === "asc" ? 1 : -1;
42909
- sortObj[field] = order;
42910
- }
42911
- });
42912
42992
  try {
42993
+ const validation = Joi107.object({
42994
+ search: Joi107.string().optional().allow("", null),
42995
+ page: Joi107.number().integer().min(1).allow("", null).default(1),
42996
+ limit: Joi107.number().integer().min(1).max(100).allow("", null).default(10),
42997
+ sort: Joi107.string().valid(...Object.values(SubjectSort)).default("_id" /* ID */),
42998
+ order: Joi107.string().valid(...Object.values(SubjectOrder)).default("desc" /* DESC */),
42999
+ site: Joi107.string().hex().length(24).required()
43000
+ });
43001
+ const { error, value } = validation.validate(req.query, {
43002
+ abortEarly: false
43003
+ });
43004
+ if (error) {
43005
+ const messages = error.details.map((d) => d.message).join(", ");
43006
+ logger151.log({ level: "error", message: messages });
43007
+ next(new BadRequestError174(messages));
43008
+ return;
43009
+ }
43010
+ const { search, page, limit, site, sort, order } = value;
43011
+ const sortObj = {
43012
+ [sort ? sort : "_id" /* ID */]: order === "asc" /* ASC */ ? 1 : -1
43013
+ };
42913
43014
  const data = await _getAll({
42914
43015
  search,
42915
43016
  page,
@@ -42919,50 +43020,54 @@ function useOccurrenceSubjectController() {
42919
43020
  });
42920
43021
  res.status(200).json(data);
42921
43022
  return;
42922
- } catch (error2) {
42923
- logger151.log({ level: "error", message: error2.message });
42924
- next(error2);
43023
+ } catch (error) {
43024
+ logger151.log({ level: "error", message: error.message });
43025
+ next(error);
42925
43026
  return;
42926
43027
  }
42927
43028
  }
42928
43029
  async function getOccurrenceSubjectById(req, res, next) {
42929
- const validation = Joi107.string().hex().required();
42930
- const _id = req.params.id;
42931
- const { error } = validation.validate(_id);
42932
- if (error) {
42933
- logger151.log({ level: "error", message: error.message });
42934
- next(new BadRequestError174(error.message));
42935
- return;
42936
- }
42937
43030
  try {
43031
+ const schema2 = Joi107.object({
43032
+ _id: Joi107.string().hex().length(24).required()
43033
+ });
43034
+ const { error, value } = schema2.validate({ _id: req.params.id });
43035
+ if (error) {
43036
+ logger151.log({ level: "error", message: error.message });
43037
+ next(new BadRequestError174(error.message));
43038
+ return;
43039
+ }
43040
+ const { _id } = value;
42938
43041
  const data = await _getOccurrenceSubjectById(_id);
42939
43042
  res.status(200).json(data);
42940
43043
  return;
42941
- } catch (error2) {
42942
- logger151.log({ level: "error", message: error2.message });
42943
- next(error2);
43044
+ } catch (error) {
43045
+ logger151.log({ level: "error", message: error.message });
43046
+ next(error);
42944
43047
  return;
42945
43048
  }
42946
43049
  }
42947
43050
  async function updateOccurrenceSubjectById(req, res, next) {
42948
- const _id = req.params.id;
42949
- const payload = { _id, ...req.body };
42950
- const { error } = schemaUpdateOccurrenceSubject.validate(payload, {
42951
- abortEarly: false
42952
- });
42953
- if (error) {
42954
- const messages = error.details.map((d) => d.message).join(", ");
42955
- logger151.log({ level: "error", message: messages });
42956
- next(new BadRequestError174(messages));
42957
- return;
42958
- }
42959
43051
  try {
42960
- const result = await _updateOccurrenceSubjectById(_id, req.body);
43052
+ const { error, value } = schemaUpdateOccurrenceSubject.validate(
43053
+ { _id: req.params.id, ...req.body },
43054
+ {
43055
+ abortEarly: false
43056
+ }
43057
+ );
43058
+ if (error) {
43059
+ const messages = error.details.map((d) => d.message).join(", ");
43060
+ logger151.log({ level: "error", message: messages });
43061
+ next(new BadRequestError174(messages));
43062
+ return;
43063
+ }
43064
+ const { _id, ...rest } = value;
43065
+ const result = await _updateOccurrenceSubjectById(_id, rest);
42961
43066
  res.status(200).json({ message: result });
42962
43067
  return;
42963
- } catch (error2) {
42964
- logger151.log({ level: "error", message: error2.message });
42965
- next(error2);
43068
+ } catch (error) {
43069
+ logger151.log({ level: "error", message: error.message });
43070
+ next(error);
42966
43071
  return;
42967
43072
  }
42968
43073
  }
@@ -50288,6 +50393,8 @@ export {
50288
50393
  EAccessCardTypes,
50289
50394
  EAccessCardUserTypes,
50290
50395
  EmailSender,
50396
+ EntryOrder,
50397
+ EntrySort,
50291
50398
  FacilitySort,
50292
50399
  FacilityStatus,
50293
50400
  GuestSort,
@@ -50369,6 +50476,8 @@ export {
50369
50476
  SortFields,
50370
50477
  SortOrder,
50371
50478
  Status,
50479
+ SubjectOrder,
50480
+ SubjectSort,
50372
50481
  SubscriptionType,
50373
50482
  UseAccessManagementRepo,
50374
50483
  UserStatus,
@@ -50424,6 +50533,7 @@ export {
50424
50533
  robotSchema,
50425
50534
  schema,
50426
50535
  schemaApprovedBy,
50536
+ schemaApprover,
50427
50537
  schemaBilling,
50428
50538
  schemaBillingConfiguration,
50429
50539
  schemaBillingItem,