@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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @7365admin1/module-hygiene
2
2
 
3
+ ## 4.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Hygiene Cleaning Schedule Area Approve and Reject
8
+
3
9
  ## 4.5.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -221,6 +221,8 @@ type TAreaChecklist = {
221
221
  type TAreaChecklistUnits = {
222
222
  unit: string | ObjectId;
223
223
  name: string;
224
+ approve?: boolean;
225
+ reject?: boolean;
224
226
  status?: (typeof allowedChecklistStatus)[number];
225
227
  remarks?: string;
226
228
  completedBy?: string | ObjectId;
@@ -240,7 +242,7 @@ type TCleaningScheduleAreaGetQuery = {
240
242
  status?: (typeof allowedStatus)[number] | "all";
241
243
  } & Pick<TCleaningScheduleArea, "schedule">;
242
244
  type TAreaChecklistUpdate = Pick<TCleaningScheduleArea, "checklist">;
243
- type TAreaChecklistUnitsUpdate = Pick<TAreaChecklistUnits, "remarks" | "completedBy">;
245
+ type TAreaChecklistUnitsUpdate = Pick<TAreaChecklistUnits, "approve" | "reject" | "remarks" | "completedBy">;
244
246
  declare const areaChecklistSchema: Joi.ObjectSchema<any>;
245
247
  declare function MAreaChecklist(value: TCleaningScheduleArea): {
246
248
  schedule: string | ObjectId;
@@ -257,7 +259,7 @@ declare function MAreaChecklist(value: TCleaningScheduleArea): {
257
259
 
258
260
  declare function useAreaChecklistService(): {
259
261
  createAreaChecklist: (value: TAreaChecklistBatchCreate) => Promise<ObjectId[]>;
260
- completeAreaChecklistUnits: (_id: string | ObjectId, set: number, unitId: string | ObjectId, value: TAreaChecklistUnitsUpdate) => Promise<void>;
262
+ updateAreaChecklistUnits: (_id: string | ObjectId, set: number, unitId: string | ObjectId, value: TAreaChecklistUnitsUpdate) => Promise<void>;
261
263
  };
262
264
 
263
265
  interface AreaUnit {
@@ -314,7 +316,7 @@ declare function useAreaChecklistRepo(): {
314
316
  getAreaChecklistByAreaAndSchedule: (schedule: string | ObjectId, area: string | ObjectId, session?: ClientSession) => Promise<mongodb.WithId<bson.Document>>;
315
317
  updateAreaChecklist: (_id: string | ObjectId, value: TAreaChecklistUpdate, session?: ClientSession) => Promise<number>;
316
318
  updateAreaChecklistStatus: (_id: string | ObjectId, status: (typeof allowedStatus)[number], session?: ClientSession) => Promise<number>;
317
- completeAreaChecklistUnits: (_id: string | ObjectId, set: number, unitId: string | ObjectId, value: TAreaChecklistUnitsUpdate, session?: ClientSession) => Promise<number>;
319
+ updateAreaChecklistUnits: (_id: string | ObjectId, set: number, unitId: string | ObjectId, value: TAreaChecklistUnitsUpdate, session?: ClientSession) => Promise<number>;
318
320
  getMaxSetNumberForArea: (areaId: string | ObjectId, session?: ClientSession) => Promise<any>;
319
321
  };
320
322
 
@@ -324,7 +326,7 @@ declare function useAreaChecklistController(): {
324
326
  getAreaChecklistHistory: (req: Request, res: Response, next: NextFunction) => Promise<void>;
325
327
  getAreaChecklistHistoryDetails: (req: Request, res: Response, next: NextFunction) => Promise<void>;
326
328
  getAreaChecklistUnits: (req: Request, res: Response, next: NextFunction) => Promise<void>;
327
- completeAreaChecklistUnits: (req: Request, res: Response, next: NextFunction) => Promise<void>;
329
+ updateAreaChecklistUnits: (req: Request, res: Response, next: NextFunction) => Promise<void>;
328
330
  };
329
331
 
330
332
  type TSupply = {
package/dist/index.js CHANGED
@@ -2599,6 +2599,8 @@ function MAreaChecklist(value) {
2599
2599
  units: checklistItem.units.map((unit) => ({
2600
2600
  unit: new import_mongodb8.ObjectId(unit.unit),
2601
2601
  name: unit.name,
2602
+ approve: false,
2603
+ reject: false,
2602
2604
  status: "ready",
2603
2605
  remarks: "",
2604
2606
  completedBy: "",
@@ -3245,7 +3247,7 @@ function useAreaChecklistRepo() {
3245
3247
  throw error;
3246
3248
  }
3247
3249
  }
3248
- async function completeAreaChecklistUnits(_id, set, unitId, value, session) {
3250
+ async function updateAreaChecklistUnits(_id, set, unitId, value, session) {
3249
3251
  try {
3250
3252
  _id = new import_mongodb9.ObjectId(_id);
3251
3253
  } catch (error) {
@@ -3260,9 +3262,17 @@ function useAreaChecklistRepo() {
3260
3262
  const now = /* @__PURE__ */ new Date();
3261
3263
  const updateValue = {
3262
3264
  "checklist.$[checklist].units.$[unit].timestamp": now,
3263
- "checklist.$[checklist].units.$[unit].status": "completed",
3264
3265
  updatedAt: now
3265
3266
  };
3267
+ if (value.approve === true) {
3268
+ updateValue["checklist.$[checklist].units.$[unit].approve"] = true;
3269
+ updateValue["checklist.$[checklist].units.$[unit].reject"] = false;
3270
+ updateValue["checklist.$[checklist].units.$[unit].status"] = "completed";
3271
+ } else if (value.reject === true) {
3272
+ updateValue["checklist.$[checklist].units.$[unit].approve"] = false;
3273
+ updateValue["checklist.$[checklist].units.$[unit].reject"] = true;
3274
+ updateValue["checklist.$[checklist].units.$[unit].status"] = "ready";
3275
+ }
3266
3276
  if (value.remarks) {
3267
3277
  updateValue["checklist.$[checklist].units.$[unit].remarks"] = value.remarks;
3268
3278
  }
@@ -3393,7 +3403,7 @@ function useAreaChecklistRepo() {
3393
3403
  getAreaChecklistByAreaAndSchedule,
3394
3404
  updateAreaChecklist,
3395
3405
  updateAreaChecklistStatus,
3396
- completeAreaChecklistUnits,
3406
+ updateAreaChecklistUnits,
3397
3407
  getMaxSetNumberForArea
3398
3408
  };
3399
3409
  }
@@ -3406,7 +3416,7 @@ function useAreaChecklistService() {
3406
3416
  getAllAreaChecklist,
3407
3417
  getAreaChecklistUnits,
3408
3418
  getAreaChecklistById,
3409
- completeAreaChecklistUnits: _completeAreaChecklistUnits,
3419
+ updateAreaChecklistUnits: _updateAreaChecklistUnits,
3410
3420
  updateAreaChecklistStatus,
3411
3421
  getMaxSetNumberForArea
3412
3422
  } = useAreaChecklistRepo();
@@ -3477,11 +3487,11 @@ function useAreaChecklistService() {
3477
3487
  session?.endSession();
3478
3488
  }
3479
3489
  }
3480
- async function completeAreaChecklistUnits(_id, set, unitId, value) {
3490
+ async function updateAreaChecklistUnits(_id, set, unitId, value) {
3481
3491
  const session = import_node_server_utils18.useAtlas.getClient()?.startSession();
3482
3492
  try {
3483
3493
  session?.startTransaction();
3484
- await _completeAreaChecklistUnits(_id, set, unitId, value, session);
3494
+ await _updateAreaChecklistUnits(_id, set, unitId, value, session);
3485
3495
  const allUnitsResult = await getAreaChecklistUnits(
3486
3496
  {
3487
3497
  page: 1,
@@ -3561,7 +3571,7 @@ function useAreaChecklistService() {
3561
3571
  session?.endSession();
3562
3572
  }
3563
3573
  }
3564
- return { createAreaChecklist, completeAreaChecklistUnits };
3574
+ return { createAreaChecklist, updateAreaChecklistUnits };
3565
3575
  }
3566
3576
 
3567
3577
  // src/controllers/hygiene-area-checklist.controller.ts
@@ -3576,7 +3586,7 @@ function useAreaChecklistController() {
3576
3586
  } = useAreaChecklistRepo();
3577
3587
  const {
3578
3588
  createAreaChecklist: _createAreaChecklist,
3579
- completeAreaChecklistUnits: _completeAreaChecklistUnits
3589
+ updateAreaChecklistUnits: _updateAreaChecklistUnits
3580
3590
  } = useAreaChecklistService();
3581
3591
  async function createAreaChecklist(req, res, next) {
3582
3592
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
@@ -3743,21 +3753,34 @@ function useAreaChecklistController() {
3743
3753
  return;
3744
3754
  }
3745
3755
  }
3746
- async function completeAreaChecklistUnits(req, res, next) {
3756
+ async function updateAreaChecklistUnits(req, res, next) {
3747
3757
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
3748
3758
  (acc, [key, value]) => ({ ...acc, [key]: value }),
3749
3759
  {}
3750
3760
  ) : {};
3751
3761
  const completedBy = cookies["user"] || "";
3762
+ const decisionMap = {
3763
+ approve: { approve: true, reject: false },
3764
+ reject: { approve: false, reject: true }
3765
+ };
3766
+ const decision = req.params.decision;
3767
+ const decisionValues = decisionMap[decision] || {
3768
+ approve: void 0,
3769
+ reject: void 0
3770
+ };
3752
3771
  const payload = {
3753
3772
  ...req.params,
3754
3773
  ...req.body,
3774
+ ...decisionValues,
3755
3775
  completedBy
3756
3776
  };
3757
3777
  const validation = import_joi9.default.object({
3758
3778
  id: import_joi9.default.string().hex().required(),
3759
3779
  set: import_joi9.default.number().integer().min(1).required(),
3760
3780
  unit: import_joi9.default.string().hex().required(),
3781
+ decision: import_joi9.default.string().valid("approve", "reject").required(),
3782
+ approve: import_joi9.default.boolean().optional(),
3783
+ reject: import_joi9.default.boolean().optional(),
3761
3784
  remarks: import_joi9.default.string().optional().allow("", null),
3762
3785
  completedBy: import_joi9.default.string().hex().required()
3763
3786
  });
@@ -3768,13 +3791,8 @@ function useAreaChecklistController() {
3768
3791
  return;
3769
3792
  }
3770
3793
  try {
3771
- const { id, set, unit, ...value } = payload;
3772
- await _completeAreaChecklistUnits(
3773
- id,
3774
- parseInt(set),
3775
- unit,
3776
- value
3777
- );
3794
+ const { id, set, unit, decision: decision2, ...value } = payload;
3795
+ await _updateAreaChecklistUnits(id, parseInt(set), unit, value);
3778
3796
  res.json({ message: "Area checklist updated successfully." });
3779
3797
  return;
3780
3798
  } catch (error2) {
@@ -3789,7 +3807,7 @@ function useAreaChecklistController() {
3789
3807
  getAreaChecklistHistory,
3790
3808
  getAreaChecklistHistoryDetails,
3791
3809
  getAreaChecklistUnits,
3792
- completeAreaChecklistUnits
3810
+ updateAreaChecklistUnits
3793
3811
  };
3794
3812
  }
3795
3813