@iservice365/module-hygiene 1.4.0 → 1.5.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 +12 -0
- package/dist/index.d.ts +29 -12
- package/dist/index.js +396 -125
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +391 -120
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -42,7 +42,6 @@ __export(src_exports, {
|
|
|
42
42
|
allowedDays: () => allowedDays,
|
|
43
43
|
allowedFrequency: () => allowedFrequency,
|
|
44
44
|
allowedMonths: () => allowedMonths,
|
|
45
|
-
allowedQuarter: () => allowedQuarter,
|
|
46
45
|
allowedRequestItemStatus: () => allowedRequestItemStatus,
|
|
47
46
|
allowedStatus: () => allowedStatus,
|
|
48
47
|
allowedTypes: () => allowedTypes,
|
|
@@ -68,6 +67,7 @@ __export(src_exports, {
|
|
|
68
67
|
useRequestItemService: () => useRequestItemService,
|
|
69
68
|
useScheduleTaskController: () => useScheduleTaskController,
|
|
70
69
|
useScheduleTaskRepository: () => useScheduleTaskRepository,
|
|
70
|
+
useScheduleTaskService: () => useScheduleTaskService,
|
|
71
71
|
useStockController: () => useStockController,
|
|
72
72
|
useStockRepository: () => useStockRepository,
|
|
73
73
|
useStockService: () => useStockService,
|
|
@@ -84,9 +84,9 @@ var allowedTypes = ["common", "toilet"];
|
|
|
84
84
|
var allowedStatus = ["ready", "ongoing", "completed"];
|
|
85
85
|
|
|
86
86
|
// src/models/hygiene-area.model.ts
|
|
87
|
-
var import_node_server_utils = require("@iservice365/node-server-utils");
|
|
88
87
|
var import_joi = __toESM(require("joi"));
|
|
89
88
|
var import_mongodb = require("mongodb");
|
|
89
|
+
var import_node_server_utils = require("@iservice365/node-server-utils");
|
|
90
90
|
var areaSchema = import_joi.default.object({
|
|
91
91
|
site: import_joi.default.string().hex().required(),
|
|
92
92
|
name: import_joi.default.string().required(),
|
|
@@ -272,12 +272,9 @@ function useAreaRepo() {
|
|
|
272
272
|
throw error;
|
|
273
273
|
}
|
|
274
274
|
}
|
|
275
|
-
async function getAreasForChecklist({
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
}) {
|
|
279
|
-
const query = { type, status: { $ne: "deleted" } };
|
|
280
|
-
const cacheOptions = { type };
|
|
275
|
+
async function getAreasForChecklist(site) {
|
|
276
|
+
const query = { status: { $ne: "deleted" } };
|
|
277
|
+
const cacheOptions = {};
|
|
281
278
|
try {
|
|
282
279
|
site = new import_mongodb2.ObjectId(site);
|
|
283
280
|
query.site = site;
|
|
@@ -297,6 +294,7 @@ function useAreaRepo() {
|
|
|
297
294
|
{
|
|
298
295
|
$project: {
|
|
299
296
|
name: 1,
|
|
297
|
+
type: 1,
|
|
300
298
|
set: 1,
|
|
301
299
|
units: 1
|
|
302
300
|
}
|
|
@@ -356,6 +354,28 @@ function useAreaRepo() {
|
|
|
356
354
|
throw error;
|
|
357
355
|
}
|
|
358
356
|
}
|
|
357
|
+
async function getAreaByMultipleId(_id) {
|
|
358
|
+
for (let i = 0; i < _id.length; i++) {
|
|
359
|
+
try {
|
|
360
|
+
_id[i] = new import_mongodb2.ObjectId(_id[i]);
|
|
361
|
+
} catch (error) {
|
|
362
|
+
throw new import_node_server_utils2.BadRequestError("Invalid area ID format.");
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
const query = {
|
|
366
|
+
_id: { $in: _id },
|
|
367
|
+
status: { $ne: "deleted" }
|
|
368
|
+
};
|
|
369
|
+
try {
|
|
370
|
+
const data = await collection.aggregate([{ $match: query }]).toArray();
|
|
371
|
+
if (!data || data.length === 0) {
|
|
372
|
+
throw new import_node_server_utils2.NotFoundError("Area not found.");
|
|
373
|
+
}
|
|
374
|
+
return data;
|
|
375
|
+
} catch (error) {
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
359
379
|
async function verifyAreaByUnitId(unitId) {
|
|
360
380
|
try {
|
|
361
381
|
unitId = new import_mongodb2.ObjectId(unitId);
|
|
@@ -517,6 +537,7 @@ function useAreaRepo() {
|
|
|
517
537
|
getAreas,
|
|
518
538
|
getAreasForChecklist,
|
|
519
539
|
getAreaById,
|
|
540
|
+
getAreaByMultipleId,
|
|
520
541
|
verifyAreaByUnitId,
|
|
521
542
|
updateArea,
|
|
522
543
|
updateAreaChecklist,
|
|
@@ -639,8 +660,8 @@ function useAreaService() {
|
|
|
639
660
|
}
|
|
640
661
|
|
|
641
662
|
// src/controllers/hygiene-area.controller.ts
|
|
642
|
-
var import_node_server_utils4 = require("@iservice365/node-server-utils");
|
|
643
663
|
var import_joi2 = __toESM(require("joi"));
|
|
664
|
+
var import_node_server_utils4 = require("@iservice365/node-server-utils");
|
|
644
665
|
|
|
645
666
|
// src/utils/convert-excel.util.ts
|
|
646
667
|
var import_stream = require("stream");
|
|
@@ -835,9 +856,9 @@ function useAreaController() {
|
|
|
835
856
|
}
|
|
836
857
|
|
|
837
858
|
// src/models/hygiene-unit.model.ts
|
|
838
|
-
var import_node_server_utils5 = require("@iservice365/node-server-utils");
|
|
839
859
|
var import_joi3 = __toESM(require("joi"));
|
|
840
860
|
var import_mongodb3 = require("mongodb");
|
|
861
|
+
var import_node_server_utils5 = require("@iservice365/node-server-utils");
|
|
841
862
|
var unitSchema = import_joi3.default.object({
|
|
842
863
|
site: import_joi3.default.string().hex().required(),
|
|
843
864
|
name: import_joi3.default.string().required()
|
|
@@ -1061,12 +1082,12 @@ function useUnitRepository() {
|
|
|
1061
1082
|
|
|
1062
1083
|
// src/services/hygiene-unit.service.ts
|
|
1063
1084
|
function useUnitService() {
|
|
1085
|
+
const { verifyAreaByUnitId, updateAreaChecklist } = useAreaRepo();
|
|
1064
1086
|
const {
|
|
1065
1087
|
createUnit: _createUnit,
|
|
1066
1088
|
updateUnit: _updateUnit,
|
|
1067
1089
|
deleteUnit: _deleteUnit
|
|
1068
1090
|
} = useUnitRepository();
|
|
1069
|
-
const { verifyAreaByUnitId, updateAreaChecklist } = useAreaRepo();
|
|
1070
1091
|
async function importUnit({
|
|
1071
1092
|
dataJson,
|
|
1072
1093
|
site
|
|
@@ -1206,8 +1227,8 @@ function useUnitService() {
|
|
|
1206
1227
|
}
|
|
1207
1228
|
|
|
1208
1229
|
// src/controllers/hygiene-unit.controller.ts
|
|
1209
|
-
var import_node_server_utils8 = require("@iservice365/node-server-utils");
|
|
1210
1230
|
var import_joi4 = __toESM(require("joi"));
|
|
1231
|
+
var import_node_server_utils8 = require("@iservice365/node-server-utils");
|
|
1211
1232
|
function useUnitController() {
|
|
1212
1233
|
const { createUnit: _createUnit, getUnits: _getUnits } = useUnitRepository();
|
|
1213
1234
|
const {
|
|
@@ -1344,9 +1365,9 @@ function useUnitController() {
|
|
|
1344
1365
|
}
|
|
1345
1366
|
|
|
1346
1367
|
// src/models/hygiene-parent-checklist.model.ts
|
|
1347
|
-
var import_node_server_utils9 = require("@iservice365/node-server-utils");
|
|
1348
1368
|
var import_joi5 = __toESM(require("joi"));
|
|
1349
1369
|
var import_mongodb5 = require("mongodb");
|
|
1370
|
+
var import_node_server_utils9 = require("@iservice365/node-server-utils");
|
|
1350
1371
|
var parentChecklistSchema = import_joi5.default.object({
|
|
1351
1372
|
createdAt: import_joi5.default.alternatives().try(import_joi5.default.date(), import_joi5.default.string()).optional().allow("", null),
|
|
1352
1373
|
site: import_joi5.default.string().hex().required()
|
|
@@ -1615,8 +1636,8 @@ function useParentChecklistRepo() {
|
|
|
1615
1636
|
}
|
|
1616
1637
|
|
|
1617
1638
|
// src/controllers/hygiene-parent-checklist.controller.ts
|
|
1618
|
-
var import_node_server_utils11 = require("@iservice365/node-server-utils");
|
|
1619
1639
|
var import_joi6 = __toESM(require("joi"));
|
|
1640
|
+
var import_node_server_utils11 = require("@iservice365/node-server-utils");
|
|
1620
1641
|
function useParentChecklistController() {
|
|
1621
1642
|
const {
|
|
1622
1643
|
createParentChecklist: _createParentChecklist,
|
|
@@ -1686,12 +1707,13 @@ function useParentChecklistController() {
|
|
|
1686
1707
|
}
|
|
1687
1708
|
|
|
1688
1709
|
// src/models/hygiene-area-checklist.model.ts
|
|
1689
|
-
var import_node_server_utils12 = require("@iservice365/node-server-utils");
|
|
1690
1710
|
var import_joi7 = __toESM(require("joi"));
|
|
1691
1711
|
var import_mongodb7 = require("mongodb");
|
|
1712
|
+
var import_node_server_utils12 = require("@iservice365/node-server-utils");
|
|
1692
1713
|
var allowedChecklistStatus = ["ready", "completed"];
|
|
1693
1714
|
var areaChecklistSchema = import_joi7.default.object({
|
|
1694
1715
|
schedule: import_joi7.default.string().hex().required(),
|
|
1716
|
+
area: import_joi7.default.string().hex().required(),
|
|
1695
1717
|
name: import_joi7.default.string().required(),
|
|
1696
1718
|
type: import_joi7.default.string().valid(...allowedTypes).required(),
|
|
1697
1719
|
checklist: import_joi7.default.array().items(
|
|
@@ -1719,6 +1741,13 @@ function MAreaChecklist(value) {
|
|
|
1719
1741
|
throw new import_node_server_utils12.BadRequestError("Invalid schedule ID format.");
|
|
1720
1742
|
}
|
|
1721
1743
|
}
|
|
1744
|
+
if (value.area) {
|
|
1745
|
+
try {
|
|
1746
|
+
value.area = new import_mongodb7.ObjectId(value.area);
|
|
1747
|
+
} catch (error2) {
|
|
1748
|
+
throw new import_node_server_utils12.BadRequestError("Invalid area ID format.");
|
|
1749
|
+
}
|
|
1750
|
+
}
|
|
1722
1751
|
if (value.checklist && Array.isArray(value.checklist)) {
|
|
1723
1752
|
value.checklist = value.checklist.map((checklistItem) => {
|
|
1724
1753
|
return {
|
|
@@ -1736,6 +1765,7 @@ function MAreaChecklist(value) {
|
|
|
1736
1765
|
}
|
|
1737
1766
|
return {
|
|
1738
1767
|
schedule: value.schedule,
|
|
1768
|
+
area: value.area,
|
|
1739
1769
|
name: value.name,
|
|
1740
1770
|
type: value.type,
|
|
1741
1771
|
checklist: value.checklist || [],
|
|
@@ -1750,8 +1780,8 @@ function MAreaChecklist(value) {
|
|
|
1750
1780
|
var import_node_server_utils14 = require("@iservice365/node-server-utils");
|
|
1751
1781
|
|
|
1752
1782
|
// src/repositories/hygiene-area-checklist.repository.ts
|
|
1753
|
-
var import_node_server_utils13 = require("@iservice365/node-server-utils");
|
|
1754
1783
|
var import_mongodb8 = require("mongodb");
|
|
1784
|
+
var import_node_server_utils13 = require("@iservice365/node-server-utils");
|
|
1755
1785
|
function useAreaChecklistRepo() {
|
|
1756
1786
|
const db = import_node_server_utils13.useAtlas.getDb();
|
|
1757
1787
|
if (!db) {
|
|
@@ -2417,6 +2447,7 @@ function useAreaChecklistRepo() {
|
|
|
2417
2447
|
|
|
2418
2448
|
// src/services/hygiene-area-checklist.service.ts
|
|
2419
2449
|
function useAreaChecklistService() {
|
|
2450
|
+
const { getAreasForChecklist } = useAreaRepo();
|
|
2420
2451
|
const {
|
|
2421
2452
|
createAreaChecklist: _createAreaChecklist,
|
|
2422
2453
|
getAllAreaChecklist,
|
|
@@ -2425,7 +2456,6 @@ function useAreaChecklistService() {
|
|
|
2425
2456
|
completeAreaChecklistUnits: _completeAreaChecklistUnits,
|
|
2426
2457
|
updateAreaChecklistStatus
|
|
2427
2458
|
} = useAreaChecklistRepo();
|
|
2428
|
-
const { getAreasForChecklist } = useAreaRepo();
|
|
2429
2459
|
const { updateParentChecklistStatuses } = useParentChecklistRepo();
|
|
2430
2460
|
async function createAreaChecklist(value) {
|
|
2431
2461
|
const session = import_node_server_utils14.useAtlas.getClient()?.startSession();
|
|
@@ -2434,19 +2464,17 @@ function useAreaChecklistService() {
|
|
|
2434
2464
|
const results = [];
|
|
2435
2465
|
let totalChecklistsCreated = 0;
|
|
2436
2466
|
const BATCH_SIZE = 10;
|
|
2437
|
-
const
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
if (commonAreas.length > 0) {
|
|
2443
|
-
for (let i = 0; i < commonAreas.length; i += BATCH_SIZE) {
|
|
2444
|
-
const batch = commonAreas.slice(i, i + BATCH_SIZE);
|
|
2467
|
+
const areasResult = await getAreasForChecklist(value.site);
|
|
2468
|
+
const areas = areasResult || [];
|
|
2469
|
+
if (areas.length > 0) {
|
|
2470
|
+
for (let i = 0; i < areas.length; i += BATCH_SIZE) {
|
|
2471
|
+
const batch = areas.slice(i, i + BATCH_SIZE);
|
|
2445
2472
|
const batchPromises = batch.map(async (area) => {
|
|
2446
2473
|
const checklistData = {
|
|
2447
2474
|
schedule: value.schedule,
|
|
2475
|
+
area: area._id.toString(),
|
|
2448
2476
|
name: area.name,
|
|
2449
|
-
type:
|
|
2477
|
+
type: area.type,
|
|
2450
2478
|
checklist: area.units && area.units.length > 0 ? Array.from({ length: area.set || 1 }, (_, index) => ({
|
|
2451
2479
|
set: index + 1,
|
|
2452
2480
|
units: area.units.map((unit) => ({
|
|
@@ -2466,51 +2494,11 @@ function useAreaChecklistService() {
|
|
|
2466
2494
|
results.push(...batchResults);
|
|
2467
2495
|
}
|
|
2468
2496
|
import_node_server_utils14.logger.info(
|
|
2469
|
-
`Created ${
|
|
2497
|
+
`Created ${areas.length} common area checklists for site: ${value.site}`
|
|
2470
2498
|
);
|
|
2471
2499
|
} else {
|
|
2472
2500
|
import_node_server_utils14.logger.warn(`No common areas found for site: ${value.site}`);
|
|
2473
2501
|
}
|
|
2474
|
-
const toiletAreasResult = await getAreasForChecklist({
|
|
2475
|
-
site: value.site,
|
|
2476
|
-
type: "toilet"
|
|
2477
|
-
});
|
|
2478
|
-
const toiletAreas = toiletAreasResult || [];
|
|
2479
|
-
if (toiletAreas.length > 0) {
|
|
2480
|
-
for (let i = 0; i < toiletAreas.length; i += BATCH_SIZE) {
|
|
2481
|
-
const batch = toiletAreas.slice(i, i + BATCH_SIZE);
|
|
2482
|
-
const batchPromises = batch.map(async (toiletLocation) => {
|
|
2483
|
-
const checklistData = {
|
|
2484
|
-
schedule: value.schedule,
|
|
2485
|
-
name: toiletLocation.name,
|
|
2486
|
-
type: "toilet",
|
|
2487
|
-
checklist: toiletLocation.units && toiletLocation.units.length > 0 ? Array.from(
|
|
2488
|
-
{ length: toiletLocation.set || 1 },
|
|
2489
|
-
(_, index) => ({
|
|
2490
|
-
set: index + 1,
|
|
2491
|
-
units: toiletLocation.units.map((unit) => ({
|
|
2492
|
-
unit: unit.unit.toString(),
|
|
2493
|
-
name: unit.name
|
|
2494
|
-
}))
|
|
2495
|
-
})
|
|
2496
|
-
) : []
|
|
2497
|
-
};
|
|
2498
|
-
const insertedId = await _createAreaChecklist(
|
|
2499
|
-
checklistData,
|
|
2500
|
-
session
|
|
2501
|
-
);
|
|
2502
|
-
totalChecklistsCreated++;
|
|
2503
|
-
return insertedId;
|
|
2504
|
-
});
|
|
2505
|
-
const batchResults = await Promise.all(batchPromises);
|
|
2506
|
-
results.push(...batchResults);
|
|
2507
|
-
}
|
|
2508
|
-
import_node_server_utils14.logger.info(
|
|
2509
|
-
`Created ${toiletAreas.length} toilet area checklists for site: ${value.site}`
|
|
2510
|
-
);
|
|
2511
|
-
} else {
|
|
2512
|
-
import_node_server_utils14.logger.warn(`No toilet locations found for site: ${value.site}`);
|
|
2513
|
-
}
|
|
2514
2502
|
await session?.commitTransaction();
|
|
2515
2503
|
import_node_server_utils14.logger.info(
|
|
2516
2504
|
`Successfully created ${totalChecklistsCreated} area checklists for site: ${value.site}`
|
|
@@ -2614,8 +2602,8 @@ function useAreaChecklistService() {
|
|
|
2614
2602
|
}
|
|
2615
2603
|
|
|
2616
2604
|
// src/controllers/hygiene-area-checklist.controller.ts
|
|
2617
|
-
var import_node_server_utils15 = require("@iservice365/node-server-utils");
|
|
2618
2605
|
var import_joi8 = __toESM(require("joi"));
|
|
2606
|
+
var import_node_server_utils15 = require("@iservice365/node-server-utils");
|
|
2619
2607
|
function useAreaChecklistController() {
|
|
2620
2608
|
const {
|
|
2621
2609
|
getAllAreaChecklist: _getAllAreaChecklist,
|
|
@@ -2833,9 +2821,9 @@ function useAreaChecklistController() {
|
|
|
2833
2821
|
}
|
|
2834
2822
|
|
|
2835
2823
|
// src/models/hygiene-supply.model.ts
|
|
2836
|
-
var import_node_server_utils16 = require("@iservice365/node-server-utils");
|
|
2837
2824
|
var import_joi9 = __toESM(require("joi"));
|
|
2838
2825
|
var import_mongodb9 = require("mongodb");
|
|
2826
|
+
var import_node_server_utils16 = require("@iservice365/node-server-utils");
|
|
2839
2827
|
var supplySchema = import_joi9.default.object({
|
|
2840
2828
|
site: import_joi9.default.string().hex().required(),
|
|
2841
2829
|
name: import_joi9.default.string().required(),
|
|
@@ -3110,8 +3098,8 @@ function useSupplyRepository() {
|
|
|
3110
3098
|
}
|
|
3111
3099
|
|
|
3112
3100
|
// src/controllers/hygiene-supply.controller.ts
|
|
3113
|
-
var import_node_server_utils18 = require("@iservice365/node-server-utils");
|
|
3114
3101
|
var import_joi10 = __toESM(require("joi"));
|
|
3102
|
+
var import_node_server_utils18 = require("@iservice365/node-server-utils");
|
|
3115
3103
|
function useSupplyController() {
|
|
3116
3104
|
const {
|
|
3117
3105
|
createSupply: _createSupply,
|
|
@@ -3246,9 +3234,9 @@ function useSupplyController() {
|
|
|
3246
3234
|
}
|
|
3247
3235
|
|
|
3248
3236
|
// src/models/hygiene-stock.model.ts
|
|
3249
|
-
var import_node_server_utils19 = require("@iservice365/node-server-utils");
|
|
3250
3237
|
var import_joi11 = __toESM(require("joi"));
|
|
3251
3238
|
var import_mongodb11 = require("mongodb");
|
|
3239
|
+
var import_node_server_utils19 = require("@iservice365/node-server-utils");
|
|
3252
3240
|
var stockSchema = import_joi11.default.object({
|
|
3253
3241
|
site: import_joi11.default.string().hex().required(),
|
|
3254
3242
|
supply: import_joi11.default.string().hex().required(),
|
|
@@ -3457,8 +3445,8 @@ function useStockService() {
|
|
|
3457
3445
|
}
|
|
3458
3446
|
|
|
3459
3447
|
// src/controllers/hygiene-stock.controller.ts
|
|
3460
|
-
var import_node_server_utils22 = require("@iservice365/node-server-utils");
|
|
3461
3448
|
var import_joi12 = __toESM(require("joi"));
|
|
3449
|
+
var import_node_server_utils22 = require("@iservice365/node-server-utils");
|
|
3462
3450
|
function useStockController() {
|
|
3463
3451
|
const { getStocksBySupplyId: _getStocksBySupplyId } = useStockRepository();
|
|
3464
3452
|
const { createStock: _createStock } = useStockService();
|
|
@@ -3529,9 +3517,9 @@ function useStockController() {
|
|
|
3529
3517
|
}
|
|
3530
3518
|
|
|
3531
3519
|
// src/models/hygiene-request-item.model.ts
|
|
3532
|
-
var import_node_server_utils23 = require("@iservice365/node-server-utils");
|
|
3533
3520
|
var import_joi13 = __toESM(require("joi"));
|
|
3534
3521
|
var import_mongodb13 = require("mongodb");
|
|
3522
|
+
var import_node_server_utils23 = require("@iservice365/node-server-utils");
|
|
3535
3523
|
var allowedRequestItemStatus = [
|
|
3536
3524
|
"pending",
|
|
3537
3525
|
"approved",
|
|
@@ -3666,6 +3654,7 @@ function useRequestItemRepository() {
|
|
|
3666
3654
|
{ $match: query },
|
|
3667
3655
|
{
|
|
3668
3656
|
$project: {
|
|
3657
|
+
supplyName: 1,
|
|
3669
3658
|
createdAt: 1,
|
|
3670
3659
|
status: 1
|
|
3671
3660
|
}
|
|
@@ -3824,8 +3813,8 @@ function useRequestItemRepository() {
|
|
|
3824
3813
|
}
|
|
3825
3814
|
|
|
3826
3815
|
// src/services/hygiene-request-item.service.ts
|
|
3827
|
-
var import_node_server_utils25 = require("@iservice365/node-server-utils");
|
|
3828
3816
|
var import_core = require("@iservice365/core");
|
|
3817
|
+
var import_node_server_utils25 = require("@iservice365/node-server-utils");
|
|
3829
3818
|
function useRequestItemService() {
|
|
3830
3819
|
const {
|
|
3831
3820
|
createRequestItem: _createRequestItem,
|
|
@@ -3940,8 +3929,8 @@ function useRequestItemService() {
|
|
|
3940
3929
|
}
|
|
3941
3930
|
|
|
3942
3931
|
// src/controllers/hygiene-request-item.controller.ts
|
|
3943
|
-
var import_node_server_utils26 = require("@iservice365/node-server-utils");
|
|
3944
3932
|
var import_joi14 = __toESM(require("joi"));
|
|
3933
|
+
var import_node_server_utils26 = require("@iservice365/node-server-utils");
|
|
3945
3934
|
function useRequestItemController() {
|
|
3946
3935
|
const {
|
|
3947
3936
|
getRequestItems: _getRequestItems,
|
|
@@ -4133,24 +4122,22 @@ function useRequestItemController() {
|
|
|
4133
4122
|
var import_node_server_utils27 = require("@iservice365/node-server-utils");
|
|
4134
4123
|
var import_joi15 = __toESM(require("joi"));
|
|
4135
4124
|
var import_mongodb15 = require("mongodb");
|
|
4136
|
-
var allowedFrequency = [
|
|
4137
|
-
|
|
4138
|
-
"
|
|
4139
|
-
"
|
|
4140
|
-
"
|
|
4141
|
-
"Thu",
|
|
4142
|
-
"Fri",
|
|
4143
|
-
"Sat",
|
|
4144
|
-
"Sun"
|
|
4125
|
+
var allowedFrequency = [
|
|
4126
|
+
"daily",
|
|
4127
|
+
"weekly",
|
|
4128
|
+
"monthly",
|
|
4129
|
+
"annually"
|
|
4145
4130
|
];
|
|
4146
|
-
var
|
|
4147
|
-
|
|
4148
|
-
"
|
|
4149
|
-
"
|
|
4150
|
-
"
|
|
4151
|
-
"
|
|
4152
|
-
"
|
|
4131
|
+
var allowedDays = [
|
|
4132
|
+
"Monday",
|
|
4133
|
+
"Tuesday",
|
|
4134
|
+
"Wednesday",
|
|
4135
|
+
"Thursday",
|
|
4136
|
+
"Friday",
|
|
4137
|
+
"Saturday",
|
|
4138
|
+
"Sunday"
|
|
4153
4139
|
];
|
|
4140
|
+
var allowedWeekOfMonth = ["start", "end"];
|
|
4154
4141
|
var allowedMonths = [
|
|
4155
4142
|
"January",
|
|
4156
4143
|
"February",
|
|
@@ -4170,22 +4157,10 @@ var scheduleTaskSchema = import_joi15.default.object({
|
|
|
4170
4157
|
title: import_joi15.default.string().required(),
|
|
4171
4158
|
frequency: import_joi15.default.string().valid(...allowedFrequency).required(),
|
|
4172
4159
|
time: import_joi15.default.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).required(),
|
|
4173
|
-
day: import_joi15.default.string().valid(...allowedDays).
|
|
4174
|
-
weekOfMonth: import_joi15.default.string().valid(...allowedWeekOfMonth).
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
otherwise: import_joi15.default.optional().allow("", null)
|
|
4178
|
-
}),
|
|
4179
|
-
quarter: import_joi15.default.string().valid(...allowedQuarter).when("frequency", {
|
|
4180
|
-
is: "quarter",
|
|
4181
|
-
then: import_joi15.default.required(),
|
|
4182
|
-
otherwise: import_joi15.default.optional().allow("", null)
|
|
4183
|
-
}),
|
|
4184
|
-
month: import_joi15.default.string().valid(...allowedMonths).when("frequency", {
|
|
4185
|
-
is: import_joi15.default.string().valid("quarter", "year"),
|
|
4186
|
-
then: import_joi15.default.required(),
|
|
4187
|
-
otherwise: import_joi15.default.optional().allow("", null)
|
|
4188
|
-
}),
|
|
4160
|
+
day: import_joi15.default.array().items(import_joi15.default.string().valid(...allowedDays)).optional().allow(null),
|
|
4161
|
+
weekOfMonth: import_joi15.default.string().valid(...allowedWeekOfMonth).optional().allow("", null),
|
|
4162
|
+
month: import_joi15.default.string().valid(...allowedMonths).optional().allow("", null),
|
|
4163
|
+
date: import_joi15.default.number().min(1).max(31).optional().allow(null),
|
|
4189
4164
|
description: import_joi15.default.string().optional().allow("", null),
|
|
4190
4165
|
areas: import_joi15.default.array().min(1).items(
|
|
4191
4166
|
import_joi15.default.object({
|
|
@@ -4226,8 +4201,8 @@ function MScheduleTask(value) {
|
|
|
4226
4201
|
time: value.time,
|
|
4227
4202
|
day: value.day,
|
|
4228
4203
|
weekOfMonth: value.weekOfMonth,
|
|
4229
|
-
quarter: value.quarter,
|
|
4230
4204
|
month: value.month,
|
|
4205
|
+
date: value.date,
|
|
4231
4206
|
description: value.description,
|
|
4232
4207
|
areas: value.areas,
|
|
4233
4208
|
status: "active",
|
|
@@ -4343,6 +4318,73 @@ function useScheduleTaskRepository() {
|
|
|
4343
4318
|
throw error;
|
|
4344
4319
|
}
|
|
4345
4320
|
}
|
|
4321
|
+
async function getAllScheduleTask() {
|
|
4322
|
+
const query = {
|
|
4323
|
+
status: { $ne: "deleted" }
|
|
4324
|
+
};
|
|
4325
|
+
try {
|
|
4326
|
+
const items = await collection.aggregate([{ $match: query }, { $sort: { _id: -1 } }]).toArray();
|
|
4327
|
+
return items;
|
|
4328
|
+
} catch (error) {
|
|
4329
|
+
throw error;
|
|
4330
|
+
}
|
|
4331
|
+
}
|
|
4332
|
+
async function getTasksForScheduleTask({
|
|
4333
|
+
page = 1,
|
|
4334
|
+
limit = 10,
|
|
4335
|
+
search = "",
|
|
4336
|
+
site
|
|
4337
|
+
}) {
|
|
4338
|
+
page = page > 0 ? page - 1 : 0;
|
|
4339
|
+
const query = {
|
|
4340
|
+
status: { $ne: "deleted" }
|
|
4341
|
+
};
|
|
4342
|
+
const cacheOptions = {
|
|
4343
|
+
page,
|
|
4344
|
+
limit
|
|
4345
|
+
};
|
|
4346
|
+
try {
|
|
4347
|
+
site = new import_mongodb16.ObjectId(site);
|
|
4348
|
+
query.site = site;
|
|
4349
|
+
cacheOptions.site = site.toString();
|
|
4350
|
+
} catch (error) {
|
|
4351
|
+
throw new import_node_server_utils28.BadRequestError("Invalid site ID format.");
|
|
4352
|
+
}
|
|
4353
|
+
if (search) {
|
|
4354
|
+
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
4355
|
+
cacheOptions.search = search;
|
|
4356
|
+
}
|
|
4357
|
+
const cacheKey = (0, import_node_server_utils28.makeCacheKey)(namespace_collection, cacheOptions);
|
|
4358
|
+
const cachedData = await getCache(cacheKey);
|
|
4359
|
+
if (cachedData) {
|
|
4360
|
+
import_node_server_utils28.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
4361
|
+
return cachedData;
|
|
4362
|
+
}
|
|
4363
|
+
try {
|
|
4364
|
+
const items = await collection.aggregate([
|
|
4365
|
+
{ $match: query },
|
|
4366
|
+
{
|
|
4367
|
+
$project: {
|
|
4368
|
+
createdAt: 1,
|
|
4369
|
+
title: 1
|
|
4370
|
+
}
|
|
4371
|
+
},
|
|
4372
|
+
{ $sort: { _id: -1 } },
|
|
4373
|
+
{ $skip: page * limit },
|
|
4374
|
+
{ $limit: limit }
|
|
4375
|
+
]).toArray();
|
|
4376
|
+
const length = await collection.countDocuments(query);
|
|
4377
|
+
const data = (0, import_node_server_utils28.paginate)(items, page, limit, length);
|
|
4378
|
+
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4379
|
+
import_node_server_utils28.logger.info(`Cache set for key: ${cacheKey}`);
|
|
4380
|
+
}).catch((err) => {
|
|
4381
|
+
import_node_server_utils28.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4382
|
+
});
|
|
4383
|
+
return data;
|
|
4384
|
+
} catch (error) {
|
|
4385
|
+
throw error;
|
|
4386
|
+
}
|
|
4387
|
+
}
|
|
4346
4388
|
async function getScheduleTaskById(_id, session) {
|
|
4347
4389
|
try {
|
|
4348
4390
|
_id = new import_mongodb16.ObjectId(_id);
|
|
@@ -4375,8 +4417,8 @@ function useScheduleTaskRepository() {
|
|
|
4375
4417
|
time: 1,
|
|
4376
4418
|
day: 1,
|
|
4377
4419
|
weekOfMonth: 1,
|
|
4378
|
-
quarter: 1,
|
|
4379
4420
|
month: 1,
|
|
4421
|
+
date: 1,
|
|
4380
4422
|
description: 1,
|
|
4381
4423
|
areas: 1,
|
|
4382
4424
|
status: 1,
|
|
@@ -4445,18 +4487,213 @@ function useScheduleTaskRepository() {
|
|
|
4445
4487
|
createTextIndex,
|
|
4446
4488
|
createScheduleTask,
|
|
4447
4489
|
getScheduleTasks,
|
|
4490
|
+
getAllScheduleTask,
|
|
4491
|
+
getTasksForScheduleTask,
|
|
4448
4492
|
getScheduleTaskById,
|
|
4449
4493
|
updateScheduleTask
|
|
4450
4494
|
};
|
|
4451
4495
|
}
|
|
4452
4496
|
|
|
4453
|
-
// src/
|
|
4497
|
+
// src/services/hygiene-schedule-task.service.ts
|
|
4454
4498
|
var import_node_server_utils29 = require("@iservice365/node-server-utils");
|
|
4499
|
+
function useScheduleTaskService() {
|
|
4500
|
+
const { createParentChecklist } = useParentChecklistRepo();
|
|
4501
|
+
const { getAllScheduleTask } = useScheduleTaskRepository();
|
|
4502
|
+
const { createAreaChecklist } = useAreaChecklistService();
|
|
4503
|
+
function checkScheduleConditions(schedule, currentDate = /* @__PURE__ */ new Date()) {
|
|
4504
|
+
try {
|
|
4505
|
+
const now = currentDate;
|
|
4506
|
+
const currentDay = now.toLocaleDateString("en-US", {
|
|
4507
|
+
weekday: "long",
|
|
4508
|
+
timeZone: "Asia/Singapore"
|
|
4509
|
+
});
|
|
4510
|
+
const currentMonth = now.toLocaleDateString("en-US", {
|
|
4511
|
+
month: "long",
|
|
4512
|
+
timeZone: "Asia/Singapore"
|
|
4513
|
+
});
|
|
4514
|
+
const currentDate_num = Number(
|
|
4515
|
+
now.toLocaleDateString("en-US", {
|
|
4516
|
+
day: "numeric",
|
|
4517
|
+
timeZone: "Asia/Singapore"
|
|
4518
|
+
})
|
|
4519
|
+
);
|
|
4520
|
+
const timeString = now.toLocaleTimeString("en-US", {
|
|
4521
|
+
hour: "2-digit",
|
|
4522
|
+
minute: "2-digit",
|
|
4523
|
+
hour12: false,
|
|
4524
|
+
timeZone: "Asia/Singapore"
|
|
4525
|
+
});
|
|
4526
|
+
const [currentHour, currentMinute] = timeString.split(":").map(Number);
|
|
4527
|
+
import_node_server_utils29.logger.info(
|
|
4528
|
+
`Checking schedule ${schedule._id}: Current time ${currentHour}:${currentMinute}, Schedule time ${schedule.time}, Frequency ${schedule.frequency}`
|
|
4529
|
+
);
|
|
4530
|
+
const [scheduleHour, scheduleMinute] = schedule.time.split(":").map(Number);
|
|
4531
|
+
const timeMatches = currentHour === scheduleHour && currentMinute === scheduleMinute;
|
|
4532
|
+
if (!timeMatches) {
|
|
4533
|
+
import_node_server_utils29.logger.info(
|
|
4534
|
+
`Schedule ${schedule._id}: Time does not match. Current: ${currentHour}:${currentMinute}, Expected: ${scheduleHour}:${scheduleMinute}`
|
|
4535
|
+
);
|
|
4536
|
+
return false;
|
|
4537
|
+
}
|
|
4538
|
+
import_node_server_utils29.logger.info(
|
|
4539
|
+
`Schedule ${schedule._id}: Time matches, checking frequency...`
|
|
4540
|
+
);
|
|
4541
|
+
switch (schedule.frequency) {
|
|
4542
|
+
case "daily":
|
|
4543
|
+
import_node_server_utils29.logger.info(`Schedule ${schedule._id}: Daily frequency matched`);
|
|
4544
|
+
return true;
|
|
4545
|
+
case "weekly":
|
|
4546
|
+
if (!schedule.day || schedule.day.length === 0) {
|
|
4547
|
+
import_node_server_utils29.logger.warn(
|
|
4548
|
+
`Schedule ${schedule._id} is weekly but has no days specified`
|
|
4549
|
+
);
|
|
4550
|
+
return false;
|
|
4551
|
+
}
|
|
4552
|
+
const dayMatches = schedule.day.includes(currentDay);
|
|
4553
|
+
import_node_server_utils29.logger.info(
|
|
4554
|
+
`Schedule ${schedule._id}: Weekly - Current day: ${currentDay}, Schedule days: ${schedule.day.join(
|
|
4555
|
+
", "
|
|
4556
|
+
)}, Match: ${dayMatches}`
|
|
4557
|
+
);
|
|
4558
|
+
return dayMatches;
|
|
4559
|
+
case "monthly":
|
|
4560
|
+
if (!schedule.weekOfMonth) {
|
|
4561
|
+
import_node_server_utils29.logger.warn(
|
|
4562
|
+
`Schedule ${schedule._id} is monthly but has no weekOfMonth specified`
|
|
4563
|
+
);
|
|
4564
|
+
return false;
|
|
4565
|
+
}
|
|
4566
|
+
if (schedule.weekOfMonth === "start") {
|
|
4567
|
+
const matches2 = currentDate_num >= 1 && currentDate_num <= 7;
|
|
4568
|
+
import_node_server_utils29.logger.info(
|
|
4569
|
+
`Schedule ${schedule._id}: Monthly start - Current date: ${currentDate_num}, Match: ${matches2}`
|
|
4570
|
+
);
|
|
4571
|
+
return matches2;
|
|
4572
|
+
} else if (schedule.weekOfMonth === "end") {
|
|
4573
|
+
const lastDayOfMonth = new Date(
|
|
4574
|
+
now.getFullYear(),
|
|
4575
|
+
now.getMonth() + 1,
|
|
4576
|
+
0
|
|
4577
|
+
).getDate();
|
|
4578
|
+
const matches2 = currentDate_num > lastDayOfMonth - 7;
|
|
4579
|
+
import_node_server_utils29.logger.info(
|
|
4580
|
+
`Schedule ${schedule._id}: Monthly end - Current date: ${currentDate_num}, Last day: ${lastDayOfMonth}, Match: ${matches2}`
|
|
4581
|
+
);
|
|
4582
|
+
return matches2;
|
|
4583
|
+
}
|
|
4584
|
+
return false;
|
|
4585
|
+
case "annually":
|
|
4586
|
+
if (!schedule.month || !schedule.date) {
|
|
4587
|
+
import_node_server_utils29.logger.warn(
|
|
4588
|
+
`Schedule ${schedule._id} is annually but has no month or date specified`
|
|
4589
|
+
);
|
|
4590
|
+
return false;
|
|
4591
|
+
}
|
|
4592
|
+
const matches = currentMonth === schedule.month && currentDate_num === schedule.date;
|
|
4593
|
+
import_node_server_utils29.logger.info(
|
|
4594
|
+
`Schedule ${schedule._id}: Annually - Current: ${currentMonth} ${currentDate_num}, Expected: ${schedule.month} ${schedule.date}, Match: ${matches}`
|
|
4595
|
+
);
|
|
4596
|
+
return matches;
|
|
4597
|
+
default:
|
|
4598
|
+
import_node_server_utils29.logger.warn(`Unknown frequency type: ${schedule.frequency}`);
|
|
4599
|
+
return false;
|
|
4600
|
+
}
|
|
4601
|
+
} catch (error) {
|
|
4602
|
+
import_node_server_utils29.logger.error(
|
|
4603
|
+
`Error checking schedule conditions for ${schedule._id}:`,
|
|
4604
|
+
error
|
|
4605
|
+
);
|
|
4606
|
+
return false;
|
|
4607
|
+
}
|
|
4608
|
+
}
|
|
4609
|
+
async function processScheduledTasks(currentDate) {
|
|
4610
|
+
try {
|
|
4611
|
+
import_node_server_utils29.logger.info("Starting scheduled task processing...");
|
|
4612
|
+
const scheduleTasks = await getAllScheduleTask();
|
|
4613
|
+
if (!scheduleTasks || scheduleTasks.length === 0) {
|
|
4614
|
+
import_node_server_utils29.logger.info("No schedule tasks found to process");
|
|
4615
|
+
return { processed: 0, validated: 0 };
|
|
4616
|
+
}
|
|
4617
|
+
import_node_server_utils29.logger.info(`Found ${scheduleTasks.length} schedule tasks to check`);
|
|
4618
|
+
let processedCount = 0;
|
|
4619
|
+
let validatedCount = 0;
|
|
4620
|
+
const validatedTasks = [];
|
|
4621
|
+
for (const scheduleTask of scheduleTasks) {
|
|
4622
|
+
try {
|
|
4623
|
+
import_node_server_utils29.logger.info(
|
|
4624
|
+
`Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time}, frequency=${scheduleTask.frequency}`
|
|
4625
|
+
);
|
|
4626
|
+
const shouldRun = checkScheduleConditions(scheduleTask, currentDate);
|
|
4627
|
+
if (!shouldRun) {
|
|
4628
|
+
import_node_server_utils29.logger.info(
|
|
4629
|
+
`Schedule ${scheduleTask._id} conditions not met, skipping`
|
|
4630
|
+
);
|
|
4631
|
+
continue;
|
|
4632
|
+
}
|
|
4633
|
+
import_node_server_utils29.logger.info(
|
|
4634
|
+
`Schedule ${scheduleTask._id} conditions validated, creating area checklists`
|
|
4635
|
+
);
|
|
4636
|
+
if (!scheduleTask._id) {
|
|
4637
|
+
import_node_server_utils29.logger.warn(`Schedule ${scheduleTask.title} has no _id, skipping`);
|
|
4638
|
+
continue;
|
|
4639
|
+
}
|
|
4640
|
+
if (!scheduleTask.site) {
|
|
4641
|
+
import_node_server_utils29.logger.warn(`Schedule ${scheduleTask._id} has no site, skipping`);
|
|
4642
|
+
continue;
|
|
4643
|
+
}
|
|
4644
|
+
import_node_server_utils29.logger.info(
|
|
4645
|
+
`Getting or creating parent checklist for schedule ${scheduleTask._id} in site ${scheduleTask.site}`
|
|
4646
|
+
);
|
|
4647
|
+
const parentChecklistIds = await createParentChecklist({
|
|
4648
|
+
site: scheduleTask.site.toString(),
|
|
4649
|
+
createdAt: /* @__PURE__ */ new Date()
|
|
4650
|
+
});
|
|
4651
|
+
const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
|
|
4652
|
+
import_node_server_utils29.logger.info(
|
|
4653
|
+
`Using parent checklist ${parentChecklistId}, now creating area checklists`
|
|
4654
|
+
);
|
|
4655
|
+
const createdChecklistIds = await createAreaChecklist({
|
|
4656
|
+
schedule: parentChecklistId.toString(),
|
|
4657
|
+
site: scheduleTask.site.toString()
|
|
4658
|
+
});
|
|
4659
|
+
processedCount++;
|
|
4660
|
+
validatedCount++;
|
|
4661
|
+
validatedTasks.push(scheduleTask);
|
|
4662
|
+
import_node_server_utils29.logger.info(
|
|
4663
|
+
`Successfully processed schedule ${scheduleTask._id}, created parent checklist ${parentChecklistId} and ${createdChecklistIds.length} area checklists`
|
|
4664
|
+
);
|
|
4665
|
+
} catch (error) {
|
|
4666
|
+
import_node_server_utils29.logger.error(
|
|
4667
|
+
`Error processing schedule task ${scheduleTask._id}:`,
|
|
4668
|
+
error
|
|
4669
|
+
);
|
|
4670
|
+
continue;
|
|
4671
|
+
}
|
|
4672
|
+
}
|
|
4673
|
+
import_node_server_utils29.logger.info(
|
|
4674
|
+
`Scheduled task processing completed. Processed: ${processedCount}, Validated: ${validatedCount} tasks`
|
|
4675
|
+
);
|
|
4676
|
+
return {
|
|
4677
|
+
processed: processedCount,
|
|
4678
|
+
validated: validatedCount,
|
|
4679
|
+
tasks: validatedTasks
|
|
4680
|
+
};
|
|
4681
|
+
} catch (error) {
|
|
4682
|
+
import_node_server_utils29.logger.error("Error processing scheduled tasks:", error);
|
|
4683
|
+
throw error;
|
|
4684
|
+
}
|
|
4685
|
+
}
|
|
4686
|
+
return { checkScheduleConditions, processScheduledTasks };
|
|
4687
|
+
}
|
|
4688
|
+
|
|
4689
|
+
// src/controllers/hygiene-schedule-task.controller.ts
|
|
4455
4690
|
var import_joi16 = __toESM(require("joi"));
|
|
4691
|
+
var import_node_server_utils30 = require("@iservice365/node-server-utils");
|
|
4456
4692
|
function useScheduleTaskController() {
|
|
4457
4693
|
const {
|
|
4458
4694
|
createScheduleTask: _createScheduleTask,
|
|
4459
4695
|
getScheduleTasks: _getScheduleTasks,
|
|
4696
|
+
getTasksForScheduleTask: _getTasksForScheduleTask,
|
|
4460
4697
|
getScheduleTaskById: _getScheduleTaskById,
|
|
4461
4698
|
updateScheduleTask: _updateScheduleTask
|
|
4462
4699
|
} = useScheduleTaskRepository();
|
|
@@ -4464,8 +4701,8 @@ function useScheduleTaskController() {
|
|
|
4464
4701
|
const payload = { ...req.body, ...req.params };
|
|
4465
4702
|
const { error } = scheduleTaskSchema.validate(payload);
|
|
4466
4703
|
if (error) {
|
|
4467
|
-
|
|
4468
|
-
next(new
|
|
4704
|
+
import_node_server_utils30.logger.log({ level: "error", message: error.message });
|
|
4705
|
+
next(new import_node_server_utils30.BadRequestError(error.message));
|
|
4469
4706
|
return;
|
|
4470
4707
|
}
|
|
4471
4708
|
try {
|
|
@@ -4473,7 +4710,7 @@ function useScheduleTaskController() {
|
|
|
4473
4710
|
res.status(201).json({ message: "Schedule task created successfully.", id });
|
|
4474
4711
|
return;
|
|
4475
4712
|
} catch (error2) {
|
|
4476
|
-
|
|
4713
|
+
import_node_server_utils30.logger.log({ level: "error", message: error2.message });
|
|
4477
4714
|
next(error2);
|
|
4478
4715
|
return;
|
|
4479
4716
|
}
|
|
@@ -4488,8 +4725,8 @@ function useScheduleTaskController() {
|
|
|
4488
4725
|
});
|
|
4489
4726
|
const { error } = validation.validate(query);
|
|
4490
4727
|
if (error) {
|
|
4491
|
-
|
|
4492
|
-
next(new
|
|
4728
|
+
import_node_server_utils30.logger.log({ level: "error", message: error.message });
|
|
4729
|
+
next(new import_node_server_utils30.BadRequestError(error.message));
|
|
4493
4730
|
return;
|
|
4494
4731
|
}
|
|
4495
4732
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -4506,7 +4743,40 @@ function useScheduleTaskController() {
|
|
|
4506
4743
|
res.json(data);
|
|
4507
4744
|
return;
|
|
4508
4745
|
} catch (error2) {
|
|
4509
|
-
|
|
4746
|
+
import_node_server_utils30.logger.log({ level: "error", message: error2.message });
|
|
4747
|
+
next(error2);
|
|
4748
|
+
return;
|
|
4749
|
+
}
|
|
4750
|
+
}
|
|
4751
|
+
async function getTasksForScheduleTask(req, res, next) {
|
|
4752
|
+
const query = { ...req.query, ...req.params };
|
|
4753
|
+
const validation = import_joi16.default.object({
|
|
4754
|
+
page: import_joi16.default.number().min(1).optional().allow("", null),
|
|
4755
|
+
limit: import_joi16.default.number().min(1).optional().allow("", null),
|
|
4756
|
+
search: import_joi16.default.string().optional().allow("", null),
|
|
4757
|
+
site: import_joi16.default.string().hex().required()
|
|
4758
|
+
});
|
|
4759
|
+
const { error } = validation.validate(query);
|
|
4760
|
+
if (error) {
|
|
4761
|
+
import_node_server_utils30.logger.log({ level: "error", message: error.message });
|
|
4762
|
+
next(new import_node_server_utils30.BadRequestError(error.message));
|
|
4763
|
+
return;
|
|
4764
|
+
}
|
|
4765
|
+
const page = parseInt(req.query.page) ?? 1;
|
|
4766
|
+
const limit = parseInt(req.query.limit) ?? 10;
|
|
4767
|
+
const search = req.query.search ?? "";
|
|
4768
|
+
const site = req.params.site ?? "";
|
|
4769
|
+
try {
|
|
4770
|
+
const data = await _getTasksForScheduleTask({
|
|
4771
|
+
page,
|
|
4772
|
+
limit,
|
|
4773
|
+
search,
|
|
4774
|
+
site
|
|
4775
|
+
});
|
|
4776
|
+
res.json(data);
|
|
4777
|
+
return;
|
|
4778
|
+
} catch (error2) {
|
|
4779
|
+
import_node_server_utils30.logger.log({ level: "error", message: error2.message });
|
|
4510
4780
|
next(error2);
|
|
4511
4781
|
return;
|
|
4512
4782
|
}
|
|
@@ -4516,8 +4786,8 @@ function useScheduleTaskController() {
|
|
|
4516
4786
|
const _id = req.params.id;
|
|
4517
4787
|
const { error } = validation.validate(_id);
|
|
4518
4788
|
if (error) {
|
|
4519
|
-
|
|
4520
|
-
next(new
|
|
4789
|
+
import_node_server_utils30.logger.log({ level: "error", message: error.message });
|
|
4790
|
+
next(new import_node_server_utils30.BadRequestError(error.message));
|
|
4521
4791
|
return;
|
|
4522
4792
|
}
|
|
4523
4793
|
try {
|
|
@@ -4525,7 +4795,7 @@ function useScheduleTaskController() {
|
|
|
4525
4795
|
res.json(data);
|
|
4526
4796
|
return;
|
|
4527
4797
|
} catch (error2) {
|
|
4528
|
-
|
|
4798
|
+
import_node_server_utils30.logger.log({ level: "error", message: error2.message });
|
|
4529
4799
|
next(error2);
|
|
4530
4800
|
return;
|
|
4531
4801
|
}
|
|
@@ -4537,10 +4807,10 @@ function useScheduleTaskController() {
|
|
|
4537
4807
|
title: import_joi16.default.string().optional().allow("", null),
|
|
4538
4808
|
frequency: import_joi16.default.string().valid(...allowedFrequency).optional().allow("", null),
|
|
4539
4809
|
time: import_joi16.default.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).optional().allow("", null),
|
|
4540
|
-
day: import_joi16.default.string().valid(...allowedDays).optional().allow(
|
|
4810
|
+
day: import_joi16.default.array().items(import_joi16.default.string().valid(...allowedDays)).optional().allow(null),
|
|
4541
4811
|
weekOfMonth: import_joi16.default.string().valid(...allowedWeekOfMonth).optional().allow("", null),
|
|
4542
|
-
quarter: import_joi16.default.string().valid(...allowedQuarter).optional().allow("", null),
|
|
4543
4812
|
month: import_joi16.default.string().valid(...allowedMonths).optional().allow("", null),
|
|
4813
|
+
date: import_joi16.default.number().min(1).max(31).optional().allow(null),
|
|
4544
4814
|
description: import_joi16.default.string().optional().allow("", null),
|
|
4545
4815
|
areas: import_joi16.default.array().min(1).items(
|
|
4546
4816
|
import_joi16.default.object({
|
|
@@ -4551,8 +4821,8 @@ function useScheduleTaskController() {
|
|
|
4551
4821
|
});
|
|
4552
4822
|
const { error } = validation.validate(payload);
|
|
4553
4823
|
if (error) {
|
|
4554
|
-
|
|
4555
|
-
next(new
|
|
4824
|
+
import_node_server_utils30.logger.log({ level: "error", message: error.message });
|
|
4825
|
+
next(new import_node_server_utils30.BadRequestError(error.message));
|
|
4556
4826
|
return;
|
|
4557
4827
|
}
|
|
4558
4828
|
try {
|
|
@@ -4561,7 +4831,7 @@ function useScheduleTaskController() {
|
|
|
4561
4831
|
res.json({ message: "Schedule task updated successfully." });
|
|
4562
4832
|
return;
|
|
4563
4833
|
} catch (error2) {
|
|
4564
|
-
|
|
4834
|
+
import_node_server_utils30.logger.log({ level: "error", message: error2.message });
|
|
4565
4835
|
next(error2);
|
|
4566
4836
|
return;
|
|
4567
4837
|
}
|
|
@@ -4569,6 +4839,7 @@ function useScheduleTaskController() {
|
|
|
4569
4839
|
return {
|
|
4570
4840
|
createScheduleTask,
|
|
4571
4841
|
getScheduleTasks,
|
|
4842
|
+
getTasksForScheduleTask,
|
|
4572
4843
|
getScheduleTaskById,
|
|
4573
4844
|
updateScheduleTask
|
|
4574
4845
|
};
|
|
@@ -4587,7 +4858,6 @@ function useScheduleTaskController() {
|
|
|
4587
4858
|
allowedDays,
|
|
4588
4859
|
allowedFrequency,
|
|
4589
4860
|
allowedMonths,
|
|
4590
|
-
allowedQuarter,
|
|
4591
4861
|
allowedRequestItemStatus,
|
|
4592
4862
|
allowedStatus,
|
|
4593
4863
|
allowedTypes,
|
|
@@ -4613,6 +4883,7 @@ function useScheduleTaskController() {
|
|
|
4613
4883
|
useRequestItemService,
|
|
4614
4884
|
useScheduleTaskController,
|
|
4615
4885
|
useScheduleTaskRepository,
|
|
4886
|
+
useScheduleTaskService,
|
|
4616
4887
|
useStockController,
|
|
4617
4888
|
useStockRepository,
|
|
4618
4889
|
useStockService,
|