@7365admin1/module-hygiene 4.7.0 → 4.8.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 +1 -0
- package/dist/index.js +568 -283
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +502 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -3096,6 +3096,38 @@ function useAreaChecklistRepo() {
|
|
|
3096
3096
|
preserveNullAndEmptyArrays: false
|
|
3097
3097
|
}
|
|
3098
3098
|
},
|
|
3099
|
+
{
|
|
3100
|
+
$addFields: {
|
|
3101
|
+
isCompleted: { $ne: ["$checklist.units.completedBy", ""] }
|
|
3102
|
+
}
|
|
3103
|
+
},
|
|
3104
|
+
{
|
|
3105
|
+
$lookup: {
|
|
3106
|
+
from: "users",
|
|
3107
|
+
let: { completedById: "$checklist.units.completedBy" },
|
|
3108
|
+
pipeline: [
|
|
3109
|
+
{
|
|
3110
|
+
$match: {
|
|
3111
|
+
$expr: {
|
|
3112
|
+
$and: [
|
|
3113
|
+
{ $ne: ["$$completedById", ""] },
|
|
3114
|
+
{ $eq: ["$_id", "$$completedById"] }
|
|
3115
|
+
]
|
|
3116
|
+
}
|
|
3117
|
+
}
|
|
3118
|
+
},
|
|
3119
|
+
{ $project: { name: 1 } }
|
|
3120
|
+
],
|
|
3121
|
+
as: "completedBy"
|
|
3122
|
+
}
|
|
3123
|
+
},
|
|
3124
|
+
{
|
|
3125
|
+
$unwind: {
|
|
3126
|
+
path: "$completedBy",
|
|
3127
|
+
preserveNullAndEmptyArrays: true
|
|
3128
|
+
}
|
|
3129
|
+
},
|
|
3130
|
+
{ $sort: { set: 1, isCompleted: -1, "checklist.units.timestamp": 1 } },
|
|
3099
3131
|
{
|
|
3100
3132
|
$project: {
|
|
3101
3133
|
_id: 0,
|
|
@@ -3120,15 +3152,16 @@ function useAreaChecklistRepo() {
|
|
|
3120
3152
|
],
|
|
3121
3153
|
default: "$checklist.units.status"
|
|
3122
3154
|
}
|
|
3123
|
-
}
|
|
3155
|
+
},
|
|
3156
|
+
completedByName: "$completedBy.name"
|
|
3124
3157
|
}
|
|
3125
3158
|
},
|
|
3126
|
-
{ $sort: { set: 1, name: 1 } },
|
|
3127
3159
|
{
|
|
3128
3160
|
$group: {
|
|
3129
3161
|
_id: "$set",
|
|
3130
3162
|
remarks: { $first: "$remarks" },
|
|
3131
3163
|
attachment: { $first: "$attachment" },
|
|
3164
|
+
completedByName: { $first: "$completedByName" },
|
|
3132
3165
|
units: {
|
|
3133
3166
|
$push: {
|
|
3134
3167
|
unit: "$unit",
|
|
@@ -3136,7 +3169,8 @@ function useAreaChecklistRepo() {
|
|
|
3136
3169
|
approve: "$approve",
|
|
3137
3170
|
reject: "$reject",
|
|
3138
3171
|
status: "$status",
|
|
3139
|
-
remarks: "$remarks"
|
|
3172
|
+
remarks: "$remarks",
|
|
3173
|
+
completedByName: "$completedByName"
|
|
3140
3174
|
}
|
|
3141
3175
|
}
|
|
3142
3176
|
}
|
|
@@ -3147,6 +3181,7 @@ function useAreaChecklistRepo() {
|
|
|
3147
3181
|
set: "$_id",
|
|
3148
3182
|
remarks: "$remarks",
|
|
3149
3183
|
attachment: "$attachment",
|
|
3184
|
+
completedByName: 1,
|
|
3150
3185
|
units: 1
|
|
3151
3186
|
}
|
|
3152
3187
|
},
|
|
@@ -3556,7 +3591,223 @@ function useAreaChecklistService() {
|
|
|
3556
3591
|
|
|
3557
3592
|
// src/controllers/hygiene-area-checklist.controller.ts
|
|
3558
3593
|
import Joi9 from "joi";
|
|
3559
|
-
import { BadRequestError as BadRequestError16, logger as
|
|
3594
|
+
import { BadRequestError as BadRequestError16, InternalServerError as InternalServerError7, logger as logger20 } from "@7365admin1/node-server-utils";
|
|
3595
|
+
|
|
3596
|
+
// src/services/hygiene-checklist-pdf.service.ts
|
|
3597
|
+
import { launch } from "puppeteer";
|
|
3598
|
+
import { InternalServerError as InternalServerError6, useAtlas as useAtlas8 } from "@7365admin1/node-server-utils";
|
|
3599
|
+
import { ObjectId as ObjectId10 } from "mongodb";
|
|
3600
|
+
function escapeHtml(text) {
|
|
3601
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
3602
|
+
}
|
|
3603
|
+
function buildChecklistHtml(areaChecklists) {
|
|
3604
|
+
const areaSections = areaChecklists.map((area) => {
|
|
3605
|
+
const sortedChecklist = [...area.checklist || []].sort(
|
|
3606
|
+
(a, b) => a.set - b.set
|
|
3607
|
+
);
|
|
3608
|
+
const setRows = sortedChecklist.map((setItem) => {
|
|
3609
|
+
const unitRows = (setItem.units || []).map(
|
|
3610
|
+
(unit) => `
|
|
3611
|
+
<tr>
|
|
3612
|
+
<td class="unit-name">${escapeHtml(unit.name || "")}</td>
|
|
3613
|
+
<td class="icon-cell">${unit.reject ? '<span class="reject-icon">✗</span>' : ""}</td>
|
|
3614
|
+
<td class="icon-cell">${unit.approve ? '<span class="approve-icon">✓</span>' : ""}</td>
|
|
3615
|
+
</tr>`
|
|
3616
|
+
).join("");
|
|
3617
|
+
return `
|
|
3618
|
+
<tr class="set-header-row">
|
|
3619
|
+
<td colspan="3">Set ${setItem.set}</td>
|
|
3620
|
+
</tr>
|
|
3621
|
+
${unitRows}`;
|
|
3622
|
+
}).join("");
|
|
3623
|
+
return `
|
|
3624
|
+
<div class="area-section">
|
|
3625
|
+
<div class="area-header">
|
|
3626
|
+
<span class="area-name">${escapeHtml(area.name || "")}</span>
|
|
3627
|
+
<span class="area-type">${escapeHtml(area.type || "")}</span>
|
|
3628
|
+
</div>
|
|
3629
|
+
<table class="checklist-table">
|
|
3630
|
+
<thead>
|
|
3631
|
+
<tr>
|
|
3632
|
+
<th class="col-unit">Unit</th>
|
|
3633
|
+
<th class="col-icon">✗</th>
|
|
3634
|
+
<th class="col-icon">✓</th>
|
|
3635
|
+
</tr>
|
|
3636
|
+
</thead>
|
|
3637
|
+
<tbody>
|
|
3638
|
+
${setRows}
|
|
3639
|
+
</tbody>
|
|
3640
|
+
</table>
|
|
3641
|
+
</div>`;
|
|
3642
|
+
}).join("");
|
|
3643
|
+
return `<!DOCTYPE html>
|
|
3644
|
+
<html lang="en">
|
|
3645
|
+
<head>
|
|
3646
|
+
<meta charset="UTF-8">
|
|
3647
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3648
|
+
<title>Checklist</title>
|
|
3649
|
+
<style>
|
|
3650
|
+
* {
|
|
3651
|
+
margin: 0;
|
|
3652
|
+
padding: 0;
|
|
3653
|
+
box-sizing: border-box;
|
|
3654
|
+
}
|
|
3655
|
+
body {
|
|
3656
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
3657
|
+
background: #ffffff;
|
|
3658
|
+
padding: 30px 35px;
|
|
3659
|
+
color: #1a1a1a;
|
|
3660
|
+
font-size: 13px;
|
|
3661
|
+
}
|
|
3662
|
+
.page-header {
|
|
3663
|
+
display: flex;
|
|
3664
|
+
align-items: center;
|
|
3665
|
+
justify-content: flex-start;
|
|
3666
|
+
background: #1a3a6b;
|
|
3667
|
+
margin-bottom: 24px;
|
|
3668
|
+
padding: 12px 16px;
|
|
3669
|
+
border-radius: 4px;
|
|
3670
|
+
}
|
|
3671
|
+
.page-logo {
|
|
3672
|
+
height: 40px;
|
|
3673
|
+
width: auto;
|
|
3674
|
+
object-fit: contain;
|
|
3675
|
+
}
|
|
3676
|
+
.area-section {
|
|
3677
|
+
margin-bottom: 22px;
|
|
3678
|
+
border: 1px solid #dce1e7;
|
|
3679
|
+
border-radius: 4px;
|
|
3680
|
+
overflow: hidden;
|
|
3681
|
+
page-break-inside: avoid;
|
|
3682
|
+
}
|
|
3683
|
+
.area-header {
|
|
3684
|
+
display: flex;
|
|
3685
|
+
align-items: center;
|
|
3686
|
+
justify-content: space-between;
|
|
3687
|
+
background: #2c3e50;
|
|
3688
|
+
color: #ffffff;
|
|
3689
|
+
padding: 9px 12px;
|
|
3690
|
+
}
|
|
3691
|
+
.area-name {
|
|
3692
|
+
font-size: 14px;
|
|
3693
|
+
font-weight: 600;
|
|
3694
|
+
}
|
|
3695
|
+
.area-type {
|
|
3696
|
+
font-size: 11px;
|
|
3697
|
+
text-transform: capitalize;
|
|
3698
|
+
background: rgba(255,255,255,0.2);
|
|
3699
|
+
padding: 2px 8px;
|
|
3700
|
+
border-radius: 10px;
|
|
3701
|
+
}
|
|
3702
|
+
.checklist-table {
|
|
3703
|
+
width: 100%;
|
|
3704
|
+
border-collapse: collapse;
|
|
3705
|
+
}
|
|
3706
|
+
.checklist-table thead tr th {
|
|
3707
|
+
background: #34495e;
|
|
3708
|
+
color: #ffffff;
|
|
3709
|
+
padding: 7px 10px;
|
|
3710
|
+
text-align: left;
|
|
3711
|
+
font-size: 12px;
|
|
3712
|
+
font-weight: 600;
|
|
3713
|
+
letter-spacing: 0.3px;
|
|
3714
|
+
}
|
|
3715
|
+
.checklist-table thead tr th.col-icon {
|
|
3716
|
+
text-align: center;
|
|
3717
|
+
width: 52px;
|
|
3718
|
+
}
|
|
3719
|
+
.checklist-table thead tr th.col-unit {
|
|
3720
|
+
width: auto;
|
|
3721
|
+
}
|
|
3722
|
+
.set-header-row td {
|
|
3723
|
+
background: #ecf0f1;
|
|
3724
|
+
color: #555;
|
|
3725
|
+
font-weight: 700;
|
|
3726
|
+
font-size: 12px;
|
|
3727
|
+
padding: 5px 10px;
|
|
3728
|
+
border-bottom: 1px solid #dce1e7;
|
|
3729
|
+
text-transform: uppercase;
|
|
3730
|
+
letter-spacing: 0.4px;
|
|
3731
|
+
}
|
|
3732
|
+
.checklist-table tbody tr td {
|
|
3733
|
+
padding: 7px 10px;
|
|
3734
|
+
border-bottom: 1px solid #f0f2f4;
|
|
3735
|
+
font-size: 13px;
|
|
3736
|
+
}
|
|
3737
|
+
.checklist-table tbody tr:last-child td {
|
|
3738
|
+
border-bottom: none;
|
|
3739
|
+
}
|
|
3740
|
+
.icon-cell {
|
|
3741
|
+
text-align: center;
|
|
3742
|
+
width: 52px;
|
|
3743
|
+
}
|
|
3744
|
+
.approve-icon {
|
|
3745
|
+
color: #27ae60;
|
|
3746
|
+
font-size: 16px;
|
|
3747
|
+
font-weight: bold;
|
|
3748
|
+
}
|
|
3749
|
+
.reject-icon {
|
|
3750
|
+
color: #e74c3c;
|
|
3751
|
+
font-size: 16px;
|
|
3752
|
+
font-weight: bold;
|
|
3753
|
+
}
|
|
3754
|
+
</style>
|
|
3755
|
+
</head>
|
|
3756
|
+
<body>
|
|
3757
|
+
<div class="page-header">
|
|
3758
|
+
<img class="page-logo" src="https://seven365-storage.sgp1.cdn.digitaloceanspaces.com/seven365-public/images/seven365-logo.png" alt="Seven365 Logo" />
|
|
3759
|
+
</div>
|
|
3760
|
+
${areaSections}
|
|
3761
|
+
</body>
|
|
3762
|
+
</html>`;
|
|
3763
|
+
}
|
|
3764
|
+
function useChecklistPdfService() {
|
|
3765
|
+
async function generateChecklistPdf(scheduleId) {
|
|
3766
|
+
const db = useAtlas8.getDb();
|
|
3767
|
+
if (!db) {
|
|
3768
|
+
throw new InternalServerError6("Unable to connect to server.");
|
|
3769
|
+
}
|
|
3770
|
+
const collection = db.collection("site.cleaning.schedule.areas");
|
|
3771
|
+
let scheduleObjectId;
|
|
3772
|
+
try {
|
|
3773
|
+
scheduleObjectId = new ObjectId10(scheduleId);
|
|
3774
|
+
} catch {
|
|
3775
|
+
throw new InternalServerError6("Invalid schedule ID format.");
|
|
3776
|
+
}
|
|
3777
|
+
const areaChecklists = await collection.find({ schedule: scheduleObjectId }).sort({ createdAt: 1, name: 1 }).toArray();
|
|
3778
|
+
const html = buildChecklistHtml(areaChecklists);
|
|
3779
|
+
const browser = await launch({
|
|
3780
|
+
headless: true,
|
|
3781
|
+
executablePath: process.env.CHROME_BINARY,
|
|
3782
|
+
args: ["--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage"]
|
|
3783
|
+
});
|
|
3784
|
+
try {
|
|
3785
|
+
const page = await browser.newPage();
|
|
3786
|
+
await page.setViewport({ width: 794, height: 1123 });
|
|
3787
|
+
await page.setContent(html, {
|
|
3788
|
+
waitUntil: ["load", "networkidle0"]
|
|
3789
|
+
});
|
|
3790
|
+
const pdfBuffer = await page.pdf({
|
|
3791
|
+
format: "A4",
|
|
3792
|
+
printBackground: true,
|
|
3793
|
+
margin: {
|
|
3794
|
+
top: "15mm",
|
|
3795
|
+
right: "15mm",
|
|
3796
|
+
bottom: "15mm",
|
|
3797
|
+
left: "15mm"
|
|
3798
|
+
}
|
|
3799
|
+
});
|
|
3800
|
+
return pdfBuffer;
|
|
3801
|
+
} finally {
|
|
3802
|
+
await browser.close();
|
|
3803
|
+
}
|
|
3804
|
+
}
|
|
3805
|
+
return {
|
|
3806
|
+
generateChecklistPdf
|
|
3807
|
+
};
|
|
3808
|
+
}
|
|
3809
|
+
|
|
3810
|
+
// src/controllers/hygiene-area-checklist.controller.ts
|
|
3560
3811
|
function useAreaChecklistController() {
|
|
3561
3812
|
const {
|
|
3562
3813
|
getAllAreaChecklist: _getAllAreaChecklist,
|
|
@@ -3568,6 +3819,7 @@ function useAreaChecklistController() {
|
|
|
3568
3819
|
createAreaChecklist: _createAreaChecklist,
|
|
3569
3820
|
updateAreaChecklistUnits: _updateAreaChecklistUnits
|
|
3570
3821
|
} = useAreaChecklistService();
|
|
3822
|
+
const { generateChecklistPdf: _generateChecklistPdf } = useChecklistPdfService();
|
|
3571
3823
|
async function createAreaChecklist(req, res, next) {
|
|
3572
3824
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
3573
3825
|
(acc, [key, value2]) => ({ ...acc, [key]: value2 }),
|
|
@@ -3586,7 +3838,7 @@ function useAreaChecklistController() {
|
|
|
3586
3838
|
});
|
|
3587
3839
|
const { error, value } = validation.validate(payload);
|
|
3588
3840
|
if (error) {
|
|
3589
|
-
|
|
3841
|
+
logger20.log({ level: "error", message: error.message });
|
|
3590
3842
|
next(new BadRequestError16(error.message));
|
|
3591
3843
|
return;
|
|
3592
3844
|
}
|
|
@@ -3595,7 +3847,7 @@ function useAreaChecklistController() {
|
|
|
3595
3847
|
res.status(201).json({ message: "Area checklist generated successfully." });
|
|
3596
3848
|
return;
|
|
3597
3849
|
} catch (error2) {
|
|
3598
|
-
|
|
3850
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3599
3851
|
next(error2);
|
|
3600
3852
|
return;
|
|
3601
3853
|
}
|
|
@@ -3612,7 +3864,7 @@ function useAreaChecklistController() {
|
|
|
3612
3864
|
});
|
|
3613
3865
|
const { error } = validation.validate(query);
|
|
3614
3866
|
if (error) {
|
|
3615
|
-
|
|
3867
|
+
logger20.log({ level: "error", message: error.message });
|
|
3616
3868
|
next(new BadRequestError16(error.message));
|
|
3617
3869
|
return;
|
|
3618
3870
|
}
|
|
@@ -3634,7 +3886,7 @@ function useAreaChecklistController() {
|
|
|
3634
3886
|
res.json(data);
|
|
3635
3887
|
return;
|
|
3636
3888
|
} catch (error2) {
|
|
3637
|
-
|
|
3889
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3638
3890
|
next(error2);
|
|
3639
3891
|
return;
|
|
3640
3892
|
}
|
|
@@ -3652,7 +3904,7 @@ function useAreaChecklistController() {
|
|
|
3652
3904
|
});
|
|
3653
3905
|
const { error } = validation.validate(query);
|
|
3654
3906
|
if (error) {
|
|
3655
|
-
|
|
3907
|
+
logger20.log({ level: "error", message: error.message });
|
|
3656
3908
|
next(new BadRequestError16(error.message));
|
|
3657
3909
|
return;
|
|
3658
3910
|
}
|
|
@@ -3676,7 +3928,7 @@ function useAreaChecklistController() {
|
|
|
3676
3928
|
res.json(data);
|
|
3677
3929
|
return;
|
|
3678
3930
|
} catch (error2) {
|
|
3679
|
-
|
|
3931
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3680
3932
|
next(error2);
|
|
3681
3933
|
return;
|
|
3682
3934
|
}
|
|
@@ -3686,7 +3938,7 @@ function useAreaChecklistController() {
|
|
|
3686
3938
|
const _id = req.params.id;
|
|
3687
3939
|
const { error, value } = validation.validate(_id);
|
|
3688
3940
|
if (error) {
|
|
3689
|
-
|
|
3941
|
+
logger20.log({ level: "error", message: error.message });
|
|
3690
3942
|
next(new BadRequestError16(error.message));
|
|
3691
3943
|
return;
|
|
3692
3944
|
}
|
|
@@ -3695,7 +3947,7 @@ function useAreaChecklistController() {
|
|
|
3695
3947
|
res.json(data);
|
|
3696
3948
|
return;
|
|
3697
3949
|
} catch (error2) {
|
|
3698
|
-
|
|
3950
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3699
3951
|
next(error2);
|
|
3700
3952
|
return;
|
|
3701
3953
|
}
|
|
@@ -3710,7 +3962,7 @@ function useAreaChecklistController() {
|
|
|
3710
3962
|
});
|
|
3711
3963
|
const { error } = validation.validate(query);
|
|
3712
3964
|
if (error) {
|
|
3713
|
-
|
|
3965
|
+
logger20.log({ level: "error", message: error.message });
|
|
3714
3966
|
next(new BadRequestError16(error.message));
|
|
3715
3967
|
return;
|
|
3716
3968
|
}
|
|
@@ -3728,7 +3980,7 @@ function useAreaChecklistController() {
|
|
|
3728
3980
|
res.json(data);
|
|
3729
3981
|
return;
|
|
3730
3982
|
} catch (error2) {
|
|
3731
|
-
|
|
3983
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3732
3984
|
next(error2);
|
|
3733
3985
|
return;
|
|
3734
3986
|
}
|
|
@@ -3767,7 +4019,7 @@ function useAreaChecklistController() {
|
|
|
3767
4019
|
});
|
|
3768
4020
|
const { error } = validation.validate(payload);
|
|
3769
4021
|
if (error) {
|
|
3770
|
-
|
|
4022
|
+
logger20.log({ level: "error", message: error.message });
|
|
3771
4023
|
next(new BadRequestError16(error.message));
|
|
3772
4024
|
return;
|
|
3773
4025
|
}
|
|
@@ -3777,7 +4029,39 @@ function useAreaChecklistController() {
|
|
|
3777
4029
|
res.json({ message: "Area checklist updated successfully." });
|
|
3778
4030
|
return;
|
|
3779
4031
|
} catch (error2) {
|
|
3780
|
-
|
|
4032
|
+
logger20.log({ level: "error", message: error2.message });
|
|
4033
|
+
next(error2);
|
|
4034
|
+
return;
|
|
4035
|
+
}
|
|
4036
|
+
}
|
|
4037
|
+
async function downloadChecklistPdf(req, res, next) {
|
|
4038
|
+
const validation = Joi9.string().hex().required();
|
|
4039
|
+
const schedule = req.params.schedule;
|
|
4040
|
+
const { error, value } = validation.validate(schedule);
|
|
4041
|
+
if (error) {
|
|
4042
|
+
logger20.log({ level: "error", message: error.message });
|
|
4043
|
+
next(new BadRequestError16(error.message));
|
|
4044
|
+
return;
|
|
4045
|
+
}
|
|
4046
|
+
try {
|
|
4047
|
+
const pdfBuffer = await _generateChecklistPdf(value);
|
|
4048
|
+
if (!pdfBuffer || pdfBuffer.length === 0) {
|
|
4049
|
+
throw new InternalServerError7("Generated checklist PDF is empty or invalid.");
|
|
4050
|
+
}
|
|
4051
|
+
const date = /* @__PURE__ */ new Date();
|
|
4052
|
+
const formattedDate = `${String(date.getDate()).padStart(2, "0")}_${String(
|
|
4053
|
+
date.getMonth() + 1
|
|
4054
|
+
).padStart(2, "0")}_${date.getFullYear()}`;
|
|
4055
|
+
res.setHeader("Content-Type", "application/pdf");
|
|
4056
|
+
res.setHeader(
|
|
4057
|
+
"Content-Disposition",
|
|
4058
|
+
`attachment; filename="CHECKLIST_${formattedDate}.pdf"`
|
|
4059
|
+
);
|
|
4060
|
+
res.setHeader("Content-Length", pdfBuffer.length);
|
|
4061
|
+
res.end(pdfBuffer);
|
|
4062
|
+
return;
|
|
4063
|
+
} catch (error2) {
|
|
4064
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3781
4065
|
next(error2);
|
|
3782
4066
|
return;
|
|
3783
4067
|
}
|
|
@@ -3788,14 +4072,15 @@ function useAreaChecklistController() {
|
|
|
3788
4072
|
getAreaChecklistHistory,
|
|
3789
4073
|
getAreaChecklistHistoryDetails,
|
|
3790
4074
|
getAreaChecklistUnits,
|
|
3791
|
-
updateAreaChecklistUnits
|
|
4075
|
+
updateAreaChecklistUnits,
|
|
4076
|
+
downloadChecklistPdf
|
|
3792
4077
|
};
|
|
3793
4078
|
}
|
|
3794
4079
|
|
|
3795
4080
|
// src/models/hygiene-supply.model.ts
|
|
3796
4081
|
import Joi10 from "joi";
|
|
3797
|
-
import { ObjectId as
|
|
3798
|
-
import { BadRequestError as BadRequestError17, logger as
|
|
4082
|
+
import { ObjectId as ObjectId11 } from "mongodb";
|
|
4083
|
+
import { BadRequestError as BadRequestError17, logger as logger21 } from "@7365admin1/node-server-utils";
|
|
3799
4084
|
var supplySchema = Joi10.object({
|
|
3800
4085
|
site: Joi10.string().hex().required(),
|
|
3801
4086
|
name: Joi10.string().required(),
|
|
@@ -3804,12 +4089,12 @@ var supplySchema = Joi10.object({
|
|
|
3804
4089
|
function MSupply(value) {
|
|
3805
4090
|
const { error } = supplySchema.validate(value);
|
|
3806
4091
|
if (error) {
|
|
3807
|
-
|
|
4092
|
+
logger21.info(`Hygiene Supply Model: ${error.message}`);
|
|
3808
4093
|
throw new BadRequestError17(error.message);
|
|
3809
4094
|
}
|
|
3810
4095
|
if (value.site) {
|
|
3811
4096
|
try {
|
|
3812
|
-
value.site = new
|
|
4097
|
+
value.site = new ObjectId11(value.site);
|
|
3813
4098
|
} catch (error2) {
|
|
3814
4099
|
throw new BadRequestError17("Invalid site ID format.");
|
|
3815
4100
|
}
|
|
@@ -3827,21 +4112,21 @@ function MSupply(value) {
|
|
|
3827
4112
|
}
|
|
3828
4113
|
|
|
3829
4114
|
// src/repositories/hygiene-supply.repository.ts
|
|
3830
|
-
import { ObjectId as
|
|
4115
|
+
import { ObjectId as ObjectId12 } from "mongodb";
|
|
3831
4116
|
import {
|
|
3832
|
-
useAtlas as
|
|
3833
|
-
InternalServerError as
|
|
4117
|
+
useAtlas as useAtlas9,
|
|
4118
|
+
InternalServerError as InternalServerError8,
|
|
3834
4119
|
paginate as paginate5,
|
|
3835
4120
|
BadRequestError as BadRequestError18,
|
|
3836
4121
|
useCache as useCache6,
|
|
3837
|
-
logger as
|
|
4122
|
+
logger as logger22,
|
|
3838
4123
|
makeCacheKey as makeCacheKey6,
|
|
3839
4124
|
NotFoundError as NotFoundError4
|
|
3840
4125
|
} from "@7365admin1/node-server-utils";
|
|
3841
4126
|
function useSupplyRepository() {
|
|
3842
|
-
const db =
|
|
4127
|
+
const db = useAtlas9.getDb();
|
|
3843
4128
|
if (!db) {
|
|
3844
|
-
throw new
|
|
4129
|
+
throw new InternalServerError8("Unable to connect to server.");
|
|
3845
4130
|
}
|
|
3846
4131
|
const namespace_collection = "site.supplies";
|
|
3847
4132
|
const collection = db.collection(namespace_collection);
|
|
@@ -3850,7 +4135,7 @@ function useSupplyRepository() {
|
|
|
3850
4135
|
try {
|
|
3851
4136
|
await collection.createIndexes([{ key: { site: 1 } }]);
|
|
3852
4137
|
} catch (error) {
|
|
3853
|
-
throw new
|
|
4138
|
+
throw new InternalServerError8(
|
|
3854
4139
|
"Failed to create index on hygiene supply."
|
|
3855
4140
|
);
|
|
3856
4141
|
}
|
|
@@ -3859,7 +4144,7 @@ function useSupplyRepository() {
|
|
|
3859
4144
|
try {
|
|
3860
4145
|
await collection.createIndex({ name: "text" });
|
|
3861
4146
|
} catch (error) {
|
|
3862
|
-
throw new
|
|
4147
|
+
throw new InternalServerError8(
|
|
3863
4148
|
"Failed to create text index on hygiene supply."
|
|
3864
4149
|
);
|
|
3865
4150
|
}
|
|
@@ -3871,7 +4156,7 @@ function useSupplyRepository() {
|
|
|
3871
4156
|
{ unique: true }
|
|
3872
4157
|
);
|
|
3873
4158
|
} catch (error) {
|
|
3874
|
-
throw new
|
|
4159
|
+
throw new InternalServerError8(
|
|
3875
4160
|
"Failed to create unique index on hygiene supply."
|
|
3876
4161
|
);
|
|
3877
4162
|
}
|
|
@@ -3881,9 +4166,9 @@ function useSupplyRepository() {
|
|
|
3881
4166
|
value = MSupply(value);
|
|
3882
4167
|
const res = await collection.insertOne(value, { session });
|
|
3883
4168
|
delNamespace().then(() => {
|
|
3884
|
-
|
|
4169
|
+
logger22.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
3885
4170
|
}).catch((err) => {
|
|
3886
|
-
|
|
4171
|
+
logger22.error(
|
|
3887
4172
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
3888
4173
|
err
|
|
3889
4174
|
);
|
|
@@ -3912,7 +4197,7 @@ function useSupplyRepository() {
|
|
|
3912
4197
|
limit
|
|
3913
4198
|
};
|
|
3914
4199
|
try {
|
|
3915
|
-
site = new
|
|
4200
|
+
site = new ObjectId12(site);
|
|
3916
4201
|
query.site = site;
|
|
3917
4202
|
cacheOptions.site = site.toString();
|
|
3918
4203
|
} catch (error) {
|
|
@@ -3925,7 +4210,7 @@ function useSupplyRepository() {
|
|
|
3925
4210
|
const cacheKey = makeCacheKey6(namespace_collection, cacheOptions);
|
|
3926
4211
|
const cachedData = await getCache(cacheKey);
|
|
3927
4212
|
if (cachedData) {
|
|
3928
|
-
|
|
4213
|
+
logger22.info(`Cache hit for key: ${cacheKey}`);
|
|
3929
4214
|
return cachedData;
|
|
3930
4215
|
}
|
|
3931
4216
|
try {
|
|
@@ -3945,9 +4230,9 @@ function useSupplyRepository() {
|
|
|
3945
4230
|
const length = await collection.countDocuments(query);
|
|
3946
4231
|
const data = paginate5(items, page, limit, length);
|
|
3947
4232
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
3948
|
-
|
|
4233
|
+
logger22.info(`Cache set for key: ${cacheKey}`);
|
|
3949
4234
|
}).catch((err) => {
|
|
3950
|
-
|
|
4235
|
+
logger22.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
3951
4236
|
});
|
|
3952
4237
|
return data;
|
|
3953
4238
|
} catch (error) {
|
|
@@ -3956,7 +4241,7 @@ function useSupplyRepository() {
|
|
|
3956
4241
|
}
|
|
3957
4242
|
async function getSupplyById(_id, session) {
|
|
3958
4243
|
try {
|
|
3959
|
-
_id = new
|
|
4244
|
+
_id = new ObjectId12(_id);
|
|
3960
4245
|
} catch (error) {
|
|
3961
4246
|
throw new BadRequestError18("Invalid supply ID format.");
|
|
3962
4247
|
}
|
|
@@ -3970,11 +4255,11 @@ function useSupplyRepository() {
|
|
|
3970
4255
|
if (!session) {
|
|
3971
4256
|
const cachedData = await getCache(cacheKey);
|
|
3972
4257
|
if (cachedData) {
|
|
3973
|
-
|
|
4258
|
+
logger22.info(`Cache hit for key: ${cacheKey}`);
|
|
3974
4259
|
return cachedData;
|
|
3975
4260
|
}
|
|
3976
4261
|
} else {
|
|
3977
|
-
|
|
4262
|
+
logger22.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
3978
4263
|
}
|
|
3979
4264
|
try {
|
|
3980
4265
|
const data = await collection.aggregate([
|
|
@@ -3991,9 +4276,9 @@ function useSupplyRepository() {
|
|
|
3991
4276
|
throw new NotFoundError4("Supply not found.");
|
|
3992
4277
|
}
|
|
3993
4278
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
3994
|
-
|
|
4279
|
+
logger22.info(`Cache set for key: ${cacheKey}`);
|
|
3995
4280
|
}).catch((err) => {
|
|
3996
|
-
|
|
4281
|
+
logger22.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
3997
4282
|
});
|
|
3998
4283
|
return data[0];
|
|
3999
4284
|
} catch (error) {
|
|
@@ -4002,7 +4287,7 @@ function useSupplyRepository() {
|
|
|
4002
4287
|
}
|
|
4003
4288
|
async function updateSupply(_id, value, session) {
|
|
4004
4289
|
try {
|
|
4005
|
-
_id = new
|
|
4290
|
+
_id = new ObjectId12(_id);
|
|
4006
4291
|
} catch (error) {
|
|
4007
4292
|
throw new BadRequestError18("Invalid supply ID format.");
|
|
4008
4293
|
}
|
|
@@ -4014,12 +4299,12 @@ function useSupplyRepository() {
|
|
|
4014
4299
|
{ session }
|
|
4015
4300
|
);
|
|
4016
4301
|
if (res.modifiedCount === 0) {
|
|
4017
|
-
throw new
|
|
4302
|
+
throw new InternalServerError8("Unable to update cleaning supply.");
|
|
4018
4303
|
}
|
|
4019
4304
|
delNamespace().then(() => {
|
|
4020
|
-
|
|
4305
|
+
logger22.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4021
4306
|
}).catch((err) => {
|
|
4022
|
-
|
|
4307
|
+
logger22.error(
|
|
4023
4308
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4024
4309
|
err
|
|
4025
4310
|
);
|
|
@@ -4035,7 +4320,7 @@ function useSupplyRepository() {
|
|
|
4035
4320
|
}
|
|
4036
4321
|
async function deleteSupply(_id, session) {
|
|
4037
4322
|
try {
|
|
4038
|
-
_id = new
|
|
4323
|
+
_id = new ObjectId12(_id);
|
|
4039
4324
|
} catch (error) {
|
|
4040
4325
|
throw new BadRequestError18("Invalid supply ID format.");
|
|
4041
4326
|
}
|
|
@@ -4051,12 +4336,12 @@ function useSupplyRepository() {
|
|
|
4051
4336
|
{ session }
|
|
4052
4337
|
);
|
|
4053
4338
|
if (res.modifiedCount === 0) {
|
|
4054
|
-
throw new
|
|
4339
|
+
throw new InternalServerError8("Unable to delete supply.");
|
|
4055
4340
|
}
|
|
4056
4341
|
delNamespace().then(() => {
|
|
4057
|
-
|
|
4342
|
+
logger22.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4058
4343
|
}).catch((err) => {
|
|
4059
|
-
|
|
4344
|
+
logger22.error(
|
|
4060
4345
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4061
4346
|
err
|
|
4062
4347
|
);
|
|
@@ -4080,7 +4365,7 @@ function useSupplyRepository() {
|
|
|
4080
4365
|
|
|
4081
4366
|
// src/controllers/hygiene-supply.controller.ts
|
|
4082
4367
|
import Joi11 from "joi";
|
|
4083
|
-
import { BadRequestError as BadRequestError19, logger as
|
|
4368
|
+
import { BadRequestError as BadRequestError19, logger as logger23 } from "@7365admin1/node-server-utils";
|
|
4084
4369
|
function useSupplyController() {
|
|
4085
4370
|
const {
|
|
4086
4371
|
createSupply: _createSupply,
|
|
@@ -4093,7 +4378,7 @@ function useSupplyController() {
|
|
|
4093
4378
|
const payload = { ...req.body, ...req.params };
|
|
4094
4379
|
const { error } = supplySchema.validate(payload);
|
|
4095
4380
|
if (error) {
|
|
4096
|
-
|
|
4381
|
+
logger23.log({ level: "error", message: error.message });
|
|
4097
4382
|
next(new BadRequestError19(error.message));
|
|
4098
4383
|
return;
|
|
4099
4384
|
}
|
|
@@ -4102,7 +4387,7 @@ function useSupplyController() {
|
|
|
4102
4387
|
res.status(201).json({ message: "Supply created successfully.", id });
|
|
4103
4388
|
return;
|
|
4104
4389
|
} catch (error2) {
|
|
4105
|
-
|
|
4390
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4106
4391
|
next(error2);
|
|
4107
4392
|
return;
|
|
4108
4393
|
}
|
|
@@ -4117,7 +4402,7 @@ function useSupplyController() {
|
|
|
4117
4402
|
});
|
|
4118
4403
|
const { error } = validation.validate(query);
|
|
4119
4404
|
if (error) {
|
|
4120
|
-
|
|
4405
|
+
logger23.log({ level: "error", message: error.message });
|
|
4121
4406
|
next(new BadRequestError19(error.message));
|
|
4122
4407
|
return;
|
|
4123
4408
|
}
|
|
@@ -4135,7 +4420,7 @@ function useSupplyController() {
|
|
|
4135
4420
|
res.json(data);
|
|
4136
4421
|
return;
|
|
4137
4422
|
} catch (error2) {
|
|
4138
|
-
|
|
4423
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4139
4424
|
next(error2);
|
|
4140
4425
|
return;
|
|
4141
4426
|
}
|
|
@@ -4145,7 +4430,7 @@ function useSupplyController() {
|
|
|
4145
4430
|
const _id = req.params.id;
|
|
4146
4431
|
const { error, value } = validation.validate(_id);
|
|
4147
4432
|
if (error) {
|
|
4148
|
-
|
|
4433
|
+
logger23.log({ level: "error", message: error.message });
|
|
4149
4434
|
next(new BadRequestError19(error.message));
|
|
4150
4435
|
return;
|
|
4151
4436
|
}
|
|
@@ -4154,7 +4439,7 @@ function useSupplyController() {
|
|
|
4154
4439
|
res.json(data);
|
|
4155
4440
|
return;
|
|
4156
4441
|
} catch (error2) {
|
|
4157
|
-
|
|
4442
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4158
4443
|
next(error2);
|
|
4159
4444
|
return;
|
|
4160
4445
|
}
|
|
@@ -4169,7 +4454,7 @@ function useSupplyController() {
|
|
|
4169
4454
|
});
|
|
4170
4455
|
const { error } = validation.validate(payload);
|
|
4171
4456
|
if (error) {
|
|
4172
|
-
|
|
4457
|
+
logger23.log({ level: "error", message: error.message });
|
|
4173
4458
|
next(new BadRequestError19(error.message));
|
|
4174
4459
|
return;
|
|
4175
4460
|
}
|
|
@@ -4179,7 +4464,7 @@ function useSupplyController() {
|
|
|
4179
4464
|
res.json({ message: "Supply updated successfully." });
|
|
4180
4465
|
return;
|
|
4181
4466
|
} catch (error2) {
|
|
4182
|
-
|
|
4467
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4183
4468
|
next(error2);
|
|
4184
4469
|
return;
|
|
4185
4470
|
}
|
|
@@ -4191,7 +4476,7 @@ function useSupplyController() {
|
|
|
4191
4476
|
});
|
|
4192
4477
|
const { error, value } = validation.validate({ id });
|
|
4193
4478
|
if (error) {
|
|
4194
|
-
|
|
4479
|
+
logger23.log({ level: "error", message: error.message });
|
|
4195
4480
|
next(new BadRequestError19(error.message));
|
|
4196
4481
|
return;
|
|
4197
4482
|
}
|
|
@@ -4200,7 +4485,7 @@ function useSupplyController() {
|
|
|
4200
4485
|
res.json({ message: "Supply deleted successfully." });
|
|
4201
4486
|
return;
|
|
4202
4487
|
} catch (error2) {
|
|
4203
|
-
|
|
4488
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4204
4489
|
next(error2);
|
|
4205
4490
|
return;
|
|
4206
4491
|
}
|
|
@@ -4216,8 +4501,8 @@ function useSupplyController() {
|
|
|
4216
4501
|
|
|
4217
4502
|
// src/models/hygiene-stock.model.ts
|
|
4218
4503
|
import Joi12 from "joi";
|
|
4219
|
-
import { ObjectId as
|
|
4220
|
-
import { BadRequestError as BadRequestError20, logger as
|
|
4504
|
+
import { ObjectId as ObjectId13 } from "mongodb";
|
|
4505
|
+
import { BadRequestError as BadRequestError20, logger as logger24 } from "@7365admin1/node-server-utils";
|
|
4221
4506
|
var stockSchema = Joi12.object({
|
|
4222
4507
|
site: Joi12.string().hex().required(),
|
|
4223
4508
|
supply: Joi12.string().hex().required(),
|
|
@@ -4229,19 +4514,19 @@ var stockSchema = Joi12.object({
|
|
|
4229
4514
|
function MStock(value) {
|
|
4230
4515
|
const { error } = stockSchema.validate(value);
|
|
4231
4516
|
if (error) {
|
|
4232
|
-
|
|
4517
|
+
logger24.info(`Hygiene Stock Model: ${error.message}`);
|
|
4233
4518
|
throw new BadRequestError20(error.message);
|
|
4234
4519
|
}
|
|
4235
4520
|
if (value.site) {
|
|
4236
4521
|
try {
|
|
4237
|
-
value.site = new
|
|
4522
|
+
value.site = new ObjectId13(value.site);
|
|
4238
4523
|
} catch (error2) {
|
|
4239
4524
|
throw new BadRequestError20("Invalid site ID format.");
|
|
4240
4525
|
}
|
|
4241
4526
|
}
|
|
4242
4527
|
if (value.supply) {
|
|
4243
4528
|
try {
|
|
4244
|
-
value.supply = new
|
|
4529
|
+
value.supply = new ObjectId13(value.supply);
|
|
4245
4530
|
} catch (error2) {
|
|
4246
4531
|
throw new BadRequestError20("Invalid supply ID format.");
|
|
4247
4532
|
}
|
|
@@ -4261,20 +4546,20 @@ function MStock(value) {
|
|
|
4261
4546
|
}
|
|
4262
4547
|
|
|
4263
4548
|
// src/repositories/hygiene-stock.repository.ts
|
|
4264
|
-
import { ObjectId as
|
|
4549
|
+
import { ObjectId as ObjectId14 } from "mongodb";
|
|
4265
4550
|
import {
|
|
4266
|
-
useAtlas as
|
|
4267
|
-
InternalServerError as
|
|
4551
|
+
useAtlas as useAtlas10,
|
|
4552
|
+
InternalServerError as InternalServerError9,
|
|
4268
4553
|
BadRequestError as BadRequestError21,
|
|
4269
4554
|
useCache as useCache7,
|
|
4270
|
-
logger as
|
|
4555
|
+
logger as logger25,
|
|
4271
4556
|
makeCacheKey as makeCacheKey7,
|
|
4272
4557
|
paginate as paginate6
|
|
4273
4558
|
} from "@7365admin1/node-server-utils";
|
|
4274
4559
|
function useStockRepository() {
|
|
4275
|
-
const db =
|
|
4560
|
+
const db = useAtlas10.getDb();
|
|
4276
4561
|
if (!db) {
|
|
4277
|
-
throw new
|
|
4562
|
+
throw new InternalServerError9("Unable to connect to server.");
|
|
4278
4563
|
}
|
|
4279
4564
|
const namespace_collection = "site.supply.stocks";
|
|
4280
4565
|
const supply_collection = "site.supplies";
|
|
@@ -4290,7 +4575,7 @@ function useStockRepository() {
|
|
|
4290
4575
|
{ key: { status: 1 } }
|
|
4291
4576
|
]);
|
|
4292
4577
|
} catch (error) {
|
|
4293
|
-
throw new
|
|
4578
|
+
throw new InternalServerError9("Failed to create index on hygiene stock.");
|
|
4294
4579
|
}
|
|
4295
4580
|
}
|
|
4296
4581
|
async function createStock(value, session) {
|
|
@@ -4298,17 +4583,17 @@ function useStockRepository() {
|
|
|
4298
4583
|
value = MStock(value);
|
|
4299
4584
|
const res = await collection.insertOne(value, { session });
|
|
4300
4585
|
delNamespace().then(() => {
|
|
4301
|
-
|
|
4586
|
+
logger25.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4302
4587
|
}).catch((err) => {
|
|
4303
|
-
|
|
4588
|
+
logger25.error(
|
|
4304
4589
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4305
4590
|
err
|
|
4306
4591
|
);
|
|
4307
4592
|
});
|
|
4308
4593
|
delSupplyNamespace().then(() => {
|
|
4309
|
-
|
|
4594
|
+
logger25.info(`Cache cleared for namespace: ${supply_collection}`);
|
|
4310
4595
|
}).catch((err) => {
|
|
4311
|
-
|
|
4596
|
+
logger25.error(
|
|
4312
4597
|
`Failed to clear cache for namespace: ${supply_collection}`,
|
|
4313
4598
|
err
|
|
4314
4599
|
);
|
|
@@ -4334,14 +4619,14 @@ function useStockRepository() {
|
|
|
4334
4619
|
limit
|
|
4335
4620
|
};
|
|
4336
4621
|
try {
|
|
4337
|
-
site = new
|
|
4622
|
+
site = new ObjectId14(site);
|
|
4338
4623
|
query.site = site;
|
|
4339
4624
|
cacheOptions.site = site.toString();
|
|
4340
4625
|
} catch (error) {
|
|
4341
4626
|
throw new BadRequestError21("Invalid site ID format.");
|
|
4342
4627
|
}
|
|
4343
4628
|
try {
|
|
4344
|
-
supply = new
|
|
4629
|
+
supply = new ObjectId14(supply);
|
|
4345
4630
|
query.supply = supply;
|
|
4346
4631
|
cacheOptions.supply = supply.toString();
|
|
4347
4632
|
} catch (error) {
|
|
@@ -4354,7 +4639,7 @@ function useStockRepository() {
|
|
|
4354
4639
|
const cacheKey = makeCacheKey7(namespace_collection, cacheOptions);
|
|
4355
4640
|
const cachedData = await getCache(cacheKey);
|
|
4356
4641
|
if (cachedData) {
|
|
4357
|
-
|
|
4642
|
+
logger25.info(`Cache hit for key: ${cacheKey}`);
|
|
4358
4643
|
return cachedData;
|
|
4359
4644
|
}
|
|
4360
4645
|
try {
|
|
@@ -4375,9 +4660,9 @@ function useStockRepository() {
|
|
|
4375
4660
|
const length = await collection.countDocuments(query);
|
|
4376
4661
|
const data = paginate6(items, page, limit, length);
|
|
4377
4662
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4378
|
-
|
|
4663
|
+
logger25.info(`Cache set for key: ${cacheKey}`);
|
|
4379
4664
|
}).catch((err) => {
|
|
4380
|
-
|
|
4665
|
+
logger25.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4381
4666
|
});
|
|
4382
4667
|
return data;
|
|
4383
4668
|
} catch (error) {
|
|
@@ -4394,7 +4679,7 @@ function useStockRepository() {
|
|
|
4394
4679
|
// src/services/hygiene-stock.service.ts
|
|
4395
4680
|
import {
|
|
4396
4681
|
NotFoundError as NotFoundError5,
|
|
4397
|
-
useAtlas as
|
|
4682
|
+
useAtlas as useAtlas11,
|
|
4398
4683
|
BadRequestError as BadRequestError22
|
|
4399
4684
|
} from "@7365admin1/node-server-utils";
|
|
4400
4685
|
function useStockService() {
|
|
@@ -4403,7 +4688,7 @@ function useStockService() {
|
|
|
4403
4688
|
async function createStock(value, out = false, session) {
|
|
4404
4689
|
let ownSession = false;
|
|
4405
4690
|
if (!session) {
|
|
4406
|
-
session =
|
|
4691
|
+
session = useAtlas11.getClient()?.startSession();
|
|
4407
4692
|
ownSession = true;
|
|
4408
4693
|
}
|
|
4409
4694
|
try {
|
|
@@ -4447,7 +4732,7 @@ function useStockService() {
|
|
|
4447
4732
|
|
|
4448
4733
|
// src/controllers/hygiene-stock.controller.ts
|
|
4449
4734
|
import Joi13 from "joi";
|
|
4450
|
-
import { BadRequestError as BadRequestError23, logger as
|
|
4735
|
+
import { BadRequestError as BadRequestError23, logger as logger26 } from "@7365admin1/node-server-utils";
|
|
4451
4736
|
function useStockController() {
|
|
4452
4737
|
const { getStocksBySupplyId: _getStocksBySupplyId } = useStockRepository();
|
|
4453
4738
|
const { createStock: _createStock } = useStockService();
|
|
@@ -4461,7 +4746,7 @@ function useStockController() {
|
|
|
4461
4746
|
});
|
|
4462
4747
|
const { error } = validation.validate(payload);
|
|
4463
4748
|
if (error) {
|
|
4464
|
-
|
|
4749
|
+
logger26.log({ level: "error", message: error.message });
|
|
4465
4750
|
next(new BadRequestError23(error.message));
|
|
4466
4751
|
return;
|
|
4467
4752
|
}
|
|
@@ -4470,7 +4755,7 @@ function useStockController() {
|
|
|
4470
4755
|
res.status(201).json({ message: "Stock created successfully.", id });
|
|
4471
4756
|
return;
|
|
4472
4757
|
} catch (error2) {
|
|
4473
|
-
|
|
4758
|
+
logger26.log({ level: "error", message: error2.message });
|
|
4474
4759
|
next(error2);
|
|
4475
4760
|
return;
|
|
4476
4761
|
}
|
|
@@ -4486,7 +4771,7 @@ function useStockController() {
|
|
|
4486
4771
|
});
|
|
4487
4772
|
const { error } = validation.validate(query);
|
|
4488
4773
|
if (error) {
|
|
4489
|
-
|
|
4774
|
+
logger26.log({ level: "error", message: error.message });
|
|
4490
4775
|
next(new BadRequestError23(error.message));
|
|
4491
4776
|
return;
|
|
4492
4777
|
}
|
|
@@ -4506,7 +4791,7 @@ function useStockController() {
|
|
|
4506
4791
|
res.json(data);
|
|
4507
4792
|
return;
|
|
4508
4793
|
} catch (error2) {
|
|
4509
|
-
|
|
4794
|
+
logger26.log({ level: "error", message: error2.message });
|
|
4510
4795
|
next(error2);
|
|
4511
4796
|
return;
|
|
4512
4797
|
}
|
|
@@ -4519,8 +4804,8 @@ function useStockController() {
|
|
|
4519
4804
|
|
|
4520
4805
|
// src/models/hygiene-checkout-item.model.ts
|
|
4521
4806
|
import Joi14 from "joi";
|
|
4522
|
-
import { ObjectId as
|
|
4523
|
-
import { BadRequestError as BadRequestError24, logger as
|
|
4807
|
+
import { ObjectId as ObjectId15 } from "mongodb";
|
|
4808
|
+
import { BadRequestError as BadRequestError24, logger as logger27 } from "@7365admin1/node-server-utils";
|
|
4524
4809
|
var allowedCheckOutItemStatus = ["pending", "completed"];
|
|
4525
4810
|
var checkOutItemSchema = Joi14.object({
|
|
4526
4811
|
site: Joi14.string().hex().required(),
|
|
@@ -4534,19 +4819,19 @@ var checkOutItemSchema = Joi14.object({
|
|
|
4534
4819
|
function MCheckOutItem(value) {
|
|
4535
4820
|
const { error } = checkOutItemSchema.validate(value);
|
|
4536
4821
|
if (error) {
|
|
4537
|
-
|
|
4822
|
+
logger27.info(`Hygiene Check Out Item Model: ${error.message}`);
|
|
4538
4823
|
throw new BadRequestError24(error.message);
|
|
4539
4824
|
}
|
|
4540
4825
|
if (value.site) {
|
|
4541
4826
|
try {
|
|
4542
|
-
value.site = new
|
|
4827
|
+
value.site = new ObjectId15(value.site);
|
|
4543
4828
|
} catch (error2) {
|
|
4544
4829
|
throw new BadRequestError24("Invalid site ID format.");
|
|
4545
4830
|
}
|
|
4546
4831
|
}
|
|
4547
4832
|
if (value.supply) {
|
|
4548
4833
|
try {
|
|
4549
|
-
value.supply = new
|
|
4834
|
+
value.supply = new ObjectId15(value.supply);
|
|
4550
4835
|
} catch (error2) {
|
|
4551
4836
|
throw new BadRequestError24("Invalid supply ID format.");
|
|
4552
4837
|
}
|
|
@@ -4567,21 +4852,21 @@ function MCheckOutItem(value) {
|
|
|
4567
4852
|
}
|
|
4568
4853
|
|
|
4569
4854
|
// src/repositories/hygiene-checkout-item.repository.ts
|
|
4570
|
-
import { ObjectId as
|
|
4855
|
+
import { ObjectId as ObjectId16 } from "mongodb";
|
|
4571
4856
|
import {
|
|
4572
|
-
useAtlas as
|
|
4573
|
-
InternalServerError as
|
|
4857
|
+
useAtlas as useAtlas12,
|
|
4858
|
+
InternalServerError as InternalServerError10,
|
|
4574
4859
|
useCache as useCache8,
|
|
4575
|
-
logger as
|
|
4860
|
+
logger as logger28,
|
|
4576
4861
|
makeCacheKey as makeCacheKey8,
|
|
4577
4862
|
paginate as paginate7,
|
|
4578
4863
|
BadRequestError as BadRequestError25,
|
|
4579
4864
|
NotFoundError as NotFoundError6
|
|
4580
4865
|
} from "@7365admin1/node-server-utils";
|
|
4581
4866
|
function useCheckOutItemRepository() {
|
|
4582
|
-
const db =
|
|
4867
|
+
const db = useAtlas12.getDb();
|
|
4583
4868
|
if (!db) {
|
|
4584
|
-
throw new
|
|
4869
|
+
throw new InternalServerError10("Unable to connect to server.");
|
|
4585
4870
|
}
|
|
4586
4871
|
const namespace_collection = "site.supply.checkouts";
|
|
4587
4872
|
const collection = db.collection(namespace_collection);
|
|
@@ -4594,7 +4879,7 @@ function useCheckOutItemRepository() {
|
|
|
4594
4879
|
{ key: { status: 1 } }
|
|
4595
4880
|
]);
|
|
4596
4881
|
} catch (error) {
|
|
4597
|
-
throw new
|
|
4882
|
+
throw new InternalServerError10(
|
|
4598
4883
|
"Failed to create index on hygiene check out item."
|
|
4599
4884
|
);
|
|
4600
4885
|
}
|
|
@@ -4603,7 +4888,7 @@ function useCheckOutItemRepository() {
|
|
|
4603
4888
|
try {
|
|
4604
4889
|
await collection.createIndex({ supplyName: "text" });
|
|
4605
4890
|
} catch (error) {
|
|
4606
|
-
throw new
|
|
4891
|
+
throw new InternalServerError10(
|
|
4607
4892
|
"Failed to create text index on hygiene supply."
|
|
4608
4893
|
);
|
|
4609
4894
|
}
|
|
@@ -4613,9 +4898,9 @@ function useCheckOutItemRepository() {
|
|
|
4613
4898
|
value = MCheckOutItem(value);
|
|
4614
4899
|
const res = await collection.insertOne(value, { session });
|
|
4615
4900
|
delNamespace().then(() => {
|
|
4616
|
-
|
|
4901
|
+
logger28.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4617
4902
|
}).catch((err) => {
|
|
4618
|
-
|
|
4903
|
+
logger28.error(
|
|
4619
4904
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4620
4905
|
err
|
|
4621
4906
|
);
|
|
@@ -4640,7 +4925,7 @@ function useCheckOutItemRepository() {
|
|
|
4640
4925
|
limit
|
|
4641
4926
|
};
|
|
4642
4927
|
try {
|
|
4643
|
-
site = new
|
|
4928
|
+
site = new ObjectId16(site);
|
|
4644
4929
|
query.site = site;
|
|
4645
4930
|
cacheOptions.site = site.toString();
|
|
4646
4931
|
} catch (error) {
|
|
@@ -4653,7 +4938,7 @@ function useCheckOutItemRepository() {
|
|
|
4653
4938
|
const cacheKey = makeCacheKey8(namespace_collection, cacheOptions);
|
|
4654
4939
|
const cachedData = await getCache(cacheKey);
|
|
4655
4940
|
if (cachedData) {
|
|
4656
|
-
|
|
4941
|
+
logger28.info(`Cache hit for key: ${cacheKey}`);
|
|
4657
4942
|
return cachedData;
|
|
4658
4943
|
}
|
|
4659
4944
|
try {
|
|
@@ -4702,9 +4987,9 @@ function useCheckOutItemRepository() {
|
|
|
4702
4987
|
const length = await collection.countDocuments(query);
|
|
4703
4988
|
const data = paginate7(items, page, limit, length);
|
|
4704
4989
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4705
|
-
|
|
4990
|
+
logger28.info(`Cache set for key: ${cacheKey}`);
|
|
4706
4991
|
}).catch((err) => {
|
|
4707
|
-
|
|
4992
|
+
logger28.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4708
4993
|
});
|
|
4709
4994
|
return data;
|
|
4710
4995
|
} catch (error) {
|
|
@@ -4713,7 +4998,7 @@ function useCheckOutItemRepository() {
|
|
|
4713
4998
|
}
|
|
4714
4999
|
async function getCheckOutItemById(_id, session) {
|
|
4715
5000
|
try {
|
|
4716
|
-
_id = new
|
|
5001
|
+
_id = new ObjectId16(_id);
|
|
4717
5002
|
} catch (error) {
|
|
4718
5003
|
throw new BadRequestError25("Invalid check out item ID format.");
|
|
4719
5004
|
}
|
|
@@ -4724,11 +5009,11 @@ function useCheckOutItemRepository() {
|
|
|
4724
5009
|
if (!session) {
|
|
4725
5010
|
const cachedData = await getCache(cacheKey);
|
|
4726
5011
|
if (cachedData) {
|
|
4727
|
-
|
|
5012
|
+
logger28.info(`Cache hit for key: ${cacheKey}`);
|
|
4728
5013
|
return cachedData;
|
|
4729
5014
|
}
|
|
4730
5015
|
} else {
|
|
4731
|
-
|
|
5016
|
+
logger28.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
4732
5017
|
}
|
|
4733
5018
|
try {
|
|
4734
5019
|
const data = await collection.aggregate(
|
|
@@ -4766,9 +5051,9 @@ function useCheckOutItemRepository() {
|
|
|
4766
5051
|
throw new NotFoundError6("Check out item not found.");
|
|
4767
5052
|
}
|
|
4768
5053
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
4769
|
-
|
|
5054
|
+
logger28.info(`Cache set for key: ${cacheKey}`);
|
|
4770
5055
|
}).catch((err) => {
|
|
4771
|
-
|
|
5056
|
+
logger28.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4772
5057
|
});
|
|
4773
5058
|
return data[0];
|
|
4774
5059
|
} catch (error) {
|
|
@@ -4777,7 +5062,7 @@ function useCheckOutItemRepository() {
|
|
|
4777
5062
|
}
|
|
4778
5063
|
async function completeCheckOutItem(_id, session) {
|
|
4779
5064
|
try {
|
|
4780
|
-
_id = new
|
|
5065
|
+
_id = new ObjectId16(_id);
|
|
4781
5066
|
} catch (error) {
|
|
4782
5067
|
throw new BadRequestError25("Invalid check out item ID format.");
|
|
4783
5068
|
}
|
|
@@ -4792,12 +5077,12 @@ function useCheckOutItemRepository() {
|
|
|
4792
5077
|
{ session }
|
|
4793
5078
|
);
|
|
4794
5079
|
if (res.modifiedCount === 0) {
|
|
4795
|
-
throw new
|
|
5080
|
+
throw new InternalServerError10("Unable to complete check out item.");
|
|
4796
5081
|
}
|
|
4797
5082
|
delNamespace().then(() => {
|
|
4798
|
-
|
|
5083
|
+
logger28.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4799
5084
|
}).catch((err) => {
|
|
4800
|
-
|
|
5085
|
+
logger28.error(
|
|
4801
5086
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4802
5087
|
err
|
|
4803
5088
|
);
|
|
@@ -4819,7 +5104,7 @@ function useCheckOutItemRepository() {
|
|
|
4819
5104
|
|
|
4820
5105
|
// src/services/hygiene-checkout-item.service.ts
|
|
4821
5106
|
import { useUserRepo } from "@7365admin1/core";
|
|
4822
|
-
import { BadRequestError as BadRequestError26, useAtlas as
|
|
5107
|
+
import { BadRequestError as BadRequestError26, useAtlas as useAtlas13 } from "@7365admin1/node-server-utils";
|
|
4823
5108
|
function useCheckOutItemService() {
|
|
4824
5109
|
const {
|
|
4825
5110
|
createCheckOutItem: _createCheckOutItem,
|
|
@@ -4830,7 +5115,7 @@ function useCheckOutItemService() {
|
|
|
4830
5115
|
const { getUserById } = useUserRepo();
|
|
4831
5116
|
const { createStock } = useStockService();
|
|
4832
5117
|
async function createCheckOutItem(value) {
|
|
4833
|
-
const session =
|
|
5118
|
+
const session = useAtlas13.getClient()?.startSession();
|
|
4834
5119
|
try {
|
|
4835
5120
|
session?.startTransaction();
|
|
4836
5121
|
const supplyData = await getSupplyById(value.supply);
|
|
@@ -4870,7 +5155,7 @@ function useCheckOutItemService() {
|
|
|
4870
5155
|
}
|
|
4871
5156
|
}
|
|
4872
5157
|
async function createCheckOutItemByBatch(value) {
|
|
4873
|
-
const session =
|
|
5158
|
+
const session = useAtlas13.getClient()?.startSession();
|
|
4874
5159
|
try {
|
|
4875
5160
|
session?.startTransaction();
|
|
4876
5161
|
const { site, attachment, createdBy, items } = value;
|
|
@@ -4918,7 +5203,7 @@ function useCheckOutItemService() {
|
|
|
4918
5203
|
|
|
4919
5204
|
// src/controllers/hygiene-checkout-item.controller.ts
|
|
4920
5205
|
import Joi15 from "joi";
|
|
4921
|
-
import { BadRequestError as BadRequestError27, logger as
|
|
5206
|
+
import { BadRequestError as BadRequestError27, logger as logger29 } from "@7365admin1/node-server-utils";
|
|
4922
5207
|
function useCheckOutItemController() {
|
|
4923
5208
|
const {
|
|
4924
5209
|
getCheckOutItems: _getCheckOutItems,
|
|
@@ -4948,7 +5233,7 @@ function useCheckOutItemController() {
|
|
|
4948
5233
|
});
|
|
4949
5234
|
const { error } = validation.validate(payload);
|
|
4950
5235
|
if (error) {
|
|
4951
|
-
|
|
5236
|
+
logger29.log({ level: "error", message: error.message });
|
|
4952
5237
|
next(new BadRequestError27(error.message));
|
|
4953
5238
|
return;
|
|
4954
5239
|
}
|
|
@@ -4957,7 +5242,7 @@ function useCheckOutItemController() {
|
|
|
4957
5242
|
res.status(201).json({ message: "Check out item created successfully.", id });
|
|
4958
5243
|
return;
|
|
4959
5244
|
} catch (error2) {
|
|
4960
|
-
|
|
5245
|
+
logger29.log({ level: "error", message: error2.message });
|
|
4961
5246
|
next(error2);
|
|
4962
5247
|
return;
|
|
4963
5248
|
}
|
|
@@ -4986,7 +5271,7 @@ function useCheckOutItemController() {
|
|
|
4986
5271
|
});
|
|
4987
5272
|
const { error } = validation.validate(payload);
|
|
4988
5273
|
if (error) {
|
|
4989
|
-
|
|
5274
|
+
logger29.log({ level: "error", message: error.message });
|
|
4990
5275
|
next(new BadRequestError27(error.message));
|
|
4991
5276
|
return;
|
|
4992
5277
|
}
|
|
@@ -4995,7 +5280,7 @@ function useCheckOutItemController() {
|
|
|
4995
5280
|
res.status(201).json({ message: "Check out items created successfully." });
|
|
4996
5281
|
return;
|
|
4997
5282
|
} catch (error2) {
|
|
4998
|
-
|
|
5283
|
+
logger29.log({ level: "error", message: error2.message });
|
|
4999
5284
|
next(error2);
|
|
5000
5285
|
return;
|
|
5001
5286
|
}
|
|
@@ -5010,7 +5295,7 @@ function useCheckOutItemController() {
|
|
|
5010
5295
|
});
|
|
5011
5296
|
const { error } = validation.validate(query);
|
|
5012
5297
|
if (error) {
|
|
5013
|
-
|
|
5298
|
+
logger29.log({ level: "error", message: error.message });
|
|
5014
5299
|
next(new BadRequestError27(error.message));
|
|
5015
5300
|
return;
|
|
5016
5301
|
}
|
|
@@ -5028,7 +5313,7 @@ function useCheckOutItemController() {
|
|
|
5028
5313
|
res.json(data);
|
|
5029
5314
|
return;
|
|
5030
5315
|
} catch (error2) {
|
|
5031
|
-
|
|
5316
|
+
logger29.log({ level: "error", message: error2.message });
|
|
5032
5317
|
next(error2);
|
|
5033
5318
|
return;
|
|
5034
5319
|
}
|
|
@@ -5038,7 +5323,7 @@ function useCheckOutItemController() {
|
|
|
5038
5323
|
const _id = req.params.id;
|
|
5039
5324
|
const { error, value } = validation.validate(_id);
|
|
5040
5325
|
if (error) {
|
|
5041
|
-
|
|
5326
|
+
logger29.log({ level: "error", message: error.message });
|
|
5042
5327
|
next(new BadRequestError27(error.message));
|
|
5043
5328
|
return;
|
|
5044
5329
|
}
|
|
@@ -5047,7 +5332,7 @@ function useCheckOutItemController() {
|
|
|
5047
5332
|
res.json(data);
|
|
5048
5333
|
return;
|
|
5049
5334
|
} catch (error2) {
|
|
5050
|
-
|
|
5335
|
+
logger29.log({ level: "error", message: error2.message });
|
|
5051
5336
|
next(error2);
|
|
5052
5337
|
return;
|
|
5053
5338
|
}
|
|
@@ -5061,9 +5346,9 @@ function useCheckOutItemController() {
|
|
|
5061
5346
|
}
|
|
5062
5347
|
|
|
5063
5348
|
// src/models/hygiene-schedule-task.model.ts
|
|
5064
|
-
import { BadRequestError as BadRequestError28, logger as
|
|
5349
|
+
import { BadRequestError as BadRequestError28, logger as logger30 } from "@7365admin1/node-server-utils";
|
|
5065
5350
|
import Joi16 from "joi";
|
|
5066
|
-
import { ObjectId as
|
|
5351
|
+
import { ObjectId as ObjectId17 } from "mongodb";
|
|
5067
5352
|
var scheduleTaskSchema = Joi16.object({
|
|
5068
5353
|
site: Joi16.string().hex().required(),
|
|
5069
5354
|
title: Joi16.string().required(),
|
|
@@ -5082,12 +5367,12 @@ var scheduleTaskSchema = Joi16.object({
|
|
|
5082
5367
|
function MScheduleTask(value) {
|
|
5083
5368
|
const { error } = scheduleTaskSchema.validate(value);
|
|
5084
5369
|
if (error) {
|
|
5085
|
-
|
|
5370
|
+
logger30.info(`Hygiene Schedule Task Model: ${error.message}`);
|
|
5086
5371
|
throw new BadRequestError28(error.message);
|
|
5087
5372
|
}
|
|
5088
5373
|
if (value.site) {
|
|
5089
5374
|
try {
|
|
5090
|
-
value.site = new
|
|
5375
|
+
value.site = new ObjectId17(value.site);
|
|
5091
5376
|
} catch (error2) {
|
|
5092
5377
|
throw new BadRequestError28("Invalid site ID format.");
|
|
5093
5378
|
}
|
|
@@ -5097,7 +5382,7 @@ function MScheduleTask(value) {
|
|
|
5097
5382
|
try {
|
|
5098
5383
|
return {
|
|
5099
5384
|
name: area.name,
|
|
5100
|
-
value: new
|
|
5385
|
+
value: new ObjectId17(area.value.toString())
|
|
5101
5386
|
};
|
|
5102
5387
|
} catch (error2) {
|
|
5103
5388
|
throw new BadRequestError28(`Invalid area value format: ${area.name}`);
|
|
@@ -5106,7 +5391,7 @@ function MScheduleTask(value) {
|
|
|
5106
5391
|
}
|
|
5107
5392
|
if (value.createdBy) {
|
|
5108
5393
|
try {
|
|
5109
|
-
value.createdBy = new
|
|
5394
|
+
value.createdBy = new ObjectId17(value.createdBy);
|
|
5110
5395
|
} catch (error2) {
|
|
5111
5396
|
throw new BadRequestError28("Invalid createdBy ID format.");
|
|
5112
5397
|
}
|
|
@@ -5128,21 +5413,21 @@ function MScheduleTask(value) {
|
|
|
5128
5413
|
}
|
|
5129
5414
|
|
|
5130
5415
|
// src/repositories/hygiene-schedule-task.repository.ts
|
|
5131
|
-
import { ObjectId as
|
|
5416
|
+
import { ObjectId as ObjectId18 } from "mongodb";
|
|
5132
5417
|
import {
|
|
5133
|
-
useAtlas as
|
|
5134
|
-
InternalServerError as
|
|
5418
|
+
useAtlas as useAtlas14,
|
|
5419
|
+
InternalServerError as InternalServerError11,
|
|
5135
5420
|
paginate as paginate8,
|
|
5136
5421
|
BadRequestError as BadRequestError29,
|
|
5137
5422
|
useCache as useCache9,
|
|
5138
|
-
logger as
|
|
5423
|
+
logger as logger31,
|
|
5139
5424
|
makeCacheKey as makeCacheKey9,
|
|
5140
5425
|
NotFoundError as NotFoundError7
|
|
5141
5426
|
} from "@7365admin1/node-server-utils";
|
|
5142
5427
|
function useScheduleTaskRepository() {
|
|
5143
|
-
const db =
|
|
5428
|
+
const db = useAtlas14.getDb();
|
|
5144
5429
|
if (!db) {
|
|
5145
|
-
throw new
|
|
5430
|
+
throw new InternalServerError11("Unable to connect to server.");
|
|
5146
5431
|
}
|
|
5147
5432
|
const namespace_collection = "site.schedule-tasks";
|
|
5148
5433
|
const collection = db.collection(namespace_collection);
|
|
@@ -5154,7 +5439,7 @@ function useScheduleTaskRepository() {
|
|
|
5154
5439
|
{ key: { status: 1 } }
|
|
5155
5440
|
]);
|
|
5156
5441
|
} catch (error) {
|
|
5157
|
-
throw new
|
|
5442
|
+
throw new InternalServerError11(
|
|
5158
5443
|
"Failed to create index on hygiene schedule task."
|
|
5159
5444
|
);
|
|
5160
5445
|
}
|
|
@@ -5163,7 +5448,7 @@ function useScheduleTaskRepository() {
|
|
|
5163
5448
|
try {
|
|
5164
5449
|
await collection.createIndex({ title: "text", description: "text" });
|
|
5165
5450
|
} catch (error) {
|
|
5166
|
-
throw new
|
|
5451
|
+
throw new InternalServerError11(
|
|
5167
5452
|
"Failed to create text index on hygiene schedule task."
|
|
5168
5453
|
);
|
|
5169
5454
|
}
|
|
@@ -5173,9 +5458,9 @@ function useScheduleTaskRepository() {
|
|
|
5173
5458
|
value = MScheduleTask(value);
|
|
5174
5459
|
const res = await collection.insertOne(value, { session });
|
|
5175
5460
|
delNamespace().then(() => {
|
|
5176
|
-
|
|
5461
|
+
logger31.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5177
5462
|
}).catch((err) => {
|
|
5178
|
-
|
|
5463
|
+
logger31.error(
|
|
5179
5464
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5180
5465
|
err
|
|
5181
5466
|
);
|
|
@@ -5200,7 +5485,7 @@ function useScheduleTaskRepository() {
|
|
|
5200
5485
|
limit
|
|
5201
5486
|
};
|
|
5202
5487
|
try {
|
|
5203
|
-
site = new
|
|
5488
|
+
site = new ObjectId18(site);
|
|
5204
5489
|
query.site = site;
|
|
5205
5490
|
cacheOptions.site = site.toString();
|
|
5206
5491
|
} catch (error) {
|
|
@@ -5213,7 +5498,7 @@ function useScheduleTaskRepository() {
|
|
|
5213
5498
|
const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
|
|
5214
5499
|
const cachedData = await getCache(cacheKey);
|
|
5215
5500
|
if (cachedData) {
|
|
5216
|
-
|
|
5501
|
+
logger31.info(`Cache hit for key: ${cacheKey}`);
|
|
5217
5502
|
return cachedData;
|
|
5218
5503
|
}
|
|
5219
5504
|
try {
|
|
@@ -5233,9 +5518,9 @@ function useScheduleTaskRepository() {
|
|
|
5233
5518
|
const length = await collection.countDocuments(query);
|
|
5234
5519
|
const data = paginate8(items, page, limit, length);
|
|
5235
5520
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5236
|
-
|
|
5521
|
+
logger31.info(`Cache set for key: ${cacheKey}`);
|
|
5237
5522
|
}).catch((err) => {
|
|
5238
|
-
|
|
5523
|
+
logger31.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5239
5524
|
});
|
|
5240
5525
|
return data;
|
|
5241
5526
|
} catch (error) {
|
|
@@ -5268,7 +5553,7 @@ function useScheduleTaskRepository() {
|
|
|
5268
5553
|
limit
|
|
5269
5554
|
};
|
|
5270
5555
|
try {
|
|
5271
|
-
site = new
|
|
5556
|
+
site = new ObjectId18(site);
|
|
5272
5557
|
query.site = site;
|
|
5273
5558
|
cacheOptions.site = site.toString();
|
|
5274
5559
|
} catch (error) {
|
|
@@ -5281,7 +5566,7 @@ function useScheduleTaskRepository() {
|
|
|
5281
5566
|
const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
|
|
5282
5567
|
const cachedData = await getCache(cacheKey);
|
|
5283
5568
|
if (cachedData) {
|
|
5284
|
-
|
|
5569
|
+
logger31.info(`Cache hit for key: ${cacheKey}`);
|
|
5285
5570
|
return cachedData;
|
|
5286
5571
|
}
|
|
5287
5572
|
try {
|
|
@@ -5300,9 +5585,9 @@ function useScheduleTaskRepository() {
|
|
|
5300
5585
|
const length = await collection.countDocuments(query);
|
|
5301
5586
|
const data = paginate8(items, page, limit, length);
|
|
5302
5587
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5303
|
-
|
|
5588
|
+
logger31.info(`Cache set for key: ${cacheKey}`);
|
|
5304
5589
|
}).catch((err) => {
|
|
5305
|
-
|
|
5590
|
+
logger31.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5306
5591
|
});
|
|
5307
5592
|
return data;
|
|
5308
5593
|
} catch (error) {
|
|
@@ -5311,7 +5596,7 @@ function useScheduleTaskRepository() {
|
|
|
5311
5596
|
}
|
|
5312
5597
|
async function getScheduleTaskById(_id, session) {
|
|
5313
5598
|
try {
|
|
5314
|
-
_id = new
|
|
5599
|
+
_id = new ObjectId18(_id);
|
|
5315
5600
|
} catch (error) {
|
|
5316
5601
|
throw new BadRequestError29("Invalid schedule task ID format.");
|
|
5317
5602
|
}
|
|
@@ -5325,11 +5610,11 @@ function useScheduleTaskRepository() {
|
|
|
5325
5610
|
if (!session) {
|
|
5326
5611
|
const cachedData = await getCache(cacheKey);
|
|
5327
5612
|
if (cachedData) {
|
|
5328
|
-
|
|
5613
|
+
logger31.info(`Cache hit for key: ${cacheKey}`);
|
|
5329
5614
|
return cachedData;
|
|
5330
5615
|
}
|
|
5331
5616
|
} else {
|
|
5332
|
-
|
|
5617
|
+
logger31.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
5333
5618
|
}
|
|
5334
5619
|
try {
|
|
5335
5620
|
const data = await collection.aggregate([
|
|
@@ -5351,9 +5636,9 @@ function useScheduleTaskRepository() {
|
|
|
5351
5636
|
throw new NotFoundError7("Schedule task not found.");
|
|
5352
5637
|
}
|
|
5353
5638
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
5354
|
-
|
|
5639
|
+
logger31.info(`Cache set for key: ${cacheKey}`);
|
|
5355
5640
|
}).catch((err) => {
|
|
5356
|
-
|
|
5641
|
+
logger31.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5357
5642
|
});
|
|
5358
5643
|
return data[0];
|
|
5359
5644
|
} catch (error) {
|
|
@@ -5362,7 +5647,7 @@ function useScheduleTaskRepository() {
|
|
|
5362
5647
|
}
|
|
5363
5648
|
async function updateScheduleTask(_id, value, session) {
|
|
5364
5649
|
try {
|
|
5365
|
-
_id = new
|
|
5650
|
+
_id = new ObjectId18(_id);
|
|
5366
5651
|
} catch (error) {
|
|
5367
5652
|
throw new BadRequestError29("Invalid schedule task ID format.");
|
|
5368
5653
|
}
|
|
@@ -5371,7 +5656,7 @@ function useScheduleTaskRepository() {
|
|
|
5371
5656
|
try {
|
|
5372
5657
|
return {
|
|
5373
5658
|
name: area.name,
|
|
5374
|
-
value: new
|
|
5659
|
+
value: new ObjectId18(area.value.toString())
|
|
5375
5660
|
};
|
|
5376
5661
|
} catch (error) {
|
|
5377
5662
|
throw new BadRequestError29(`Invalid area value format: ${area.name}`);
|
|
@@ -5386,14 +5671,14 @@ function useScheduleTaskRepository() {
|
|
|
5386
5671
|
{ session }
|
|
5387
5672
|
);
|
|
5388
5673
|
if (res.modifiedCount === 0) {
|
|
5389
|
-
throw new
|
|
5674
|
+
throw new InternalServerError11(
|
|
5390
5675
|
"Unable to update hygiene schedule task."
|
|
5391
5676
|
);
|
|
5392
5677
|
}
|
|
5393
5678
|
delNamespace().then(() => {
|
|
5394
|
-
|
|
5679
|
+
logger31.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5395
5680
|
}).catch((err) => {
|
|
5396
|
-
|
|
5681
|
+
logger31.error(
|
|
5397
5682
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5398
5683
|
err
|
|
5399
5684
|
);
|
|
@@ -5416,7 +5701,7 @@ function useScheduleTaskRepository() {
|
|
|
5416
5701
|
}
|
|
5417
5702
|
|
|
5418
5703
|
// src/services/hygiene-schedule-task.service.ts
|
|
5419
|
-
import { logger as
|
|
5704
|
+
import { logger as logger32 } from "@7365admin1/node-server-utils";
|
|
5420
5705
|
function useScheduleTaskService() {
|
|
5421
5706
|
const { createParentChecklist } = useParentChecklistRepo();
|
|
5422
5707
|
const { getAllScheduleTask } = useScheduleTaskRepository();
|
|
@@ -5439,13 +5724,13 @@ function useScheduleTaskService() {
|
|
|
5439
5724
|
const currentDateString = now.toLocaleDateString("en-US", {
|
|
5440
5725
|
timeZone: "Asia/Singapore"
|
|
5441
5726
|
});
|
|
5442
|
-
|
|
5727
|
+
logger32.info(
|
|
5443
5728
|
`Checking schedule ${schedule._id}: Current time ${currentHour}:${currentMinute}, Current date ${currentDateString}, Schedule time ${schedule.time}, Start date ${schedule.startDate}, End date ${schedule.endDate}`
|
|
5444
5729
|
);
|
|
5445
5730
|
const startDate = /* @__PURE__ */ new Date(schedule.startDate + "T00:00:00");
|
|
5446
5731
|
const currentDateOnly = /* @__PURE__ */ new Date(currentDateString + "T00:00:00");
|
|
5447
5732
|
if (currentDateOnly < startDate) {
|
|
5448
|
-
|
|
5733
|
+
logger32.info(
|
|
5449
5734
|
`Schedule ${schedule._id}: Current date ${currentDateString} is before start date ${schedule.startDate}`
|
|
5450
5735
|
);
|
|
5451
5736
|
return false;
|
|
@@ -5453,7 +5738,7 @@ function useScheduleTaskService() {
|
|
|
5453
5738
|
if (schedule.endDate) {
|
|
5454
5739
|
const endDate = /* @__PURE__ */ new Date(schedule.endDate + "T00:00:00");
|
|
5455
5740
|
if (currentDateOnly > endDate) {
|
|
5456
|
-
|
|
5741
|
+
logger32.info(
|
|
5457
5742
|
`Schedule ${schedule._id}: Current date ${currentDateString} is after end date ${schedule.endDate}`
|
|
5458
5743
|
);
|
|
5459
5744
|
return false;
|
|
@@ -5462,17 +5747,17 @@ function useScheduleTaskService() {
|
|
|
5462
5747
|
const [scheduleHour, scheduleMinute] = schedule.time.split(":").map(Number);
|
|
5463
5748
|
const timeMatches = currentHour === scheduleHour && currentMinute === scheduleMinute;
|
|
5464
5749
|
if (!timeMatches) {
|
|
5465
|
-
|
|
5750
|
+
logger32.info(
|
|
5466
5751
|
`Schedule ${schedule._id}: Time does not match. Current: ${currentHour}:${currentMinute}, Expected: ${scheduleHour}:${scheduleMinute}`
|
|
5467
5752
|
);
|
|
5468
5753
|
return false;
|
|
5469
5754
|
}
|
|
5470
|
-
|
|
5755
|
+
logger32.info(
|
|
5471
5756
|
`Schedule ${schedule._id}: All conditions matched - Date is within range and time matches`
|
|
5472
5757
|
);
|
|
5473
5758
|
return true;
|
|
5474
5759
|
} catch (error) {
|
|
5475
|
-
|
|
5760
|
+
logger32.error(
|
|
5476
5761
|
`Error checking schedule conditions for ${schedule._id}:`,
|
|
5477
5762
|
error
|
|
5478
5763
|
);
|
|
@@ -5481,40 +5766,40 @@ function useScheduleTaskService() {
|
|
|
5481
5766
|
}
|
|
5482
5767
|
async function processScheduledTasks(currentDate) {
|
|
5483
5768
|
try {
|
|
5484
|
-
|
|
5769
|
+
logger32.info("Starting scheduled task processing...");
|
|
5485
5770
|
const scheduleTasks = await getAllScheduleTask();
|
|
5486
5771
|
if (!scheduleTasks || scheduleTasks.length === 0) {
|
|
5487
|
-
|
|
5772
|
+
logger32.info("No schedule tasks found to process");
|
|
5488
5773
|
return { processed: 0, validated: 0 };
|
|
5489
5774
|
}
|
|
5490
|
-
|
|
5775
|
+
logger32.info(`Found ${scheduleTasks.length} schedule tasks to check`);
|
|
5491
5776
|
let processedCount = 0;
|
|
5492
5777
|
let validatedCount = 0;
|
|
5493
5778
|
const validatedTasks = [];
|
|
5494
5779
|
for (const scheduleTask of scheduleTasks) {
|
|
5495
5780
|
try {
|
|
5496
|
-
|
|
5781
|
+
logger32.info(
|
|
5497
5782
|
`Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time}, startDate=${scheduleTask.startDate}, endDate=${scheduleTask.endDate}`
|
|
5498
5783
|
);
|
|
5499
5784
|
const shouldRun = checkScheduleConditions(scheduleTask, currentDate);
|
|
5500
5785
|
if (!shouldRun) {
|
|
5501
|
-
|
|
5786
|
+
logger32.info(
|
|
5502
5787
|
`Schedule ${scheduleTask._id} conditions not met, skipping`
|
|
5503
5788
|
);
|
|
5504
5789
|
continue;
|
|
5505
5790
|
}
|
|
5506
|
-
|
|
5791
|
+
logger32.info(
|
|
5507
5792
|
`Schedule ${scheduleTask._id} conditions validated, creating area checklists`
|
|
5508
5793
|
);
|
|
5509
5794
|
if (!scheduleTask._id) {
|
|
5510
|
-
|
|
5795
|
+
logger32.warn(`Schedule ${scheduleTask.title} has no _id, skipping`);
|
|
5511
5796
|
continue;
|
|
5512
5797
|
}
|
|
5513
5798
|
if (!scheduleTask.site) {
|
|
5514
|
-
|
|
5799
|
+
logger32.warn(`Schedule ${scheduleTask._id} has no site, skipping`);
|
|
5515
5800
|
continue;
|
|
5516
5801
|
}
|
|
5517
|
-
|
|
5802
|
+
logger32.info(
|
|
5518
5803
|
`Getting or creating parent checklist for schedule ${scheduleTask._id} in site ${scheduleTask.site}`
|
|
5519
5804
|
);
|
|
5520
5805
|
const parentChecklistIds = await createParentChecklist({
|
|
@@ -5522,7 +5807,7 @@ function useScheduleTaskService() {
|
|
|
5522
5807
|
createdAt: /* @__PURE__ */ new Date()
|
|
5523
5808
|
});
|
|
5524
5809
|
const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
|
|
5525
|
-
|
|
5810
|
+
logger32.info(
|
|
5526
5811
|
`Using parent checklist ${parentChecklistId}, now creating/updating area checklists`
|
|
5527
5812
|
);
|
|
5528
5813
|
for (const area of scheduleTask.areas) {
|
|
@@ -5535,14 +5820,14 @@ function useScheduleTaskService() {
|
|
|
5535
5820
|
unit: unit.unit.toString(),
|
|
5536
5821
|
name: unit.name
|
|
5537
5822
|
}));
|
|
5538
|
-
|
|
5823
|
+
logger32.info(
|
|
5539
5824
|
`Area ${area.name} (${areaId}): Using units from area details: ${JSON.stringify(
|
|
5540
5825
|
units
|
|
5541
5826
|
)}`
|
|
5542
5827
|
);
|
|
5543
5828
|
}
|
|
5544
5829
|
if (units.length === 0) {
|
|
5545
|
-
|
|
5830
|
+
logger32.warn(
|
|
5546
5831
|
`Area ${area.name} (${areaId}): No units found, skipping area.`
|
|
5547
5832
|
);
|
|
5548
5833
|
continue;
|
|
@@ -5553,11 +5838,11 @@ function useScheduleTaskService() {
|
|
|
5553
5838
|
parentChecklistId.toString(),
|
|
5554
5839
|
areaId
|
|
5555
5840
|
);
|
|
5556
|
-
|
|
5841
|
+
logger32.info(
|
|
5557
5842
|
`Area ${area.name} (${areaId}): Existing area checklist found: ${existingAreaChecklist ? "Yes" : "No"}`
|
|
5558
5843
|
);
|
|
5559
5844
|
if (existingAreaChecklist) {
|
|
5560
|
-
|
|
5845
|
+
logger32.info(
|
|
5561
5846
|
`Area ${area.name} (${areaId}): Existing checklist content: ${JSON.stringify(
|
|
5562
5847
|
existingAreaChecklist.checklist
|
|
5563
5848
|
)}`
|
|
@@ -5565,7 +5850,7 @@ function useScheduleTaskService() {
|
|
|
5565
5850
|
}
|
|
5566
5851
|
} catch (error) {
|
|
5567
5852
|
existingAreaChecklist = null;
|
|
5568
|
-
|
|
5853
|
+
logger32.info(
|
|
5569
5854
|
`Area ${area.name} (${areaId}): No existing area checklist found (exception).`
|
|
5570
5855
|
);
|
|
5571
5856
|
}
|
|
@@ -5579,7 +5864,7 @@ function useScheduleTaskService() {
|
|
|
5579
5864
|
...existingAreaChecklist.checklist || [],
|
|
5580
5865
|
newSet
|
|
5581
5866
|
];
|
|
5582
|
-
|
|
5867
|
+
logger32.info(
|
|
5583
5868
|
`Area ${area.name} (${areaId}): Appending new set ${newSet.set} to checklist. Updated checklist: ${JSON.stringify(
|
|
5584
5869
|
updatedChecklist
|
|
5585
5870
|
)}`
|
|
@@ -5587,7 +5872,7 @@ function useScheduleTaskService() {
|
|
|
5587
5872
|
await updateAreaChecklist(existingAreaChecklist._id, {
|
|
5588
5873
|
checklist: updatedChecklist
|
|
5589
5874
|
});
|
|
5590
|
-
|
|
5875
|
+
logger32.info(
|
|
5591
5876
|
`Appended set ${newSet.set} to area checklist for area ${area.name}`
|
|
5592
5877
|
);
|
|
5593
5878
|
try {
|
|
@@ -5595,13 +5880,13 @@ function useScheduleTaskService() {
|
|
|
5595
5880
|
parentChecklistId.toString(),
|
|
5596
5881
|
areaId
|
|
5597
5882
|
);
|
|
5598
|
-
|
|
5883
|
+
logger32.info(
|
|
5599
5884
|
`Area ${area.name} (${areaId}): Checklist after update: ${JSON.stringify(
|
|
5600
5885
|
verifyChecklist.checklist
|
|
5601
5886
|
)}`
|
|
5602
5887
|
);
|
|
5603
5888
|
} catch (verifyError) {
|
|
5604
|
-
|
|
5889
|
+
logger32.warn(
|
|
5605
5890
|
`Area ${area.name} (${areaId}): Error verifying checklist after update:`,
|
|
5606
5891
|
verifyError
|
|
5607
5892
|
);
|
|
@@ -5620,50 +5905,50 @@ function useScheduleTaskService() {
|
|
|
5620
5905
|
],
|
|
5621
5906
|
createdBy: scheduleTask.createdBy
|
|
5622
5907
|
};
|
|
5623
|
-
|
|
5908
|
+
logger32.info(
|
|
5624
5909
|
`Area ${area.name} (${areaId}): Creating new area checklist with data: ${JSON.stringify(
|
|
5625
5910
|
checklistData
|
|
5626
5911
|
)}`
|
|
5627
5912
|
);
|
|
5628
5913
|
await createAreaChecklist(checklistData);
|
|
5629
|
-
|
|
5914
|
+
logger32.info(`Created new area checklist for area ${area.name}`);
|
|
5630
5915
|
try {
|
|
5631
5916
|
const verifyChecklist = await getAreaChecklistByAreaAndSchedule(
|
|
5632
5917
|
parentChecklistId.toString(),
|
|
5633
5918
|
areaId
|
|
5634
5919
|
);
|
|
5635
|
-
|
|
5920
|
+
logger32.info(
|
|
5636
5921
|
`Area ${area.name} (${areaId}): Checklist after creation: ${JSON.stringify(
|
|
5637
5922
|
verifyChecklist.checklist
|
|
5638
5923
|
)}`
|
|
5639
5924
|
);
|
|
5640
5925
|
} catch (verifyError) {
|
|
5641
|
-
|
|
5926
|
+
logger32.warn(
|
|
5642
5927
|
`Area ${area.name} (${areaId}): Error verifying checklist after creation:`,
|
|
5643
5928
|
verifyError
|
|
5644
5929
|
);
|
|
5645
5930
|
}
|
|
5646
5931
|
}
|
|
5647
5932
|
} catch (error) {
|
|
5648
|
-
|
|
5933
|
+
logger32.error(`Error processing area ${area.name}:`, error);
|
|
5649
5934
|
continue;
|
|
5650
5935
|
}
|
|
5651
5936
|
}
|
|
5652
5937
|
processedCount++;
|
|
5653
5938
|
validatedCount++;
|
|
5654
5939
|
validatedTasks.push(scheduleTask);
|
|
5655
|
-
|
|
5940
|
+
logger32.info(
|
|
5656
5941
|
`Successfully processed schedule ${scheduleTask._id}, created/updated area checklists for all areas.`
|
|
5657
5942
|
);
|
|
5658
5943
|
} catch (error) {
|
|
5659
|
-
|
|
5944
|
+
logger32.error(
|
|
5660
5945
|
`Error processing schedule task ${scheduleTask._id}:`,
|
|
5661
5946
|
error
|
|
5662
5947
|
);
|
|
5663
5948
|
continue;
|
|
5664
5949
|
}
|
|
5665
5950
|
}
|
|
5666
|
-
|
|
5951
|
+
logger32.info(
|
|
5667
5952
|
`Scheduled task processing completed. Processed: ${processedCount}, Validated: ${validatedCount} tasks`
|
|
5668
5953
|
);
|
|
5669
5954
|
return {
|
|
@@ -5672,7 +5957,7 @@ function useScheduleTaskService() {
|
|
|
5672
5957
|
tasks: validatedTasks
|
|
5673
5958
|
};
|
|
5674
5959
|
} catch (error) {
|
|
5675
|
-
|
|
5960
|
+
logger32.error("Error processing scheduled tasks:", error);
|
|
5676
5961
|
throw error;
|
|
5677
5962
|
}
|
|
5678
5963
|
}
|
|
@@ -5681,7 +5966,7 @@ function useScheduleTaskService() {
|
|
|
5681
5966
|
|
|
5682
5967
|
// src/controllers/hygiene-schedule-task.controller.ts
|
|
5683
5968
|
import Joi17 from "joi";
|
|
5684
|
-
import { BadRequestError as BadRequestError30, logger as
|
|
5969
|
+
import { BadRequestError as BadRequestError30, logger as logger33 } from "@7365admin1/node-server-utils";
|
|
5685
5970
|
function useScheduleTaskController() {
|
|
5686
5971
|
const {
|
|
5687
5972
|
createScheduleTask: _createScheduleTask,
|
|
@@ -5699,7 +5984,7 @@ function useScheduleTaskController() {
|
|
|
5699
5984
|
const payload = { ...req.body, ...req.params, createdBy };
|
|
5700
5985
|
const { error } = scheduleTaskSchema.validate(payload);
|
|
5701
5986
|
if (error) {
|
|
5702
|
-
|
|
5987
|
+
logger33.log({ level: "error", message: error.message });
|
|
5703
5988
|
next(new BadRequestError30(error.message));
|
|
5704
5989
|
return;
|
|
5705
5990
|
}
|
|
@@ -5708,7 +5993,7 @@ function useScheduleTaskController() {
|
|
|
5708
5993
|
res.status(201).json({ message: "Schedule task created successfully.", id });
|
|
5709
5994
|
return;
|
|
5710
5995
|
} catch (error2) {
|
|
5711
|
-
|
|
5996
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5712
5997
|
next(error2);
|
|
5713
5998
|
return;
|
|
5714
5999
|
}
|
|
@@ -5723,7 +6008,7 @@ function useScheduleTaskController() {
|
|
|
5723
6008
|
});
|
|
5724
6009
|
const { error } = validation.validate(query);
|
|
5725
6010
|
if (error) {
|
|
5726
|
-
|
|
6011
|
+
logger33.log({ level: "error", message: error.message });
|
|
5727
6012
|
next(new BadRequestError30(error.message));
|
|
5728
6013
|
return;
|
|
5729
6014
|
}
|
|
@@ -5741,7 +6026,7 @@ function useScheduleTaskController() {
|
|
|
5741
6026
|
res.json(data);
|
|
5742
6027
|
return;
|
|
5743
6028
|
} catch (error2) {
|
|
5744
|
-
|
|
6029
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5745
6030
|
next(error2);
|
|
5746
6031
|
return;
|
|
5747
6032
|
}
|
|
@@ -5756,7 +6041,7 @@ function useScheduleTaskController() {
|
|
|
5756
6041
|
});
|
|
5757
6042
|
const { error } = validation.validate(query);
|
|
5758
6043
|
if (error) {
|
|
5759
|
-
|
|
6044
|
+
logger33.log({ level: "error", message: error.message });
|
|
5760
6045
|
next(new BadRequestError30(error.message));
|
|
5761
6046
|
return;
|
|
5762
6047
|
}
|
|
@@ -5774,7 +6059,7 @@ function useScheduleTaskController() {
|
|
|
5774
6059
|
res.json(data);
|
|
5775
6060
|
return;
|
|
5776
6061
|
} catch (error2) {
|
|
5777
|
-
|
|
6062
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5778
6063
|
next(error2);
|
|
5779
6064
|
return;
|
|
5780
6065
|
}
|
|
@@ -5784,7 +6069,7 @@ function useScheduleTaskController() {
|
|
|
5784
6069
|
const _id = req.params.id;
|
|
5785
6070
|
const { error, value } = validation.validate(_id);
|
|
5786
6071
|
if (error) {
|
|
5787
|
-
|
|
6072
|
+
logger33.log({ level: "error", message: error.message });
|
|
5788
6073
|
next(new BadRequestError30(error.message));
|
|
5789
6074
|
return;
|
|
5790
6075
|
}
|
|
@@ -5793,7 +6078,7 @@ function useScheduleTaskController() {
|
|
|
5793
6078
|
res.json(data);
|
|
5794
6079
|
return;
|
|
5795
6080
|
} catch (error2) {
|
|
5796
|
-
|
|
6081
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5797
6082
|
next(error2);
|
|
5798
6083
|
return;
|
|
5799
6084
|
}
|
|
@@ -5816,7 +6101,7 @@ function useScheduleTaskController() {
|
|
|
5816
6101
|
});
|
|
5817
6102
|
const { error } = validation.validate(payload);
|
|
5818
6103
|
if (error) {
|
|
5819
|
-
|
|
6104
|
+
logger33.log({ level: "error", message: error.message });
|
|
5820
6105
|
next(new BadRequestError30(error.message));
|
|
5821
6106
|
return;
|
|
5822
6107
|
}
|
|
@@ -5826,7 +6111,7 @@ function useScheduleTaskController() {
|
|
|
5826
6111
|
res.json({ message: "Schedule task updated successfully." });
|
|
5827
6112
|
return;
|
|
5828
6113
|
} catch (error2) {
|
|
5829
|
-
|
|
6114
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5830
6115
|
next(error2);
|
|
5831
6116
|
return;
|
|
5832
6117
|
}
|
|
@@ -5841,8 +6126,8 @@ function useScheduleTaskController() {
|
|
|
5841
6126
|
}
|
|
5842
6127
|
|
|
5843
6128
|
// src/services/hygiene-qr.service.ts
|
|
5844
|
-
import { logger as
|
|
5845
|
-
import { launch } from "puppeteer";
|
|
6129
|
+
import { logger as logger34 } from "@7365admin1/node-server-utils";
|
|
6130
|
+
import { launch as launch2 } from "puppeteer";
|
|
5846
6131
|
import QRCode from "qrcode";
|
|
5847
6132
|
function useQRService() {
|
|
5848
6133
|
async function generateQRDataUrl(qrUrl) {
|
|
@@ -5859,7 +6144,7 @@ function useQRService() {
|
|
|
5859
6144
|
async function generateQRImage(qrUrl) {
|
|
5860
6145
|
try {
|
|
5861
6146
|
const qrDataUrl = await generateQRDataUrl(qrUrl);
|
|
5862
|
-
const browser = await
|
|
6147
|
+
const browser = await launch2({
|
|
5863
6148
|
headless: true,
|
|
5864
6149
|
executablePath: process.env.CHROME_BINARY,
|
|
5865
6150
|
args: [`--no-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`]
|
|
@@ -5912,7 +6197,7 @@ function useQRService() {
|
|
|
5912
6197
|
await browser.close();
|
|
5913
6198
|
return imageBuffer;
|
|
5914
6199
|
} catch (error) {
|
|
5915
|
-
|
|
6200
|
+
logger34.log({
|
|
5916
6201
|
level: "error",
|
|
5917
6202
|
message: `Failed to generate QR image: ${error.message}`
|
|
5918
6203
|
});
|
|
@@ -5922,7 +6207,7 @@ function useQRService() {
|
|
|
5922
6207
|
async function generateQRPDF(qrUrl, title) {
|
|
5923
6208
|
try {
|
|
5924
6209
|
const qrDataUrl = await generateQRDataUrl(qrUrl);
|
|
5925
|
-
const browser = await
|
|
6210
|
+
const browser = await launch2({
|
|
5926
6211
|
headless: true,
|
|
5927
6212
|
executablePath: process.env.CHROME_BINARY,
|
|
5928
6213
|
args: [`--no-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`]
|
|
@@ -6035,7 +6320,7 @@ function useQRService() {
|
|
|
6035
6320
|
await browser.close();
|
|
6036
6321
|
return pdfBuffer;
|
|
6037
6322
|
} catch (error) {
|
|
6038
|
-
|
|
6323
|
+
logger34.log({
|
|
6039
6324
|
level: "error",
|
|
6040
6325
|
message: `Failed to generate QR PDF: ${error.message}`
|
|
6041
6326
|
});
|
|
@@ -6050,7 +6335,7 @@ function useQRService() {
|
|
|
6050
6335
|
|
|
6051
6336
|
// src/controllers/hygiene-qr.controller.ts
|
|
6052
6337
|
import Joi18 from "joi";
|
|
6053
|
-
import { BadRequestError as BadRequestError31, logger as
|
|
6338
|
+
import { BadRequestError as BadRequestError31, logger as logger35 } from "@7365admin1/node-server-utils";
|
|
6054
6339
|
function useQRController() {
|
|
6055
6340
|
const { generateQRImage: _generateQRImage, generateQRPDF: _generateQRPDF } = useQRService();
|
|
6056
6341
|
async function generateQR(req, res, next) {
|
|
@@ -6063,7 +6348,7 @@ function useQRController() {
|
|
|
6063
6348
|
const query = { ...req.query };
|
|
6064
6349
|
const { error, value } = validation.validate(query);
|
|
6065
6350
|
if (error) {
|
|
6066
|
-
|
|
6351
|
+
logger35.log({ level: "error", message: error.message });
|
|
6067
6352
|
next(new BadRequestError31(error.message));
|
|
6068
6353
|
return;
|
|
6069
6354
|
}
|
|
@@ -6099,7 +6384,7 @@ function useQRController() {
|
|
|
6099
6384
|
}
|
|
6100
6385
|
return;
|
|
6101
6386
|
} catch (error2) {
|
|
6102
|
-
|
|
6387
|
+
logger35.log({ level: "error", message: error2.message });
|
|
6103
6388
|
next(error2);
|
|
6104
6389
|
return;
|
|
6105
6390
|
}
|