@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.js
CHANGED
|
@@ -3131,6 +3131,38 @@ function useAreaChecklistRepo() {
|
|
|
3131
3131
|
preserveNullAndEmptyArrays: false
|
|
3132
3132
|
}
|
|
3133
3133
|
},
|
|
3134
|
+
{
|
|
3135
|
+
$addFields: {
|
|
3136
|
+
isCompleted: { $ne: ["$checklist.units.completedBy", ""] }
|
|
3137
|
+
}
|
|
3138
|
+
},
|
|
3139
|
+
{
|
|
3140
|
+
$lookup: {
|
|
3141
|
+
from: "users",
|
|
3142
|
+
let: { completedById: "$checklist.units.completedBy" },
|
|
3143
|
+
pipeline: [
|
|
3144
|
+
{
|
|
3145
|
+
$match: {
|
|
3146
|
+
$expr: {
|
|
3147
|
+
$and: [
|
|
3148
|
+
{ $ne: ["$$completedById", ""] },
|
|
3149
|
+
{ $eq: ["$_id", "$$completedById"] }
|
|
3150
|
+
]
|
|
3151
|
+
}
|
|
3152
|
+
}
|
|
3153
|
+
},
|
|
3154
|
+
{ $project: { name: 1 } }
|
|
3155
|
+
],
|
|
3156
|
+
as: "completedBy"
|
|
3157
|
+
}
|
|
3158
|
+
},
|
|
3159
|
+
{
|
|
3160
|
+
$unwind: {
|
|
3161
|
+
path: "$completedBy",
|
|
3162
|
+
preserveNullAndEmptyArrays: true
|
|
3163
|
+
}
|
|
3164
|
+
},
|
|
3165
|
+
{ $sort: { set: 1, isCompleted: -1, "checklist.units.timestamp": 1 } },
|
|
3134
3166
|
{
|
|
3135
3167
|
$project: {
|
|
3136
3168
|
_id: 0,
|
|
@@ -3155,15 +3187,16 @@ function useAreaChecklistRepo() {
|
|
|
3155
3187
|
],
|
|
3156
3188
|
default: "$checklist.units.status"
|
|
3157
3189
|
}
|
|
3158
|
-
}
|
|
3190
|
+
},
|
|
3191
|
+
completedByName: "$completedBy.name"
|
|
3159
3192
|
}
|
|
3160
3193
|
},
|
|
3161
|
-
{ $sort: { set: 1, name: 1 } },
|
|
3162
3194
|
{
|
|
3163
3195
|
$group: {
|
|
3164
3196
|
_id: "$set",
|
|
3165
3197
|
remarks: { $first: "$remarks" },
|
|
3166
3198
|
attachment: { $first: "$attachment" },
|
|
3199
|
+
completedByName: { $first: "$completedByName" },
|
|
3167
3200
|
units: {
|
|
3168
3201
|
$push: {
|
|
3169
3202
|
unit: "$unit",
|
|
@@ -3171,7 +3204,8 @@ function useAreaChecklistRepo() {
|
|
|
3171
3204
|
approve: "$approve",
|
|
3172
3205
|
reject: "$reject",
|
|
3173
3206
|
status: "$status",
|
|
3174
|
-
remarks: "$remarks"
|
|
3207
|
+
remarks: "$remarks",
|
|
3208
|
+
completedByName: "$completedByName"
|
|
3175
3209
|
}
|
|
3176
3210
|
}
|
|
3177
3211
|
}
|
|
@@ -3182,6 +3216,7 @@ function useAreaChecklistRepo() {
|
|
|
3182
3216
|
set: "$_id",
|
|
3183
3217
|
remarks: "$remarks",
|
|
3184
3218
|
attachment: "$attachment",
|
|
3219
|
+
completedByName: 1,
|
|
3185
3220
|
units: 1
|
|
3186
3221
|
}
|
|
3187
3222
|
},
|
|
@@ -3591,7 +3626,223 @@ function useAreaChecklistService() {
|
|
|
3591
3626
|
|
|
3592
3627
|
// src/controllers/hygiene-area-checklist.controller.ts
|
|
3593
3628
|
var import_joi9 = __toESM(require("joi"));
|
|
3629
|
+
var import_node_server_utils20 = require("@7365admin1/node-server-utils");
|
|
3630
|
+
|
|
3631
|
+
// src/services/hygiene-checklist-pdf.service.ts
|
|
3632
|
+
var import_puppeteer = require("puppeteer");
|
|
3594
3633
|
var import_node_server_utils19 = require("@7365admin1/node-server-utils");
|
|
3634
|
+
var import_mongodb10 = require("mongodb");
|
|
3635
|
+
function escapeHtml(text) {
|
|
3636
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
3637
|
+
}
|
|
3638
|
+
function buildChecklistHtml(areaChecklists) {
|
|
3639
|
+
const areaSections = areaChecklists.map((area) => {
|
|
3640
|
+
const sortedChecklist = [...area.checklist || []].sort(
|
|
3641
|
+
(a, b) => a.set - b.set
|
|
3642
|
+
);
|
|
3643
|
+
const setRows = sortedChecklist.map((setItem) => {
|
|
3644
|
+
const unitRows = (setItem.units || []).map(
|
|
3645
|
+
(unit) => `
|
|
3646
|
+
<tr>
|
|
3647
|
+
<td class="unit-name">${escapeHtml(unit.name || "")}</td>
|
|
3648
|
+
<td class="icon-cell">${unit.reject ? '<span class="reject-icon">✗</span>' : ""}</td>
|
|
3649
|
+
<td class="icon-cell">${unit.approve ? '<span class="approve-icon">✓</span>' : ""}</td>
|
|
3650
|
+
</tr>`
|
|
3651
|
+
).join("");
|
|
3652
|
+
return `
|
|
3653
|
+
<tr class="set-header-row">
|
|
3654
|
+
<td colspan="3">Set ${setItem.set}</td>
|
|
3655
|
+
</tr>
|
|
3656
|
+
${unitRows}`;
|
|
3657
|
+
}).join("");
|
|
3658
|
+
return `
|
|
3659
|
+
<div class="area-section">
|
|
3660
|
+
<div class="area-header">
|
|
3661
|
+
<span class="area-name">${escapeHtml(area.name || "")}</span>
|
|
3662
|
+
<span class="area-type">${escapeHtml(area.type || "")}</span>
|
|
3663
|
+
</div>
|
|
3664
|
+
<table class="checklist-table">
|
|
3665
|
+
<thead>
|
|
3666
|
+
<tr>
|
|
3667
|
+
<th class="col-unit">Unit</th>
|
|
3668
|
+
<th class="col-icon">✗</th>
|
|
3669
|
+
<th class="col-icon">✓</th>
|
|
3670
|
+
</tr>
|
|
3671
|
+
</thead>
|
|
3672
|
+
<tbody>
|
|
3673
|
+
${setRows}
|
|
3674
|
+
</tbody>
|
|
3675
|
+
</table>
|
|
3676
|
+
</div>`;
|
|
3677
|
+
}).join("");
|
|
3678
|
+
return `<!DOCTYPE html>
|
|
3679
|
+
<html lang="en">
|
|
3680
|
+
<head>
|
|
3681
|
+
<meta charset="UTF-8">
|
|
3682
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
3683
|
+
<title>Checklist</title>
|
|
3684
|
+
<style>
|
|
3685
|
+
* {
|
|
3686
|
+
margin: 0;
|
|
3687
|
+
padding: 0;
|
|
3688
|
+
box-sizing: border-box;
|
|
3689
|
+
}
|
|
3690
|
+
body {
|
|
3691
|
+
font-family: Arial, Helvetica, sans-serif;
|
|
3692
|
+
background: #ffffff;
|
|
3693
|
+
padding: 30px 35px;
|
|
3694
|
+
color: #1a1a1a;
|
|
3695
|
+
font-size: 13px;
|
|
3696
|
+
}
|
|
3697
|
+
.page-header {
|
|
3698
|
+
display: flex;
|
|
3699
|
+
align-items: center;
|
|
3700
|
+
justify-content: flex-start;
|
|
3701
|
+
background: #1a3a6b;
|
|
3702
|
+
margin-bottom: 24px;
|
|
3703
|
+
padding: 12px 16px;
|
|
3704
|
+
border-radius: 4px;
|
|
3705
|
+
}
|
|
3706
|
+
.page-logo {
|
|
3707
|
+
height: 40px;
|
|
3708
|
+
width: auto;
|
|
3709
|
+
object-fit: contain;
|
|
3710
|
+
}
|
|
3711
|
+
.area-section {
|
|
3712
|
+
margin-bottom: 22px;
|
|
3713
|
+
border: 1px solid #dce1e7;
|
|
3714
|
+
border-radius: 4px;
|
|
3715
|
+
overflow: hidden;
|
|
3716
|
+
page-break-inside: avoid;
|
|
3717
|
+
}
|
|
3718
|
+
.area-header {
|
|
3719
|
+
display: flex;
|
|
3720
|
+
align-items: center;
|
|
3721
|
+
justify-content: space-between;
|
|
3722
|
+
background: #2c3e50;
|
|
3723
|
+
color: #ffffff;
|
|
3724
|
+
padding: 9px 12px;
|
|
3725
|
+
}
|
|
3726
|
+
.area-name {
|
|
3727
|
+
font-size: 14px;
|
|
3728
|
+
font-weight: 600;
|
|
3729
|
+
}
|
|
3730
|
+
.area-type {
|
|
3731
|
+
font-size: 11px;
|
|
3732
|
+
text-transform: capitalize;
|
|
3733
|
+
background: rgba(255,255,255,0.2);
|
|
3734
|
+
padding: 2px 8px;
|
|
3735
|
+
border-radius: 10px;
|
|
3736
|
+
}
|
|
3737
|
+
.checklist-table {
|
|
3738
|
+
width: 100%;
|
|
3739
|
+
border-collapse: collapse;
|
|
3740
|
+
}
|
|
3741
|
+
.checklist-table thead tr th {
|
|
3742
|
+
background: #34495e;
|
|
3743
|
+
color: #ffffff;
|
|
3744
|
+
padding: 7px 10px;
|
|
3745
|
+
text-align: left;
|
|
3746
|
+
font-size: 12px;
|
|
3747
|
+
font-weight: 600;
|
|
3748
|
+
letter-spacing: 0.3px;
|
|
3749
|
+
}
|
|
3750
|
+
.checklist-table thead tr th.col-icon {
|
|
3751
|
+
text-align: center;
|
|
3752
|
+
width: 52px;
|
|
3753
|
+
}
|
|
3754
|
+
.checklist-table thead tr th.col-unit {
|
|
3755
|
+
width: auto;
|
|
3756
|
+
}
|
|
3757
|
+
.set-header-row td {
|
|
3758
|
+
background: #ecf0f1;
|
|
3759
|
+
color: #555;
|
|
3760
|
+
font-weight: 700;
|
|
3761
|
+
font-size: 12px;
|
|
3762
|
+
padding: 5px 10px;
|
|
3763
|
+
border-bottom: 1px solid #dce1e7;
|
|
3764
|
+
text-transform: uppercase;
|
|
3765
|
+
letter-spacing: 0.4px;
|
|
3766
|
+
}
|
|
3767
|
+
.checklist-table tbody tr td {
|
|
3768
|
+
padding: 7px 10px;
|
|
3769
|
+
border-bottom: 1px solid #f0f2f4;
|
|
3770
|
+
font-size: 13px;
|
|
3771
|
+
}
|
|
3772
|
+
.checklist-table tbody tr:last-child td {
|
|
3773
|
+
border-bottom: none;
|
|
3774
|
+
}
|
|
3775
|
+
.icon-cell {
|
|
3776
|
+
text-align: center;
|
|
3777
|
+
width: 52px;
|
|
3778
|
+
}
|
|
3779
|
+
.approve-icon {
|
|
3780
|
+
color: #27ae60;
|
|
3781
|
+
font-size: 16px;
|
|
3782
|
+
font-weight: bold;
|
|
3783
|
+
}
|
|
3784
|
+
.reject-icon {
|
|
3785
|
+
color: #e74c3c;
|
|
3786
|
+
font-size: 16px;
|
|
3787
|
+
font-weight: bold;
|
|
3788
|
+
}
|
|
3789
|
+
</style>
|
|
3790
|
+
</head>
|
|
3791
|
+
<body>
|
|
3792
|
+
<div class="page-header">
|
|
3793
|
+
<img class="page-logo" src="https://seven365-storage.sgp1.cdn.digitaloceanspaces.com/seven365-public/images/seven365-logo.png" alt="Seven365 Logo" />
|
|
3794
|
+
</div>
|
|
3795
|
+
${areaSections}
|
|
3796
|
+
</body>
|
|
3797
|
+
</html>`;
|
|
3798
|
+
}
|
|
3799
|
+
function useChecklistPdfService() {
|
|
3800
|
+
async function generateChecklistPdf(scheduleId) {
|
|
3801
|
+
const db = import_node_server_utils19.useAtlas.getDb();
|
|
3802
|
+
if (!db) {
|
|
3803
|
+
throw new import_node_server_utils19.InternalServerError("Unable to connect to server.");
|
|
3804
|
+
}
|
|
3805
|
+
const collection = db.collection("site.cleaning.schedule.areas");
|
|
3806
|
+
let scheduleObjectId;
|
|
3807
|
+
try {
|
|
3808
|
+
scheduleObjectId = new import_mongodb10.ObjectId(scheduleId);
|
|
3809
|
+
} catch {
|
|
3810
|
+
throw new import_node_server_utils19.InternalServerError("Invalid schedule ID format.");
|
|
3811
|
+
}
|
|
3812
|
+
const areaChecklists = await collection.find({ schedule: scheduleObjectId }).sort({ createdAt: 1, name: 1 }).toArray();
|
|
3813
|
+
const html = buildChecklistHtml(areaChecklists);
|
|
3814
|
+
const browser = await (0, import_puppeteer.launch)({
|
|
3815
|
+
headless: true,
|
|
3816
|
+
executablePath: process.env.CHROME_BINARY,
|
|
3817
|
+
args: ["--no-sandbox", "--disable-gpu", "--disable-dev-shm-usage"]
|
|
3818
|
+
});
|
|
3819
|
+
try {
|
|
3820
|
+
const page = await browser.newPage();
|
|
3821
|
+
await page.setViewport({ width: 794, height: 1123 });
|
|
3822
|
+
await page.setContent(html, {
|
|
3823
|
+
waitUntil: ["load", "networkidle0"]
|
|
3824
|
+
});
|
|
3825
|
+
const pdfBuffer = await page.pdf({
|
|
3826
|
+
format: "A4",
|
|
3827
|
+
printBackground: true,
|
|
3828
|
+
margin: {
|
|
3829
|
+
top: "15mm",
|
|
3830
|
+
right: "15mm",
|
|
3831
|
+
bottom: "15mm",
|
|
3832
|
+
left: "15mm"
|
|
3833
|
+
}
|
|
3834
|
+
});
|
|
3835
|
+
return pdfBuffer;
|
|
3836
|
+
} finally {
|
|
3837
|
+
await browser.close();
|
|
3838
|
+
}
|
|
3839
|
+
}
|
|
3840
|
+
return {
|
|
3841
|
+
generateChecklistPdf
|
|
3842
|
+
};
|
|
3843
|
+
}
|
|
3844
|
+
|
|
3845
|
+
// src/controllers/hygiene-area-checklist.controller.ts
|
|
3595
3846
|
function useAreaChecklistController() {
|
|
3596
3847
|
const {
|
|
3597
3848
|
getAllAreaChecklist: _getAllAreaChecklist,
|
|
@@ -3603,6 +3854,7 @@ function useAreaChecklistController() {
|
|
|
3603
3854
|
createAreaChecklist: _createAreaChecklist,
|
|
3604
3855
|
updateAreaChecklistUnits: _updateAreaChecklistUnits
|
|
3605
3856
|
} = useAreaChecklistService();
|
|
3857
|
+
const { generateChecklistPdf: _generateChecklistPdf } = useChecklistPdfService();
|
|
3606
3858
|
async function createAreaChecklist(req, res, next) {
|
|
3607
3859
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
3608
3860
|
(acc, [key, value2]) => ({ ...acc, [key]: value2 }),
|
|
@@ -3621,8 +3873,8 @@ function useAreaChecklistController() {
|
|
|
3621
3873
|
});
|
|
3622
3874
|
const { error, value } = validation.validate(payload);
|
|
3623
3875
|
if (error) {
|
|
3624
|
-
|
|
3625
|
-
next(new
|
|
3876
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
3877
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3626
3878
|
return;
|
|
3627
3879
|
}
|
|
3628
3880
|
try {
|
|
@@ -3630,7 +3882,7 @@ function useAreaChecklistController() {
|
|
|
3630
3882
|
res.status(201).json({ message: "Area checklist generated successfully." });
|
|
3631
3883
|
return;
|
|
3632
3884
|
} catch (error2) {
|
|
3633
|
-
|
|
3885
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3634
3886
|
next(error2);
|
|
3635
3887
|
return;
|
|
3636
3888
|
}
|
|
@@ -3647,8 +3899,8 @@ function useAreaChecklistController() {
|
|
|
3647
3899
|
});
|
|
3648
3900
|
const { error } = validation.validate(query);
|
|
3649
3901
|
if (error) {
|
|
3650
|
-
|
|
3651
|
-
next(new
|
|
3902
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
3903
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3652
3904
|
return;
|
|
3653
3905
|
}
|
|
3654
3906
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -3669,7 +3921,7 @@ function useAreaChecklistController() {
|
|
|
3669
3921
|
res.json(data);
|
|
3670
3922
|
return;
|
|
3671
3923
|
} catch (error2) {
|
|
3672
|
-
|
|
3924
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3673
3925
|
next(error2);
|
|
3674
3926
|
return;
|
|
3675
3927
|
}
|
|
@@ -3687,8 +3939,8 @@ function useAreaChecklistController() {
|
|
|
3687
3939
|
});
|
|
3688
3940
|
const { error } = validation.validate(query);
|
|
3689
3941
|
if (error) {
|
|
3690
|
-
|
|
3691
|
-
next(new
|
|
3942
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
3943
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3692
3944
|
return;
|
|
3693
3945
|
}
|
|
3694
3946
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -3711,7 +3963,7 @@ function useAreaChecklistController() {
|
|
|
3711
3963
|
res.json(data);
|
|
3712
3964
|
return;
|
|
3713
3965
|
} catch (error2) {
|
|
3714
|
-
|
|
3966
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3715
3967
|
next(error2);
|
|
3716
3968
|
return;
|
|
3717
3969
|
}
|
|
@@ -3721,8 +3973,8 @@ function useAreaChecklistController() {
|
|
|
3721
3973
|
const _id = req.params.id;
|
|
3722
3974
|
const { error, value } = validation.validate(_id);
|
|
3723
3975
|
if (error) {
|
|
3724
|
-
|
|
3725
|
-
next(new
|
|
3976
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
3977
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3726
3978
|
return;
|
|
3727
3979
|
}
|
|
3728
3980
|
try {
|
|
@@ -3730,7 +3982,7 @@ function useAreaChecklistController() {
|
|
|
3730
3982
|
res.json(data);
|
|
3731
3983
|
return;
|
|
3732
3984
|
} catch (error2) {
|
|
3733
|
-
|
|
3985
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3734
3986
|
next(error2);
|
|
3735
3987
|
return;
|
|
3736
3988
|
}
|
|
@@ -3745,8 +3997,8 @@ function useAreaChecklistController() {
|
|
|
3745
3997
|
});
|
|
3746
3998
|
const { error } = validation.validate(query);
|
|
3747
3999
|
if (error) {
|
|
3748
|
-
|
|
3749
|
-
next(new
|
|
4000
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
4001
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3750
4002
|
return;
|
|
3751
4003
|
}
|
|
3752
4004
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -3763,7 +4015,7 @@ function useAreaChecklistController() {
|
|
|
3763
4015
|
res.json(data);
|
|
3764
4016
|
return;
|
|
3765
4017
|
} catch (error2) {
|
|
3766
|
-
|
|
4018
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3767
4019
|
next(error2);
|
|
3768
4020
|
return;
|
|
3769
4021
|
}
|
|
@@ -3802,8 +4054,8 @@ function useAreaChecklistController() {
|
|
|
3802
4054
|
});
|
|
3803
4055
|
const { error } = validation.validate(payload);
|
|
3804
4056
|
if (error) {
|
|
3805
|
-
|
|
3806
|
-
next(new
|
|
4057
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
4058
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3807
4059
|
return;
|
|
3808
4060
|
}
|
|
3809
4061
|
try {
|
|
@@ -3812,7 +4064,39 @@ function useAreaChecklistController() {
|
|
|
3812
4064
|
res.json({ message: "Area checklist updated successfully." });
|
|
3813
4065
|
return;
|
|
3814
4066
|
} catch (error2) {
|
|
3815
|
-
|
|
4067
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
4068
|
+
next(error2);
|
|
4069
|
+
return;
|
|
4070
|
+
}
|
|
4071
|
+
}
|
|
4072
|
+
async function downloadChecklistPdf(req, res, next) {
|
|
4073
|
+
const validation = import_joi9.default.string().hex().required();
|
|
4074
|
+
const schedule = req.params.schedule;
|
|
4075
|
+
const { error, value } = validation.validate(schedule);
|
|
4076
|
+
if (error) {
|
|
4077
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
4078
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
4079
|
+
return;
|
|
4080
|
+
}
|
|
4081
|
+
try {
|
|
4082
|
+
const pdfBuffer = await _generateChecklistPdf(value);
|
|
4083
|
+
if (!pdfBuffer || pdfBuffer.length === 0) {
|
|
4084
|
+
throw new import_node_server_utils20.InternalServerError("Generated checklist PDF is empty or invalid.");
|
|
4085
|
+
}
|
|
4086
|
+
const date = /* @__PURE__ */ new Date();
|
|
4087
|
+
const formattedDate = `${String(date.getDate()).padStart(2, "0")}_${String(
|
|
4088
|
+
date.getMonth() + 1
|
|
4089
|
+
).padStart(2, "0")}_${date.getFullYear()}`;
|
|
4090
|
+
res.setHeader("Content-Type", "application/pdf");
|
|
4091
|
+
res.setHeader(
|
|
4092
|
+
"Content-Disposition",
|
|
4093
|
+
`attachment; filename="CHECKLIST_${formattedDate}.pdf"`
|
|
4094
|
+
);
|
|
4095
|
+
res.setHeader("Content-Length", pdfBuffer.length);
|
|
4096
|
+
res.end(pdfBuffer);
|
|
4097
|
+
return;
|
|
4098
|
+
} catch (error2) {
|
|
4099
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3816
4100
|
next(error2);
|
|
3817
4101
|
return;
|
|
3818
4102
|
}
|
|
@@ -3823,14 +4107,15 @@ function useAreaChecklistController() {
|
|
|
3823
4107
|
getAreaChecklistHistory,
|
|
3824
4108
|
getAreaChecklistHistoryDetails,
|
|
3825
4109
|
getAreaChecklistUnits,
|
|
3826
|
-
updateAreaChecklistUnits
|
|
4110
|
+
updateAreaChecklistUnits,
|
|
4111
|
+
downloadChecklistPdf
|
|
3827
4112
|
};
|
|
3828
4113
|
}
|
|
3829
4114
|
|
|
3830
4115
|
// src/models/hygiene-supply.model.ts
|
|
3831
4116
|
var import_joi10 = __toESM(require("joi"));
|
|
3832
|
-
var
|
|
3833
|
-
var
|
|
4117
|
+
var import_mongodb11 = require("mongodb");
|
|
4118
|
+
var import_node_server_utils21 = require("@7365admin1/node-server-utils");
|
|
3834
4119
|
var supplySchema = import_joi10.default.object({
|
|
3835
4120
|
site: import_joi10.default.string().hex().required(),
|
|
3836
4121
|
name: import_joi10.default.string().required(),
|
|
@@ -3839,14 +4124,14 @@ var supplySchema = import_joi10.default.object({
|
|
|
3839
4124
|
function MSupply(value) {
|
|
3840
4125
|
const { error } = supplySchema.validate(value);
|
|
3841
4126
|
if (error) {
|
|
3842
|
-
|
|
3843
|
-
throw new
|
|
4127
|
+
import_node_server_utils21.logger.info(`Hygiene Supply Model: ${error.message}`);
|
|
4128
|
+
throw new import_node_server_utils21.BadRequestError(error.message);
|
|
3844
4129
|
}
|
|
3845
4130
|
if (value.site) {
|
|
3846
4131
|
try {
|
|
3847
|
-
value.site = new
|
|
4132
|
+
value.site = new import_mongodb11.ObjectId(value.site);
|
|
3848
4133
|
} catch (error2) {
|
|
3849
|
-
throw new
|
|
4134
|
+
throw new import_node_server_utils21.BadRequestError("Invalid site ID format.");
|
|
3850
4135
|
}
|
|
3851
4136
|
}
|
|
3852
4137
|
return {
|
|
@@ -3862,21 +4147,21 @@ function MSupply(value) {
|
|
|
3862
4147
|
}
|
|
3863
4148
|
|
|
3864
4149
|
// src/repositories/hygiene-supply.repository.ts
|
|
3865
|
-
var
|
|
3866
|
-
var
|
|
4150
|
+
var import_mongodb12 = require("mongodb");
|
|
4151
|
+
var import_node_server_utils22 = require("@7365admin1/node-server-utils");
|
|
3867
4152
|
function useSupplyRepository() {
|
|
3868
|
-
const db =
|
|
4153
|
+
const db = import_node_server_utils22.useAtlas.getDb();
|
|
3869
4154
|
if (!db) {
|
|
3870
|
-
throw new
|
|
4155
|
+
throw new import_node_server_utils22.InternalServerError("Unable to connect to server.");
|
|
3871
4156
|
}
|
|
3872
4157
|
const namespace_collection = "site.supplies";
|
|
3873
4158
|
const collection = db.collection(namespace_collection);
|
|
3874
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
4159
|
+
const { delNamespace, setCache, getCache } = (0, import_node_server_utils22.useCache)(namespace_collection);
|
|
3875
4160
|
async function createIndex() {
|
|
3876
4161
|
try {
|
|
3877
4162
|
await collection.createIndexes([{ key: { site: 1 } }]);
|
|
3878
4163
|
} catch (error) {
|
|
3879
|
-
throw new
|
|
4164
|
+
throw new import_node_server_utils22.InternalServerError(
|
|
3880
4165
|
"Failed to create index on hygiene supply."
|
|
3881
4166
|
);
|
|
3882
4167
|
}
|
|
@@ -3885,7 +4170,7 @@ function useSupplyRepository() {
|
|
|
3885
4170
|
try {
|
|
3886
4171
|
await collection.createIndex({ name: "text" });
|
|
3887
4172
|
} catch (error) {
|
|
3888
|
-
throw new
|
|
4173
|
+
throw new import_node_server_utils22.InternalServerError(
|
|
3889
4174
|
"Failed to create text index on hygiene supply."
|
|
3890
4175
|
);
|
|
3891
4176
|
}
|
|
@@ -3897,7 +4182,7 @@ function useSupplyRepository() {
|
|
|
3897
4182
|
{ unique: true }
|
|
3898
4183
|
);
|
|
3899
4184
|
} catch (error) {
|
|
3900
|
-
throw new
|
|
4185
|
+
throw new import_node_server_utils22.InternalServerError(
|
|
3901
4186
|
"Failed to create unique index on hygiene supply."
|
|
3902
4187
|
);
|
|
3903
4188
|
}
|
|
@@ -3907,9 +4192,9 @@ function useSupplyRepository() {
|
|
|
3907
4192
|
value = MSupply(value);
|
|
3908
4193
|
const res = await collection.insertOne(value, { session });
|
|
3909
4194
|
delNamespace().then(() => {
|
|
3910
|
-
|
|
4195
|
+
import_node_server_utils22.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
3911
4196
|
}).catch((err) => {
|
|
3912
|
-
|
|
4197
|
+
import_node_server_utils22.logger.error(
|
|
3913
4198
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
3914
4199
|
err
|
|
3915
4200
|
);
|
|
@@ -3918,7 +4203,7 @@ function useSupplyRepository() {
|
|
|
3918
4203
|
} catch (error) {
|
|
3919
4204
|
const isDuplicated = error.message.includes("duplicate");
|
|
3920
4205
|
if (isDuplicated) {
|
|
3921
|
-
throw new
|
|
4206
|
+
throw new import_node_server_utils22.BadRequestError("Supply already exists.");
|
|
3922
4207
|
}
|
|
3923
4208
|
throw error;
|
|
3924
4209
|
}
|
|
@@ -3938,20 +4223,20 @@ function useSupplyRepository() {
|
|
|
3938
4223
|
limit
|
|
3939
4224
|
};
|
|
3940
4225
|
try {
|
|
3941
|
-
site = new
|
|
4226
|
+
site = new import_mongodb12.ObjectId(site);
|
|
3942
4227
|
query.site = site;
|
|
3943
4228
|
cacheOptions.site = site.toString();
|
|
3944
4229
|
} catch (error) {
|
|
3945
|
-
throw new
|
|
4230
|
+
throw new import_node_server_utils22.BadRequestError("Invalid site ID format.");
|
|
3946
4231
|
}
|
|
3947
4232
|
if (search) {
|
|
3948
4233
|
query.$text = { $search: search };
|
|
3949
4234
|
cacheOptions.search = search;
|
|
3950
4235
|
}
|
|
3951
|
-
const cacheKey = (0,
|
|
4236
|
+
const cacheKey = (0, import_node_server_utils22.makeCacheKey)(namespace_collection, cacheOptions);
|
|
3952
4237
|
const cachedData = await getCache(cacheKey);
|
|
3953
4238
|
if (cachedData) {
|
|
3954
|
-
|
|
4239
|
+
import_node_server_utils22.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
3955
4240
|
return cachedData;
|
|
3956
4241
|
}
|
|
3957
4242
|
try {
|
|
@@ -3969,11 +4254,11 @@ function useSupplyRepository() {
|
|
|
3969
4254
|
{ $limit: limit }
|
|
3970
4255
|
]).toArray();
|
|
3971
4256
|
const length = await collection.countDocuments(query);
|
|
3972
|
-
const data = (0,
|
|
4257
|
+
const data = (0, import_node_server_utils22.paginate)(items, page, limit, length);
|
|
3973
4258
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
3974
|
-
|
|
4259
|
+
import_node_server_utils22.logger.info(`Cache set for key: ${cacheKey}`);
|
|
3975
4260
|
}).catch((err) => {
|
|
3976
|
-
|
|
4261
|
+
import_node_server_utils22.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
3977
4262
|
});
|
|
3978
4263
|
return data;
|
|
3979
4264
|
} catch (error) {
|
|
@@ -3982,25 +4267,25 @@ function useSupplyRepository() {
|
|
|
3982
4267
|
}
|
|
3983
4268
|
async function getSupplyById(_id, session) {
|
|
3984
4269
|
try {
|
|
3985
|
-
_id = new
|
|
4270
|
+
_id = new import_mongodb12.ObjectId(_id);
|
|
3986
4271
|
} catch (error) {
|
|
3987
|
-
throw new
|
|
4272
|
+
throw new import_node_server_utils22.BadRequestError("Invalid supply ID format.");
|
|
3988
4273
|
}
|
|
3989
4274
|
const query = {
|
|
3990
4275
|
_id,
|
|
3991
4276
|
status: { $ne: "deleted" }
|
|
3992
4277
|
};
|
|
3993
|
-
const cacheKey = (0,
|
|
4278
|
+
const cacheKey = (0, import_node_server_utils22.makeCacheKey)(namespace_collection, {
|
|
3994
4279
|
_id: _id.toString()
|
|
3995
4280
|
});
|
|
3996
4281
|
if (!session) {
|
|
3997
4282
|
const cachedData = await getCache(cacheKey);
|
|
3998
4283
|
if (cachedData) {
|
|
3999
|
-
|
|
4284
|
+
import_node_server_utils22.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
4000
4285
|
return cachedData;
|
|
4001
4286
|
}
|
|
4002
4287
|
} else {
|
|
4003
|
-
|
|
4288
|
+
import_node_server_utils22.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
4004
4289
|
}
|
|
4005
4290
|
try {
|
|
4006
4291
|
const data = await collection.aggregate([
|
|
@@ -4014,12 +4299,12 @@ function useSupplyRepository() {
|
|
|
4014
4299
|
}
|
|
4015
4300
|
]).toArray();
|
|
4016
4301
|
if (!data || data.length === 0) {
|
|
4017
|
-
throw new
|
|
4302
|
+
throw new import_node_server_utils22.NotFoundError("Supply not found.");
|
|
4018
4303
|
}
|
|
4019
4304
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
4020
|
-
|
|
4305
|
+
import_node_server_utils22.logger.info(`Cache set for key: ${cacheKey}`);
|
|
4021
4306
|
}).catch((err) => {
|
|
4022
|
-
|
|
4307
|
+
import_node_server_utils22.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4023
4308
|
});
|
|
4024
4309
|
return data[0];
|
|
4025
4310
|
} catch (error) {
|
|
@@ -4028,9 +4313,9 @@ function useSupplyRepository() {
|
|
|
4028
4313
|
}
|
|
4029
4314
|
async function updateSupply(_id, value, session) {
|
|
4030
4315
|
try {
|
|
4031
|
-
_id = new
|
|
4316
|
+
_id = new import_mongodb12.ObjectId(_id);
|
|
4032
4317
|
} catch (error) {
|
|
4033
|
-
throw new
|
|
4318
|
+
throw new import_node_server_utils22.BadRequestError("Invalid supply ID format.");
|
|
4034
4319
|
}
|
|
4035
4320
|
try {
|
|
4036
4321
|
const updateValue = { ...value, updatedAt: /* @__PURE__ */ new Date() };
|
|
@@ -4040,12 +4325,12 @@ function useSupplyRepository() {
|
|
|
4040
4325
|
{ session }
|
|
4041
4326
|
);
|
|
4042
4327
|
if (res.modifiedCount === 0) {
|
|
4043
|
-
throw new
|
|
4328
|
+
throw new import_node_server_utils22.InternalServerError("Unable to update cleaning supply.");
|
|
4044
4329
|
}
|
|
4045
4330
|
delNamespace().then(() => {
|
|
4046
|
-
|
|
4331
|
+
import_node_server_utils22.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4047
4332
|
}).catch((err) => {
|
|
4048
|
-
|
|
4333
|
+
import_node_server_utils22.logger.error(
|
|
4049
4334
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4050
4335
|
err
|
|
4051
4336
|
);
|
|
@@ -4054,16 +4339,16 @@ function useSupplyRepository() {
|
|
|
4054
4339
|
} catch (error) {
|
|
4055
4340
|
const isDuplicated = error.message.includes("duplicate");
|
|
4056
4341
|
if (isDuplicated) {
|
|
4057
|
-
throw new
|
|
4342
|
+
throw new import_node_server_utils22.BadRequestError("Supply already exists.");
|
|
4058
4343
|
}
|
|
4059
4344
|
throw error;
|
|
4060
4345
|
}
|
|
4061
4346
|
}
|
|
4062
4347
|
async function deleteSupply(_id, session) {
|
|
4063
4348
|
try {
|
|
4064
|
-
_id = new
|
|
4349
|
+
_id = new import_mongodb12.ObjectId(_id);
|
|
4065
4350
|
} catch (error) {
|
|
4066
|
-
throw new
|
|
4351
|
+
throw new import_node_server_utils22.BadRequestError("Invalid supply ID format.");
|
|
4067
4352
|
}
|
|
4068
4353
|
try {
|
|
4069
4354
|
const updateValue = {
|
|
@@ -4077,12 +4362,12 @@ function useSupplyRepository() {
|
|
|
4077
4362
|
{ session }
|
|
4078
4363
|
);
|
|
4079
4364
|
if (res.modifiedCount === 0) {
|
|
4080
|
-
throw new
|
|
4365
|
+
throw new import_node_server_utils22.InternalServerError("Unable to delete supply.");
|
|
4081
4366
|
}
|
|
4082
4367
|
delNamespace().then(() => {
|
|
4083
|
-
|
|
4368
|
+
import_node_server_utils22.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4084
4369
|
}).catch((err) => {
|
|
4085
|
-
|
|
4370
|
+
import_node_server_utils22.logger.error(
|
|
4086
4371
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4087
4372
|
err
|
|
4088
4373
|
);
|
|
@@ -4106,7 +4391,7 @@ function useSupplyRepository() {
|
|
|
4106
4391
|
|
|
4107
4392
|
// src/controllers/hygiene-supply.controller.ts
|
|
4108
4393
|
var import_joi11 = __toESM(require("joi"));
|
|
4109
|
-
var
|
|
4394
|
+
var import_node_server_utils23 = require("@7365admin1/node-server-utils");
|
|
4110
4395
|
function useSupplyController() {
|
|
4111
4396
|
const {
|
|
4112
4397
|
createSupply: _createSupply,
|
|
@@ -4119,8 +4404,8 @@ function useSupplyController() {
|
|
|
4119
4404
|
const payload = { ...req.body, ...req.params };
|
|
4120
4405
|
const { error } = supplySchema.validate(payload);
|
|
4121
4406
|
if (error) {
|
|
4122
|
-
|
|
4123
|
-
next(new
|
|
4407
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4408
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4124
4409
|
return;
|
|
4125
4410
|
}
|
|
4126
4411
|
try {
|
|
@@ -4128,7 +4413,7 @@ function useSupplyController() {
|
|
|
4128
4413
|
res.status(201).json({ message: "Supply created successfully.", id });
|
|
4129
4414
|
return;
|
|
4130
4415
|
} catch (error2) {
|
|
4131
|
-
|
|
4416
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4132
4417
|
next(error2);
|
|
4133
4418
|
return;
|
|
4134
4419
|
}
|
|
@@ -4143,8 +4428,8 @@ function useSupplyController() {
|
|
|
4143
4428
|
});
|
|
4144
4429
|
const { error } = validation.validate(query);
|
|
4145
4430
|
if (error) {
|
|
4146
|
-
|
|
4147
|
-
next(new
|
|
4431
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4432
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4148
4433
|
return;
|
|
4149
4434
|
}
|
|
4150
4435
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -4161,7 +4446,7 @@ function useSupplyController() {
|
|
|
4161
4446
|
res.json(data);
|
|
4162
4447
|
return;
|
|
4163
4448
|
} catch (error2) {
|
|
4164
|
-
|
|
4449
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4165
4450
|
next(error2);
|
|
4166
4451
|
return;
|
|
4167
4452
|
}
|
|
@@ -4171,8 +4456,8 @@ function useSupplyController() {
|
|
|
4171
4456
|
const _id = req.params.id;
|
|
4172
4457
|
const { error, value } = validation.validate(_id);
|
|
4173
4458
|
if (error) {
|
|
4174
|
-
|
|
4175
|
-
next(new
|
|
4459
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4460
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4176
4461
|
return;
|
|
4177
4462
|
}
|
|
4178
4463
|
try {
|
|
@@ -4180,7 +4465,7 @@ function useSupplyController() {
|
|
|
4180
4465
|
res.json(data);
|
|
4181
4466
|
return;
|
|
4182
4467
|
} catch (error2) {
|
|
4183
|
-
|
|
4468
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4184
4469
|
next(error2);
|
|
4185
4470
|
return;
|
|
4186
4471
|
}
|
|
@@ -4195,8 +4480,8 @@ function useSupplyController() {
|
|
|
4195
4480
|
});
|
|
4196
4481
|
const { error } = validation.validate(payload);
|
|
4197
4482
|
if (error) {
|
|
4198
|
-
|
|
4199
|
-
next(new
|
|
4483
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4484
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4200
4485
|
return;
|
|
4201
4486
|
}
|
|
4202
4487
|
try {
|
|
@@ -4205,7 +4490,7 @@ function useSupplyController() {
|
|
|
4205
4490
|
res.json({ message: "Supply updated successfully." });
|
|
4206
4491
|
return;
|
|
4207
4492
|
} catch (error2) {
|
|
4208
|
-
|
|
4493
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4209
4494
|
next(error2);
|
|
4210
4495
|
return;
|
|
4211
4496
|
}
|
|
@@ -4217,8 +4502,8 @@ function useSupplyController() {
|
|
|
4217
4502
|
});
|
|
4218
4503
|
const { error, value } = validation.validate({ id });
|
|
4219
4504
|
if (error) {
|
|
4220
|
-
|
|
4221
|
-
next(new
|
|
4505
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4506
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4222
4507
|
return;
|
|
4223
4508
|
}
|
|
4224
4509
|
try {
|
|
@@ -4226,7 +4511,7 @@ function useSupplyController() {
|
|
|
4226
4511
|
res.json({ message: "Supply deleted successfully." });
|
|
4227
4512
|
return;
|
|
4228
4513
|
} catch (error2) {
|
|
4229
|
-
|
|
4514
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4230
4515
|
next(error2);
|
|
4231
4516
|
return;
|
|
4232
4517
|
}
|
|
@@ -4242,8 +4527,8 @@ function useSupplyController() {
|
|
|
4242
4527
|
|
|
4243
4528
|
// src/models/hygiene-stock.model.ts
|
|
4244
4529
|
var import_joi12 = __toESM(require("joi"));
|
|
4245
|
-
var
|
|
4246
|
-
var
|
|
4530
|
+
var import_mongodb13 = require("mongodb");
|
|
4531
|
+
var import_node_server_utils24 = require("@7365admin1/node-server-utils");
|
|
4247
4532
|
var stockSchema = import_joi12.default.object({
|
|
4248
4533
|
site: import_joi12.default.string().hex().required(),
|
|
4249
4534
|
supply: import_joi12.default.string().hex().required(),
|
|
@@ -4255,21 +4540,21 @@ var stockSchema = import_joi12.default.object({
|
|
|
4255
4540
|
function MStock(value) {
|
|
4256
4541
|
const { error } = stockSchema.validate(value);
|
|
4257
4542
|
if (error) {
|
|
4258
|
-
|
|
4259
|
-
throw new
|
|
4543
|
+
import_node_server_utils24.logger.info(`Hygiene Stock Model: ${error.message}`);
|
|
4544
|
+
throw new import_node_server_utils24.BadRequestError(error.message);
|
|
4260
4545
|
}
|
|
4261
4546
|
if (value.site) {
|
|
4262
4547
|
try {
|
|
4263
|
-
value.site = new
|
|
4548
|
+
value.site = new import_mongodb13.ObjectId(value.site);
|
|
4264
4549
|
} catch (error2) {
|
|
4265
|
-
throw new
|
|
4550
|
+
throw new import_node_server_utils24.BadRequestError("Invalid site ID format.");
|
|
4266
4551
|
}
|
|
4267
4552
|
}
|
|
4268
4553
|
if (value.supply) {
|
|
4269
4554
|
try {
|
|
4270
|
-
value.supply = new
|
|
4555
|
+
value.supply = new import_mongodb13.ObjectId(value.supply);
|
|
4271
4556
|
} catch (error2) {
|
|
4272
|
-
throw new
|
|
4557
|
+
throw new import_node_server_utils24.BadRequestError("Invalid supply ID format.");
|
|
4273
4558
|
}
|
|
4274
4559
|
}
|
|
4275
4560
|
return {
|
|
@@ -4287,18 +4572,18 @@ function MStock(value) {
|
|
|
4287
4572
|
}
|
|
4288
4573
|
|
|
4289
4574
|
// src/repositories/hygiene-stock.repository.ts
|
|
4290
|
-
var
|
|
4291
|
-
var
|
|
4575
|
+
var import_mongodb14 = require("mongodb");
|
|
4576
|
+
var import_node_server_utils25 = require("@7365admin1/node-server-utils");
|
|
4292
4577
|
function useStockRepository() {
|
|
4293
|
-
const db =
|
|
4578
|
+
const db = import_node_server_utils25.useAtlas.getDb();
|
|
4294
4579
|
if (!db) {
|
|
4295
|
-
throw new
|
|
4580
|
+
throw new import_node_server_utils25.InternalServerError("Unable to connect to server.");
|
|
4296
4581
|
}
|
|
4297
4582
|
const namespace_collection = "site.supply.stocks";
|
|
4298
4583
|
const supply_collection = "site.supplies";
|
|
4299
4584
|
const collection = db.collection(namespace_collection);
|
|
4300
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
4301
|
-
const { delNamespace: delSupplyNamespace } = (0,
|
|
4585
|
+
const { delNamespace, setCache, getCache } = (0, import_node_server_utils25.useCache)(namespace_collection);
|
|
4586
|
+
const { delNamespace: delSupplyNamespace } = (0, import_node_server_utils25.useCache)(supply_collection);
|
|
4302
4587
|
async function createIndex() {
|
|
4303
4588
|
try {
|
|
4304
4589
|
await collection.createIndexes([
|
|
@@ -4308,7 +4593,7 @@ function useStockRepository() {
|
|
|
4308
4593
|
{ key: { status: 1 } }
|
|
4309
4594
|
]);
|
|
4310
4595
|
} catch (error) {
|
|
4311
|
-
throw new
|
|
4596
|
+
throw new import_node_server_utils25.InternalServerError("Failed to create index on hygiene stock.");
|
|
4312
4597
|
}
|
|
4313
4598
|
}
|
|
4314
4599
|
async function createStock(value, session) {
|
|
@@ -4316,17 +4601,17 @@ function useStockRepository() {
|
|
|
4316
4601
|
value = MStock(value);
|
|
4317
4602
|
const res = await collection.insertOne(value, { session });
|
|
4318
4603
|
delNamespace().then(() => {
|
|
4319
|
-
|
|
4604
|
+
import_node_server_utils25.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4320
4605
|
}).catch((err) => {
|
|
4321
|
-
|
|
4606
|
+
import_node_server_utils25.logger.error(
|
|
4322
4607
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4323
4608
|
err
|
|
4324
4609
|
);
|
|
4325
4610
|
});
|
|
4326
4611
|
delSupplyNamespace().then(() => {
|
|
4327
|
-
|
|
4612
|
+
import_node_server_utils25.logger.info(`Cache cleared for namespace: ${supply_collection}`);
|
|
4328
4613
|
}).catch((err) => {
|
|
4329
|
-
|
|
4614
|
+
import_node_server_utils25.logger.error(
|
|
4330
4615
|
`Failed to clear cache for namespace: ${supply_collection}`,
|
|
4331
4616
|
err
|
|
4332
4617
|
);
|
|
@@ -4352,27 +4637,27 @@ function useStockRepository() {
|
|
|
4352
4637
|
limit
|
|
4353
4638
|
};
|
|
4354
4639
|
try {
|
|
4355
|
-
site = new
|
|
4640
|
+
site = new import_mongodb14.ObjectId(site);
|
|
4356
4641
|
query.site = site;
|
|
4357
4642
|
cacheOptions.site = site.toString();
|
|
4358
4643
|
} catch (error) {
|
|
4359
|
-
throw new
|
|
4644
|
+
throw new import_node_server_utils25.BadRequestError("Invalid site ID format.");
|
|
4360
4645
|
}
|
|
4361
4646
|
try {
|
|
4362
|
-
supply = new
|
|
4647
|
+
supply = new import_mongodb14.ObjectId(supply);
|
|
4363
4648
|
query.supply = supply;
|
|
4364
4649
|
cacheOptions.supply = supply.toString();
|
|
4365
4650
|
} catch (error) {
|
|
4366
|
-
throw new
|
|
4651
|
+
throw new import_node_server_utils25.BadRequestError("Invalid supply ID format.");
|
|
4367
4652
|
}
|
|
4368
4653
|
if (search) {
|
|
4369
4654
|
query.$text = { $search: search };
|
|
4370
4655
|
cacheOptions.search = search;
|
|
4371
4656
|
}
|
|
4372
|
-
const cacheKey = (0,
|
|
4657
|
+
const cacheKey = (0, import_node_server_utils25.makeCacheKey)(namespace_collection, cacheOptions);
|
|
4373
4658
|
const cachedData = await getCache(cacheKey);
|
|
4374
4659
|
if (cachedData) {
|
|
4375
|
-
|
|
4660
|
+
import_node_server_utils25.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
4376
4661
|
return cachedData;
|
|
4377
4662
|
}
|
|
4378
4663
|
try {
|
|
@@ -4391,11 +4676,11 @@ function useStockRepository() {
|
|
|
4391
4676
|
{ $limit: limit }
|
|
4392
4677
|
]).toArray();
|
|
4393
4678
|
const length = await collection.countDocuments(query);
|
|
4394
|
-
const data = (0,
|
|
4679
|
+
const data = (0, import_node_server_utils25.paginate)(items, page, limit, length);
|
|
4395
4680
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4396
|
-
|
|
4681
|
+
import_node_server_utils25.logger.info(`Cache set for key: ${cacheKey}`);
|
|
4397
4682
|
}).catch((err) => {
|
|
4398
|
-
|
|
4683
|
+
import_node_server_utils25.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4399
4684
|
});
|
|
4400
4685
|
return data;
|
|
4401
4686
|
} catch (error) {
|
|
@@ -4410,14 +4695,14 @@ function useStockRepository() {
|
|
|
4410
4695
|
}
|
|
4411
4696
|
|
|
4412
4697
|
// src/services/hygiene-stock.service.ts
|
|
4413
|
-
var
|
|
4698
|
+
var import_node_server_utils26 = require("@7365admin1/node-server-utils");
|
|
4414
4699
|
function useStockService() {
|
|
4415
4700
|
const { createStock: _createStock } = useStockRepository();
|
|
4416
4701
|
const { getSupplyById, updateSupply } = useSupplyRepository();
|
|
4417
4702
|
async function createStock(value, out = false, session) {
|
|
4418
4703
|
let ownSession = false;
|
|
4419
4704
|
if (!session) {
|
|
4420
|
-
session =
|
|
4705
|
+
session = import_node_server_utils26.useAtlas.getClient()?.startSession();
|
|
4421
4706
|
ownSession = true;
|
|
4422
4707
|
}
|
|
4423
4708
|
try {
|
|
@@ -4426,11 +4711,11 @@ function useStockService() {
|
|
|
4426
4711
|
const { qty, ...stockData } = value;
|
|
4427
4712
|
const supply = await getSupplyById(value.supply, session);
|
|
4428
4713
|
if (!supply || supply.qty === void 0) {
|
|
4429
|
-
throw new
|
|
4714
|
+
throw new import_node_server_utils26.NotFoundError("Supply not found.");
|
|
4430
4715
|
}
|
|
4431
4716
|
const newSupplyQty = out ? supply.qty - qty : supply.qty + qty;
|
|
4432
4717
|
if (out && newSupplyQty < 0) {
|
|
4433
|
-
throw new
|
|
4718
|
+
throw new import_node_server_utils26.BadRequestError(
|
|
4434
4719
|
`Insufficient stock. Available: ${supply.qty}, Requested: ${qty}`
|
|
4435
4720
|
);
|
|
4436
4721
|
}
|
|
@@ -4461,7 +4746,7 @@ function useStockService() {
|
|
|
4461
4746
|
|
|
4462
4747
|
// src/controllers/hygiene-stock.controller.ts
|
|
4463
4748
|
var import_joi13 = __toESM(require("joi"));
|
|
4464
|
-
var
|
|
4749
|
+
var import_node_server_utils27 = require("@7365admin1/node-server-utils");
|
|
4465
4750
|
function useStockController() {
|
|
4466
4751
|
const { getStocksBySupplyId: _getStocksBySupplyId } = useStockRepository();
|
|
4467
4752
|
const { createStock: _createStock } = useStockService();
|
|
@@ -4475,8 +4760,8 @@ function useStockController() {
|
|
|
4475
4760
|
});
|
|
4476
4761
|
const { error } = validation.validate(payload);
|
|
4477
4762
|
if (error) {
|
|
4478
|
-
|
|
4479
|
-
next(new
|
|
4763
|
+
import_node_server_utils27.logger.log({ level: "error", message: error.message });
|
|
4764
|
+
next(new import_node_server_utils27.BadRequestError(error.message));
|
|
4480
4765
|
return;
|
|
4481
4766
|
}
|
|
4482
4767
|
try {
|
|
@@ -4484,7 +4769,7 @@ function useStockController() {
|
|
|
4484
4769
|
res.status(201).json({ message: "Stock created successfully.", id });
|
|
4485
4770
|
return;
|
|
4486
4771
|
} catch (error2) {
|
|
4487
|
-
|
|
4772
|
+
import_node_server_utils27.logger.log({ level: "error", message: error2.message });
|
|
4488
4773
|
next(error2);
|
|
4489
4774
|
return;
|
|
4490
4775
|
}
|
|
@@ -4500,8 +4785,8 @@ function useStockController() {
|
|
|
4500
4785
|
});
|
|
4501
4786
|
const { error } = validation.validate(query);
|
|
4502
4787
|
if (error) {
|
|
4503
|
-
|
|
4504
|
-
next(new
|
|
4788
|
+
import_node_server_utils27.logger.log({ level: "error", message: error.message });
|
|
4789
|
+
next(new import_node_server_utils27.BadRequestError(error.message));
|
|
4505
4790
|
return;
|
|
4506
4791
|
}
|
|
4507
4792
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -4520,7 +4805,7 @@ function useStockController() {
|
|
|
4520
4805
|
res.json(data);
|
|
4521
4806
|
return;
|
|
4522
4807
|
} catch (error2) {
|
|
4523
|
-
|
|
4808
|
+
import_node_server_utils27.logger.log({ level: "error", message: error2.message });
|
|
4524
4809
|
next(error2);
|
|
4525
4810
|
return;
|
|
4526
4811
|
}
|
|
@@ -4533,8 +4818,8 @@ function useStockController() {
|
|
|
4533
4818
|
|
|
4534
4819
|
// src/models/hygiene-checkout-item.model.ts
|
|
4535
4820
|
var import_joi14 = __toESM(require("joi"));
|
|
4536
|
-
var
|
|
4537
|
-
var
|
|
4821
|
+
var import_mongodb15 = require("mongodb");
|
|
4822
|
+
var import_node_server_utils28 = require("@7365admin1/node-server-utils");
|
|
4538
4823
|
var allowedCheckOutItemStatus = ["pending", "completed"];
|
|
4539
4824
|
var checkOutItemSchema = import_joi14.default.object({
|
|
4540
4825
|
site: import_joi14.default.string().hex().required(),
|
|
@@ -4548,21 +4833,21 @@ var checkOutItemSchema = import_joi14.default.object({
|
|
|
4548
4833
|
function MCheckOutItem(value) {
|
|
4549
4834
|
const { error } = checkOutItemSchema.validate(value);
|
|
4550
4835
|
if (error) {
|
|
4551
|
-
|
|
4552
|
-
throw new
|
|
4836
|
+
import_node_server_utils28.logger.info(`Hygiene Check Out Item Model: ${error.message}`);
|
|
4837
|
+
throw new import_node_server_utils28.BadRequestError(error.message);
|
|
4553
4838
|
}
|
|
4554
4839
|
if (value.site) {
|
|
4555
4840
|
try {
|
|
4556
|
-
value.site = new
|
|
4841
|
+
value.site = new import_mongodb15.ObjectId(value.site);
|
|
4557
4842
|
} catch (error2) {
|
|
4558
|
-
throw new
|
|
4843
|
+
throw new import_node_server_utils28.BadRequestError("Invalid site ID format.");
|
|
4559
4844
|
}
|
|
4560
4845
|
}
|
|
4561
4846
|
if (value.supply) {
|
|
4562
4847
|
try {
|
|
4563
|
-
value.supply = new
|
|
4848
|
+
value.supply = new import_mongodb15.ObjectId(value.supply);
|
|
4564
4849
|
} catch (error2) {
|
|
4565
|
-
throw new
|
|
4850
|
+
throw new import_node_server_utils28.BadRequestError("Invalid supply ID format.");
|
|
4566
4851
|
}
|
|
4567
4852
|
}
|
|
4568
4853
|
return {
|
|
@@ -4581,16 +4866,16 @@ function MCheckOutItem(value) {
|
|
|
4581
4866
|
}
|
|
4582
4867
|
|
|
4583
4868
|
// src/repositories/hygiene-checkout-item.repository.ts
|
|
4584
|
-
var
|
|
4585
|
-
var
|
|
4869
|
+
var import_mongodb16 = require("mongodb");
|
|
4870
|
+
var import_node_server_utils29 = require("@7365admin1/node-server-utils");
|
|
4586
4871
|
function useCheckOutItemRepository() {
|
|
4587
|
-
const db =
|
|
4872
|
+
const db = import_node_server_utils29.useAtlas.getDb();
|
|
4588
4873
|
if (!db) {
|
|
4589
|
-
throw new
|
|
4874
|
+
throw new import_node_server_utils29.InternalServerError("Unable to connect to server.");
|
|
4590
4875
|
}
|
|
4591
4876
|
const namespace_collection = "site.supply.checkouts";
|
|
4592
4877
|
const collection = db.collection(namespace_collection);
|
|
4593
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
4878
|
+
const { delNamespace, setCache, getCache } = (0, import_node_server_utils29.useCache)(namespace_collection);
|
|
4594
4879
|
async function createIndex() {
|
|
4595
4880
|
try {
|
|
4596
4881
|
await collection.createIndexes([
|
|
@@ -4599,7 +4884,7 @@ function useCheckOutItemRepository() {
|
|
|
4599
4884
|
{ key: { status: 1 } }
|
|
4600
4885
|
]);
|
|
4601
4886
|
} catch (error) {
|
|
4602
|
-
throw new
|
|
4887
|
+
throw new import_node_server_utils29.InternalServerError(
|
|
4603
4888
|
"Failed to create index on hygiene check out item."
|
|
4604
4889
|
);
|
|
4605
4890
|
}
|
|
@@ -4608,7 +4893,7 @@ function useCheckOutItemRepository() {
|
|
|
4608
4893
|
try {
|
|
4609
4894
|
await collection.createIndex({ supplyName: "text" });
|
|
4610
4895
|
} catch (error) {
|
|
4611
|
-
throw new
|
|
4896
|
+
throw new import_node_server_utils29.InternalServerError(
|
|
4612
4897
|
"Failed to create text index on hygiene supply."
|
|
4613
4898
|
);
|
|
4614
4899
|
}
|
|
@@ -4618,9 +4903,9 @@ function useCheckOutItemRepository() {
|
|
|
4618
4903
|
value = MCheckOutItem(value);
|
|
4619
4904
|
const res = await collection.insertOne(value, { session });
|
|
4620
4905
|
delNamespace().then(() => {
|
|
4621
|
-
|
|
4906
|
+
import_node_server_utils29.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4622
4907
|
}).catch((err) => {
|
|
4623
|
-
|
|
4908
|
+
import_node_server_utils29.logger.error(
|
|
4624
4909
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4625
4910
|
err
|
|
4626
4911
|
);
|
|
@@ -4645,20 +4930,20 @@ function useCheckOutItemRepository() {
|
|
|
4645
4930
|
limit
|
|
4646
4931
|
};
|
|
4647
4932
|
try {
|
|
4648
|
-
site = new
|
|
4933
|
+
site = new import_mongodb16.ObjectId(site);
|
|
4649
4934
|
query.site = site;
|
|
4650
4935
|
cacheOptions.site = site.toString();
|
|
4651
4936
|
} catch (error) {
|
|
4652
|
-
throw new
|
|
4937
|
+
throw new import_node_server_utils29.BadRequestError("Invalid site ID format.");
|
|
4653
4938
|
}
|
|
4654
4939
|
if (search) {
|
|
4655
4940
|
query.$text = { $search: search };
|
|
4656
4941
|
cacheOptions.search = search;
|
|
4657
4942
|
}
|
|
4658
|
-
const cacheKey = (0,
|
|
4943
|
+
const cacheKey = (0, import_node_server_utils29.makeCacheKey)(namespace_collection, cacheOptions);
|
|
4659
4944
|
const cachedData = await getCache(cacheKey);
|
|
4660
4945
|
if (cachedData) {
|
|
4661
|
-
|
|
4946
|
+
import_node_server_utils29.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
4662
4947
|
return cachedData;
|
|
4663
4948
|
}
|
|
4664
4949
|
try {
|
|
@@ -4705,11 +4990,11 @@ function useCheckOutItemRepository() {
|
|
|
4705
4990
|
{ $limit: limit }
|
|
4706
4991
|
]).toArray();
|
|
4707
4992
|
const length = await collection.countDocuments(query);
|
|
4708
|
-
const data = (0,
|
|
4993
|
+
const data = (0, import_node_server_utils29.paginate)(items, page, limit, length);
|
|
4709
4994
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4710
|
-
|
|
4995
|
+
import_node_server_utils29.logger.info(`Cache set for key: ${cacheKey}`);
|
|
4711
4996
|
}).catch((err) => {
|
|
4712
|
-
|
|
4997
|
+
import_node_server_utils29.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4713
4998
|
});
|
|
4714
4999
|
return data;
|
|
4715
5000
|
} catch (error) {
|
|
@@ -4718,22 +5003,22 @@ function useCheckOutItemRepository() {
|
|
|
4718
5003
|
}
|
|
4719
5004
|
async function getCheckOutItemById(_id, session) {
|
|
4720
5005
|
try {
|
|
4721
|
-
_id = new
|
|
5006
|
+
_id = new import_mongodb16.ObjectId(_id);
|
|
4722
5007
|
} catch (error) {
|
|
4723
|
-
throw new
|
|
5008
|
+
throw new import_node_server_utils29.BadRequestError("Invalid check out item ID format.");
|
|
4724
5009
|
}
|
|
4725
5010
|
const query = { _id };
|
|
4726
|
-
const cacheKey = (0,
|
|
5011
|
+
const cacheKey = (0, import_node_server_utils29.makeCacheKey)(namespace_collection, {
|
|
4727
5012
|
_id: _id.toString()
|
|
4728
5013
|
});
|
|
4729
5014
|
if (!session) {
|
|
4730
5015
|
const cachedData = await getCache(cacheKey);
|
|
4731
5016
|
if (cachedData) {
|
|
4732
|
-
|
|
5017
|
+
import_node_server_utils29.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
4733
5018
|
return cachedData;
|
|
4734
5019
|
}
|
|
4735
5020
|
} else {
|
|
4736
|
-
|
|
5021
|
+
import_node_server_utils29.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
4737
5022
|
}
|
|
4738
5023
|
try {
|
|
4739
5024
|
const data = await collection.aggregate(
|
|
@@ -4768,12 +5053,12 @@ function useCheckOutItemRepository() {
|
|
|
4768
5053
|
session ? { session } : void 0
|
|
4769
5054
|
).toArray();
|
|
4770
5055
|
if (!data || data.length === 0) {
|
|
4771
|
-
throw new
|
|
5056
|
+
throw new import_node_server_utils29.NotFoundError("Check out item not found.");
|
|
4772
5057
|
}
|
|
4773
5058
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
4774
|
-
|
|
5059
|
+
import_node_server_utils29.logger.info(`Cache set for key: ${cacheKey}`);
|
|
4775
5060
|
}).catch((err) => {
|
|
4776
|
-
|
|
5061
|
+
import_node_server_utils29.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4777
5062
|
});
|
|
4778
5063
|
return data[0];
|
|
4779
5064
|
} catch (error) {
|
|
@@ -4782,9 +5067,9 @@ function useCheckOutItemRepository() {
|
|
|
4782
5067
|
}
|
|
4783
5068
|
async function completeCheckOutItem(_id, session) {
|
|
4784
5069
|
try {
|
|
4785
|
-
_id = new
|
|
5070
|
+
_id = new import_mongodb16.ObjectId(_id);
|
|
4786
5071
|
} catch (error) {
|
|
4787
|
-
throw new
|
|
5072
|
+
throw new import_node_server_utils29.BadRequestError("Invalid check out item ID format.");
|
|
4788
5073
|
}
|
|
4789
5074
|
try {
|
|
4790
5075
|
const updateValue = {
|
|
@@ -4797,12 +5082,12 @@ function useCheckOutItemRepository() {
|
|
|
4797
5082
|
{ session }
|
|
4798
5083
|
);
|
|
4799
5084
|
if (res.modifiedCount === 0) {
|
|
4800
|
-
throw new
|
|
5085
|
+
throw new import_node_server_utils29.InternalServerError("Unable to complete check out item.");
|
|
4801
5086
|
}
|
|
4802
5087
|
delNamespace().then(() => {
|
|
4803
|
-
|
|
5088
|
+
import_node_server_utils29.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4804
5089
|
}).catch((err) => {
|
|
4805
|
-
|
|
5090
|
+
import_node_server_utils29.logger.error(
|
|
4806
5091
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4807
5092
|
err
|
|
4808
5093
|
);
|
|
@@ -4824,7 +5109,7 @@ function useCheckOutItemRepository() {
|
|
|
4824
5109
|
|
|
4825
5110
|
// src/services/hygiene-checkout-item.service.ts
|
|
4826
5111
|
var import_core = require("@7365admin1/core");
|
|
4827
|
-
var
|
|
5112
|
+
var import_node_server_utils30 = require("@7365admin1/node-server-utils");
|
|
4828
5113
|
function useCheckOutItemService() {
|
|
4829
5114
|
const {
|
|
4830
5115
|
createCheckOutItem: _createCheckOutItem,
|
|
@@ -4835,7 +5120,7 @@ function useCheckOutItemService() {
|
|
|
4835
5120
|
const { getUserById } = (0, import_core.useUserRepo)();
|
|
4836
5121
|
const { createStock } = useStockService();
|
|
4837
5122
|
async function createCheckOutItem(value) {
|
|
4838
|
-
const session =
|
|
5123
|
+
const session = import_node_server_utils30.useAtlas.getClient()?.startSession();
|
|
4839
5124
|
try {
|
|
4840
5125
|
session?.startTransaction();
|
|
4841
5126
|
const supplyData = await getSupplyById(value.supply);
|
|
@@ -4853,7 +5138,7 @@ function useCheckOutItemService() {
|
|
|
4853
5138
|
session
|
|
4854
5139
|
);
|
|
4855
5140
|
if (!checkOutItem) {
|
|
4856
|
-
throw new
|
|
5141
|
+
throw new import_node_server_utils30.BadRequestError("Failed to create check out item.");
|
|
4857
5142
|
}
|
|
4858
5143
|
const createdStocks = await createStock(
|
|
4859
5144
|
{
|
|
@@ -4875,7 +5160,7 @@ function useCheckOutItemService() {
|
|
|
4875
5160
|
}
|
|
4876
5161
|
}
|
|
4877
5162
|
async function createCheckOutItemByBatch(value) {
|
|
4878
|
-
const session =
|
|
5163
|
+
const session = import_node_server_utils30.useAtlas.getClient()?.startSession();
|
|
4879
5164
|
try {
|
|
4880
5165
|
session?.startTransaction();
|
|
4881
5166
|
const { site, attachment, createdBy, items } = value;
|
|
@@ -4923,7 +5208,7 @@ function useCheckOutItemService() {
|
|
|
4923
5208
|
|
|
4924
5209
|
// src/controllers/hygiene-checkout-item.controller.ts
|
|
4925
5210
|
var import_joi15 = __toESM(require("joi"));
|
|
4926
|
-
var
|
|
5211
|
+
var import_node_server_utils31 = require("@7365admin1/node-server-utils");
|
|
4927
5212
|
function useCheckOutItemController() {
|
|
4928
5213
|
const {
|
|
4929
5214
|
getCheckOutItems: _getCheckOutItems,
|
|
@@ -4953,8 +5238,8 @@ function useCheckOutItemController() {
|
|
|
4953
5238
|
});
|
|
4954
5239
|
const { error } = validation.validate(payload);
|
|
4955
5240
|
if (error) {
|
|
4956
|
-
|
|
4957
|
-
next(new
|
|
5241
|
+
import_node_server_utils31.logger.log({ level: "error", message: error.message });
|
|
5242
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
4958
5243
|
return;
|
|
4959
5244
|
}
|
|
4960
5245
|
try {
|
|
@@ -4962,7 +5247,7 @@ function useCheckOutItemController() {
|
|
|
4962
5247
|
res.status(201).json({ message: "Check out item created successfully.", id });
|
|
4963
5248
|
return;
|
|
4964
5249
|
} catch (error2) {
|
|
4965
|
-
|
|
5250
|
+
import_node_server_utils31.logger.log({ level: "error", message: error2.message });
|
|
4966
5251
|
next(error2);
|
|
4967
5252
|
return;
|
|
4968
5253
|
}
|
|
@@ -4991,8 +5276,8 @@ function useCheckOutItemController() {
|
|
|
4991
5276
|
});
|
|
4992
5277
|
const { error } = validation.validate(payload);
|
|
4993
5278
|
if (error) {
|
|
4994
|
-
|
|
4995
|
-
next(new
|
|
5279
|
+
import_node_server_utils31.logger.log({ level: "error", message: error.message });
|
|
5280
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
4996
5281
|
return;
|
|
4997
5282
|
}
|
|
4998
5283
|
try {
|
|
@@ -5000,7 +5285,7 @@ function useCheckOutItemController() {
|
|
|
5000
5285
|
res.status(201).json({ message: "Check out items created successfully." });
|
|
5001
5286
|
return;
|
|
5002
5287
|
} catch (error2) {
|
|
5003
|
-
|
|
5288
|
+
import_node_server_utils31.logger.log({ level: "error", message: error2.message });
|
|
5004
5289
|
next(error2);
|
|
5005
5290
|
return;
|
|
5006
5291
|
}
|
|
@@ -5015,8 +5300,8 @@ function useCheckOutItemController() {
|
|
|
5015
5300
|
});
|
|
5016
5301
|
const { error } = validation.validate(query);
|
|
5017
5302
|
if (error) {
|
|
5018
|
-
|
|
5019
|
-
next(new
|
|
5303
|
+
import_node_server_utils31.logger.log({ level: "error", message: error.message });
|
|
5304
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
5020
5305
|
return;
|
|
5021
5306
|
}
|
|
5022
5307
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -5033,7 +5318,7 @@ function useCheckOutItemController() {
|
|
|
5033
5318
|
res.json(data);
|
|
5034
5319
|
return;
|
|
5035
5320
|
} catch (error2) {
|
|
5036
|
-
|
|
5321
|
+
import_node_server_utils31.logger.log({ level: "error", message: error2.message });
|
|
5037
5322
|
next(error2);
|
|
5038
5323
|
return;
|
|
5039
5324
|
}
|
|
@@ -5043,8 +5328,8 @@ function useCheckOutItemController() {
|
|
|
5043
5328
|
const _id = req.params.id;
|
|
5044
5329
|
const { error, value } = validation.validate(_id);
|
|
5045
5330
|
if (error) {
|
|
5046
|
-
|
|
5047
|
-
next(new
|
|
5331
|
+
import_node_server_utils31.logger.log({ level: "error", message: error.message });
|
|
5332
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
5048
5333
|
return;
|
|
5049
5334
|
}
|
|
5050
5335
|
try {
|
|
@@ -5052,7 +5337,7 @@ function useCheckOutItemController() {
|
|
|
5052
5337
|
res.json(data);
|
|
5053
5338
|
return;
|
|
5054
5339
|
} catch (error2) {
|
|
5055
|
-
|
|
5340
|
+
import_node_server_utils31.logger.log({ level: "error", message: error2.message });
|
|
5056
5341
|
next(error2);
|
|
5057
5342
|
return;
|
|
5058
5343
|
}
|
|
@@ -5066,9 +5351,9 @@ function useCheckOutItemController() {
|
|
|
5066
5351
|
}
|
|
5067
5352
|
|
|
5068
5353
|
// src/models/hygiene-schedule-task.model.ts
|
|
5069
|
-
var
|
|
5354
|
+
var import_node_server_utils32 = require("@7365admin1/node-server-utils");
|
|
5070
5355
|
var import_joi16 = __toESM(require("joi"));
|
|
5071
|
-
var
|
|
5356
|
+
var import_mongodb17 = require("mongodb");
|
|
5072
5357
|
var scheduleTaskSchema = import_joi16.default.object({
|
|
5073
5358
|
site: import_joi16.default.string().hex().required(),
|
|
5074
5359
|
title: import_joi16.default.string().required(),
|
|
@@ -5087,14 +5372,14 @@ var scheduleTaskSchema = import_joi16.default.object({
|
|
|
5087
5372
|
function MScheduleTask(value) {
|
|
5088
5373
|
const { error } = scheduleTaskSchema.validate(value);
|
|
5089
5374
|
if (error) {
|
|
5090
|
-
|
|
5091
|
-
throw new
|
|
5375
|
+
import_node_server_utils32.logger.info(`Hygiene Schedule Task Model: ${error.message}`);
|
|
5376
|
+
throw new import_node_server_utils32.BadRequestError(error.message);
|
|
5092
5377
|
}
|
|
5093
5378
|
if (value.site) {
|
|
5094
5379
|
try {
|
|
5095
|
-
value.site = new
|
|
5380
|
+
value.site = new import_mongodb17.ObjectId(value.site);
|
|
5096
5381
|
} catch (error2) {
|
|
5097
|
-
throw new
|
|
5382
|
+
throw new import_node_server_utils32.BadRequestError("Invalid site ID format.");
|
|
5098
5383
|
}
|
|
5099
5384
|
}
|
|
5100
5385
|
if (value.areas && Array.isArray(value.areas)) {
|
|
@@ -5102,18 +5387,18 @@ function MScheduleTask(value) {
|
|
|
5102
5387
|
try {
|
|
5103
5388
|
return {
|
|
5104
5389
|
name: area.name,
|
|
5105
|
-
value: new
|
|
5390
|
+
value: new import_mongodb17.ObjectId(area.value.toString())
|
|
5106
5391
|
};
|
|
5107
5392
|
} catch (error2) {
|
|
5108
|
-
throw new
|
|
5393
|
+
throw new import_node_server_utils32.BadRequestError(`Invalid area value format: ${area.name}`);
|
|
5109
5394
|
}
|
|
5110
5395
|
});
|
|
5111
5396
|
}
|
|
5112
5397
|
if (value.createdBy) {
|
|
5113
5398
|
try {
|
|
5114
|
-
value.createdBy = new
|
|
5399
|
+
value.createdBy = new import_mongodb17.ObjectId(value.createdBy);
|
|
5115
5400
|
} catch (error2) {
|
|
5116
|
-
throw new
|
|
5401
|
+
throw new import_node_server_utils32.BadRequestError("Invalid createdBy ID format.");
|
|
5117
5402
|
}
|
|
5118
5403
|
}
|
|
5119
5404
|
return {
|
|
@@ -5133,16 +5418,16 @@ function MScheduleTask(value) {
|
|
|
5133
5418
|
}
|
|
5134
5419
|
|
|
5135
5420
|
// src/repositories/hygiene-schedule-task.repository.ts
|
|
5136
|
-
var
|
|
5137
|
-
var
|
|
5421
|
+
var import_mongodb18 = require("mongodb");
|
|
5422
|
+
var import_node_server_utils33 = require("@7365admin1/node-server-utils");
|
|
5138
5423
|
function useScheduleTaskRepository() {
|
|
5139
|
-
const db =
|
|
5424
|
+
const db = import_node_server_utils33.useAtlas.getDb();
|
|
5140
5425
|
if (!db) {
|
|
5141
|
-
throw new
|
|
5426
|
+
throw new import_node_server_utils33.InternalServerError("Unable to connect to server.");
|
|
5142
5427
|
}
|
|
5143
5428
|
const namespace_collection = "site.schedule-tasks";
|
|
5144
5429
|
const collection = db.collection(namespace_collection);
|
|
5145
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
5430
|
+
const { delNamespace, setCache, getCache } = (0, import_node_server_utils33.useCache)(namespace_collection);
|
|
5146
5431
|
async function createIndex() {
|
|
5147
5432
|
try {
|
|
5148
5433
|
await collection.createIndexes([
|
|
@@ -5150,7 +5435,7 @@ function useScheduleTaskRepository() {
|
|
|
5150
5435
|
{ key: { status: 1 } }
|
|
5151
5436
|
]);
|
|
5152
5437
|
} catch (error) {
|
|
5153
|
-
throw new
|
|
5438
|
+
throw new import_node_server_utils33.InternalServerError(
|
|
5154
5439
|
"Failed to create index on hygiene schedule task."
|
|
5155
5440
|
);
|
|
5156
5441
|
}
|
|
@@ -5159,7 +5444,7 @@ function useScheduleTaskRepository() {
|
|
|
5159
5444
|
try {
|
|
5160
5445
|
await collection.createIndex({ title: "text", description: "text" });
|
|
5161
5446
|
} catch (error) {
|
|
5162
|
-
throw new
|
|
5447
|
+
throw new import_node_server_utils33.InternalServerError(
|
|
5163
5448
|
"Failed to create text index on hygiene schedule task."
|
|
5164
5449
|
);
|
|
5165
5450
|
}
|
|
@@ -5169,9 +5454,9 @@ function useScheduleTaskRepository() {
|
|
|
5169
5454
|
value = MScheduleTask(value);
|
|
5170
5455
|
const res = await collection.insertOne(value, { session });
|
|
5171
5456
|
delNamespace().then(() => {
|
|
5172
|
-
|
|
5457
|
+
import_node_server_utils33.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5173
5458
|
}).catch((err) => {
|
|
5174
|
-
|
|
5459
|
+
import_node_server_utils33.logger.error(
|
|
5175
5460
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5176
5461
|
err
|
|
5177
5462
|
);
|
|
@@ -5196,20 +5481,20 @@ function useScheduleTaskRepository() {
|
|
|
5196
5481
|
limit
|
|
5197
5482
|
};
|
|
5198
5483
|
try {
|
|
5199
|
-
site = new
|
|
5484
|
+
site = new import_mongodb18.ObjectId(site);
|
|
5200
5485
|
query.site = site;
|
|
5201
5486
|
cacheOptions.site = site.toString();
|
|
5202
5487
|
} catch (error) {
|
|
5203
|
-
throw new
|
|
5488
|
+
throw new import_node_server_utils33.BadRequestError("Invalid site ID format.");
|
|
5204
5489
|
}
|
|
5205
5490
|
if (search) {
|
|
5206
5491
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
5207
5492
|
cacheOptions.search = search;
|
|
5208
5493
|
}
|
|
5209
|
-
const cacheKey = (0,
|
|
5494
|
+
const cacheKey = (0, import_node_server_utils33.makeCacheKey)(namespace_collection, cacheOptions);
|
|
5210
5495
|
const cachedData = await getCache(cacheKey);
|
|
5211
5496
|
if (cachedData) {
|
|
5212
|
-
|
|
5497
|
+
import_node_server_utils33.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5213
5498
|
return cachedData;
|
|
5214
5499
|
}
|
|
5215
5500
|
try {
|
|
@@ -5227,11 +5512,11 @@ function useScheduleTaskRepository() {
|
|
|
5227
5512
|
{ $limit: limit }
|
|
5228
5513
|
]).toArray();
|
|
5229
5514
|
const length = await collection.countDocuments(query);
|
|
5230
|
-
const data = (0,
|
|
5515
|
+
const data = (0, import_node_server_utils33.paginate)(items, page, limit, length);
|
|
5231
5516
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5232
|
-
|
|
5517
|
+
import_node_server_utils33.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5233
5518
|
}).catch((err) => {
|
|
5234
|
-
|
|
5519
|
+
import_node_server_utils33.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5235
5520
|
});
|
|
5236
5521
|
return data;
|
|
5237
5522
|
} catch (error) {
|
|
@@ -5264,20 +5549,20 @@ function useScheduleTaskRepository() {
|
|
|
5264
5549
|
limit
|
|
5265
5550
|
};
|
|
5266
5551
|
try {
|
|
5267
|
-
site = new
|
|
5552
|
+
site = new import_mongodb18.ObjectId(site);
|
|
5268
5553
|
query.site = site;
|
|
5269
5554
|
cacheOptions.site = site.toString();
|
|
5270
5555
|
} catch (error) {
|
|
5271
|
-
throw new
|
|
5556
|
+
throw new import_node_server_utils33.BadRequestError("Invalid site ID format.");
|
|
5272
5557
|
}
|
|
5273
5558
|
if (search) {
|
|
5274
5559
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
5275
5560
|
cacheOptions.search = search;
|
|
5276
5561
|
}
|
|
5277
|
-
const cacheKey = (0,
|
|
5562
|
+
const cacheKey = (0, import_node_server_utils33.makeCacheKey)(namespace_collection, cacheOptions);
|
|
5278
5563
|
const cachedData = await getCache(cacheKey);
|
|
5279
5564
|
if (cachedData) {
|
|
5280
|
-
|
|
5565
|
+
import_node_server_utils33.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5281
5566
|
return cachedData;
|
|
5282
5567
|
}
|
|
5283
5568
|
try {
|
|
@@ -5294,11 +5579,11 @@ function useScheduleTaskRepository() {
|
|
|
5294
5579
|
{ $limit: limit }
|
|
5295
5580
|
]).toArray();
|
|
5296
5581
|
const length = await collection.countDocuments(query);
|
|
5297
|
-
const data = (0,
|
|
5582
|
+
const data = (0, import_node_server_utils33.paginate)(items, page, limit, length);
|
|
5298
5583
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5299
|
-
|
|
5584
|
+
import_node_server_utils33.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5300
5585
|
}).catch((err) => {
|
|
5301
|
-
|
|
5586
|
+
import_node_server_utils33.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5302
5587
|
});
|
|
5303
5588
|
return data;
|
|
5304
5589
|
} catch (error) {
|
|
@@ -5307,25 +5592,25 @@ function useScheduleTaskRepository() {
|
|
|
5307
5592
|
}
|
|
5308
5593
|
async function getScheduleTaskById(_id, session) {
|
|
5309
5594
|
try {
|
|
5310
|
-
_id = new
|
|
5595
|
+
_id = new import_mongodb18.ObjectId(_id);
|
|
5311
5596
|
} catch (error) {
|
|
5312
|
-
throw new
|
|
5597
|
+
throw new import_node_server_utils33.BadRequestError("Invalid schedule task ID format.");
|
|
5313
5598
|
}
|
|
5314
5599
|
const query = {
|
|
5315
5600
|
_id,
|
|
5316
5601
|
status: { $ne: "deleted" }
|
|
5317
5602
|
};
|
|
5318
|
-
const cacheKey = (0,
|
|
5603
|
+
const cacheKey = (0, import_node_server_utils33.makeCacheKey)(namespace_collection, {
|
|
5319
5604
|
_id: _id.toString()
|
|
5320
5605
|
});
|
|
5321
5606
|
if (!session) {
|
|
5322
5607
|
const cachedData = await getCache(cacheKey);
|
|
5323
5608
|
if (cachedData) {
|
|
5324
|
-
|
|
5609
|
+
import_node_server_utils33.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5325
5610
|
return cachedData;
|
|
5326
5611
|
}
|
|
5327
5612
|
} else {
|
|
5328
|
-
|
|
5613
|
+
import_node_server_utils33.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
5329
5614
|
}
|
|
5330
5615
|
try {
|
|
5331
5616
|
const data = await collection.aggregate([
|
|
@@ -5344,12 +5629,12 @@ function useScheduleTaskRepository() {
|
|
|
5344
5629
|
}
|
|
5345
5630
|
]).toArray();
|
|
5346
5631
|
if (!data || data.length === 0) {
|
|
5347
|
-
throw new
|
|
5632
|
+
throw new import_node_server_utils33.NotFoundError("Schedule task not found.");
|
|
5348
5633
|
}
|
|
5349
5634
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
5350
|
-
|
|
5635
|
+
import_node_server_utils33.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5351
5636
|
}).catch((err) => {
|
|
5352
|
-
|
|
5637
|
+
import_node_server_utils33.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5353
5638
|
});
|
|
5354
5639
|
return data[0];
|
|
5355
5640
|
} catch (error) {
|
|
@@ -5358,19 +5643,19 @@ function useScheduleTaskRepository() {
|
|
|
5358
5643
|
}
|
|
5359
5644
|
async function updateScheduleTask(_id, value, session) {
|
|
5360
5645
|
try {
|
|
5361
|
-
_id = new
|
|
5646
|
+
_id = new import_mongodb18.ObjectId(_id);
|
|
5362
5647
|
} catch (error) {
|
|
5363
|
-
throw new
|
|
5648
|
+
throw new import_node_server_utils33.BadRequestError("Invalid schedule task ID format.");
|
|
5364
5649
|
}
|
|
5365
5650
|
if (value.areas && Array.isArray(value.areas)) {
|
|
5366
5651
|
value.areas = value.areas.map((area) => {
|
|
5367
5652
|
try {
|
|
5368
5653
|
return {
|
|
5369
5654
|
name: area.name,
|
|
5370
|
-
value: new
|
|
5655
|
+
value: new import_mongodb18.ObjectId(area.value.toString())
|
|
5371
5656
|
};
|
|
5372
5657
|
} catch (error) {
|
|
5373
|
-
throw new
|
|
5658
|
+
throw new import_node_server_utils33.BadRequestError(`Invalid area value format: ${area.name}`);
|
|
5374
5659
|
}
|
|
5375
5660
|
});
|
|
5376
5661
|
}
|
|
@@ -5382,14 +5667,14 @@ function useScheduleTaskRepository() {
|
|
|
5382
5667
|
{ session }
|
|
5383
5668
|
);
|
|
5384
5669
|
if (res.modifiedCount === 0) {
|
|
5385
|
-
throw new
|
|
5670
|
+
throw new import_node_server_utils33.InternalServerError(
|
|
5386
5671
|
"Unable to update hygiene schedule task."
|
|
5387
5672
|
);
|
|
5388
5673
|
}
|
|
5389
5674
|
delNamespace().then(() => {
|
|
5390
|
-
|
|
5675
|
+
import_node_server_utils33.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5391
5676
|
}).catch((err) => {
|
|
5392
|
-
|
|
5677
|
+
import_node_server_utils33.logger.error(
|
|
5393
5678
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5394
5679
|
err
|
|
5395
5680
|
);
|
|
@@ -5412,7 +5697,7 @@ function useScheduleTaskRepository() {
|
|
|
5412
5697
|
}
|
|
5413
5698
|
|
|
5414
5699
|
// src/services/hygiene-schedule-task.service.ts
|
|
5415
|
-
var
|
|
5700
|
+
var import_node_server_utils34 = require("@7365admin1/node-server-utils");
|
|
5416
5701
|
function useScheduleTaskService() {
|
|
5417
5702
|
const { createParentChecklist } = useParentChecklistRepo();
|
|
5418
5703
|
const { getAllScheduleTask } = useScheduleTaskRepository();
|
|
@@ -5435,13 +5720,13 @@ function useScheduleTaskService() {
|
|
|
5435
5720
|
const currentDateString = now.toLocaleDateString("en-US", {
|
|
5436
5721
|
timeZone: "Asia/Singapore"
|
|
5437
5722
|
});
|
|
5438
|
-
|
|
5723
|
+
import_node_server_utils34.logger.info(
|
|
5439
5724
|
`Checking schedule ${schedule._id}: Current time ${currentHour}:${currentMinute}, Current date ${currentDateString}, Schedule time ${schedule.time}, Start date ${schedule.startDate}, End date ${schedule.endDate}`
|
|
5440
5725
|
);
|
|
5441
5726
|
const startDate = /* @__PURE__ */ new Date(schedule.startDate + "T00:00:00");
|
|
5442
5727
|
const currentDateOnly = /* @__PURE__ */ new Date(currentDateString + "T00:00:00");
|
|
5443
5728
|
if (currentDateOnly < startDate) {
|
|
5444
|
-
|
|
5729
|
+
import_node_server_utils34.logger.info(
|
|
5445
5730
|
`Schedule ${schedule._id}: Current date ${currentDateString} is before start date ${schedule.startDate}`
|
|
5446
5731
|
);
|
|
5447
5732
|
return false;
|
|
@@ -5449,7 +5734,7 @@ function useScheduleTaskService() {
|
|
|
5449
5734
|
if (schedule.endDate) {
|
|
5450
5735
|
const endDate = /* @__PURE__ */ new Date(schedule.endDate + "T00:00:00");
|
|
5451
5736
|
if (currentDateOnly > endDate) {
|
|
5452
|
-
|
|
5737
|
+
import_node_server_utils34.logger.info(
|
|
5453
5738
|
`Schedule ${schedule._id}: Current date ${currentDateString} is after end date ${schedule.endDate}`
|
|
5454
5739
|
);
|
|
5455
5740
|
return false;
|
|
@@ -5458,17 +5743,17 @@ function useScheduleTaskService() {
|
|
|
5458
5743
|
const [scheduleHour, scheduleMinute] = schedule.time.split(":").map(Number);
|
|
5459
5744
|
const timeMatches = currentHour === scheduleHour && currentMinute === scheduleMinute;
|
|
5460
5745
|
if (!timeMatches) {
|
|
5461
|
-
|
|
5746
|
+
import_node_server_utils34.logger.info(
|
|
5462
5747
|
`Schedule ${schedule._id}: Time does not match. Current: ${currentHour}:${currentMinute}, Expected: ${scheduleHour}:${scheduleMinute}`
|
|
5463
5748
|
);
|
|
5464
5749
|
return false;
|
|
5465
5750
|
}
|
|
5466
|
-
|
|
5751
|
+
import_node_server_utils34.logger.info(
|
|
5467
5752
|
`Schedule ${schedule._id}: All conditions matched - Date is within range and time matches`
|
|
5468
5753
|
);
|
|
5469
5754
|
return true;
|
|
5470
5755
|
} catch (error) {
|
|
5471
|
-
|
|
5756
|
+
import_node_server_utils34.logger.error(
|
|
5472
5757
|
`Error checking schedule conditions for ${schedule._id}:`,
|
|
5473
5758
|
error
|
|
5474
5759
|
);
|
|
@@ -5477,40 +5762,40 @@ function useScheduleTaskService() {
|
|
|
5477
5762
|
}
|
|
5478
5763
|
async function processScheduledTasks(currentDate) {
|
|
5479
5764
|
try {
|
|
5480
|
-
|
|
5765
|
+
import_node_server_utils34.logger.info("Starting scheduled task processing...");
|
|
5481
5766
|
const scheduleTasks = await getAllScheduleTask();
|
|
5482
5767
|
if (!scheduleTasks || scheduleTasks.length === 0) {
|
|
5483
|
-
|
|
5768
|
+
import_node_server_utils34.logger.info("No schedule tasks found to process");
|
|
5484
5769
|
return { processed: 0, validated: 0 };
|
|
5485
5770
|
}
|
|
5486
|
-
|
|
5771
|
+
import_node_server_utils34.logger.info(`Found ${scheduleTasks.length} schedule tasks to check`);
|
|
5487
5772
|
let processedCount = 0;
|
|
5488
5773
|
let validatedCount = 0;
|
|
5489
5774
|
const validatedTasks = [];
|
|
5490
5775
|
for (const scheduleTask of scheduleTasks) {
|
|
5491
5776
|
try {
|
|
5492
|
-
|
|
5777
|
+
import_node_server_utils34.logger.info(
|
|
5493
5778
|
`Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time}, startDate=${scheduleTask.startDate}, endDate=${scheduleTask.endDate}`
|
|
5494
5779
|
);
|
|
5495
5780
|
const shouldRun = checkScheduleConditions(scheduleTask, currentDate);
|
|
5496
5781
|
if (!shouldRun) {
|
|
5497
|
-
|
|
5782
|
+
import_node_server_utils34.logger.info(
|
|
5498
5783
|
`Schedule ${scheduleTask._id} conditions not met, skipping`
|
|
5499
5784
|
);
|
|
5500
5785
|
continue;
|
|
5501
5786
|
}
|
|
5502
|
-
|
|
5787
|
+
import_node_server_utils34.logger.info(
|
|
5503
5788
|
`Schedule ${scheduleTask._id} conditions validated, creating area checklists`
|
|
5504
5789
|
);
|
|
5505
5790
|
if (!scheduleTask._id) {
|
|
5506
|
-
|
|
5791
|
+
import_node_server_utils34.logger.warn(`Schedule ${scheduleTask.title} has no _id, skipping`);
|
|
5507
5792
|
continue;
|
|
5508
5793
|
}
|
|
5509
5794
|
if (!scheduleTask.site) {
|
|
5510
|
-
|
|
5795
|
+
import_node_server_utils34.logger.warn(`Schedule ${scheduleTask._id} has no site, skipping`);
|
|
5511
5796
|
continue;
|
|
5512
5797
|
}
|
|
5513
|
-
|
|
5798
|
+
import_node_server_utils34.logger.info(
|
|
5514
5799
|
`Getting or creating parent checklist for schedule ${scheduleTask._id} in site ${scheduleTask.site}`
|
|
5515
5800
|
);
|
|
5516
5801
|
const parentChecklistIds = await createParentChecklist({
|
|
@@ -5518,7 +5803,7 @@ function useScheduleTaskService() {
|
|
|
5518
5803
|
createdAt: /* @__PURE__ */ new Date()
|
|
5519
5804
|
});
|
|
5520
5805
|
const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
|
|
5521
|
-
|
|
5806
|
+
import_node_server_utils34.logger.info(
|
|
5522
5807
|
`Using parent checklist ${parentChecklistId}, now creating/updating area checklists`
|
|
5523
5808
|
);
|
|
5524
5809
|
for (const area of scheduleTask.areas) {
|
|
@@ -5531,14 +5816,14 @@ function useScheduleTaskService() {
|
|
|
5531
5816
|
unit: unit.unit.toString(),
|
|
5532
5817
|
name: unit.name
|
|
5533
5818
|
}));
|
|
5534
|
-
|
|
5819
|
+
import_node_server_utils34.logger.info(
|
|
5535
5820
|
`Area ${area.name} (${areaId}): Using units from area details: ${JSON.stringify(
|
|
5536
5821
|
units
|
|
5537
5822
|
)}`
|
|
5538
5823
|
);
|
|
5539
5824
|
}
|
|
5540
5825
|
if (units.length === 0) {
|
|
5541
|
-
|
|
5826
|
+
import_node_server_utils34.logger.warn(
|
|
5542
5827
|
`Area ${area.name} (${areaId}): No units found, skipping area.`
|
|
5543
5828
|
);
|
|
5544
5829
|
continue;
|
|
@@ -5549,11 +5834,11 @@ function useScheduleTaskService() {
|
|
|
5549
5834
|
parentChecklistId.toString(),
|
|
5550
5835
|
areaId
|
|
5551
5836
|
);
|
|
5552
|
-
|
|
5837
|
+
import_node_server_utils34.logger.info(
|
|
5553
5838
|
`Area ${area.name} (${areaId}): Existing area checklist found: ${existingAreaChecklist ? "Yes" : "No"}`
|
|
5554
5839
|
);
|
|
5555
5840
|
if (existingAreaChecklist) {
|
|
5556
|
-
|
|
5841
|
+
import_node_server_utils34.logger.info(
|
|
5557
5842
|
`Area ${area.name} (${areaId}): Existing checklist content: ${JSON.stringify(
|
|
5558
5843
|
existingAreaChecklist.checklist
|
|
5559
5844
|
)}`
|
|
@@ -5561,7 +5846,7 @@ function useScheduleTaskService() {
|
|
|
5561
5846
|
}
|
|
5562
5847
|
} catch (error) {
|
|
5563
5848
|
existingAreaChecklist = null;
|
|
5564
|
-
|
|
5849
|
+
import_node_server_utils34.logger.info(
|
|
5565
5850
|
`Area ${area.name} (${areaId}): No existing area checklist found (exception).`
|
|
5566
5851
|
);
|
|
5567
5852
|
}
|
|
@@ -5575,7 +5860,7 @@ function useScheduleTaskService() {
|
|
|
5575
5860
|
...existingAreaChecklist.checklist || [],
|
|
5576
5861
|
newSet
|
|
5577
5862
|
];
|
|
5578
|
-
|
|
5863
|
+
import_node_server_utils34.logger.info(
|
|
5579
5864
|
`Area ${area.name} (${areaId}): Appending new set ${newSet.set} to checklist. Updated checklist: ${JSON.stringify(
|
|
5580
5865
|
updatedChecklist
|
|
5581
5866
|
)}`
|
|
@@ -5583,7 +5868,7 @@ function useScheduleTaskService() {
|
|
|
5583
5868
|
await updateAreaChecklist(existingAreaChecklist._id, {
|
|
5584
5869
|
checklist: updatedChecklist
|
|
5585
5870
|
});
|
|
5586
|
-
|
|
5871
|
+
import_node_server_utils34.logger.info(
|
|
5587
5872
|
`Appended set ${newSet.set} to area checklist for area ${area.name}`
|
|
5588
5873
|
);
|
|
5589
5874
|
try {
|
|
@@ -5591,13 +5876,13 @@ function useScheduleTaskService() {
|
|
|
5591
5876
|
parentChecklistId.toString(),
|
|
5592
5877
|
areaId
|
|
5593
5878
|
);
|
|
5594
|
-
|
|
5879
|
+
import_node_server_utils34.logger.info(
|
|
5595
5880
|
`Area ${area.name} (${areaId}): Checklist after update: ${JSON.stringify(
|
|
5596
5881
|
verifyChecklist.checklist
|
|
5597
5882
|
)}`
|
|
5598
5883
|
);
|
|
5599
5884
|
} catch (verifyError) {
|
|
5600
|
-
|
|
5885
|
+
import_node_server_utils34.logger.warn(
|
|
5601
5886
|
`Area ${area.name} (${areaId}): Error verifying checklist after update:`,
|
|
5602
5887
|
verifyError
|
|
5603
5888
|
);
|
|
@@ -5616,50 +5901,50 @@ function useScheduleTaskService() {
|
|
|
5616
5901
|
],
|
|
5617
5902
|
createdBy: scheduleTask.createdBy
|
|
5618
5903
|
};
|
|
5619
|
-
|
|
5904
|
+
import_node_server_utils34.logger.info(
|
|
5620
5905
|
`Area ${area.name} (${areaId}): Creating new area checklist with data: ${JSON.stringify(
|
|
5621
5906
|
checklistData
|
|
5622
5907
|
)}`
|
|
5623
5908
|
);
|
|
5624
5909
|
await createAreaChecklist(checklistData);
|
|
5625
|
-
|
|
5910
|
+
import_node_server_utils34.logger.info(`Created new area checklist for area ${area.name}`);
|
|
5626
5911
|
try {
|
|
5627
5912
|
const verifyChecklist = await getAreaChecklistByAreaAndSchedule(
|
|
5628
5913
|
parentChecklistId.toString(),
|
|
5629
5914
|
areaId
|
|
5630
5915
|
);
|
|
5631
|
-
|
|
5916
|
+
import_node_server_utils34.logger.info(
|
|
5632
5917
|
`Area ${area.name} (${areaId}): Checklist after creation: ${JSON.stringify(
|
|
5633
5918
|
verifyChecklist.checklist
|
|
5634
5919
|
)}`
|
|
5635
5920
|
);
|
|
5636
5921
|
} catch (verifyError) {
|
|
5637
|
-
|
|
5922
|
+
import_node_server_utils34.logger.warn(
|
|
5638
5923
|
`Area ${area.name} (${areaId}): Error verifying checklist after creation:`,
|
|
5639
5924
|
verifyError
|
|
5640
5925
|
);
|
|
5641
5926
|
}
|
|
5642
5927
|
}
|
|
5643
5928
|
} catch (error) {
|
|
5644
|
-
|
|
5929
|
+
import_node_server_utils34.logger.error(`Error processing area ${area.name}:`, error);
|
|
5645
5930
|
continue;
|
|
5646
5931
|
}
|
|
5647
5932
|
}
|
|
5648
5933
|
processedCount++;
|
|
5649
5934
|
validatedCount++;
|
|
5650
5935
|
validatedTasks.push(scheduleTask);
|
|
5651
|
-
|
|
5936
|
+
import_node_server_utils34.logger.info(
|
|
5652
5937
|
`Successfully processed schedule ${scheduleTask._id}, created/updated area checklists for all areas.`
|
|
5653
5938
|
);
|
|
5654
5939
|
} catch (error) {
|
|
5655
|
-
|
|
5940
|
+
import_node_server_utils34.logger.error(
|
|
5656
5941
|
`Error processing schedule task ${scheduleTask._id}:`,
|
|
5657
5942
|
error
|
|
5658
5943
|
);
|
|
5659
5944
|
continue;
|
|
5660
5945
|
}
|
|
5661
5946
|
}
|
|
5662
|
-
|
|
5947
|
+
import_node_server_utils34.logger.info(
|
|
5663
5948
|
`Scheduled task processing completed. Processed: ${processedCount}, Validated: ${validatedCount} tasks`
|
|
5664
5949
|
);
|
|
5665
5950
|
return {
|
|
@@ -5668,7 +5953,7 @@ function useScheduleTaskService() {
|
|
|
5668
5953
|
tasks: validatedTasks
|
|
5669
5954
|
};
|
|
5670
5955
|
} catch (error) {
|
|
5671
|
-
|
|
5956
|
+
import_node_server_utils34.logger.error("Error processing scheduled tasks:", error);
|
|
5672
5957
|
throw error;
|
|
5673
5958
|
}
|
|
5674
5959
|
}
|
|
@@ -5677,7 +5962,7 @@ function useScheduleTaskService() {
|
|
|
5677
5962
|
|
|
5678
5963
|
// src/controllers/hygiene-schedule-task.controller.ts
|
|
5679
5964
|
var import_joi17 = __toESM(require("joi"));
|
|
5680
|
-
var
|
|
5965
|
+
var import_node_server_utils35 = require("@7365admin1/node-server-utils");
|
|
5681
5966
|
function useScheduleTaskController() {
|
|
5682
5967
|
const {
|
|
5683
5968
|
createScheduleTask: _createScheduleTask,
|
|
@@ -5695,8 +5980,8 @@ function useScheduleTaskController() {
|
|
|
5695
5980
|
const payload = { ...req.body, ...req.params, createdBy };
|
|
5696
5981
|
const { error } = scheduleTaskSchema.validate(payload);
|
|
5697
5982
|
if (error) {
|
|
5698
|
-
|
|
5699
|
-
next(new
|
|
5983
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
5984
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5700
5985
|
return;
|
|
5701
5986
|
}
|
|
5702
5987
|
try {
|
|
@@ -5704,7 +5989,7 @@ function useScheduleTaskController() {
|
|
|
5704
5989
|
res.status(201).json({ message: "Schedule task created successfully.", id });
|
|
5705
5990
|
return;
|
|
5706
5991
|
} catch (error2) {
|
|
5707
|
-
|
|
5992
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5708
5993
|
next(error2);
|
|
5709
5994
|
return;
|
|
5710
5995
|
}
|
|
@@ -5719,8 +6004,8 @@ function useScheduleTaskController() {
|
|
|
5719
6004
|
});
|
|
5720
6005
|
const { error } = validation.validate(query);
|
|
5721
6006
|
if (error) {
|
|
5722
|
-
|
|
5723
|
-
next(new
|
|
6007
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6008
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5724
6009
|
return;
|
|
5725
6010
|
}
|
|
5726
6011
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -5737,7 +6022,7 @@ function useScheduleTaskController() {
|
|
|
5737
6022
|
res.json(data);
|
|
5738
6023
|
return;
|
|
5739
6024
|
} catch (error2) {
|
|
5740
|
-
|
|
6025
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5741
6026
|
next(error2);
|
|
5742
6027
|
return;
|
|
5743
6028
|
}
|
|
@@ -5752,8 +6037,8 @@ function useScheduleTaskController() {
|
|
|
5752
6037
|
});
|
|
5753
6038
|
const { error } = validation.validate(query);
|
|
5754
6039
|
if (error) {
|
|
5755
|
-
|
|
5756
|
-
next(new
|
|
6040
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6041
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5757
6042
|
return;
|
|
5758
6043
|
}
|
|
5759
6044
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -5770,7 +6055,7 @@ function useScheduleTaskController() {
|
|
|
5770
6055
|
res.json(data);
|
|
5771
6056
|
return;
|
|
5772
6057
|
} catch (error2) {
|
|
5773
|
-
|
|
6058
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5774
6059
|
next(error2);
|
|
5775
6060
|
return;
|
|
5776
6061
|
}
|
|
@@ -5780,8 +6065,8 @@ function useScheduleTaskController() {
|
|
|
5780
6065
|
const _id = req.params.id;
|
|
5781
6066
|
const { error, value } = validation.validate(_id);
|
|
5782
6067
|
if (error) {
|
|
5783
|
-
|
|
5784
|
-
next(new
|
|
6068
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6069
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5785
6070
|
return;
|
|
5786
6071
|
}
|
|
5787
6072
|
try {
|
|
@@ -5789,7 +6074,7 @@ function useScheduleTaskController() {
|
|
|
5789
6074
|
res.json(data);
|
|
5790
6075
|
return;
|
|
5791
6076
|
} catch (error2) {
|
|
5792
|
-
|
|
6077
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5793
6078
|
next(error2);
|
|
5794
6079
|
return;
|
|
5795
6080
|
}
|
|
@@ -5812,8 +6097,8 @@ function useScheduleTaskController() {
|
|
|
5812
6097
|
});
|
|
5813
6098
|
const { error } = validation.validate(payload);
|
|
5814
6099
|
if (error) {
|
|
5815
|
-
|
|
5816
|
-
next(new
|
|
6100
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6101
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5817
6102
|
return;
|
|
5818
6103
|
}
|
|
5819
6104
|
try {
|
|
@@ -5822,7 +6107,7 @@ function useScheduleTaskController() {
|
|
|
5822
6107
|
res.json({ message: "Schedule task updated successfully." });
|
|
5823
6108
|
return;
|
|
5824
6109
|
} catch (error2) {
|
|
5825
|
-
|
|
6110
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5826
6111
|
next(error2);
|
|
5827
6112
|
return;
|
|
5828
6113
|
}
|
|
@@ -5837,8 +6122,8 @@ function useScheduleTaskController() {
|
|
|
5837
6122
|
}
|
|
5838
6123
|
|
|
5839
6124
|
// src/services/hygiene-qr.service.ts
|
|
5840
|
-
var
|
|
5841
|
-
var
|
|
6125
|
+
var import_node_server_utils36 = require("@7365admin1/node-server-utils");
|
|
6126
|
+
var import_puppeteer2 = require("puppeteer");
|
|
5842
6127
|
var import_qrcode = __toESM(require("qrcode"));
|
|
5843
6128
|
function useQRService() {
|
|
5844
6129
|
async function generateQRDataUrl(qrUrl) {
|
|
@@ -5855,7 +6140,7 @@ function useQRService() {
|
|
|
5855
6140
|
async function generateQRImage(qrUrl) {
|
|
5856
6141
|
try {
|
|
5857
6142
|
const qrDataUrl = await generateQRDataUrl(qrUrl);
|
|
5858
|
-
const browser = await (0,
|
|
6143
|
+
const browser = await (0, import_puppeteer2.launch)({
|
|
5859
6144
|
headless: true,
|
|
5860
6145
|
executablePath: process.env.CHROME_BINARY,
|
|
5861
6146
|
args: [`--no-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`]
|
|
@@ -5908,7 +6193,7 @@ function useQRService() {
|
|
|
5908
6193
|
await browser.close();
|
|
5909
6194
|
return imageBuffer;
|
|
5910
6195
|
} catch (error) {
|
|
5911
|
-
|
|
6196
|
+
import_node_server_utils36.logger.log({
|
|
5912
6197
|
level: "error",
|
|
5913
6198
|
message: `Failed to generate QR image: ${error.message}`
|
|
5914
6199
|
});
|
|
@@ -5918,7 +6203,7 @@ function useQRService() {
|
|
|
5918
6203
|
async function generateQRPDF(qrUrl, title) {
|
|
5919
6204
|
try {
|
|
5920
6205
|
const qrDataUrl = await generateQRDataUrl(qrUrl);
|
|
5921
|
-
const browser = await (0,
|
|
6206
|
+
const browser = await (0, import_puppeteer2.launch)({
|
|
5922
6207
|
headless: true,
|
|
5923
6208
|
executablePath: process.env.CHROME_BINARY,
|
|
5924
6209
|
args: [`--no-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`]
|
|
@@ -6031,7 +6316,7 @@ function useQRService() {
|
|
|
6031
6316
|
await browser.close();
|
|
6032
6317
|
return pdfBuffer;
|
|
6033
6318
|
} catch (error) {
|
|
6034
|
-
|
|
6319
|
+
import_node_server_utils36.logger.log({
|
|
6035
6320
|
level: "error",
|
|
6036
6321
|
message: `Failed to generate QR PDF: ${error.message}`
|
|
6037
6322
|
});
|
|
@@ -6046,7 +6331,7 @@ function useQRService() {
|
|
|
6046
6331
|
|
|
6047
6332
|
// src/controllers/hygiene-qr.controller.ts
|
|
6048
6333
|
var import_joi18 = __toESM(require("joi"));
|
|
6049
|
-
var
|
|
6334
|
+
var import_node_server_utils37 = require("@7365admin1/node-server-utils");
|
|
6050
6335
|
function useQRController() {
|
|
6051
6336
|
const { generateQRImage: _generateQRImage, generateQRPDF: _generateQRPDF } = useQRService();
|
|
6052
6337
|
async function generateQR(req, res, next) {
|
|
@@ -6059,8 +6344,8 @@ function useQRController() {
|
|
|
6059
6344
|
const query = { ...req.query };
|
|
6060
6345
|
const { error, value } = validation.validate(query);
|
|
6061
6346
|
if (error) {
|
|
6062
|
-
|
|
6063
|
-
next(new
|
|
6347
|
+
import_node_server_utils37.logger.log({ level: "error", message: error.message });
|
|
6348
|
+
next(new import_node_server_utils37.BadRequestError(error.message));
|
|
6064
6349
|
return;
|
|
6065
6350
|
}
|
|
6066
6351
|
try {
|
|
@@ -6095,7 +6380,7 @@ function useQRController() {
|
|
|
6095
6380
|
}
|
|
6096
6381
|
return;
|
|
6097
6382
|
} catch (error2) {
|
|
6098
|
-
|
|
6383
|
+
import_node_server_utils37.logger.log({ level: "error", message: error2.message });
|
|
6099
6384
|
next(error2);
|
|
6100
6385
|
return;
|
|
6101
6386
|
}
|