@7365admin1/module-hygiene 4.6.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 +12 -0
- package/dist/index.d.ts +4 -1
- package/dist/index.js +584 -283
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +518 -217
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
package/dist/index.mjs
CHANGED
|
@@ -3096,12 +3096,48 @@ 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,
|
|
3102
3134
|
set: "$checklist.set",
|
|
3135
|
+
remarks: "$checklist.remarks",
|
|
3136
|
+
attachment: "$checklist.attachment",
|
|
3103
3137
|
unit: "$checklist.units.unit",
|
|
3104
3138
|
name: "$checklist.units.name",
|
|
3139
|
+
approve: "$checklist.units.approve",
|
|
3140
|
+
reject: "$checklist.units.reject",
|
|
3105
3141
|
status: {
|
|
3106
3142
|
$switch: {
|
|
3107
3143
|
branches: [
|
|
@@ -3117,19 +3153,24 @@ function useAreaChecklistRepo() {
|
|
|
3117
3153
|
default: "$checklist.units.status"
|
|
3118
3154
|
}
|
|
3119
3155
|
},
|
|
3120
|
-
|
|
3156
|
+
completedByName: "$completedBy.name"
|
|
3121
3157
|
}
|
|
3122
3158
|
},
|
|
3123
|
-
{ $sort: { set: 1, name: 1 } },
|
|
3124
3159
|
{
|
|
3125
3160
|
$group: {
|
|
3126
3161
|
_id: "$set",
|
|
3162
|
+
remarks: { $first: "$remarks" },
|
|
3163
|
+
attachment: { $first: "$attachment" },
|
|
3164
|
+
completedByName: { $first: "$completedByName" },
|
|
3127
3165
|
units: {
|
|
3128
3166
|
$push: {
|
|
3129
3167
|
unit: "$unit",
|
|
3130
3168
|
name: "$name",
|
|
3169
|
+
approve: "$approve",
|
|
3170
|
+
reject: "$reject",
|
|
3131
3171
|
status: "$status",
|
|
3132
|
-
remarks: "$remarks"
|
|
3172
|
+
remarks: "$remarks",
|
|
3173
|
+
completedByName: "$completedByName"
|
|
3133
3174
|
}
|
|
3134
3175
|
}
|
|
3135
3176
|
}
|
|
@@ -3138,6 +3179,9 @@ function useAreaChecklistRepo() {
|
|
|
3138
3179
|
$project: {
|
|
3139
3180
|
_id: 0,
|
|
3140
3181
|
set: "$_id",
|
|
3182
|
+
remarks: "$remarks",
|
|
3183
|
+
attachment: "$attachment",
|
|
3184
|
+
completedByName: 1,
|
|
3141
3185
|
units: 1
|
|
3142
3186
|
}
|
|
3143
3187
|
},
|
|
@@ -3241,6 +3285,12 @@ function useAreaChecklistRepo() {
|
|
|
3241
3285
|
if (value.remarks) {
|
|
3242
3286
|
updateValue["checklist.$[checklist].units.$[unit].remarks"] = value.remarks;
|
|
3243
3287
|
}
|
|
3288
|
+
if (value.attachment) {
|
|
3289
|
+
updateValue["checklist.$[checklist].attachment"] = value.attachment;
|
|
3290
|
+
if (value.remarks) {
|
|
3291
|
+
updateValue["checklist.$[checklist].remarks"] = value.remarks;
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3244
3294
|
if (value.completedBy) {
|
|
3245
3295
|
updateValue["checklist.$[checklist].units.$[unit].completedBy"] = new ObjectId9(value.completedBy);
|
|
3246
3296
|
}
|
|
@@ -3541,7 +3591,223 @@ function useAreaChecklistService() {
|
|
|
3541
3591
|
|
|
3542
3592
|
// src/controllers/hygiene-area-checklist.controller.ts
|
|
3543
3593
|
import Joi9 from "joi";
|
|
3544
|
-
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
|
|
3545
3811
|
function useAreaChecklistController() {
|
|
3546
3812
|
const {
|
|
3547
3813
|
getAllAreaChecklist: _getAllAreaChecklist,
|
|
@@ -3553,6 +3819,7 @@ function useAreaChecklistController() {
|
|
|
3553
3819
|
createAreaChecklist: _createAreaChecklist,
|
|
3554
3820
|
updateAreaChecklistUnits: _updateAreaChecklistUnits
|
|
3555
3821
|
} = useAreaChecklistService();
|
|
3822
|
+
const { generateChecklistPdf: _generateChecklistPdf } = useChecklistPdfService();
|
|
3556
3823
|
async function createAreaChecklist(req, res, next) {
|
|
3557
3824
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
3558
3825
|
(acc, [key, value2]) => ({ ...acc, [key]: value2 }),
|
|
@@ -3571,7 +3838,7 @@ function useAreaChecklistController() {
|
|
|
3571
3838
|
});
|
|
3572
3839
|
const { error, value } = validation.validate(payload);
|
|
3573
3840
|
if (error) {
|
|
3574
|
-
|
|
3841
|
+
logger20.log({ level: "error", message: error.message });
|
|
3575
3842
|
next(new BadRequestError16(error.message));
|
|
3576
3843
|
return;
|
|
3577
3844
|
}
|
|
@@ -3580,7 +3847,7 @@ function useAreaChecklistController() {
|
|
|
3580
3847
|
res.status(201).json({ message: "Area checklist generated successfully." });
|
|
3581
3848
|
return;
|
|
3582
3849
|
} catch (error2) {
|
|
3583
|
-
|
|
3850
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3584
3851
|
next(error2);
|
|
3585
3852
|
return;
|
|
3586
3853
|
}
|
|
@@ -3597,7 +3864,7 @@ function useAreaChecklistController() {
|
|
|
3597
3864
|
});
|
|
3598
3865
|
const { error } = validation.validate(query);
|
|
3599
3866
|
if (error) {
|
|
3600
|
-
|
|
3867
|
+
logger20.log({ level: "error", message: error.message });
|
|
3601
3868
|
next(new BadRequestError16(error.message));
|
|
3602
3869
|
return;
|
|
3603
3870
|
}
|
|
@@ -3619,7 +3886,7 @@ function useAreaChecklistController() {
|
|
|
3619
3886
|
res.json(data);
|
|
3620
3887
|
return;
|
|
3621
3888
|
} catch (error2) {
|
|
3622
|
-
|
|
3889
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3623
3890
|
next(error2);
|
|
3624
3891
|
return;
|
|
3625
3892
|
}
|
|
@@ -3637,7 +3904,7 @@ function useAreaChecklistController() {
|
|
|
3637
3904
|
});
|
|
3638
3905
|
const { error } = validation.validate(query);
|
|
3639
3906
|
if (error) {
|
|
3640
|
-
|
|
3907
|
+
logger20.log({ level: "error", message: error.message });
|
|
3641
3908
|
next(new BadRequestError16(error.message));
|
|
3642
3909
|
return;
|
|
3643
3910
|
}
|
|
@@ -3661,7 +3928,7 @@ function useAreaChecklistController() {
|
|
|
3661
3928
|
res.json(data);
|
|
3662
3929
|
return;
|
|
3663
3930
|
} catch (error2) {
|
|
3664
|
-
|
|
3931
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3665
3932
|
next(error2);
|
|
3666
3933
|
return;
|
|
3667
3934
|
}
|
|
@@ -3671,7 +3938,7 @@ function useAreaChecklistController() {
|
|
|
3671
3938
|
const _id = req.params.id;
|
|
3672
3939
|
const { error, value } = validation.validate(_id);
|
|
3673
3940
|
if (error) {
|
|
3674
|
-
|
|
3941
|
+
logger20.log({ level: "error", message: error.message });
|
|
3675
3942
|
next(new BadRequestError16(error.message));
|
|
3676
3943
|
return;
|
|
3677
3944
|
}
|
|
@@ -3680,7 +3947,7 @@ function useAreaChecklistController() {
|
|
|
3680
3947
|
res.json(data);
|
|
3681
3948
|
return;
|
|
3682
3949
|
} catch (error2) {
|
|
3683
|
-
|
|
3950
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3684
3951
|
next(error2);
|
|
3685
3952
|
return;
|
|
3686
3953
|
}
|
|
@@ -3695,7 +3962,7 @@ function useAreaChecklistController() {
|
|
|
3695
3962
|
});
|
|
3696
3963
|
const { error } = validation.validate(query);
|
|
3697
3964
|
if (error) {
|
|
3698
|
-
|
|
3965
|
+
logger20.log({ level: "error", message: error.message });
|
|
3699
3966
|
next(new BadRequestError16(error.message));
|
|
3700
3967
|
return;
|
|
3701
3968
|
}
|
|
@@ -3713,7 +3980,7 @@ function useAreaChecklistController() {
|
|
|
3713
3980
|
res.json(data);
|
|
3714
3981
|
return;
|
|
3715
3982
|
} catch (error2) {
|
|
3716
|
-
|
|
3983
|
+
logger20.log({ level: "error", message: error2.message });
|
|
3717
3984
|
next(error2);
|
|
3718
3985
|
return;
|
|
3719
3986
|
}
|
|
@@ -3747,11 +4014,12 @@ function useAreaChecklistController() {
|
|
|
3747
4014
|
approve: Joi9.boolean().optional(),
|
|
3748
4015
|
reject: Joi9.boolean().optional(),
|
|
3749
4016
|
remarks: Joi9.string().optional().allow("", null),
|
|
4017
|
+
attachment: Joi9.array().items(Joi9.string()).optional(),
|
|
3750
4018
|
completedBy: Joi9.string().hex().required()
|
|
3751
4019
|
});
|
|
3752
4020
|
const { error } = validation.validate(payload);
|
|
3753
4021
|
if (error) {
|
|
3754
|
-
|
|
4022
|
+
logger20.log({ level: "error", message: error.message });
|
|
3755
4023
|
next(new BadRequestError16(error.message));
|
|
3756
4024
|
return;
|
|
3757
4025
|
}
|
|
@@ -3761,7 +4029,39 @@ function useAreaChecklistController() {
|
|
|
3761
4029
|
res.json({ message: "Area checklist updated successfully." });
|
|
3762
4030
|
return;
|
|
3763
4031
|
} catch (error2) {
|
|
3764
|
-
|
|
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 });
|
|
3765
4065
|
next(error2);
|
|
3766
4066
|
return;
|
|
3767
4067
|
}
|
|
@@ -3772,14 +4072,15 @@ function useAreaChecklistController() {
|
|
|
3772
4072
|
getAreaChecklistHistory,
|
|
3773
4073
|
getAreaChecklistHistoryDetails,
|
|
3774
4074
|
getAreaChecklistUnits,
|
|
3775
|
-
updateAreaChecklistUnits
|
|
4075
|
+
updateAreaChecklistUnits,
|
|
4076
|
+
downloadChecklistPdf
|
|
3776
4077
|
};
|
|
3777
4078
|
}
|
|
3778
4079
|
|
|
3779
4080
|
// src/models/hygiene-supply.model.ts
|
|
3780
4081
|
import Joi10 from "joi";
|
|
3781
|
-
import { ObjectId as
|
|
3782
|
-
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";
|
|
3783
4084
|
var supplySchema = Joi10.object({
|
|
3784
4085
|
site: Joi10.string().hex().required(),
|
|
3785
4086
|
name: Joi10.string().required(),
|
|
@@ -3788,12 +4089,12 @@ var supplySchema = Joi10.object({
|
|
|
3788
4089
|
function MSupply(value) {
|
|
3789
4090
|
const { error } = supplySchema.validate(value);
|
|
3790
4091
|
if (error) {
|
|
3791
|
-
|
|
4092
|
+
logger21.info(`Hygiene Supply Model: ${error.message}`);
|
|
3792
4093
|
throw new BadRequestError17(error.message);
|
|
3793
4094
|
}
|
|
3794
4095
|
if (value.site) {
|
|
3795
4096
|
try {
|
|
3796
|
-
value.site = new
|
|
4097
|
+
value.site = new ObjectId11(value.site);
|
|
3797
4098
|
} catch (error2) {
|
|
3798
4099
|
throw new BadRequestError17("Invalid site ID format.");
|
|
3799
4100
|
}
|
|
@@ -3811,21 +4112,21 @@ function MSupply(value) {
|
|
|
3811
4112
|
}
|
|
3812
4113
|
|
|
3813
4114
|
// src/repositories/hygiene-supply.repository.ts
|
|
3814
|
-
import { ObjectId as
|
|
4115
|
+
import { ObjectId as ObjectId12 } from "mongodb";
|
|
3815
4116
|
import {
|
|
3816
|
-
useAtlas as
|
|
3817
|
-
InternalServerError as
|
|
4117
|
+
useAtlas as useAtlas9,
|
|
4118
|
+
InternalServerError as InternalServerError8,
|
|
3818
4119
|
paginate as paginate5,
|
|
3819
4120
|
BadRequestError as BadRequestError18,
|
|
3820
4121
|
useCache as useCache6,
|
|
3821
|
-
logger as
|
|
4122
|
+
logger as logger22,
|
|
3822
4123
|
makeCacheKey as makeCacheKey6,
|
|
3823
4124
|
NotFoundError as NotFoundError4
|
|
3824
4125
|
} from "@7365admin1/node-server-utils";
|
|
3825
4126
|
function useSupplyRepository() {
|
|
3826
|
-
const db =
|
|
4127
|
+
const db = useAtlas9.getDb();
|
|
3827
4128
|
if (!db) {
|
|
3828
|
-
throw new
|
|
4129
|
+
throw new InternalServerError8("Unable to connect to server.");
|
|
3829
4130
|
}
|
|
3830
4131
|
const namespace_collection = "site.supplies";
|
|
3831
4132
|
const collection = db.collection(namespace_collection);
|
|
@@ -3834,7 +4135,7 @@ function useSupplyRepository() {
|
|
|
3834
4135
|
try {
|
|
3835
4136
|
await collection.createIndexes([{ key: { site: 1 } }]);
|
|
3836
4137
|
} catch (error) {
|
|
3837
|
-
throw new
|
|
4138
|
+
throw new InternalServerError8(
|
|
3838
4139
|
"Failed to create index on hygiene supply."
|
|
3839
4140
|
);
|
|
3840
4141
|
}
|
|
@@ -3843,7 +4144,7 @@ function useSupplyRepository() {
|
|
|
3843
4144
|
try {
|
|
3844
4145
|
await collection.createIndex({ name: "text" });
|
|
3845
4146
|
} catch (error) {
|
|
3846
|
-
throw new
|
|
4147
|
+
throw new InternalServerError8(
|
|
3847
4148
|
"Failed to create text index on hygiene supply."
|
|
3848
4149
|
);
|
|
3849
4150
|
}
|
|
@@ -3855,7 +4156,7 @@ function useSupplyRepository() {
|
|
|
3855
4156
|
{ unique: true }
|
|
3856
4157
|
);
|
|
3857
4158
|
} catch (error) {
|
|
3858
|
-
throw new
|
|
4159
|
+
throw new InternalServerError8(
|
|
3859
4160
|
"Failed to create unique index on hygiene supply."
|
|
3860
4161
|
);
|
|
3861
4162
|
}
|
|
@@ -3865,9 +4166,9 @@ function useSupplyRepository() {
|
|
|
3865
4166
|
value = MSupply(value);
|
|
3866
4167
|
const res = await collection.insertOne(value, { session });
|
|
3867
4168
|
delNamespace().then(() => {
|
|
3868
|
-
|
|
4169
|
+
logger22.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
3869
4170
|
}).catch((err) => {
|
|
3870
|
-
|
|
4171
|
+
logger22.error(
|
|
3871
4172
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
3872
4173
|
err
|
|
3873
4174
|
);
|
|
@@ -3896,7 +4197,7 @@ function useSupplyRepository() {
|
|
|
3896
4197
|
limit
|
|
3897
4198
|
};
|
|
3898
4199
|
try {
|
|
3899
|
-
site = new
|
|
4200
|
+
site = new ObjectId12(site);
|
|
3900
4201
|
query.site = site;
|
|
3901
4202
|
cacheOptions.site = site.toString();
|
|
3902
4203
|
} catch (error) {
|
|
@@ -3909,7 +4210,7 @@ function useSupplyRepository() {
|
|
|
3909
4210
|
const cacheKey = makeCacheKey6(namespace_collection, cacheOptions);
|
|
3910
4211
|
const cachedData = await getCache(cacheKey);
|
|
3911
4212
|
if (cachedData) {
|
|
3912
|
-
|
|
4213
|
+
logger22.info(`Cache hit for key: ${cacheKey}`);
|
|
3913
4214
|
return cachedData;
|
|
3914
4215
|
}
|
|
3915
4216
|
try {
|
|
@@ -3929,9 +4230,9 @@ function useSupplyRepository() {
|
|
|
3929
4230
|
const length = await collection.countDocuments(query);
|
|
3930
4231
|
const data = paginate5(items, page, limit, length);
|
|
3931
4232
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
3932
|
-
|
|
4233
|
+
logger22.info(`Cache set for key: ${cacheKey}`);
|
|
3933
4234
|
}).catch((err) => {
|
|
3934
|
-
|
|
4235
|
+
logger22.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
3935
4236
|
});
|
|
3936
4237
|
return data;
|
|
3937
4238
|
} catch (error) {
|
|
@@ -3940,7 +4241,7 @@ function useSupplyRepository() {
|
|
|
3940
4241
|
}
|
|
3941
4242
|
async function getSupplyById(_id, session) {
|
|
3942
4243
|
try {
|
|
3943
|
-
_id = new
|
|
4244
|
+
_id = new ObjectId12(_id);
|
|
3944
4245
|
} catch (error) {
|
|
3945
4246
|
throw new BadRequestError18("Invalid supply ID format.");
|
|
3946
4247
|
}
|
|
@@ -3954,11 +4255,11 @@ function useSupplyRepository() {
|
|
|
3954
4255
|
if (!session) {
|
|
3955
4256
|
const cachedData = await getCache(cacheKey);
|
|
3956
4257
|
if (cachedData) {
|
|
3957
|
-
|
|
4258
|
+
logger22.info(`Cache hit for key: ${cacheKey}`);
|
|
3958
4259
|
return cachedData;
|
|
3959
4260
|
}
|
|
3960
4261
|
} else {
|
|
3961
|
-
|
|
4262
|
+
logger22.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
3962
4263
|
}
|
|
3963
4264
|
try {
|
|
3964
4265
|
const data = await collection.aggregate([
|
|
@@ -3975,9 +4276,9 @@ function useSupplyRepository() {
|
|
|
3975
4276
|
throw new NotFoundError4("Supply not found.");
|
|
3976
4277
|
}
|
|
3977
4278
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
3978
|
-
|
|
4279
|
+
logger22.info(`Cache set for key: ${cacheKey}`);
|
|
3979
4280
|
}).catch((err) => {
|
|
3980
|
-
|
|
4281
|
+
logger22.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
3981
4282
|
});
|
|
3982
4283
|
return data[0];
|
|
3983
4284
|
} catch (error) {
|
|
@@ -3986,7 +4287,7 @@ function useSupplyRepository() {
|
|
|
3986
4287
|
}
|
|
3987
4288
|
async function updateSupply(_id, value, session) {
|
|
3988
4289
|
try {
|
|
3989
|
-
_id = new
|
|
4290
|
+
_id = new ObjectId12(_id);
|
|
3990
4291
|
} catch (error) {
|
|
3991
4292
|
throw new BadRequestError18("Invalid supply ID format.");
|
|
3992
4293
|
}
|
|
@@ -3998,12 +4299,12 @@ function useSupplyRepository() {
|
|
|
3998
4299
|
{ session }
|
|
3999
4300
|
);
|
|
4000
4301
|
if (res.modifiedCount === 0) {
|
|
4001
|
-
throw new
|
|
4302
|
+
throw new InternalServerError8("Unable to update cleaning supply.");
|
|
4002
4303
|
}
|
|
4003
4304
|
delNamespace().then(() => {
|
|
4004
|
-
|
|
4305
|
+
logger22.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4005
4306
|
}).catch((err) => {
|
|
4006
|
-
|
|
4307
|
+
logger22.error(
|
|
4007
4308
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4008
4309
|
err
|
|
4009
4310
|
);
|
|
@@ -4019,7 +4320,7 @@ function useSupplyRepository() {
|
|
|
4019
4320
|
}
|
|
4020
4321
|
async function deleteSupply(_id, session) {
|
|
4021
4322
|
try {
|
|
4022
|
-
_id = new
|
|
4323
|
+
_id = new ObjectId12(_id);
|
|
4023
4324
|
} catch (error) {
|
|
4024
4325
|
throw new BadRequestError18("Invalid supply ID format.");
|
|
4025
4326
|
}
|
|
@@ -4035,12 +4336,12 @@ function useSupplyRepository() {
|
|
|
4035
4336
|
{ session }
|
|
4036
4337
|
);
|
|
4037
4338
|
if (res.modifiedCount === 0) {
|
|
4038
|
-
throw new
|
|
4339
|
+
throw new InternalServerError8("Unable to delete supply.");
|
|
4039
4340
|
}
|
|
4040
4341
|
delNamespace().then(() => {
|
|
4041
|
-
|
|
4342
|
+
logger22.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4042
4343
|
}).catch((err) => {
|
|
4043
|
-
|
|
4344
|
+
logger22.error(
|
|
4044
4345
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4045
4346
|
err
|
|
4046
4347
|
);
|
|
@@ -4064,7 +4365,7 @@ function useSupplyRepository() {
|
|
|
4064
4365
|
|
|
4065
4366
|
// src/controllers/hygiene-supply.controller.ts
|
|
4066
4367
|
import Joi11 from "joi";
|
|
4067
|
-
import { BadRequestError as BadRequestError19, logger as
|
|
4368
|
+
import { BadRequestError as BadRequestError19, logger as logger23 } from "@7365admin1/node-server-utils";
|
|
4068
4369
|
function useSupplyController() {
|
|
4069
4370
|
const {
|
|
4070
4371
|
createSupply: _createSupply,
|
|
@@ -4077,7 +4378,7 @@ function useSupplyController() {
|
|
|
4077
4378
|
const payload = { ...req.body, ...req.params };
|
|
4078
4379
|
const { error } = supplySchema.validate(payload);
|
|
4079
4380
|
if (error) {
|
|
4080
|
-
|
|
4381
|
+
logger23.log({ level: "error", message: error.message });
|
|
4081
4382
|
next(new BadRequestError19(error.message));
|
|
4082
4383
|
return;
|
|
4083
4384
|
}
|
|
@@ -4086,7 +4387,7 @@ function useSupplyController() {
|
|
|
4086
4387
|
res.status(201).json({ message: "Supply created successfully.", id });
|
|
4087
4388
|
return;
|
|
4088
4389
|
} catch (error2) {
|
|
4089
|
-
|
|
4390
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4090
4391
|
next(error2);
|
|
4091
4392
|
return;
|
|
4092
4393
|
}
|
|
@@ -4101,7 +4402,7 @@ function useSupplyController() {
|
|
|
4101
4402
|
});
|
|
4102
4403
|
const { error } = validation.validate(query);
|
|
4103
4404
|
if (error) {
|
|
4104
|
-
|
|
4405
|
+
logger23.log({ level: "error", message: error.message });
|
|
4105
4406
|
next(new BadRequestError19(error.message));
|
|
4106
4407
|
return;
|
|
4107
4408
|
}
|
|
@@ -4119,7 +4420,7 @@ function useSupplyController() {
|
|
|
4119
4420
|
res.json(data);
|
|
4120
4421
|
return;
|
|
4121
4422
|
} catch (error2) {
|
|
4122
|
-
|
|
4423
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4123
4424
|
next(error2);
|
|
4124
4425
|
return;
|
|
4125
4426
|
}
|
|
@@ -4129,7 +4430,7 @@ function useSupplyController() {
|
|
|
4129
4430
|
const _id = req.params.id;
|
|
4130
4431
|
const { error, value } = validation.validate(_id);
|
|
4131
4432
|
if (error) {
|
|
4132
|
-
|
|
4433
|
+
logger23.log({ level: "error", message: error.message });
|
|
4133
4434
|
next(new BadRequestError19(error.message));
|
|
4134
4435
|
return;
|
|
4135
4436
|
}
|
|
@@ -4138,7 +4439,7 @@ function useSupplyController() {
|
|
|
4138
4439
|
res.json(data);
|
|
4139
4440
|
return;
|
|
4140
4441
|
} catch (error2) {
|
|
4141
|
-
|
|
4442
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4142
4443
|
next(error2);
|
|
4143
4444
|
return;
|
|
4144
4445
|
}
|
|
@@ -4153,7 +4454,7 @@ function useSupplyController() {
|
|
|
4153
4454
|
});
|
|
4154
4455
|
const { error } = validation.validate(payload);
|
|
4155
4456
|
if (error) {
|
|
4156
|
-
|
|
4457
|
+
logger23.log({ level: "error", message: error.message });
|
|
4157
4458
|
next(new BadRequestError19(error.message));
|
|
4158
4459
|
return;
|
|
4159
4460
|
}
|
|
@@ -4163,7 +4464,7 @@ function useSupplyController() {
|
|
|
4163
4464
|
res.json({ message: "Supply updated successfully." });
|
|
4164
4465
|
return;
|
|
4165
4466
|
} catch (error2) {
|
|
4166
|
-
|
|
4467
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4167
4468
|
next(error2);
|
|
4168
4469
|
return;
|
|
4169
4470
|
}
|
|
@@ -4175,7 +4476,7 @@ function useSupplyController() {
|
|
|
4175
4476
|
});
|
|
4176
4477
|
const { error, value } = validation.validate({ id });
|
|
4177
4478
|
if (error) {
|
|
4178
|
-
|
|
4479
|
+
logger23.log({ level: "error", message: error.message });
|
|
4179
4480
|
next(new BadRequestError19(error.message));
|
|
4180
4481
|
return;
|
|
4181
4482
|
}
|
|
@@ -4184,7 +4485,7 @@ function useSupplyController() {
|
|
|
4184
4485
|
res.json({ message: "Supply deleted successfully." });
|
|
4185
4486
|
return;
|
|
4186
4487
|
} catch (error2) {
|
|
4187
|
-
|
|
4488
|
+
logger23.log({ level: "error", message: error2.message });
|
|
4188
4489
|
next(error2);
|
|
4189
4490
|
return;
|
|
4190
4491
|
}
|
|
@@ -4200,8 +4501,8 @@ function useSupplyController() {
|
|
|
4200
4501
|
|
|
4201
4502
|
// src/models/hygiene-stock.model.ts
|
|
4202
4503
|
import Joi12 from "joi";
|
|
4203
|
-
import { ObjectId as
|
|
4204
|
-
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";
|
|
4205
4506
|
var stockSchema = Joi12.object({
|
|
4206
4507
|
site: Joi12.string().hex().required(),
|
|
4207
4508
|
supply: Joi12.string().hex().required(),
|
|
@@ -4213,19 +4514,19 @@ var stockSchema = Joi12.object({
|
|
|
4213
4514
|
function MStock(value) {
|
|
4214
4515
|
const { error } = stockSchema.validate(value);
|
|
4215
4516
|
if (error) {
|
|
4216
|
-
|
|
4517
|
+
logger24.info(`Hygiene Stock Model: ${error.message}`);
|
|
4217
4518
|
throw new BadRequestError20(error.message);
|
|
4218
4519
|
}
|
|
4219
4520
|
if (value.site) {
|
|
4220
4521
|
try {
|
|
4221
|
-
value.site = new
|
|
4522
|
+
value.site = new ObjectId13(value.site);
|
|
4222
4523
|
} catch (error2) {
|
|
4223
4524
|
throw new BadRequestError20("Invalid site ID format.");
|
|
4224
4525
|
}
|
|
4225
4526
|
}
|
|
4226
4527
|
if (value.supply) {
|
|
4227
4528
|
try {
|
|
4228
|
-
value.supply = new
|
|
4529
|
+
value.supply = new ObjectId13(value.supply);
|
|
4229
4530
|
} catch (error2) {
|
|
4230
4531
|
throw new BadRequestError20("Invalid supply ID format.");
|
|
4231
4532
|
}
|
|
@@ -4245,20 +4546,20 @@ function MStock(value) {
|
|
|
4245
4546
|
}
|
|
4246
4547
|
|
|
4247
4548
|
// src/repositories/hygiene-stock.repository.ts
|
|
4248
|
-
import { ObjectId as
|
|
4549
|
+
import { ObjectId as ObjectId14 } from "mongodb";
|
|
4249
4550
|
import {
|
|
4250
|
-
useAtlas as
|
|
4251
|
-
InternalServerError as
|
|
4551
|
+
useAtlas as useAtlas10,
|
|
4552
|
+
InternalServerError as InternalServerError9,
|
|
4252
4553
|
BadRequestError as BadRequestError21,
|
|
4253
4554
|
useCache as useCache7,
|
|
4254
|
-
logger as
|
|
4555
|
+
logger as logger25,
|
|
4255
4556
|
makeCacheKey as makeCacheKey7,
|
|
4256
4557
|
paginate as paginate6
|
|
4257
4558
|
} from "@7365admin1/node-server-utils";
|
|
4258
4559
|
function useStockRepository() {
|
|
4259
|
-
const db =
|
|
4560
|
+
const db = useAtlas10.getDb();
|
|
4260
4561
|
if (!db) {
|
|
4261
|
-
throw new
|
|
4562
|
+
throw new InternalServerError9("Unable to connect to server.");
|
|
4262
4563
|
}
|
|
4263
4564
|
const namespace_collection = "site.supply.stocks";
|
|
4264
4565
|
const supply_collection = "site.supplies";
|
|
@@ -4274,7 +4575,7 @@ function useStockRepository() {
|
|
|
4274
4575
|
{ key: { status: 1 } }
|
|
4275
4576
|
]);
|
|
4276
4577
|
} catch (error) {
|
|
4277
|
-
throw new
|
|
4578
|
+
throw new InternalServerError9("Failed to create index on hygiene stock.");
|
|
4278
4579
|
}
|
|
4279
4580
|
}
|
|
4280
4581
|
async function createStock(value, session) {
|
|
@@ -4282,17 +4583,17 @@ function useStockRepository() {
|
|
|
4282
4583
|
value = MStock(value);
|
|
4283
4584
|
const res = await collection.insertOne(value, { session });
|
|
4284
4585
|
delNamespace().then(() => {
|
|
4285
|
-
|
|
4586
|
+
logger25.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4286
4587
|
}).catch((err) => {
|
|
4287
|
-
|
|
4588
|
+
logger25.error(
|
|
4288
4589
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4289
4590
|
err
|
|
4290
4591
|
);
|
|
4291
4592
|
});
|
|
4292
4593
|
delSupplyNamespace().then(() => {
|
|
4293
|
-
|
|
4594
|
+
logger25.info(`Cache cleared for namespace: ${supply_collection}`);
|
|
4294
4595
|
}).catch((err) => {
|
|
4295
|
-
|
|
4596
|
+
logger25.error(
|
|
4296
4597
|
`Failed to clear cache for namespace: ${supply_collection}`,
|
|
4297
4598
|
err
|
|
4298
4599
|
);
|
|
@@ -4318,14 +4619,14 @@ function useStockRepository() {
|
|
|
4318
4619
|
limit
|
|
4319
4620
|
};
|
|
4320
4621
|
try {
|
|
4321
|
-
site = new
|
|
4622
|
+
site = new ObjectId14(site);
|
|
4322
4623
|
query.site = site;
|
|
4323
4624
|
cacheOptions.site = site.toString();
|
|
4324
4625
|
} catch (error) {
|
|
4325
4626
|
throw new BadRequestError21("Invalid site ID format.");
|
|
4326
4627
|
}
|
|
4327
4628
|
try {
|
|
4328
|
-
supply = new
|
|
4629
|
+
supply = new ObjectId14(supply);
|
|
4329
4630
|
query.supply = supply;
|
|
4330
4631
|
cacheOptions.supply = supply.toString();
|
|
4331
4632
|
} catch (error) {
|
|
@@ -4338,7 +4639,7 @@ function useStockRepository() {
|
|
|
4338
4639
|
const cacheKey = makeCacheKey7(namespace_collection, cacheOptions);
|
|
4339
4640
|
const cachedData = await getCache(cacheKey);
|
|
4340
4641
|
if (cachedData) {
|
|
4341
|
-
|
|
4642
|
+
logger25.info(`Cache hit for key: ${cacheKey}`);
|
|
4342
4643
|
return cachedData;
|
|
4343
4644
|
}
|
|
4344
4645
|
try {
|
|
@@ -4359,9 +4660,9 @@ function useStockRepository() {
|
|
|
4359
4660
|
const length = await collection.countDocuments(query);
|
|
4360
4661
|
const data = paginate6(items, page, limit, length);
|
|
4361
4662
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4362
|
-
|
|
4663
|
+
logger25.info(`Cache set for key: ${cacheKey}`);
|
|
4363
4664
|
}).catch((err) => {
|
|
4364
|
-
|
|
4665
|
+
logger25.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4365
4666
|
});
|
|
4366
4667
|
return data;
|
|
4367
4668
|
} catch (error) {
|
|
@@ -4378,7 +4679,7 @@ function useStockRepository() {
|
|
|
4378
4679
|
// src/services/hygiene-stock.service.ts
|
|
4379
4680
|
import {
|
|
4380
4681
|
NotFoundError as NotFoundError5,
|
|
4381
|
-
useAtlas as
|
|
4682
|
+
useAtlas as useAtlas11,
|
|
4382
4683
|
BadRequestError as BadRequestError22
|
|
4383
4684
|
} from "@7365admin1/node-server-utils";
|
|
4384
4685
|
function useStockService() {
|
|
@@ -4387,7 +4688,7 @@ function useStockService() {
|
|
|
4387
4688
|
async function createStock(value, out = false, session) {
|
|
4388
4689
|
let ownSession = false;
|
|
4389
4690
|
if (!session) {
|
|
4390
|
-
session =
|
|
4691
|
+
session = useAtlas11.getClient()?.startSession();
|
|
4391
4692
|
ownSession = true;
|
|
4392
4693
|
}
|
|
4393
4694
|
try {
|
|
@@ -4431,7 +4732,7 @@ function useStockService() {
|
|
|
4431
4732
|
|
|
4432
4733
|
// src/controllers/hygiene-stock.controller.ts
|
|
4433
4734
|
import Joi13 from "joi";
|
|
4434
|
-
import { BadRequestError as BadRequestError23, logger as
|
|
4735
|
+
import { BadRequestError as BadRequestError23, logger as logger26 } from "@7365admin1/node-server-utils";
|
|
4435
4736
|
function useStockController() {
|
|
4436
4737
|
const { getStocksBySupplyId: _getStocksBySupplyId } = useStockRepository();
|
|
4437
4738
|
const { createStock: _createStock } = useStockService();
|
|
@@ -4445,7 +4746,7 @@ function useStockController() {
|
|
|
4445
4746
|
});
|
|
4446
4747
|
const { error } = validation.validate(payload);
|
|
4447
4748
|
if (error) {
|
|
4448
|
-
|
|
4749
|
+
logger26.log({ level: "error", message: error.message });
|
|
4449
4750
|
next(new BadRequestError23(error.message));
|
|
4450
4751
|
return;
|
|
4451
4752
|
}
|
|
@@ -4454,7 +4755,7 @@ function useStockController() {
|
|
|
4454
4755
|
res.status(201).json({ message: "Stock created successfully.", id });
|
|
4455
4756
|
return;
|
|
4456
4757
|
} catch (error2) {
|
|
4457
|
-
|
|
4758
|
+
logger26.log({ level: "error", message: error2.message });
|
|
4458
4759
|
next(error2);
|
|
4459
4760
|
return;
|
|
4460
4761
|
}
|
|
@@ -4470,7 +4771,7 @@ function useStockController() {
|
|
|
4470
4771
|
});
|
|
4471
4772
|
const { error } = validation.validate(query);
|
|
4472
4773
|
if (error) {
|
|
4473
|
-
|
|
4774
|
+
logger26.log({ level: "error", message: error.message });
|
|
4474
4775
|
next(new BadRequestError23(error.message));
|
|
4475
4776
|
return;
|
|
4476
4777
|
}
|
|
@@ -4490,7 +4791,7 @@ function useStockController() {
|
|
|
4490
4791
|
res.json(data);
|
|
4491
4792
|
return;
|
|
4492
4793
|
} catch (error2) {
|
|
4493
|
-
|
|
4794
|
+
logger26.log({ level: "error", message: error2.message });
|
|
4494
4795
|
next(error2);
|
|
4495
4796
|
return;
|
|
4496
4797
|
}
|
|
@@ -4503,8 +4804,8 @@ function useStockController() {
|
|
|
4503
4804
|
|
|
4504
4805
|
// src/models/hygiene-checkout-item.model.ts
|
|
4505
4806
|
import Joi14 from "joi";
|
|
4506
|
-
import { ObjectId as
|
|
4507
|
-
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";
|
|
4508
4809
|
var allowedCheckOutItemStatus = ["pending", "completed"];
|
|
4509
4810
|
var checkOutItemSchema = Joi14.object({
|
|
4510
4811
|
site: Joi14.string().hex().required(),
|
|
@@ -4518,19 +4819,19 @@ var checkOutItemSchema = Joi14.object({
|
|
|
4518
4819
|
function MCheckOutItem(value) {
|
|
4519
4820
|
const { error } = checkOutItemSchema.validate(value);
|
|
4520
4821
|
if (error) {
|
|
4521
|
-
|
|
4822
|
+
logger27.info(`Hygiene Check Out Item Model: ${error.message}`);
|
|
4522
4823
|
throw new BadRequestError24(error.message);
|
|
4523
4824
|
}
|
|
4524
4825
|
if (value.site) {
|
|
4525
4826
|
try {
|
|
4526
|
-
value.site = new
|
|
4827
|
+
value.site = new ObjectId15(value.site);
|
|
4527
4828
|
} catch (error2) {
|
|
4528
4829
|
throw new BadRequestError24("Invalid site ID format.");
|
|
4529
4830
|
}
|
|
4530
4831
|
}
|
|
4531
4832
|
if (value.supply) {
|
|
4532
4833
|
try {
|
|
4533
|
-
value.supply = new
|
|
4834
|
+
value.supply = new ObjectId15(value.supply);
|
|
4534
4835
|
} catch (error2) {
|
|
4535
4836
|
throw new BadRequestError24("Invalid supply ID format.");
|
|
4536
4837
|
}
|
|
@@ -4551,21 +4852,21 @@ function MCheckOutItem(value) {
|
|
|
4551
4852
|
}
|
|
4552
4853
|
|
|
4553
4854
|
// src/repositories/hygiene-checkout-item.repository.ts
|
|
4554
|
-
import { ObjectId as
|
|
4855
|
+
import { ObjectId as ObjectId16 } from "mongodb";
|
|
4555
4856
|
import {
|
|
4556
|
-
useAtlas as
|
|
4557
|
-
InternalServerError as
|
|
4857
|
+
useAtlas as useAtlas12,
|
|
4858
|
+
InternalServerError as InternalServerError10,
|
|
4558
4859
|
useCache as useCache8,
|
|
4559
|
-
logger as
|
|
4860
|
+
logger as logger28,
|
|
4560
4861
|
makeCacheKey as makeCacheKey8,
|
|
4561
4862
|
paginate as paginate7,
|
|
4562
4863
|
BadRequestError as BadRequestError25,
|
|
4563
4864
|
NotFoundError as NotFoundError6
|
|
4564
4865
|
} from "@7365admin1/node-server-utils";
|
|
4565
4866
|
function useCheckOutItemRepository() {
|
|
4566
|
-
const db =
|
|
4867
|
+
const db = useAtlas12.getDb();
|
|
4567
4868
|
if (!db) {
|
|
4568
|
-
throw new
|
|
4869
|
+
throw new InternalServerError10("Unable to connect to server.");
|
|
4569
4870
|
}
|
|
4570
4871
|
const namespace_collection = "site.supply.checkouts";
|
|
4571
4872
|
const collection = db.collection(namespace_collection);
|
|
@@ -4578,7 +4879,7 @@ function useCheckOutItemRepository() {
|
|
|
4578
4879
|
{ key: { status: 1 } }
|
|
4579
4880
|
]);
|
|
4580
4881
|
} catch (error) {
|
|
4581
|
-
throw new
|
|
4882
|
+
throw new InternalServerError10(
|
|
4582
4883
|
"Failed to create index on hygiene check out item."
|
|
4583
4884
|
);
|
|
4584
4885
|
}
|
|
@@ -4587,7 +4888,7 @@ function useCheckOutItemRepository() {
|
|
|
4587
4888
|
try {
|
|
4588
4889
|
await collection.createIndex({ supplyName: "text" });
|
|
4589
4890
|
} catch (error) {
|
|
4590
|
-
throw new
|
|
4891
|
+
throw new InternalServerError10(
|
|
4591
4892
|
"Failed to create text index on hygiene supply."
|
|
4592
4893
|
);
|
|
4593
4894
|
}
|
|
@@ -4597,9 +4898,9 @@ function useCheckOutItemRepository() {
|
|
|
4597
4898
|
value = MCheckOutItem(value);
|
|
4598
4899
|
const res = await collection.insertOne(value, { session });
|
|
4599
4900
|
delNamespace().then(() => {
|
|
4600
|
-
|
|
4901
|
+
logger28.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4601
4902
|
}).catch((err) => {
|
|
4602
|
-
|
|
4903
|
+
logger28.error(
|
|
4603
4904
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4604
4905
|
err
|
|
4605
4906
|
);
|
|
@@ -4624,7 +4925,7 @@ function useCheckOutItemRepository() {
|
|
|
4624
4925
|
limit
|
|
4625
4926
|
};
|
|
4626
4927
|
try {
|
|
4627
|
-
site = new
|
|
4928
|
+
site = new ObjectId16(site);
|
|
4628
4929
|
query.site = site;
|
|
4629
4930
|
cacheOptions.site = site.toString();
|
|
4630
4931
|
} catch (error) {
|
|
@@ -4637,7 +4938,7 @@ function useCheckOutItemRepository() {
|
|
|
4637
4938
|
const cacheKey = makeCacheKey8(namespace_collection, cacheOptions);
|
|
4638
4939
|
const cachedData = await getCache(cacheKey);
|
|
4639
4940
|
if (cachedData) {
|
|
4640
|
-
|
|
4941
|
+
logger28.info(`Cache hit for key: ${cacheKey}`);
|
|
4641
4942
|
return cachedData;
|
|
4642
4943
|
}
|
|
4643
4944
|
try {
|
|
@@ -4686,9 +4987,9 @@ function useCheckOutItemRepository() {
|
|
|
4686
4987
|
const length = await collection.countDocuments(query);
|
|
4687
4988
|
const data = paginate7(items, page, limit, length);
|
|
4688
4989
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4689
|
-
|
|
4990
|
+
logger28.info(`Cache set for key: ${cacheKey}`);
|
|
4690
4991
|
}).catch((err) => {
|
|
4691
|
-
|
|
4992
|
+
logger28.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4692
4993
|
});
|
|
4693
4994
|
return data;
|
|
4694
4995
|
} catch (error) {
|
|
@@ -4697,7 +4998,7 @@ function useCheckOutItemRepository() {
|
|
|
4697
4998
|
}
|
|
4698
4999
|
async function getCheckOutItemById(_id, session) {
|
|
4699
5000
|
try {
|
|
4700
|
-
_id = new
|
|
5001
|
+
_id = new ObjectId16(_id);
|
|
4701
5002
|
} catch (error) {
|
|
4702
5003
|
throw new BadRequestError25("Invalid check out item ID format.");
|
|
4703
5004
|
}
|
|
@@ -4708,11 +5009,11 @@ function useCheckOutItemRepository() {
|
|
|
4708
5009
|
if (!session) {
|
|
4709
5010
|
const cachedData = await getCache(cacheKey);
|
|
4710
5011
|
if (cachedData) {
|
|
4711
|
-
|
|
5012
|
+
logger28.info(`Cache hit for key: ${cacheKey}`);
|
|
4712
5013
|
return cachedData;
|
|
4713
5014
|
}
|
|
4714
5015
|
} else {
|
|
4715
|
-
|
|
5016
|
+
logger28.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
4716
5017
|
}
|
|
4717
5018
|
try {
|
|
4718
5019
|
const data = await collection.aggregate(
|
|
@@ -4750,9 +5051,9 @@ function useCheckOutItemRepository() {
|
|
|
4750
5051
|
throw new NotFoundError6("Check out item not found.");
|
|
4751
5052
|
}
|
|
4752
5053
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
4753
|
-
|
|
5054
|
+
logger28.info(`Cache set for key: ${cacheKey}`);
|
|
4754
5055
|
}).catch((err) => {
|
|
4755
|
-
|
|
5056
|
+
logger28.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4756
5057
|
});
|
|
4757
5058
|
return data[0];
|
|
4758
5059
|
} catch (error) {
|
|
@@ -4761,7 +5062,7 @@ function useCheckOutItemRepository() {
|
|
|
4761
5062
|
}
|
|
4762
5063
|
async function completeCheckOutItem(_id, session) {
|
|
4763
5064
|
try {
|
|
4764
|
-
_id = new
|
|
5065
|
+
_id = new ObjectId16(_id);
|
|
4765
5066
|
} catch (error) {
|
|
4766
5067
|
throw new BadRequestError25("Invalid check out item ID format.");
|
|
4767
5068
|
}
|
|
@@ -4776,12 +5077,12 @@ function useCheckOutItemRepository() {
|
|
|
4776
5077
|
{ session }
|
|
4777
5078
|
);
|
|
4778
5079
|
if (res.modifiedCount === 0) {
|
|
4779
|
-
throw new
|
|
5080
|
+
throw new InternalServerError10("Unable to complete check out item.");
|
|
4780
5081
|
}
|
|
4781
5082
|
delNamespace().then(() => {
|
|
4782
|
-
|
|
5083
|
+
logger28.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4783
5084
|
}).catch((err) => {
|
|
4784
|
-
|
|
5085
|
+
logger28.error(
|
|
4785
5086
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4786
5087
|
err
|
|
4787
5088
|
);
|
|
@@ -4803,7 +5104,7 @@ function useCheckOutItemRepository() {
|
|
|
4803
5104
|
|
|
4804
5105
|
// src/services/hygiene-checkout-item.service.ts
|
|
4805
5106
|
import { useUserRepo } from "@7365admin1/core";
|
|
4806
|
-
import { BadRequestError as BadRequestError26, useAtlas as
|
|
5107
|
+
import { BadRequestError as BadRequestError26, useAtlas as useAtlas13 } from "@7365admin1/node-server-utils";
|
|
4807
5108
|
function useCheckOutItemService() {
|
|
4808
5109
|
const {
|
|
4809
5110
|
createCheckOutItem: _createCheckOutItem,
|
|
@@ -4814,7 +5115,7 @@ function useCheckOutItemService() {
|
|
|
4814
5115
|
const { getUserById } = useUserRepo();
|
|
4815
5116
|
const { createStock } = useStockService();
|
|
4816
5117
|
async function createCheckOutItem(value) {
|
|
4817
|
-
const session =
|
|
5118
|
+
const session = useAtlas13.getClient()?.startSession();
|
|
4818
5119
|
try {
|
|
4819
5120
|
session?.startTransaction();
|
|
4820
5121
|
const supplyData = await getSupplyById(value.supply);
|
|
@@ -4854,7 +5155,7 @@ function useCheckOutItemService() {
|
|
|
4854
5155
|
}
|
|
4855
5156
|
}
|
|
4856
5157
|
async function createCheckOutItemByBatch(value) {
|
|
4857
|
-
const session =
|
|
5158
|
+
const session = useAtlas13.getClient()?.startSession();
|
|
4858
5159
|
try {
|
|
4859
5160
|
session?.startTransaction();
|
|
4860
5161
|
const { site, attachment, createdBy, items } = value;
|
|
@@ -4902,7 +5203,7 @@ function useCheckOutItemService() {
|
|
|
4902
5203
|
|
|
4903
5204
|
// src/controllers/hygiene-checkout-item.controller.ts
|
|
4904
5205
|
import Joi15 from "joi";
|
|
4905
|
-
import { BadRequestError as BadRequestError27, logger as
|
|
5206
|
+
import { BadRequestError as BadRequestError27, logger as logger29 } from "@7365admin1/node-server-utils";
|
|
4906
5207
|
function useCheckOutItemController() {
|
|
4907
5208
|
const {
|
|
4908
5209
|
getCheckOutItems: _getCheckOutItems,
|
|
@@ -4932,7 +5233,7 @@ function useCheckOutItemController() {
|
|
|
4932
5233
|
});
|
|
4933
5234
|
const { error } = validation.validate(payload);
|
|
4934
5235
|
if (error) {
|
|
4935
|
-
|
|
5236
|
+
logger29.log({ level: "error", message: error.message });
|
|
4936
5237
|
next(new BadRequestError27(error.message));
|
|
4937
5238
|
return;
|
|
4938
5239
|
}
|
|
@@ -4941,7 +5242,7 @@ function useCheckOutItemController() {
|
|
|
4941
5242
|
res.status(201).json({ message: "Check out item created successfully.", id });
|
|
4942
5243
|
return;
|
|
4943
5244
|
} catch (error2) {
|
|
4944
|
-
|
|
5245
|
+
logger29.log({ level: "error", message: error2.message });
|
|
4945
5246
|
next(error2);
|
|
4946
5247
|
return;
|
|
4947
5248
|
}
|
|
@@ -4970,7 +5271,7 @@ function useCheckOutItemController() {
|
|
|
4970
5271
|
});
|
|
4971
5272
|
const { error } = validation.validate(payload);
|
|
4972
5273
|
if (error) {
|
|
4973
|
-
|
|
5274
|
+
logger29.log({ level: "error", message: error.message });
|
|
4974
5275
|
next(new BadRequestError27(error.message));
|
|
4975
5276
|
return;
|
|
4976
5277
|
}
|
|
@@ -4979,7 +5280,7 @@ function useCheckOutItemController() {
|
|
|
4979
5280
|
res.status(201).json({ message: "Check out items created successfully." });
|
|
4980
5281
|
return;
|
|
4981
5282
|
} catch (error2) {
|
|
4982
|
-
|
|
5283
|
+
logger29.log({ level: "error", message: error2.message });
|
|
4983
5284
|
next(error2);
|
|
4984
5285
|
return;
|
|
4985
5286
|
}
|
|
@@ -4994,7 +5295,7 @@ function useCheckOutItemController() {
|
|
|
4994
5295
|
});
|
|
4995
5296
|
const { error } = validation.validate(query);
|
|
4996
5297
|
if (error) {
|
|
4997
|
-
|
|
5298
|
+
logger29.log({ level: "error", message: error.message });
|
|
4998
5299
|
next(new BadRequestError27(error.message));
|
|
4999
5300
|
return;
|
|
5000
5301
|
}
|
|
@@ -5012,7 +5313,7 @@ function useCheckOutItemController() {
|
|
|
5012
5313
|
res.json(data);
|
|
5013
5314
|
return;
|
|
5014
5315
|
} catch (error2) {
|
|
5015
|
-
|
|
5316
|
+
logger29.log({ level: "error", message: error2.message });
|
|
5016
5317
|
next(error2);
|
|
5017
5318
|
return;
|
|
5018
5319
|
}
|
|
@@ -5022,7 +5323,7 @@ function useCheckOutItemController() {
|
|
|
5022
5323
|
const _id = req.params.id;
|
|
5023
5324
|
const { error, value } = validation.validate(_id);
|
|
5024
5325
|
if (error) {
|
|
5025
|
-
|
|
5326
|
+
logger29.log({ level: "error", message: error.message });
|
|
5026
5327
|
next(new BadRequestError27(error.message));
|
|
5027
5328
|
return;
|
|
5028
5329
|
}
|
|
@@ -5031,7 +5332,7 @@ function useCheckOutItemController() {
|
|
|
5031
5332
|
res.json(data);
|
|
5032
5333
|
return;
|
|
5033
5334
|
} catch (error2) {
|
|
5034
|
-
|
|
5335
|
+
logger29.log({ level: "error", message: error2.message });
|
|
5035
5336
|
next(error2);
|
|
5036
5337
|
return;
|
|
5037
5338
|
}
|
|
@@ -5045,9 +5346,9 @@ function useCheckOutItemController() {
|
|
|
5045
5346
|
}
|
|
5046
5347
|
|
|
5047
5348
|
// src/models/hygiene-schedule-task.model.ts
|
|
5048
|
-
import { BadRequestError as BadRequestError28, logger as
|
|
5349
|
+
import { BadRequestError as BadRequestError28, logger as logger30 } from "@7365admin1/node-server-utils";
|
|
5049
5350
|
import Joi16 from "joi";
|
|
5050
|
-
import { ObjectId as
|
|
5351
|
+
import { ObjectId as ObjectId17 } from "mongodb";
|
|
5051
5352
|
var scheduleTaskSchema = Joi16.object({
|
|
5052
5353
|
site: Joi16.string().hex().required(),
|
|
5053
5354
|
title: Joi16.string().required(),
|
|
@@ -5066,12 +5367,12 @@ var scheduleTaskSchema = Joi16.object({
|
|
|
5066
5367
|
function MScheduleTask(value) {
|
|
5067
5368
|
const { error } = scheduleTaskSchema.validate(value);
|
|
5068
5369
|
if (error) {
|
|
5069
|
-
|
|
5370
|
+
logger30.info(`Hygiene Schedule Task Model: ${error.message}`);
|
|
5070
5371
|
throw new BadRequestError28(error.message);
|
|
5071
5372
|
}
|
|
5072
5373
|
if (value.site) {
|
|
5073
5374
|
try {
|
|
5074
|
-
value.site = new
|
|
5375
|
+
value.site = new ObjectId17(value.site);
|
|
5075
5376
|
} catch (error2) {
|
|
5076
5377
|
throw new BadRequestError28("Invalid site ID format.");
|
|
5077
5378
|
}
|
|
@@ -5081,7 +5382,7 @@ function MScheduleTask(value) {
|
|
|
5081
5382
|
try {
|
|
5082
5383
|
return {
|
|
5083
5384
|
name: area.name,
|
|
5084
|
-
value: new
|
|
5385
|
+
value: new ObjectId17(area.value.toString())
|
|
5085
5386
|
};
|
|
5086
5387
|
} catch (error2) {
|
|
5087
5388
|
throw new BadRequestError28(`Invalid area value format: ${area.name}`);
|
|
@@ -5090,7 +5391,7 @@ function MScheduleTask(value) {
|
|
|
5090
5391
|
}
|
|
5091
5392
|
if (value.createdBy) {
|
|
5092
5393
|
try {
|
|
5093
|
-
value.createdBy = new
|
|
5394
|
+
value.createdBy = new ObjectId17(value.createdBy);
|
|
5094
5395
|
} catch (error2) {
|
|
5095
5396
|
throw new BadRequestError28("Invalid createdBy ID format.");
|
|
5096
5397
|
}
|
|
@@ -5112,21 +5413,21 @@ function MScheduleTask(value) {
|
|
|
5112
5413
|
}
|
|
5113
5414
|
|
|
5114
5415
|
// src/repositories/hygiene-schedule-task.repository.ts
|
|
5115
|
-
import { ObjectId as
|
|
5416
|
+
import { ObjectId as ObjectId18 } from "mongodb";
|
|
5116
5417
|
import {
|
|
5117
|
-
useAtlas as
|
|
5118
|
-
InternalServerError as
|
|
5418
|
+
useAtlas as useAtlas14,
|
|
5419
|
+
InternalServerError as InternalServerError11,
|
|
5119
5420
|
paginate as paginate8,
|
|
5120
5421
|
BadRequestError as BadRequestError29,
|
|
5121
5422
|
useCache as useCache9,
|
|
5122
|
-
logger as
|
|
5423
|
+
logger as logger31,
|
|
5123
5424
|
makeCacheKey as makeCacheKey9,
|
|
5124
5425
|
NotFoundError as NotFoundError7
|
|
5125
5426
|
} from "@7365admin1/node-server-utils";
|
|
5126
5427
|
function useScheduleTaskRepository() {
|
|
5127
|
-
const db =
|
|
5428
|
+
const db = useAtlas14.getDb();
|
|
5128
5429
|
if (!db) {
|
|
5129
|
-
throw new
|
|
5430
|
+
throw new InternalServerError11("Unable to connect to server.");
|
|
5130
5431
|
}
|
|
5131
5432
|
const namespace_collection = "site.schedule-tasks";
|
|
5132
5433
|
const collection = db.collection(namespace_collection);
|
|
@@ -5138,7 +5439,7 @@ function useScheduleTaskRepository() {
|
|
|
5138
5439
|
{ key: { status: 1 } }
|
|
5139
5440
|
]);
|
|
5140
5441
|
} catch (error) {
|
|
5141
|
-
throw new
|
|
5442
|
+
throw new InternalServerError11(
|
|
5142
5443
|
"Failed to create index on hygiene schedule task."
|
|
5143
5444
|
);
|
|
5144
5445
|
}
|
|
@@ -5147,7 +5448,7 @@ function useScheduleTaskRepository() {
|
|
|
5147
5448
|
try {
|
|
5148
5449
|
await collection.createIndex({ title: "text", description: "text" });
|
|
5149
5450
|
} catch (error) {
|
|
5150
|
-
throw new
|
|
5451
|
+
throw new InternalServerError11(
|
|
5151
5452
|
"Failed to create text index on hygiene schedule task."
|
|
5152
5453
|
);
|
|
5153
5454
|
}
|
|
@@ -5157,9 +5458,9 @@ function useScheduleTaskRepository() {
|
|
|
5157
5458
|
value = MScheduleTask(value);
|
|
5158
5459
|
const res = await collection.insertOne(value, { session });
|
|
5159
5460
|
delNamespace().then(() => {
|
|
5160
|
-
|
|
5461
|
+
logger31.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5161
5462
|
}).catch((err) => {
|
|
5162
|
-
|
|
5463
|
+
logger31.error(
|
|
5163
5464
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5164
5465
|
err
|
|
5165
5466
|
);
|
|
@@ -5184,7 +5485,7 @@ function useScheduleTaskRepository() {
|
|
|
5184
5485
|
limit
|
|
5185
5486
|
};
|
|
5186
5487
|
try {
|
|
5187
|
-
site = new
|
|
5488
|
+
site = new ObjectId18(site);
|
|
5188
5489
|
query.site = site;
|
|
5189
5490
|
cacheOptions.site = site.toString();
|
|
5190
5491
|
} catch (error) {
|
|
@@ -5197,7 +5498,7 @@ function useScheduleTaskRepository() {
|
|
|
5197
5498
|
const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
|
|
5198
5499
|
const cachedData = await getCache(cacheKey);
|
|
5199
5500
|
if (cachedData) {
|
|
5200
|
-
|
|
5501
|
+
logger31.info(`Cache hit for key: ${cacheKey}`);
|
|
5201
5502
|
return cachedData;
|
|
5202
5503
|
}
|
|
5203
5504
|
try {
|
|
@@ -5217,9 +5518,9 @@ function useScheduleTaskRepository() {
|
|
|
5217
5518
|
const length = await collection.countDocuments(query);
|
|
5218
5519
|
const data = paginate8(items, page, limit, length);
|
|
5219
5520
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5220
|
-
|
|
5521
|
+
logger31.info(`Cache set for key: ${cacheKey}`);
|
|
5221
5522
|
}).catch((err) => {
|
|
5222
|
-
|
|
5523
|
+
logger31.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5223
5524
|
});
|
|
5224
5525
|
return data;
|
|
5225
5526
|
} catch (error) {
|
|
@@ -5252,7 +5553,7 @@ function useScheduleTaskRepository() {
|
|
|
5252
5553
|
limit
|
|
5253
5554
|
};
|
|
5254
5555
|
try {
|
|
5255
|
-
site = new
|
|
5556
|
+
site = new ObjectId18(site);
|
|
5256
5557
|
query.site = site;
|
|
5257
5558
|
cacheOptions.site = site.toString();
|
|
5258
5559
|
} catch (error) {
|
|
@@ -5265,7 +5566,7 @@ function useScheduleTaskRepository() {
|
|
|
5265
5566
|
const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
|
|
5266
5567
|
const cachedData = await getCache(cacheKey);
|
|
5267
5568
|
if (cachedData) {
|
|
5268
|
-
|
|
5569
|
+
logger31.info(`Cache hit for key: ${cacheKey}`);
|
|
5269
5570
|
return cachedData;
|
|
5270
5571
|
}
|
|
5271
5572
|
try {
|
|
@@ -5284,9 +5585,9 @@ function useScheduleTaskRepository() {
|
|
|
5284
5585
|
const length = await collection.countDocuments(query);
|
|
5285
5586
|
const data = paginate8(items, page, limit, length);
|
|
5286
5587
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5287
|
-
|
|
5588
|
+
logger31.info(`Cache set for key: ${cacheKey}`);
|
|
5288
5589
|
}).catch((err) => {
|
|
5289
|
-
|
|
5590
|
+
logger31.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5290
5591
|
});
|
|
5291
5592
|
return data;
|
|
5292
5593
|
} catch (error) {
|
|
@@ -5295,7 +5596,7 @@ function useScheduleTaskRepository() {
|
|
|
5295
5596
|
}
|
|
5296
5597
|
async function getScheduleTaskById(_id, session) {
|
|
5297
5598
|
try {
|
|
5298
|
-
_id = new
|
|
5599
|
+
_id = new ObjectId18(_id);
|
|
5299
5600
|
} catch (error) {
|
|
5300
5601
|
throw new BadRequestError29("Invalid schedule task ID format.");
|
|
5301
5602
|
}
|
|
@@ -5309,11 +5610,11 @@ function useScheduleTaskRepository() {
|
|
|
5309
5610
|
if (!session) {
|
|
5310
5611
|
const cachedData = await getCache(cacheKey);
|
|
5311
5612
|
if (cachedData) {
|
|
5312
|
-
|
|
5613
|
+
logger31.info(`Cache hit for key: ${cacheKey}`);
|
|
5313
5614
|
return cachedData;
|
|
5314
5615
|
}
|
|
5315
5616
|
} else {
|
|
5316
|
-
|
|
5617
|
+
logger31.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
5317
5618
|
}
|
|
5318
5619
|
try {
|
|
5319
5620
|
const data = await collection.aggregate([
|
|
@@ -5335,9 +5636,9 @@ function useScheduleTaskRepository() {
|
|
|
5335
5636
|
throw new NotFoundError7("Schedule task not found.");
|
|
5336
5637
|
}
|
|
5337
5638
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
5338
|
-
|
|
5639
|
+
logger31.info(`Cache set for key: ${cacheKey}`);
|
|
5339
5640
|
}).catch((err) => {
|
|
5340
|
-
|
|
5641
|
+
logger31.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5341
5642
|
});
|
|
5342
5643
|
return data[0];
|
|
5343
5644
|
} catch (error) {
|
|
@@ -5346,7 +5647,7 @@ function useScheduleTaskRepository() {
|
|
|
5346
5647
|
}
|
|
5347
5648
|
async function updateScheduleTask(_id, value, session) {
|
|
5348
5649
|
try {
|
|
5349
|
-
_id = new
|
|
5650
|
+
_id = new ObjectId18(_id);
|
|
5350
5651
|
} catch (error) {
|
|
5351
5652
|
throw new BadRequestError29("Invalid schedule task ID format.");
|
|
5352
5653
|
}
|
|
@@ -5355,7 +5656,7 @@ function useScheduleTaskRepository() {
|
|
|
5355
5656
|
try {
|
|
5356
5657
|
return {
|
|
5357
5658
|
name: area.name,
|
|
5358
|
-
value: new
|
|
5659
|
+
value: new ObjectId18(area.value.toString())
|
|
5359
5660
|
};
|
|
5360
5661
|
} catch (error) {
|
|
5361
5662
|
throw new BadRequestError29(`Invalid area value format: ${area.name}`);
|
|
@@ -5370,14 +5671,14 @@ function useScheduleTaskRepository() {
|
|
|
5370
5671
|
{ session }
|
|
5371
5672
|
);
|
|
5372
5673
|
if (res.modifiedCount === 0) {
|
|
5373
|
-
throw new
|
|
5674
|
+
throw new InternalServerError11(
|
|
5374
5675
|
"Unable to update hygiene schedule task."
|
|
5375
5676
|
);
|
|
5376
5677
|
}
|
|
5377
5678
|
delNamespace().then(() => {
|
|
5378
|
-
|
|
5679
|
+
logger31.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5379
5680
|
}).catch((err) => {
|
|
5380
|
-
|
|
5681
|
+
logger31.error(
|
|
5381
5682
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5382
5683
|
err
|
|
5383
5684
|
);
|
|
@@ -5400,7 +5701,7 @@ function useScheduleTaskRepository() {
|
|
|
5400
5701
|
}
|
|
5401
5702
|
|
|
5402
5703
|
// src/services/hygiene-schedule-task.service.ts
|
|
5403
|
-
import { logger as
|
|
5704
|
+
import { logger as logger32 } from "@7365admin1/node-server-utils";
|
|
5404
5705
|
function useScheduleTaskService() {
|
|
5405
5706
|
const { createParentChecklist } = useParentChecklistRepo();
|
|
5406
5707
|
const { getAllScheduleTask } = useScheduleTaskRepository();
|
|
@@ -5423,13 +5724,13 @@ function useScheduleTaskService() {
|
|
|
5423
5724
|
const currentDateString = now.toLocaleDateString("en-US", {
|
|
5424
5725
|
timeZone: "Asia/Singapore"
|
|
5425
5726
|
});
|
|
5426
|
-
|
|
5727
|
+
logger32.info(
|
|
5427
5728
|
`Checking schedule ${schedule._id}: Current time ${currentHour}:${currentMinute}, Current date ${currentDateString}, Schedule time ${schedule.time}, Start date ${schedule.startDate}, End date ${schedule.endDate}`
|
|
5428
5729
|
);
|
|
5429
5730
|
const startDate = /* @__PURE__ */ new Date(schedule.startDate + "T00:00:00");
|
|
5430
5731
|
const currentDateOnly = /* @__PURE__ */ new Date(currentDateString + "T00:00:00");
|
|
5431
5732
|
if (currentDateOnly < startDate) {
|
|
5432
|
-
|
|
5733
|
+
logger32.info(
|
|
5433
5734
|
`Schedule ${schedule._id}: Current date ${currentDateString} is before start date ${schedule.startDate}`
|
|
5434
5735
|
);
|
|
5435
5736
|
return false;
|
|
@@ -5437,7 +5738,7 @@ function useScheduleTaskService() {
|
|
|
5437
5738
|
if (schedule.endDate) {
|
|
5438
5739
|
const endDate = /* @__PURE__ */ new Date(schedule.endDate + "T00:00:00");
|
|
5439
5740
|
if (currentDateOnly > endDate) {
|
|
5440
|
-
|
|
5741
|
+
logger32.info(
|
|
5441
5742
|
`Schedule ${schedule._id}: Current date ${currentDateString} is after end date ${schedule.endDate}`
|
|
5442
5743
|
);
|
|
5443
5744
|
return false;
|
|
@@ -5446,17 +5747,17 @@ function useScheduleTaskService() {
|
|
|
5446
5747
|
const [scheduleHour, scheduleMinute] = schedule.time.split(":").map(Number);
|
|
5447
5748
|
const timeMatches = currentHour === scheduleHour && currentMinute === scheduleMinute;
|
|
5448
5749
|
if (!timeMatches) {
|
|
5449
|
-
|
|
5750
|
+
logger32.info(
|
|
5450
5751
|
`Schedule ${schedule._id}: Time does not match. Current: ${currentHour}:${currentMinute}, Expected: ${scheduleHour}:${scheduleMinute}`
|
|
5451
5752
|
);
|
|
5452
5753
|
return false;
|
|
5453
5754
|
}
|
|
5454
|
-
|
|
5755
|
+
logger32.info(
|
|
5455
5756
|
`Schedule ${schedule._id}: All conditions matched - Date is within range and time matches`
|
|
5456
5757
|
);
|
|
5457
5758
|
return true;
|
|
5458
5759
|
} catch (error) {
|
|
5459
|
-
|
|
5760
|
+
logger32.error(
|
|
5460
5761
|
`Error checking schedule conditions for ${schedule._id}:`,
|
|
5461
5762
|
error
|
|
5462
5763
|
);
|
|
@@ -5465,40 +5766,40 @@ function useScheduleTaskService() {
|
|
|
5465
5766
|
}
|
|
5466
5767
|
async function processScheduledTasks(currentDate) {
|
|
5467
5768
|
try {
|
|
5468
|
-
|
|
5769
|
+
logger32.info("Starting scheduled task processing...");
|
|
5469
5770
|
const scheduleTasks = await getAllScheduleTask();
|
|
5470
5771
|
if (!scheduleTasks || scheduleTasks.length === 0) {
|
|
5471
|
-
|
|
5772
|
+
logger32.info("No schedule tasks found to process");
|
|
5472
5773
|
return { processed: 0, validated: 0 };
|
|
5473
5774
|
}
|
|
5474
|
-
|
|
5775
|
+
logger32.info(`Found ${scheduleTasks.length} schedule tasks to check`);
|
|
5475
5776
|
let processedCount = 0;
|
|
5476
5777
|
let validatedCount = 0;
|
|
5477
5778
|
const validatedTasks = [];
|
|
5478
5779
|
for (const scheduleTask of scheduleTasks) {
|
|
5479
5780
|
try {
|
|
5480
|
-
|
|
5781
|
+
logger32.info(
|
|
5481
5782
|
`Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time}, startDate=${scheduleTask.startDate}, endDate=${scheduleTask.endDate}`
|
|
5482
5783
|
);
|
|
5483
5784
|
const shouldRun = checkScheduleConditions(scheduleTask, currentDate);
|
|
5484
5785
|
if (!shouldRun) {
|
|
5485
|
-
|
|
5786
|
+
logger32.info(
|
|
5486
5787
|
`Schedule ${scheduleTask._id} conditions not met, skipping`
|
|
5487
5788
|
);
|
|
5488
5789
|
continue;
|
|
5489
5790
|
}
|
|
5490
|
-
|
|
5791
|
+
logger32.info(
|
|
5491
5792
|
`Schedule ${scheduleTask._id} conditions validated, creating area checklists`
|
|
5492
5793
|
);
|
|
5493
5794
|
if (!scheduleTask._id) {
|
|
5494
|
-
|
|
5795
|
+
logger32.warn(`Schedule ${scheduleTask.title} has no _id, skipping`);
|
|
5495
5796
|
continue;
|
|
5496
5797
|
}
|
|
5497
5798
|
if (!scheduleTask.site) {
|
|
5498
|
-
|
|
5799
|
+
logger32.warn(`Schedule ${scheduleTask._id} has no site, skipping`);
|
|
5499
5800
|
continue;
|
|
5500
5801
|
}
|
|
5501
|
-
|
|
5802
|
+
logger32.info(
|
|
5502
5803
|
`Getting or creating parent checklist for schedule ${scheduleTask._id} in site ${scheduleTask.site}`
|
|
5503
5804
|
);
|
|
5504
5805
|
const parentChecklistIds = await createParentChecklist({
|
|
@@ -5506,7 +5807,7 @@ function useScheduleTaskService() {
|
|
|
5506
5807
|
createdAt: /* @__PURE__ */ new Date()
|
|
5507
5808
|
});
|
|
5508
5809
|
const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
|
|
5509
|
-
|
|
5810
|
+
logger32.info(
|
|
5510
5811
|
`Using parent checklist ${parentChecklistId}, now creating/updating area checklists`
|
|
5511
5812
|
);
|
|
5512
5813
|
for (const area of scheduleTask.areas) {
|
|
@@ -5519,14 +5820,14 @@ function useScheduleTaskService() {
|
|
|
5519
5820
|
unit: unit.unit.toString(),
|
|
5520
5821
|
name: unit.name
|
|
5521
5822
|
}));
|
|
5522
|
-
|
|
5823
|
+
logger32.info(
|
|
5523
5824
|
`Area ${area.name} (${areaId}): Using units from area details: ${JSON.stringify(
|
|
5524
5825
|
units
|
|
5525
5826
|
)}`
|
|
5526
5827
|
);
|
|
5527
5828
|
}
|
|
5528
5829
|
if (units.length === 0) {
|
|
5529
|
-
|
|
5830
|
+
logger32.warn(
|
|
5530
5831
|
`Area ${area.name} (${areaId}): No units found, skipping area.`
|
|
5531
5832
|
);
|
|
5532
5833
|
continue;
|
|
@@ -5537,11 +5838,11 @@ function useScheduleTaskService() {
|
|
|
5537
5838
|
parentChecklistId.toString(),
|
|
5538
5839
|
areaId
|
|
5539
5840
|
);
|
|
5540
|
-
|
|
5841
|
+
logger32.info(
|
|
5541
5842
|
`Area ${area.name} (${areaId}): Existing area checklist found: ${existingAreaChecklist ? "Yes" : "No"}`
|
|
5542
5843
|
);
|
|
5543
5844
|
if (existingAreaChecklist) {
|
|
5544
|
-
|
|
5845
|
+
logger32.info(
|
|
5545
5846
|
`Area ${area.name} (${areaId}): Existing checklist content: ${JSON.stringify(
|
|
5546
5847
|
existingAreaChecklist.checklist
|
|
5547
5848
|
)}`
|
|
@@ -5549,7 +5850,7 @@ function useScheduleTaskService() {
|
|
|
5549
5850
|
}
|
|
5550
5851
|
} catch (error) {
|
|
5551
5852
|
existingAreaChecklist = null;
|
|
5552
|
-
|
|
5853
|
+
logger32.info(
|
|
5553
5854
|
`Area ${area.name} (${areaId}): No existing area checklist found (exception).`
|
|
5554
5855
|
);
|
|
5555
5856
|
}
|
|
@@ -5563,7 +5864,7 @@ function useScheduleTaskService() {
|
|
|
5563
5864
|
...existingAreaChecklist.checklist || [],
|
|
5564
5865
|
newSet
|
|
5565
5866
|
];
|
|
5566
|
-
|
|
5867
|
+
logger32.info(
|
|
5567
5868
|
`Area ${area.name} (${areaId}): Appending new set ${newSet.set} to checklist. Updated checklist: ${JSON.stringify(
|
|
5568
5869
|
updatedChecklist
|
|
5569
5870
|
)}`
|
|
@@ -5571,7 +5872,7 @@ function useScheduleTaskService() {
|
|
|
5571
5872
|
await updateAreaChecklist(existingAreaChecklist._id, {
|
|
5572
5873
|
checklist: updatedChecklist
|
|
5573
5874
|
});
|
|
5574
|
-
|
|
5875
|
+
logger32.info(
|
|
5575
5876
|
`Appended set ${newSet.set} to area checklist for area ${area.name}`
|
|
5576
5877
|
);
|
|
5577
5878
|
try {
|
|
@@ -5579,13 +5880,13 @@ function useScheduleTaskService() {
|
|
|
5579
5880
|
parentChecklistId.toString(),
|
|
5580
5881
|
areaId
|
|
5581
5882
|
);
|
|
5582
|
-
|
|
5883
|
+
logger32.info(
|
|
5583
5884
|
`Area ${area.name} (${areaId}): Checklist after update: ${JSON.stringify(
|
|
5584
5885
|
verifyChecklist.checklist
|
|
5585
5886
|
)}`
|
|
5586
5887
|
);
|
|
5587
5888
|
} catch (verifyError) {
|
|
5588
|
-
|
|
5889
|
+
logger32.warn(
|
|
5589
5890
|
`Area ${area.name} (${areaId}): Error verifying checklist after update:`,
|
|
5590
5891
|
verifyError
|
|
5591
5892
|
);
|
|
@@ -5604,50 +5905,50 @@ function useScheduleTaskService() {
|
|
|
5604
5905
|
],
|
|
5605
5906
|
createdBy: scheduleTask.createdBy
|
|
5606
5907
|
};
|
|
5607
|
-
|
|
5908
|
+
logger32.info(
|
|
5608
5909
|
`Area ${area.name} (${areaId}): Creating new area checklist with data: ${JSON.stringify(
|
|
5609
5910
|
checklistData
|
|
5610
5911
|
)}`
|
|
5611
5912
|
);
|
|
5612
5913
|
await createAreaChecklist(checklistData);
|
|
5613
|
-
|
|
5914
|
+
logger32.info(`Created new area checklist for area ${area.name}`);
|
|
5614
5915
|
try {
|
|
5615
5916
|
const verifyChecklist = await getAreaChecklistByAreaAndSchedule(
|
|
5616
5917
|
parentChecklistId.toString(),
|
|
5617
5918
|
areaId
|
|
5618
5919
|
);
|
|
5619
|
-
|
|
5920
|
+
logger32.info(
|
|
5620
5921
|
`Area ${area.name} (${areaId}): Checklist after creation: ${JSON.stringify(
|
|
5621
5922
|
verifyChecklist.checklist
|
|
5622
5923
|
)}`
|
|
5623
5924
|
);
|
|
5624
5925
|
} catch (verifyError) {
|
|
5625
|
-
|
|
5926
|
+
logger32.warn(
|
|
5626
5927
|
`Area ${area.name} (${areaId}): Error verifying checklist after creation:`,
|
|
5627
5928
|
verifyError
|
|
5628
5929
|
);
|
|
5629
5930
|
}
|
|
5630
5931
|
}
|
|
5631
5932
|
} catch (error) {
|
|
5632
|
-
|
|
5933
|
+
logger32.error(`Error processing area ${area.name}:`, error);
|
|
5633
5934
|
continue;
|
|
5634
5935
|
}
|
|
5635
5936
|
}
|
|
5636
5937
|
processedCount++;
|
|
5637
5938
|
validatedCount++;
|
|
5638
5939
|
validatedTasks.push(scheduleTask);
|
|
5639
|
-
|
|
5940
|
+
logger32.info(
|
|
5640
5941
|
`Successfully processed schedule ${scheduleTask._id}, created/updated area checklists for all areas.`
|
|
5641
5942
|
);
|
|
5642
5943
|
} catch (error) {
|
|
5643
|
-
|
|
5944
|
+
logger32.error(
|
|
5644
5945
|
`Error processing schedule task ${scheduleTask._id}:`,
|
|
5645
5946
|
error
|
|
5646
5947
|
);
|
|
5647
5948
|
continue;
|
|
5648
5949
|
}
|
|
5649
5950
|
}
|
|
5650
|
-
|
|
5951
|
+
logger32.info(
|
|
5651
5952
|
`Scheduled task processing completed. Processed: ${processedCount}, Validated: ${validatedCount} tasks`
|
|
5652
5953
|
);
|
|
5653
5954
|
return {
|
|
@@ -5656,7 +5957,7 @@ function useScheduleTaskService() {
|
|
|
5656
5957
|
tasks: validatedTasks
|
|
5657
5958
|
};
|
|
5658
5959
|
} catch (error) {
|
|
5659
|
-
|
|
5960
|
+
logger32.error("Error processing scheduled tasks:", error);
|
|
5660
5961
|
throw error;
|
|
5661
5962
|
}
|
|
5662
5963
|
}
|
|
@@ -5665,7 +5966,7 @@ function useScheduleTaskService() {
|
|
|
5665
5966
|
|
|
5666
5967
|
// src/controllers/hygiene-schedule-task.controller.ts
|
|
5667
5968
|
import Joi17 from "joi";
|
|
5668
|
-
import { BadRequestError as BadRequestError30, logger as
|
|
5969
|
+
import { BadRequestError as BadRequestError30, logger as logger33 } from "@7365admin1/node-server-utils";
|
|
5669
5970
|
function useScheduleTaskController() {
|
|
5670
5971
|
const {
|
|
5671
5972
|
createScheduleTask: _createScheduleTask,
|
|
@@ -5683,7 +5984,7 @@ function useScheduleTaskController() {
|
|
|
5683
5984
|
const payload = { ...req.body, ...req.params, createdBy };
|
|
5684
5985
|
const { error } = scheduleTaskSchema.validate(payload);
|
|
5685
5986
|
if (error) {
|
|
5686
|
-
|
|
5987
|
+
logger33.log({ level: "error", message: error.message });
|
|
5687
5988
|
next(new BadRequestError30(error.message));
|
|
5688
5989
|
return;
|
|
5689
5990
|
}
|
|
@@ -5692,7 +5993,7 @@ function useScheduleTaskController() {
|
|
|
5692
5993
|
res.status(201).json({ message: "Schedule task created successfully.", id });
|
|
5693
5994
|
return;
|
|
5694
5995
|
} catch (error2) {
|
|
5695
|
-
|
|
5996
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5696
5997
|
next(error2);
|
|
5697
5998
|
return;
|
|
5698
5999
|
}
|
|
@@ -5707,7 +6008,7 @@ function useScheduleTaskController() {
|
|
|
5707
6008
|
});
|
|
5708
6009
|
const { error } = validation.validate(query);
|
|
5709
6010
|
if (error) {
|
|
5710
|
-
|
|
6011
|
+
logger33.log({ level: "error", message: error.message });
|
|
5711
6012
|
next(new BadRequestError30(error.message));
|
|
5712
6013
|
return;
|
|
5713
6014
|
}
|
|
@@ -5725,7 +6026,7 @@ function useScheduleTaskController() {
|
|
|
5725
6026
|
res.json(data);
|
|
5726
6027
|
return;
|
|
5727
6028
|
} catch (error2) {
|
|
5728
|
-
|
|
6029
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5729
6030
|
next(error2);
|
|
5730
6031
|
return;
|
|
5731
6032
|
}
|
|
@@ -5740,7 +6041,7 @@ function useScheduleTaskController() {
|
|
|
5740
6041
|
});
|
|
5741
6042
|
const { error } = validation.validate(query);
|
|
5742
6043
|
if (error) {
|
|
5743
|
-
|
|
6044
|
+
logger33.log({ level: "error", message: error.message });
|
|
5744
6045
|
next(new BadRequestError30(error.message));
|
|
5745
6046
|
return;
|
|
5746
6047
|
}
|
|
@@ -5758,7 +6059,7 @@ function useScheduleTaskController() {
|
|
|
5758
6059
|
res.json(data);
|
|
5759
6060
|
return;
|
|
5760
6061
|
} catch (error2) {
|
|
5761
|
-
|
|
6062
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5762
6063
|
next(error2);
|
|
5763
6064
|
return;
|
|
5764
6065
|
}
|
|
@@ -5768,7 +6069,7 @@ function useScheduleTaskController() {
|
|
|
5768
6069
|
const _id = req.params.id;
|
|
5769
6070
|
const { error, value } = validation.validate(_id);
|
|
5770
6071
|
if (error) {
|
|
5771
|
-
|
|
6072
|
+
logger33.log({ level: "error", message: error.message });
|
|
5772
6073
|
next(new BadRequestError30(error.message));
|
|
5773
6074
|
return;
|
|
5774
6075
|
}
|
|
@@ -5777,7 +6078,7 @@ function useScheduleTaskController() {
|
|
|
5777
6078
|
res.json(data);
|
|
5778
6079
|
return;
|
|
5779
6080
|
} catch (error2) {
|
|
5780
|
-
|
|
6081
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5781
6082
|
next(error2);
|
|
5782
6083
|
return;
|
|
5783
6084
|
}
|
|
@@ -5800,7 +6101,7 @@ function useScheduleTaskController() {
|
|
|
5800
6101
|
});
|
|
5801
6102
|
const { error } = validation.validate(payload);
|
|
5802
6103
|
if (error) {
|
|
5803
|
-
|
|
6104
|
+
logger33.log({ level: "error", message: error.message });
|
|
5804
6105
|
next(new BadRequestError30(error.message));
|
|
5805
6106
|
return;
|
|
5806
6107
|
}
|
|
@@ -5810,7 +6111,7 @@ function useScheduleTaskController() {
|
|
|
5810
6111
|
res.json({ message: "Schedule task updated successfully." });
|
|
5811
6112
|
return;
|
|
5812
6113
|
} catch (error2) {
|
|
5813
|
-
|
|
6114
|
+
logger33.log({ level: "error", message: error2.message });
|
|
5814
6115
|
next(error2);
|
|
5815
6116
|
return;
|
|
5816
6117
|
}
|
|
@@ -5825,8 +6126,8 @@ function useScheduleTaskController() {
|
|
|
5825
6126
|
}
|
|
5826
6127
|
|
|
5827
6128
|
// src/services/hygiene-qr.service.ts
|
|
5828
|
-
import { logger as
|
|
5829
|
-
import { launch } from "puppeteer";
|
|
6129
|
+
import { logger as logger34 } from "@7365admin1/node-server-utils";
|
|
6130
|
+
import { launch as launch2 } from "puppeteer";
|
|
5830
6131
|
import QRCode from "qrcode";
|
|
5831
6132
|
function useQRService() {
|
|
5832
6133
|
async function generateQRDataUrl(qrUrl) {
|
|
@@ -5843,7 +6144,7 @@ function useQRService() {
|
|
|
5843
6144
|
async function generateQRImage(qrUrl) {
|
|
5844
6145
|
try {
|
|
5845
6146
|
const qrDataUrl = await generateQRDataUrl(qrUrl);
|
|
5846
|
-
const browser = await
|
|
6147
|
+
const browser = await launch2({
|
|
5847
6148
|
headless: true,
|
|
5848
6149
|
executablePath: process.env.CHROME_BINARY,
|
|
5849
6150
|
args: [`--no-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`]
|
|
@@ -5896,7 +6197,7 @@ function useQRService() {
|
|
|
5896
6197
|
await browser.close();
|
|
5897
6198
|
return imageBuffer;
|
|
5898
6199
|
} catch (error) {
|
|
5899
|
-
|
|
6200
|
+
logger34.log({
|
|
5900
6201
|
level: "error",
|
|
5901
6202
|
message: `Failed to generate QR image: ${error.message}`
|
|
5902
6203
|
});
|
|
@@ -5906,7 +6207,7 @@ function useQRService() {
|
|
|
5906
6207
|
async function generateQRPDF(qrUrl, title) {
|
|
5907
6208
|
try {
|
|
5908
6209
|
const qrDataUrl = await generateQRDataUrl(qrUrl);
|
|
5909
|
-
const browser = await
|
|
6210
|
+
const browser = await launch2({
|
|
5910
6211
|
headless: true,
|
|
5911
6212
|
executablePath: process.env.CHROME_BINARY,
|
|
5912
6213
|
args: [`--no-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`]
|
|
@@ -6019,7 +6320,7 @@ function useQRService() {
|
|
|
6019
6320
|
await browser.close();
|
|
6020
6321
|
return pdfBuffer;
|
|
6021
6322
|
} catch (error) {
|
|
6022
|
-
|
|
6323
|
+
logger34.log({
|
|
6023
6324
|
level: "error",
|
|
6024
6325
|
message: `Failed to generate QR PDF: ${error.message}`
|
|
6025
6326
|
});
|
|
@@ -6034,7 +6335,7 @@ function useQRService() {
|
|
|
6034
6335
|
|
|
6035
6336
|
// src/controllers/hygiene-qr.controller.ts
|
|
6036
6337
|
import Joi18 from "joi";
|
|
6037
|
-
import { BadRequestError as BadRequestError31, logger as
|
|
6338
|
+
import { BadRequestError as BadRequestError31, logger as logger35 } from "@7365admin1/node-server-utils";
|
|
6038
6339
|
function useQRController() {
|
|
6039
6340
|
const { generateQRImage: _generateQRImage, generateQRPDF: _generateQRPDF } = useQRService();
|
|
6040
6341
|
async function generateQR(req, res, next) {
|
|
@@ -6047,7 +6348,7 @@ function useQRController() {
|
|
|
6047
6348
|
const query = { ...req.query };
|
|
6048
6349
|
const { error, value } = validation.validate(query);
|
|
6049
6350
|
if (error) {
|
|
6050
|
-
|
|
6351
|
+
logger35.log({ level: "error", message: error.message });
|
|
6051
6352
|
next(new BadRequestError31(error.message));
|
|
6052
6353
|
return;
|
|
6053
6354
|
}
|
|
@@ -6083,7 +6384,7 @@ function useQRController() {
|
|
|
6083
6384
|
}
|
|
6084
6385
|
return;
|
|
6085
6386
|
} catch (error2) {
|
|
6086
|
-
|
|
6387
|
+
logger35.log({ level: "error", message: error2.message });
|
|
6087
6388
|
next(error2);
|
|
6088
6389
|
return;
|
|
6089
6390
|
}
|