@7365admin1/module-hygiene 4.9.0 → 4.11.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 +1 -0
- package/dist/index.js +85 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +90 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -2651,7 +2651,12 @@ function MAreaChecklist(value) {
|
|
|
2651
2651
|
}
|
|
2652
2652
|
|
|
2653
2653
|
// src/services/hygiene-area-checklist.service.ts
|
|
2654
|
-
import {
|
|
2654
|
+
import {
|
|
2655
|
+
logger as logger18,
|
|
2656
|
+
UnauthorizedError,
|
|
2657
|
+
useAtlas as useAtlas7
|
|
2658
|
+
} from "@7365admin1/node-server-utils";
|
|
2659
|
+
import { useUserRepo } from "@7365admin1/core";
|
|
2655
2660
|
|
|
2656
2661
|
// src/repositories/hygiene-area-checklist.repository.ts
|
|
2657
2662
|
import { ObjectId as ObjectId9 } from "mongodb";
|
|
@@ -2808,6 +2813,22 @@ function useAreaChecklistRepo() {
|
|
|
2808
2813
|
preserveNullAndEmptyArrays: true
|
|
2809
2814
|
}
|
|
2810
2815
|
},
|
|
2816
|
+
{
|
|
2817
|
+
$addFields: {
|
|
2818
|
+
statusOrder: {
|
|
2819
|
+
$switch: {
|
|
2820
|
+
branches: [
|
|
2821
|
+
{ case: { $eq: ["$status", "open"] }, then: 0 },
|
|
2822
|
+
{ case: { $eq: ["$status", "ongoing"] }, then: 1 },
|
|
2823
|
+
{ case: { $eq: ["$status", "completed"] }, then: 3 },
|
|
2824
|
+
{ case: { $eq: ["$status", "closed"] }, then: 4 }
|
|
2825
|
+
],
|
|
2826
|
+
default: 2
|
|
2827
|
+
}
|
|
2828
|
+
}
|
|
2829
|
+
}
|
|
2830
|
+
},
|
|
2831
|
+
{ $sort: { statusOrder: 1, _id: -1 } },
|
|
2811
2832
|
{
|
|
2812
2833
|
$project: {
|
|
2813
2834
|
name: 1,
|
|
@@ -2847,7 +2868,6 @@ function useAreaChecklistRepo() {
|
|
|
2847
2868
|
createdByName: "$createdByDoc.name"
|
|
2848
2869
|
}
|
|
2849
2870
|
},
|
|
2850
|
-
{ $sort: { _id: -1 } },
|
|
2851
2871
|
{ $skip: page * limit },
|
|
2852
2872
|
{ $limit: limit }
|
|
2853
2873
|
];
|
|
@@ -3177,7 +3197,19 @@ function useAreaChecklistRepo() {
|
|
|
3177
3197
|
},
|
|
3178
3198
|
{
|
|
3179
3199
|
$addFields: {
|
|
3180
|
-
isCompleted: { $ne: ["$checklist.units.completedBy", ""] }
|
|
3200
|
+
isCompleted: { $ne: ["$checklist.units.completedBy", ""] },
|
|
3201
|
+
isActioned: {
|
|
3202
|
+
$cond: {
|
|
3203
|
+
if: {
|
|
3204
|
+
$or: [
|
|
3205
|
+
{ $eq: ["$checklist.units.approve", true] },
|
|
3206
|
+
{ $eq: ["$checklist.units.reject", true] }
|
|
3207
|
+
]
|
|
3208
|
+
},
|
|
3209
|
+
then: 1,
|
|
3210
|
+
else: 0
|
|
3211
|
+
}
|
|
3212
|
+
}
|
|
3181
3213
|
}
|
|
3182
3214
|
},
|
|
3183
3215
|
{
|
|
@@ -3206,7 +3238,14 @@ function useAreaChecklistRepo() {
|
|
|
3206
3238
|
preserveNullAndEmptyArrays: true
|
|
3207
3239
|
}
|
|
3208
3240
|
},
|
|
3209
|
-
{
|
|
3241
|
+
{
|
|
3242
|
+
$sort: {
|
|
3243
|
+
set: 1,
|
|
3244
|
+
isActioned: 1,
|
|
3245
|
+
"checklist.units.timestamp": 1,
|
|
3246
|
+
isCompleted: -1
|
|
3247
|
+
}
|
|
3248
|
+
},
|
|
3210
3249
|
{
|
|
3211
3250
|
$project: {
|
|
3212
3251
|
_id: 0,
|
|
@@ -3217,6 +3256,7 @@ function useAreaChecklistRepo() {
|
|
|
3217
3256
|
name: "$checklist.units.name",
|
|
3218
3257
|
approve: "$checklist.units.approve",
|
|
3219
3258
|
reject: "$checklist.units.reject",
|
|
3259
|
+
timestamp: "$checklist.units.timestamp",
|
|
3220
3260
|
status: {
|
|
3221
3261
|
$switch: {
|
|
3222
3262
|
branches: [
|
|
@@ -3251,6 +3291,7 @@ function useAreaChecklistRepo() {
|
|
|
3251
3291
|
name: "$name",
|
|
3252
3292
|
approve: "$approve",
|
|
3253
3293
|
reject: "$reject",
|
|
3294
|
+
timestamp: "$timestamp",
|
|
3254
3295
|
status: "$status",
|
|
3255
3296
|
remarks: "$remarks",
|
|
3256
3297
|
completedByName: "$completedByName"
|
|
@@ -3268,7 +3309,25 @@ function useAreaChecklistRepo() {
|
|
|
3268
3309
|
units: 1
|
|
3269
3310
|
}
|
|
3270
3311
|
},
|
|
3271
|
-
{
|
|
3312
|
+
{
|
|
3313
|
+
$addFields: {
|
|
3314
|
+
isFullyActioned: {
|
|
3315
|
+
$allElementsTrue: {
|
|
3316
|
+
$map: {
|
|
3317
|
+
input: "$units",
|
|
3318
|
+
as: "u",
|
|
3319
|
+
in: {
|
|
3320
|
+
$or: [
|
|
3321
|
+
{ $eq: ["$$u.approve", true] },
|
|
3322
|
+
{ $eq: ["$$u.reject", true] }
|
|
3323
|
+
]
|
|
3324
|
+
}
|
|
3325
|
+
}
|
|
3326
|
+
}
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3329
|
+
},
|
|
3330
|
+
{ $sort: { isFullyActioned: 1 } },
|
|
3272
3331
|
{ $skip: page * limit },
|
|
3273
3332
|
{ $limit: limit }
|
|
3274
3333
|
];
|
|
@@ -3472,6 +3531,20 @@ function useAreaChecklistRepo() {
|
|
|
3472
3531
|
throw error;
|
|
3473
3532
|
}
|
|
3474
3533
|
}
|
|
3534
|
+
async function getAreaChecklistSetOwner(_id, set, session) {
|
|
3535
|
+
try {
|
|
3536
|
+
_id = new ObjectId9(_id);
|
|
3537
|
+
} catch (error) {
|
|
3538
|
+
throw new BadRequestError15("Invalid area checklist ID format.");
|
|
3539
|
+
}
|
|
3540
|
+
const existing = await collection.findOne(
|
|
3541
|
+
{ _id, "checklist.set": set },
|
|
3542
|
+
{ projection: { "checklist.$": 1 }, session }
|
|
3543
|
+
);
|
|
3544
|
+
if (!existing?.checklist?.length)
|
|
3545
|
+
return null;
|
|
3546
|
+
return existing.checklist[0].units.map((u) => u.completedBy).find((cb) => cb && cb.toString() !== "") ?? null;
|
|
3547
|
+
}
|
|
3475
3548
|
async function getMaxSetNumberForArea(areaId, session) {
|
|
3476
3549
|
try {
|
|
3477
3550
|
const _id = new ObjectId9(areaId);
|
|
@@ -3535,6 +3608,7 @@ function useAreaChecklistRepo() {
|
|
|
3535
3608
|
getAreaChecklistUnits,
|
|
3536
3609
|
getAreaChecklistById,
|
|
3537
3610
|
getAreaChecklistByAreaAndSchedule,
|
|
3611
|
+
getAreaChecklistSetOwner,
|
|
3538
3612
|
updateAreaChecklist,
|
|
3539
3613
|
updateAreaChecklistStatus,
|
|
3540
3614
|
updateAreaChecklistUnits,
|
|
@@ -3551,11 +3625,13 @@ function useAreaChecklistService() {
|
|
|
3551
3625
|
getAllAreaChecklist,
|
|
3552
3626
|
getAreaChecklistUnits,
|
|
3553
3627
|
getAreaChecklistById,
|
|
3628
|
+
getAreaChecklistSetOwner,
|
|
3554
3629
|
updateAreaChecklistUnits: _updateAreaChecklistUnits,
|
|
3555
3630
|
updateAreaChecklistStatus,
|
|
3556
3631
|
getMaxSetNumberForArea
|
|
3557
3632
|
} = useAreaChecklistRepo();
|
|
3558
3633
|
const { updateParentChecklistStatuses } = useParentChecklistRepo();
|
|
3634
|
+
const { getUserById } = useUserRepo();
|
|
3559
3635
|
async function createAreaChecklist(value) {
|
|
3560
3636
|
const session = useAtlas7.getClient()?.startSession();
|
|
3561
3637
|
try {
|
|
@@ -3626,6 +3702,13 @@ function useAreaChecklistService() {
|
|
|
3626
3702
|
const session = useAtlas7.getClient()?.startSession();
|
|
3627
3703
|
try {
|
|
3628
3704
|
session?.startTransaction();
|
|
3705
|
+
const setOwner = await getAreaChecklistSetOwner(_id, set, session);
|
|
3706
|
+
if (setOwner && value.completedBy && setOwner.toString() !== value.completedBy.toString()) {
|
|
3707
|
+
const acceptedBy = await getUserById(setOwner.toString());
|
|
3708
|
+
throw new UnauthorizedError(
|
|
3709
|
+
`${acceptedBy.name} has already taken this set.`
|
|
3710
|
+
);
|
|
3711
|
+
}
|
|
3629
3712
|
await _updateAreaChecklistUnits(_id, set, unitId, value, session);
|
|
3630
3713
|
const allUnitsResult = await getAreaChecklistUnits(
|
|
3631
3714
|
{
|
|
@@ -5223,7 +5306,7 @@ function useCheckOutItemRepository() {
|
|
|
5223
5306
|
}
|
|
5224
5307
|
|
|
5225
5308
|
// src/services/hygiene-checkout-item.service.ts
|
|
5226
|
-
import { useUserRepo } from "@7365admin1/core";
|
|
5309
|
+
import { useUserRepo as useUserRepo2 } from "@7365admin1/core";
|
|
5227
5310
|
import { BadRequestError as BadRequestError26, useAtlas as useAtlas13 } from "@7365admin1/node-server-utils";
|
|
5228
5311
|
function useCheckOutItemService() {
|
|
5229
5312
|
const {
|
|
@@ -5232,7 +5315,7 @@ function useCheckOutItemService() {
|
|
|
5232
5315
|
completeCheckOutItem
|
|
5233
5316
|
} = useCheckOutItemRepository();
|
|
5234
5317
|
const { getSupplyById } = useSupplyRepository();
|
|
5235
|
-
const { getUserById } =
|
|
5318
|
+
const { getUserById } = useUserRepo2();
|
|
5236
5319
|
const { createStock } = useStockService();
|
|
5237
5320
|
async function createCheckOutItem(value) {
|
|
5238
5321
|
const session = useAtlas13.getClient()?.startSession();
|