@7365admin1/module-hygiene 4.28.2-staging.10 → 4.29.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
@@ -5887,6 +5887,13 @@ function buildCheckOutDecision(decision, remarks, now = (/* @__PURE__ */ new Dat
5887
5887
  updatedAt: now
5888
5888
  };
5889
5889
  }
5890
+ async function applyCheckOutDecision(decision, decide, returnStock) {
5891
+ const decided = await decide();
5892
+ if (decided > 0 && decision === "disapprove") {
5893
+ await returnStock();
5894
+ }
5895
+ return decided;
5896
+ }
5890
5897
 
5891
5898
  // src/models/hygiene-checkout-item.model.ts
5892
5899
  import Joi14 from "joi";
@@ -6261,7 +6268,8 @@ function useCheckOutItemService() {
6261
6268
  const {
6262
6269
  createCheckOutItem: _createCheckOutItem,
6263
6270
  getCheckOutItemById: _getCheckOutItemById,
6264
- completeCheckOutItem
6271
+ completeCheckOutItem,
6272
+ decideCheckOutItem: _decideCheckOutItem
6265
6273
  } = useCheckOutItemRepository();
6266
6274
  const { getSupplyById } = useSupplyRepository();
6267
6275
  const { getUserById } = useUserRepo2();
@@ -6352,9 +6360,41 @@ function useCheckOutItemService() {
6352
6360
  await session?.endSession();
6353
6361
  }
6354
6362
  }
6363
+ async function decideCheckOutItem(_id, value) {
6364
+ const session = useAtlas13.getClient()?.startSession();
6365
+ try {
6366
+ session?.startTransaction();
6367
+ const checkOutItem = await _getCheckOutItemById(_id, session);
6368
+ if (!checkOutItem) {
6369
+ throw new BadRequestError26("Check out item not found.");
6370
+ }
6371
+ const decided = await applyCheckOutDecision(
6372
+ value.approve === true ? "approve" : "disapprove",
6373
+ () => _decideCheckOutItem(_id, value, session),
6374
+ () => createStock(
6375
+ {
6376
+ site: checkOutItem.site.toString(),
6377
+ serviceType: checkOutItem.serviceType,
6378
+ supply: checkOutItem.supply.toString(),
6379
+ qty: checkOutItem.qty
6380
+ },
6381
+ false,
6382
+ session
6383
+ )
6384
+ );
6385
+ await session?.commitTransaction();
6386
+ return decided;
6387
+ } catch (error) {
6388
+ await session?.abortTransaction();
6389
+ throw error;
6390
+ } finally {
6391
+ await session?.endSession();
6392
+ }
6393
+ }
6355
6394
  return {
6356
6395
  createCheckOutItem,
6357
- createCheckOutItemByBatch
6396
+ createCheckOutItemByBatch,
6397
+ decideCheckOutItem
6358
6398
  };
6359
6399
  }
6360
6400
 
@@ -6365,12 +6405,12 @@ import { AppServiceType as AppServiceType16 } from "@7365admin1/core";
6365
6405
  function useCheckOutItemController() {
6366
6406
  const {
6367
6407
  getCheckOutItems: _getCheckOutItems,
6368
- getCheckOutItemById: _getCheckOutItemById,
6369
- decideCheckOutItem: _decideCheckOutItem
6408
+ getCheckOutItemById: _getCheckOutItemById
6370
6409
  } = useCheckOutItemRepository();
6371
6410
  const {
6372
6411
  createCheckOutItem: _createCheckOutItem,
6373
- createCheckOutItemByBatch: _createCheckOutItemByBatch
6412
+ createCheckOutItemByBatch: _createCheckOutItemByBatch,
6413
+ decideCheckOutItem: _decideCheckOutItem
6374
6414
  } = useCheckOutItemService();
6375
6415
  async function createCheckOutItem(req, res, next) {
6376
6416
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
@@ -7618,6 +7658,7 @@ export {
7618
7658
  allowedPeriods,
7619
7659
  allowedStatus,
7620
7660
  allowedTypes,
7661
+ applyCheckOutDecision,
7621
7662
  areaChecklistSchema,
7622
7663
  areaSchema,
7623
7664
  buildCheckOutDecision,