@7365admin1/module-hygiene 4.12.0 → 4.13.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 +6 -0
- package/dist/index.d.ts +42 -14
- package/dist/index.js +130 -76
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +129 -76
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
// src/models/hygiene-base.model.ts
|
|
2
|
+
var ServiceType = /* @__PURE__ */ ((ServiceType2) => {
|
|
3
|
+
ServiceType2["REAL_ESTATE_DEVELOPER"] = "real_estate_developer";
|
|
4
|
+
ServiceType2["PROPERTY_MANAGEMENT_AGENCY"] = "property_management_agency";
|
|
5
|
+
ServiceType2["SECURITY_AGENCY"] = "security_agency";
|
|
6
|
+
ServiceType2["CLEANING_SERVICES"] = "cleaning_services";
|
|
7
|
+
ServiceType2["MECHANICAL_ELECTRICAL_SERVICES"] = "mechanical_electrical_services";
|
|
8
|
+
ServiceType2["LANDSCAPING_SERVICES"] = "landscaping_services";
|
|
9
|
+
ServiceType2["PEST_CONTROL_SERVICES"] = "pest_control_services";
|
|
10
|
+
ServiceType2["POOL_MAINTENANCE_SERVICES"] = "pool_maintenance_services";
|
|
11
|
+
return ServiceType2;
|
|
12
|
+
})(ServiceType || {});
|
|
2
13
|
var allowedTypes = ["common", "toilet"];
|
|
3
14
|
var allowedStatus = [
|
|
4
15
|
"open",
|
|
@@ -547,6 +558,7 @@ import { ObjectId as ObjectId2 } from "mongodb";
|
|
|
547
558
|
import { BadRequestError as BadRequestError3, logger as logger3 } from "@7365admin1/node-server-utils";
|
|
548
559
|
var areaSchema = Joi2.object({
|
|
549
560
|
site: Joi2.string().hex().required(),
|
|
561
|
+
serviceType: Joi2.string().valid(...Object.values(ServiceType)).required(),
|
|
550
562
|
name: Joi2.string().required(),
|
|
551
563
|
type: Joi2.string().valid(...allowedTypes).required(),
|
|
552
564
|
set: Joi2.number().min(0).optional(),
|
|
@@ -586,6 +598,7 @@ function MArea(value) {
|
|
|
586
598
|
}
|
|
587
599
|
return {
|
|
588
600
|
site: value.site,
|
|
601
|
+
serviceType: value.serviceType,
|
|
589
602
|
name: value.name,
|
|
590
603
|
type: value.type,
|
|
591
604
|
set: value.set ?? 0,
|
|
@@ -630,6 +643,7 @@ function useAreaRepo() {
|
|
|
630
643
|
try {
|
|
631
644
|
await collection.createIndexes([
|
|
632
645
|
{ key: { site: 1 } },
|
|
646
|
+
{ key: { serviceType: 1 } },
|
|
633
647
|
{ key: { type: 1 } },
|
|
634
648
|
{ key: { status: 1 } },
|
|
635
649
|
{ key: { "units.unit": 1 } }
|
|
@@ -650,7 +664,7 @@ function useAreaRepo() {
|
|
|
650
664
|
async function createUniqueIndex() {
|
|
651
665
|
try {
|
|
652
666
|
await collection.createIndex(
|
|
653
|
-
{ site: 1, name: 1, type: 1, deletedAt: 1 },
|
|
667
|
+
{ site: 1, serviceType: 1, name: 1, type: 1, deletedAt: 1 },
|
|
654
668
|
{ unique: true }
|
|
655
669
|
);
|
|
656
670
|
} catch (error) {
|
|
@@ -687,15 +701,18 @@ function useAreaRepo() {
|
|
|
687
701
|
limit = 10,
|
|
688
702
|
search = "",
|
|
689
703
|
type = "all",
|
|
690
|
-
site
|
|
704
|
+
site,
|
|
705
|
+
serviceType
|
|
691
706
|
}) {
|
|
692
707
|
page = page > 0 ? page - 1 : 0;
|
|
693
708
|
const query = {
|
|
694
|
-
status: { $ne: "deleted" }
|
|
709
|
+
status: { $ne: "deleted" },
|
|
710
|
+
serviceType
|
|
695
711
|
};
|
|
696
712
|
const cacheOptions = {
|
|
697
713
|
page,
|
|
698
|
-
limit
|
|
714
|
+
limit,
|
|
715
|
+
serviceType
|
|
699
716
|
};
|
|
700
717
|
try {
|
|
701
718
|
site = new ObjectId3(site);
|
|
@@ -744,9 +761,15 @@ function useAreaRepo() {
|
|
|
744
761
|
throw error;
|
|
745
762
|
}
|
|
746
763
|
}
|
|
747
|
-
async function getAreasForChecklist(site) {
|
|
748
|
-
const query = {
|
|
764
|
+
async function getAreasForChecklist(site, serviceType) {
|
|
765
|
+
const query = {
|
|
766
|
+
status: { $ne: "deleted" }
|
|
767
|
+
};
|
|
749
768
|
const cacheOptions = {};
|
|
769
|
+
if (serviceType) {
|
|
770
|
+
query.serviceType = serviceType;
|
|
771
|
+
cacheOptions.serviceType = serviceType;
|
|
772
|
+
}
|
|
750
773
|
try {
|
|
751
774
|
site = new ObjectId3(site);
|
|
752
775
|
query.site = site;
|
|
@@ -826,28 +849,6 @@ function useAreaRepo() {
|
|
|
826
849
|
throw error;
|
|
827
850
|
}
|
|
828
851
|
}
|
|
829
|
-
async function getAreaByMultipleId(_id) {
|
|
830
|
-
for (let i = 0; i < _id.length; i++) {
|
|
831
|
-
try {
|
|
832
|
-
_id[i] = new ObjectId3(_id[i]);
|
|
833
|
-
} catch (error) {
|
|
834
|
-
throw new BadRequestError4("Invalid area ID format.");
|
|
835
|
-
}
|
|
836
|
-
}
|
|
837
|
-
const query = {
|
|
838
|
-
_id: { $in: _id },
|
|
839
|
-
status: { $ne: "deleted" }
|
|
840
|
-
};
|
|
841
|
-
try {
|
|
842
|
-
const data = await collection.aggregate([{ $match: query }]).toArray();
|
|
843
|
-
if (!data || data.length === 0) {
|
|
844
|
-
throw new NotFoundError("Area not found.");
|
|
845
|
-
}
|
|
846
|
-
return data;
|
|
847
|
-
} catch (error) {
|
|
848
|
-
throw error;
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
852
|
async function verifyAreaByUnitId(unitId) {
|
|
852
853
|
try {
|
|
853
854
|
unitId = new ObjectId3(unitId);
|
|
@@ -1009,7 +1010,6 @@ function useAreaRepo() {
|
|
|
1009
1010
|
getAreas,
|
|
1010
1011
|
getAreasForChecklist,
|
|
1011
1012
|
getAreaById,
|
|
1012
|
-
getAreaByMultipleId,
|
|
1013
1013
|
verifyAreaByUnitId,
|
|
1014
1014
|
updateArea,
|
|
1015
1015
|
updateAreaChecklist,
|
|
@@ -1088,6 +1088,7 @@ import { ObjectId as ObjectId4 } from "mongodb";
|
|
|
1088
1088
|
import { BadRequestError as BadRequestError5, logger as logger6 } from "@7365admin1/node-server-utils";
|
|
1089
1089
|
var unitSchema = Joi3.object({
|
|
1090
1090
|
site: Joi3.string().hex().required(),
|
|
1091
|
+
serviceType: Joi3.string().valid(...Object.values(ServiceType)).required(),
|
|
1091
1092
|
name: Joi3.string().required()
|
|
1092
1093
|
});
|
|
1093
1094
|
function MUnit(value) {
|
|
@@ -1105,6 +1106,7 @@ function MUnit(value) {
|
|
|
1105
1106
|
}
|
|
1106
1107
|
return {
|
|
1107
1108
|
site: value.site,
|
|
1109
|
+
serviceType: value.serviceType,
|
|
1108
1110
|
name: value.name,
|
|
1109
1111
|
status: "active",
|
|
1110
1112
|
createdAt: /* @__PURE__ */ new Date(),
|
|
@@ -1126,6 +1128,7 @@ function useUnitRepository() {
|
|
|
1126
1128
|
try {
|
|
1127
1129
|
await collection.createIndexes([
|
|
1128
1130
|
{ key: { site: 1 } },
|
|
1131
|
+
{ key: { serviceType: 1 } },
|
|
1129
1132
|
{ key: { status: 1 } }
|
|
1130
1133
|
]);
|
|
1131
1134
|
} catch (error) {
|
|
@@ -1144,7 +1147,7 @@ function useUnitRepository() {
|
|
|
1144
1147
|
async function createUniqueIndex() {
|
|
1145
1148
|
try {
|
|
1146
1149
|
await collection.createIndex(
|
|
1147
|
-
{ site: 1, name: 1, deletedAt: 1 },
|
|
1150
|
+
{ site: 1, serviceType: 1, name: 1, deletedAt: 1 },
|
|
1148
1151
|
{ unique: true }
|
|
1149
1152
|
);
|
|
1150
1153
|
} catch (error) {
|
|
@@ -1178,7 +1181,8 @@ function useUnitRepository() {
|
|
|
1178
1181
|
page = 1,
|
|
1179
1182
|
limit = 10,
|
|
1180
1183
|
search = "",
|
|
1181
|
-
site
|
|
1184
|
+
site,
|
|
1185
|
+
serviceType
|
|
1182
1186
|
}) {
|
|
1183
1187
|
page = page > 0 ? page - 1 : 0;
|
|
1184
1188
|
const query = {
|
|
@@ -1195,6 +1199,10 @@ function useUnitRepository() {
|
|
|
1195
1199
|
} catch (error) {
|
|
1196
1200
|
throw new BadRequestError6("Invalid site ID format.");
|
|
1197
1201
|
}
|
|
1202
|
+
if (serviceType) {
|
|
1203
|
+
query.serviceType = serviceType;
|
|
1204
|
+
cacheOptions.serviceType = serviceType;
|
|
1205
|
+
}
|
|
1198
1206
|
if (search) {
|
|
1199
1207
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
1200
1208
|
cacheOptions.search = search;
|
|
@@ -1253,7 +1261,7 @@ function useUnitRepository() {
|
|
|
1253
1261
|
} catch (error) {
|
|
1254
1262
|
const isDuplicated = error.message.includes("duplicate");
|
|
1255
1263
|
if (isDuplicated) {
|
|
1256
|
-
throw new BadRequestError6("
|
|
1264
|
+
throw new BadRequestError6("Unit already exists.");
|
|
1257
1265
|
}
|
|
1258
1266
|
throw error;
|
|
1259
1267
|
}
|
|
@@ -1309,7 +1317,8 @@ function useAreaService() {
|
|
|
1309
1317
|
const { getUnits: _getUnits } = useUnitRepository();
|
|
1310
1318
|
async function importArea({
|
|
1311
1319
|
dataJson,
|
|
1312
|
-
site
|
|
1320
|
+
site,
|
|
1321
|
+
serviceType
|
|
1313
1322
|
}) {
|
|
1314
1323
|
let dataArray;
|
|
1315
1324
|
try {
|
|
@@ -1330,7 +1339,8 @@ function useAreaService() {
|
|
|
1330
1339
|
page: 1,
|
|
1331
1340
|
limit: 999999,
|
|
1332
1341
|
search: "",
|
|
1333
|
-
site
|
|
1342
|
+
site,
|
|
1343
|
+
serviceType
|
|
1334
1344
|
});
|
|
1335
1345
|
if (unitsData && unitsData.items) {
|
|
1336
1346
|
availableUnits = unitsData.items;
|
|
@@ -1377,7 +1387,8 @@ function useAreaService() {
|
|
|
1377
1387
|
const areaData = {
|
|
1378
1388
|
type: areaType,
|
|
1379
1389
|
name: areaName,
|
|
1380
|
-
site
|
|
1390
|
+
site,
|
|
1391
|
+
serviceType
|
|
1381
1392
|
};
|
|
1382
1393
|
if (row.SET !== void 0 && row.SET !== null && row.SET !== "") {
|
|
1383
1394
|
const setNumber = parseInt(String(row.SET).trim());
|
|
@@ -1471,9 +1482,12 @@ function useAreaService() {
|
|
|
1471
1482
|
}
|
|
1472
1483
|
}
|
|
1473
1484
|
}
|
|
1474
|
-
async function exportAreas(
|
|
1485
|
+
async function exportAreas({
|
|
1486
|
+
site,
|
|
1487
|
+
serviceType
|
|
1488
|
+
}) {
|
|
1475
1489
|
try {
|
|
1476
|
-
const areas = await getAreasForChecklist(site);
|
|
1490
|
+
const areas = await getAreasForChecklist(site, serviceType);
|
|
1477
1491
|
if (!areas || !Array.isArray(areas) || areas.length === 0) {
|
|
1478
1492
|
throw new BadRequestError7(
|
|
1479
1493
|
"There are no areas to export yet. Please add some areas first, then try again."
|
|
@@ -1560,7 +1574,8 @@ function useAreaController() {
|
|
|
1560
1574
|
limit: Joi4.number().min(1).optional().allow("", null),
|
|
1561
1575
|
search: Joi4.string().optional().allow("", null),
|
|
1562
1576
|
type: Joi4.string().valid("all", ...allowedTypes).optional().allow("", null),
|
|
1563
|
-
site: Joi4.string().hex().required()
|
|
1577
|
+
site: Joi4.string().hex().required(),
|
|
1578
|
+
serviceType: Joi4.string().valid(...Object.values(ServiceType)).required()
|
|
1564
1579
|
});
|
|
1565
1580
|
const { error } = validation.validate(query);
|
|
1566
1581
|
if (error) {
|
|
@@ -1573,13 +1588,15 @@ function useAreaController() {
|
|
|
1573
1588
|
const search = req.query.search ?? "";
|
|
1574
1589
|
const type = req.query.type ?? "all";
|
|
1575
1590
|
const site = req.params.site ?? "";
|
|
1591
|
+
const serviceType = req.query.serviceType ?? "";
|
|
1576
1592
|
try {
|
|
1577
1593
|
const data = await _getAreas({
|
|
1578
1594
|
page,
|
|
1579
1595
|
limit,
|
|
1580
1596
|
search,
|
|
1581
1597
|
type,
|
|
1582
|
-
site
|
|
1598
|
+
site,
|
|
1599
|
+
serviceType
|
|
1583
1600
|
});
|
|
1584
1601
|
res.json(data);
|
|
1585
1602
|
return;
|
|
@@ -1664,9 +1681,12 @@ function useAreaController() {
|
|
|
1664
1681
|
next(new BadRequestError8("File is required!"));
|
|
1665
1682
|
return;
|
|
1666
1683
|
}
|
|
1667
|
-
const
|
|
1668
|
-
const
|
|
1669
|
-
|
|
1684
|
+
const query = { ...req.query, ...req.params };
|
|
1685
|
+
const validation = Joi4.object({
|
|
1686
|
+
site: Joi4.string().hex().required(),
|
|
1687
|
+
serviceType: Joi4.string().valid(...Object.values(ServiceType)).required()
|
|
1688
|
+
});
|
|
1689
|
+
const { error, value } = validation.validate(query);
|
|
1670
1690
|
if (error) {
|
|
1671
1691
|
logger9.log({ level: "error", message: error.message });
|
|
1672
1692
|
next(new BadRequestError8(error.message));
|
|
@@ -1675,7 +1695,7 @@ function useAreaController() {
|
|
|
1675
1695
|
try {
|
|
1676
1696
|
const xlsData = await convertBufferFile(req.file.buffer);
|
|
1677
1697
|
const dataJson = JSON.stringify(xlsData);
|
|
1678
|
-
const result = await _importArea({ dataJson,
|
|
1698
|
+
const result = await _importArea({ dataJson, ...value });
|
|
1679
1699
|
return res.status(201).json(result);
|
|
1680
1700
|
} catch (error2) {
|
|
1681
1701
|
logger9.log({ level: "error", message: error2.message });
|
|
@@ -1684,9 +1704,12 @@ function useAreaController() {
|
|
|
1684
1704
|
}
|
|
1685
1705
|
}
|
|
1686
1706
|
async function exportAreas(req, res, next) {
|
|
1687
|
-
const
|
|
1688
|
-
const validation = Joi4.
|
|
1689
|
-
|
|
1707
|
+
const query = { ...req.query, ...req.params };
|
|
1708
|
+
const validation = Joi4.object({
|
|
1709
|
+
site: Joi4.string().hex().required(),
|
|
1710
|
+
serviceType: Joi4.string().valid(...Object.values(ServiceType)).required()
|
|
1711
|
+
});
|
|
1712
|
+
const { error, value } = validation.validate(query);
|
|
1690
1713
|
if (error) {
|
|
1691
1714
|
logger9.log({ level: "error", message: error.message });
|
|
1692
1715
|
next(new BadRequestError8(error.message));
|
|
@@ -1782,7 +1805,8 @@ function useUnitService() {
|
|
|
1782
1805
|
} = useUnitRepository();
|
|
1783
1806
|
async function importUnit({
|
|
1784
1807
|
dataJson,
|
|
1785
|
-
site
|
|
1808
|
+
site,
|
|
1809
|
+
serviceType
|
|
1786
1810
|
}) {
|
|
1787
1811
|
let dataArray;
|
|
1788
1812
|
try {
|
|
@@ -1823,7 +1847,8 @@ function useUnitService() {
|
|
|
1823
1847
|
try {
|
|
1824
1848
|
const insertedId = await _createUnit({
|
|
1825
1849
|
name: unitName,
|
|
1826
|
-
site
|
|
1850
|
+
site,
|
|
1851
|
+
serviceType
|
|
1827
1852
|
});
|
|
1828
1853
|
insertedUnitIds.push(insertedId);
|
|
1829
1854
|
logger11.info(`Successfully created unit: ${unitName}`);
|
|
@@ -1928,7 +1953,10 @@ function useUnitService() {
|
|
|
1928
1953
|
session?.endSession();
|
|
1929
1954
|
}
|
|
1930
1955
|
}
|
|
1931
|
-
async function exportUnits(
|
|
1956
|
+
async function exportUnits({
|
|
1957
|
+
site,
|
|
1958
|
+
serviceType
|
|
1959
|
+
}) {
|
|
1932
1960
|
const { generateUnitExcel: _generateUnitExcel } = useUnitExportService();
|
|
1933
1961
|
const { getUnits: _getUnits } = useUnitRepository();
|
|
1934
1962
|
try {
|
|
@@ -1936,7 +1964,8 @@ function useUnitService() {
|
|
|
1936
1964
|
page: 1,
|
|
1937
1965
|
limit: 999999,
|
|
1938
1966
|
search: "",
|
|
1939
|
-
site
|
|
1967
|
+
site,
|
|
1968
|
+
serviceType
|
|
1940
1969
|
});
|
|
1941
1970
|
if (!data || !data.items || data.items.length === 0) {
|
|
1942
1971
|
throw new BadRequestError9(
|
|
@@ -1993,7 +2022,8 @@ function useUnitController() {
|
|
|
1993
2022
|
page: Joi5.number().min(1).optional().allow("", null),
|
|
1994
2023
|
limit: Joi5.number().min(1).optional().allow("", null),
|
|
1995
2024
|
search: Joi5.string().optional().allow("", null),
|
|
1996
|
-
site: Joi5.string().hex().required()
|
|
2025
|
+
site: Joi5.string().hex().required(),
|
|
2026
|
+
serviceType: Joi5.string().valid(...Object.values(ServiceType)).required()
|
|
1997
2027
|
});
|
|
1998
2028
|
const { error } = validation.validate(query);
|
|
1999
2029
|
if (error) {
|
|
@@ -2005,12 +2035,14 @@ function useUnitController() {
|
|
|
2005
2035
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
2006
2036
|
const search = req.query.search ?? "";
|
|
2007
2037
|
const site = req.params.site ?? "";
|
|
2038
|
+
const serviceType = req.query.serviceType ?? "";
|
|
2008
2039
|
try {
|
|
2009
2040
|
const data = await _getUnits({
|
|
2010
2041
|
page,
|
|
2011
2042
|
limit,
|
|
2012
2043
|
search,
|
|
2013
|
-
site
|
|
2044
|
+
site,
|
|
2045
|
+
serviceType
|
|
2014
2046
|
});
|
|
2015
2047
|
res.json(data);
|
|
2016
2048
|
return;
|
|
@@ -2069,9 +2101,12 @@ function useUnitController() {
|
|
|
2069
2101
|
next(new BadRequestError10("File is required!"));
|
|
2070
2102
|
return;
|
|
2071
2103
|
}
|
|
2072
|
-
const
|
|
2073
|
-
const validation = Joi5.
|
|
2074
|
-
|
|
2104
|
+
const query = { ...req.query, ...req.params };
|
|
2105
|
+
const validation = Joi5.object({
|
|
2106
|
+
site: Joi5.string().hex().required(),
|
|
2107
|
+
serviceType: Joi5.string().valid(...Object.values(ServiceType)).required()
|
|
2108
|
+
});
|
|
2109
|
+
const { error, value } = validation.validate(query);
|
|
2075
2110
|
if (error) {
|
|
2076
2111
|
logger12.log({ level: "error", message: error.message });
|
|
2077
2112
|
next(new BadRequestError10(error.message));
|
|
@@ -2080,7 +2115,7 @@ function useUnitController() {
|
|
|
2080
2115
|
try {
|
|
2081
2116
|
const xlsData = await convertBufferFile(req.file.buffer);
|
|
2082
2117
|
const dataJson = JSON.stringify(xlsData);
|
|
2083
|
-
const result = await _importUnit({ dataJson,
|
|
2118
|
+
const result = await _importUnit({ dataJson, ...value });
|
|
2084
2119
|
return res.status(201).json(result);
|
|
2085
2120
|
} catch (error2) {
|
|
2086
2121
|
logger12.log({ level: "error", message: error2.message });
|
|
@@ -2089,9 +2124,12 @@ function useUnitController() {
|
|
|
2089
2124
|
}
|
|
2090
2125
|
}
|
|
2091
2126
|
async function exportUnits(req, res, next) {
|
|
2092
|
-
const
|
|
2093
|
-
const validation = Joi5.
|
|
2094
|
-
|
|
2127
|
+
const query = { ...req.query, ...req.params };
|
|
2128
|
+
const validation = Joi5.object({
|
|
2129
|
+
site: Joi5.string().hex().required(),
|
|
2130
|
+
serviceType: Joi5.string().valid(...Object.values(ServiceType)).required()
|
|
2131
|
+
});
|
|
2132
|
+
const { error, value } = validation.validate(query);
|
|
2095
2133
|
if (error) {
|
|
2096
2134
|
logger12.log({ level: "error", message: error.message });
|
|
2097
2135
|
next(new BadRequestError10(error.message));
|
|
@@ -2137,7 +2175,8 @@ import { ObjectId as ObjectId6 } from "mongodb";
|
|
|
2137
2175
|
import { BadRequestError as BadRequestError11, logger as logger13 } from "@7365admin1/node-server-utils";
|
|
2138
2176
|
var parentChecklistSchema = Joi6.object({
|
|
2139
2177
|
createdAt: Joi6.alternatives().try(Joi6.date(), Joi6.string()).optional().allow("", null),
|
|
2140
|
-
site: Joi6.string().hex().required()
|
|
2178
|
+
site: Joi6.string().hex().required(),
|
|
2179
|
+
serviceType: Joi6.string().valid(...Object.values(ServiceType)).required()
|
|
2141
2180
|
});
|
|
2142
2181
|
function MParentChecklist(value) {
|
|
2143
2182
|
const { error } = parentChecklistSchema.validate(value);
|
|
@@ -2154,6 +2193,7 @@ function MParentChecklist(value) {
|
|
|
2154
2193
|
}
|
|
2155
2194
|
return {
|
|
2156
2195
|
site: value.site,
|
|
2196
|
+
serviceType: value.serviceType,
|
|
2157
2197
|
status: "open",
|
|
2158
2198
|
createdAt: value.createdAt ?? /* @__PURE__ */ new Date(),
|
|
2159
2199
|
updatedAt: value.updatedAt ?? ""
|
|
@@ -2236,12 +2276,16 @@ function useParentChecklistRepo() {
|
|
|
2236
2276
|
);
|
|
2237
2277
|
return existingChecklist._id;
|
|
2238
2278
|
}
|
|
2279
|
+
const allServiceTypes = Object.values(ServiceType);
|
|
2239
2280
|
if (value.site) {
|
|
2240
|
-
const
|
|
2241
|
-
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2281
|
+
const checklistDocs2 = allServiceTypes.map(
|
|
2282
|
+
(serviceType) => MParentChecklist({
|
|
2283
|
+
site: value.site,
|
|
2284
|
+
createdAt: currentDate,
|
|
2285
|
+
serviceType
|
|
2286
|
+
})
|
|
2287
|
+
);
|
|
2288
|
+
const result2 = await collection.insertMany(checklistDocs2, { session });
|
|
2245
2289
|
delNamespace().then(() => {
|
|
2246
2290
|
logger14.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
2247
2291
|
}).catch((err) => {
|
|
@@ -2252,9 +2296,9 @@ function useParentChecklistRepo() {
|
|
|
2252
2296
|
});
|
|
2253
2297
|
const dateStr2 = currentDate.toISOString().split("T")[0];
|
|
2254
2298
|
logger14.info(
|
|
2255
|
-
`Created parent
|
|
2299
|
+
`Created ${checklistDocs2.length} parent checklists for site ${value.site} for today: ${dateStr2}`
|
|
2256
2300
|
);
|
|
2257
|
-
return result2.
|
|
2301
|
+
return Object.values(result2.insertedIds);
|
|
2258
2302
|
}
|
|
2259
2303
|
const siteIds = await getHygieneSiteIds();
|
|
2260
2304
|
if (!Array.isArray(siteIds)) {
|
|
@@ -2267,12 +2311,15 @@ function useParentChecklistRepo() {
|
|
|
2267
2311
|
}
|
|
2268
2312
|
const checklistDocs = [];
|
|
2269
2313
|
for (const site of siteIds) {
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2314
|
+
for (const serviceType of allServiceTypes) {
|
|
2315
|
+
checklistDocs.push(
|
|
2316
|
+
MParentChecklist({
|
|
2317
|
+
site,
|
|
2318
|
+
createdAt: currentDate,
|
|
2319
|
+
serviceType
|
|
2320
|
+
})
|
|
2321
|
+
);
|
|
2322
|
+
}
|
|
2276
2323
|
}
|
|
2277
2324
|
const result = await collection.insertMany(checklistDocs, { session });
|
|
2278
2325
|
delNamespace().then(() => {
|
|
@@ -2300,13 +2347,15 @@ function useParentChecklistRepo() {
|
|
|
2300
2347
|
site,
|
|
2301
2348
|
startDate = "",
|
|
2302
2349
|
endDate = "",
|
|
2303
|
-
status = "all"
|
|
2350
|
+
status = "all",
|
|
2351
|
+
serviceType
|
|
2304
2352
|
}) {
|
|
2305
2353
|
page = page > 0 ? page - 1 : 0;
|
|
2306
|
-
const query = {};
|
|
2354
|
+
const query = { serviceType };
|
|
2307
2355
|
const cacheOptions = {
|
|
2308
2356
|
page,
|
|
2309
|
-
limit
|
|
2357
|
+
limit,
|
|
2358
|
+
serviceType
|
|
2310
2359
|
};
|
|
2311
2360
|
try {
|
|
2312
2361
|
site = new ObjectId7(site);
|
|
@@ -2546,6 +2595,7 @@ function useParentChecklistController() {
|
|
|
2546
2595
|
limit: Joi7.number().min(1).optional().allow("", null),
|
|
2547
2596
|
search: Joi7.string().optional().allow("", null),
|
|
2548
2597
|
site: Joi7.string().hex().required(),
|
|
2598
|
+
serviceType: Joi7.string().valid(...Object.values(ServiceType)).required(),
|
|
2549
2599
|
startDate: Joi7.alternatives().try(Joi7.date(), Joi7.string()).optional().allow("", null),
|
|
2550
2600
|
endDate: Joi7.alternatives().try(Joi7.date(), Joi7.string()).optional().allow("", null),
|
|
2551
2601
|
status: Joi7.string().valid(...allowedStatus, "all").optional().allow("", null)
|
|
@@ -2560,6 +2610,7 @@ function useParentChecklistController() {
|
|
|
2560
2610
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
2561
2611
|
const search = req.query.search ?? "";
|
|
2562
2612
|
const site = req.params.site ?? "";
|
|
2613
|
+
const serviceType = req.query.serviceType ?? "";
|
|
2563
2614
|
const startDate = req.query.startDate ?? "";
|
|
2564
2615
|
const endDate = req.query.endDate ?? "";
|
|
2565
2616
|
const status = req.query.status ?? "all";
|
|
@@ -2569,6 +2620,7 @@ function useParentChecklistController() {
|
|
|
2569
2620
|
limit,
|
|
2570
2621
|
search,
|
|
2571
2622
|
site,
|
|
2623
|
+
serviceType,
|
|
2572
2624
|
startDate,
|
|
2573
2625
|
endDate,
|
|
2574
2626
|
status
|
|
@@ -6872,6 +6924,7 @@ export {
|
|
|
6872
6924
|
MStock,
|
|
6873
6925
|
MSupply,
|
|
6874
6926
|
MUnit,
|
|
6927
|
+
ServiceType,
|
|
6875
6928
|
allowedCheckOutItemStatus,
|
|
6876
6929
|
allowedChecklistStatus,
|
|
6877
6930
|
allowedPeriods,
|