@7365admin1/module-hygiene 4.5.0 → 4.7.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 +12 -0
- package/dist/index.d.ts +8 -4
- package/dist/index.js +53 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -217,10 +217,14 @@ type TCleaningScheduleArea = {
|
|
|
217
217
|
type TAreaChecklist = {
|
|
218
218
|
set: number;
|
|
219
219
|
units: TAreaChecklistUnits[];
|
|
220
|
+
remarks?: string;
|
|
221
|
+
attachment?: string[];
|
|
220
222
|
};
|
|
221
223
|
type TAreaChecklistUnits = {
|
|
222
224
|
unit: string | ObjectId;
|
|
223
225
|
name: string;
|
|
226
|
+
approve?: boolean;
|
|
227
|
+
reject?: boolean;
|
|
224
228
|
status?: (typeof allowedChecklistStatus)[number];
|
|
225
229
|
remarks?: string;
|
|
226
230
|
completedBy?: string | ObjectId;
|
|
@@ -240,7 +244,7 @@ type TCleaningScheduleAreaGetQuery = {
|
|
|
240
244
|
status?: (typeof allowedStatus)[number] | "all";
|
|
241
245
|
} & Pick<TCleaningScheduleArea, "schedule">;
|
|
242
246
|
type TAreaChecklistUpdate = Pick<TCleaningScheduleArea, "checklist">;
|
|
243
|
-
type TAreaChecklistUnitsUpdate = Pick<TAreaChecklistUnits, "remarks" | "completedBy">;
|
|
247
|
+
type TAreaChecklistUnitsUpdate = Pick<TAreaChecklistUnits, "approve" | "reject" | "remarks" | "completedBy"> & Pick<TAreaChecklist, "attachment">;
|
|
244
248
|
declare const areaChecklistSchema: Joi.ObjectSchema<any>;
|
|
245
249
|
declare function MAreaChecklist(value: TCleaningScheduleArea): {
|
|
246
250
|
schedule: string | ObjectId;
|
|
@@ -257,7 +261,7 @@ declare function MAreaChecklist(value: TCleaningScheduleArea): {
|
|
|
257
261
|
|
|
258
262
|
declare function useAreaChecklistService(): {
|
|
259
263
|
createAreaChecklist: (value: TAreaChecklistBatchCreate) => Promise<ObjectId[]>;
|
|
260
|
-
|
|
264
|
+
updateAreaChecklistUnits: (_id: string | ObjectId, set: number, unitId: string | ObjectId, value: TAreaChecklistUnitsUpdate) => Promise<void>;
|
|
261
265
|
};
|
|
262
266
|
|
|
263
267
|
interface AreaUnit {
|
|
@@ -314,7 +318,7 @@ declare function useAreaChecklistRepo(): {
|
|
|
314
318
|
getAreaChecklistByAreaAndSchedule: (schedule: string | ObjectId, area: string | ObjectId, session?: ClientSession) => Promise<mongodb.WithId<bson.Document>>;
|
|
315
319
|
updateAreaChecklist: (_id: string | ObjectId, value: TAreaChecklistUpdate, session?: ClientSession) => Promise<number>;
|
|
316
320
|
updateAreaChecklistStatus: (_id: string | ObjectId, status: (typeof allowedStatus)[number], session?: ClientSession) => Promise<number>;
|
|
317
|
-
|
|
321
|
+
updateAreaChecklistUnits: (_id: string | ObjectId, set: number, unitId: string | ObjectId, value: TAreaChecklistUnitsUpdate, session?: ClientSession) => Promise<number>;
|
|
318
322
|
getMaxSetNumberForArea: (areaId: string | ObjectId, session?: ClientSession) => Promise<any>;
|
|
319
323
|
};
|
|
320
324
|
|
|
@@ -324,7 +328,7 @@ declare function useAreaChecklistController(): {
|
|
|
324
328
|
getAreaChecklistHistory: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
325
329
|
getAreaChecklistHistoryDetails: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
326
330
|
getAreaChecklistUnits: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
327
|
-
|
|
331
|
+
updateAreaChecklistUnits: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
328
332
|
};
|
|
329
333
|
|
|
330
334
|
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: "",
|
|
@@ -3133,8 +3135,12 @@ function useAreaChecklistRepo() {
|
|
|
3133
3135
|
$project: {
|
|
3134
3136
|
_id: 0,
|
|
3135
3137
|
set: "$checklist.set",
|
|
3138
|
+
remarks: "$checklist.remarks",
|
|
3139
|
+
attachment: "$checklist.attachment",
|
|
3136
3140
|
unit: "$checklist.units.unit",
|
|
3137
3141
|
name: "$checklist.units.name",
|
|
3142
|
+
approve: "$checklist.units.approve",
|
|
3143
|
+
reject: "$checklist.units.reject",
|
|
3138
3144
|
status: {
|
|
3139
3145
|
$switch: {
|
|
3140
3146
|
branches: [
|
|
@@ -3149,18 +3155,21 @@ function useAreaChecklistRepo() {
|
|
|
3149
3155
|
],
|
|
3150
3156
|
default: "$checklist.units.status"
|
|
3151
3157
|
}
|
|
3152
|
-
}
|
|
3153
|
-
remarks: "$checklist.units.remarks"
|
|
3158
|
+
}
|
|
3154
3159
|
}
|
|
3155
3160
|
},
|
|
3156
3161
|
{ $sort: { set: 1, name: 1 } },
|
|
3157
3162
|
{
|
|
3158
3163
|
$group: {
|
|
3159
3164
|
_id: "$set",
|
|
3165
|
+
remarks: { $first: "$remarks" },
|
|
3166
|
+
attachment: { $first: "$attachment" },
|
|
3160
3167
|
units: {
|
|
3161
3168
|
$push: {
|
|
3162
3169
|
unit: "$unit",
|
|
3163
3170
|
name: "$name",
|
|
3171
|
+
approve: "$approve",
|
|
3172
|
+
reject: "$reject",
|
|
3164
3173
|
status: "$status",
|
|
3165
3174
|
remarks: "$remarks"
|
|
3166
3175
|
}
|
|
@@ -3171,6 +3180,8 @@ function useAreaChecklistRepo() {
|
|
|
3171
3180
|
$project: {
|
|
3172
3181
|
_id: 0,
|
|
3173
3182
|
set: "$_id",
|
|
3183
|
+
remarks: "$remarks",
|
|
3184
|
+
attachment: "$attachment",
|
|
3174
3185
|
units: 1
|
|
3175
3186
|
}
|
|
3176
3187
|
},
|
|
@@ -3245,7 +3256,7 @@ function useAreaChecklistRepo() {
|
|
|
3245
3256
|
throw error;
|
|
3246
3257
|
}
|
|
3247
3258
|
}
|
|
3248
|
-
async function
|
|
3259
|
+
async function updateAreaChecklistUnits(_id, set, unitId, value, session) {
|
|
3249
3260
|
try {
|
|
3250
3261
|
_id = new import_mongodb9.ObjectId(_id);
|
|
3251
3262
|
} catch (error) {
|
|
@@ -3260,12 +3271,26 @@ function useAreaChecklistRepo() {
|
|
|
3260
3271
|
const now = /* @__PURE__ */ new Date();
|
|
3261
3272
|
const updateValue = {
|
|
3262
3273
|
"checklist.$[checklist].units.$[unit].timestamp": now,
|
|
3263
|
-
"checklist.$[checklist].units.$[unit].status": "completed",
|
|
3264
3274
|
updatedAt: now
|
|
3265
3275
|
};
|
|
3276
|
+
if (value.approve === true) {
|
|
3277
|
+
updateValue["checklist.$[checklist].units.$[unit].approve"] = true;
|
|
3278
|
+
updateValue["checklist.$[checklist].units.$[unit].reject"] = false;
|
|
3279
|
+
updateValue["checklist.$[checklist].units.$[unit].status"] = "completed";
|
|
3280
|
+
} else if (value.reject === true) {
|
|
3281
|
+
updateValue["checklist.$[checklist].units.$[unit].approve"] = false;
|
|
3282
|
+
updateValue["checklist.$[checklist].units.$[unit].reject"] = true;
|
|
3283
|
+
updateValue["checklist.$[checklist].units.$[unit].status"] = "ready";
|
|
3284
|
+
}
|
|
3266
3285
|
if (value.remarks) {
|
|
3267
3286
|
updateValue["checklist.$[checklist].units.$[unit].remarks"] = value.remarks;
|
|
3268
3287
|
}
|
|
3288
|
+
if (value.attachment) {
|
|
3289
|
+
updateValue["checklist.$[checklist].attachment"] = value.attachment;
|
|
3290
|
+
if (value.remarks) {
|
|
3291
|
+
updateValue["checklist.$[checklist].remarks"] = value.remarks;
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3269
3294
|
if (value.completedBy) {
|
|
3270
3295
|
updateValue["checklist.$[checklist].units.$[unit].completedBy"] = new import_mongodb9.ObjectId(value.completedBy);
|
|
3271
3296
|
}
|
|
@@ -3393,7 +3418,7 @@ function useAreaChecklistRepo() {
|
|
|
3393
3418
|
getAreaChecklistByAreaAndSchedule,
|
|
3394
3419
|
updateAreaChecklist,
|
|
3395
3420
|
updateAreaChecklistStatus,
|
|
3396
|
-
|
|
3421
|
+
updateAreaChecklistUnits,
|
|
3397
3422
|
getMaxSetNumberForArea
|
|
3398
3423
|
};
|
|
3399
3424
|
}
|
|
@@ -3406,7 +3431,7 @@ function useAreaChecklistService() {
|
|
|
3406
3431
|
getAllAreaChecklist,
|
|
3407
3432
|
getAreaChecklistUnits,
|
|
3408
3433
|
getAreaChecklistById,
|
|
3409
|
-
|
|
3434
|
+
updateAreaChecklistUnits: _updateAreaChecklistUnits,
|
|
3410
3435
|
updateAreaChecklistStatus,
|
|
3411
3436
|
getMaxSetNumberForArea
|
|
3412
3437
|
} = useAreaChecklistRepo();
|
|
@@ -3477,11 +3502,11 @@ function useAreaChecklistService() {
|
|
|
3477
3502
|
session?.endSession();
|
|
3478
3503
|
}
|
|
3479
3504
|
}
|
|
3480
|
-
async function
|
|
3505
|
+
async function updateAreaChecklistUnits(_id, set, unitId, value) {
|
|
3481
3506
|
const session = import_node_server_utils18.useAtlas.getClient()?.startSession();
|
|
3482
3507
|
try {
|
|
3483
3508
|
session?.startTransaction();
|
|
3484
|
-
await
|
|
3509
|
+
await _updateAreaChecklistUnits(_id, set, unitId, value, session);
|
|
3485
3510
|
const allUnitsResult = await getAreaChecklistUnits(
|
|
3486
3511
|
{
|
|
3487
3512
|
page: 1,
|
|
@@ -3561,7 +3586,7 @@ function useAreaChecklistService() {
|
|
|
3561
3586
|
session?.endSession();
|
|
3562
3587
|
}
|
|
3563
3588
|
}
|
|
3564
|
-
return { createAreaChecklist,
|
|
3589
|
+
return { createAreaChecklist, updateAreaChecklistUnits };
|
|
3565
3590
|
}
|
|
3566
3591
|
|
|
3567
3592
|
// src/controllers/hygiene-area-checklist.controller.ts
|
|
@@ -3576,7 +3601,7 @@ function useAreaChecklistController() {
|
|
|
3576
3601
|
} = useAreaChecklistRepo();
|
|
3577
3602
|
const {
|
|
3578
3603
|
createAreaChecklist: _createAreaChecklist,
|
|
3579
|
-
|
|
3604
|
+
updateAreaChecklistUnits: _updateAreaChecklistUnits
|
|
3580
3605
|
} = useAreaChecklistService();
|
|
3581
3606
|
async function createAreaChecklist(req, res, next) {
|
|
3582
3607
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
@@ -3743,22 +3768,36 @@ function useAreaChecklistController() {
|
|
|
3743
3768
|
return;
|
|
3744
3769
|
}
|
|
3745
3770
|
}
|
|
3746
|
-
async function
|
|
3771
|
+
async function updateAreaChecklistUnits(req, res, next) {
|
|
3747
3772
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
3748
3773
|
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
3749
3774
|
{}
|
|
3750
3775
|
) : {};
|
|
3751
3776
|
const completedBy = cookies["user"] || "";
|
|
3777
|
+
const decisionMap = {
|
|
3778
|
+
approve: { approve: true, reject: false },
|
|
3779
|
+
reject: { approve: false, reject: true }
|
|
3780
|
+
};
|
|
3781
|
+
const decision = req.params.decision;
|
|
3782
|
+
const decisionValues = decisionMap[decision] || {
|
|
3783
|
+
approve: void 0,
|
|
3784
|
+
reject: void 0
|
|
3785
|
+
};
|
|
3752
3786
|
const payload = {
|
|
3753
3787
|
...req.params,
|
|
3754
3788
|
...req.body,
|
|
3789
|
+
...decisionValues,
|
|
3755
3790
|
completedBy
|
|
3756
3791
|
};
|
|
3757
3792
|
const validation = import_joi9.default.object({
|
|
3758
3793
|
id: import_joi9.default.string().hex().required(),
|
|
3759
3794
|
set: import_joi9.default.number().integer().min(1).required(),
|
|
3760
3795
|
unit: import_joi9.default.string().hex().required(),
|
|
3796
|
+
decision: import_joi9.default.string().valid("approve", "reject").required(),
|
|
3797
|
+
approve: import_joi9.default.boolean().optional(),
|
|
3798
|
+
reject: import_joi9.default.boolean().optional(),
|
|
3761
3799
|
remarks: import_joi9.default.string().optional().allow("", null),
|
|
3800
|
+
attachment: import_joi9.default.array().items(import_joi9.default.string()).optional(),
|
|
3762
3801
|
completedBy: import_joi9.default.string().hex().required()
|
|
3763
3802
|
});
|
|
3764
3803
|
const { error } = validation.validate(payload);
|
|
@@ -3768,13 +3807,8 @@ function useAreaChecklistController() {
|
|
|
3768
3807
|
return;
|
|
3769
3808
|
}
|
|
3770
3809
|
try {
|
|
3771
|
-
const { id, set, unit, ...value } = payload;
|
|
3772
|
-
await
|
|
3773
|
-
id,
|
|
3774
|
-
parseInt(set),
|
|
3775
|
-
unit,
|
|
3776
|
-
value
|
|
3777
|
-
);
|
|
3810
|
+
const { id, set, unit, decision: decision2, ...value } = payload;
|
|
3811
|
+
await _updateAreaChecklistUnits(id, parseInt(set), unit, value);
|
|
3778
3812
|
res.json({ message: "Area checklist updated successfully." });
|
|
3779
3813
|
return;
|
|
3780
3814
|
} catch (error2) {
|
|
@@ -3789,7 +3823,7 @@ function useAreaChecklistController() {
|
|
|
3789
3823
|
getAreaChecklistHistory,
|
|
3790
3824
|
getAreaChecklistHistoryDetails,
|
|
3791
3825
|
getAreaChecklistUnits,
|
|
3792
|
-
|
|
3826
|
+
updateAreaChecklistUnits
|
|
3793
3827
|
};
|
|
3794
3828
|
}
|
|
3795
3829
|
|