@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/CHANGELOG.md
CHANGED
package/dist/index.d.ts
CHANGED
|
@@ -317,6 +317,7 @@ declare function useAreaChecklistRepo(): {
|
|
|
317
317
|
}, session?: ClientSession) => Promise<{}>;
|
|
318
318
|
getAreaChecklistById: (_id: string | ObjectId, session?: ClientSession) => Promise<mongodb.WithId<bson.Document>>;
|
|
319
319
|
getAreaChecklistByAreaAndSchedule: (schedule: string | ObjectId, area: string | ObjectId, session?: ClientSession) => Promise<mongodb.WithId<bson.Document>>;
|
|
320
|
+
getAreaChecklistSetOwner: (_id: string | ObjectId, set: number, session?: ClientSession) => Promise<any>;
|
|
320
321
|
updateAreaChecklist: (_id: string | ObjectId, value: TAreaChecklistUpdate, session?: ClientSession) => Promise<number>;
|
|
321
322
|
updateAreaChecklistStatus: (_id: string | ObjectId, status: (typeof allowedStatus)[number], session?: ClientSession) => Promise<number>;
|
|
322
323
|
updateAreaChecklistUnits: (_id: string | ObjectId, set: number, unitId: string | ObjectId, value: TAreaChecklistUnitsUpdate, session?: ClientSession) => Promise<number>;
|
package/dist/index.js
CHANGED
|
@@ -2695,6 +2695,7 @@ function MAreaChecklist(value) {
|
|
|
2695
2695
|
|
|
2696
2696
|
// src/services/hygiene-area-checklist.service.ts
|
|
2697
2697
|
var import_node_server_utils18 = require("@7365admin1/node-server-utils");
|
|
2698
|
+
var import_core = require("@7365admin1/core");
|
|
2698
2699
|
|
|
2699
2700
|
// src/repositories/hygiene-area-checklist.repository.ts
|
|
2700
2701
|
var import_mongodb9 = require("mongodb");
|
|
@@ -2843,6 +2844,22 @@ function useAreaChecklistRepo() {
|
|
|
2843
2844
|
preserveNullAndEmptyArrays: true
|
|
2844
2845
|
}
|
|
2845
2846
|
},
|
|
2847
|
+
{
|
|
2848
|
+
$addFields: {
|
|
2849
|
+
statusOrder: {
|
|
2850
|
+
$switch: {
|
|
2851
|
+
branches: [
|
|
2852
|
+
{ case: { $eq: ["$status", "open"] }, then: 0 },
|
|
2853
|
+
{ case: { $eq: ["$status", "ongoing"] }, then: 1 },
|
|
2854
|
+
{ case: { $eq: ["$status", "completed"] }, then: 3 },
|
|
2855
|
+
{ case: { $eq: ["$status", "closed"] }, then: 4 }
|
|
2856
|
+
],
|
|
2857
|
+
default: 2
|
|
2858
|
+
}
|
|
2859
|
+
}
|
|
2860
|
+
}
|
|
2861
|
+
},
|
|
2862
|
+
{ $sort: { statusOrder: 1, _id: -1 } },
|
|
2846
2863
|
{
|
|
2847
2864
|
$project: {
|
|
2848
2865
|
name: 1,
|
|
@@ -2882,7 +2899,6 @@ function useAreaChecklistRepo() {
|
|
|
2882
2899
|
createdByName: "$createdByDoc.name"
|
|
2883
2900
|
}
|
|
2884
2901
|
},
|
|
2885
|
-
{ $sort: { _id: -1 } },
|
|
2886
2902
|
{ $skip: page * limit },
|
|
2887
2903
|
{ $limit: limit }
|
|
2888
2904
|
];
|
|
@@ -3212,7 +3228,19 @@ function useAreaChecklistRepo() {
|
|
|
3212
3228
|
},
|
|
3213
3229
|
{
|
|
3214
3230
|
$addFields: {
|
|
3215
|
-
isCompleted: { $ne: ["$checklist.units.completedBy", ""] }
|
|
3231
|
+
isCompleted: { $ne: ["$checklist.units.completedBy", ""] },
|
|
3232
|
+
isActioned: {
|
|
3233
|
+
$cond: {
|
|
3234
|
+
if: {
|
|
3235
|
+
$or: [
|
|
3236
|
+
{ $eq: ["$checklist.units.approve", true] },
|
|
3237
|
+
{ $eq: ["$checklist.units.reject", true] }
|
|
3238
|
+
]
|
|
3239
|
+
},
|
|
3240
|
+
then: 1,
|
|
3241
|
+
else: 0
|
|
3242
|
+
}
|
|
3243
|
+
}
|
|
3216
3244
|
}
|
|
3217
3245
|
},
|
|
3218
3246
|
{
|
|
@@ -3241,7 +3269,14 @@ function useAreaChecklistRepo() {
|
|
|
3241
3269
|
preserveNullAndEmptyArrays: true
|
|
3242
3270
|
}
|
|
3243
3271
|
},
|
|
3244
|
-
{
|
|
3272
|
+
{
|
|
3273
|
+
$sort: {
|
|
3274
|
+
set: 1,
|
|
3275
|
+
isActioned: 1,
|
|
3276
|
+
"checklist.units.timestamp": 1,
|
|
3277
|
+
isCompleted: -1
|
|
3278
|
+
}
|
|
3279
|
+
},
|
|
3245
3280
|
{
|
|
3246
3281
|
$project: {
|
|
3247
3282
|
_id: 0,
|
|
@@ -3252,6 +3287,7 @@ function useAreaChecklistRepo() {
|
|
|
3252
3287
|
name: "$checklist.units.name",
|
|
3253
3288
|
approve: "$checklist.units.approve",
|
|
3254
3289
|
reject: "$checklist.units.reject",
|
|
3290
|
+
timestamp: "$checklist.units.timestamp",
|
|
3255
3291
|
status: {
|
|
3256
3292
|
$switch: {
|
|
3257
3293
|
branches: [
|
|
@@ -3286,6 +3322,7 @@ function useAreaChecklistRepo() {
|
|
|
3286
3322
|
name: "$name",
|
|
3287
3323
|
approve: "$approve",
|
|
3288
3324
|
reject: "$reject",
|
|
3325
|
+
timestamp: "$timestamp",
|
|
3289
3326
|
status: "$status",
|
|
3290
3327
|
remarks: "$remarks",
|
|
3291
3328
|
completedByName: "$completedByName"
|
|
@@ -3303,7 +3340,25 @@ function useAreaChecklistRepo() {
|
|
|
3303
3340
|
units: 1
|
|
3304
3341
|
}
|
|
3305
3342
|
},
|
|
3306
|
-
{
|
|
3343
|
+
{
|
|
3344
|
+
$addFields: {
|
|
3345
|
+
isFullyActioned: {
|
|
3346
|
+
$allElementsTrue: {
|
|
3347
|
+
$map: {
|
|
3348
|
+
input: "$units",
|
|
3349
|
+
as: "u",
|
|
3350
|
+
in: {
|
|
3351
|
+
$or: [
|
|
3352
|
+
{ $eq: ["$$u.approve", true] },
|
|
3353
|
+
{ $eq: ["$$u.reject", true] }
|
|
3354
|
+
]
|
|
3355
|
+
}
|
|
3356
|
+
}
|
|
3357
|
+
}
|
|
3358
|
+
}
|
|
3359
|
+
}
|
|
3360
|
+
},
|
|
3361
|
+
{ $sort: { isFullyActioned: 1 } },
|
|
3307
3362
|
{ $skip: page * limit },
|
|
3308
3363
|
{ $limit: limit }
|
|
3309
3364
|
];
|
|
@@ -3507,6 +3562,20 @@ function useAreaChecklistRepo() {
|
|
|
3507
3562
|
throw error;
|
|
3508
3563
|
}
|
|
3509
3564
|
}
|
|
3565
|
+
async function getAreaChecklistSetOwner(_id, set, session) {
|
|
3566
|
+
try {
|
|
3567
|
+
_id = new import_mongodb9.ObjectId(_id);
|
|
3568
|
+
} catch (error) {
|
|
3569
|
+
throw new import_node_server_utils17.BadRequestError("Invalid area checklist ID format.");
|
|
3570
|
+
}
|
|
3571
|
+
const existing = await collection.findOne(
|
|
3572
|
+
{ _id, "checklist.set": set },
|
|
3573
|
+
{ projection: { "checklist.$": 1 }, session }
|
|
3574
|
+
);
|
|
3575
|
+
if (!existing?.checklist?.length)
|
|
3576
|
+
return null;
|
|
3577
|
+
return existing.checklist[0].units.map((u) => u.completedBy).find((cb) => cb && cb.toString() !== "") ?? null;
|
|
3578
|
+
}
|
|
3510
3579
|
async function getMaxSetNumberForArea(areaId, session) {
|
|
3511
3580
|
try {
|
|
3512
3581
|
const _id = new import_mongodb9.ObjectId(areaId);
|
|
@@ -3570,6 +3639,7 @@ function useAreaChecklistRepo() {
|
|
|
3570
3639
|
getAreaChecklistUnits,
|
|
3571
3640
|
getAreaChecklistById,
|
|
3572
3641
|
getAreaChecklistByAreaAndSchedule,
|
|
3642
|
+
getAreaChecklistSetOwner,
|
|
3573
3643
|
updateAreaChecklist,
|
|
3574
3644
|
updateAreaChecklistStatus,
|
|
3575
3645
|
updateAreaChecklistUnits,
|
|
@@ -3586,11 +3656,13 @@ function useAreaChecklistService() {
|
|
|
3586
3656
|
getAllAreaChecklist,
|
|
3587
3657
|
getAreaChecklistUnits,
|
|
3588
3658
|
getAreaChecklistById,
|
|
3659
|
+
getAreaChecklistSetOwner,
|
|
3589
3660
|
updateAreaChecklistUnits: _updateAreaChecklistUnits,
|
|
3590
3661
|
updateAreaChecklistStatus,
|
|
3591
3662
|
getMaxSetNumberForArea
|
|
3592
3663
|
} = useAreaChecklistRepo();
|
|
3593
3664
|
const { updateParentChecklistStatuses } = useParentChecklistRepo();
|
|
3665
|
+
const { getUserById } = (0, import_core.useUserRepo)();
|
|
3594
3666
|
async function createAreaChecklist(value) {
|
|
3595
3667
|
const session = import_node_server_utils18.useAtlas.getClient()?.startSession();
|
|
3596
3668
|
try {
|
|
@@ -3661,6 +3733,13 @@ function useAreaChecklistService() {
|
|
|
3661
3733
|
const session = import_node_server_utils18.useAtlas.getClient()?.startSession();
|
|
3662
3734
|
try {
|
|
3663
3735
|
session?.startTransaction();
|
|
3736
|
+
const setOwner = await getAreaChecklistSetOwner(_id, set, session);
|
|
3737
|
+
if (setOwner && value.completedBy && setOwner.toString() !== value.completedBy.toString()) {
|
|
3738
|
+
const acceptedBy = await getUserById(setOwner.toString());
|
|
3739
|
+
throw new import_node_server_utils18.UnauthorizedError(
|
|
3740
|
+
`${acceptedBy.name} has already taken this set.`
|
|
3741
|
+
);
|
|
3742
|
+
}
|
|
3664
3743
|
await _updateAreaChecklistUnits(_id, set, unitId, value, session);
|
|
3665
3744
|
const allUnitsResult = await getAreaChecklistUnits(
|
|
3666
3745
|
{
|
|
@@ -5228,7 +5307,7 @@ function useCheckOutItemRepository() {
|
|
|
5228
5307
|
}
|
|
5229
5308
|
|
|
5230
5309
|
// src/services/hygiene-checkout-item.service.ts
|
|
5231
|
-
var
|
|
5310
|
+
var import_core2 = require("@7365admin1/core");
|
|
5232
5311
|
var import_node_server_utils30 = require("@7365admin1/node-server-utils");
|
|
5233
5312
|
function useCheckOutItemService() {
|
|
5234
5313
|
const {
|
|
@@ -5237,7 +5316,7 @@ function useCheckOutItemService() {
|
|
|
5237
5316
|
completeCheckOutItem
|
|
5238
5317
|
} = useCheckOutItemRepository();
|
|
5239
5318
|
const { getSupplyById } = useSupplyRepository();
|
|
5240
|
-
const { getUserById } = (0,
|
|
5319
|
+
const { getUserById } = (0, import_core2.useUserRepo)();
|
|
5241
5320
|
const { createStock } = useStockService();
|
|
5242
5321
|
async function createCheckOutItem(value) {
|
|
5243
5322
|
const session = import_node_server_utils30.useAtlas.getClient()?.startSession();
|