@7365admin1/module-hygiene 2.0.1 → 4.0.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 +10 -20
- package/dist/index.js +40 -173
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +40 -169
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @7365admin1/module-hygiene
|
|
2
2
|
|
|
3
|
+
## 4.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Change import logic to expect AREA instead of NAME in area import, and UNIT instead of NAME in unit import (breaking change to Excel import format).
|
|
8
|
+
|
|
9
|
+
## 3.0.0
|
|
10
|
+
|
|
11
|
+
### Major Changes
|
|
12
|
+
|
|
13
|
+
- Update TScheduleTask model to remove frequency-based fields and add startDate/endDate
|
|
14
|
+
|
|
3
15
|
## 2.0.1
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/dist/index.d.ts
CHANGED
|
@@ -462,52 +462,42 @@ declare function useRequestItemController(): {
|
|
|
462
462
|
disapproveRequestItem: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
463
463
|
};
|
|
464
464
|
|
|
465
|
-
declare const allowedFrequency: string[];
|
|
466
|
-
declare const allowedDays: string[];
|
|
467
|
-
declare const allowedWeekOfMonth: string[];
|
|
468
|
-
declare const allowedMonths: string[];
|
|
469
465
|
type TScheduleTask = {
|
|
470
466
|
_id?: ObjectId;
|
|
471
467
|
site: string | ObjectId;
|
|
472
468
|
title: string;
|
|
473
|
-
frequency: (typeof allowedFrequency)[number];
|
|
474
469
|
time: string;
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
month?: (typeof allowedMonths)[number];
|
|
478
|
-
date?: number;
|
|
470
|
+
startDate: string;
|
|
471
|
+
endDate?: string;
|
|
479
472
|
description?: string;
|
|
480
473
|
areas: {
|
|
481
474
|
name: string;
|
|
482
|
-
value:
|
|
475
|
+
value: ObjectId;
|
|
483
476
|
}[];
|
|
484
477
|
status?: "active" | "deleted";
|
|
485
478
|
createdAt?: string | Date;
|
|
486
479
|
updatedAt?: string | Date;
|
|
487
480
|
deletedAt?: string | Date;
|
|
488
481
|
};
|
|
489
|
-
type TScheduleTaskCreate = Pick<TScheduleTask, "site" | "title" | "
|
|
482
|
+
type TScheduleTaskCreate = Pick<TScheduleTask, "site" | "title" | "time" | "startDate" | "endDate" | "description" | "areas">;
|
|
490
483
|
type TScheduleTaskGetQuery = {
|
|
491
484
|
page?: number;
|
|
492
485
|
limit?: number;
|
|
493
486
|
search?: string;
|
|
494
487
|
} & Pick<TScheduleTask, "site">;
|
|
495
|
-
type TScheduleTaskGetById = Pick<TScheduleTask, "title" | "
|
|
496
|
-
type TScheduleTaskUpdate = Partial<Pick<TScheduleTask, "title" | "
|
|
488
|
+
type TScheduleTaskGetById = Pick<TScheduleTask, "title" | "time" | "startDate" | "endDate" | "description" | "areas" | "status" | "createdAt">;
|
|
489
|
+
type TScheduleTaskUpdate = Partial<Pick<TScheduleTask, "title" | "time" | "startDate" | "endDate" | "description" | "areas">>;
|
|
497
490
|
declare const scheduleTaskSchema: Joi.ObjectSchema<any>;
|
|
498
491
|
declare function MScheduleTask(value: TScheduleTaskCreate): {
|
|
499
492
|
site: string | ObjectId;
|
|
500
493
|
title: string;
|
|
501
|
-
frequency: string;
|
|
502
494
|
time: string;
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
month: string | undefined;
|
|
506
|
-
date: number | undefined;
|
|
495
|
+
startDate: string;
|
|
496
|
+
endDate: string | undefined;
|
|
507
497
|
description: string | undefined;
|
|
508
498
|
areas: {
|
|
509
499
|
name: string;
|
|
510
|
-
value:
|
|
500
|
+
value: ObjectId;
|
|
511
501
|
}[];
|
|
512
502
|
status: string;
|
|
513
503
|
createdAt: Date;
|
|
@@ -547,4 +537,4 @@ declare function useScheduleTaskController(): {
|
|
|
547
537
|
updateScheduleTask: (req: Request, res: Response, next: NextFunction) => Promise<void>;
|
|
548
538
|
};
|
|
549
539
|
|
|
550
|
-
export { MArea, MAreaChecklist, MParentChecklist, MRequestItem, MScheduleTask, MStock, MSupply, MUnit, TArea, TAreaChecklist, TAreaChecklistBatchCreate, TAreaChecklistCreate, TAreaChecklistUnits, TAreaChecklistUnitsUpdate, TAreaChecklistUpdate, TAreaCreate, TAreaGetQuery, TAreaUnits, TAreaUpdate, TAreaUpdateChecklist, TCleaningScheduleArea, TCleaningScheduleAreaGetQuery, TGetStocksQuery, TParentChecklist, TParentChecklistGetQuery, TRequestItem, TRequestItemCreate, TRequestItemCreateByBatchService, TRequestItemCreateService, TRequestItemGetById, TRequestItemGetQuery, TScheduleTask, TScheduleTaskCreate, TScheduleTaskGetById, TScheduleTaskGetQuery, TScheduleTaskUpdate, TStock, TStockCreate, TStockCreateService, TSupply, TSupplyCreate, TSupplyGetById, TSupplyGetQuery, TSupplyUpdate, TUnit, TUnitCreate, TUnitGetQuery, TUnitUpdate, allowedChecklistStatus,
|
|
540
|
+
export { MArea, MAreaChecklist, MParentChecklist, MRequestItem, MScheduleTask, MStock, MSupply, MUnit, TArea, TAreaChecklist, TAreaChecklistBatchCreate, TAreaChecklistCreate, TAreaChecklistUnits, TAreaChecklistUnitsUpdate, TAreaChecklistUpdate, TAreaCreate, TAreaGetQuery, TAreaUnits, TAreaUpdate, TAreaUpdateChecklist, TCleaningScheduleArea, TCleaningScheduleAreaGetQuery, TGetStocksQuery, TParentChecklist, TParentChecklistGetQuery, TRequestItem, TRequestItemCreate, TRequestItemCreateByBatchService, TRequestItemCreateService, TRequestItemGetById, TRequestItemGetQuery, TScheduleTask, TScheduleTaskCreate, TScheduleTaskGetById, TScheduleTaskGetQuery, TScheduleTaskUpdate, TStock, TStockCreate, TStockCreateService, TSupply, TSupplyCreate, TSupplyGetById, TSupplyGetQuery, TSupplyUpdate, TUnit, TUnitCreate, TUnitGetQuery, TUnitUpdate, allowedChecklistStatus, allowedPeriods, allowedRequestItemStatus, allowedStatus, allowedTypes, areaChecklistSchema, areaSchema, parentChecklistSchema, requestItemSchema, scheduleTaskSchema, stockSchema, supplySchema, unitSchema, useAreaChecklistController, useAreaChecklistRepo, useAreaChecklistService, useAreaController, useAreaRepo, useAreaService, useHygieneDashboardController, useHygieneDashboardRepository, useParentChecklistController, useParentChecklistRepo, useRequestItemController, useRequestItemRepository, useRequestItemService, useScheduleTaskController, useScheduleTaskRepository, useScheduleTaskService, useStockController, useStockRepository, useStockService, useSupplyController, useSupplyRepository, useUnitController, useUnitRepository, useUnitService };
|
package/dist/index.js
CHANGED
|
@@ -39,14 +39,10 @@ __export(src_exports, {
|
|
|
39
39
|
MSupply: () => MSupply,
|
|
40
40
|
MUnit: () => MUnit,
|
|
41
41
|
allowedChecklistStatus: () => allowedChecklistStatus,
|
|
42
|
-
allowedDays: () => allowedDays,
|
|
43
|
-
allowedFrequency: () => allowedFrequency,
|
|
44
|
-
allowedMonths: () => allowedMonths,
|
|
45
42
|
allowedPeriods: () => allowedPeriods,
|
|
46
43
|
allowedRequestItemStatus: () => allowedRequestItemStatus,
|
|
47
44
|
allowedStatus: () => allowedStatus,
|
|
48
45
|
allowedTypes: () => allowedTypes,
|
|
49
|
-
allowedWeekOfMonth: () => allowedWeekOfMonth,
|
|
50
46
|
areaChecklistSchema: () => areaChecklistSchema,
|
|
51
47
|
areaSchema: () => areaSchema,
|
|
52
48
|
parentChecklistSchema: () => parentChecklistSchema,
|
|
@@ -1115,12 +1111,12 @@ function useAreaService() {
|
|
|
1115
1111
|
skippedRows.push(i + 1);
|
|
1116
1112
|
continue;
|
|
1117
1113
|
}
|
|
1118
|
-
if (!row?.
|
|
1119
|
-
import_node_server_utils5.logger.warn(`Skipping row ${i + 1} with missing
|
|
1114
|
+
if (!row?.AREA) {
|
|
1115
|
+
import_node_server_utils5.logger.warn(`Skipping row ${i + 1} with missing AREA:`, row);
|
|
1120
1116
|
skippedRows.push(i + 1);
|
|
1121
1117
|
continue;
|
|
1122
1118
|
}
|
|
1123
|
-
const areaName = String(row.
|
|
1119
|
+
const areaName = String(row.AREA).trim();
|
|
1124
1120
|
if (!areaName) {
|
|
1125
1121
|
import_node_server_utils5.logger.warn(`Skipping row ${i + 1} with empty ${areaType} area name`);
|
|
1126
1122
|
skippedRows.push(i + 1);
|
|
@@ -1646,12 +1642,12 @@ function useUnitService() {
|
|
|
1646
1642
|
try {
|
|
1647
1643
|
for (let i = 0; i < dataArray.length; i++) {
|
|
1648
1644
|
const row = dataArray[i];
|
|
1649
|
-
if (!row?.
|
|
1650
|
-
import_node_server_utils9.logger.warn(`Skipping row ${i + 1} with missing
|
|
1645
|
+
if (!row?.UNIT) {
|
|
1646
|
+
import_node_server_utils9.logger.warn(`Skipping row ${i + 1} with missing UNIT:`, row);
|
|
1651
1647
|
skippedRows.push(i + 1);
|
|
1652
1648
|
continue;
|
|
1653
1649
|
}
|
|
1654
|
-
const unitName = String(row.
|
|
1650
|
+
const unitName = String(row.UNIT).trim();
|
|
1655
1651
|
if (!unitName) {
|
|
1656
1652
|
import_node_server_utils9.logger.warn(`Skipping row ${i + 1} with empty unit name`);
|
|
1657
1653
|
skippedRows.push(i + 1);
|
|
@@ -4798,45 +4794,12 @@ function useRequestItemController() {
|
|
|
4798
4794
|
var import_node_server_utils29 = require("@7365admin1/node-server-utils");
|
|
4799
4795
|
var import_joi16 = __toESM(require("joi"));
|
|
4800
4796
|
var import_mongodb16 = require("mongodb");
|
|
4801
|
-
var allowedFrequency = [
|
|
4802
|
-
"daily",
|
|
4803
|
-
"weekly",
|
|
4804
|
-
"monthly",
|
|
4805
|
-
"annually"
|
|
4806
|
-
];
|
|
4807
|
-
var allowedDays = [
|
|
4808
|
-
"Monday",
|
|
4809
|
-
"Tuesday",
|
|
4810
|
-
"Wednesday",
|
|
4811
|
-
"Thursday",
|
|
4812
|
-
"Friday",
|
|
4813
|
-
"Saturday",
|
|
4814
|
-
"Sunday"
|
|
4815
|
-
];
|
|
4816
|
-
var allowedWeekOfMonth = ["start", "end"];
|
|
4817
|
-
var allowedMonths = [
|
|
4818
|
-
"January",
|
|
4819
|
-
"February",
|
|
4820
|
-
"March",
|
|
4821
|
-
"April",
|
|
4822
|
-
"May",
|
|
4823
|
-
"June",
|
|
4824
|
-
"July",
|
|
4825
|
-
"August",
|
|
4826
|
-
"September",
|
|
4827
|
-
"October",
|
|
4828
|
-
"November",
|
|
4829
|
-
"December"
|
|
4830
|
-
];
|
|
4831
4797
|
var scheduleTaskSchema = import_joi16.default.object({
|
|
4832
4798
|
site: import_joi16.default.string().hex().required(),
|
|
4833
4799
|
title: import_joi16.default.string().required(),
|
|
4834
|
-
frequency: import_joi16.default.string().valid(...allowedFrequency).required(),
|
|
4835
4800
|
time: import_joi16.default.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).required(),
|
|
4836
|
-
|
|
4837
|
-
|
|
4838
|
-
month: import_joi16.default.string().valid(...allowedMonths).optional().allow("", null),
|
|
4839
|
-
date: import_joi16.default.number().min(1).max(31).optional().allow(null),
|
|
4801
|
+
startDate: import_joi16.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).required(),
|
|
4802
|
+
endDate: import_joi16.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
|
|
4840
4803
|
description: import_joi16.default.string().optional().allow("", null),
|
|
4841
4804
|
areas: import_joi16.default.array().min(1).items(
|
|
4842
4805
|
import_joi16.default.object({
|
|
@@ -4873,12 +4836,9 @@ function MScheduleTask(value) {
|
|
|
4873
4836
|
return {
|
|
4874
4837
|
site: value.site,
|
|
4875
4838
|
title: value.title,
|
|
4876
|
-
frequency: value.frequency,
|
|
4877
4839
|
time: value.time,
|
|
4878
|
-
|
|
4879
|
-
|
|
4880
|
-
month: value.month,
|
|
4881
|
-
date: value.date,
|
|
4840
|
+
startDate: value.startDate,
|
|
4841
|
+
endDate: value.endDate,
|
|
4882
4842
|
description: value.description,
|
|
4883
4843
|
areas: value.areas,
|
|
4884
4844
|
status: "active",
|
|
@@ -5089,12 +5049,9 @@ function useScheduleTaskRepository() {
|
|
|
5089
5049
|
{
|
|
5090
5050
|
$project: {
|
|
5091
5051
|
title: 1,
|
|
5092
|
-
frequency: 1,
|
|
5093
5052
|
time: 1,
|
|
5094
|
-
|
|
5095
|
-
|
|
5096
|
-
month: 1,
|
|
5097
|
-
date: 1,
|
|
5053
|
+
startDate: 1,
|
|
5054
|
+
endDate: 1,
|
|
5098
5055
|
description: 1,
|
|
5099
5056
|
areas: 1,
|
|
5100
5057
|
status: 1,
|
|
@@ -5184,20 +5141,6 @@ function useScheduleTaskService() {
|
|
|
5184
5141
|
function checkScheduleConditions(schedule, currentDate = /* @__PURE__ */ new Date()) {
|
|
5185
5142
|
try {
|
|
5186
5143
|
const now = currentDate;
|
|
5187
|
-
const currentDay = now.toLocaleDateString("en-US", {
|
|
5188
|
-
weekday: "long",
|
|
5189
|
-
timeZone: "Asia/Singapore"
|
|
5190
|
-
});
|
|
5191
|
-
const currentMonth = now.toLocaleDateString("en-US", {
|
|
5192
|
-
month: "long",
|
|
5193
|
-
timeZone: "Asia/Singapore"
|
|
5194
|
-
});
|
|
5195
|
-
const currentDate_num = Number(
|
|
5196
|
-
now.toLocaleDateString("en-US", {
|
|
5197
|
-
day: "numeric",
|
|
5198
|
-
timeZone: "Asia/Singapore"
|
|
5199
|
-
})
|
|
5200
|
-
);
|
|
5201
5144
|
const timeString = now.toLocaleTimeString("en-US", {
|
|
5202
5145
|
hour: "2-digit",
|
|
5203
5146
|
minute: "2-digit",
|
|
@@ -5205,9 +5148,29 @@ function useScheduleTaskService() {
|
|
|
5205
5148
|
timeZone: "Asia/Singapore"
|
|
5206
5149
|
});
|
|
5207
5150
|
const [currentHour, currentMinute] = timeString.split(":").map(Number);
|
|
5151
|
+
const currentDateString = now.toLocaleDateString("en-US", {
|
|
5152
|
+
timeZone: "Asia/Singapore"
|
|
5153
|
+
});
|
|
5208
5154
|
import_node_server_utils31.logger.info(
|
|
5209
|
-
`Checking schedule ${schedule._id}: Current time ${currentHour}:${currentMinute}, Schedule time ${schedule.time},
|
|
5155
|
+
`Checking schedule ${schedule._id}: Current time ${currentHour}:${currentMinute}, Current date ${currentDateString}, Schedule time ${schedule.time}, Start date ${schedule.startDate}, End date ${schedule.endDate}`
|
|
5210
5156
|
);
|
|
5157
|
+
const startDate = /* @__PURE__ */ new Date(schedule.startDate + "T00:00:00");
|
|
5158
|
+
const currentDateOnly = /* @__PURE__ */ new Date(currentDateString + "T00:00:00");
|
|
5159
|
+
if (currentDateOnly < startDate) {
|
|
5160
|
+
import_node_server_utils31.logger.info(
|
|
5161
|
+
`Schedule ${schedule._id}: Current date ${currentDateString} is before start date ${schedule.startDate}`
|
|
5162
|
+
);
|
|
5163
|
+
return false;
|
|
5164
|
+
}
|
|
5165
|
+
if (schedule.endDate) {
|
|
5166
|
+
const endDate = /* @__PURE__ */ new Date(schedule.endDate + "T00:00:00");
|
|
5167
|
+
if (currentDateOnly > endDate) {
|
|
5168
|
+
import_node_server_utils31.logger.info(
|
|
5169
|
+
`Schedule ${schedule._id}: Current date ${currentDateString} is after end date ${schedule.endDate}`
|
|
5170
|
+
);
|
|
5171
|
+
return false;
|
|
5172
|
+
}
|
|
5173
|
+
}
|
|
5211
5174
|
const [scheduleHour, scheduleMinute] = schedule.time.split(":").map(Number);
|
|
5212
5175
|
const timeMatches = currentHour === scheduleHour && currentMinute === scheduleMinute;
|
|
5213
5176
|
if (!timeMatches) {
|
|
@@ -5217,68 +5180,9 @@ function useScheduleTaskService() {
|
|
|
5217
5180
|
return false;
|
|
5218
5181
|
}
|
|
5219
5182
|
import_node_server_utils31.logger.info(
|
|
5220
|
-
`Schedule ${schedule._id}:
|
|
5183
|
+
`Schedule ${schedule._id}: All conditions matched - Date is within range and time matches`
|
|
5221
5184
|
);
|
|
5222
|
-
|
|
5223
|
-
case "daily":
|
|
5224
|
-
import_node_server_utils31.logger.info(`Schedule ${schedule._id}: Daily frequency matched`);
|
|
5225
|
-
return true;
|
|
5226
|
-
case "weekly":
|
|
5227
|
-
if (!schedule.day || schedule.day.length === 0) {
|
|
5228
|
-
import_node_server_utils31.logger.warn(
|
|
5229
|
-
`Schedule ${schedule._id} is weekly but has no days specified`
|
|
5230
|
-
);
|
|
5231
|
-
return false;
|
|
5232
|
-
}
|
|
5233
|
-
const dayMatches = schedule.day.includes(currentDay);
|
|
5234
|
-
import_node_server_utils31.logger.info(
|
|
5235
|
-
`Schedule ${schedule._id}: Weekly - Current day: ${currentDay}, Schedule days: ${schedule.day.join(
|
|
5236
|
-
", "
|
|
5237
|
-
)}, Match: ${dayMatches}`
|
|
5238
|
-
);
|
|
5239
|
-
return dayMatches;
|
|
5240
|
-
case "monthly":
|
|
5241
|
-
if (!schedule.weekOfMonth) {
|
|
5242
|
-
import_node_server_utils31.logger.warn(
|
|
5243
|
-
`Schedule ${schedule._id} is monthly but has no weekOfMonth specified`
|
|
5244
|
-
);
|
|
5245
|
-
return false;
|
|
5246
|
-
}
|
|
5247
|
-
if (schedule.weekOfMonth === "start") {
|
|
5248
|
-
const matches2 = currentDate_num >= 1 && currentDate_num <= 7;
|
|
5249
|
-
import_node_server_utils31.logger.info(
|
|
5250
|
-
`Schedule ${schedule._id}: Monthly start - Current date: ${currentDate_num}, Match: ${matches2}`
|
|
5251
|
-
);
|
|
5252
|
-
return matches2;
|
|
5253
|
-
} else if (schedule.weekOfMonth === "end") {
|
|
5254
|
-
const lastDayOfMonth = new Date(
|
|
5255
|
-
now.getFullYear(),
|
|
5256
|
-
now.getMonth() + 1,
|
|
5257
|
-
0
|
|
5258
|
-
).getDate();
|
|
5259
|
-
const matches2 = currentDate_num > lastDayOfMonth - 7;
|
|
5260
|
-
import_node_server_utils31.logger.info(
|
|
5261
|
-
`Schedule ${schedule._id}: Monthly end - Current date: ${currentDate_num}, Last day: ${lastDayOfMonth}, Match: ${matches2}`
|
|
5262
|
-
);
|
|
5263
|
-
return matches2;
|
|
5264
|
-
}
|
|
5265
|
-
return false;
|
|
5266
|
-
case "annually":
|
|
5267
|
-
if (!schedule.month || !schedule.date) {
|
|
5268
|
-
import_node_server_utils31.logger.warn(
|
|
5269
|
-
`Schedule ${schedule._id} is annually but has no month or date specified`
|
|
5270
|
-
);
|
|
5271
|
-
return false;
|
|
5272
|
-
}
|
|
5273
|
-
const matches = currentMonth === schedule.month && currentDate_num === schedule.date;
|
|
5274
|
-
import_node_server_utils31.logger.info(
|
|
5275
|
-
`Schedule ${schedule._id}: Annually - Current: ${currentMonth} ${currentDate_num}, Expected: ${schedule.month} ${schedule.date}, Match: ${matches}`
|
|
5276
|
-
);
|
|
5277
|
-
return matches;
|
|
5278
|
-
default:
|
|
5279
|
-
import_node_server_utils31.logger.warn(`Unknown frequency type: ${schedule.frequency}`);
|
|
5280
|
-
return false;
|
|
5281
|
-
}
|
|
5185
|
+
return true;
|
|
5282
5186
|
} catch (error) {
|
|
5283
5187
|
import_node_server_utils31.logger.error(
|
|
5284
5188
|
`Error checking schedule conditions for ${schedule._id}:`,
|
|
@@ -5302,7 +5206,7 @@ function useScheduleTaskService() {
|
|
|
5302
5206
|
for (const scheduleTask of scheduleTasks) {
|
|
5303
5207
|
try {
|
|
5304
5208
|
import_node_server_utils31.logger.info(
|
|
5305
|
-
`Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time},
|
|
5209
|
+
`Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time}, startDate=${scheduleTask.startDate}, endDate=${scheduleTask.endDate}`
|
|
5306
5210
|
);
|
|
5307
5211
|
const shouldRun = checkScheduleConditions(scheduleTask, currentDate);
|
|
5308
5212
|
if (!shouldRun) {
|
|
@@ -5333,48 +5237,18 @@ function useScheduleTaskService() {
|
|
|
5333
5237
|
import_node_server_utils31.logger.info(
|
|
5334
5238
|
`Using parent checklist ${parentChecklistId}, now creating/updating area checklists`
|
|
5335
5239
|
);
|
|
5336
|
-
const fullScheduleTask = await getScheduleTaskById(
|
|
5337
|
-
scheduleTask._id.toString()
|
|
5338
|
-
);
|
|
5339
|
-
const tasksMap = /* @__PURE__ */ new Map();
|
|
5340
|
-
if (fullScheduleTask.tasks && Array.isArray(fullScheduleTask.tasks)) {
|
|
5341
|
-
for (const task of fullScheduleTask.tasks) {
|
|
5342
|
-
const areaId = task.area?.toString();
|
|
5343
|
-
if (areaId) {
|
|
5344
|
-
if (!tasksMap.has(areaId)) {
|
|
5345
|
-
tasksMap.set(areaId, []);
|
|
5346
|
-
}
|
|
5347
|
-
tasksMap.get(areaId).push(task);
|
|
5348
|
-
}
|
|
5349
|
-
}
|
|
5350
|
-
}
|
|
5351
5240
|
for (const area of scheduleTask.areas) {
|
|
5352
5241
|
try {
|
|
5353
5242
|
const areaId = area.value.toString();
|
|
5354
5243
|
const areaDetails = await getAreaById(areaId);
|
|
5355
5244
|
let units = [];
|
|
5356
|
-
|
|
5357
|
-
if (areaTasks && areaTasks.length > 0) {
|
|
5358
|
-
import_node_server_utils31.logger.info(
|
|
5359
|
-
`Area ${area.name} (${areaId}): Found ${areaTasks.length} tasks, using units from first task.`
|
|
5360
|
-
);
|
|
5361
|
-
units = areaTasks[0].units.map((unit) => ({
|
|
5362
|
-
unit: unit.unit.toString(),
|
|
5363
|
-
name: unit.name
|
|
5364
|
-
}));
|
|
5365
|
-
import_node_server_utils31.logger.info(
|
|
5366
|
-
`Area ${area.name} (${areaId}): Units from task: ${JSON.stringify(units)}`
|
|
5367
|
-
);
|
|
5368
|
-
} else if (areaDetails.units && areaDetails.units.length > 0) {
|
|
5369
|
-
import_node_server_utils31.logger.info(
|
|
5370
|
-
`Area ${area.name} (${areaId}): No tasks found, using units from area details.`
|
|
5371
|
-
);
|
|
5245
|
+
if (areaDetails.units && areaDetails.units.length > 0) {
|
|
5372
5246
|
units = areaDetails.units.map((unit) => ({
|
|
5373
5247
|
unit: unit.unit.toString(),
|
|
5374
5248
|
name: unit.name
|
|
5375
5249
|
}));
|
|
5376
5250
|
import_node_server_utils31.logger.info(
|
|
5377
|
-
`Area ${area.name} (${areaId}):
|
|
5251
|
+
`Area ${area.name} (${areaId}): Using units from area details: ${JSON.stringify(
|
|
5378
5252
|
units
|
|
5379
5253
|
)}`
|
|
5380
5254
|
);
|
|
@@ -5635,12 +5509,9 @@ function useScheduleTaskController() {
|
|
|
5635
5509
|
const validation = import_joi17.default.object({
|
|
5636
5510
|
id: import_joi17.default.string().hex().required(),
|
|
5637
5511
|
title: import_joi17.default.string().optional().allow("", null),
|
|
5638
|
-
frequency: import_joi17.default.string().valid(...allowedFrequency).optional().allow("", null),
|
|
5639
5512
|
time: import_joi17.default.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).optional().allow("", null),
|
|
5640
|
-
|
|
5641
|
-
|
|
5642
|
-
month: import_joi17.default.string().valid(...allowedMonths).optional().allow("", null),
|
|
5643
|
-
date: import_joi17.default.number().min(1).max(31).optional().allow(null),
|
|
5513
|
+
startDate: import_joi17.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
|
|
5514
|
+
endDate: import_joi17.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
|
|
5644
5515
|
description: import_joi17.default.string().optional().allow("", null),
|
|
5645
5516
|
areas: import_joi17.default.array().min(1).items(
|
|
5646
5517
|
import_joi17.default.object({
|
|
@@ -5685,14 +5556,10 @@ function useScheduleTaskController() {
|
|
|
5685
5556
|
MSupply,
|
|
5686
5557
|
MUnit,
|
|
5687
5558
|
allowedChecklistStatus,
|
|
5688
|
-
allowedDays,
|
|
5689
|
-
allowedFrequency,
|
|
5690
|
-
allowedMonths,
|
|
5691
5559
|
allowedPeriods,
|
|
5692
5560
|
allowedRequestItemStatus,
|
|
5693
5561
|
allowedStatus,
|
|
5694
5562
|
allowedTypes,
|
|
5695
|
-
allowedWeekOfMonth,
|
|
5696
5563
|
areaChecklistSchema,
|
|
5697
5564
|
areaSchema,
|
|
5698
5565
|
parentChecklistSchema,
|