@7365admin1/module-hygiene 4.29.1-staging.12 → 4.29.1-staging.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.changeset/area-import-unit-ids.md +5 -0
- package/.changeset/checklist-photo-set-finish-approve-reject.md +9 -0
- package/.changeset/photo-required-only-on-completion.md +9 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +348 -296
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +348 -296
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
- package/test/area-import-unit-id.test.mjs +18 -0
- package/test/require-photo-on-completion.test.mjs +161 -117
package/dist/index.mjs
CHANGED
|
@@ -843,21 +843,30 @@ function useHygieneDashboardController() {
|
|
|
843
843
|
}
|
|
844
844
|
|
|
845
845
|
// src/models/hygiene-area.model.ts
|
|
846
|
-
import
|
|
846
|
+
import Joi3 from "joi";
|
|
847
847
|
import { ObjectId as ObjectId2 } from "mongodb";
|
|
848
848
|
import { BadRequestError as BadRequestError3, logger as logger3 } from "@7365admin1/node-server-utils";
|
|
849
849
|
import { AppServiceType as AppServiceType2 } from "@7365admin1/core";
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
850
|
+
|
|
851
|
+
// src/utils/area-unit.util.ts
|
|
852
|
+
import Joi2 from "joi";
|
|
853
|
+
var areaUnitSchema = Joi2.object({
|
|
854
|
+
unit: Joi2.string().hex().required(),
|
|
855
|
+
name: Joi2.string().required()
|
|
856
|
+
});
|
|
857
|
+
function toAreaUnit(unit) {
|
|
858
|
+
return { unit: String(unit._id), name: unit.name };
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// src/models/hygiene-area.model.ts
|
|
862
|
+
var areaSchema = Joi3.object({
|
|
863
|
+
site: Joi3.string().hex().required(),
|
|
864
|
+
serviceType: Joi3.string().valid(...Object.values(AppServiceType2)).required(),
|
|
865
|
+
name: Joi3.string().required(),
|
|
866
|
+
type: Joi3.string().valid(...allowedTypes).required(),
|
|
867
|
+
set: Joi3.number().min(0).optional(),
|
|
868
|
+
units: Joi3.array().items(
|
|
869
|
+
areaUnitSchema.optional()
|
|
861
870
|
).min(1).unique("unit", { ignoreUndefined: true }).messages({
|
|
862
871
|
"array.unique": "Duplicate area units are not allowed"
|
|
863
872
|
})
|
|
@@ -1371,14 +1380,14 @@ import {
|
|
|
1371
1380
|
} from "@7365admin1/node-server-utils";
|
|
1372
1381
|
|
|
1373
1382
|
// src/models/hygiene-unit.model.ts
|
|
1374
|
-
import
|
|
1383
|
+
import Joi4 from "joi";
|
|
1375
1384
|
import { ObjectId as ObjectId4 } from "mongodb";
|
|
1376
1385
|
import { BadRequestError as BadRequestError5, logger as logger6 } from "@7365admin1/node-server-utils";
|
|
1377
1386
|
import { AppServiceType as AppServiceType3 } from "@7365admin1/core";
|
|
1378
|
-
var unitSchema =
|
|
1379
|
-
site:
|
|
1380
|
-
serviceType:
|
|
1381
|
-
name:
|
|
1387
|
+
var unitSchema = Joi4.object({
|
|
1388
|
+
site: Joi4.string().hex().required(),
|
|
1389
|
+
serviceType: Joi4.string().valid(...Object.values(AppServiceType3)).required(),
|
|
1390
|
+
name: Joi4.string().required()
|
|
1382
1391
|
});
|
|
1383
1392
|
function MUnit(value) {
|
|
1384
1393
|
const { error } = unitSchema.validate(value);
|
|
@@ -1713,10 +1722,7 @@ function useAreaService() {
|
|
|
1713
1722
|
}
|
|
1714
1723
|
}
|
|
1715
1724
|
if (foundUnit) {
|
|
1716
|
-
areaUnits.push(
|
|
1717
|
-
unit: foundUnit._id,
|
|
1718
|
-
name: foundUnit.name
|
|
1719
|
-
});
|
|
1725
|
+
areaUnits.push(toAreaUnit(foundUnit));
|
|
1720
1726
|
}
|
|
1721
1727
|
}
|
|
1722
1728
|
if (areaUnits.length > 0) {
|
|
@@ -1813,7 +1819,7 @@ function useAreaService() {
|
|
|
1813
1819
|
}
|
|
1814
1820
|
|
|
1815
1821
|
// src/controllers/hygiene-area.controller.ts
|
|
1816
|
-
import
|
|
1822
|
+
import Joi5 from "joi";
|
|
1817
1823
|
import { BadRequestError as BadRequestError8, logger as logger9 } from "@7365admin1/node-server-utils";
|
|
1818
1824
|
import { AppServiceType as AppServiceType4 } from "@7365admin1/core";
|
|
1819
1825
|
|
|
@@ -1874,13 +1880,13 @@ function useAreaController() {
|
|
|
1874
1880
|
}
|
|
1875
1881
|
async function getAreas(req, res, next) {
|
|
1876
1882
|
const query = { ...req.query, ...req.params };
|
|
1877
|
-
const validation =
|
|
1878
|
-
page:
|
|
1879
|
-
limit:
|
|
1880
|
-
search:
|
|
1881
|
-
type:
|
|
1882
|
-
site:
|
|
1883
|
-
serviceType:
|
|
1883
|
+
const validation = Joi5.object({
|
|
1884
|
+
page: Joi5.number().min(1).optional().allow("", null),
|
|
1885
|
+
limit: Joi5.number().min(1).optional().allow("", null),
|
|
1886
|
+
search: Joi5.string().optional().allow("", null),
|
|
1887
|
+
type: Joi5.string().valid("all", ...allowedTypes).optional().allow("", null),
|
|
1888
|
+
site: Joi5.string().hex().required(),
|
|
1889
|
+
serviceType: Joi5.string().valid(...Object.values(AppServiceType4)).required()
|
|
1884
1890
|
});
|
|
1885
1891
|
const { error } = validation.validate(query);
|
|
1886
1892
|
if (error) {
|
|
@@ -1911,7 +1917,7 @@ function useAreaController() {
|
|
|
1911
1917
|
}
|
|
1912
1918
|
}
|
|
1913
1919
|
async function getAreaById(req, res, next) {
|
|
1914
|
-
const validation =
|
|
1920
|
+
const validation = Joi5.string().hex().required();
|
|
1915
1921
|
const _id = req.params.id;
|
|
1916
1922
|
const { error, value } = validation.validate(_id);
|
|
1917
1923
|
if (error) {
|
|
@@ -1931,15 +1937,15 @@ function useAreaController() {
|
|
|
1931
1937
|
}
|
|
1932
1938
|
async function updateArea(req, res, next) {
|
|
1933
1939
|
const payload = { id: req.params.id, ...req.body };
|
|
1934
|
-
const schema =
|
|
1935
|
-
id:
|
|
1936
|
-
name:
|
|
1937
|
-
type:
|
|
1938
|
-
set:
|
|
1939
|
-
units:
|
|
1940
|
-
|
|
1941
|
-
unit:
|
|
1942
|
-
name:
|
|
1940
|
+
const schema = Joi5.object({
|
|
1941
|
+
id: Joi5.string().hex().required(),
|
|
1942
|
+
name: Joi5.string().optional().allow("", null),
|
|
1943
|
+
type: Joi5.string().optional().allow("", null, ...allowedTypes),
|
|
1944
|
+
set: Joi5.number().min(0).optional(),
|
|
1945
|
+
units: Joi5.array().items(
|
|
1946
|
+
Joi5.object({
|
|
1947
|
+
unit: Joi5.string().hex().required(),
|
|
1948
|
+
name: Joi5.string().required()
|
|
1943
1949
|
}).required()
|
|
1944
1950
|
).min(1).unique("unit", { ignoreUndefined: true }).optional().messages({
|
|
1945
1951
|
"array.unique": "Duplicate area units are not allowed"
|
|
@@ -1964,7 +1970,7 @@ function useAreaController() {
|
|
|
1964
1970
|
}
|
|
1965
1971
|
async function deleteArea(req, res, next) {
|
|
1966
1972
|
const id = req.params.id;
|
|
1967
|
-
const validation =
|
|
1973
|
+
const validation = Joi5.string().hex().required();
|
|
1968
1974
|
const { error, value } = validation.validate(id);
|
|
1969
1975
|
if (error) {
|
|
1970
1976
|
logger9.log({ level: "error", message: error.message });
|
|
@@ -1987,9 +1993,9 @@ function useAreaController() {
|
|
|
1987
1993
|
return;
|
|
1988
1994
|
}
|
|
1989
1995
|
const query = { ...req.query, ...req.params };
|
|
1990
|
-
const validation =
|
|
1991
|
-
site:
|
|
1992
|
-
serviceType:
|
|
1996
|
+
const validation = Joi5.object({
|
|
1997
|
+
site: Joi5.string().hex().required(),
|
|
1998
|
+
serviceType: Joi5.string().valid(...Object.values(AppServiceType4)).required()
|
|
1993
1999
|
});
|
|
1994
2000
|
const { error, value } = validation.validate(query);
|
|
1995
2001
|
if (error) {
|
|
@@ -2010,9 +2016,9 @@ function useAreaController() {
|
|
|
2010
2016
|
}
|
|
2011
2017
|
async function exportAreas(req, res, next) {
|
|
2012
2018
|
const query = { ...req.query, ...req.params };
|
|
2013
|
-
const validation =
|
|
2014
|
-
site:
|
|
2015
|
-
serviceType:
|
|
2019
|
+
const validation = Joi5.object({
|
|
2020
|
+
site: Joi5.string().hex().required(),
|
|
2021
|
+
serviceType: Joi5.string().valid(...Object.values(AppServiceType4)).required()
|
|
2016
2022
|
});
|
|
2017
2023
|
const { error, value } = validation.validate(query);
|
|
2018
2024
|
if (error) {
|
|
@@ -2299,7 +2305,7 @@ function useUnitService() {
|
|
|
2299
2305
|
}
|
|
2300
2306
|
|
|
2301
2307
|
// src/controllers/hygiene-unit.controller.ts
|
|
2302
|
-
import
|
|
2308
|
+
import Joi6 from "joi";
|
|
2303
2309
|
import { BadRequestError as BadRequestError10, logger as logger12 } from "@7365admin1/node-server-utils";
|
|
2304
2310
|
import { AppServiceType as AppServiceType5 } from "@7365admin1/core";
|
|
2305
2311
|
function useUnitController() {
|
|
@@ -2330,12 +2336,12 @@ function useUnitController() {
|
|
|
2330
2336
|
}
|
|
2331
2337
|
async function getUnits(req, res, next) {
|
|
2332
2338
|
const query = { ...req.query, ...req.params };
|
|
2333
|
-
const validation =
|
|
2334
|
-
page:
|
|
2335
|
-
limit:
|
|
2336
|
-
search:
|
|
2337
|
-
site:
|
|
2338
|
-
serviceType:
|
|
2339
|
+
const validation = Joi6.object({
|
|
2340
|
+
page: Joi6.number().min(1).optional().allow("", null),
|
|
2341
|
+
limit: Joi6.number().min(1).optional().allow("", null),
|
|
2342
|
+
search: Joi6.string().optional().allow("", null),
|
|
2343
|
+
site: Joi6.string().hex().required(),
|
|
2344
|
+
serviceType: Joi6.string().valid(...Object.values(AppServiceType5)).required()
|
|
2339
2345
|
});
|
|
2340
2346
|
const { error } = validation.validate(query);
|
|
2341
2347
|
if (error) {
|
|
@@ -2366,9 +2372,9 @@ function useUnitController() {
|
|
|
2366
2372
|
}
|
|
2367
2373
|
async function updateUnit(req, res, next) {
|
|
2368
2374
|
const payload = { id: req.params.id, ...req.body };
|
|
2369
|
-
const validation =
|
|
2370
|
-
id:
|
|
2371
|
-
name:
|
|
2375
|
+
const validation = Joi6.object({
|
|
2376
|
+
id: Joi6.string().hex().required(),
|
|
2377
|
+
name: Joi6.string().required()
|
|
2372
2378
|
});
|
|
2373
2379
|
const { error } = validation.validate(payload);
|
|
2374
2380
|
if (error) {
|
|
@@ -2389,8 +2395,8 @@ function useUnitController() {
|
|
|
2389
2395
|
}
|
|
2390
2396
|
async function deleteUnit(req, res, next) {
|
|
2391
2397
|
const id = req.params.id;
|
|
2392
|
-
const validation =
|
|
2393
|
-
id:
|
|
2398
|
+
const validation = Joi6.object({
|
|
2399
|
+
id: Joi6.string().hex().required()
|
|
2394
2400
|
});
|
|
2395
2401
|
const { error, value } = validation.validate({ id });
|
|
2396
2402
|
if (error) {
|
|
@@ -2414,9 +2420,9 @@ function useUnitController() {
|
|
|
2414
2420
|
return;
|
|
2415
2421
|
}
|
|
2416
2422
|
const query = { ...req.query, ...req.params };
|
|
2417
|
-
const validation =
|
|
2418
|
-
site:
|
|
2419
|
-
serviceType:
|
|
2423
|
+
const validation = Joi6.object({
|
|
2424
|
+
site: Joi6.string().hex().required(),
|
|
2425
|
+
serviceType: Joi6.string().valid(...Object.values(AppServiceType5)).required()
|
|
2420
2426
|
});
|
|
2421
2427
|
const { error, value } = validation.validate(query);
|
|
2422
2428
|
if (error) {
|
|
@@ -2437,9 +2443,9 @@ function useUnitController() {
|
|
|
2437
2443
|
}
|
|
2438
2444
|
async function exportUnits(req, res, next) {
|
|
2439
2445
|
const query = { ...req.query, ...req.params };
|
|
2440
|
-
const validation =
|
|
2441
|
-
site:
|
|
2442
|
-
serviceType:
|
|
2446
|
+
const validation = Joi6.object({
|
|
2447
|
+
site: Joi6.string().hex().required(),
|
|
2448
|
+
serviceType: Joi6.string().valid(...Object.values(AppServiceType5)).required()
|
|
2443
2449
|
});
|
|
2444
2450
|
const { error, value } = validation.validate(query);
|
|
2445
2451
|
if (error) {
|
|
@@ -2482,15 +2488,15 @@ function useUnitController() {
|
|
|
2482
2488
|
}
|
|
2483
2489
|
|
|
2484
2490
|
// src/models/hygiene-parent-checklist.model.ts
|
|
2485
|
-
import
|
|
2491
|
+
import Joi7 from "joi";
|
|
2486
2492
|
import { ObjectId as ObjectId6 } from "mongodb";
|
|
2487
2493
|
import { BadRequestError as BadRequestError11, logger as logger13 } from "@7365admin1/node-server-utils";
|
|
2488
2494
|
import { AppServiceType as AppServiceType6 } from "@7365admin1/core";
|
|
2489
|
-
var parentChecklistSchema =
|
|
2490
|
-
createdAt:
|
|
2491
|
-
site:
|
|
2492
|
-
serviceType:
|
|
2493
|
-
dateStr:
|
|
2495
|
+
var parentChecklistSchema = Joi7.object({
|
|
2496
|
+
createdAt: Joi7.alternatives().try(Joi7.date(), Joi7.string()).optional().allow("", null),
|
|
2497
|
+
site: Joi7.string().hex().required(),
|
|
2498
|
+
serviceType: Joi7.string().valid(...Object.values(AppServiceType6)).required(),
|
|
2499
|
+
dateStr: Joi7.string().optional().allow("", null)
|
|
2494
2500
|
});
|
|
2495
2501
|
function MParentChecklist(value) {
|
|
2496
2502
|
const { error } = parentChecklistSchema.validate(value);
|
|
@@ -3071,7 +3077,7 @@ function useParentChecklistRepo() {
|
|
|
3071
3077
|
}
|
|
3072
3078
|
|
|
3073
3079
|
// src/controllers/hygiene-parent-checklist.controller.ts
|
|
3074
|
-
import
|
|
3080
|
+
import Joi8 from "joi";
|
|
3075
3081
|
import { BadRequestError as BadRequestError13, logger as logger15 } from "@7365admin1/node-server-utils";
|
|
3076
3082
|
import { AppServiceType as AppServiceType8 } from "@7365admin1/core";
|
|
3077
3083
|
function useParentChecklistController() {
|
|
@@ -3081,10 +3087,10 @@ function useParentChecklistController() {
|
|
|
3081
3087
|
} = useParentChecklistRepo();
|
|
3082
3088
|
async function createParentChecklist(req, res, next) {
|
|
3083
3089
|
const payload = req.body;
|
|
3084
|
-
const validation =
|
|
3085
|
-
createdAt:
|
|
3086
|
-
site:
|
|
3087
|
-
serviceType:
|
|
3090
|
+
const validation = Joi8.object({
|
|
3091
|
+
createdAt: Joi8.alternatives().try(Joi8.date(), Joi8.string()).optional().allow("", null),
|
|
3092
|
+
site: Joi8.string().hex().required(),
|
|
3093
|
+
serviceType: Joi8.string().valid(...Object.values(AppServiceType8)).optional().allow("", null)
|
|
3088
3094
|
});
|
|
3089
3095
|
const { error } = validation.validate(payload);
|
|
3090
3096
|
if (error) {
|
|
@@ -3104,15 +3110,15 @@ function useParentChecklistController() {
|
|
|
3104
3110
|
}
|
|
3105
3111
|
async function getAllParentChecklist(req, res, next) {
|
|
3106
3112
|
const query = { ...req.query, ...req.params };
|
|
3107
|
-
const validation =
|
|
3108
|
-
page:
|
|
3109
|
-
limit:
|
|
3110
|
-
search:
|
|
3111
|
-
site:
|
|
3112
|
-
serviceType:
|
|
3113
|
-
startDate:
|
|
3114
|
-
endDate:
|
|
3115
|
-
status:
|
|
3113
|
+
const validation = Joi8.object({
|
|
3114
|
+
page: Joi8.number().min(1).optional().allow("", null),
|
|
3115
|
+
limit: Joi8.number().min(1).optional().allow("", null),
|
|
3116
|
+
search: Joi8.string().optional().allow("", null),
|
|
3117
|
+
site: Joi8.string().hex().required(),
|
|
3118
|
+
serviceType: Joi8.string().valid(...Object.values(AppServiceType8)).required(),
|
|
3119
|
+
startDate: Joi8.alternatives().try(Joi8.date(), Joi8.string()).optional().allow("", null),
|
|
3120
|
+
endDate: Joi8.alternatives().try(Joi8.date(), Joi8.string()).optional().allow("", null),
|
|
3121
|
+
status: Joi8.string().valid(...allowedStatus, "all").optional().allow("", null)
|
|
3116
3122
|
});
|
|
3117
3123
|
const { error } = validation.validate(query);
|
|
3118
3124
|
if (error) {
|
|
@@ -3154,28 +3160,28 @@ function useParentChecklistController() {
|
|
|
3154
3160
|
}
|
|
3155
3161
|
|
|
3156
3162
|
// src/models/hygiene-area-checklist.model.ts
|
|
3157
|
-
import
|
|
3163
|
+
import Joi9 from "joi";
|
|
3158
3164
|
import { ObjectId as ObjectId8 } from "mongodb";
|
|
3159
3165
|
import { BadRequestError as BadRequestError14, logger as logger16 } from "@7365admin1/node-server-utils";
|
|
3160
3166
|
import { AppServiceType as AppServiceType9 } from "@7365admin1/core";
|
|
3161
3167
|
var allowedChecklistStatus = ["open", "completed", "closed"];
|
|
3162
|
-
var areaChecklistSchema =
|
|
3163
|
-
schedule:
|
|
3164
|
-
serviceType:
|
|
3165
|
-
area:
|
|
3166
|
-
name:
|
|
3167
|
-
type:
|
|
3168
|
-
checklist:
|
|
3169
|
-
|
|
3170
|
-
set:
|
|
3171
|
-
units:
|
|
3172
|
-
|
|
3173
|
-
unit:
|
|
3174
|
-
name:
|
|
3168
|
+
var areaChecklistSchema = Joi9.object({
|
|
3169
|
+
schedule: Joi9.string().hex().required(),
|
|
3170
|
+
serviceType: Joi9.string().valid(...Object.values(AppServiceType9)).required(),
|
|
3171
|
+
area: Joi9.string().hex().required(),
|
|
3172
|
+
name: Joi9.string().required(),
|
|
3173
|
+
type: Joi9.string().valid(...allowedTypes).required(),
|
|
3174
|
+
checklist: Joi9.array().items(
|
|
3175
|
+
Joi9.object({
|
|
3176
|
+
set: Joi9.number().min(0).required(),
|
|
3177
|
+
units: Joi9.array().items(
|
|
3178
|
+
Joi9.object({
|
|
3179
|
+
unit: Joi9.string().hex().required(),
|
|
3180
|
+
name: Joi9.string().required()
|
|
3175
3181
|
}).required()
|
|
3176
3182
|
).min(1).required(),
|
|
3177
|
-
isScheduleTask:
|
|
3178
|
-
scheduleTaskId:
|
|
3183
|
+
isScheduleTask: Joi9.boolean().optional().default(false),
|
|
3184
|
+
scheduleTaskId: Joi9.string().hex().optional().allow(null)
|
|
3179
3185
|
}).required()
|
|
3180
3186
|
).optional().default([])
|
|
3181
3187
|
});
|
|
@@ -3253,6 +3259,39 @@ import {
|
|
|
3253
3259
|
useAtlas as useAtlas6,
|
|
3254
3260
|
useCache as useCache5
|
|
3255
3261
|
} from "@7365admin1/node-server-utils";
|
|
3262
|
+
|
|
3263
|
+
// src/utils/completion-photo.util.ts
|
|
3264
|
+
var COMPLETION_PHOTO_MESSAGE = "A photo is required to complete this task. Take or upload at least one photo before marking it complete.";
|
|
3265
|
+
function readCompletion(units, unitId) {
|
|
3266
|
+
if (units.length === 0)
|
|
3267
|
+
return { completesSet: false, hasEvidence: false };
|
|
3268
|
+
const others = units.filter((unit) => String(unit.unit) !== String(unitId));
|
|
3269
|
+
return {
|
|
3270
|
+
completesSet: others.every(
|
|
3271
|
+
(unit) => unit.approve === true || unit.reject === true
|
|
3272
|
+
),
|
|
3273
|
+
hasEvidence: others.some(
|
|
3274
|
+
(unit) => Array.isArray(unit.attachment) && unit.attachment.length > 0
|
|
3275
|
+
)
|
|
3276
|
+
};
|
|
3277
|
+
}
|
|
3278
|
+
function requiresCompletionPhoto({
|
|
3279
|
+
decision,
|
|
3280
|
+
attachment,
|
|
3281
|
+
completesSet,
|
|
3282
|
+
hasEvidence
|
|
3283
|
+
}) {
|
|
3284
|
+
if (decision !== "approve")
|
|
3285
|
+
return false;
|
|
3286
|
+
if (!completesSet)
|
|
3287
|
+
return false;
|
|
3288
|
+
if (hasEvidence)
|
|
3289
|
+
return false;
|
|
3290
|
+
const carriesEvidence = Array.isArray(attachment) && attachment.some((id) => typeof id === "string" && id.trim().length > 0);
|
|
3291
|
+
return !carriesEvidence;
|
|
3292
|
+
}
|
|
3293
|
+
|
|
3294
|
+
// src/repositories/hygiene-area-checklist.repository.ts
|
|
3256
3295
|
function useAreaChecklistRepo() {
|
|
3257
3296
|
const db = useAtlas6.getDb();
|
|
3258
3297
|
if (!db) {
|
|
@@ -3324,7 +3363,11 @@ function useAreaChecklistRepo() {
|
|
|
3324
3363
|
const parentChecklistId = new ObjectId9(value.schedule);
|
|
3325
3364
|
const areaId = new ObjectId9(value.area);
|
|
3326
3365
|
const existingChecklist = await collection.findOne(
|
|
3327
|
-
{
|
|
3366
|
+
{
|
|
3367
|
+
schedule: parentChecklistId,
|
|
3368
|
+
area: areaId,
|
|
3369
|
+
serviceType: value.serviceType
|
|
3370
|
+
},
|
|
3328
3371
|
{ session }
|
|
3329
3372
|
);
|
|
3330
3373
|
if (existingChecklist) {
|
|
@@ -4080,6 +4123,21 @@ function useAreaChecklistRepo() {
|
|
|
4080
4123
|
throw error;
|
|
4081
4124
|
}
|
|
4082
4125
|
}
|
|
4126
|
+
async function readSetCompletionState(_id, set, unitId) {
|
|
4127
|
+
try {
|
|
4128
|
+
_id = new ObjectId9(_id);
|
|
4129
|
+
} catch (error) {
|
|
4130
|
+
throw new BadRequestError15("Invalid area checklist ID format.");
|
|
4131
|
+
}
|
|
4132
|
+
const doc = await collection.findOne(
|
|
4133
|
+
{ _id, "checklist.set": set },
|
|
4134
|
+
{ projection: { checklist: 1 } }
|
|
4135
|
+
);
|
|
4136
|
+
const group = (doc?.checklist ?? []).find(
|
|
4137
|
+
(entry) => entry.set === set
|
|
4138
|
+
);
|
|
4139
|
+
return readCompletion(group?.units ?? [], unitId);
|
|
4140
|
+
}
|
|
4083
4141
|
async function updateAreaChecklist(_id, value, session) {
|
|
4084
4142
|
try {
|
|
4085
4143
|
_id = new ObjectId9(_id);
|
|
@@ -4364,6 +4422,7 @@ function useAreaChecklistRepo() {
|
|
|
4364
4422
|
updateAreaChecklist,
|
|
4365
4423
|
updateAreaChecklistStatus,
|
|
4366
4424
|
updateAreaChecklistUnits,
|
|
4425
|
+
readSetCompletionState,
|
|
4367
4426
|
getMaxSetNumberForArea,
|
|
4368
4427
|
closeExpiredAreaChecklists,
|
|
4369
4428
|
pushScheduleTaskSets,
|
|
@@ -4611,7 +4670,7 @@ function useAreaChecklistService() {
|
|
|
4611
4670
|
}
|
|
4612
4671
|
|
|
4613
4672
|
// src/controllers/hygiene-area-checklist.controller.ts
|
|
4614
|
-
import
|
|
4673
|
+
import Joi10 from "joi";
|
|
4615
4674
|
import {
|
|
4616
4675
|
BadRequestError as BadRequestError16,
|
|
4617
4676
|
InternalServerError as InternalServerError7,
|
|
@@ -4839,7 +4898,8 @@ function useAreaChecklistController() {
|
|
|
4839
4898
|
getAllAreaChecklist: _getAllAreaChecklist,
|
|
4840
4899
|
getAreaChecklistHistory: _getAreaChecklistHistory,
|
|
4841
4900
|
getAreaChecklistHistoryDetails: _getAreaChecklistHistoryDetails,
|
|
4842
|
-
getAreaChecklistUnits: _getAreaChecklistUnits
|
|
4901
|
+
getAreaChecklistUnits: _getAreaChecklistUnits,
|
|
4902
|
+
readSetCompletionState: _readSetCompletionState
|
|
4843
4903
|
} = useAreaChecklistRepo();
|
|
4844
4904
|
const {
|
|
4845
4905
|
createAreaChecklist: _createAreaChecklist,
|
|
@@ -4855,9 +4915,9 @@ function useAreaChecklistController() {
|
|
|
4855
4915
|
site: req.params.site,
|
|
4856
4916
|
schedule: req.params.schedule
|
|
4857
4917
|
};
|
|
4858
|
-
const validation =
|
|
4859
|
-
site:
|
|
4860
|
-
schedule:
|
|
4918
|
+
const validation = Joi10.object({
|
|
4919
|
+
site: Joi10.string().hex().required(),
|
|
4920
|
+
schedule: Joi10.string().hex().required()
|
|
4861
4921
|
});
|
|
4862
4922
|
const { error, value } = validation.validate(payload);
|
|
4863
4923
|
if (error) {
|
|
@@ -4877,14 +4937,14 @@ function useAreaChecklistController() {
|
|
|
4877
4937
|
}
|
|
4878
4938
|
async function getAllAreaChecklist(req, res, next) {
|
|
4879
4939
|
const query = { ...req.query, ...req.params };
|
|
4880
|
-
const validation =
|
|
4881
|
-
page:
|
|
4882
|
-
limit:
|
|
4883
|
-
search:
|
|
4884
|
-
type:
|
|
4885
|
-
status:
|
|
4886
|
-
schedule:
|
|
4887
|
-
serviceType:
|
|
4940
|
+
const validation = Joi10.object({
|
|
4941
|
+
page: Joi10.number().min(1).optional().allow("", null),
|
|
4942
|
+
limit: Joi10.number().min(1).optional().allow("", null),
|
|
4943
|
+
search: Joi10.string().optional().allow("", null),
|
|
4944
|
+
type: Joi10.string().valid(...allowedTypes, "all").optional().allow("", null),
|
|
4945
|
+
status: Joi10.string().valid(...allowedStatus, "all").optional().allow("", null),
|
|
4946
|
+
schedule: Joi10.string().hex().required(),
|
|
4947
|
+
serviceType: Joi10.string().valid(...Object.values(AppServiceType10)).required()
|
|
4888
4948
|
});
|
|
4889
4949
|
const { error } = validation.validate(query);
|
|
4890
4950
|
if (error) {
|
|
@@ -4919,14 +4979,14 @@ function useAreaChecklistController() {
|
|
|
4919
4979
|
}
|
|
4920
4980
|
async function getAreaChecklistHistory(req, res, next) {
|
|
4921
4981
|
const query = { ...req.query, ...req.params };
|
|
4922
|
-
const validation =
|
|
4923
|
-
page:
|
|
4924
|
-
limit:
|
|
4925
|
-
search:
|
|
4926
|
-
type:
|
|
4927
|
-
schedule:
|
|
4928
|
-
status:
|
|
4929
|
-
createdAt:
|
|
4982
|
+
const validation = Joi10.object({
|
|
4983
|
+
page: Joi10.number().min(1).optional().allow("", null),
|
|
4984
|
+
limit: Joi10.number().min(1).optional().allow("", null),
|
|
4985
|
+
search: Joi10.string().optional().allow("", null),
|
|
4986
|
+
type: Joi10.string().optional().allow("", ...allowedTypes),
|
|
4987
|
+
schedule: Joi10.string().hex().required(),
|
|
4988
|
+
status: Joi10.string().allow("", null, ...allowedStatus),
|
|
4989
|
+
createdAt: Joi10.alternatives().try(Joi10.date(), Joi10.string()).optional().allow("", null)
|
|
4930
4990
|
});
|
|
4931
4991
|
const { error } = validation.validate(query);
|
|
4932
4992
|
if (error) {
|
|
@@ -4960,7 +5020,7 @@ function useAreaChecklistController() {
|
|
|
4960
5020
|
}
|
|
4961
5021
|
}
|
|
4962
5022
|
async function getAreaChecklistHistoryDetails(req, res, next) {
|
|
4963
|
-
const validation =
|
|
5023
|
+
const validation = Joi10.string().hex().required();
|
|
4964
5024
|
const _id = req.params.id;
|
|
4965
5025
|
const { error, value } = validation.validate(_id);
|
|
4966
5026
|
if (error) {
|
|
@@ -4980,12 +5040,12 @@ function useAreaChecklistController() {
|
|
|
4980
5040
|
}
|
|
4981
5041
|
async function getAreaChecklistUnits(req, res, next) {
|
|
4982
5042
|
const query = { ...req.query, ...req.params };
|
|
4983
|
-
const validation =
|
|
4984
|
-
page:
|
|
4985
|
-
limit:
|
|
4986
|
-
search:
|
|
4987
|
-
serviceType:
|
|
4988
|
-
id:
|
|
5043
|
+
const validation = Joi10.object({
|
|
5044
|
+
page: Joi10.number().min(1).optional().allow("", null),
|
|
5045
|
+
limit: Joi10.number().min(1).optional().allow("", null),
|
|
5046
|
+
search: Joi10.string().optional().allow("", null),
|
|
5047
|
+
serviceType: Joi10.string().valid(...Object.values(AppServiceType10)).required(),
|
|
5048
|
+
id: Joi10.string().hex().required()
|
|
4989
5049
|
});
|
|
4990
5050
|
const { error } = validation.validate(query);
|
|
4991
5051
|
if (error) {
|
|
@@ -5035,46 +5095,21 @@ function useAreaChecklistController() {
|
|
|
5035
5095
|
...decisionValues,
|
|
5036
5096
|
completedBy
|
|
5037
5097
|
};
|
|
5038
|
-
const validation =
|
|
5039
|
-
id:
|
|
5040
|
-
set:
|
|
5041
|
-
unit:
|
|
5042
|
-
decision:
|
|
5043
|
-
approve:
|
|
5044
|
-
reject:
|
|
5045
|
-
remarks:
|
|
5098
|
+
const validation = Joi10.object({
|
|
5099
|
+
id: Joi10.string().hex().required(),
|
|
5100
|
+
set: Joi10.number().integer().min(1).required(),
|
|
5101
|
+
unit: Joi10.string().hex().required(),
|
|
5102
|
+
decision: Joi10.string().valid("approve", "reject").required(),
|
|
5103
|
+
approve: Joi10.boolean().optional(),
|
|
5104
|
+
reject: Joi10.boolean().optional(),
|
|
5105
|
+
remarks: Joi10.string().optional().allow("", null),
|
|
5046
5106
|
/*
|
|
5047
|
-
*
|
|
5048
|
-
*
|
|
5049
|
-
*
|
|
5050
|
-
* to take photo before completing the task ... all the services that has
|
|
5051
|
-
* this module must be the same process."*
|
|
5052
|
-
*
|
|
5053
|
-
* This endpoint is the one place every service and every client meets:
|
|
5054
|
-
* the five field apps (M&E, Cleaning, Landscape, Pest, Pool) all PATCH
|
|
5055
|
-
* `/api/hygiene-area-checklist/...` with a `serviceType`, and the web
|
|
5056
|
-
* checklist (`layer-common ManageChecklistMain`) posts here too. Requiring
|
|
5057
|
-
* it here is what makes "the same process" true rather than five client
|
|
5058
|
-
* guards that can drift apart — and a client guard alone is a suggestion.
|
|
5059
|
-
*
|
|
5060
|
-
* ONLY ON APPROVE. Completing a unit is the act the evidence is for.
|
|
5061
|
-
* A REJECT is the technician reporting a problem, and demanding a
|
|
5062
|
-
* photograph before somebody can report one would stop them reporting it.
|
|
5063
|
-
* `decision` carries which is which.
|
|
5064
|
-
*
|
|
5065
|
-
* At least one entry, and each must be a real id — an empty array or a
|
|
5066
|
-
* blank string would satisfy `.optional()` while carrying no evidence at
|
|
5067
|
-
* all, which is the shape a client sends when its uploader failed.
|
|
5107
|
+
* Shape only. WHETHER a photo is required depends on the set's current
|
|
5108
|
+
* state in the database, which Joi cannot see — see the check below.
|
|
5109
|
+
* Each entry must still be a real id: a blank string carries no evidence.
|
|
5068
5110
|
*/
|
|
5069
|
-
attachment:
|
|
5070
|
-
|
|
5071
|
-
then: Joi9.array().min(1).required().messages({
|
|
5072
|
-
"array.min": "A photo is required to complete this task. Take or upload at least one photo before marking it complete.",
|
|
5073
|
-
"any.required": "A photo is required to complete this task. Take or upload at least one photo before marking it complete."
|
|
5074
|
-
}),
|
|
5075
|
-
otherwise: Joi9.array().optional()
|
|
5076
|
-
}),
|
|
5077
|
-
completedBy: Joi9.string().hex().required()
|
|
5111
|
+
attachment: Joi10.array().items(Joi10.string().trim().min(1)).optional(),
|
|
5112
|
+
completedBy: Joi10.string().hex().required()
|
|
5078
5113
|
});
|
|
5079
5114
|
const { error } = validation.validate(payload);
|
|
5080
5115
|
if (error) {
|
|
@@ -5084,7 +5119,24 @@ function useAreaChecklistController() {
|
|
|
5084
5119
|
}
|
|
5085
5120
|
try {
|
|
5086
5121
|
const { id, set, unit, decision: decision2, ...value } = payload;
|
|
5087
|
-
|
|
5122
|
+
const setNumber = parseInt(set);
|
|
5123
|
+
if (decision2 === "approve") {
|
|
5124
|
+
const { completesSet, hasEvidence } = await _readSetCompletionState(
|
|
5125
|
+
id,
|
|
5126
|
+
setNumber,
|
|
5127
|
+
unit
|
|
5128
|
+
);
|
|
5129
|
+
if (requiresCompletionPhoto({
|
|
5130
|
+
decision: decision2,
|
|
5131
|
+
attachment: value.attachment,
|
|
5132
|
+
completesSet,
|
|
5133
|
+
hasEvidence
|
|
5134
|
+
})) {
|
|
5135
|
+
next(new BadRequestError16(COMPLETION_PHOTO_MESSAGE));
|
|
5136
|
+
return;
|
|
5137
|
+
}
|
|
5138
|
+
}
|
|
5139
|
+
await _updateAreaChecklistUnits(id, setNumber, unit, value);
|
|
5088
5140
|
res.json({ message: "Area checklist updated successfully." });
|
|
5089
5141
|
return;
|
|
5090
5142
|
} catch (error2) {
|
|
@@ -5094,7 +5146,7 @@ function useAreaChecklistController() {
|
|
|
5094
5146
|
}
|
|
5095
5147
|
}
|
|
5096
5148
|
async function downloadChecklistPdf(req, res, next) {
|
|
5097
|
-
const validation =
|
|
5149
|
+
const validation = Joi10.string().hex().required();
|
|
5098
5150
|
const schedule = req.params.schedule;
|
|
5099
5151
|
const { error, value } = validation.validate(schedule);
|
|
5100
5152
|
if (error) {
|
|
@@ -5140,16 +5192,16 @@ function useAreaChecklistController() {
|
|
|
5140
5192
|
}
|
|
5141
5193
|
|
|
5142
5194
|
// src/models/hygiene-supply.model.ts
|
|
5143
|
-
import
|
|
5195
|
+
import Joi11 from "joi";
|
|
5144
5196
|
import { ObjectId as ObjectId12 } from "mongodb";
|
|
5145
5197
|
import { BadRequestError as BadRequestError17, logger as logger21 } from "@7365admin1/node-server-utils";
|
|
5146
5198
|
import { AppServiceType as AppServiceType11 } from "@7365admin1/core";
|
|
5147
|
-
var supplySchema =
|
|
5148
|
-
site:
|
|
5149
|
-
serviceType:
|
|
5150
|
-
name:
|
|
5151
|
-
unitOfMeasurement:
|
|
5152
|
-
attachment:
|
|
5199
|
+
var supplySchema = Joi11.object({
|
|
5200
|
+
site: Joi11.string().hex().required(),
|
|
5201
|
+
serviceType: Joi11.string().valid(...Object.values(AppServiceType11)).required(),
|
|
5202
|
+
name: Joi11.string().required(),
|
|
5203
|
+
unitOfMeasurement: Joi11.string().required(),
|
|
5204
|
+
attachment: Joi11.string().allow(null, "").optional()
|
|
5153
5205
|
});
|
|
5154
5206
|
function MSupply(value) {
|
|
5155
5207
|
const { error } = supplySchema.validate(value);
|
|
@@ -5448,7 +5500,7 @@ function useSupplyRepository() {
|
|
|
5448
5500
|
}
|
|
5449
5501
|
|
|
5450
5502
|
// src/controllers/hygiene-supply.controller.ts
|
|
5451
|
-
import
|
|
5503
|
+
import Joi12 from "joi";
|
|
5452
5504
|
import { BadRequestError as BadRequestError19, logger as logger23 } from "@7365admin1/node-server-utils";
|
|
5453
5505
|
import { AppServiceType as AppServiceType12 } from "@7365admin1/core";
|
|
5454
5506
|
function useSupplyController() {
|
|
@@ -5479,12 +5531,12 @@ function useSupplyController() {
|
|
|
5479
5531
|
}
|
|
5480
5532
|
async function getSupplies(req, res, next) {
|
|
5481
5533
|
const query = { ...req.query, ...req.params };
|
|
5482
|
-
const validation =
|
|
5483
|
-
page:
|
|
5484
|
-
limit:
|
|
5485
|
-
search:
|
|
5486
|
-
site:
|
|
5487
|
-
serviceType:
|
|
5534
|
+
const validation = Joi12.object({
|
|
5535
|
+
page: Joi12.number().min(1).optional().allow("", null),
|
|
5536
|
+
limit: Joi12.number().min(1).optional().allow("", null),
|
|
5537
|
+
search: Joi12.string().optional().allow("", null),
|
|
5538
|
+
site: Joi12.string().hex().required(),
|
|
5539
|
+
serviceType: Joi12.string().valid(...Object.values(AppServiceType12)).required()
|
|
5488
5540
|
});
|
|
5489
5541
|
const { error } = validation.validate(query);
|
|
5490
5542
|
if (error) {
|
|
@@ -5514,7 +5566,7 @@ function useSupplyController() {
|
|
|
5514
5566
|
}
|
|
5515
5567
|
}
|
|
5516
5568
|
async function getSupplyById(req, res, next) {
|
|
5517
|
-
const validation =
|
|
5569
|
+
const validation = Joi12.string().hex().required();
|
|
5518
5570
|
const _id = req.params.id;
|
|
5519
5571
|
const { error, value } = validation.validate(_id);
|
|
5520
5572
|
if (error) {
|
|
@@ -5534,12 +5586,12 @@ function useSupplyController() {
|
|
|
5534
5586
|
}
|
|
5535
5587
|
async function updateSupply(req, res, next) {
|
|
5536
5588
|
const payload = { id: req.params.id, ...req.body };
|
|
5537
|
-
const validation =
|
|
5538
|
-
id:
|
|
5539
|
-
name:
|
|
5540
|
-
unitOfMeasurement:
|
|
5541
|
-
qty:
|
|
5542
|
-
attachment:
|
|
5589
|
+
const validation = Joi12.object({
|
|
5590
|
+
id: Joi12.string().hex().required(),
|
|
5591
|
+
name: Joi12.string().optional().allow("", null),
|
|
5592
|
+
unitOfMeasurement: Joi12.string().optional().allow("", null),
|
|
5593
|
+
qty: Joi12.number().min(0).optional().allow("", null),
|
|
5594
|
+
attachment: Joi12.string().optional().allow("", null)
|
|
5543
5595
|
});
|
|
5544
5596
|
const { error } = validation.validate(payload);
|
|
5545
5597
|
if (error) {
|
|
@@ -5560,7 +5612,7 @@ function useSupplyController() {
|
|
|
5560
5612
|
}
|
|
5561
5613
|
async function deleteSupply(req, res, next) {
|
|
5562
5614
|
const id = req.params.id;
|
|
5563
|
-
const validation =
|
|
5615
|
+
const validation = Joi12.string().hex().required();
|
|
5564
5616
|
const { error, value } = validation.validate(id);
|
|
5565
5617
|
if (error) {
|
|
5566
5618
|
logger23.log({ level: "error", message: error.message });
|
|
@@ -5587,18 +5639,18 @@ function useSupplyController() {
|
|
|
5587
5639
|
}
|
|
5588
5640
|
|
|
5589
5641
|
// src/models/hygiene-stock.model.ts
|
|
5590
|
-
import
|
|
5642
|
+
import Joi13 from "joi";
|
|
5591
5643
|
import { ObjectId as ObjectId14 } from "mongodb";
|
|
5592
5644
|
import { BadRequestError as BadRequestError20, logger as logger24 } from "@7365admin1/node-server-utils";
|
|
5593
5645
|
import { AppServiceType as AppServiceType13 } from "@7365admin1/core";
|
|
5594
|
-
var stockSchema =
|
|
5595
|
-
site:
|
|
5596
|
-
serviceType:
|
|
5597
|
-
supply:
|
|
5598
|
-
in:
|
|
5599
|
-
out:
|
|
5600
|
-
balance:
|
|
5601
|
-
remarks:
|
|
5646
|
+
var stockSchema = Joi13.object({
|
|
5647
|
+
site: Joi13.string().hex().required(),
|
|
5648
|
+
serviceType: Joi13.string().valid(...Object.values(AppServiceType13)).required(),
|
|
5649
|
+
supply: Joi13.string().hex().required(),
|
|
5650
|
+
in: Joi13.number().min(0).optional(),
|
|
5651
|
+
out: Joi13.number().min(0).optional(),
|
|
5652
|
+
balance: Joi13.number().min(0).required(),
|
|
5653
|
+
remarks: Joi13.string().optional().allow("", null)
|
|
5602
5654
|
});
|
|
5603
5655
|
function MStock(value) {
|
|
5604
5656
|
const { error } = stockSchema.validate(value);
|
|
@@ -5825,7 +5877,7 @@ function useStockService() {
|
|
|
5825
5877
|
}
|
|
5826
5878
|
|
|
5827
5879
|
// src/controllers/hygiene-stock.controller.ts
|
|
5828
|
-
import
|
|
5880
|
+
import Joi14 from "joi";
|
|
5829
5881
|
import { BadRequestError as BadRequestError23, logger as logger26 } from "@7365admin1/node-server-utils";
|
|
5830
5882
|
import { AppServiceType as AppServiceType14 } from "@7365admin1/core";
|
|
5831
5883
|
function useStockController() {
|
|
@@ -5833,12 +5885,12 @@ function useStockController() {
|
|
|
5833
5885
|
const { createStock: _createStock } = useStockService();
|
|
5834
5886
|
async function createStock(req, res, next) {
|
|
5835
5887
|
const payload = { ...req.body, ...req.params };
|
|
5836
|
-
const validation =
|
|
5837
|
-
site:
|
|
5838
|
-
serviceType:
|
|
5839
|
-
supply:
|
|
5840
|
-
qty:
|
|
5841
|
-
remarks:
|
|
5888
|
+
const validation = Joi14.object({
|
|
5889
|
+
site: Joi14.string().hex().required(),
|
|
5890
|
+
serviceType: Joi14.string().valid(...Object.values(AppServiceType14)).required(),
|
|
5891
|
+
supply: Joi14.string().hex().required(),
|
|
5892
|
+
qty: Joi14.number().min(0).required(),
|
|
5893
|
+
remarks: Joi14.string().optional().allow("", null)
|
|
5842
5894
|
});
|
|
5843
5895
|
const { error } = validation.validate(payload);
|
|
5844
5896
|
if (error) {
|
|
@@ -5858,13 +5910,13 @@ function useStockController() {
|
|
|
5858
5910
|
}
|
|
5859
5911
|
async function getStocksBySupplyId(req, res, next) {
|
|
5860
5912
|
const query = { ...req.query, ...req.params };
|
|
5861
|
-
const validation =
|
|
5862
|
-
page:
|
|
5863
|
-
limit:
|
|
5864
|
-
search:
|
|
5865
|
-
site:
|
|
5866
|
-
serviceType:
|
|
5867
|
-
supply:
|
|
5913
|
+
const validation = Joi14.object({
|
|
5914
|
+
page: Joi14.number().min(1).optional().allow("", null),
|
|
5915
|
+
limit: Joi14.number().min(1).optional().allow("", null),
|
|
5916
|
+
search: Joi14.string().optional().allow("", null),
|
|
5917
|
+
site: Joi14.string().hex().required(),
|
|
5918
|
+
serviceType: Joi14.string().valid(...Object.values(AppServiceType14)).required(),
|
|
5919
|
+
supply: Joi14.string().hex().required()
|
|
5868
5920
|
});
|
|
5869
5921
|
const { error } = validation.validate(query);
|
|
5870
5922
|
if (error) {
|
|
@@ -5926,21 +5978,21 @@ async function applyCheckOutDecision(decision, decide, returnStock) {
|
|
|
5926
5978
|
}
|
|
5927
5979
|
|
|
5928
5980
|
// src/models/hygiene-checkout-item.model.ts
|
|
5929
|
-
import
|
|
5981
|
+
import Joi15 from "joi";
|
|
5930
5982
|
import { ObjectId as ObjectId16 } from "mongodb";
|
|
5931
5983
|
import { BadRequestError as BadRequestError24, logger as logger27 } from "@7365admin1/node-server-utils";
|
|
5932
5984
|
import { AppServiceType as AppServiceType15 } from "@7365admin1/core";
|
|
5933
5985
|
var allowedCheckOutItemStatus = ["pending", "completed"];
|
|
5934
|
-
var checkOutItemSchema =
|
|
5935
|
-
site:
|
|
5936
|
-
serviceType:
|
|
5937
|
-
supply:
|
|
5938
|
-
supplyName:
|
|
5939
|
-
supplyQty:
|
|
5940
|
-
qty:
|
|
5941
|
-
attachment:
|
|
5942
|
-
createdBy:
|
|
5943
|
-
createdByName:
|
|
5986
|
+
var checkOutItemSchema = Joi15.object({
|
|
5987
|
+
site: Joi15.string().hex().required(),
|
|
5988
|
+
serviceType: Joi15.string().valid(...Object.values(AppServiceType15)).required(),
|
|
5989
|
+
supply: Joi15.string().hex().required(),
|
|
5990
|
+
supplyName: Joi15.string().required(),
|
|
5991
|
+
supplyQty: Joi15.number().min(0).required(),
|
|
5992
|
+
qty: Joi15.number().min(0).required(),
|
|
5993
|
+
attachment: Joi15.array().items(Joi15.string()).optional().allow(null),
|
|
5994
|
+
createdBy: Joi15.string().hex().required(),
|
|
5995
|
+
createdByName: Joi15.string().required()
|
|
5944
5996
|
});
|
|
5945
5997
|
function MCheckOutItem(value) {
|
|
5946
5998
|
const { error } = checkOutItemSchema.validate(value);
|
|
@@ -6429,7 +6481,7 @@ function useCheckOutItemService() {
|
|
|
6429
6481
|
}
|
|
6430
6482
|
|
|
6431
6483
|
// src/controllers/hygiene-checkout-item.controller.ts
|
|
6432
|
-
import
|
|
6484
|
+
import Joi16 from "joi";
|
|
6433
6485
|
import { BadRequestError as BadRequestError27, logger as logger29 } from "@7365admin1/node-server-utils";
|
|
6434
6486
|
import { AppServiceType as AppServiceType16 } from "@7365admin1/core";
|
|
6435
6487
|
function useCheckOutItemController() {
|
|
@@ -6453,13 +6505,13 @@ function useCheckOutItemController() {
|
|
|
6453
6505
|
...req.params,
|
|
6454
6506
|
createdBy
|
|
6455
6507
|
};
|
|
6456
|
-
const validation =
|
|
6457
|
-
site:
|
|
6458
|
-
serviceType:
|
|
6459
|
-
supply:
|
|
6460
|
-
qty:
|
|
6461
|
-
attachment:
|
|
6462
|
-
createdBy:
|
|
6508
|
+
const validation = Joi16.object({
|
|
6509
|
+
site: Joi16.string().hex().required(),
|
|
6510
|
+
serviceType: Joi16.string().valid(...Object.values(AppServiceType16)).required(),
|
|
6511
|
+
supply: Joi16.string().hex().required(),
|
|
6512
|
+
qty: Joi16.number().min(0).required(),
|
|
6513
|
+
attachment: Joi16.array().items(Joi16.string()).optional().allow(null),
|
|
6514
|
+
createdBy: Joi16.string().hex().required()
|
|
6463
6515
|
});
|
|
6464
6516
|
const { error } = validation.validate(payload);
|
|
6465
6517
|
if (error) {
|
|
@@ -6488,15 +6540,15 @@ function useCheckOutItemController() {
|
|
|
6488
6540
|
...req.params,
|
|
6489
6541
|
createdBy
|
|
6490
6542
|
};
|
|
6491
|
-
const validation =
|
|
6492
|
-
site:
|
|
6493
|
-
serviceType:
|
|
6494
|
-
createdBy:
|
|
6495
|
-
items:
|
|
6496
|
-
|
|
6497
|
-
supply:
|
|
6498
|
-
qty:
|
|
6499
|
-
attachment:
|
|
6543
|
+
const validation = Joi16.object({
|
|
6544
|
+
site: Joi16.string().hex().required(),
|
|
6545
|
+
serviceType: Joi16.string().valid(...Object.values(AppServiceType16)).required(),
|
|
6546
|
+
createdBy: Joi16.string().hex().required(),
|
|
6547
|
+
items: Joi16.array().items(
|
|
6548
|
+
Joi16.object({
|
|
6549
|
+
supply: Joi16.string().hex().required(),
|
|
6550
|
+
qty: Joi16.number().min(0).required(),
|
|
6551
|
+
attachment: Joi16.array().items(Joi16.string()).optional().allow(null)
|
|
6500
6552
|
})
|
|
6501
6553
|
).min(1).required()
|
|
6502
6554
|
});
|
|
@@ -6518,12 +6570,12 @@ function useCheckOutItemController() {
|
|
|
6518
6570
|
}
|
|
6519
6571
|
async function getCheckOutItems(req, res, next) {
|
|
6520
6572
|
const query = { ...req.query, ...req.params };
|
|
6521
|
-
const validation =
|
|
6522
|
-
page:
|
|
6523
|
-
limit:
|
|
6524
|
-
search:
|
|
6525
|
-
site:
|
|
6526
|
-
serviceType:
|
|
6573
|
+
const validation = Joi16.object({
|
|
6574
|
+
page: Joi16.number().min(1).optional().allow("", null),
|
|
6575
|
+
limit: Joi16.number().min(1).optional().allow("", null),
|
|
6576
|
+
search: Joi16.string().optional().allow("", null),
|
|
6577
|
+
site: Joi16.string().hex().required(),
|
|
6578
|
+
serviceType: Joi16.string().valid(...Object.values(AppServiceType16)).required()
|
|
6527
6579
|
});
|
|
6528
6580
|
const { error } = validation.validate(query);
|
|
6529
6581
|
if (error) {
|
|
@@ -6553,7 +6605,7 @@ function useCheckOutItemController() {
|
|
|
6553
6605
|
}
|
|
6554
6606
|
}
|
|
6555
6607
|
async function getCheckOutItemById(req, res, next) {
|
|
6556
|
-
const validation =
|
|
6608
|
+
const validation = Joi16.string().hex().required();
|
|
6557
6609
|
const _id = req.params.id;
|
|
6558
6610
|
const { error, value } = validation.validate(_id);
|
|
6559
6611
|
if (error) {
|
|
@@ -6592,13 +6644,13 @@ function useCheckOutItemController() {
|
|
|
6592
6644
|
...decisionValues,
|
|
6593
6645
|
completedBy
|
|
6594
6646
|
};
|
|
6595
|
-
const validation =
|
|
6596
|
-
id:
|
|
6597
|
-
decision:
|
|
6598
|
-
approve:
|
|
6599
|
-
reject:
|
|
6600
|
-
remarks:
|
|
6601
|
-
completedBy:
|
|
6647
|
+
const validation = Joi16.object({
|
|
6648
|
+
id: Joi16.string().hex().required(),
|
|
6649
|
+
decision: Joi16.string().valid("approve", "disapprove").required(),
|
|
6650
|
+
approve: Joi16.boolean().required(),
|
|
6651
|
+
reject: Joi16.boolean().required(),
|
|
6652
|
+
remarks: Joi16.string().optional().allow("", null),
|
|
6653
|
+
completedBy: Joi16.string().hex().required()
|
|
6602
6654
|
});
|
|
6603
6655
|
const { error } = validation.validate(payload);
|
|
6604
6656
|
if (error) {
|
|
@@ -6631,21 +6683,21 @@ function useCheckOutItemController() {
|
|
|
6631
6683
|
// src/models/hygiene-schedule-task.model.ts
|
|
6632
6684
|
import { BadRequestError as BadRequestError28, logger as logger30 } from "@7365admin1/node-server-utils";
|
|
6633
6685
|
import { AppServiceType as AppServiceType17 } from "@7365admin1/core";
|
|
6634
|
-
import
|
|
6686
|
+
import Joi17 from "joi";
|
|
6635
6687
|
import { ObjectId as ObjectId18 } from "mongodb";
|
|
6636
|
-
var scheduleTaskSchema =
|
|
6637
|
-
site:
|
|
6638
|
-
serviceType:
|
|
6639
|
-
title:
|
|
6640
|
-
time:
|
|
6641
|
-
dates:
|
|
6642
|
-
|
|
6688
|
+
var scheduleTaskSchema = Joi17.object({
|
|
6689
|
+
site: Joi17.string().hex().required(),
|
|
6690
|
+
serviceType: Joi17.string().valid(...Object.values(AppServiceType17)).required(),
|
|
6691
|
+
title: Joi17.string().required(),
|
|
6692
|
+
time: Joi17.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).required(),
|
|
6693
|
+
dates: Joi17.array().min(1).items(
|
|
6694
|
+
Joi17.string().pattern(/^\d{4}-\d{2}-\d{2}$/).required()
|
|
6643
6695
|
).required(),
|
|
6644
|
-
description:
|
|
6645
|
-
areas:
|
|
6646
|
-
|
|
6647
|
-
name:
|
|
6648
|
-
value:
|
|
6696
|
+
description: Joi17.string().optional().allow("", null),
|
|
6697
|
+
areas: Joi17.array().min(1).items(
|
|
6698
|
+
Joi17.object({
|
|
6699
|
+
name: Joi17.string().required(),
|
|
6700
|
+
value: Joi17.any().required()
|
|
6649
6701
|
})
|
|
6650
6702
|
).required()
|
|
6651
6703
|
});
|
|
@@ -7249,7 +7301,7 @@ function useScheduleTaskService() {
|
|
|
7249
7301
|
}
|
|
7250
7302
|
|
|
7251
7303
|
// src/controllers/hygiene-schedule-task.controller.ts
|
|
7252
|
-
import
|
|
7304
|
+
import Joi18 from "joi";
|
|
7253
7305
|
import { BadRequestError as BadRequestError30, logger as logger33 } from "@7365admin1/node-server-utils";
|
|
7254
7306
|
import { AppServiceType as AppServiceType18 } from "@7365admin1/core";
|
|
7255
7307
|
function useScheduleTaskController() {
|
|
@@ -7280,12 +7332,12 @@ function useScheduleTaskController() {
|
|
|
7280
7332
|
}
|
|
7281
7333
|
async function getScheduleTasks(req, res, next) {
|
|
7282
7334
|
const query = { ...req.query, ...req.params };
|
|
7283
|
-
const validation =
|
|
7284
|
-
page:
|
|
7285
|
-
limit:
|
|
7286
|
-
search:
|
|
7287
|
-
site:
|
|
7288
|
-
serviceType:
|
|
7335
|
+
const validation = Joi18.object({
|
|
7336
|
+
page: Joi18.number().min(1).optional().allow("", null),
|
|
7337
|
+
limit: Joi18.number().min(1).optional().allow("", null),
|
|
7338
|
+
search: Joi18.string().optional().allow("", null),
|
|
7339
|
+
site: Joi18.string().hex().required(),
|
|
7340
|
+
serviceType: Joi18.string().valid(...Object.values(AppServiceType18)).required()
|
|
7289
7341
|
});
|
|
7290
7342
|
const { error } = validation.validate(query);
|
|
7291
7343
|
if (error) {
|
|
@@ -7315,7 +7367,7 @@ function useScheduleTaskController() {
|
|
|
7315
7367
|
}
|
|
7316
7368
|
}
|
|
7317
7369
|
async function getScheduleTaskById(req, res, next) {
|
|
7318
|
-
const validation =
|
|
7370
|
+
const validation = Joi18.string().hex().required();
|
|
7319
7371
|
const _id = req.params.id;
|
|
7320
7372
|
const { error, value } = validation.validate(_id);
|
|
7321
7373
|
if (error) {
|
|
@@ -7335,18 +7387,18 @@ function useScheduleTaskController() {
|
|
|
7335
7387
|
}
|
|
7336
7388
|
async function updateScheduleTask(req, res, next) {
|
|
7337
7389
|
const payload = { id: req.params.id, ...req.body };
|
|
7338
|
-
const validation =
|
|
7339
|
-
id:
|
|
7340
|
-
title:
|
|
7341
|
-
time:
|
|
7342
|
-
dates:
|
|
7343
|
-
|
|
7390
|
+
const validation = Joi18.object({
|
|
7391
|
+
id: Joi18.string().hex().required(),
|
|
7392
|
+
title: Joi18.string().optional().allow("", null),
|
|
7393
|
+
time: Joi18.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).optional().allow("", null),
|
|
7394
|
+
dates: Joi18.array().min(1).items(
|
|
7395
|
+
Joi18.string().pattern(/^\d{4}-\d{2}-\d{2}$/).required()
|
|
7344
7396
|
).optional(),
|
|
7345
|
-
description:
|
|
7346
|
-
areas:
|
|
7347
|
-
|
|
7348
|
-
name:
|
|
7349
|
-
value:
|
|
7397
|
+
description: Joi18.string().optional().allow("", null),
|
|
7398
|
+
areas: Joi18.array().min(1).items(
|
|
7399
|
+
Joi18.object({
|
|
7400
|
+
name: Joi18.string().required(),
|
|
7401
|
+
value: Joi18.any().required()
|
|
7350
7402
|
})
|
|
7351
7403
|
).optional()
|
|
7352
7404
|
});
|
|
@@ -7368,7 +7420,7 @@ function useScheduleTaskController() {
|
|
|
7368
7420
|
}
|
|
7369
7421
|
}
|
|
7370
7422
|
async function deleteScheduleTask(req, res, next) {
|
|
7371
|
-
const validation =
|
|
7423
|
+
const validation = Joi18.string().hex().required();
|
|
7372
7424
|
const _id = req.params.id;
|
|
7373
7425
|
const { error, value } = validation.validate(_id);
|
|
7374
7426
|
if (error) {
|
|
@@ -7612,17 +7664,17 @@ function useQRService() {
|
|
|
7612
7664
|
}
|
|
7613
7665
|
|
|
7614
7666
|
// src/controllers/hygiene-qr.controller.ts
|
|
7615
|
-
import
|
|
7667
|
+
import Joi19 from "joi";
|
|
7616
7668
|
import { BadRequestError as BadRequestError31, logger as logger35 } from "@7365admin1/node-server-utils";
|
|
7617
7669
|
function useQRController() {
|
|
7618
7670
|
const { generateQRImage: _generateQRImage, generateQRPDF: _generateQRPDF } = useQRService();
|
|
7619
7671
|
async function generateQR(req, res, next) {
|
|
7620
|
-
const validation =
|
|
7621
|
-
url:
|
|
7622
|
-
filename:
|
|
7623
|
-
title:
|
|
7624
|
-
subtitle:
|
|
7625
|
-
download:
|
|
7672
|
+
const validation = Joi19.object({
|
|
7673
|
+
url: Joi19.string().uri().required(),
|
|
7674
|
+
filename: Joi19.string().optional().allow("", null),
|
|
7675
|
+
title: Joi19.string().optional().allow("", null),
|
|
7676
|
+
subtitle: Joi19.string().optional().allow("", null),
|
|
7677
|
+
download: Joi19.boolean().optional().default(false)
|
|
7626
7678
|
});
|
|
7627
7679
|
const query = { ...req.query };
|
|
7628
7680
|
const { error, value } = validation.validate(query);
|