@7365admin1/module-hygiene 4.12.0 → 4.14.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 +74 -29
- package/dist/index.js +334 -229
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +338 -230
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -38,6 +38,7 @@ __export(src_exports, {
|
|
|
38
38
|
MStock: () => MStock,
|
|
39
39
|
MSupply: () => MSupply,
|
|
40
40
|
MUnit: () => MUnit,
|
|
41
|
+
ServiceType: () => ServiceType,
|
|
41
42
|
allowedCheckOutItemStatus: () => allowedCheckOutItemStatus,
|
|
42
43
|
allowedChecklistStatus: () => allowedChecklistStatus,
|
|
43
44
|
allowedPeriods: () => allowedPeriods,
|
|
@@ -83,6 +84,17 @@ __export(src_exports, {
|
|
|
83
84
|
module.exports = __toCommonJS(src_exports);
|
|
84
85
|
|
|
85
86
|
// src/models/hygiene-base.model.ts
|
|
87
|
+
var ServiceType = /* @__PURE__ */ ((ServiceType2) => {
|
|
88
|
+
ServiceType2["REAL_ESTATE_DEVELOPER"] = "real_estate_developer";
|
|
89
|
+
ServiceType2["PROPERTY_MANAGEMENT_AGENCY"] = "property_management_agency";
|
|
90
|
+
ServiceType2["SECURITY_AGENCY"] = "security_agency";
|
|
91
|
+
ServiceType2["CLEANING_SERVICES"] = "cleaning_services";
|
|
92
|
+
ServiceType2["MECHANICAL_ELECTRICAL_SERVICES"] = "mechanical_electrical_services";
|
|
93
|
+
ServiceType2["LANDSCAPING_SERVICES"] = "landscaping_services";
|
|
94
|
+
ServiceType2["PEST_CONTROL_SERVICES"] = "pest_control_services";
|
|
95
|
+
ServiceType2["POOL_MAINTENANCE_SERVICES"] = "pool_maintenance_services";
|
|
96
|
+
return ServiceType2;
|
|
97
|
+
})(ServiceType || {});
|
|
86
98
|
var allowedTypes = ["common", "toilet"];
|
|
87
99
|
var allowedStatus = [
|
|
88
100
|
"open",
|
|
@@ -624,6 +636,7 @@ var import_mongodb2 = require("mongodb");
|
|
|
624
636
|
var import_node_server_utils3 = require("@7365admin1/node-server-utils");
|
|
625
637
|
var areaSchema = import_joi2.default.object({
|
|
626
638
|
site: import_joi2.default.string().hex().required(),
|
|
639
|
+
serviceType: import_joi2.default.string().valid(...Object.values(ServiceType)).required(),
|
|
627
640
|
name: import_joi2.default.string().required(),
|
|
628
641
|
type: import_joi2.default.string().valid(...allowedTypes).required(),
|
|
629
642
|
set: import_joi2.default.number().min(0).optional(),
|
|
@@ -663,6 +676,7 @@ function MArea(value) {
|
|
|
663
676
|
}
|
|
664
677
|
return {
|
|
665
678
|
site: value.site,
|
|
679
|
+
serviceType: value.serviceType,
|
|
666
680
|
name: value.name,
|
|
667
681
|
type: value.type,
|
|
668
682
|
set: value.set ?? 0,
|
|
@@ -698,6 +712,7 @@ function useAreaRepo() {
|
|
|
698
712
|
try {
|
|
699
713
|
await collection.createIndexes([
|
|
700
714
|
{ key: { site: 1 } },
|
|
715
|
+
{ key: { serviceType: 1 } },
|
|
701
716
|
{ key: { type: 1 } },
|
|
702
717
|
{ key: { status: 1 } },
|
|
703
718
|
{ key: { "units.unit": 1 } }
|
|
@@ -718,7 +733,7 @@ function useAreaRepo() {
|
|
|
718
733
|
async function createUniqueIndex() {
|
|
719
734
|
try {
|
|
720
735
|
await collection.createIndex(
|
|
721
|
-
{ site: 1, name: 1, type: 1, deletedAt: 1 },
|
|
736
|
+
{ site: 1, serviceType: 1, name: 1, type: 1, deletedAt: 1 },
|
|
722
737
|
{ unique: true }
|
|
723
738
|
);
|
|
724
739
|
} catch (error) {
|
|
@@ -755,15 +770,18 @@ function useAreaRepo() {
|
|
|
755
770
|
limit = 10,
|
|
756
771
|
search = "",
|
|
757
772
|
type = "all",
|
|
758
|
-
site
|
|
773
|
+
site,
|
|
774
|
+
serviceType
|
|
759
775
|
}) {
|
|
760
776
|
page = page > 0 ? page - 1 : 0;
|
|
761
777
|
const query = {
|
|
762
|
-
status: { $ne: "deleted" }
|
|
778
|
+
status: { $ne: "deleted" },
|
|
779
|
+
serviceType
|
|
763
780
|
};
|
|
764
781
|
const cacheOptions = {
|
|
765
782
|
page,
|
|
766
|
-
limit
|
|
783
|
+
limit,
|
|
784
|
+
serviceType
|
|
767
785
|
};
|
|
768
786
|
try {
|
|
769
787
|
site = new import_mongodb3.ObjectId(site);
|
|
@@ -812,9 +830,12 @@ function useAreaRepo() {
|
|
|
812
830
|
throw error;
|
|
813
831
|
}
|
|
814
832
|
}
|
|
815
|
-
async function getAreasForChecklist(site) {
|
|
816
|
-
const query = {
|
|
817
|
-
|
|
833
|
+
async function getAreasForChecklist(site, serviceType) {
|
|
834
|
+
const query = {
|
|
835
|
+
status: { $ne: "deleted" },
|
|
836
|
+
serviceType
|
|
837
|
+
};
|
|
838
|
+
const cacheOptions = { serviceType };
|
|
818
839
|
try {
|
|
819
840
|
site = new import_mongodb3.ObjectId(site);
|
|
820
841
|
query.site = site;
|
|
@@ -894,28 +915,6 @@ function useAreaRepo() {
|
|
|
894
915
|
throw error;
|
|
895
916
|
}
|
|
896
917
|
}
|
|
897
|
-
async function getAreaByMultipleId(_id) {
|
|
898
|
-
for (let i = 0; i < _id.length; i++) {
|
|
899
|
-
try {
|
|
900
|
-
_id[i] = new import_mongodb3.ObjectId(_id[i]);
|
|
901
|
-
} catch (error) {
|
|
902
|
-
throw new import_node_server_utils4.BadRequestError("Invalid area ID format.");
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
const query = {
|
|
906
|
-
_id: { $in: _id },
|
|
907
|
-
status: { $ne: "deleted" }
|
|
908
|
-
};
|
|
909
|
-
try {
|
|
910
|
-
const data = await collection.aggregate([{ $match: query }]).toArray();
|
|
911
|
-
if (!data || data.length === 0) {
|
|
912
|
-
throw new import_node_server_utils4.NotFoundError("Area not found.");
|
|
913
|
-
}
|
|
914
|
-
return data;
|
|
915
|
-
} catch (error) {
|
|
916
|
-
throw error;
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
918
|
async function verifyAreaByUnitId(unitId) {
|
|
920
919
|
try {
|
|
921
920
|
unitId = new import_mongodb3.ObjectId(unitId);
|
|
@@ -1077,7 +1076,6 @@ function useAreaRepo() {
|
|
|
1077
1076
|
getAreas,
|
|
1078
1077
|
getAreasForChecklist,
|
|
1079
1078
|
getAreaById,
|
|
1080
|
-
getAreaByMultipleId,
|
|
1081
1079
|
verifyAreaByUnitId,
|
|
1082
1080
|
updateArea,
|
|
1083
1081
|
updateAreaChecklist,
|
|
@@ -1144,6 +1142,7 @@ var import_mongodb4 = require("mongodb");
|
|
|
1144
1142
|
var import_node_server_utils6 = require("@7365admin1/node-server-utils");
|
|
1145
1143
|
var unitSchema = import_joi3.default.object({
|
|
1146
1144
|
site: import_joi3.default.string().hex().required(),
|
|
1145
|
+
serviceType: import_joi3.default.string().valid(...Object.values(ServiceType)).required(),
|
|
1147
1146
|
name: import_joi3.default.string().required()
|
|
1148
1147
|
});
|
|
1149
1148
|
function MUnit(value) {
|
|
@@ -1161,6 +1160,7 @@ function MUnit(value) {
|
|
|
1161
1160
|
}
|
|
1162
1161
|
return {
|
|
1163
1162
|
site: value.site,
|
|
1163
|
+
serviceType: value.serviceType,
|
|
1164
1164
|
name: value.name,
|
|
1165
1165
|
status: "active",
|
|
1166
1166
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -1182,6 +1182,7 @@ function useUnitRepository() {
|
|
|
1182
1182
|
try {
|
|
1183
1183
|
await collection.createIndexes([
|
|
1184
1184
|
{ key: { site: 1 } },
|
|
1185
|
+
{ key: { serviceType: 1 } },
|
|
1185
1186
|
{ key: { status: 1 } }
|
|
1186
1187
|
]);
|
|
1187
1188
|
} catch (error) {
|
|
@@ -1200,7 +1201,7 @@ function useUnitRepository() {
|
|
|
1200
1201
|
async function createUniqueIndex() {
|
|
1201
1202
|
try {
|
|
1202
1203
|
await collection.createIndex(
|
|
1203
|
-
{ site: 1, name: 1, deletedAt: 1 },
|
|
1204
|
+
{ site: 1, serviceType: 1, name: 1, deletedAt: 1 },
|
|
1204
1205
|
{ unique: true }
|
|
1205
1206
|
);
|
|
1206
1207
|
} catch (error) {
|
|
@@ -1234,7 +1235,8 @@ function useUnitRepository() {
|
|
|
1234
1235
|
page = 1,
|
|
1235
1236
|
limit = 10,
|
|
1236
1237
|
search = "",
|
|
1237
|
-
site
|
|
1238
|
+
site,
|
|
1239
|
+
serviceType
|
|
1238
1240
|
}) {
|
|
1239
1241
|
page = page > 0 ? page - 1 : 0;
|
|
1240
1242
|
const query = {
|
|
@@ -1251,6 +1253,10 @@ function useUnitRepository() {
|
|
|
1251
1253
|
} catch (error) {
|
|
1252
1254
|
throw new import_node_server_utils7.BadRequestError("Invalid site ID format.");
|
|
1253
1255
|
}
|
|
1256
|
+
if (serviceType) {
|
|
1257
|
+
query.serviceType = serviceType;
|
|
1258
|
+
cacheOptions.serviceType = serviceType;
|
|
1259
|
+
}
|
|
1254
1260
|
if (search) {
|
|
1255
1261
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
1256
1262
|
cacheOptions.search = search;
|
|
@@ -1309,7 +1315,7 @@ function useUnitRepository() {
|
|
|
1309
1315
|
} catch (error) {
|
|
1310
1316
|
const isDuplicated = error.message.includes("duplicate");
|
|
1311
1317
|
if (isDuplicated) {
|
|
1312
|
-
throw new import_node_server_utils7.BadRequestError("
|
|
1318
|
+
throw new import_node_server_utils7.BadRequestError("Unit already exists.");
|
|
1313
1319
|
}
|
|
1314
1320
|
throw error;
|
|
1315
1321
|
}
|
|
@@ -1365,7 +1371,8 @@ function useAreaService() {
|
|
|
1365
1371
|
const { getUnits: _getUnits } = useUnitRepository();
|
|
1366
1372
|
async function importArea({
|
|
1367
1373
|
dataJson,
|
|
1368
|
-
site
|
|
1374
|
+
site,
|
|
1375
|
+
serviceType
|
|
1369
1376
|
}) {
|
|
1370
1377
|
let dataArray;
|
|
1371
1378
|
try {
|
|
@@ -1386,7 +1393,8 @@ function useAreaService() {
|
|
|
1386
1393
|
page: 1,
|
|
1387
1394
|
limit: 999999,
|
|
1388
1395
|
search: "",
|
|
1389
|
-
site
|
|
1396
|
+
site,
|
|
1397
|
+
serviceType
|
|
1390
1398
|
});
|
|
1391
1399
|
if (unitsData && unitsData.items) {
|
|
1392
1400
|
availableUnits = unitsData.items;
|
|
@@ -1433,7 +1441,8 @@ function useAreaService() {
|
|
|
1433
1441
|
const areaData = {
|
|
1434
1442
|
type: areaType,
|
|
1435
1443
|
name: areaName,
|
|
1436
|
-
site
|
|
1444
|
+
site,
|
|
1445
|
+
serviceType
|
|
1437
1446
|
};
|
|
1438
1447
|
if (row.SET !== void 0 && row.SET !== null && row.SET !== "") {
|
|
1439
1448
|
const setNumber = parseInt(String(row.SET).trim());
|
|
@@ -1527,9 +1536,12 @@ function useAreaService() {
|
|
|
1527
1536
|
}
|
|
1528
1537
|
}
|
|
1529
1538
|
}
|
|
1530
|
-
async function exportAreas(
|
|
1539
|
+
async function exportAreas({
|
|
1540
|
+
site,
|
|
1541
|
+
serviceType
|
|
1542
|
+
}) {
|
|
1531
1543
|
try {
|
|
1532
|
-
const areas = await getAreasForChecklist(site);
|
|
1544
|
+
const areas = await getAreasForChecklist(site, serviceType);
|
|
1533
1545
|
if (!areas || !Array.isArray(areas) || areas.length === 0) {
|
|
1534
1546
|
throw new import_node_server_utils8.BadRequestError(
|
|
1535
1547
|
"There are no areas to export yet. Please add some areas first, then try again."
|
|
@@ -1616,7 +1628,8 @@ function useAreaController() {
|
|
|
1616
1628
|
limit: import_joi4.default.number().min(1).optional().allow("", null),
|
|
1617
1629
|
search: import_joi4.default.string().optional().allow("", null),
|
|
1618
1630
|
type: import_joi4.default.string().valid("all", ...allowedTypes).optional().allow("", null),
|
|
1619
|
-
site: import_joi4.default.string().hex().required()
|
|
1631
|
+
site: import_joi4.default.string().hex().required(),
|
|
1632
|
+
serviceType: import_joi4.default.string().valid(...Object.values(ServiceType)).required()
|
|
1620
1633
|
});
|
|
1621
1634
|
const { error } = validation.validate(query);
|
|
1622
1635
|
if (error) {
|
|
@@ -1629,13 +1642,15 @@ function useAreaController() {
|
|
|
1629
1642
|
const search = req.query.search ?? "";
|
|
1630
1643
|
const type = req.query.type ?? "all";
|
|
1631
1644
|
const site = req.params.site ?? "";
|
|
1645
|
+
const serviceType = req.query.serviceType ?? "";
|
|
1632
1646
|
try {
|
|
1633
1647
|
const data = await _getAreas({
|
|
1634
1648
|
page,
|
|
1635
1649
|
limit,
|
|
1636
1650
|
search,
|
|
1637
1651
|
type,
|
|
1638
|
-
site
|
|
1652
|
+
site,
|
|
1653
|
+
serviceType
|
|
1639
1654
|
});
|
|
1640
1655
|
res.json(data);
|
|
1641
1656
|
return;
|
|
@@ -1720,9 +1735,12 @@ function useAreaController() {
|
|
|
1720
1735
|
next(new import_node_server_utils9.BadRequestError("File is required!"));
|
|
1721
1736
|
return;
|
|
1722
1737
|
}
|
|
1723
|
-
const
|
|
1724
|
-
const
|
|
1725
|
-
|
|
1738
|
+
const query = { ...req.query, ...req.params };
|
|
1739
|
+
const validation = import_joi4.default.object({
|
|
1740
|
+
site: import_joi4.default.string().hex().required(),
|
|
1741
|
+
serviceType: import_joi4.default.string().valid(...Object.values(ServiceType)).required()
|
|
1742
|
+
});
|
|
1743
|
+
const { error, value } = validation.validate(query);
|
|
1726
1744
|
if (error) {
|
|
1727
1745
|
import_node_server_utils9.logger.log({ level: "error", message: error.message });
|
|
1728
1746
|
next(new import_node_server_utils9.BadRequestError(error.message));
|
|
@@ -1731,7 +1749,7 @@ function useAreaController() {
|
|
|
1731
1749
|
try {
|
|
1732
1750
|
const xlsData = await convertBufferFile(req.file.buffer);
|
|
1733
1751
|
const dataJson = JSON.stringify(xlsData);
|
|
1734
|
-
const result = await _importArea({ dataJson,
|
|
1752
|
+
const result = await _importArea({ dataJson, ...value });
|
|
1735
1753
|
return res.status(201).json(result);
|
|
1736
1754
|
} catch (error2) {
|
|
1737
1755
|
import_node_server_utils9.logger.log({ level: "error", message: error2.message });
|
|
@@ -1740,9 +1758,12 @@ function useAreaController() {
|
|
|
1740
1758
|
}
|
|
1741
1759
|
}
|
|
1742
1760
|
async function exportAreas(req, res, next) {
|
|
1743
|
-
const
|
|
1744
|
-
const validation = import_joi4.default.
|
|
1745
|
-
|
|
1761
|
+
const query = { ...req.query, ...req.params };
|
|
1762
|
+
const validation = import_joi4.default.object({
|
|
1763
|
+
site: import_joi4.default.string().hex().required(),
|
|
1764
|
+
serviceType: import_joi4.default.string().valid(...Object.values(ServiceType)).required()
|
|
1765
|
+
});
|
|
1766
|
+
const { error, value } = validation.validate(query);
|
|
1746
1767
|
if (error) {
|
|
1747
1768
|
import_node_server_utils9.logger.log({ level: "error", message: error.message });
|
|
1748
1769
|
next(new import_node_server_utils9.BadRequestError(error.message));
|
|
@@ -1833,7 +1854,8 @@ function useUnitService() {
|
|
|
1833
1854
|
} = useUnitRepository();
|
|
1834
1855
|
async function importUnit({
|
|
1835
1856
|
dataJson,
|
|
1836
|
-
site
|
|
1857
|
+
site,
|
|
1858
|
+
serviceType
|
|
1837
1859
|
}) {
|
|
1838
1860
|
let dataArray;
|
|
1839
1861
|
try {
|
|
@@ -1874,7 +1896,8 @@ function useUnitService() {
|
|
|
1874
1896
|
try {
|
|
1875
1897
|
const insertedId = await _createUnit({
|
|
1876
1898
|
name: unitName,
|
|
1877
|
-
site
|
|
1899
|
+
site,
|
|
1900
|
+
serviceType
|
|
1878
1901
|
});
|
|
1879
1902
|
insertedUnitIds.push(insertedId);
|
|
1880
1903
|
import_node_server_utils11.logger.info(`Successfully created unit: ${unitName}`);
|
|
@@ -1979,7 +2002,10 @@ function useUnitService() {
|
|
|
1979
2002
|
session?.endSession();
|
|
1980
2003
|
}
|
|
1981
2004
|
}
|
|
1982
|
-
async function exportUnits(
|
|
2005
|
+
async function exportUnits({
|
|
2006
|
+
site,
|
|
2007
|
+
serviceType
|
|
2008
|
+
}) {
|
|
1983
2009
|
const { generateUnitExcel: _generateUnitExcel } = useUnitExportService();
|
|
1984
2010
|
const { getUnits: _getUnits } = useUnitRepository();
|
|
1985
2011
|
try {
|
|
@@ -1987,7 +2013,8 @@ function useUnitService() {
|
|
|
1987
2013
|
page: 1,
|
|
1988
2014
|
limit: 999999,
|
|
1989
2015
|
search: "",
|
|
1990
|
-
site
|
|
2016
|
+
site,
|
|
2017
|
+
serviceType
|
|
1991
2018
|
});
|
|
1992
2019
|
if (!data || !data.items || data.items.length === 0) {
|
|
1993
2020
|
throw new import_node_server_utils11.BadRequestError(
|
|
@@ -2044,7 +2071,8 @@ function useUnitController() {
|
|
|
2044
2071
|
page: import_joi5.default.number().min(1).optional().allow("", null),
|
|
2045
2072
|
limit: import_joi5.default.number().min(1).optional().allow("", null),
|
|
2046
2073
|
search: import_joi5.default.string().optional().allow("", null),
|
|
2047
|
-
site: import_joi5.default.string().hex().required()
|
|
2074
|
+
site: import_joi5.default.string().hex().required(),
|
|
2075
|
+
serviceType: import_joi5.default.string().valid(...Object.values(ServiceType)).required()
|
|
2048
2076
|
});
|
|
2049
2077
|
const { error } = validation.validate(query);
|
|
2050
2078
|
if (error) {
|
|
@@ -2056,12 +2084,14 @@ function useUnitController() {
|
|
|
2056
2084
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
2057
2085
|
const search = req.query.search ?? "";
|
|
2058
2086
|
const site = req.params.site ?? "";
|
|
2087
|
+
const serviceType = req.query.serviceType ?? "";
|
|
2059
2088
|
try {
|
|
2060
2089
|
const data = await _getUnits({
|
|
2061
2090
|
page,
|
|
2062
2091
|
limit,
|
|
2063
2092
|
search,
|
|
2064
|
-
site
|
|
2093
|
+
site,
|
|
2094
|
+
serviceType
|
|
2065
2095
|
});
|
|
2066
2096
|
res.json(data);
|
|
2067
2097
|
return;
|
|
@@ -2120,9 +2150,12 @@ function useUnitController() {
|
|
|
2120
2150
|
next(new import_node_server_utils12.BadRequestError("File is required!"));
|
|
2121
2151
|
return;
|
|
2122
2152
|
}
|
|
2123
|
-
const
|
|
2124
|
-
const validation = import_joi5.default.
|
|
2125
|
-
|
|
2153
|
+
const query = { ...req.query, ...req.params };
|
|
2154
|
+
const validation = import_joi5.default.object({
|
|
2155
|
+
site: import_joi5.default.string().hex().required(),
|
|
2156
|
+
serviceType: import_joi5.default.string().valid(...Object.values(ServiceType)).required()
|
|
2157
|
+
});
|
|
2158
|
+
const { error, value } = validation.validate(query);
|
|
2126
2159
|
if (error) {
|
|
2127
2160
|
import_node_server_utils12.logger.log({ level: "error", message: error.message });
|
|
2128
2161
|
next(new import_node_server_utils12.BadRequestError(error.message));
|
|
@@ -2131,7 +2164,7 @@ function useUnitController() {
|
|
|
2131
2164
|
try {
|
|
2132
2165
|
const xlsData = await convertBufferFile(req.file.buffer);
|
|
2133
2166
|
const dataJson = JSON.stringify(xlsData);
|
|
2134
|
-
const result = await _importUnit({ dataJson,
|
|
2167
|
+
const result = await _importUnit({ dataJson, ...value });
|
|
2135
2168
|
return res.status(201).json(result);
|
|
2136
2169
|
} catch (error2) {
|
|
2137
2170
|
import_node_server_utils12.logger.log({ level: "error", message: error2.message });
|
|
@@ -2140,9 +2173,12 @@ function useUnitController() {
|
|
|
2140
2173
|
}
|
|
2141
2174
|
}
|
|
2142
2175
|
async function exportUnits(req, res, next) {
|
|
2143
|
-
const
|
|
2144
|
-
const validation = import_joi5.default.
|
|
2145
|
-
|
|
2176
|
+
const query = { ...req.query, ...req.params };
|
|
2177
|
+
const validation = import_joi5.default.object({
|
|
2178
|
+
site: import_joi5.default.string().hex().required(),
|
|
2179
|
+
serviceType: import_joi5.default.string().valid(...Object.values(ServiceType)).required()
|
|
2180
|
+
});
|
|
2181
|
+
const { error, value } = validation.validate(query);
|
|
2146
2182
|
if (error) {
|
|
2147
2183
|
import_node_server_utils12.logger.log({ level: "error", message: error.message });
|
|
2148
2184
|
next(new import_node_server_utils12.BadRequestError(error.message));
|
|
@@ -2188,7 +2224,8 @@ var import_mongodb6 = require("mongodb");
|
|
|
2188
2224
|
var import_node_server_utils13 = require("@7365admin1/node-server-utils");
|
|
2189
2225
|
var parentChecklistSchema = import_joi6.default.object({
|
|
2190
2226
|
createdAt: import_joi6.default.alternatives().try(import_joi6.default.date(), import_joi6.default.string()).optional().allow("", null),
|
|
2191
|
-
site: import_joi6.default.string().hex().required()
|
|
2227
|
+
site: import_joi6.default.string().hex().required(),
|
|
2228
|
+
serviceType: import_joi6.default.string().valid(...Object.values(ServiceType)).required()
|
|
2192
2229
|
});
|
|
2193
2230
|
function MParentChecklist(value) {
|
|
2194
2231
|
const { error } = parentChecklistSchema.validate(value);
|
|
@@ -2205,6 +2242,7 @@ function MParentChecklist(value) {
|
|
|
2205
2242
|
}
|
|
2206
2243
|
return {
|
|
2207
2244
|
site: value.site,
|
|
2245
|
+
serviceType: value.serviceType,
|
|
2208
2246
|
status: "open",
|
|
2209
2247
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
2210
2248
|
updatedAt: value.updatedAt ?? ""
|
|
@@ -2227,6 +2265,7 @@ function useParentChecklistRepo() {
|
|
|
2227
2265
|
async function createIndex() {
|
|
2228
2266
|
try {
|
|
2229
2267
|
await collection.createIndexes([
|
|
2268
|
+
{ key: { serviceType: 1 } },
|
|
2230
2269
|
{ key: { createdAt: 1 } },
|
|
2231
2270
|
{ key: { site: 1 } },
|
|
2232
2271
|
{ key: { status: 1 } }
|
|
@@ -2244,60 +2283,80 @@ function useParentChecklistRepo() {
|
|
|
2244
2283
|
startOfDay.setUTCHours(0, 0, 0, 0);
|
|
2245
2284
|
const endOfDay = new Date(currentDate);
|
|
2246
2285
|
endOfDay.setUTCHours(23, 59, 59, 999);
|
|
2247
|
-
const
|
|
2248
|
-
|
|
2249
|
-
$gte: startOfDay,
|
|
2250
|
-
$lte: endOfDay
|
|
2251
|
-
}
|
|
2252
|
-
};
|
|
2286
|
+
const allServiceTypes = Object.values(ServiceType);
|
|
2287
|
+
const dateStr = currentDate.toISOString().split("T")[0];
|
|
2253
2288
|
if (value.site) {
|
|
2289
|
+
let siteObjectId;
|
|
2254
2290
|
try {
|
|
2255
|
-
|
|
2256
|
-
import_node_server_utils14.logger.info(
|
|
2257
|
-
`createParentChecklist: Looking for existing checklist with query: ${JSON.stringify(
|
|
2258
|
-
{ ...existingQuery, site: value.site }
|
|
2259
|
-
)}`
|
|
2260
|
-
);
|
|
2291
|
+
siteObjectId = new import_mongodb7.ObjectId(value.site);
|
|
2261
2292
|
} catch (error) {
|
|
2262
2293
|
throw new import_node_server_utils14.BadRequestError("Invalid site ID format.");
|
|
2263
2294
|
}
|
|
2264
|
-
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
|
|
2295
|
+
if (value.serviceType) {
|
|
2296
|
+
const existingChecklist = await collection.findOne({
|
|
2297
|
+
createdAt: { $gte: startOfDay, $lte: endOfDay },
|
|
2298
|
+
site: siteObjectId,
|
|
2299
|
+
serviceType: value.serviceType
|
|
2300
|
+
});
|
|
2301
|
+
if (existingChecklist) {
|
|
2302
|
+
import_node_server_utils14.logger.info(
|
|
2303
|
+
`Parent checklist already exists for site ${value.site} / ${value.serviceType} on ${dateStr}. _id: ${existingChecklist._id}`
|
|
2304
|
+
);
|
|
2305
|
+
return existingChecklist._id;
|
|
2306
|
+
}
|
|
2307
|
+
const doc = MParentChecklist({
|
|
2308
|
+
site: value.site,
|
|
2309
|
+
createdAt: currentDate,
|
|
2310
|
+
serviceType: value.serviceType
|
|
2311
|
+
});
|
|
2312
|
+
const result3 = await collection.insertOne(doc, { session });
|
|
2313
|
+
delNamespace().catch((err) => {
|
|
2314
|
+
import_node_server_utils14.logger.error(
|
|
2315
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
2316
|
+
err
|
|
2317
|
+
);
|
|
2318
|
+
});
|
|
2319
|
+
import_node_server_utils14.logger.info(
|
|
2320
|
+
`Created parent checklist for site ${value.site} / ${value.serviceType} for today: ${dateStr}`
|
|
2321
|
+
);
|
|
2322
|
+
return result3.insertedId;
|
|
2323
|
+
}
|
|
2324
|
+
const existingServiceTypes = await collection.distinct("serviceType", {
|
|
2325
|
+
createdAt: { $gte: startOfDay, $lte: endOfDay },
|
|
2326
|
+
site: siteObjectId,
|
|
2327
|
+
serviceType: { $exists: true, $ne: null }
|
|
2328
|
+
});
|
|
2329
|
+
const missingServiceTypes = allServiceTypes.filter(
|
|
2330
|
+
(st) => !existingServiceTypes.includes(st)
|
|
2269
2331
|
);
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2332
|
+
if (missingServiceTypes.length === 0) {
|
|
2333
|
+
import_node_server_utils14.logger.info(
|
|
2334
|
+
`All serviceType checklists already exist for site ${value.site} on ${dateStr}`
|
|
2335
|
+
);
|
|
2336
|
+
const first = await collection.findOne({
|
|
2337
|
+
createdAt: { $gte: startOfDay, $lte: endOfDay },
|
|
2338
|
+
site: siteObjectId
|
|
2339
|
+
});
|
|
2340
|
+
return first._id;
|
|
2341
|
+
}
|
|
2342
|
+
const checklistDocs2 = missingServiceTypes.map(
|
|
2343
|
+
(serviceType) => MParentChecklist({
|
|
2344
|
+
site: value.site,
|
|
2345
|
+
createdAt: currentDate,
|
|
2346
|
+
serviceType
|
|
2347
|
+
})
|
|
2279
2348
|
);
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
if (value.site) {
|
|
2283
|
-
const checklistDoc = MParentChecklist({
|
|
2284
|
-
site: value.site,
|
|
2285
|
-
createdAt: currentDate
|
|
2286
|
-
});
|
|
2287
|
-
const result2 = await collection.insertOne(checklistDoc, { session });
|
|
2288
|
-
delNamespace().then(() => {
|
|
2289
|
-
import_node_server_utils14.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
2290
|
-
}).catch((err) => {
|
|
2349
|
+
const result2 = await collection.insertMany(checklistDocs2, { session });
|
|
2350
|
+
delNamespace().catch((err) => {
|
|
2291
2351
|
import_node_server_utils14.logger.error(
|
|
2292
2352
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
2293
2353
|
err
|
|
2294
2354
|
);
|
|
2295
2355
|
});
|
|
2296
|
-
const dateStr2 = currentDate.toISOString().split("T")[0];
|
|
2297
2356
|
import_node_server_utils14.logger.info(
|
|
2298
|
-
`Created parent
|
|
2357
|
+
`Created ${checklistDocs2.length} parent checklists for site ${value.site} for today: ${dateStr}`
|
|
2299
2358
|
);
|
|
2300
|
-
return result2.
|
|
2359
|
+
return Object.values(result2.insertedIds);
|
|
2301
2360
|
}
|
|
2302
2361
|
const siteIds = await getHygieneSiteIds();
|
|
2303
2362
|
if (!Array.isArray(siteIds)) {
|
|
@@ -2308,15 +2367,41 @@ function useParentChecklistRepo() {
|
|
|
2308
2367
|
import_node_server_utils14.logger.warn("No sites found for creating parent checklist");
|
|
2309
2368
|
throw new import_node_server_utils14.BadRequestError("No sites available for checklist creation");
|
|
2310
2369
|
}
|
|
2370
|
+
const existingPairs = await collection.find(
|
|
2371
|
+
{
|
|
2372
|
+
createdAt: { $gte: startOfDay, $lte: endOfDay },
|
|
2373
|
+
serviceType: { $exists: true, $ne: null }
|
|
2374
|
+
},
|
|
2375
|
+
{ projection: { site: 1, serviceType: 1 } }
|
|
2376
|
+
).toArray();
|
|
2377
|
+
const existingSet = new Set(
|
|
2378
|
+
existingPairs.map(
|
|
2379
|
+
(doc) => `${doc.site?.toString()}|${doc.serviceType}`
|
|
2380
|
+
)
|
|
2381
|
+
);
|
|
2311
2382
|
const checklistDocs = [];
|
|
2312
2383
|
for (const site of siteIds) {
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2384
|
+
for (const serviceType of allServiceTypes) {
|
|
2385
|
+
if (!existingSet.has(`${site}|${serviceType}`)) {
|
|
2386
|
+
checklistDocs.push(
|
|
2387
|
+
MParentChecklist({
|
|
2388
|
+
site,
|
|
2389
|
+
createdAt: currentDate,
|
|
2390
|
+
serviceType
|
|
2391
|
+
})
|
|
2392
|
+
);
|
|
2393
|
+
}
|
|
2394
|
+
}
|
|
2395
|
+
}
|
|
2396
|
+
if (checklistDocs.length === 0) {
|
|
2397
|
+
import_node_server_utils14.logger.info(
|
|
2398
|
+
`All site+serviceType checklists already exist for today: ${dateStr}`
|
|
2318
2399
|
);
|
|
2400
|
+
return [];
|
|
2319
2401
|
}
|
|
2402
|
+
import_node_server_utils14.logger.info(
|
|
2403
|
+
`createParentChecklist: Creating ${checklistDocs.length} missing site+serviceType checklist(s) for today: ${dateStr}`
|
|
2404
|
+
);
|
|
2320
2405
|
const result = await collection.insertMany(checklistDocs, { session });
|
|
2321
2406
|
delNamespace().then(() => {
|
|
2322
2407
|
import_node_server_utils14.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
@@ -2326,7 +2411,6 @@ function useParentChecklistRepo() {
|
|
|
2326
2411
|
err
|
|
2327
2412
|
);
|
|
2328
2413
|
});
|
|
2329
|
-
const dateStr = currentDate.toISOString().split("T")[0];
|
|
2330
2414
|
import_node_server_utils14.logger.info(
|
|
2331
2415
|
`Created ${Object.keys(result.insertedIds).length} parent checklists for today: ${dateStr}`
|
|
2332
2416
|
);
|
|
@@ -2343,13 +2427,15 @@ function useParentChecklistRepo() {
|
|
|
2343
2427
|
site,
|
|
2344
2428
|
startDate = "",
|
|
2345
2429
|
endDate = "",
|
|
2346
|
-
status = "all"
|
|
2430
|
+
status = "all",
|
|
2431
|
+
serviceType
|
|
2347
2432
|
}) {
|
|
2348
2433
|
page = page > 0 ? page - 1 : 0;
|
|
2349
|
-
const query = {};
|
|
2434
|
+
const query = { serviceType };
|
|
2350
2435
|
const cacheOptions = {
|
|
2351
2436
|
page,
|
|
2352
|
-
limit
|
|
2437
|
+
limit,
|
|
2438
|
+
serviceType
|
|
2353
2439
|
};
|
|
2354
2440
|
try {
|
|
2355
2441
|
site = new import_mongodb7.ObjectId(site);
|
|
@@ -2432,6 +2518,23 @@ function useParentChecklistRepo() {
|
|
|
2432
2518
|
throw error;
|
|
2433
2519
|
}
|
|
2434
2520
|
}
|
|
2521
|
+
async function getParentChecklistById(_id) {
|
|
2522
|
+
try {
|
|
2523
|
+
_id = new import_mongodb7.ObjectId(_id);
|
|
2524
|
+
} catch (error) {
|
|
2525
|
+
throw new import_node_server_utils14.BadRequestError("Invalid parent checklist ID format.");
|
|
2526
|
+
}
|
|
2527
|
+
try {
|
|
2528
|
+
const data = await collection.findOne({ _id });
|
|
2529
|
+
if (!data) {
|
|
2530
|
+
throw new import_node_server_utils14.BadRequestError("Parent checklist not found.");
|
|
2531
|
+
}
|
|
2532
|
+
return data;
|
|
2533
|
+
} catch (error) {
|
|
2534
|
+
import_node_server_utils14.logger.error("Failed to get parent checklist by ID", error);
|
|
2535
|
+
throw error;
|
|
2536
|
+
}
|
|
2537
|
+
}
|
|
2435
2538
|
async function updateParentChecklistStatuses(_id, status, session) {
|
|
2436
2539
|
try {
|
|
2437
2540
|
_id = new import_mongodb7.ObjectId(_id);
|
|
@@ -2546,13 +2649,38 @@ function useParentChecklistRepo() {
|
|
|
2546
2649
|
throw error;
|
|
2547
2650
|
}
|
|
2548
2651
|
}
|
|
2652
|
+
async function getTodayParentChecklistsForAreaGen() {
|
|
2653
|
+
const now = /* @__PURE__ */ new Date();
|
|
2654
|
+
const start = new Date(now);
|
|
2655
|
+
start.setUTCHours(0, 0, 0, 0);
|
|
2656
|
+
const end = new Date(now);
|
|
2657
|
+
end.setUTCHours(23, 59, 59, 999);
|
|
2658
|
+
try {
|
|
2659
|
+
const items = await collection.find(
|
|
2660
|
+
{
|
|
2661
|
+
createdAt: { $gte: start, $lte: end },
|
|
2662
|
+
serviceType: { $exists: true, $ne: null }
|
|
2663
|
+
},
|
|
2664
|
+
{ projection: { _id: 1, site: 1, serviceType: 1 } }
|
|
2665
|
+
).toArray();
|
|
2666
|
+
return items;
|
|
2667
|
+
} catch (error) {
|
|
2668
|
+
import_node_server_utils14.logger.error(
|
|
2669
|
+
"Failed to get today's parent checklists for area generation",
|
|
2670
|
+
error
|
|
2671
|
+
);
|
|
2672
|
+
throw error;
|
|
2673
|
+
}
|
|
2674
|
+
}
|
|
2549
2675
|
return {
|
|
2550
2676
|
createIndex,
|
|
2551
2677
|
createParentChecklist,
|
|
2552
2678
|
getAllParentChecklist,
|
|
2679
|
+
getParentChecklistById,
|
|
2553
2680
|
updateParentChecklistStatuses,
|
|
2554
2681
|
closeExpiredParentChecklists,
|
|
2555
|
-
getTodayParentChecklists
|
|
2682
|
+
getTodayParentChecklists,
|
|
2683
|
+
getTodayParentChecklistsForAreaGen
|
|
2556
2684
|
};
|
|
2557
2685
|
}
|
|
2558
2686
|
|
|
@@ -2589,6 +2717,7 @@ function useParentChecklistController() {
|
|
|
2589
2717
|
limit: import_joi7.default.number().min(1).optional().allow("", null),
|
|
2590
2718
|
search: import_joi7.default.string().optional().allow("", null),
|
|
2591
2719
|
site: import_joi7.default.string().hex().required(),
|
|
2720
|
+
serviceType: import_joi7.default.string().valid(...Object.values(ServiceType)).required(),
|
|
2592
2721
|
startDate: import_joi7.default.alternatives().try(import_joi7.default.date(), import_joi7.default.string()).optional().allow("", null),
|
|
2593
2722
|
endDate: import_joi7.default.alternatives().try(import_joi7.default.date(), import_joi7.default.string()).optional().allow("", null),
|
|
2594
2723
|
status: import_joi7.default.string().valid(...allowedStatus, "all").optional().allow("", null)
|
|
@@ -2603,6 +2732,7 @@ function useParentChecklistController() {
|
|
|
2603
2732
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
2604
2733
|
const search = req.query.search ?? "";
|
|
2605
2734
|
const site = req.params.site ?? "";
|
|
2735
|
+
const serviceType = req.query.serviceType ?? "";
|
|
2606
2736
|
const startDate = req.query.startDate ?? "";
|
|
2607
2737
|
const endDate = req.query.endDate ?? "";
|
|
2608
2738
|
const status = req.query.status ?? "all";
|
|
@@ -2612,6 +2742,7 @@ function useParentChecklistController() {
|
|
|
2612
2742
|
limit,
|
|
2613
2743
|
search,
|
|
2614
2744
|
site,
|
|
2745
|
+
serviceType,
|
|
2615
2746
|
startDate,
|
|
2616
2747
|
endDate,
|
|
2617
2748
|
status
|
|
@@ -2637,6 +2768,7 @@ var import_node_server_utils16 = require("@7365admin1/node-server-utils");
|
|
|
2637
2768
|
var allowedChecklistStatus = ["open", "completed", "closed"];
|
|
2638
2769
|
var areaChecklistSchema = import_joi8.default.object({
|
|
2639
2770
|
schedule: import_joi8.default.string().hex().required(),
|
|
2771
|
+
serviceType: import_joi8.default.string().valid(...Object.values(ServiceType)).optional(),
|
|
2640
2772
|
area: import_joi8.default.string().hex().required(),
|
|
2641
2773
|
name: import_joi8.default.string().required(),
|
|
2642
2774
|
type: import_joi8.default.string().valid(...allowedTypes).required(),
|
|
@@ -2703,6 +2835,7 @@ function MAreaChecklist(value) {
|
|
|
2703
2835
|
}
|
|
2704
2836
|
return {
|
|
2705
2837
|
schedule: value.schedule,
|
|
2838
|
+
serviceType: value.serviceType,
|
|
2706
2839
|
area: value.area,
|
|
2707
2840
|
name: value.name,
|
|
2708
2841
|
type: value.type,
|
|
@@ -2812,7 +2945,8 @@ function useAreaChecklistRepo() {
|
|
|
2812
2945
|
search = "",
|
|
2813
2946
|
type = "all",
|
|
2814
2947
|
status = "all",
|
|
2815
|
-
schedule
|
|
2948
|
+
schedule,
|
|
2949
|
+
serviceType
|
|
2816
2950
|
}, session) {
|
|
2817
2951
|
page = page > 0 ? page - 1 : 0;
|
|
2818
2952
|
const query = {};
|
|
@@ -2826,6 +2960,10 @@ function useAreaChecklistRepo() {
|
|
|
2826
2960
|
} catch (error) {
|
|
2827
2961
|
throw new import_node_server_utils17.BadRequestError("Invalid parent checklist ID format.");
|
|
2828
2962
|
}
|
|
2963
|
+
if (serviceType) {
|
|
2964
|
+
query.serviceType = serviceType;
|
|
2965
|
+
cacheOptions.serviceType = serviceType;
|
|
2966
|
+
}
|
|
2829
2967
|
if (type && type !== "all") {
|
|
2830
2968
|
query.type = type;
|
|
2831
2969
|
cacheOptions.type = type;
|
|
@@ -3221,6 +3359,7 @@ function useAreaChecklistRepo() {
|
|
|
3221
3359
|
page = 1,
|
|
3222
3360
|
limit = 10,
|
|
3223
3361
|
search = "",
|
|
3362
|
+
serviceType,
|
|
3224
3363
|
_id
|
|
3225
3364
|
}, session) {
|
|
3226
3365
|
page = page > 0 ? page - 1 : 0;
|
|
@@ -3235,6 +3374,10 @@ function useAreaChecklistRepo() {
|
|
|
3235
3374
|
} catch (error) {
|
|
3236
3375
|
throw new import_node_server_utils17.BadRequestError("Invalid area checklist ID format.");
|
|
3237
3376
|
}
|
|
3377
|
+
if (serviceType) {
|
|
3378
|
+
query.serviceType = serviceType;
|
|
3379
|
+
cacheOptions.serviceType = serviceType;
|
|
3380
|
+
}
|
|
3238
3381
|
if (search) {
|
|
3239
3382
|
query.$text = { $search: search };
|
|
3240
3383
|
cacheOptions.search = search;
|
|
@@ -3458,7 +3601,12 @@ function useAreaChecklistRepo() {
|
|
|
3458
3601
|
throw error;
|
|
3459
3602
|
}
|
|
3460
3603
|
}
|
|
3461
|
-
async function getAreaChecklistByAreaAndSchedule(
|
|
3604
|
+
async function getAreaChecklistByAreaAndSchedule({
|
|
3605
|
+
schedule,
|
|
3606
|
+
serviceType,
|
|
3607
|
+
area,
|
|
3608
|
+
session
|
|
3609
|
+
}) {
|
|
3462
3610
|
try {
|
|
3463
3611
|
schedule = new import_mongodb9.ObjectId(schedule);
|
|
3464
3612
|
area = new import_mongodb9.ObjectId(area);
|
|
@@ -3466,7 +3614,10 @@ function useAreaChecklistRepo() {
|
|
|
3466
3614
|
throw new import_node_server_utils17.BadRequestError("Invalid area checklist ID format.");
|
|
3467
3615
|
}
|
|
3468
3616
|
try {
|
|
3469
|
-
const data = await collection.findOne(
|
|
3617
|
+
const data = await collection.findOne(
|
|
3618
|
+
{ schedule, serviceType, area },
|
|
3619
|
+
{ session }
|
|
3620
|
+
);
|
|
3470
3621
|
if (!data) {
|
|
3471
3622
|
throw new import_node_server_utils17.BadRequestError("Area checklist not found.");
|
|
3472
3623
|
}
|
|
@@ -3675,7 +3826,7 @@ function useAreaChecklistRepo() {
|
|
|
3675
3826
|
throw error;
|
|
3676
3827
|
}
|
|
3677
3828
|
}
|
|
3678
|
-
async function pushScheduleTaskSets(scheduleId, areaId, scheduleTaskId, newSets) {
|
|
3829
|
+
async function pushScheduleTaskSets(scheduleId, serviceType, areaId, scheduleTaskId, newSets) {
|
|
3679
3830
|
try {
|
|
3680
3831
|
const schedule = new import_mongodb9.ObjectId(scheduleId);
|
|
3681
3832
|
const area = new import_mongodb9.ObjectId(areaId);
|
|
@@ -3683,6 +3834,7 @@ function useAreaChecklistRepo() {
|
|
|
3683
3834
|
const result = await collection.updateOne(
|
|
3684
3835
|
{
|
|
3685
3836
|
schedule,
|
|
3837
|
+
serviceType,
|
|
3686
3838
|
area,
|
|
3687
3839
|
checklist: { $not: { $elemMatch: { scheduleTaskId: taskId } } }
|
|
3688
3840
|
},
|
|
@@ -3705,13 +3857,14 @@ function useAreaChecklistRepo() {
|
|
|
3705
3857
|
throw error;
|
|
3706
3858
|
}
|
|
3707
3859
|
}
|
|
3708
|
-
async function insertAutoGenSets(scheduleId, areaId, newSets) {
|
|
3860
|
+
async function insertAutoGenSets(scheduleId, serviceType, areaId, newSets) {
|
|
3709
3861
|
try {
|
|
3710
3862
|
const schedule = new import_mongodb9.ObjectId(scheduleId);
|
|
3711
3863
|
const area = new import_mongodb9.ObjectId(areaId);
|
|
3712
3864
|
const result = await collection.updateOne(
|
|
3713
3865
|
{
|
|
3714
3866
|
schedule,
|
|
3867
|
+
serviceType,
|
|
3715
3868
|
area,
|
|
3716
3869
|
checklist: {
|
|
3717
3870
|
$not: { $elemMatch: { isScheduleTask: { $ne: true } } }
|
|
@@ -3857,14 +4010,25 @@ function useAreaChecklistService() {
|
|
|
3857
4010
|
updateAreaChecklistStatus,
|
|
3858
4011
|
insertAutoGenSets
|
|
3859
4012
|
} = useAreaChecklistRepo();
|
|
3860
|
-
const { updateParentChecklistStatuses } = useParentChecklistRepo();
|
|
4013
|
+
const { updateParentChecklistStatuses, getParentChecklistById } = useParentChecklistRepo();
|
|
3861
4014
|
const { getUserById } = (0, import_core.useUserRepo)();
|
|
3862
4015
|
async function createAreaChecklist(value) {
|
|
3863
4016
|
const results = [];
|
|
3864
4017
|
let totalChecklistsCreated = 0;
|
|
3865
4018
|
try {
|
|
3866
4019
|
const BATCH_SIZE = 10;
|
|
3867
|
-
const
|
|
4020
|
+
const schedule = await getParentChecklistById(value.schedule.toString());
|
|
4021
|
+
const serviceType = schedule.serviceType;
|
|
4022
|
+
if (!serviceType) {
|
|
4023
|
+
import_node_server_utils18.logger.warn(
|
|
4024
|
+
`createAreaChecklist: Parent checklist ${value.schedule} has no serviceType, skipping area checklist generation`
|
|
4025
|
+
);
|
|
4026
|
+
return results;
|
|
4027
|
+
}
|
|
4028
|
+
const areasResult = await getAreasForChecklist(
|
|
4029
|
+
value.site,
|
|
4030
|
+
serviceType
|
|
4031
|
+
);
|
|
3868
4032
|
const areas = areasResult || [];
|
|
3869
4033
|
if (areas.length > 0) {
|
|
3870
4034
|
for (let i = 0; i < areas.length; i += BATCH_SIZE) {
|
|
@@ -3878,10 +4042,11 @@ function useAreaChecklistService() {
|
|
|
3878
4042
|
}
|
|
3879
4043
|
let existing = null;
|
|
3880
4044
|
try {
|
|
3881
|
-
existing = await getAreaChecklistByAreaAndSchedule(
|
|
3882
|
-
value.schedule.toString(),
|
|
3883
|
-
|
|
3884
|
-
|
|
4045
|
+
existing = await getAreaChecklistByAreaAndSchedule({
|
|
4046
|
+
schedule: value.schedule.toString(),
|
|
4047
|
+
serviceType,
|
|
4048
|
+
area: area._id.toString()
|
|
4049
|
+
});
|
|
3885
4050
|
} catch (_) {
|
|
3886
4051
|
}
|
|
3887
4052
|
if (existing) {
|
|
@@ -3929,6 +4094,7 @@ function useAreaChecklistService() {
|
|
|
3929
4094
|
);
|
|
3930
4095
|
await insertAutoGenSets(
|
|
3931
4096
|
value.schedule.toString(),
|
|
4097
|
+
serviceType,
|
|
3932
4098
|
area._id.toString(),
|
|
3933
4099
|
autoGenSets
|
|
3934
4100
|
);
|
|
@@ -3937,6 +4103,7 @@ function useAreaChecklistService() {
|
|
|
3937
4103
|
const setCount = Number(area.set) || 1;
|
|
3938
4104
|
const checklistData = {
|
|
3939
4105
|
schedule: value.schedule,
|
|
4106
|
+
serviceType,
|
|
3940
4107
|
area: area._id.toString(),
|
|
3941
4108
|
name: area.name,
|
|
3942
4109
|
type: area.type,
|
|
@@ -4336,7 +4503,8 @@ function useAreaChecklistController() {
|
|
|
4336
4503
|
search: import_joi9.default.string().optional().allow("", null),
|
|
4337
4504
|
type: import_joi9.default.string().valid(...allowedTypes, "all").optional().allow("", null),
|
|
4338
4505
|
status: import_joi9.default.string().valid(...allowedStatus, "all").optional().allow("", null),
|
|
4339
|
-
schedule: import_joi9.default.string().hex().required()
|
|
4506
|
+
schedule: import_joi9.default.string().hex().required(),
|
|
4507
|
+
serviceType: import_joi9.default.string().valid(...Object.values(ServiceType)).required()
|
|
4340
4508
|
});
|
|
4341
4509
|
const { error } = validation.validate(query);
|
|
4342
4510
|
if (error) {
|
|
@@ -4350,6 +4518,7 @@ function useAreaChecklistController() {
|
|
|
4350
4518
|
const type = req.query.type ?? "all";
|
|
4351
4519
|
const status = req.query.status ?? "all";
|
|
4352
4520
|
const schedule = req.params.schedule ?? "";
|
|
4521
|
+
const serviceType = req.query.serviceType ?? "";
|
|
4353
4522
|
try {
|
|
4354
4523
|
const data = await _getAllAreaChecklist({
|
|
4355
4524
|
page,
|
|
@@ -4357,7 +4526,8 @@ function useAreaChecklistController() {
|
|
|
4357
4526
|
search,
|
|
4358
4527
|
type,
|
|
4359
4528
|
status,
|
|
4360
|
-
schedule
|
|
4529
|
+
schedule,
|
|
4530
|
+
serviceType
|
|
4361
4531
|
});
|
|
4362
4532
|
res.json(data);
|
|
4363
4533
|
return;
|
|
@@ -4434,6 +4604,7 @@ function useAreaChecklistController() {
|
|
|
4434
4604
|
page: import_joi9.default.number().min(1).optional().allow("", null),
|
|
4435
4605
|
limit: import_joi9.default.number().min(1).optional().allow("", null),
|
|
4436
4606
|
search: import_joi9.default.string().optional().allow("", null),
|
|
4607
|
+
serviceType: import_joi9.default.string().valid(...Object.values(ServiceType)).required(),
|
|
4437
4608
|
id: import_joi9.default.string().hex().required()
|
|
4438
4609
|
});
|
|
4439
4610
|
const { error } = validation.validate(query);
|
|
@@ -4445,12 +4616,14 @@ function useAreaChecklistController() {
|
|
|
4445
4616
|
const page = parseInt(req.query.page) ?? 1;
|
|
4446
4617
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
4447
4618
|
const search = req.query.search ?? "";
|
|
4619
|
+
const serviceType = req.query.serviceType ?? "";
|
|
4448
4620
|
const _id = req.params.id ?? "";
|
|
4449
4621
|
try {
|
|
4450
4622
|
const data = await _getAreaChecklistUnits({
|
|
4451
4623
|
page,
|
|
4452
4624
|
limit,
|
|
4453
4625
|
search,
|
|
4626
|
+
serviceType,
|
|
4454
4627
|
_id
|
|
4455
4628
|
});
|
|
4456
4629
|
res.json(data);
|
|
@@ -4522,12 +4695,15 @@ function useAreaChecklistController() {
|
|
|
4522
4695
|
try {
|
|
4523
4696
|
const pdfBuffer = await _generateChecklistPdf(value);
|
|
4524
4697
|
if (!pdfBuffer || pdfBuffer.length === 0) {
|
|
4525
|
-
throw new import_node_server_utils20.InternalServerError(
|
|
4698
|
+
throw new import_node_server_utils20.InternalServerError(
|
|
4699
|
+
"Generated checklist PDF is empty or invalid."
|
|
4700
|
+
);
|
|
4526
4701
|
}
|
|
4527
4702
|
const date = /* @__PURE__ */ new Date();
|
|
4528
|
-
const formattedDate = `${String(date.getDate()).padStart(
|
|
4529
|
-
|
|
4530
|
-
|
|
4703
|
+
const formattedDate = `${String(date.getDate()).padStart(
|
|
4704
|
+
2,
|
|
4705
|
+
"0"
|
|
4706
|
+
)}_${String(date.getMonth() + 1).padStart(2, "0")}_${date.getFullYear()}`;
|
|
4531
4707
|
res.setHeader("Content-Type", "application/pdf");
|
|
4532
4708
|
res.setHeader(
|
|
4533
4709
|
"Content-Disposition",
|
|
@@ -5797,6 +5973,7 @@ var import_joi16 = __toESM(require("joi"));
|
|
|
5797
5973
|
var import_mongodb18 = require("mongodb");
|
|
5798
5974
|
var scheduleTaskSchema = import_joi16.default.object({
|
|
5799
5975
|
site: import_joi16.default.string().hex().required(),
|
|
5976
|
+
serviceType: import_joi16.default.string().valid(...Object.values(ServiceType)).required(),
|
|
5800
5977
|
title: import_joi16.default.string().required(),
|
|
5801
5978
|
time: import_joi16.default.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).required(),
|
|
5802
5979
|
dates: import_joi16.default.array().min(1).items(
|
|
@@ -5845,6 +6022,7 @@ function MScheduleTask(value) {
|
|
|
5845
6022
|
}
|
|
5846
6023
|
return {
|
|
5847
6024
|
site: value.site,
|
|
6025
|
+
serviceType: value.serviceType,
|
|
5848
6026
|
title: value.title,
|
|
5849
6027
|
time: value.time,
|
|
5850
6028
|
dates: value.dates,
|
|
@@ -5873,6 +6051,7 @@ function useScheduleTaskRepository() {
|
|
|
5873
6051
|
try {
|
|
5874
6052
|
await collection.createIndexes([
|
|
5875
6053
|
{ key: { site: 1 } },
|
|
6054
|
+
{ key: { serviceType: 1 } },
|
|
5876
6055
|
{ key: { status: 1 } }
|
|
5877
6056
|
]);
|
|
5878
6057
|
} catch (error) {
|
|
@@ -5911,15 +6090,18 @@ function useScheduleTaskRepository() {
|
|
|
5911
6090
|
page = 1,
|
|
5912
6091
|
limit = 10,
|
|
5913
6092
|
search = "",
|
|
5914
|
-
site
|
|
6093
|
+
site,
|
|
6094
|
+
serviceType
|
|
5915
6095
|
}) {
|
|
5916
6096
|
page = page > 0 ? page - 1 : 0;
|
|
5917
6097
|
const query = {
|
|
5918
|
-
status: { $ne: "deleted" }
|
|
6098
|
+
status: { $ne: "deleted" },
|
|
6099
|
+
serviceType
|
|
5919
6100
|
};
|
|
5920
6101
|
const cacheOptions = {
|
|
5921
6102
|
page,
|
|
5922
|
-
limit
|
|
6103
|
+
limit,
|
|
6104
|
+
serviceType
|
|
5923
6105
|
};
|
|
5924
6106
|
try {
|
|
5925
6107
|
site = new import_mongodb19.ObjectId(site);
|
|
@@ -5975,62 +6157,6 @@ function useScheduleTaskRepository() {
|
|
|
5975
6157
|
throw error;
|
|
5976
6158
|
}
|
|
5977
6159
|
}
|
|
5978
|
-
async function getTasksForScheduleTask({
|
|
5979
|
-
page = 1,
|
|
5980
|
-
limit = 10,
|
|
5981
|
-
search = "",
|
|
5982
|
-
site
|
|
5983
|
-
}) {
|
|
5984
|
-
page = page > 0 ? page - 1 : 0;
|
|
5985
|
-
const query = {
|
|
5986
|
-
status: { $ne: "deleted" }
|
|
5987
|
-
};
|
|
5988
|
-
const cacheOptions = {
|
|
5989
|
-
page,
|
|
5990
|
-
limit
|
|
5991
|
-
};
|
|
5992
|
-
try {
|
|
5993
|
-
site = new import_mongodb19.ObjectId(site);
|
|
5994
|
-
query.site = site;
|
|
5995
|
-
cacheOptions.site = site.toString();
|
|
5996
|
-
} catch (error) {
|
|
5997
|
-
throw new import_node_server_utils33.BadRequestError("Invalid site ID format.");
|
|
5998
|
-
}
|
|
5999
|
-
if (search) {
|
|
6000
|
-
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
6001
|
-
cacheOptions.search = search;
|
|
6002
|
-
}
|
|
6003
|
-
const cacheKey = (0, import_node_server_utils33.makeCacheKey)(namespace_collection, cacheOptions);
|
|
6004
|
-
const cachedData = await getCache(cacheKey);
|
|
6005
|
-
if (cachedData) {
|
|
6006
|
-
import_node_server_utils33.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
6007
|
-
return cachedData;
|
|
6008
|
-
}
|
|
6009
|
-
try {
|
|
6010
|
-
const items = await collection.aggregate([
|
|
6011
|
-
{ $match: query },
|
|
6012
|
-
{
|
|
6013
|
-
$project: {
|
|
6014
|
-
createdAt: 1,
|
|
6015
|
-
title: 1
|
|
6016
|
-
}
|
|
6017
|
-
},
|
|
6018
|
-
{ $sort: { _id: -1 } },
|
|
6019
|
-
{ $skip: page * limit },
|
|
6020
|
-
{ $limit: limit }
|
|
6021
|
-
]).toArray();
|
|
6022
|
-
const length = await collection.countDocuments(query);
|
|
6023
|
-
const data = (0, import_node_server_utils33.paginate)(items, page, limit, length);
|
|
6024
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
6025
|
-
import_node_server_utils33.logger.info(`Cache set for key: ${cacheKey}`);
|
|
6026
|
-
}).catch((err) => {
|
|
6027
|
-
import_node_server_utils33.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
6028
|
-
});
|
|
6029
|
-
return data;
|
|
6030
|
-
} catch (error) {
|
|
6031
|
-
throw error;
|
|
6032
|
-
}
|
|
6033
|
-
}
|
|
6034
6160
|
async function getScheduleTaskById(_id, session) {
|
|
6035
6161
|
try {
|
|
6036
6162
|
_id = new import_mongodb19.ObjectId(_id);
|
|
@@ -6130,7 +6256,6 @@ function useScheduleTaskRepository() {
|
|
|
6130
6256
|
createScheduleTask,
|
|
6131
6257
|
getScheduleTasks,
|
|
6132
6258
|
getAllScheduleTask,
|
|
6133
|
-
getTasksForScheduleTask,
|
|
6134
6259
|
getScheduleTaskById,
|
|
6135
6260
|
updateScheduleTask
|
|
6136
6261
|
};
|
|
@@ -6148,7 +6273,7 @@ function useScheduleTaskService() {
|
|
|
6148
6273
|
pushScheduleTaskSets
|
|
6149
6274
|
} = useAreaChecklistRepo();
|
|
6150
6275
|
const { getAreaById } = useAreaRepo();
|
|
6151
|
-
function checkScheduleConditions(schedule, currentDate = /* @__PURE__ */ new Date()) {
|
|
6276
|
+
function checkScheduleConditions(schedule, serviceType, currentDate = /* @__PURE__ */ new Date()) {
|
|
6152
6277
|
try {
|
|
6153
6278
|
const now = currentDate;
|
|
6154
6279
|
const timeString = now.toLocaleTimeString("en-US", {
|
|
@@ -6239,12 +6364,17 @@ function useScheduleTaskService() {
|
|
|
6239
6364
|
const validatedTasks = [];
|
|
6240
6365
|
for (const scheduleTask of scheduleTasks) {
|
|
6241
6366
|
try {
|
|
6367
|
+
const serviceType = scheduleTask.serviceType;
|
|
6242
6368
|
import_node_server_utils34.logger.info(
|
|
6243
6369
|
`Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time}, dates=${JSON.stringify(
|
|
6244
6370
|
scheduleTask.dates
|
|
6245
6371
|
)}`
|
|
6246
6372
|
);
|
|
6247
|
-
const shouldRun = checkScheduleConditions(
|
|
6373
|
+
const shouldRun = checkScheduleConditions(
|
|
6374
|
+
scheduleTask,
|
|
6375
|
+
serviceType,
|
|
6376
|
+
currentDate
|
|
6377
|
+
);
|
|
6248
6378
|
if (!shouldRun) {
|
|
6249
6379
|
import_node_server_utils34.logger.info(
|
|
6250
6380
|
`Schedule ${scheduleTask._id} conditions not met, skipping`
|
|
@@ -6267,6 +6397,7 @@ function useScheduleTaskService() {
|
|
|
6267
6397
|
);
|
|
6268
6398
|
const parentChecklistIds = await createParentChecklist({
|
|
6269
6399
|
site: scheduleTask.site.toString(),
|
|
6400
|
+
serviceType,
|
|
6270
6401
|
createdAt: /* @__PURE__ */ new Date()
|
|
6271
6402
|
});
|
|
6272
6403
|
const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
|
|
@@ -6304,8 +6435,11 @@ function useScheduleTaskService() {
|
|
|
6304
6435
|
let existingAreaChecklist;
|
|
6305
6436
|
try {
|
|
6306
6437
|
existingAreaChecklist = await getAreaChecklistByAreaAndSchedule(
|
|
6307
|
-
|
|
6308
|
-
|
|
6438
|
+
{
|
|
6439
|
+
schedule: parentChecklistId.toString(),
|
|
6440
|
+
serviceType,
|
|
6441
|
+
area: areaId
|
|
6442
|
+
}
|
|
6309
6443
|
);
|
|
6310
6444
|
import_node_server_utils34.logger.info(
|
|
6311
6445
|
`Area ${area.name} (${areaId}): Existing area checklist found: ${existingAreaChecklist ? "Yes" : "No"}`
|
|
@@ -6342,6 +6476,7 @@ function useScheduleTaskService() {
|
|
|
6342
6476
|
);
|
|
6343
6477
|
const modified = await pushScheduleTaskSets(
|
|
6344
6478
|
parentChecklistId.toString(),
|
|
6479
|
+
serviceType,
|
|
6345
6480
|
areaId,
|
|
6346
6481
|
scheduleTask._id.toString(),
|
|
6347
6482
|
newSets
|
|
@@ -6369,6 +6504,7 @@ function useScheduleTaskService() {
|
|
|
6369
6504
|
);
|
|
6370
6505
|
const checklistData = {
|
|
6371
6506
|
schedule: parentChecklistId.toString(),
|
|
6507
|
+
serviceType,
|
|
6372
6508
|
area: areaId,
|
|
6373
6509
|
name: area.name,
|
|
6374
6510
|
type: areaDetails.type || "common",
|
|
@@ -6423,7 +6559,6 @@ function useScheduleTaskController() {
|
|
|
6423
6559
|
const {
|
|
6424
6560
|
createScheduleTask: _createScheduleTask,
|
|
6425
6561
|
getScheduleTasks: _getScheduleTasks,
|
|
6426
|
-
getTasksForScheduleTask: _getTasksForScheduleTask,
|
|
6427
6562
|
getScheduleTaskById: _getScheduleTaskById,
|
|
6428
6563
|
updateScheduleTask: _updateScheduleTask
|
|
6429
6564
|
} = useScheduleTaskRepository();
|
|
@@ -6456,7 +6591,8 @@ function useScheduleTaskController() {
|
|
|
6456
6591
|
page: import_joi17.default.number().min(1).optional().allow("", null),
|
|
6457
6592
|
limit: import_joi17.default.number().min(1).optional().allow("", null),
|
|
6458
6593
|
search: import_joi17.default.string().optional().allow("", null),
|
|
6459
|
-
site: import_joi17.default.string().hex().required()
|
|
6594
|
+
site: import_joi17.default.string().hex().required(),
|
|
6595
|
+
serviceType: import_joi17.default.string().valid(...Object.values(ServiceType)).required()
|
|
6460
6596
|
});
|
|
6461
6597
|
const { error } = validation.validate(query);
|
|
6462
6598
|
if (error) {
|
|
@@ -6468,45 +6604,14 @@ function useScheduleTaskController() {
|
|
|
6468
6604
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
6469
6605
|
const search = req.query.search ?? "";
|
|
6470
6606
|
const site = req.params.site ?? "";
|
|
6607
|
+
const serviceType = req.query.serviceType ?? "";
|
|
6471
6608
|
try {
|
|
6472
6609
|
const data = await _getScheduleTasks({
|
|
6473
6610
|
page,
|
|
6474
6611
|
limit,
|
|
6475
6612
|
search,
|
|
6476
|
-
site
|
|
6477
|
-
|
|
6478
|
-
res.json(data);
|
|
6479
|
-
return;
|
|
6480
|
-
} catch (error2) {
|
|
6481
|
-
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
6482
|
-
next(error2);
|
|
6483
|
-
return;
|
|
6484
|
-
}
|
|
6485
|
-
}
|
|
6486
|
-
async function getTasksForScheduleTask(req, res, next) {
|
|
6487
|
-
const query = { ...req.query, ...req.params };
|
|
6488
|
-
const validation = import_joi17.default.object({
|
|
6489
|
-
page: import_joi17.default.number().min(1).optional().allow("", null),
|
|
6490
|
-
limit: import_joi17.default.number().min(1).optional().allow("", null),
|
|
6491
|
-
search: import_joi17.default.string().optional().allow("", null),
|
|
6492
|
-
site: import_joi17.default.string().hex().required()
|
|
6493
|
-
});
|
|
6494
|
-
const { error } = validation.validate(query);
|
|
6495
|
-
if (error) {
|
|
6496
|
-
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6497
|
-
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
6498
|
-
return;
|
|
6499
|
-
}
|
|
6500
|
-
const page = parseInt(req.query.page) ?? 1;
|
|
6501
|
-
const limit = parseInt(req.query.limit) ?? 10;
|
|
6502
|
-
const search = req.query.search ?? "";
|
|
6503
|
-
const site = req.params.site ?? "";
|
|
6504
|
-
try {
|
|
6505
|
-
const data = await _getTasksForScheduleTask({
|
|
6506
|
-
page,
|
|
6507
|
-
limit,
|
|
6508
|
-
search,
|
|
6509
|
-
site
|
|
6613
|
+
site,
|
|
6614
|
+
serviceType
|
|
6510
6615
|
});
|
|
6511
6616
|
res.json(data);
|
|
6512
6617
|
return;
|
|
@@ -6572,7 +6677,6 @@ function useScheduleTaskController() {
|
|
|
6572
6677
|
return {
|
|
6573
6678
|
createScheduleTask,
|
|
6574
6679
|
getScheduleTasks,
|
|
6575
|
-
getTasksForScheduleTask,
|
|
6576
6680
|
getScheduleTaskById,
|
|
6577
6681
|
updateScheduleTask
|
|
6578
6682
|
};
|
|
@@ -6865,6 +6969,7 @@ function useQRController() {
|
|
|
6865
6969
|
MStock,
|
|
6866
6970
|
MSupply,
|
|
6867
6971
|
MUnit,
|
|
6972
|
+
ServiceType,
|
|
6868
6973
|
allowedCheckOutItemStatus,
|
|
6869
6974
|
allowedChecklistStatus,
|
|
6870
6975
|
allowedPeriods,
|