@7365admin1/module-hygiene 4.32.0 → 4.32.1
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 +40 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/schedule-followups.test.mjs +6 -0
- package/test/schedule-task-rules.test.mjs +13 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @7365admin1/module-hygiene
|
|
2
2
|
|
|
3
|
+
## 4.32.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 98ff56f: Extra visits: editing a repeating visit no longer fails; one extra visit adds one round; an area or day already Done is reopened when an extra round is added; Next visit is right for a task saved after today's time.
|
|
8
|
+
|
|
3
9
|
## 4.32.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -242,6 +242,7 @@ declare function useParentChecklistRepo(): {
|
|
|
242
242
|
_id: ObjectId;
|
|
243
243
|
}>;
|
|
244
244
|
updateParentChecklistStatuses: (_id: string | ObjectId, status: (typeof allowedStatus)[number], session?: ClientSession) => Promise<number>;
|
|
245
|
+
reopenParentChecklist: (_id: string | ObjectId) => Promise<number>;
|
|
245
246
|
getHygieneSiteIds: () => Promise<any[]>;
|
|
246
247
|
closeExpiredParentChecklists: () => Promise<number>;
|
|
247
248
|
getTodayParentChecklists: () => Promise<{
|
package/dist/index.js
CHANGED
|
@@ -3015,6 +3015,18 @@ function useParentChecklistRepo() {
|
|
|
3015
3015
|
throw error;
|
|
3016
3016
|
}
|
|
3017
3017
|
}
|
|
3018
|
+
async function reopenParentChecklist(_id) {
|
|
3019
|
+
const res = await collection.updateOne(
|
|
3020
|
+
{ _id: new import_mongodb7.ObjectId(_id), status: "completed" },
|
|
3021
|
+
{ $set: { status: "ongoing", updatedAt: /* @__PURE__ */ new Date() }, $unset: { completedAt: "" } }
|
|
3022
|
+
);
|
|
3023
|
+
if (res.modifiedCount > 0) {
|
|
3024
|
+
delNamespace().catch((err) => {
|
|
3025
|
+
import_node_server_utils14.logger.error(`Failed to clear cache for namespace: ${namespace_collection}`, err);
|
|
3026
|
+
});
|
|
3027
|
+
}
|
|
3028
|
+
return res.modifiedCount;
|
|
3029
|
+
}
|
|
3018
3030
|
async function getHygieneSiteIds() {
|
|
3019
3031
|
const query = {
|
|
3020
3032
|
status: { $ne: "deleted" }
|
|
@@ -3121,6 +3133,7 @@ function useParentChecklistRepo() {
|
|
|
3121
3133
|
getAllParentChecklist,
|
|
3122
3134
|
getParentChecklistById,
|
|
3123
3135
|
updateParentChecklistStatuses,
|
|
3136
|
+
reopenParentChecklist,
|
|
3124
3137
|
getHygieneSiteIds,
|
|
3125
3138
|
closeExpiredParentChecklists,
|
|
3126
3139
|
getTodayParentChecklists,
|
|
@@ -4337,6 +4350,10 @@ function useAreaChecklistRepo() {
|
|
|
4337
4350
|
}
|
|
4338
4351
|
);
|
|
4339
4352
|
if (result.modifiedCount > 0) {
|
|
4353
|
+
await collection.updateOne(
|
|
4354
|
+
{ schedule, serviceType, area, status: "completed" },
|
|
4355
|
+
{ $set: { status: "ongoing", updatedAt: /* @__PURE__ */ new Date() }, $unset: { completedAt: "" } }
|
|
4356
|
+
);
|
|
4340
4357
|
delNamespace().catch((err) => {
|
|
4341
4358
|
import_node_server_utils17.logger.error(
|
|
4342
4359
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
@@ -4633,6 +4650,9 @@ function validateScheduleRules(task, now = /* @__PURE__ */ new Date()) {
|
|
|
4633
4650
|
}
|
|
4634
4651
|
if (task.endDate && task.endDate < today)
|
|
4635
4652
|
return "The end date has already passed.";
|
|
4653
|
+
if (!repeating && !(task.dates ?? []).length) {
|
|
4654
|
+
return "Pick at least one date, or choose a repeat.";
|
|
4655
|
+
}
|
|
4636
4656
|
if (!repeating) {
|
|
4637
4657
|
const dates = (task.dates ?? []).filter((d) => !task.endDate || d <= task.endDate);
|
|
4638
4658
|
if (dates.length && dates.every((d) => d < today)) {
|
|
@@ -7050,7 +7070,11 @@ var SCHEDULE_FIELDS = {
|
|
|
7050
7070
|
startDate: 1,
|
|
7051
7071
|
endDate: 1,
|
|
7052
7072
|
paused: 1,
|
|
7053
|
-
lastRunDate: 1
|
|
7073
|
+
lastRunDate: 1,
|
|
7074
|
+
// when it was saved: a task saved after its time today waits for its next
|
|
7075
|
+
// day, so Next visit must know it (else it says "today" for a visit that never comes)
|
|
7076
|
+
createdAt: 1,
|
|
7077
|
+
updatedAt: 1
|
|
7054
7078
|
};
|
|
7055
7079
|
function useScheduleTaskRepository() {
|
|
7056
7080
|
const db = import_node_server_utils33.useAtlas.getDb();
|
|
@@ -7295,7 +7319,6 @@ function useScheduleTaskRepository() {
|
|
|
7295
7319
|
description: 1,
|
|
7296
7320
|
areas: 1,
|
|
7297
7321
|
status: 1,
|
|
7298
|
-
createdAt: 1,
|
|
7299
7322
|
site: 1,
|
|
7300
7323
|
serviceType: 1,
|
|
7301
7324
|
...SCHEDULE_FIELDS
|
|
@@ -7421,7 +7444,7 @@ function useScheduleTaskRepository() {
|
|
|
7421
7444
|
}
|
|
7422
7445
|
|
|
7423
7446
|
// src/utils/schedule-task-set.util.ts
|
|
7424
|
-
function buildScheduleTaskSets(task, units, startSet, count) {
|
|
7447
|
+
function buildScheduleTaskSets(task, units, startSet, count = 1) {
|
|
7425
7448
|
return Array.from({ length: count }, (_, i) => ({
|
|
7426
7449
|
set: startSet + i,
|
|
7427
7450
|
units,
|
|
@@ -7436,7 +7459,7 @@ function buildScheduleTaskSets(task, units, startSet, count) {
|
|
|
7436
7459
|
var import_mongodb20 = require("mongodb");
|
|
7437
7460
|
var import_node_server_utils34 = require("@7365admin1/node-server-utils");
|
|
7438
7461
|
function useScheduleTaskService() {
|
|
7439
|
-
const { createParentChecklist } = useParentChecklistRepo();
|
|
7462
|
+
const { createParentChecklist, reopenParentChecklist } = useParentChecklistRepo();
|
|
7440
7463
|
const { getAllScheduleTask, markScheduleTaskRan } = useScheduleTaskRepository();
|
|
7441
7464
|
const {
|
|
7442
7465
|
createAreaChecklist,
|
|
@@ -7507,7 +7530,7 @@ function useScheduleTaskService() {
|
|
|
7507
7530
|
const parentChecklistIds = await createParentChecklist({
|
|
7508
7531
|
site: scheduleTask.site.toString(),
|
|
7509
7532
|
serviceType,
|
|
7510
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
7533
|
+
createdAt: currentDate ?? /* @__PURE__ */ new Date()
|
|
7511
7534
|
});
|
|
7512
7535
|
const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
|
|
7513
7536
|
import_node_server_utils34.logger.info(
|
|
@@ -7570,14 +7593,13 @@ function useScheduleTaskService() {
|
|
|
7570
7593
|
);
|
|
7571
7594
|
}
|
|
7572
7595
|
if (existingAreaChecklist) {
|
|
7573
|
-
const areaSetConfig = Number(areaDetails.set) || 1;
|
|
7574
7596
|
const maxSetInChecklist = existingAreaChecklist.checklist?.length ? Math.max(
|
|
7575
7597
|
...existingAreaChecklist.checklist.map(
|
|
7576
7598
|
(c) => c.set
|
|
7577
7599
|
)
|
|
7578
7600
|
) : 0;
|
|
7579
7601
|
const startSetNumber = maxSetInChecklist + 1;
|
|
7580
|
-
const newSets = buildScheduleTaskSets(scheduleTask, units, startSetNumber
|
|
7602
|
+
const newSets = buildScheduleTaskSets(scheduleTask, units, startSetNumber);
|
|
7581
7603
|
const modified = await pushScheduleTaskSets(
|
|
7582
7604
|
parentChecklistId.toString(),
|
|
7583
7605
|
serviceType,
|
|
@@ -7588,7 +7610,7 @@ function useScheduleTaskService() {
|
|
|
7588
7610
|
if (modified > 0) {
|
|
7589
7611
|
addedAreas.push(area.name);
|
|
7590
7612
|
import_node_server_utils34.logger.info(
|
|
7591
|
-
`Appended
|
|
7613
|
+
`Appended extra-visit set ${startSetNumber} to area checklist for area ${area.name}`
|
|
7592
7614
|
);
|
|
7593
7615
|
} else {
|
|
7594
7616
|
import_node_server_utils34.logger.info(
|
|
@@ -7596,8 +7618,7 @@ function useScheduleTaskService() {
|
|
|
7596
7618
|
);
|
|
7597
7619
|
}
|
|
7598
7620
|
} else {
|
|
7599
|
-
const
|
|
7600
|
-
const schedTaskSets = buildScheduleTaskSets(scheduleTask, units, 1, areaSetConfig);
|
|
7621
|
+
const schedTaskSets = buildScheduleTaskSets(scheduleTask, units, 1);
|
|
7601
7622
|
const checklistData = {
|
|
7602
7623
|
schedule: parentChecklistId.toString(),
|
|
7603
7624
|
serviceType,
|
|
@@ -7619,6 +7640,13 @@ function useScheduleTaskService() {
|
|
|
7619
7640
|
continue;
|
|
7620
7641
|
}
|
|
7621
7642
|
}
|
|
7643
|
+
if (addedAreas.length > 0) {
|
|
7644
|
+
try {
|
|
7645
|
+
await reopenParentChecklist(parentChecklistId);
|
|
7646
|
+
} catch (error) {
|
|
7647
|
+
import_node_server_utils34.logger.error(`Could not reopen day list ${parentChecklistId}`, error);
|
|
7648
|
+
}
|
|
7649
|
+
}
|
|
7622
7650
|
const attemptKey = `${scheduleTask._id}:${today}`;
|
|
7623
7651
|
const tried = (attempts.get(attemptKey) ?? 0) + 1;
|
|
7624
7652
|
attempts.set(attemptKey, tried);
|
|
@@ -7768,8 +7796,8 @@ function useScheduleTaskController() {
|
|
|
7768
7796
|
const optional = Object.fromEntries(
|
|
7769
7797
|
Object.entries(scheduleTaskFields).map(([key, rule]) => [
|
|
7770
7798
|
key,
|
|
7771
|
-
key === "dates" ? import_joi19.default.array().
|
|
7772
|
-
"array.
|
|
7799
|
+
key === "dates" ? import_joi19.default.array().items(scheduleDate).optional().messages({
|
|
7800
|
+
"array.base": "Dates must be a list of dates."
|
|
7773
7801
|
}) : rule.optional()
|
|
7774
7802
|
])
|
|
7775
7803
|
);
|