@7365admin1/module-hygiene 4.28.1 → 4.28.2-staging.10

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
@@ -5871,6 +5871,23 @@ function useStockController() {
5871
5871
  };
5872
5872
  }
5873
5873
 
5874
+ // src/utils/hygiene-checkout-decision.util.ts
5875
+ var CHECKOUT_DECISIONS = ["approve", "disapprove"];
5876
+ function isCheckOutDecision(value) {
5877
+ return CHECKOUT_DECISIONS.includes(value);
5878
+ }
5879
+ var CHECKOUT_DECIDABLE_STATUS = "pending";
5880
+ function buildCheckOutDecision(decision, remarks, now = (/* @__PURE__ */ new Date()).toISOString()) {
5881
+ const approve = decision === "approve";
5882
+ return {
5883
+ approve,
5884
+ reject: !approve,
5885
+ status: "completed",
5886
+ remarks: remarks ?? "",
5887
+ updatedAt: now
5888
+ };
5889
+ }
5890
+
5874
5891
  // src/models/hygiene-checkout-item.model.ts
5875
5892
  import Joi14 from "joi";
5876
5893
  import { ObjectId as ObjectId16 } from "mongodb";
@@ -5919,6 +5936,10 @@ function MCheckOutItem(value) {
5919
5936
  createdBy: value.createdBy,
5920
5937
  createdByName: value.createdByName,
5921
5938
  status: "pending",
5939
+ approve: false,
5940
+ reject: false,
5941
+ remarks: "",
5942
+ completedBy: "",
5922
5943
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
5923
5944
  updatedAt: "",
5924
5945
  deletedAt: ""
@@ -6058,7 +6079,10 @@ function useCheckOutItemRepository() {
6058
6079
  profile: "$createdByDoc.profile",
6059
6080
  checkOutQty: "$qty",
6060
6081
  createdAt: 1,
6061
- status: 1
6082
+ status: 1,
6083
+ approve: 1,
6084
+ reject: 1,
6085
+ remarks: 1
6062
6086
  }
6063
6087
  },
6064
6088
  { $sort: { _id: -1 } },
@@ -6124,7 +6148,10 @@ function useCheckOutItemRepository() {
6124
6148
  status: 1,
6125
6149
  unitOfMeasurement: "$supplyDetails.unitOfMeasurement",
6126
6150
  stockQty: "$supplyQty",
6127
- attachment: 1
6151
+ attachment: 1,
6152
+ approve: 1,
6153
+ reject: 1,
6154
+ remarks: 1
6128
6155
  }
6129
6156
  }
6130
6157
  ],
@@ -6175,13 +6202,55 @@ function useCheckOutItemRepository() {
6175
6202
  throw error;
6176
6203
  }
6177
6204
  }
6205
+ async function decideCheckOutItem(_id, value, session) {
6206
+ try {
6207
+ _id = new ObjectId17(_id);
6208
+ } catch (error) {
6209
+ throw new BadRequestError25("Invalid check out item ID format.");
6210
+ }
6211
+ const updateValue = buildCheckOutDecision(
6212
+ value.approve === true ? "approve" : "disapprove",
6213
+ value.remarks
6214
+ );
6215
+ if (value.completedBy) {
6216
+ try {
6217
+ updateValue.completedBy = new ObjectId17(value.completedBy);
6218
+ } catch (error) {
6219
+ throw new BadRequestError25("Invalid user ID format.");
6220
+ }
6221
+ }
6222
+ try {
6223
+ const res = await collection.updateOne(
6224
+ { _id, status: CHECKOUT_DECIDABLE_STATUS },
6225
+ { $set: updateValue },
6226
+ { session }
6227
+ );
6228
+ if (res.matchedCount === 0) {
6229
+ throw new NotFoundError6(
6230
+ "Check out item not found or is no longer pending approval."
6231
+ );
6232
+ }
6233
+ delNamespace().then(() => {
6234
+ logger28.info(`Cache cleared for namespace: ${namespace_collection}`);
6235
+ }).catch((err) => {
6236
+ logger28.error(
6237
+ `Failed to clear cache for namespace: ${namespace_collection}`,
6238
+ err
6239
+ );
6240
+ });
6241
+ return res.modifiedCount;
6242
+ } catch (error) {
6243
+ throw error;
6244
+ }
6245
+ }
6178
6246
  return {
6179
6247
  createIndex,
6180
6248
  createTextIndex,
6181
6249
  createCheckOutItem,
6182
6250
  getCheckOutItems,
6183
6251
  getCheckOutItemById,
6184
- completeCheckOutItem
6252
+ completeCheckOutItem,
6253
+ decideCheckOutItem
6185
6254
  };
