@7365admin1/module-hygiene 4.5.0 → 4.6.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
@@ -2556,6 +2556,8 @@ function MAreaChecklist(value) {
2556
2556
  units: checklistItem.units.map((unit) => ({
2557
2557
  unit: new ObjectId8(unit.unit),
2558
2558
  name: unit.name,
2559
+ approve: false,
2560
+ reject: false,
2559
2561
  status: "ready",
2560
2562
  remarks: "",
2561
2563
  completedBy: "",
@@ -3210,7 +3212,7 @@ function useAreaChecklistRepo() {
3210
3212
  throw error;
3211
3213
  }
3212
3214
  }
3213
- async function completeAreaChecklistUnits(_id, set, unitId, value, session) {
3215
+ async function updateAreaChecklistUnits(_id, set, unitId, value, session) {
3214
3216
  try {
3215
3217
  _id = new ObjectId9(_id);
3216
3218
  } catch (error) {
@@ -3225,9 +3227,17 @@ function useAreaChecklistRepo() {
3225
3227
  const now = /* @__PURE__ */ new Date();
3226
3228
  const updateValue = {
3227
3229
  "checklist.$[checklist].units.$[unit].timestamp": now,
3228
- "checklist.$[checklist].units.$[unit].status": "completed",
3229
3230
  updatedAt: now
3230
3231
  };
3232
+ if (value.approve === true) {
3233
+ updateValue["checklist.$[checklist].units.$[unit].approve"] = true;
3234
+ updateValue["checklist.$[checklist].units.$[unit].reject"] = false;
3235
+ updateValue["checklist.$[checklist].units.$[unit].status"] = "completed";
3236
+ } else if (value.reject === true) {
3237
+ updateValue["checklist.$[checklist].units.$[unit].approve"] = false;
3238
+ updateValue["checklist.$[checklist].units.$[unit].reject"] = true;
3239
+ updateValue["checklist.$[checklist].units.$[unit].status"] = "ready";
3240
+ }
3231
3241
  if (value.remarks) {
3232
3242
  updateValue["checklist.$[checklist].units.$[unit].remarks"] = value.remarks;
3233
3243
  }
@@ -3358,7 +3368,7 @@ function useAreaChecklistRepo() {
3358
3368
  getAreaChecklistByAreaAndSchedule,
3359
3369
  updateAreaChecklist,
3360
3370
  updateAreaChecklistStatus,
3361
- completeAreaChecklistUnits,
3371
+ updateAreaChecklistUnits,
3362
3372
  getMaxSetNumberForArea
3363
3373
  };
3364
3374
  }
@@ -3371,7 +3381,7 @@ function useAreaChecklistService() {
3371
3381
  getAllAreaChecklist,
3372
3382
  getAreaChecklistUnits,
3373
3383
  getAreaChecklistById,
3374
- completeAreaChecklistUnits: _completeAreaChecklistUnits,
3384
+ updateAreaChecklistUnits: _updateAreaChecklistUnits,
3375
3385
  updateAreaChecklistStatus,
3376
3386
  getMaxSetNumberForArea
3377
3387
  } = useAreaChecklistRepo();
@@ -3442,11 +3452,11 @@ function useAreaChecklistService() {
3442
3452
  session?.endSession();
3443
3453
  }
3444
3454
  }
3445
- async function completeAreaChecklistUnits(_id, set, unitId, value) {
3455
+ async function updateAreaChecklistUnits(_id, set, unitId, value) {
3446
3456
  const session = useAtlas7.getClient()?.startSession();
3447
3457
  try {
3448
3458
  session?.startTransaction();
3449
- await _completeAreaChecklistUnits(_id, set, unitId, value, session);
3459
+ await _updateAreaChecklistUnits(_id, set, unitId, value, session);
3450
3460
  const allUnitsResult = await getAreaChecklistUnits(
3451
3461
  {
3452
3462
  page: 1,
@@ -3526,7 +3536,7 @@ function useAreaChecklistService() {
3526
3536
  session?.endSession();
3527
3537
  }
3528
3538
  }
3529
- return { createAreaChecklist, completeAreaChecklistUnits };
3539
+ return { createAreaChecklist, updateAreaChecklistUnits };
3530
3540
  }
3531
3541
 
3532
3542
  // src/controllers/hygiene-area-checklist.controller.ts
@@ -3541,7 +3551,7 @@ function useAreaChecklistController() {
3541
3551
  } = useAreaChecklistRepo();
3542
3552
  const {
3543
3553
  createAreaChecklist: _createAreaChecklist,
3544
- completeAreaChecklistUnits: _completeAreaChecklistUnits
3554
+ updateAreaChecklistUnits: _updateAreaChecklistUnits
3545
3555
  } = useAreaChecklistService();
3546
3556
  async function createAreaChecklist(req, res, next) {
3547
3557
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
@@ -3708,21 +3718,34 @@ function useAreaChecklistController() {
3708
3718
  return;
3709
3719
  }
3710
3720
  }
3711
- async function completeAreaChecklistUnits(req, res, next) {
3721
+ async function updateAreaChecklistUnits(req, res, next) {
3712
3722
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
3713
3723
  (acc, [key, value]) => ({ ...acc, [key]: value }),
3714
3724
  {}
3715
3725
  ) : {};
3716
3726
  const completedBy = cookies["user"] || "";
3727
+ const decisionMap = {
3728
+ approve: { approve: true, reject: false },
3729
+ reject: { approve: false, reject: true }
3730
+ };
3731
+ const decision = req.params.decision;
3732
+ const decisionValues = decisionMap[decision] || {
3733
+ approve: void 0,
3734
+ reject: void 0
3735
+ };
3717
3736
  const payload = {
3718
3737
  ...req.params,
3719
3738
  ...req.body,
3739
+ ...decisionValues,
3720
3740
  completedBy
3721
3741
  };
3722
3742
  const validation = Joi9.object({
3723
3743
  id: Joi9.string().hex().required(),
3724
3744
  set: Joi9.number().integer().min(1).required(),
3725
3745
  unit: Joi9.string().hex().required(),
3746
+ decision: Joi9.string().valid("approve", "reject").required(),
3747
+ approve: Joi9.boolean().optional(),
3748
+ reject: Joi9.boolean().optional(),
3726
3749
  remarks: Joi9.string().optional().allow("", null),
3727
3750
  completedBy: Joi9.string().hex().required()
3728
3751
  });
@@ -3733,13 +3756,8 @@ function useAreaChecklistController() {
3733
3756
  return;
3734
3757
  }
3735
3758
  try {
3736
- const { id, set, unit, ...value } = payload;
3737
- await _completeAreaChecklistUnits(
3738
- id,
3739
- parseInt(set),
3740
- unit,
3741
- value
3742
- );
3759
+ const { id, set, unit, decision: decision2, ...value } = payload;
3760
+ await _updateAreaChecklistUnits(id, parseInt(set), unit, value);
3743
3761
  res.json({ message: "Area checklist updated successfully." });
3744
3762
  return;
3745
3763
  } catch (error2) {
@@ -3754,7 +3772,7 @@ function useAreaChecklistController() {
3754
3772
  getAreaChecklistHistory,
3755
3773
  getAreaChecklistHistoryDetails,
3756
3774
  getAreaChecklistUnits,
3757
- completeAreaChecklistUnits
3775
+ updateAreaChecklistUnits
3758
3776
  };
3759
3777
  }
3760
3778