@7365admin1/module-hygiene 4.29.1-staging.17 → 4.29.1-staging.18
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/.changeset/extra-visits-fixes.md +5 -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/dist/index.mjs
CHANGED
|
@@ -2968,6 +2968,18 @@ function useParentChecklistRepo() {
|
|
|
2968
2968
|
throw error;
|
|
2969
2969
|
}
|
|
2970
2970
|
}
|
|
2971
|
+
async function reopenParentChecklist(_id) {
|
|
2972
|
+
const res = await collection.updateOne(
|
|
2973
|
+
{ _id: new ObjectId7(_id), status: "completed" },
|
|
2974
|
+
{ $set: { status: "ongoing", updatedAt: /* @__PURE__ */ new Date() }, $unset: { completedAt: "" } }
|
|
2975
|
+
);
|
|
2976
|
+
if (res.modifiedCount > 0) {
|
|
2977
|
+
delNamespace().catch((err) => {
|
|
2978
|
+
logger14.error(`Failed to clear cache for namespace: ${namespace_collection}`, err);
|
|
2979
|
+
});
|
|
2980
|
+
}
|
|
2981
|
+
return res.modifiedCount;
|
|
2982
|
+
}
|
|
2971
2983
|
async function getHygieneSiteIds() {
|
|
2972
2984
|
const query = {
|
|
2973
2985
|
status: { $ne: "deleted" }
|
|
@@ -3074,6 +3086,7 @@ function useParentChecklistRepo() {
|
|
|
3074
3086
|
getAllParentChecklist,
|
|
3075
3087
|
getParentChecklistById,
|
|
3076
3088
|
updateParentChecklistStatuses,
|
|
3089
|
+
reopenParentChecklist,
|
|
3077
3090
|
getHygieneSiteIds,
|
|
3078
3091
|
closeExpiredParentChecklists,
|
|
3079
3092
|
getTodayParentChecklists,
|
|
@@ -4302,6 +4315,10 @@ function useAreaChecklistRepo() {
|
|
|
4302
4315
|
}
|
|
4303
4316
|
);
|
|
4304
4317
|
if (result.modifiedCount > 0) {
|
|
4318
|
+
await collection.updateOne(
|
|
4319
|
+
{ schedule, serviceType, area, status: "completed" },
|
|
4320
|
+
{ $set: { status: "ongoing", updatedAt: /* @__PURE__ */ new Date() }, $unset: { completedAt: "" } }
|
|
4321
|
+
);
|
|
4305
4322
|
delNamespace().catch((err) => {
|
|
4306
4323
|
logger17.error(
|
|
4307
4324
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
@@ -4598,6 +4615,9 @@ function validateScheduleRules(task, now = /* @__PURE__ */ new Date()) {
|
|
|
4598
4615
|
}
|
|
4599
4616
|
if (task.endDate && task.endDate < today)
|
|
4600
4617
|
return "The end date has already passed.";
|
|
4618
|
+
if (!repeating && !(task.dates ?? []).length) {
|
|
4619
|
+
return "Pick at least one date, or choose a repeat.";
|
|
4620
|
+
}
|
|
4601
4621
|
if (!repeating) {
|
|
4602
4622
|
const dates = (task.dates ?? []).filter((d) => !task.endDate || d <= task.endDate);
|
|
4603
4623
|
if (dates.length && dates.every((d) => d < today)) {
|
|
@@ -7058,7 +7078,11 @@ var SCHEDULE_FIELDS = {
|
|
|
7058
7078
|
startDate: 1,
|
|
7059
7079
|
endDate: 1,
|
|
7060
7080
|
paused: 1,
|
|
7061
|
-
lastRunDate: 1
|
|
7081
|
+
lastRunDate: 1,
|
|
7082
|
+
// when it was saved: a task saved after its time today waits for its next
|
|
7083
|
+
// day, so Next visit must know it (else it says "today" for a visit that never comes)
|
|
7084
|
+
createdAt: 1,
|
|
7085
|
+
updatedAt: 1
|
|
7062
7086
|
};
|
|
7063
7087
|
function useScheduleTaskRepository() {
|
|
7064
7088
|
const db = useAtlas14.getDb();
|
|
@@ -7303,7 +7327,6 @@ function useScheduleTaskRepository() {
|
|
|
7303
7327
|
description: 1,
|
|
7304
7328
|
areas: 1,
|
|
7305
7329
|
status: 1,
|
|
7306
|
-
createdAt: 1,
|
|
7307
7330
|
site: 1,
|
|
7308
7331
|
serviceType: 1,
|
|
7309
7332
|
...SCHEDULE_FIELDS
|
|
@@ -7429,7 +7452,7 @@ function useScheduleTaskRepository() {
|
|
|
7429
7452
|
}
|
|
7430
7453
|
|
|
7431
7454
|
// src/utils/schedule-task-set.util.ts
|
|
7432
|
-
function buildScheduleTaskSets(task, units, startSet, count) {
|
|
7455
|
+
function buildScheduleTaskSets(task, units, startSet, count = 1) {
|
|
7433
7456
|
return Array.from({ length: count }, (_, i) => ({
|
|
7434
7457
|
set: startSet + i,
|
|
7435
7458
|
units,
|
|
@@ -7444,7 +7467,7 @@ function buildScheduleTaskSets(task, units, startSet, count) {
|
|
|
7444
7467
|
import { ObjectId as ObjectId20 } from "mongodb";
|
|
7445
7468
|
import { logger as logger32 } from "@7365admin1/node-server-utils";
|
|
7446
7469
|
function useScheduleTaskService() {
|
|
7447
|
-
const { createParentChecklist } = useParentChecklistRepo();
|
|
7470
|
+
const { createParentChecklist, reopenParentChecklist } = useParentChecklistRepo();
|
|
7448
7471
|
const { getAllScheduleTask, markScheduleTaskRan } = useScheduleTaskRepository();
|
|
7449
7472
|
const {
|
|
7450
7473
|
createAreaChecklist,
|
|
@@ -7515,7 +7538,7 @@ function useScheduleTaskService() {
|
|
|
7515
7538
|
const parentChecklistIds = await createParentChecklist({
|
|
7516
7539
|
site: scheduleTask.site.toString(),
|
|
7517
7540
|
serviceType,
|
|
7518
|
-
createdAt: /* @__PURE__ */ new Date()
|
|
7541
|
+
createdAt: currentDate ?? /* @__PURE__ */ new Date()
|
|
7519
7542
|
});
|
|
7520
7543
|
const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
|
|
7521
7544
|
logger32.info(
|
|
@@ -7578,14 +7601,13 @@ function useScheduleTaskService() {
|
|
|
7578
7601
|
);
|
|
7579
7602
|
}
|
|
7580
7603
|
if (existingAreaChecklist) {
|
|
7581
|
-
const areaSetConfig = Number(areaDetails.set) || 1;
|
|
7582
7604
|
const maxSetInChecklist = existingAreaChecklist.checklist?.length ? Math.max(
|
|
7583
7605
|
...existingAreaChecklist.checklist.map(
|
|
7584
7606
|
(c) => c.set
|
|
7585
7607
|
)
|
|
7586
7608
|
) : 0;
|
|
7587
7609
|
const startSetNumber = maxSetInChecklist + 1;
|
|
7588
|
-
const newSets = buildScheduleTaskSets(scheduleTask, units, startSetNumber
|
|
7610
|
+
const newSets = buildScheduleTaskSets(scheduleTask, units, startSetNumber);
|
|
7589
7611
|
const modified = await pushScheduleTaskSets(
|
|
7590
7612
|
parentChecklistId.toString(),
|
|
7591
7613
|
serviceType,
|
|
@@ -7596,7 +7618,7 @@ function useScheduleTaskService() {
|
|
|
7596
7618
|
if (modified > 0) {
|
|
7597
7619
|
addedAreas.push(area.name);
|
|
7598
7620
|
logger32.info(
|
|
7599
|
-
`Appended
|
|
7621
|
+
`Appended extra-visit set ${startSetNumber} to area checklist for area ${area.name}`
|
|
7600
7622
|
);
|
|
7601
7623
|
} else {
|
|
7602
7624
|
logger32.info(
|
|
@@ -7604,8 +7626,7 @@ function useScheduleTaskService() {
|
|
|
7604
7626
|
);
|
|
7605
7627
|
}
|
|
7606
7628
|
} else {
|
|
7607
|
-
const
|
|
7608
|
-
const schedTaskSets = buildScheduleTaskSets(scheduleTask, units, 1, areaSetConfig);
|
|
7629
|
+
const schedTaskSets = buildScheduleTaskSets(scheduleTask, units, 1);
|
|
7609
7630
|
const checklistData = {
|
|
7610
7631
|
schedule: parentChecklistId.toString(),
|
|
7611
7632
|
serviceType,
|
|
@@ -7627,6 +7648,13 @@ function useScheduleTaskService() {
|
|
|
7627
7648
|
continue;
|
|
7628
7649
|
}
|
|
7629
7650
|
}
|
|
7651
|
+
if (addedAreas.length > 0) {
|
|
7652
|
+
try {
|
|
7653
|
+
await reopenParentChecklist(parentChecklistId);
|
|
7654
|
+
} catch (error) {
|
|
7655
|
+
logger32.error(`Could not reopen day list ${parentChecklistId}`, error);
|
|
7656
|
+
}
|
|
7657
|
+
}
|
|
7630
7658
|
const attemptKey = `${scheduleTask._id}:${today}`;
|
|
7631
7659
|
const tried = (attempts.get(attemptKey) ?? 0) + 1;
|
|
7632
7660
|
attempts.set(attemptKey, tried);
|
|
@@ -7776,8 +7804,8 @@ function useScheduleTaskController() {
|
|
|
7776
7804
|
const optional = Object.fromEntries(
|
|
7777
7805
|
Object.entries(scheduleTaskFields).map(([key, rule]) => [
|
|
7778
7806
|
key,
|
|
7779
|
-
key === "dates" ? Joi19.array().
|
|
7780
|
-
"array.
|
|
7807
|
+
key === "dates" ? Joi19.array().items(scheduleDate).optional().messages({
|
|
7808
|
+
"array.base": "Dates must be a list of dates."
|
|
7781
7809
|
}) : rule.optional()
|
|
7782
7810
|
])
|
|
7783
7811
|
);
|