@7365admin1/core 2.17.0 → 2.18.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
@@ -15772,6 +15772,7 @@ import {
15772
15772
  makeCacheKey as makeCacheKey26,
15773
15773
  NotFoundError as NotFoundError19,
15774
15774
  paginate as paginate21,
15775
+ toObjectId as toObjectId3,
15775
15776
  useAtlas as useAtlas38,
15776
15777
  useCache as useCache28
15777
15778
  } from "@7365admin1/node-server-utils";
@@ -15797,6 +15798,17 @@ var VehicleStatus = /* @__PURE__ */ ((VehicleStatus2) => {
15797
15798
  VehicleStatus2["DELETED"] = "deleted";
15798
15799
  return VehicleStatus2;
15799
15800
  })(VehicleStatus || {});
15801
+ var VehicleOrder = /* @__PURE__ */ ((VehicleOrder2) => {
15802
+ VehicleOrder2["ASC"] = "asc";
15803
+ VehicleOrder2["DESC"] = "desc";
15804
+ return VehicleOrder2;
15805
+ })(VehicleOrder || {});
15806
+ var VehicleSort = /* @__PURE__ */ ((VehicleSort2) => {
15807
+ VehicleSort2["CREATED_AT"] = "createdAt";
15808
+ VehicleSort2["ID"] = "_id";
15809
+ VehicleSort2["NAME"] = "name";
15810
+ return VehicleSort2;
15811
+ })(VehicleSort || {});
15800
15812
  var OrgNature = /* @__PURE__ */ ((OrgNature2) => {
15801
15813
  OrgNature2["PROPERTY_MANAGEMENT_AGENCY"] = "property_management_agency";
15802
15814
  OrgNature2["SECURITY_AGENCY"] = "security_agency";
@@ -16636,6 +16648,48 @@ function useVehicleRepo() {
16636
16648
  throw error;
16637
16649
  }
16638
16650
  }
16651
+ async function getAllVehiclesByUnitId({
16652
+ unitId,
16653
+ page = 1,
16654
+ limit = 10,
16655
+ sort = { _id: -1 }
16656
+ }) {
16657
+ try {
16658
+ const unit = toObjectId3(unitId);
16659
+ const cacheOptions = {
16660
+ unit: unitId,
16661
+ page,
16662
+ limit,
16663
+ sort: JSON.stringify(sort)
16664
+ };
16665
+ const cacheKey = makeCacheKey26(namespace_collection, cacheOptions);
16666
+ const cachedData = await getCache(cacheKey);
16667
+ if (cachedData) {
16668
+ logger62.info(`Cache hit for key: ${cacheKey}`);
16669
+ return cachedData;
16670
+ }
16671
+ const skip = (page - 1) * limit;
16672
+ const data = await collection.find(
16673
+ { unit },
16674
+ {
16675
+ projection: {
16676
+ createdAt: 0,
16677
+ updatedAt: 0,
16678
+ deletedAt: 0
16679
+ },
16680
+ sort,
16681
+ skip,
16682
+ limit
16683
+ }
16684
+ ).toArray();
16685
+ setCache(cacheKey, data, 15 * 60).then(() => logger62.info(`Cache set for key: ${cacheKey}`)).catch(
16686
+ (err) => logger62.error(`Failed to set cache for key: ${cacheKey}`, err)
16687
+ );
16688
+ return data;
16689
+ } catch (error) {
16690
+ throw error;
16691
+ }
16692
+ }
16639
16693
  return {
16640
16694
  createIndex,
16641
16695
  createTextIndex,
@@ -16648,7 +16702,8 @@ function useVehicleRepo() {
16648
16702
  getByPlaceNumber,
16649
16703
  getVehicleByPlateNumber,
16650
16704
  getVehiclesByNRIC,
16651
- deleteExpiredVehicles
16705
+ deleteExpiredVehicles,
16706
+ getAllVehiclesByUnitId
16652
16707
  };
16653
16708
  }
16654
16709
 
@@ -17685,7 +17740,8 @@ function useVehicleController() {
17685
17740
  getSeasonPassTypes: _getSeasonPassTypes,
17686
17741
  getVehicles: _getVehicles,
17687
17742
  getVehicleById: _getVehicleById,
17688
- getVehiclesByNRIC: _getVehiclesByNRIC
17743
+ getVehiclesByNRIC: _getVehiclesByNRIC,
17744
+ getAllVehiclesByUnitId: _getAllVehiclesByUnitId
17689
17745
  } = useVehicleRepo();
17690
17746
  async function add(req, res, next) {
17691
17747
  const payload = req.body;
@@ -17957,6 +18013,45 @@ function useVehicleController() {
17957
18013
  return;
17958
18014
  }
17959
18015
  }
18016
+ async function getAllVehiclesByUnitId(req, res, next) {
18017
+ const validation = Joi46.object({
18018
+ page: Joi46.number().min(1).optional().default(1),
18019
+ limit: Joi46.number().min(1).optional().default(10),
18020
+ sort: Joi46.string().valid(...Object.values(VehicleSort)).default("_id"),
18021
+ order: Joi46.string().valid(...Object.values(SortOrder)).default("desc" /* DESC */),
18022
+ unit: Joi46.string().hex().length(24).required()
18023
+ });
18024
+ const { error, value } = validation.validate(
18025
+ { unit: req.params.unitId, ...req.query },
18026
+ {
18027
+ abortEarly: false
18028
+ }
18029
+ );
18030
+ if (error) {
18031
+ const messages = error.details.map((d) => d.message);
18032
+ logger65.log({ level: "error", message: messages.join(", ") });
18033
+ next(new BadRequestError82(messages.join(", ")));
18034
+ return;
18035
+ }
18036
+ const { page, limit, unit, sort, order } = value;
18037
+ const sortObj = {
18038
+ [sort]: order === "asc" /* ASC */ ? 1 : -1
18039
+ };
18040
+ try {
18041
+ const data = await _getAllVehiclesByUnitId({
18042
+ unitId: unit,
18043
+ page,
18044
+ limit,
18045
+ sort: sortObj
18046
+ });
18047
+ res.json({ items: data });
18048
+ return;
18049
+ } catch (error2) {
18050
+ logger65.log({ level: "error", message: error2.message });
18051
+ next(error2);
18052
+ return;
18053
+ }
18054
+ }
17960
18055
  return {
17961
18056
  add,
17962
18057
  getVehicles,
@@ -17966,7 +18061,8 @@ function useVehicleController() {
17966
18061
  deleteVehicle,
17967
18062
  approveVehicleById,
17968
18063
  getVehiclesByNRIC,
17969
- reactivateVehicleById
18064
+ reactivateVehicleById,
18065
+ getAllVehiclesByUnitId
17970
18066
  };
17971
18067
  }
17972
18068
 
@@ -24801,8 +24897,7 @@ function useSiteFacilityBookingController() {
24801
24897
  deleteSiteFacilityBookingById: _deleteSiteFacilityBookingById
24802
24898
  } = useSiteFacilityBookingRepo();
24803
24899
  async function add(req, res, next) {
24804
- const payload = { ...req.body };
24805
- const { error } = schemaSiteFacilityBooking.validate(payload, {
24900
+ const { error, value } = schemaSiteFacilityBooking.validate(req.body, {
24806
24901
  abortEarly: false
24807
24902
  });
24808
24903
  if (error) {
@@ -24812,7 +24907,7 @@ function useSiteFacilityBookingController() {
24812
24907
  return;
24813
24908
  }
24814
24909
  try {
24815
- const data = await _add(payload);
24910
+ const data = await _add(value);
24816
24911
  res.status(201).json(data);
24817
24912
  return;
24818
24913
  } catch (error2) {
@@ -38335,6 +38430,8 @@ export {
38335
38430
  SortOrder,
38336
38431
  UseAccessManagementRepo,
38337
38432
  VehicleCategory,
38433
+ VehicleOrder,
38434
+ VehicleSort,
38338
38435
  VehicleStatus,
38339
38436
  VehicleType,
38340
38437
  allowedFieldsSite,