6186
6255
  }
6187
6256
 
@@ -6296,7 +6365,8 @@ import { AppServiceType as AppServiceType16 } from "@7365admin1/core";
6296
6365
  function useCheckOutItemController() {
6297
6366
  const {
6298
6367
  getCheckOutItems: _getCheckOutItems,
6299
- getCheckOutItemById: _getCheckOutItemById
6368
+ getCheckOutItemById: _getCheckOutItemById,
6369
+ decideCheckOutItem: _decideCheckOutItem
6300
6370
  } = useCheckOutItemRepository();
6301
6371
  const {
6302
6372
  createCheckOutItem: _createCheckOutItem,
@@ -6431,11 +6501,60 @@ function useCheckOutItemController() {
6431
6501
  return;
6432
6502
  }
6433
6503
  }
6504
+ async function decideCheckOutItem(req, res, next) {
6505
+ const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
6506
+ (acc, [key, value]) => ({ ...acc, [key]: value }),
6507
+ {}
6508
+ ) : {};
6509
+ const completedBy = cookies["user"] || "";
6510
+ const decisionMap = {
6511
+ approve: { approve: true, reject: false },
6512
+ disapprove: { approve: false, reject: true }
6513
+ };
6514
+ const decision = req.params.decision;
6515
+ const decisionValues = decisionMap[decision] || {
6516
+ approve: void 0,
6517
+ reject: void 0
6518
+ };
6519
+ const payload = {
6520
+ ...req.params,
6521
+ ...req.body,
6522
+ ...decisionValues,
6523
+ completedBy
6524
+ };
6525
+ const validation = Joi15.object({
6526
+ id: Joi15.string().hex().required(),
6527
+ decision: Joi15.string().valid("approve", "disapprove").required(),
6528
+ approve: Joi15.boolean().required(),
6529
+ reject: Joi15.boolean().required(),
6530
+ remarks: Joi15.string().optional().allow("", null),
6531
+ completedBy: Joi15.string().hex().required()
6532
+ });
6533
+ const { error } = validation.validate(payload);
6534
+ if (error) {
6535
+ logger29.log({ level: "error", message: error.message });
6536
+ next(new BadRequestError27(error.message));
6537
+ return;
6538
+ }
6539
+ try {
6540
+ const { id, decision: _d, ...value } = payload;
6541
+ await _decideCheckOutItem(id, value);
6542
+ res.json({
6543
+ message: `Check out item ${decision === "approve" ? "approved" : "disapproved"} successfully.`
6544
+ });
6545
+ return;
6546
+ } catch (error2) {
6547
+ logger29.log({ level: "error", message: error2.message });
6548
+ next(error2);
6549
+ return;
6550
+ }
6551
+ }
6434
6552
  return {
6435
6553
  createCheckOutItem,
6436
6554
  createCheckOutItemByBatch,
6437
6555
  getCheckOutItems,
6438
- getCheckOutItemById
6556
+ getCheckOutItemById,
6557
+ decideCheckOutItem
6439
6558
  };
6440
6559
  }
6441
6560
 
@@ -7484,6 +7603,8 @@ function useQRController() {
7484
7603
  };
7485
7604
  }
7486
7605
  export {
7606
+ CHECKOUT_DECIDABLE_STATUS,
7607
+ CHECKOUT_DECISIONS,
7487
7608
  MArea,
7488
7609
  MAreaChecklist,
7489
7610
  MCheckOutItem,
@@ -7499,7 +7620,9 @@ export {
7499
7620
  allowedTypes,
7500
7621
  areaChecklistSchema,
7501
7622
  areaSchema,
7623
+ buildCheckOutDecision,
7502
7624
  checkOutItemSchema,
7625
+ isCheckOutDecision,
7503
7626
  parentChecklistSchema,
7504
7627
  scheduleTaskSchema,
7505
7628
  stockSchema,