@7365admin1/module-hygiene 4.10.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 +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +67 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +72 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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");
|
|
@@ -3227,7 +3228,19 @@ function useAreaChecklistRepo() {
|
|
|
3227
3228
|
},
|
|
3228
3229
|
{
|
|
3229
3230
|
$addFields: {
|
|
3230
|
-
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
|
+
}
|
|
3231
3244
|
}
|
|
3232
3245
|
},
|
|
3233
3246
|
{
|
|
@@ -3256,7 +3269,14 @@ function useAreaChecklistRepo() {
|
|
|
3256
3269
|
preserveNullAndEmptyArrays: true
|
|
3257
3270
|
}
|
|
3258
3271
|
},
|
|
3259
|
-
{
|
|
3272
|
+
{
|
|
3273
|
+
$sort: {
|
|
3274
|
+
set: 1,
|
|
3275
|
+
isActioned: 1,
|
|
3276
|
+
"checklist.units.timestamp": 1,
|
|
3277
|
+
isCompleted: -1
|
|
3278
|
+
}
|
|
3279
|
+
},
|
|
3260
3280
|
{
|
|
3261
3281
|
$project: {
|
|
3262
3282
|
_id: 0,
|
|
@@ -3320,7 +3340,25 @@ function useAreaChecklistRepo() {
|
|
|
3320
3340
|
units: 1
|
|
3321
3341
|
}
|
|
3322
3342
|
},
|
|
3323
|
-
{
|
|
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 } },
|
|
3324
3362
|
{ $skip: page * limit },
|
|
3325
3363
|
{ $limit: limit }
|
|
3326
3364
|
];
|
|
@@ -3524,6 +3562,20 @@ function useAreaChecklistRepo() {
|
|
|
3524
3562
|
throw error;
|
|
3525
3563
|
}
|
|
3526
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
|
+
}
|
|
3527
3579
|
async function getMaxSetNumberForArea(areaId, session) {
|
|
3528
3580
|
try {
|
|
3529
3581
|
const _id = new import_mongodb9.ObjectId(areaId);
|
|
@@ -3587,6 +3639,7 @@ function useAreaChecklistRepo() {
|
|
|
3587
3639
|
getAreaChecklistUnits,
|
|
3588
3640
|
getAreaChecklistById,
|
|
3589
3641
|
getAreaChecklistByAreaAndSchedule,
|
|
3642
|
+
getAreaChecklistSetOwner,
|
|
3590
3643
|
updateAreaChecklist,
|
|
3591
3644
|
updateAreaChecklistStatus,
|
|
3592
3645
|
updateAreaChecklistUnits,
|
|
@@ -3603,11 +3656,13 @@ function useAreaChecklistService() {
|
|
|
3603
3656
|
getAllAreaChecklist,
|
|
3604
3657
|
getAreaChecklistUnits,
|
|
3605
3658
|
getAreaChecklistById,
|
|
3659
|
+
getAreaChecklistSetOwner,
|
|
3606
3660
|
updateAreaChecklistUnits: _updateAreaChecklistUnits,
|
|
3607
3661
|
updateAreaChecklistStatus,
|
|
3608
3662
|
getMaxSetNumberForArea
|
|
3609
3663
|
} = useAreaChecklistRepo();
|
|
3610
3664
|
const { updateParentChecklistStatuses } = useParentChecklistRepo();
|
|
3665
|
+
const { getUserById } = (0, import_core.useUserRepo)();
|
|
3611
3666
|
async function createAreaChecklist(value) {
|
|
3612
3667
|
const session = import_node_server_utils18.useAtlas.getClient()?.startSession();
|
|
3613
3668
|
try {
|
|
@@ -3678,6 +3733,13 @@ function useAreaChecklistService() {
|
|
|
3678
3733
|
const session = import_node_server_utils18.useAtlas.getClient()?.startSession();
|
|
3679
3734
|
try {
|
|
3680
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
|
+
}
|
|
3681
3743
|
await _updateAreaChecklistUnits(_id, set, unitId, value, session);
|
|
3682
3744
|
const allUnitsResult = await getAreaChecklistUnits(
|
|
3683
3745
|
{
|
|
@@ -5245,7 +5307,7 @@ function useCheckOutItemRepository() {
|
|
|
5245
5307
|
}
|
|
5246
5308
|
|
|
5247
5309
|
// src/services/hygiene-checkout-item.service.ts
|
|
5248
|
-
var
|
|
5310
|
+
var import_core2 = require("@7365admin1/core");
|
|
5249
5311
|
var import_node_server_utils30 = require("@7365admin1/node-server-utils");
|
|
5250
5312
|
function useCheckOutItemService() {
|
|
5251
5313
|
const {
|
|
@@ -5254,7 +5316,7 @@ function useCheckOutItemService() {
|
|
|
5254
5316
|
completeCheckOutItem
|
|
5255
5317
|
} = useCheckOutItemRepository();
|
|
5256
5318
|
const { getSupplyById } = useSupplyRepository();
|
|
5257
|
-
const { getUserById } = (0,
|
|
5319
|
+
const { getUserById } = (0, import_core2.useUserRepo)();
|
|
5258
5320
|
const { createStock } = useStockService();
|
|
5259
5321
|
async function createCheckOutItem(value) {
|
|
5260
5322
|
const session = import_node_server_utils30.useAtlas.getClient()?.startSession();
|