@7365admin1/module-hygiene 4.15.0 → 4.17.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 +23 -25
- package/dist/index.js +42 -87
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +42 -87
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1183,11 +1183,13 @@ function useUnitRepository() {
|
|
|
1183
1183
|
}) {
|
|
1184
1184
|
page = page > 0 ? page - 1 : 0;
|
|
1185
1185
|
const query = {
|
|
1186
|
-
status: { $ne: "deleted" }
|
|
1186
|
+
status: { $ne: "deleted" },
|
|
1187
|
+
serviceType
|
|
1187
1188
|
};
|
|
1188
1189
|
const cacheOptions = {
|
|
1189
1190
|
page,
|
|
1190
|
-
limit
|
|
1191
|
+
limit,
|
|
1192
|
+
serviceType
|
|
1191
1193
|
};
|
|
1192
1194
|
try {
|
|
1193
1195
|
site = new ObjectId5(site);
|
|
@@ -1196,10 +1198,6 @@ function useUnitRepository() {
|
|
|
1196
1198
|
} catch (error) {
|
|
1197
1199
|
throw new BadRequestError6("Invalid site ID format.");
|
|
1198
1200
|
}
|
|
1199
|
-
if (serviceType) {
|
|
1200
|
-
query.serviceType = serviceType;
|
|
1201
|
-
cacheOptions.serviceType = serviceType;
|
|
1202
|
-
}
|
|
1203
1201
|
if (search) {
|
|
1204
1202
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
1205
1203
|
cacheOptions.search = search;
|
|
@@ -2634,6 +2632,7 @@ function useParentChecklistRepo() {
|
|
|
2634
2632
|
getAllParentChecklist,
|
|
2635
2633
|
getParentChecklistById,
|
|
2636
2634
|
updateParentChecklistStatuses,
|
|
2635
|
+
getHygieneSiteIds,
|
|
2637
2636
|
closeExpiredParentChecklists,
|
|
2638
2637
|
getTodayParentChecklists,
|
|
2639
2638
|
getTodayParentChecklistsForAreaGen
|
|
@@ -2650,7 +2649,12 @@ function useParentChecklistController() {
|
|
|
2650
2649
|
} = useParentChecklistRepo();
|
|
2651
2650
|
async function createParentChecklist(req, res, next) {
|
|
2652
2651
|
const payload = req.body;
|
|
2653
|
-
const
|
|
2652
|
+
const validation = Joi7.object({
|
|
2653
|
+
createdAt: Joi7.alternatives().try(Joi7.date(), Joi7.string()).optional().allow("", null),
|
|
2654
|
+
site: Joi7.string().hex().required(),
|
|
2655
|
+
serviceType: Joi7.string().valid(...Object.values(ServiceType)).optional().allow("", null)
|
|
2656
|
+
});
|
|
2657
|
+
const { error } = validation.validate(payload);
|
|
2654
2658
|
if (error) {
|
|
2655
2659
|
logger15.log({ level: "error", message: error.message });
|
|
2656
2660
|
next(new BadRequestError13(error.message));
|
|
@@ -2724,7 +2728,7 @@ import { BadRequestError as BadRequestError14, logger as logger16 } from "@7365a
|
|
|
2724
2728
|
var allowedChecklistStatus = ["open", "completed", "closed"];
|
|
2725
2729
|
var areaChecklistSchema = Joi8.object({
|
|
2726
2730
|
schedule: Joi8.string().hex().required(),
|
|
2727
|
-
serviceType: Joi8.string().valid(...Object.values(ServiceType)).
|
|
2731
|
+
serviceType: Joi8.string().valid(...Object.values(ServiceType)).required(),
|
|
2728
2732
|
area: Joi8.string().hex().required(),
|
|
2729
2733
|
name: Joi8.string().required(),
|
|
2730
2734
|
type: Joi8.string().valid(...allowedTypes).required(),
|
|
@@ -2740,8 +2744,7 @@ var areaChecklistSchema = Joi8.object({
|
|
|
2740
2744
|
isScheduleTask: Joi8.boolean().optional().default(false),
|
|
2741
2745
|
scheduleTaskId: Joi8.string().hex().optional().allow(null)
|
|
2742
2746
|
}).required()
|
|
2743
|
-
).optional().default([])
|
|
2744
|
-
createdBy: Joi8.string().hex().required()
|
|
2747
|
+
).optional().default([])
|
|
2745
2748
|
});
|
|
2746
2749
|
function MAreaChecklist(value) {
|
|
2747
2750
|
const { error } = areaChecklistSchema.validate(value);
|
|
@@ -2782,13 +2785,6 @@ function MAreaChecklist(value) {
|
|
|
2782
2785
|
};
|
|
2783
2786
|
});
|
|
2784
2787
|
}
|
|
2785
|
-
if (value.createdBy) {
|
|
2786
|
-
try {
|
|
2787
|
-
value.createdBy = new ObjectId8(value.createdBy);
|
|
2788
|
-
} catch (error2) {
|
|
2789
|
-
throw new BadRequestError14("Invalid createdBy ID format.");
|
|
2790
|
-
}
|
|
2791
|
-
}
|
|
2792
2788
|
return {
|
|
2793
2789
|
schedule: value.schedule,
|
|
2794
2790
|
serviceType: value.serviceType,
|
|
@@ -2797,7 +2793,6 @@ function MAreaChecklist(value) {
|
|
|
2797
2793
|
type: value.type,
|
|
2798
2794
|
checklist: value.checklist || [],
|
|
2799
2795
|
status: "open",
|
|
2800
|
-
createdBy: value.createdBy,
|
|
2801
2796
|
createdAt: /* @__PURE__ */ new Date(),
|
|
2802
2797
|
completedAt: "",
|
|
2803
2798
|
updatedAt: ""
|
|
@@ -2917,10 +2912,11 @@ function useAreaChecklistRepo() {
|
|
|
2917
2912
|
serviceType
|
|
2918
2913
|
}, session) {
|
|
2919
2914
|
page = page > 0 ? page - 1 : 0;
|
|
2920
|
-
const query = {};
|
|
2915
|
+
const query = { serviceType };
|
|
2921
2916
|
const cacheOptions = {
|
|
2922
2917
|
page,
|
|
2923
|
-
limit
|
|
2918
|
+
limit,
|
|
2919
|
+
serviceType
|
|
2924
2920
|
};
|
|
2925
2921
|
try {
|
|
2926
2922
|
query.schedule = new ObjectId9(schedule);
|
|
@@ -2928,10 +2924,6 @@ function useAreaChecklistRepo() {
|
|
|
2928
2924
|
} catch (error) {
|
|
2929
2925
|
throw new BadRequestError15("Invalid parent checklist ID format.");
|
|
2930
2926
|
}
|
|
2931
|
-
if (serviceType) {
|
|
2932
|
-
query.serviceType = serviceType;
|
|
2933
|
-
cacheOptions.serviceType = serviceType;
|
|
2934
|
-
}
|
|
2935
2927
|
if (type && type !== "all") {
|
|
2936
2928
|
query.type = type;
|
|
2937
2929
|
cacheOptions.type = type;
|
|
@@ -2955,32 +2947,6 @@ function useAreaChecklistRepo() {
|
|
|
2955
2947
|
try {
|
|
2956
2948
|
const pipeline = [
|
|
2957
2949
|
{ $match: query },
|
|
2958
|
-
{
|
|
2959
|
-
$lookup: {
|
|
2960
|
-
from: "users",
|
|
2961
|
-
let: { createdById: "$createdBy" },
|
|
2962
|
-
pipeline: [
|
|
2963
|
-
{
|
|
2964
|
-
$match: {
|
|
2965
|
-
$expr: {
|
|
2966
|
-
$and: [
|
|
2967
|
-
{ $ne: ["$$createdById", ""] },
|
|
2968
|
-
{ $eq: ["$_id", "$$createdById"] }
|
|
2969
|
-
]
|
|
2970
|
-
}
|
|
2971
|
-
}
|
|
2972
|
-
},
|
|
2973
|
-
{ $project: { name: 1 } }
|
|
2974
|
-
],
|
|
2975
|
-
as: "createdByDoc"
|
|
2976
|
-
}
|
|
2977
|
-
},
|
|
2978
|
-
{
|
|
2979
|
-
$unwind: {
|
|
2980
|
-
path: "$createdByDoc",
|
|
2981
|
-
preserveNullAndEmptyArrays: true
|
|
2982
|
-
}
|
|
2983
|
-
},
|
|
2984
2950
|
{
|
|
2985
2951
|
$addFields: {
|
|
2986
2952
|
statusOrder: {
|
|
@@ -3032,8 +2998,7 @@ function useAreaChecklistRepo() {
|
|
|
3032
2998
|
},
|
|
3033
2999
|
else: 0
|
|
3034
3000
|
}
|
|
3035
|
-
}
|
|
3036
|
-
createdByName: "$createdByDoc.name"
|
|
3001
|
+
}
|
|
3037
3002
|
}
|
|
3038
3003
|
},
|
|
3039
3004
|
{ $skip: page * limit },
|
|
@@ -3331,10 +3296,11 @@ function useAreaChecklistRepo() {
|
|
|
3331
3296
|
_id
|
|
3332
3297
|
}, session) {
|
|
3333
3298
|
page = page > 0 ? page - 1 : 0;
|
|
3334
|
-
const query = {};
|
|
3299
|
+
const query = { serviceType };
|
|
3335
3300
|
const cacheOptions = {
|
|
3336
3301
|
page,
|
|
3337
|
-
limit
|
|
3302
|
+
limit,
|
|
3303
|
+
serviceType
|
|
3338
3304
|
};
|
|
3339
3305
|
try {
|
|
3340
3306
|
query._id = new ObjectId9(_id);
|
|
@@ -3342,10 +3308,6 @@ function useAreaChecklistRepo() {
|
|
|
3342
3308
|
} catch (error) {
|
|
3343
3309
|
throw new BadRequestError15("Invalid area checklist ID format.");
|
|
3344
3310
|
}
|
|
3345
|
-
if (serviceType) {
|
|
3346
|
-
query.serviceType = serviceType;
|
|
3347
|
-
cacheOptions.serviceType = serviceType;
|
|
3348
|
-
}
|
|
3349
3311
|
if (search) {
|
|
3350
3312
|
query.$text = { $search: search };
|
|
3351
3313
|
cacheOptions.search = search;
|
|
@@ -3559,7 +3521,16 @@ function useAreaChecklistRepo() {
|
|
|
3559
3521
|
try {
|
|
3560
3522
|
const area = await collection.findOne(
|
|
3561
3523
|
{ _id },
|
|
3562
|
-
{
|
|
3524
|
+
{
|
|
3525
|
+
projection: {
|
|
3526
|
+
schedule: 1,
|
|
3527
|
+
serviceType: 1,
|
|
3528
|
+
name: 1,
|
|
3529
|
+
type: 1,
|
|
3530
|
+
status: 1
|
|
3531
|
+
},
|
|
3532
|
+
session
|
|
3533
|
+
}
|
|
3563
3534
|
);
|
|
3564
3535
|
if (!area) {
|
|
3565
3536
|
throw new BadRequestError15("Area checklist not found.");
|
|
@@ -4081,8 +4052,7 @@ function useAreaChecklistService() {
|
|
|
4081
4052
|
unit: unit.unit.toString(),
|
|
4082
4053
|
name: unit.name
|
|
4083
4054
|
}))
|
|
4084
|
-
}))
|
|
4085
|
-
createdBy: value.createdBy
|
|
4055
|
+
}))
|
|
4086
4056
|
};
|
|
4087
4057
|
const insertedId = await _createAreaChecklist(checklistData);
|
|
4088
4058
|
totalChecklistsCreated++;
|
|
@@ -4118,10 +4088,14 @@ function useAreaChecklistService() {
|
|
|
4118
4088
|
);
|
|
4119
4089
|
}
|
|
4120
4090
|
await _updateAreaChecklistUnits(_id, set, unitId, value, session);
|
|
4091
|
+
const currentArea = await getAreaChecklistById(_id, session);
|
|
4092
|
+
const scheduleId = currentArea.schedule;
|
|
4093
|
+
const serviceType = currentArea.serviceType;
|
|
4121
4094
|
const allUnitsResult = await getAreaChecklistUnits(
|
|
4122
4095
|
{
|
|
4123
4096
|
page: 1,
|
|
4124
4097
|
limit: 1e3,
|
|
4098
|
+
serviceType,
|
|
4125
4099
|
_id: _id.toString()
|
|
4126
4100
|
},
|
|
4127
4101
|
session
|
|
@@ -4146,14 +4120,13 @@ function useAreaChecklistService() {
|
|
|
4146
4120
|
}
|
|
4147
4121
|
}
|
|
4148
4122
|
await updateAreaChecklistStatus(_id, areaStatus, session);
|
|
4149
|
-
const currentArea = await getAreaChecklistById(_id, session);
|
|
4150
|
-
const scheduleId = currentArea.schedule;
|
|
4151
4123
|
if (scheduleId) {
|
|
4152
4124
|
const allAreasResult = await getAllAreaChecklist(
|
|
4153
4125
|
{
|
|
4154
4126
|
page: 1,
|
|
4155
4127
|
limit: 1e3,
|
|
4156
|
-
schedule: scheduleId.toString()
|
|
4128
|
+
schedule: scheduleId.toString(),
|
|
4129
|
+
serviceType
|
|
4157
4130
|
},
|
|
4158
4131
|
session
|
|
4159
4132
|
);
|
|
@@ -4440,16 +4413,13 @@ function useAreaChecklistController() {
|
|
|
4440
4413
|
(acc, [key, value2]) => ({ ...acc, [key]: value2 }),
|
|
4441
4414
|
{}
|
|
4442
4415
|
) : {};
|
|
4443
|
-
const createdBy = cookies["user"] || "";
|
|
4444
4416
|
const payload = {
|
|
4445
4417
|
site: req.params.site,
|
|
4446
|
-
schedule: req.params.schedule
|
|
4447
|
-
createdBy
|
|
4418
|
+
schedule: req.params.schedule
|
|
4448
4419
|
};
|
|
4449
4420
|
const validation = Joi9.object({
|
|
4450
4421
|
site: Joi9.string().hex().required(),
|
|
4451
|
-
schedule: Joi9.string().hex().required()
|
|
4452
|
-
createdBy: Joi9.string().hex().required()
|
|
4422
|
+
schedule: Joi9.string().hex().required()
|
|
4453
4423
|
});
|
|
4454
4424
|
const { error, value } = validation.validate(payload);
|
|
4455
4425
|
if (error) {
|
|
@@ -6021,8 +5991,7 @@ var scheduleTaskSchema = Joi16.object({
|
|
|
6021
5991
|
name: Joi16.string().required(),
|
|
6022
5992
|
value: Joi16.any().required()
|
|
6023
5993
|
})
|
|
6024
|
-
).required()
|
|
6025
|
-
createdBy: Joi16.string().hex().required()
|
|
5994
|
+
).required()
|
|
6026
5995
|
});
|
|
6027
5996
|
function MScheduleTask(value) {
|
|
6028
5997
|
const { error } = scheduleTaskSchema.validate(value);
|
|
@@ -6049,13 +6018,6 @@ function MScheduleTask(value) {
|
|
|
6049
6018
|
}
|
|
6050
6019
|
});
|
|
6051
6020
|
}
|
|
6052
|
-
if (value.createdBy) {
|
|
6053
|
-
try {
|
|
6054
|
-
value.createdBy = new ObjectId18(value.createdBy);
|
|
6055
|
-
} catch (error2) {
|
|
6056
|
-
throw new BadRequestError28("Invalid createdBy ID format.");
|
|
6057
|
-
}
|
|
6058
|
-
}
|
|
6059
6021
|
return {
|
|
6060
6022
|
site: value.site,
|
|
6061
6023
|
serviceType: value.serviceType,
|
|
@@ -6065,7 +6027,6 @@ function MScheduleTask(value) {
|
|
|
6065
6027
|
description: value.description,
|
|
6066
6028
|
areas: value.areas,
|
|
6067
6029
|
status: "active",
|
|
6068
|
-
createdBy: value.createdBy,
|
|
6069
6030
|
createdAt: /* @__PURE__ */ new Date(),
|
|
6070
6031
|
updatedAt: "",
|
|
6071
6032
|
deletedAt: ""
|
|
@@ -6587,8 +6548,7 @@ function useScheduleTaskService() {
|
|
|
6587
6548
|
area: areaId,
|
|
6588
6549
|
name: area.name,
|
|
6589
6550
|
type: areaDetails.type || "common",
|
|
6590
|
-
checklist: schedTaskSets
|
|
6591
|
-
createdBy: scheduleTask.createdBy
|
|
6551
|
+
checklist: schedTaskSets
|
|
6592
6552
|
};
|
|
6593
6553
|
logger32.info(
|
|
6594
6554
|
`Area ${area.name} (${areaId}): Creating new area checklist with schedule-task sets only`
|
|
@@ -6643,12 +6603,7 @@ function useScheduleTaskController() {
|
|
|
6643
6603
|
deleteScheduleTask: _deleteScheduleTask
|
|
6644
6604
|
} = useScheduleTaskRepository();
|
|
6645
6605
|
async function createScheduleTask(req, res, next) {
|
|
6646
|
-
const
|
|
6647
|
-
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
6648
|
-
{}
|
|
6649
|
-
) : {};
|
|
6650
|
-
const createdBy = cookies["user"] || "";
|
|
6651
|
-
const payload = { ...req.body, ...req.params, createdBy };
|
|
6606
|
+
const payload = { ...req.body, ...req.params };
|
|
6652
6607
|
const { error } = scheduleTaskSchema.validate(payload);
|
|
6653
6608
|
if (error) {
|
|
6654
6609
|
logger33.log({ level: "error", message: error.message });
|