@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.js
CHANGED
|
@@ -3131,12 +3131,48 @@ 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,
|
|
3137
3169
|
set: "$checklist.set",
|
|
3170
|
+
remarks: "$checklist.remarks",
|
|
3171
|
+
attachment: "$checklist.attachment",
|
|
3138
3172
|
unit: "$checklist.units.unit",
|
|
3139
3173
|
name: "$checklist.units.name",
|
|
3174
|
+
approve: "$checklist.units.approve",
|
|
3175
|
+
reject: "$checklist.units.reject",
|
|
3140
3176
|
status: {
|
|
3141
3177
|
$switch: {
|
|
3142
3178
|
branches: [
|
|
@@ -3152,19 +3188,24 @@ function useAreaChecklistRepo() {
|
|
|
3152
3188
|
default: "$checklist.units.status"
|
|
3153
3189
|
}
|
|
3154
3190
|
},
|
|
3155
|
-
|
|
3191
|
+
completedByName: "$completedBy.name"
|
|
3156
3192
|
}
|
|
3157
3193
|
},
|
|
3158
|
-
{ $sort: { set: 1, name: 1 } },
|
|
3159
3194
|
{
|
|
3160
3195
|
$group: {
|
|
3161
3196
|
_id: "$set",
|
|
3197
|
+
remarks: { $first: "$remarks" },
|
|
3198
|
+
attachment: { $first: "$attachment" },
|
|
3199
|
+
completedByName: { $first: "$completedByName" },
|
|
3162
3200
|
units: {
|
|
3163
3201
|
$push: {
|
|
3164
3202
|
unit: "$unit",
|
|
3165
3203
|
name: "$name",
|
|
3204
|
+
approve: "$approve",
|
|
3205
|
+
reject: "$reject",
|
|
3166
3206
|
status: "$status",
|
|
3167
|
-
remarks: "$remarks"
|
|
3207
|
+
remarks: "$remarks",
|
|
3208
|
+
completedByName: "$completedByName"
|
|
3168
3209
|
}
|
|
3169
3210
|
}
|
|
3170
3211
|
}
|
|
@@ -3173,6 +3214,9 @@ function useAreaChecklistRepo() {
|
|
|
3173
3214
|
$project: {
|
|
3174
3215
|
_id: 0,
|
|
3175
3216
|
set: "$_id",
|
|
3217
|
+
remarks: "$remarks",
|
|
3218
|
+
attachment: "$attachment",
|
|
3219
|
+
completedByName: 1,
|
|
3176
3220
|
units: 1
|
|
3177
3221
|
}
|
|
3178
3222
|
},
|
|
@@ -3276,6 +3320,12 @@ function useAreaChecklistRepo() {
|
|
|
3276
3320
|
if (value.remarks) {
|
|
3277
3321
|
updateValue["checklist.$[checklist].units.$[unit].remarks"] = value.remarks;
|
|
3278
3322
|
}
|
|
3323
|
+
if (value.attachment) {
|
|
3324
|
+
updateValue["checklist.$[checklist].attachment"] = value.attachment;
|
|
3325
|
+
if (value.remarks) {
|
|
3326
|
+
updateValue["checklist.$[checklist].remarks"] = value.remarks;
|
|
3327
|
+
}
|
|
3328
|
+
}
|
|
3279
3329
|
if (value.completedBy) {
|
|
3280
3330
|
updateValue["checklist.$[checklist].units.$[unit].completedBy"] = new import_mongodb9.ObjectId(value.completedBy);
|
|
3281
3331
|
}
|
|
@@ -3576,7 +3626,223 @@ function useAreaChecklistService() {
|
|
|
3576
3626
|
|
|
3577
3627
|
// src/controllers/hygiene-area-checklist.controller.ts
|
|
3578
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");
|
|
3579
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
|
|
3580
3846
|
function useAreaChecklistController() {
|
|
3581
3847
|
const {
|
|
3582
3848
|
getAllAreaChecklist: _getAllAreaChecklist,
|
|
@@ -3588,6 +3854,7 @@ function useAreaChecklistController() {
|
|
|
3588
3854
|
createAreaChecklist: _createAreaChecklist,
|
|
3589
3855
|
updateAreaChecklistUnits: _updateAreaChecklistUnits
|
|
3590
3856
|
} = useAreaChecklistService();
|
|
3857
|
+
const { generateChecklistPdf: _generateChecklistPdf } = useChecklistPdfService();
|
|
3591
3858
|
async function createAreaChecklist(req, res, next) {
|
|
3592
3859
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
3593
3860
|
(acc, [key, value2]) => ({ ...acc, [key]: value2 }),
|
|
@@ -3606,8 +3873,8 @@ function useAreaChecklistController() {
|
|
|
3606
3873
|
});
|
|
3607
3874
|
const { error, value } = validation.validate(payload);
|
|
3608
3875
|
if (error) {
|
|
3609
|
-
|
|
3610
|
-
next(new
|
|
3876
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
3877
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3611
3878
|
return;
|
|
3612
3879
|
}
|
|
3613
3880
|
try {
|
|
@@ -3615,7 +3882,7 @@ function useAreaChecklistController() {
|
|
|
3615
3882
|
res.status(201).json({ message: "Area checklist generated successfully." });
|
|
3616
3883
|
return;
|
|
3617
3884
|
} catch (error2) {
|
|
3618
|
-
|
|
3885
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3619
3886
|
next(error2);
|
|
3620
3887
|
return;
|
|
3621
3888
|
}
|
|
@@ -3632,8 +3899,8 @@ function useAreaChecklistController() {
|
|
|
3632
3899
|
});
|
|
3633
3900
|
const { error } = validation.validate(query);
|
|
3634
3901
|
if (error) {
|
|
3635
|
-
|
|
3636
|
-
next(new
|
|
3902
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
3903
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3637
3904
|
return;
|
|
3638
3905
|
}
|
|
3639
3906
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -3654,7 +3921,7 @@ function useAreaChecklistController() {
|
|
|
3654
3921
|
res.json(data);
|
|
3655
3922
|
return;
|
|
3656
3923
|
} catch (error2) {
|
|
3657
|
-
|
|
3924
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3658
3925
|
next(error2);
|
|
3659
3926
|
return;
|
|
3660
3927
|
}
|
|
@@ -3672,8 +3939,8 @@ function useAreaChecklistController() {
|
|
|
3672
3939
|
});
|
|
3673
3940
|
const { error } = validation.validate(query);
|
|
3674
3941
|
if (error) {
|
|
3675
|
-
|
|
3676
|
-
next(new
|
|
3942
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
3943
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3677
3944
|
return;
|
|
3678
3945
|
}
|
|
3679
3946
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -3696,7 +3963,7 @@ function useAreaChecklistController() {
|
|
|
3696
3963
|
res.json(data);
|
|
3697
3964
|
return;
|
|
3698
3965
|
} catch (error2) {
|
|
3699
|
-
|
|
3966
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3700
3967
|
next(error2);
|
|
3701
3968
|
return;
|
|
3702
3969
|
}
|
|
@@ -3706,8 +3973,8 @@ function useAreaChecklistController() {
|
|
|
3706
3973
|
const _id = req.params.id;
|
|
3707
3974
|
const { error, value } = validation.validate(_id);
|
|
3708
3975
|
if (error) {
|
|
3709
|
-
|
|
3710
|
-
next(new
|
|
3976
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
3977
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3711
3978
|
return;
|
|
3712
3979
|
}
|
|
3713
3980
|
try {
|
|
@@ -3715,7 +3982,7 @@ function useAreaChecklistController() {
|
|
|
3715
3982
|
res.json(data);
|
|
3716
3983
|
return;
|
|
3717
3984
|
} catch (error2) {
|
|
3718
|
-
|
|
3985
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3719
3986
|
next(error2);
|
|
3720
3987
|
return;
|
|
3721
3988
|
}
|
|
@@ -3730,8 +3997,8 @@ function useAreaChecklistController() {
|
|
|
3730
3997
|
});
|
|
3731
3998
|
const { error } = validation.validate(query);
|
|
3732
3999
|
if (error) {
|
|
3733
|
-
|
|
3734
|
-
next(new
|
|
4000
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
4001
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3735
4002
|
return;
|
|
3736
4003
|
}
|
|
3737
4004
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -3748,7 +4015,7 @@ function useAreaChecklistController() {
|
|
|
3748
4015
|
res.json(data);
|
|
3749
4016
|
return;
|
|
3750
4017
|
} catch (error2) {
|
|
3751
|
-
|
|
4018
|
+
import_node_server_utils20.logger.log({ level: "error", message: error2.message });
|
|
3752
4019
|
next(error2);
|
|
3753
4020
|
return;
|
|
3754
4021
|
}
|
|
@@ -3782,12 +4049,13 @@ function useAreaChecklistController() {
|
|
|
3782
4049
|
approve: import_joi9.default.boolean().optional(),
|
|
3783
4050
|
reject: import_joi9.default.boolean().optional(),
|
|
3784
4051
|
remarks: import_joi9.default.string().optional().allow("", null),
|
|
4052
|
+
attachment: import_joi9.default.array().items(import_joi9.default.string()).optional(),
|
|
3785
4053
|
completedBy: import_joi9.default.string().hex().required()
|
|
3786
4054
|
});
|
|
3787
4055
|
const { error } = validation.validate(payload);
|
|
3788
4056
|
if (error) {
|
|
3789
|
-
|
|
3790
|
-
next(new
|
|
4057
|
+
import_node_server_utils20.logger.log({ level: "error", message: error.message });
|
|
4058
|
+
next(new import_node_server_utils20.BadRequestError(error.message));
|
|
3791
4059
|
return;
|
|
3792
4060
|
}
|
|
3793
4061
|
try {
|
|
@@ -3796,7 +4064,39 @@ function useAreaChecklistController() {
|
|
|
3796
4064
|
res.json({ message: "Area checklist updated successfully." });
|
|
3797
4065
|
return;
|
|
3798
4066
|
} catch (error2) {
|
|
3799
|
-
|
|
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 });
|
|
3800
4100
|
next(error2);
|
|
3801
4101
|
return;
|
|
3802
4102
|
}
|
|
@@ -3807,14 +4107,15 @@ function useAreaChecklistController() {
|
|
|
3807
4107
|
getAreaChecklistHistory,
|
|
3808
4108
|
getAreaChecklistHistoryDetails,
|
|
3809
4109
|
getAreaChecklistUnits,
|
|
3810
|
-
updateAreaChecklistUnits
|
|
4110
|
+
updateAreaChecklistUnits,
|
|
4111
|
+
downloadChecklistPdf
|
|
3811
4112
|
};
|
|
3812
4113
|
}
|
|
3813
4114
|
|
|
3814
4115
|
// src/models/hygiene-supply.model.ts
|
|
3815
4116
|
var import_joi10 = __toESM(require("joi"));
|
|
3816
|
-
var
|
|
3817
|
-
var
|
|
4117
|
+
var import_mongodb11 = require("mongodb");
|
|
4118
|
+
var import_node_server_utils21 = require("@7365admin1/node-server-utils");
|
|
3818
4119
|
var supplySchema = import_joi10.default.object({
|
|
3819
4120
|
site: import_joi10.default.string().hex().required(),
|
|
3820
4121
|
name: import_joi10.default.string().required(),
|
|
@@ -3823,14 +4124,14 @@ var supplySchema = import_joi10.default.object({
|
|
|
3823
4124
|
function MSupply(value) {
|
|
3824
4125
|
const { error } = supplySchema.validate(value);
|
|
3825
4126
|
if (error) {
|
|
3826
|
-
|
|
3827
|
-
throw new
|
|
4127
|
+
import_node_server_utils21.logger.info(`Hygiene Supply Model: ${error.message}`);
|
|
4128
|
+
throw new import_node_server_utils21.BadRequestError(error.message);
|
|
3828
4129
|
}
|
|
3829
4130
|
if (value.site) {
|
|
3830
4131
|
try {
|
|
3831
|
-
value.site = new
|
|
4132
|
+
value.site = new import_mongodb11.ObjectId(value.site);
|
|
3832
4133
|
} catch (error2) {
|
|
3833
|
-
throw new
|
|
4134
|
+
throw new import_node_server_utils21.BadRequestError("Invalid site ID format.");
|
|
3834
4135
|
}
|
|
3835
4136
|
}
|
|
3836
4137
|
return {
|
|
@@ -3846,21 +4147,21 @@ function MSupply(value) {
|
|
|
3846
4147
|
}
|
|
3847
4148
|
|
|
3848
4149
|
// src/repositories/hygiene-supply.repository.ts
|
|
3849
|
-
var
|
|
3850
|
-
var
|
|
4150
|
+
var import_mongodb12 = require("mongodb");
|
|
4151
|
+
var import_node_server_utils22 = require("@7365admin1/node-server-utils");
|
|
3851
4152
|
function useSupplyRepository() {
|
|
3852
|
-
const db =
|
|
4153
|
+
const db = import_node_server_utils22.useAtlas.getDb();
|
|
3853
4154
|
if (!db) {
|
|
3854
|
-
throw new
|
|
4155
|
+
throw new import_node_server_utils22.InternalServerError("Unable to connect to server.");
|
|
3855
4156
|
}
|
|
3856
4157
|
const namespace_collection = "site.supplies";
|
|
3857
4158
|
const collection = db.collection(namespace_collection);
|
|
3858
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
4159
|
+
const { delNamespace, setCache, getCache } = (0, import_node_server_utils22.useCache)(namespace_collection);
|
|
3859
4160
|
async function createIndex() {
|
|
3860
4161
|
try {
|
|
3861
4162
|
await collection.createIndexes([{ key: { site: 1 } }]);
|
|
3862
4163
|
} catch (error) {
|
|
3863
|
-
throw new
|
|
4164
|
+
throw new import_node_server_utils22.InternalServerError(
|
|
3864
4165
|
"Failed to create index on hygiene supply."
|
|
3865
4166
|
);
|
|
3866
4167
|
}
|
|
@@ -3869,7 +4170,7 @@ function useSupplyRepository() {
|
|
|
3869
4170
|
try {
|
|
3870
4171
|
await collection.createIndex({ name: "text" });
|
|
3871
4172
|
} catch (error) {
|
|
3872
|
-
throw new
|
|
4173
|
+
throw new import_node_server_utils22.InternalServerError(
|
|
3873
4174
|
"Failed to create text index on hygiene supply."
|
|
3874
4175
|
);
|
|
3875
4176
|
}
|
|
@@ -3881,7 +4182,7 @@ function useSupplyRepository() {
|
|
|
3881
4182
|
{ unique: true }
|
|
3882
4183
|
);
|
|
3883
4184
|
} catch (error) {
|
|
3884
|
-
throw new
|
|
4185
|
+
throw new import_node_server_utils22.InternalServerError(
|
|
3885
4186
|
"Failed to create unique index on hygiene supply."
|
|
3886
4187
|
);
|
|
3887
4188
|
}
|
|
@@ -3891,9 +4192,9 @@ function useSupplyRepository() {
|
|
|
3891
4192
|
value = MSupply(value);
|
|
3892
4193
|
const res = await collection.insertOne(value, { session });
|
|
3893
4194
|
delNamespace().then(() => {
|
|
3894
|
-
|
|
4195
|
+
import_node_server_utils22.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
3895
4196
|
}).catch((err) => {
|
|
3896
|
-
|
|
4197
|
+
import_node_server_utils22.logger.error(
|
|
3897
4198
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
3898
4199
|
err
|
|
3899
4200
|
);
|
|
@@ -3902,7 +4203,7 @@ function useSupplyRepository() {
|
|
|
3902
4203
|
} catch (error) {
|
|
3903
4204
|
const isDuplicated = error.message.includes("duplicate");
|
|
3904
4205
|
if (isDuplicated) {
|
|
3905
|
-
throw new
|
|
4206
|
+
throw new import_node_server_utils22.BadRequestError("Supply already exists.");
|
|
3906
4207
|
}
|
|
3907
4208
|
throw error;
|
|
3908
4209
|
}
|
|
@@ -3922,20 +4223,20 @@ function useSupplyRepository() {
|
|
|
3922
4223
|
limit
|
|
3923
4224
|
};
|
|
3924
4225
|
try {
|
|
3925
|
-
site = new
|
|
4226
|
+
site = new import_mongodb12.ObjectId(site);
|
|
3926
4227
|
query.site = site;
|
|
3927
4228
|
cacheOptions.site = site.toString();
|
|
3928
4229
|
} catch (error) {
|
|
3929
|
-
throw new
|
|
4230
|
+
throw new import_node_server_utils22.BadRequestError("Invalid site ID format.");
|
|
3930
4231
|
}
|
|
3931
4232
|
if (search) {
|
|
3932
4233
|
query.$text = { $search: search };
|
|
3933
4234
|
cacheOptions.search = search;
|
|
3934
4235
|
}
|
|
3935
|
-
const cacheKey = (0,
|
|
4236
|
+
const cacheKey = (0, import_node_server_utils22.makeCacheKey)(namespace_collection, cacheOptions);
|
|
3936
4237
|
const cachedData = await getCache(cacheKey);
|
|
3937
4238
|
if (cachedData) {
|
|
3938
|
-
|
|
4239
|
+
import_node_server_utils22.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
3939
4240
|
return cachedData;
|
|
3940
4241
|
}
|
|
3941
4242
|
try {
|
|
@@ -3953,11 +4254,11 @@ function useSupplyRepository() {
|
|
|
3953
4254
|
{ $limit: limit }
|
|
3954
4255
|
]).toArray();
|
|
3955
4256
|
const length = await collection.countDocuments(query);
|
|
3956
|
-
const data = (0,
|
|
4257
|
+
const data = (0, import_node_server_utils22.paginate)(items, page, limit, length);
|
|
3957
4258
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
3958
|
-
|
|
4259
|
+
import_node_server_utils22.logger.info(`Cache set for key: ${cacheKey}`);
|
|
3959
4260
|
}).catch((err) => {
|
|
3960
|
-
|
|
4261
|
+
import_node_server_utils22.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
3961
4262
|
});
|
|
3962
4263
|
return data;
|
|
3963
4264
|
} catch (error) {
|
|
@@ -3966,25 +4267,25 @@ function useSupplyRepository() {
|
|
|
3966
4267
|
}
|
|
3967
4268
|
async function getSupplyById(_id, session) {
|
|
3968
4269
|
try {
|
|
3969
|
-
_id = new
|
|
4270
|
+
_id = new import_mongodb12.ObjectId(_id);
|
|
3970
4271
|
} catch (error) {
|
|
3971
|
-
throw new
|
|
4272
|
+
throw new import_node_server_utils22.BadRequestError("Invalid supply ID format.");
|
|
3972
4273
|
}
|
|
3973
4274
|
const query = {
|
|
3974
4275
|
_id,
|
|
3975
4276
|
status: { $ne: "deleted" }
|
|
3976
4277
|
};
|
|
3977
|
-
const cacheKey = (0,
|
|
4278
|
+
const cacheKey = (0, import_node_server_utils22.makeCacheKey)(namespace_collection, {
|
|
3978
4279
|
_id: _id.toString()
|
|
3979
4280
|
});
|
|
3980
4281
|
if (!session) {
|
|
3981
4282
|
const cachedData = await getCache(cacheKey);
|
|
3982
4283
|
if (cachedData) {
|
|
3983
|
-
|
|
4284
|
+
import_node_server_utils22.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
3984
4285
|
return cachedData;
|
|
3985
4286
|
}
|
|
3986
4287
|
} else {
|
|
3987
|
-
|
|
4288
|
+
import_node_server_utils22.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
3988
4289
|
}
|
|
3989
4290
|
try {
|
|
3990
4291
|
const data = await collection.aggregate([
|
|
@@ -3998,12 +4299,12 @@ function useSupplyRepository() {
|
|
|
3998
4299
|
}
|
|
3999
4300
|
]).toArray();
|
|
4000
4301
|
if (!data || data.length === 0) {
|
|
4001
|
-
throw new
|
|
4302
|
+
throw new import_node_server_utils22.NotFoundError("Supply not found.");
|
|
4002
4303
|
}
|
|
4003
4304
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
4004
|
-
|
|
4305
|
+
import_node_server_utils22.logger.info(`Cache set for key: ${cacheKey}`);
|
|
4005
4306
|
}).catch((err) => {
|
|
4006
|
-
|
|
4307
|
+
import_node_server_utils22.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4007
4308
|
});
|
|
4008
4309
|
return data[0];
|
|
4009
4310
|
} catch (error) {
|
|
@@ -4012,9 +4313,9 @@ function useSupplyRepository() {
|
|
|
4012
4313
|
}
|
|
4013
4314
|
async function updateSupply(_id, value, session) {
|
|
4014
4315
|
try {
|
|
4015
|
-
_id = new
|
|
4316
|
+
_id = new import_mongodb12.ObjectId(_id);
|
|
4016
4317
|
} catch (error) {
|
|
4017
|
-
throw new
|
|
4318
|
+
throw new import_node_server_utils22.BadRequestError("Invalid supply ID format.");
|
|
4018
4319
|
}
|
|
4019
4320
|
try {
|
|
4020
4321
|
const updateValue = { ...value, updatedAt: /* @__PURE__ */ new Date() };
|
|
@@ -4024,12 +4325,12 @@ function useSupplyRepository() {
|
|
|
4024
4325
|
{ session }
|
|
4025
4326
|
);
|
|
4026
4327
|
if (res.modifiedCount === 0) {
|
|
4027
|
-
throw new
|
|
4328
|
+
throw new import_node_server_utils22.InternalServerError("Unable to update cleaning supply.");
|
|
4028
4329
|
}
|
|
4029
4330
|
delNamespace().then(() => {
|
|
4030
|
-
|
|
4331
|
+
import_node_server_utils22.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4031
4332
|
}).catch((err) => {
|
|
4032
|
-
|
|
4333
|
+
import_node_server_utils22.logger.error(
|
|
4033
4334
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4034
4335
|
err
|
|
4035
4336
|
);
|
|
@@ -4038,16 +4339,16 @@ function useSupplyRepository() {
|
|
|
4038
4339
|
} catch (error) {
|
|
4039
4340
|
const isDuplicated = error.message.includes("duplicate");
|
|
4040
4341
|
if (isDuplicated) {
|
|
4041
|
-
throw new
|
|
4342
|
+
throw new import_node_server_utils22.BadRequestError("Supply already exists.");
|
|
4042
4343
|
}
|
|
4043
4344
|
throw error;
|
|
4044
4345
|
}
|
|
4045
4346
|
}
|
|
4046
4347
|
async function deleteSupply(_id, session) {
|
|
4047
4348
|
try {
|
|
4048
|
-
_id = new
|
|
4349
|
+
_id = new import_mongodb12.ObjectId(_id);
|
|
4049
4350
|
} catch (error) {
|
|
4050
|
-
throw new
|
|
4351
|
+
throw new import_node_server_utils22.BadRequestError("Invalid supply ID format.");
|
|
4051
4352
|
}
|
|
4052
4353
|
try {
|
|
4053
4354
|
const updateValue = {
|
|
@@ -4061,12 +4362,12 @@ function useSupplyRepository() {
|
|
|
4061
4362
|
{ session }
|
|
4062
4363
|
);
|
|
4063
4364
|
if (res.modifiedCount === 0) {
|
|
4064
|
-
throw new
|
|
4365
|
+
throw new import_node_server_utils22.InternalServerError("Unable to delete supply.");
|
|
4065
4366
|
}
|
|
4066
4367
|
delNamespace().then(() => {
|
|
4067
|
-
|
|
4368
|
+
import_node_server_utils22.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4068
4369
|
}).catch((err) => {
|
|
4069
|
-
|
|
4370
|
+
import_node_server_utils22.logger.error(
|
|
4070
4371
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4071
4372
|
err
|
|
4072
4373
|
);
|
|
@@ -4090,7 +4391,7 @@ function useSupplyRepository() {
|
|
|
4090
4391
|
|
|
4091
4392
|
// src/controllers/hygiene-supply.controller.ts
|
|
4092
4393
|
var import_joi11 = __toESM(require("joi"));
|
|
4093
|
-
var
|
|
4394
|
+
var import_node_server_utils23 = require("@7365admin1/node-server-utils");
|
|
4094
4395
|
function useSupplyController() {
|
|
4095
4396
|
const {
|
|
4096
4397
|
createSupply: _createSupply,
|
|
@@ -4103,8 +4404,8 @@ function useSupplyController() {
|
|
|
4103
4404
|
const payload = { ...req.body, ...req.params };
|
|
4104
4405
|
const { error } = supplySchema.validate(payload);
|
|
4105
4406
|
if (error) {
|
|
4106
|
-
|
|
4107
|
-
next(new
|
|
4407
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4408
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4108
4409
|
return;
|
|
4109
4410
|
}
|
|
4110
4411
|
try {
|
|
@@ -4112,7 +4413,7 @@ function useSupplyController() {
|
|
|
4112
4413
|
res.status(201).json({ message: "Supply created successfully.", id });
|
|
4113
4414
|
return;
|
|
4114
4415
|
} catch (error2) {
|
|
4115
|
-
|
|
4416
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4116
4417
|
next(error2);
|
|
4117
4418
|
return;
|
|
4118
4419
|
}
|
|
@@ -4127,8 +4428,8 @@ function useSupplyController() {
|
|
|
4127
4428
|
});
|
|
4128
4429
|
const { error } = validation.validate(query);
|
|
4129
4430
|
if (error) {
|
|
4130
|
-
|
|
4131
|
-
next(new
|
|
4431
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4432
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4132
4433
|
return;
|
|
4133
4434
|
}
|
|
4134
4435
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -4145,7 +4446,7 @@ function useSupplyController() {
|
|
|
4145
4446
|
res.json(data);
|
|
4146
4447
|
return;
|
|
4147
4448
|
} catch (error2) {
|
|
4148
|
-
|
|
4449
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4149
4450
|
next(error2);
|
|
4150
4451
|
return;
|
|
4151
4452
|
}
|
|
@@ -4155,8 +4456,8 @@ function useSupplyController() {
|
|
|
4155
4456
|
const _id = req.params.id;
|
|
4156
4457
|
const { error, value } = validation.validate(_id);
|
|
4157
4458
|
if (error) {
|
|
4158
|
-
|
|
4159
|
-
next(new
|
|
4459
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4460
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4160
4461
|
return;
|
|
4161
4462
|
}
|
|
4162
4463
|
try {
|
|
@@ -4164,7 +4465,7 @@ function useSupplyController() {
|
|
|
4164
4465
|
res.json(data);
|
|
4165
4466
|
return;
|
|
4166
4467
|
} catch (error2) {
|
|
4167
|
-
|
|
4468
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4168
4469
|
next(error2);
|
|
4169
4470
|
return;
|
|
4170
4471
|
}
|
|
@@ -4179,8 +4480,8 @@ function useSupplyController() {
|
|
|
4179
4480
|
});
|
|
4180
4481
|
const { error } = validation.validate(payload);
|
|
4181
4482
|
if (error) {
|
|
4182
|
-
|
|
4183
|
-
next(new
|
|
4483
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4484
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4184
4485
|
return;
|
|
4185
4486
|
}
|
|
4186
4487
|
try {
|
|
@@ -4189,7 +4490,7 @@ function useSupplyController() {
|
|
|
4189
4490
|
res.json({ message: "Supply updated successfully." });
|
|
4190
4491
|
return;
|
|
4191
4492
|
} catch (error2) {
|
|
4192
|
-
|
|
4493
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4193
4494
|
next(error2);
|
|
4194
4495
|
return;
|
|
4195
4496
|
}
|
|
@@ -4201,8 +4502,8 @@ function useSupplyController() {
|
|
|
4201
4502
|
});
|
|
4202
4503
|
const { error, value } = validation.validate({ id });
|
|
4203
4504
|
if (error) {
|
|
4204
|
-
|
|
4205
|
-
next(new
|
|
4505
|
+
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
4506
|
+
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
4206
4507
|
return;
|
|
4207
4508
|
}
|
|
4208
4509
|
try {
|
|
@@ -4210,7 +4511,7 @@ function useSupplyController() {
|
|
|
4210
4511
|
res.json({ message: "Supply deleted successfully." });
|
|
4211
4512
|
return;
|
|
4212
4513
|
} catch (error2) {
|
|
4213
|
-
|
|
4514
|
+
import_node_server_utils23.logger.log({ level: "error", message: error2.message });
|
|
4214
4515
|
next(error2);
|
|
4215
4516
|
return;
|
|
4216
4517
|
}
|
|
@@ -4226,8 +4527,8 @@ function useSupplyController() {
|
|
|
4226
4527
|
|
|
4227
4528
|
// src/models/hygiene-stock.model.ts
|
|
4228
4529
|
var import_joi12 = __toESM(require("joi"));
|
|
4229
|
-
var
|
|
4230
|
-
var
|
|
4530
|
+
var import_mongodb13 = require("mongodb");
|
|
4531
|
+
var import_node_server_utils24 = require("@7365admin1/node-server-utils");
|
|
4231
4532
|
var stockSchema = import_joi12.default.object({
|
|
4232
4533
|
site: import_joi12.default.string().hex().required(),
|
|
4233
4534
|
supply: import_joi12.default.string().hex().required(),
|
|
@@ -4239,21 +4540,21 @@ var stockSchema = import_joi12.default.object({
|
|
|
4239
4540
|
function MStock(value) {
|
|
4240
4541
|
const { error } = stockSchema.validate(value);
|
|
4241
4542
|
if (error) {
|
|
4242
|
-
|
|
4243
|
-
throw new
|
|
4543
|
+
import_node_server_utils24.logger.info(`Hygiene Stock Model: ${error.message}`);
|
|
4544
|
+
throw new import_node_server_utils24.BadRequestError(error.message);
|
|
4244
4545
|
}
|
|
4245
4546
|
if (value.site) {
|
|
4246
4547
|
try {
|
|
4247
|
-
value.site = new
|
|
4548
|
+
value.site = new import_mongodb13.ObjectId(value.site);
|
|
4248
4549
|
} catch (error2) {
|
|
4249
|
-
throw new
|
|
4550
|
+
throw new import_node_server_utils24.BadRequestError("Invalid site ID format.");
|
|
4250
4551
|
}
|
|
4251
4552
|
}
|
|
4252
4553
|
if (value.supply) {
|
|
4253
4554
|
try {
|
|
4254
|
-
value.supply = new
|
|
4555
|
+
value.supply = new import_mongodb13.ObjectId(value.supply);
|
|
4255
4556
|
} catch (error2) {
|
|
4256
|
-
throw new
|
|
4557
|
+
throw new import_node_server_utils24.BadRequestError("Invalid supply ID format.");
|
|
4257
4558
|
}
|
|
4258
4559
|
}
|
|
4259
4560
|
return {
|
|
@@ -4271,18 +4572,18 @@ function MStock(value) {
|
|
|
4271
4572
|
}
|
|
4272
4573
|
|
|
4273
4574
|
// src/repositories/hygiene-stock.repository.ts
|
|
4274
|
-
var
|
|
4275
|
-
var
|
|
4575
|
+
var import_mongodb14 = require("mongodb");
|
|
4576
|
+
var import_node_server_utils25 = require("@7365admin1/node-server-utils");
|
|
4276
4577
|
function useStockRepository() {
|
|
4277
|
-
const db =
|
|
4578
|
+
const db = import_node_server_utils25.useAtlas.getDb();
|
|
4278
4579
|
if (!db) {
|
|
4279
|
-
throw new
|
|
4580
|
+
throw new import_node_server_utils25.InternalServerError("Unable to connect to server.");
|
|
4280
4581
|
}
|
|
4281
4582
|
const namespace_collection = "site.supply.stocks";
|
|
4282
4583
|
const supply_collection = "site.supplies";
|
|
4283
4584
|
const collection = db.collection(namespace_collection);
|
|
4284
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
4285
|
-
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);
|
|
4286
4587
|
async function createIndex() {
|
|
4287
4588
|
try {
|
|
4288
4589
|
await collection.createIndexes([
|
|
@@ -4292,7 +4593,7 @@ function useStockRepository() {
|
|
|
4292
4593
|
{ key: { status: 1 } }
|
|
4293
4594
|
]);
|
|
4294
4595
|
} catch (error) {
|
|
4295
|
-
throw new
|
|
4596
|
+
throw new import_node_server_utils25.InternalServerError("Failed to create index on hygiene stock.");
|
|
4296
4597
|
}
|
|
4297
4598
|
}
|
|
4298
4599
|
async function createStock(value, session) {
|
|
@@ -4300,17 +4601,17 @@ function useStockRepository() {
|
|
|
4300
4601
|
value = MStock(value);
|
|
4301
4602
|
const res = await collection.insertOne(value, { session });
|
|
4302
4603
|
delNamespace().then(() => {
|
|
4303
|
-
|
|
4604
|
+
import_node_server_utils25.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4304
4605
|
}).catch((err) => {
|
|
4305
|
-
|
|
4606
|
+
import_node_server_utils25.logger.error(
|
|
4306
4607
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4307
4608
|
err
|
|
4308
4609
|
);
|
|
4309
4610
|
});
|
|
4310
4611
|
delSupplyNamespace().then(() => {
|
|
4311
|
-
|
|
4612
|
+
import_node_server_utils25.logger.info(`Cache cleared for namespace: ${supply_collection}`);
|
|
4312
4613
|
}).catch((err) => {
|
|
4313
|
-
|
|
4614
|
+
import_node_server_utils25.logger.error(
|
|
4314
4615
|
`Failed to clear cache for namespace: ${supply_collection}`,
|
|
4315
4616
|
err
|
|
4316
4617
|
);
|
|
@@ -4336,27 +4637,27 @@ function useStockRepository() {
|
|
|
4336
4637
|
limit
|
|
4337
4638
|
};
|
|
4338
4639
|
try {
|
|
4339
|
-
site = new
|
|
4640
|
+
site = new import_mongodb14.ObjectId(site);
|
|
4340
4641
|
query.site = site;
|
|
4341
4642
|
cacheOptions.site = site.toString();
|
|
4342
4643
|
} catch (error) {
|
|
4343
|
-
throw new
|
|
4644
|
+
throw new import_node_server_utils25.BadRequestError("Invalid site ID format.");
|
|
4344
4645
|
}
|
|
4345
4646
|
try {
|
|
4346
|
-
supply = new
|
|
4647
|
+
supply = new import_mongodb14.ObjectId(supply);
|
|
4347
4648
|
query.supply = supply;
|
|
4348
4649
|
cacheOptions.supply = supply.toString();
|
|
4349
4650
|
} catch (error) {
|
|
4350
|
-
throw new
|
|
4651
|
+
throw new import_node_server_utils25.BadRequestError("Invalid supply ID format.");
|
|
4351
4652
|
}
|
|
4352
4653
|
if (search) {
|
|
4353
4654
|
query.$text = { $search: search };
|
|
4354
4655
|
cacheOptions.search = search;
|
|
4355
4656
|
}
|
|
4356
|
-
const cacheKey = (0,
|
|
4657
|
+
const cacheKey = (0, import_node_server_utils25.makeCacheKey)(namespace_collection, cacheOptions);
|
|
4357
4658
|
const cachedData = await getCache(cacheKey);
|
|
4358
4659
|
if (cachedData) {
|
|
4359
|
-
|
|
4660
|
+
import_node_server_utils25.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
4360
4661
|
return cachedData;
|
|
4361
4662
|
}
|
|
4362
4663
|
try {
|
|
@@ -4375,11 +4676,11 @@ function useStockRepository() {
|
|
|
4375
4676
|
{ $limit: limit }
|
|
4376
4677
|
]).toArray();
|
|
4377
4678
|
const length = await collection.countDocuments(query);
|
|
4378
|
-
const data = (0,
|
|
4679
|
+
const data = (0, import_node_server_utils25.paginate)(items, page, limit, length);
|
|
4379
4680
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4380
|
-
|
|
4681
|
+
import_node_server_utils25.logger.info(`Cache set for key: ${cacheKey}`);
|
|
4381
4682
|
}).catch((err) => {
|
|
4382
|
-
|
|
4683
|
+
import_node_server_utils25.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4383
4684
|
});
|
|
4384
4685
|
return data;
|
|
4385
4686
|
} catch (error) {
|
|
@@ -4394,14 +4695,14 @@ function useStockRepository() {
|
|
|
4394
4695
|
}
|
|
4395
4696
|
|
|
4396
4697
|
// src/services/hygiene-stock.service.ts
|
|
4397
|
-
var
|
|
4698
|
+
var import_node_server_utils26 = require("@7365admin1/node-server-utils");
|
|
4398
4699
|
function useStockService() {
|
|
4399
4700
|
const { createStock: _createStock } = useStockRepository();
|
|
4400
4701
|
const { getSupplyById, updateSupply } = useSupplyRepository();
|
|
4401
4702
|
async function createStock(value, out = false, session) {
|
|
4402
4703
|
let ownSession = false;
|
|
4403
4704
|
if (!session) {
|
|
4404
|
-
session =
|
|
4705
|
+
session = import_node_server_utils26.useAtlas.getClient()?.startSession();
|
|
4405
4706
|
ownSession = true;
|
|
4406
4707
|
}
|
|
4407
4708
|
try {
|
|
@@ -4410,11 +4711,11 @@ function useStockService() {
|
|
|
4410
4711
|
const { qty, ...stockData } = value;
|
|
4411
4712
|
const supply = await getSupplyById(value.supply, session);
|
|
4412
4713
|
if (!supply || supply.qty === void 0) {
|
|
4413
|
-
throw new
|
|
4714
|
+
throw new import_node_server_utils26.NotFoundError("Supply not found.");
|
|
4414
4715
|
}
|
|
4415
4716
|
const newSupplyQty = out ? supply.qty - qty : supply.qty + qty;
|
|
4416
4717
|
if (out && newSupplyQty < 0) {
|
|
4417
|
-
throw new
|
|
4718
|
+
throw new import_node_server_utils26.BadRequestError(
|
|
4418
4719
|
`Insufficient stock. Available: ${supply.qty}, Requested: ${qty}`
|
|
4419
4720
|
);
|
|
4420
4721
|
}
|
|
@@ -4445,7 +4746,7 @@ function useStockService() {
|
|
|
4445
4746
|
|
|
4446
4747
|
// src/controllers/hygiene-stock.controller.ts
|
|
4447
4748
|
var import_joi13 = __toESM(require("joi"));
|
|
4448
|
-
var
|
|
4749
|
+
var import_node_server_utils27 = require("@7365admin1/node-server-utils");
|
|
4449
4750
|
function useStockController() {
|
|
4450
4751
|
const { getStocksBySupplyId: _getStocksBySupplyId } = useStockRepository();
|
|
4451
4752
|
const { createStock: _createStock } = useStockService();
|
|
@@ -4459,8 +4760,8 @@ function useStockController() {
|
|
|
4459
4760
|
});
|
|
4460
4761
|
const { error } = validation.validate(payload);
|
|
4461
4762
|
if (error) {
|
|
4462
|
-
|
|
4463
|
-
next(new
|
|
4763
|
+
import_node_server_utils27.logger.log({ level: "error", message: error.message });
|
|
4764
|
+
next(new import_node_server_utils27.BadRequestError(error.message));
|
|
4464
4765
|
return;
|
|
4465
4766
|
}
|
|
4466
4767
|
try {
|
|
@@ -4468,7 +4769,7 @@ function useStockController() {
|
|
|
4468
4769
|
res.status(201).json({ message: "Stock created successfully.", id });
|
|
4469
4770
|
return;
|
|
4470
4771
|
} catch (error2) {
|
|
4471
|
-
|
|
4772
|
+
import_node_server_utils27.logger.log({ level: "error", message: error2.message });
|
|
4472
4773
|
next(error2);
|
|
4473
4774
|
return;
|
|
4474
4775
|
}
|
|
@@ -4484,8 +4785,8 @@ function useStockController() {
|
|
|
4484
4785
|
});
|
|
4485
4786
|
const { error } = validation.validate(query);
|
|
4486
4787
|
if (error) {
|
|
4487
|
-
|
|
4488
|
-
next(new
|
|
4788
|
+
import_node_server_utils27.logger.log({ level: "error", message: error.message });
|
|
4789
|
+
next(new import_node_server_utils27.BadRequestError(error.message));
|
|
4489
4790
|
return;
|
|
4490
4791
|
}
|
|
4491
4792
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -4504,7 +4805,7 @@ function useStockController() {
|
|
|
4504
4805
|
res.json(data);
|
|
4505
4806
|
return;
|
|
4506
4807
|
} catch (error2) {
|
|
4507
|
-
|
|
4808
|
+
import_node_server_utils27.logger.log({ level: "error", message: error2.message });
|
|
4508
4809
|
next(error2);
|
|
4509
4810
|
return;
|
|
4510
4811
|
}
|
|
@@ -4517,8 +4818,8 @@ function useStockController() {
|
|
|
4517
4818
|
|
|
4518
4819
|
// src/models/hygiene-checkout-item.model.ts
|
|
4519
4820
|
var import_joi14 = __toESM(require("joi"));
|
|
4520
|
-
var
|
|
4521
|
-
var
|
|
4821
|
+
var import_mongodb15 = require("mongodb");
|
|
4822
|
+
var import_node_server_utils28 = require("@7365admin1/node-server-utils");
|
|
4522
4823
|
var allowedCheckOutItemStatus = ["pending", "completed"];
|
|
4523
4824
|
var checkOutItemSchema = import_joi14.default.object({
|
|
4524
4825
|
site: import_joi14.default.string().hex().required(),
|
|
@@ -4532,21 +4833,21 @@ var checkOutItemSchema = import_joi14.default.object({
|
|
|
4532
4833
|
function MCheckOutItem(value) {
|
|
4533
4834
|
const { error } = checkOutItemSchema.validate(value);
|
|
4534
4835
|
if (error) {
|
|
4535
|
-
|
|
4536
|
-
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);
|
|
4537
4838
|
}
|
|
4538
4839
|
if (value.site) {
|
|
4539
4840
|
try {
|
|
4540
|
-
value.site = new
|
|
4841
|
+
value.site = new import_mongodb15.ObjectId(value.site);
|
|
4541
4842
|
} catch (error2) {
|
|
4542
|
-
throw new
|
|
4843
|
+
throw new import_node_server_utils28.BadRequestError("Invalid site ID format.");
|
|
4543
4844
|
}
|
|
4544
4845
|
}
|
|
4545
4846
|
if (value.supply) {
|
|
4546
4847
|
try {
|
|
4547
|
-
value.supply = new
|
|
4848
|
+
value.supply = new import_mongodb15.ObjectId(value.supply);
|
|
4548
4849
|
} catch (error2) {
|
|
4549
|
-
throw new
|
|
4850
|
+
throw new import_node_server_utils28.BadRequestError("Invalid supply ID format.");
|
|
4550
4851
|
}
|
|
4551
4852
|
}
|
|
4552
4853
|
return {
|
|
@@ -4565,16 +4866,16 @@ function MCheckOutItem(value) {
|
|
|
4565
4866
|
}
|
|
4566
4867
|
|
|
4567
4868
|
// src/repositories/hygiene-checkout-item.repository.ts
|
|
4568
|
-
var
|
|
4569
|
-
var
|
|
4869
|
+
var import_mongodb16 = require("mongodb");
|
|
4870
|
+
var import_node_server_utils29 = require("@7365admin1/node-server-utils");
|
|
4570
4871
|
function useCheckOutItemRepository() {
|
|
4571
|
-
const db =
|
|
4872
|
+
const db = import_node_server_utils29.useAtlas.getDb();
|
|
4572
4873
|
if (!db) {
|
|
4573
|
-
throw new
|
|
4874
|
+
throw new import_node_server_utils29.InternalServerError("Unable to connect to server.");
|
|
4574
4875
|
}
|
|
4575
4876
|
const namespace_collection = "site.supply.checkouts";
|
|
4576
4877
|
const collection = db.collection(namespace_collection);
|
|
4577
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
4878
|
+
const { delNamespace, setCache, getCache } = (0, import_node_server_utils29.useCache)(namespace_collection);
|
|
4578
4879
|
async function createIndex() {
|
|
4579
4880
|
try {
|
|
4580
4881
|
await collection.createIndexes([
|
|
@@ -4583,7 +4884,7 @@ function useCheckOutItemRepository() {
|
|
|
4583
4884
|
{ key: { status: 1 } }
|
|
4584
4885
|
]);
|
|
4585
4886
|
} catch (error) {
|
|
4586
|
-
throw new
|
|
4887
|
+
throw new import_node_server_utils29.InternalServerError(
|
|
4587
4888
|
"Failed to create index on hygiene check out item."
|
|
4588
4889
|
);
|
|
4589
4890
|
}
|
|
@@ -4592,7 +4893,7 @@ function useCheckOutItemRepository() {
|
|
|
4592
4893
|
try {
|
|
4593
4894
|
await collection.createIndex({ supplyName: "text" });
|
|
4594
4895
|
} catch (error) {
|
|
4595
|
-
throw new
|
|
4896
|
+
throw new import_node_server_utils29.InternalServerError(
|
|
4596
4897
|
"Failed to create text index on hygiene supply."
|
|
4597
4898
|
);
|
|
4598
4899
|
}
|
|
@@ -4602,9 +4903,9 @@ function useCheckOutItemRepository() {
|
|
|
4602
4903
|
value = MCheckOutItem(value);
|
|
4603
4904
|
const res = await collection.insertOne(value, { session });
|
|
4604
4905
|
delNamespace().then(() => {
|
|
4605
|
-
|
|
4906
|
+
import_node_server_utils29.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4606
4907
|
}).catch((err) => {
|
|
4607
|
-
|
|
4908
|
+
import_node_server_utils29.logger.error(
|
|
4608
4909
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4609
4910
|
err
|
|
4610
4911
|
);
|
|
@@ -4629,20 +4930,20 @@ function useCheckOutItemRepository() {
|
|
|
4629
4930
|
limit
|
|
4630
4931
|
};
|
|
4631
4932
|
try {
|
|
4632
|
-
site = new
|
|
4933
|
+
site = new import_mongodb16.ObjectId(site);
|
|
4633
4934
|
query.site = site;
|
|
4634
4935
|
cacheOptions.site = site.toString();
|
|
4635
4936
|
} catch (error) {
|
|
4636
|
-
throw new
|
|
4937
|
+
throw new import_node_server_utils29.BadRequestError("Invalid site ID format.");
|
|
4637
4938
|
}
|
|
4638
4939
|
if (search) {
|
|
4639
4940
|
query.$text = { $search: search };
|
|
4640
4941
|
cacheOptions.search = search;
|
|
4641
4942
|
}
|
|
4642
|
-
const cacheKey = (0,
|
|
4943
|
+
const cacheKey = (0, import_node_server_utils29.makeCacheKey)(namespace_collection, cacheOptions);
|
|
4643
4944
|
const cachedData = await getCache(cacheKey);
|
|
4644
4945
|
if (cachedData) {
|
|
4645
|
-
|
|
4946
|
+
import_node_server_utils29.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
4646
4947
|
return cachedData;
|
|
4647
4948
|
}
|
|
4648
4949
|
try {
|
|
@@ -4689,11 +4990,11 @@ function useCheckOutItemRepository() {
|
|
|
4689
4990
|
{ $limit: limit }
|
|
4690
4991
|
]).toArray();
|
|
4691
4992
|
const length = await collection.countDocuments(query);
|
|
4692
|
-
const data = (0,
|
|
4993
|
+
const data = (0, import_node_server_utils29.paginate)(items, page, limit, length);
|
|
4693
4994
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
4694
|
-
|
|
4995
|
+
import_node_server_utils29.logger.info(`Cache set for key: ${cacheKey}`);
|
|
4695
4996
|
}).catch((err) => {
|
|
4696
|
-
|
|
4997
|
+
import_node_server_utils29.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4697
4998
|
});
|
|
4698
4999
|
return data;
|
|
4699
5000
|
} catch (error) {
|
|
@@ -4702,22 +5003,22 @@ function useCheckOutItemRepository() {
|
|
|
4702
5003
|
}
|
|
4703
5004
|
async function getCheckOutItemById(_id, session) {
|
|
4704
5005
|
try {
|
|
4705
|
-
_id = new
|
|
5006
|
+
_id = new import_mongodb16.ObjectId(_id);
|
|
4706
5007
|
} catch (error) {
|
|
4707
|
-
throw new
|
|
5008
|
+
throw new import_node_server_utils29.BadRequestError("Invalid check out item ID format.");
|
|
4708
5009
|
}
|
|
4709
5010
|
const query = { _id };
|
|
4710
|
-
const cacheKey = (0,
|
|
5011
|
+
const cacheKey = (0, import_node_server_utils29.makeCacheKey)(namespace_collection, {
|
|
4711
5012
|
_id: _id.toString()
|
|
4712
5013
|
});
|
|
4713
5014
|
if (!session) {
|
|
4714
5015
|
const cachedData = await getCache(cacheKey);
|
|
4715
5016
|
if (cachedData) {
|
|
4716
|
-
|
|
5017
|
+
import_node_server_utils29.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
4717
5018
|
return cachedData;
|
|
4718
5019
|
}
|
|
4719
5020
|
} else {
|
|
4720
|
-
|
|
5021
|
+
import_node_server_utils29.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
4721
5022
|
}
|
|
4722
5023
|
try {
|
|
4723
5024
|
const data = await collection.aggregate(
|
|
@@ -4752,12 +5053,12 @@ function useCheckOutItemRepository() {
|
|
|
4752
5053
|
session ? { session } : void 0
|
|
4753
5054
|
).toArray();
|
|
4754
5055
|
if (!data || data.length === 0) {
|
|
4755
|
-
throw new
|
|
5056
|
+
throw new import_node_server_utils29.NotFoundError("Check out item not found.");
|
|
4756
5057
|
}
|
|
4757
5058
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
4758
|
-
|
|
5059
|
+
import_node_server_utils29.logger.info(`Cache set for key: ${cacheKey}`);
|
|
4759
5060
|
}).catch((err) => {
|
|
4760
|
-
|
|
5061
|
+
import_node_server_utils29.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
4761
5062
|
});
|
|
4762
5063
|
return data[0];
|
|
4763
5064
|
} catch (error) {
|
|
@@ -4766,9 +5067,9 @@ function useCheckOutItemRepository() {
|
|
|
4766
5067
|
}
|
|
4767
5068
|
async function completeCheckOutItem(_id, session) {
|
|
4768
5069
|
try {
|
|
4769
|
-
_id = new
|
|
5070
|
+
_id = new import_mongodb16.ObjectId(_id);
|
|
4770
5071
|
} catch (error) {
|
|
4771
|
-
throw new
|
|
5072
|
+
throw new import_node_server_utils29.BadRequestError("Invalid check out item ID format.");
|
|
4772
5073
|
}
|
|
4773
5074
|
try {
|
|
4774
5075
|
const updateValue = {
|
|
@@ -4781,12 +5082,12 @@ function useCheckOutItemRepository() {
|
|
|
4781
5082
|
{ session }
|
|
4782
5083
|
);
|
|
4783
5084
|
if (res.modifiedCount === 0) {
|
|
4784
|
-
throw new
|
|
5085
|
+
throw new import_node_server_utils29.InternalServerError("Unable to complete check out item.");
|
|
4785
5086
|
}
|
|
4786
5087
|
delNamespace().then(() => {
|
|
4787
|
-
|
|
5088
|
+
import_node_server_utils29.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4788
5089
|
}).catch((err) => {
|
|
4789
|
-
|
|
5090
|
+
import_node_server_utils29.logger.error(
|
|
4790
5091
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4791
5092
|
err
|
|
4792
5093
|
);
|
|
@@ -4808,7 +5109,7 @@ function useCheckOutItemRepository() {
|
|
|
4808
5109
|
|
|
4809
5110
|
// src/services/hygiene-checkout-item.service.ts
|
|
4810
5111
|
var import_core = require("@7365admin1/core");
|
|
4811
|
-
var
|
|
5112
|
+
var import_node_server_utils30 = require("@7365admin1/node-server-utils");
|
|
4812
5113
|
function useCheckOutItemService() {
|
|
4813
5114
|
const {
|
|
4814
5115
|
createCheckOutItem: _createCheckOutItem,
|
|
@@ -4819,7 +5120,7 @@ function useCheckOutItemService() {
|
|
|
4819
5120
|
const { getUserById } = (0, import_core.useUserRepo)();
|
|
4820
5121
|
const { createStock } = useStockService();
|
|
4821
5122
|
async function createCheckOutItem(value) {
|
|
4822
|
-
const session =
|
|
5123
|
+
const session = import_node_server_utils30.useAtlas.getClient()?.startSession();
|
|
4823
5124
|
try {
|
|
4824
5125
|
session?.startTransaction();
|
|
4825
5126
|
const supplyData = await getSupplyById(value.supply);
|
|
@@ -4837,7 +5138,7 @@ function useCheckOutItemService() {
|
|
|
4837
5138
|
session
|
|
4838
5139
|
);
|
|
4839
5140
|
if (!checkOutItem) {
|
|
4840
|
-
throw new
|
|
5141
|
+
throw new import_node_server_utils30.BadRequestError("Failed to create check out item.");
|
|
4841
5142
|
}
|
|
4842
5143
|
const createdStocks = await createStock(
|
|
4843
5144
|
{
|
|
@@ -4859,7 +5160,7 @@ function useCheckOutItemService() {
|
|
|
4859
5160
|
}
|
|
4860
5161
|
}
|
|
4861
5162
|
async function createCheckOutItemByBatch(value) {
|
|
4862
|
-
const session =
|
|
5163
|
+
const session = import_node_server_utils30.useAtlas.getClient()?.startSession();
|
|
4863
5164
|
try {
|
|
4864
5165
|
session?.startTransaction();
|
|
4865
5166
|
const { site, attachment, createdBy, items } = value;
|
|
@@ -4907,7 +5208,7 @@ function useCheckOutItemService() {
|
|
|
4907
5208
|
|
|
4908
5209
|
// src/controllers/hygiene-checkout-item.controller.ts
|
|
4909
5210
|
var import_joi15 = __toESM(require("joi"));
|
|
4910
|
-
var
|
|
5211
|
+
var import_node_server_utils31 = require("@7365admin1/node-server-utils");
|
|
4911
5212
|
function useCheckOutItemController() {
|
|
4912
5213
|
const {
|
|
4913
5214
|
getCheckOutItems: _getCheckOutItems,
|
|
@@ -4937,8 +5238,8 @@ function useCheckOutItemController() {
|
|
|
4937
5238
|
});
|
|
4938
5239
|
const { error } = validation.validate(payload);
|
|
4939
5240
|
if (error) {
|
|
4940
|
-
|
|
4941
|
-
next(new
|
|
5241
|
+
import_node_server_utils31.logger.log({ level: "error", message: error.message });
|
|
5242
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
4942
5243
|
return;
|
|
4943
5244
|
}
|
|
4944
5245
|
try {
|
|
@@ -4946,7 +5247,7 @@ function useCheckOutItemController() {
|
|
|
4946
5247
|
res.status(201).json({ message: "Check out item created successfully.", id });
|
|
4947
5248
|
return;
|
|
4948
5249
|
} catch (error2) {
|
|
4949
|
-
|
|
5250
|
+
import_node_server_utils31.logger.log({ level: "error", message: error2.message });
|
|
4950
5251
|
next(error2);
|
|
4951
5252
|
return;
|
|
4952
5253
|
}
|
|
@@ -4975,8 +5276,8 @@ function useCheckOutItemController() {
|
|
|
4975
5276
|
});
|
|
4976
5277
|
const { error } = validation.validate(payload);
|
|
4977
5278
|
if (error) {
|
|
4978
|
-
|
|
4979
|
-
next(new
|
|
5279
|
+
import_node_server_utils31.logger.log({ level: "error", message: error.message });
|
|
5280
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
4980
5281
|
return;
|
|
4981
5282
|
}
|
|
4982
5283
|
try {
|
|
@@ -4984,7 +5285,7 @@ function useCheckOutItemController() {
|
|
|
4984
5285
|
res.status(201).json({ message: "Check out items created successfully." });
|
|
4985
5286
|
return;
|
|
4986
5287
|
} catch (error2) {
|
|
4987
|
-
|
|
5288
|
+
import_node_server_utils31.logger.log({ level: "error", message: error2.message });
|
|
4988
5289
|
next(error2);
|
|
4989
5290
|
return;
|
|
4990
5291
|
}
|
|
@@ -4999,8 +5300,8 @@ function useCheckOutItemController() {
|
|
|
4999
5300
|
});
|
|
5000
5301
|
const { error } = validation.validate(query);
|
|
5001
5302
|
if (error) {
|
|
5002
|
-
|
|
5003
|
-
next(new
|
|
5303
|
+
import_node_server_utils31.logger.log({ level: "error", message: error.message });
|
|
5304
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
5004
5305
|
return;
|
|
5005
5306
|
}
|
|
5006
5307
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -5017,7 +5318,7 @@ function useCheckOutItemController() {
|
|
|
5017
5318
|
res.json(data);
|
|
5018
5319
|
return;
|
|
5019
5320
|
} catch (error2) {
|
|
5020
|
-
|
|
5321
|
+
import_node_server_utils31.logger.log({ level: "error", message: error2.message });
|
|
5021
5322
|
next(error2);
|
|
5022
5323
|
return;
|
|
5023
5324
|
}
|
|
@@ -5027,8 +5328,8 @@ function useCheckOutItemController() {
|
|
|
5027
5328
|
const _id = req.params.id;
|
|
5028
5329
|
const { error, value } = validation.validate(_id);
|
|
5029
5330
|
if (error) {
|
|
5030
|
-
|
|
5031
|
-
next(new
|
|
5331
|
+
import_node_server_utils31.logger.log({ level: "error", message: error.message });
|
|
5332
|
+
next(new import_node_server_utils31.BadRequestError(error.message));
|
|
5032
5333
|
return;
|
|
5033
5334
|
}
|
|
5034
5335
|
try {
|
|
@@ -5036,7 +5337,7 @@ function useCheckOutItemController() {
|
|
|
5036
5337
|
res.json(data);
|
|
5037
5338
|
return;
|
|
5038
5339
|
} catch (error2) {
|
|
5039
|
-
|
|
5340
|
+
import_node_server_utils31.logger.log({ level: "error", message: error2.message });
|
|
5040
5341
|
next(error2);
|
|
5041
5342
|
return;
|
|
5042
5343
|
}
|
|
@@ -5050,9 +5351,9 @@ function useCheckOutItemController() {
|
|
|
5050
5351
|
}
|
|
5051
5352
|
|
|
5052
5353
|
// src/models/hygiene-schedule-task.model.ts
|
|
5053
|
-
var
|
|
5354
|
+
var import_node_server_utils32 = require("@7365admin1/node-server-utils");
|
|
5054
5355
|
var import_joi16 = __toESM(require("joi"));
|
|
5055
|
-
var
|
|
5356
|
+
var import_mongodb17 = require("mongodb");
|
|
5056
5357
|
var scheduleTaskSchema = import_joi16.default.object({
|
|
5057
5358
|
site: import_joi16.default.string().hex().required(),
|
|
5058
5359
|
title: import_joi16.default.string().required(),
|
|
@@ -5071,14 +5372,14 @@ var scheduleTaskSchema = import_joi16.default.object({
|
|
|
5071
5372
|
function MScheduleTask(value) {
|
|
5072
5373
|
const { error } = scheduleTaskSchema.validate(value);
|
|
5073
5374
|
if (error) {
|
|
5074
|
-
|
|
5075
|
-
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);
|
|
5076
5377
|
}
|
|
5077
5378
|
if (value.site) {
|
|
5078
5379
|
try {
|
|
5079
|
-
value.site = new
|
|
5380
|
+
value.site = new import_mongodb17.ObjectId(value.site);
|
|
5080
5381
|
} catch (error2) {
|
|
5081
|
-
throw new
|
|
5382
|
+
throw new import_node_server_utils32.BadRequestError("Invalid site ID format.");
|
|
5082
5383
|
}
|
|
5083
5384
|
}
|
|
5084
5385
|
if (value.areas && Array.isArray(value.areas)) {
|
|
@@ -5086,18 +5387,18 @@ function MScheduleTask(value) {
|
|
|
5086
5387
|
try {
|
|
5087
5388
|
return {
|
|
5088
5389
|
name: area.name,
|
|
5089
|
-
value: new
|
|
5390
|
+
value: new import_mongodb17.ObjectId(area.value.toString())
|
|
5090
5391
|
};
|
|
5091
5392
|
} catch (error2) {
|
|
5092
|
-
throw new
|
|
5393
|
+
throw new import_node_server_utils32.BadRequestError(`Invalid area value format: ${area.name}`);
|
|
5093
5394
|
}
|
|
5094
5395
|
});
|
|
5095
5396
|
}
|
|
5096
5397
|
if (value.createdBy) {
|
|
5097
5398
|
try {
|
|
5098
|
-
value.createdBy = new
|
|
5399
|
+
value.createdBy = new import_mongodb17.ObjectId(value.createdBy);
|
|
5099
5400
|
} catch (error2) {
|
|
5100
|
-
throw new
|
|
5401
|
+
throw new import_node_server_utils32.BadRequestError("Invalid createdBy ID format.");
|
|
5101
5402
|
}
|
|
5102
5403
|
}
|
|
5103
5404
|
return {
|
|
@@ -5117,16 +5418,16 @@ function MScheduleTask(value) {
|
|
|
5117
5418
|
}
|
|
5118
5419
|
|
|
5119
5420
|
// src/repositories/hygiene-schedule-task.repository.ts
|
|
5120
|
-
var
|
|
5121
|
-
var
|
|
5421
|
+
var import_mongodb18 = require("mongodb");
|
|
5422
|
+
var import_node_server_utils33 = require("@7365admin1/node-server-utils");
|
|
5122
5423
|
function useScheduleTaskRepository() {
|
|
5123
|
-
const db =
|
|
5424
|
+
const db = import_node_server_utils33.useAtlas.getDb();
|
|
5124
5425
|
if (!db) {
|
|
5125
|
-
throw new
|
|
5426
|
+
throw new import_node_server_utils33.InternalServerError("Unable to connect to server.");
|
|
5126
5427
|
}
|
|
5127
5428
|
const namespace_collection = "site.schedule-tasks";
|
|
5128
5429
|
const collection = db.collection(namespace_collection);
|
|
5129
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
5430
|
+
const { delNamespace, setCache, getCache } = (0, import_node_server_utils33.useCache)(namespace_collection);
|
|
5130
5431
|
async function createIndex() {
|
|
5131
5432
|
try {
|
|
5132
5433
|
await collection.createIndexes([
|
|
@@ -5134,7 +5435,7 @@ function useScheduleTaskRepository() {
|
|
|
5134
5435
|
{ key: { status: 1 } }
|
|
5135
5436
|
]);
|
|
5136
5437
|
} catch (error) {
|
|
5137
|
-
throw new
|
|
5438
|
+
throw new import_node_server_utils33.InternalServerError(
|
|
5138
5439
|
"Failed to create index on hygiene schedule task."
|
|
5139
5440
|
);
|
|
5140
5441
|
}
|
|
@@ -5143,7 +5444,7 @@ function useScheduleTaskRepository() {
|
|
|
5143
5444
|
try {
|
|
5144
5445
|
await collection.createIndex({ title: "text", description: "text" });
|
|
5145
5446
|
} catch (error) {
|
|
5146
|
-
throw new
|
|
5447
|
+
throw new import_node_server_utils33.InternalServerError(
|
|
5147
5448
|
"Failed to create text index on hygiene schedule task."
|
|
5148
5449
|
);
|
|
5149
5450
|
}
|
|
@@ -5153,9 +5454,9 @@ function useScheduleTaskRepository() {
|
|
|
5153
5454
|
value = MScheduleTask(value);
|
|
5154
5455
|
const res = await collection.insertOne(value, { session });
|
|
5155
5456
|
delNamespace().then(() => {
|
|
5156
|
-
|
|
5457
|
+
import_node_server_utils33.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5157
5458
|
}).catch((err) => {
|
|
5158
|
-
|
|
5459
|
+
import_node_server_utils33.logger.error(
|
|
5159
5460
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5160
5461
|
err
|
|
5161
5462
|
);
|
|
@@ -5180,20 +5481,20 @@ function useScheduleTaskRepository() {
|
|
|
5180
5481
|
limit
|
|
5181
5482
|
};
|
|
5182
5483
|
try {
|
|
5183
|
-
site = new
|
|
5484
|
+
site = new import_mongodb18.ObjectId(site);
|
|
5184
5485
|
query.site = site;
|
|
5185
5486
|
cacheOptions.site = site.toString();
|
|
5186
5487
|
} catch (error) {
|
|
5187
|
-
throw new
|
|
5488
|
+
throw new import_node_server_utils33.BadRequestError("Invalid site ID format.");
|
|
5188
5489
|
}
|
|
5189
5490
|
if (search) {
|
|
5190
5491
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
5191
5492
|
cacheOptions.search = search;
|
|
5192
5493
|
}
|
|
5193
|
-
const cacheKey = (0,
|
|
5494
|
+
const cacheKey = (0, import_node_server_utils33.makeCacheKey)(namespace_collection, cacheOptions);
|
|
5194
5495
|
const cachedData = await getCache(cacheKey);
|
|
5195
5496
|
if (cachedData) {
|
|
5196
|
-
|
|
5497
|
+
import_node_server_utils33.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5197
5498
|
return cachedData;
|
|
5198
5499
|
}
|
|
5199
5500
|
try {
|
|
@@ -5211,11 +5512,11 @@ function useScheduleTaskRepository() {
|
|
|
5211
5512
|
{ $limit: limit }
|
|
5212
5513
|
]).toArray();
|
|
5213
5514
|
const length = await collection.countDocuments(query);
|
|
5214
|
-
const data = (0,
|
|
5515
|
+
const data = (0, import_node_server_utils33.paginate)(items, page, limit, length);
|
|
5215
5516
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5216
|
-
|
|
5517
|
+
import_node_server_utils33.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5217
5518
|
}).catch((err) => {
|
|
5218
|
-
|
|
5519
|
+
import_node_server_utils33.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5219
5520
|
});
|
|
5220
5521
|
return data;
|
|
5221
5522
|
} catch (error) {
|
|
@@ -5248,20 +5549,20 @@ function useScheduleTaskRepository() {
|
|
|
5248
5549
|
limit
|
|
5249
5550
|
};
|
|
5250
5551
|
try {
|
|
5251
|
-
site = new
|
|
5552
|
+
site = new import_mongodb18.ObjectId(site);
|
|
5252
5553
|
query.site = site;
|
|
5253
5554
|
cacheOptions.site = site.toString();
|
|
5254
5555
|
} catch (error) {
|
|
5255
|
-
throw new
|
|
5556
|
+
throw new import_node_server_utils33.BadRequestError("Invalid site ID format.");
|
|
5256
5557
|
}
|
|
5257
5558
|
if (search) {
|
|
5258
5559
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
5259
5560
|
cacheOptions.search = search;
|
|
5260
5561
|
}
|
|
5261
|
-
const cacheKey = (0,
|
|
5562
|
+
const cacheKey = (0, import_node_server_utils33.makeCacheKey)(namespace_collection, cacheOptions);
|
|
5262
5563
|
const cachedData = await getCache(cacheKey);
|
|
5263
5564
|
if (cachedData) {
|
|
5264
|
-
|
|
5565
|
+
import_node_server_utils33.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5265
5566
|
return cachedData;
|
|
5266
5567
|
}
|
|
5267
5568
|
try {
|
|
@@ -5278,11 +5579,11 @@ function useScheduleTaskRepository() {
|
|
|
5278
5579
|
{ $limit: limit }
|
|
5279
5580
|
]).toArray();
|
|
5280
5581
|
const length = await collection.countDocuments(query);
|
|
5281
|
-
const data = (0,
|
|
5582
|
+
const data = (0, import_node_server_utils33.paginate)(items, page, limit, length);
|
|
5282
5583
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5283
|
-
|
|
5584
|
+
import_node_server_utils33.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5284
5585
|
}).catch((err) => {
|
|
5285
|
-
|
|
5586
|
+
import_node_server_utils33.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5286
5587
|
});
|
|
5287
5588
|
return data;
|
|
5288
5589
|
} catch (error) {
|
|
@@ -5291,25 +5592,25 @@ function useScheduleTaskRepository() {
|
|
|
5291
5592
|
}
|
|
5292
5593
|
async function getScheduleTaskById(_id, session) {
|
|
5293
5594
|
try {
|
|
5294
|
-
_id = new
|
|
5595
|
+
_id = new import_mongodb18.ObjectId(_id);
|
|
5295
5596
|
} catch (error) {
|
|
5296
|
-
throw new
|
|
5597
|
+
throw new import_node_server_utils33.BadRequestError("Invalid schedule task ID format.");
|
|
5297
5598
|
}
|
|
5298
5599
|
const query = {
|
|
5299
5600
|
_id,
|
|
5300
5601
|
status: { $ne: "deleted" }
|
|
5301
5602
|
};
|
|
5302
|
-
const cacheKey = (0,
|
|
5603
|
+
const cacheKey = (0, import_node_server_utils33.makeCacheKey)(namespace_collection, {
|
|
5303
5604
|
_id: _id.toString()
|
|
5304
5605
|
});
|
|
5305
5606
|
if (!session) {
|
|
5306
5607
|
const cachedData = await getCache(cacheKey);
|
|
5307
5608
|
if (cachedData) {
|
|
5308
|
-
|
|
5609
|
+
import_node_server_utils33.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5309
5610
|
return cachedData;
|
|
5310
5611
|
}
|
|
5311
5612
|
} else {
|
|
5312
|
-
|
|
5613
|
+
import_node_server_utils33.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
5313
5614
|
}
|
|
5314
5615
|
try {
|
|
5315
5616
|
const data = await collection.aggregate([
|
|
@@ -5328,12 +5629,12 @@ function useScheduleTaskRepository() {
|
|
|
5328
5629
|
}
|
|
5329
5630
|
]).toArray();
|
|
5330
5631
|
if (!data || data.length === 0) {
|
|
5331
|
-
throw new
|
|
5632
|
+
throw new import_node_server_utils33.NotFoundError("Schedule task not found.");
|
|
5332
5633
|
}
|
|
5333
5634
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
5334
|
-
|
|
5635
|
+
import_node_server_utils33.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5335
5636
|
}).catch((err) => {
|
|
5336
|
-
|
|
5637
|
+
import_node_server_utils33.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5337
5638
|
});
|
|
5338
5639
|
return data[0];
|
|
5339
5640
|
} catch (error) {
|
|
@@ -5342,19 +5643,19 @@ function useScheduleTaskRepository() {
|
|
|
5342
5643
|
}
|
|
5343
5644
|
async function updateScheduleTask(_id, value, session) {
|
|
5344
5645
|
try {
|
|
5345
|
-
_id = new
|
|
5646
|
+
_id = new import_mongodb18.ObjectId(_id);
|
|
5346
5647
|
} catch (error) {
|
|
5347
|
-
throw new
|
|
5648
|
+
throw new import_node_server_utils33.BadRequestError("Invalid schedule task ID format.");
|
|
5348
5649
|
}
|
|
5349
5650
|
if (value.areas && Array.isArray(value.areas)) {
|
|
5350
5651
|
value.areas = value.areas.map((area) => {
|
|
5351
5652
|
try {
|
|
5352
5653
|
return {
|
|
5353
5654
|
name: area.name,
|
|
5354
|
-
value: new
|
|
5655
|
+
value: new import_mongodb18.ObjectId(area.value.toString())
|
|
5355
5656
|
};
|
|
5356
5657
|
} catch (error) {
|
|
5357
|
-
throw new
|
|
5658
|
+
throw new import_node_server_utils33.BadRequestError(`Invalid area value format: ${area.name}`);
|
|
5358
5659
|
}
|
|
5359
5660
|
});
|
|
5360
5661
|
}
|
|
@@ -5366,14 +5667,14 @@ function useScheduleTaskRepository() {
|
|
|
5366
5667
|
{ session }
|
|
5367
5668
|
);
|
|
5368
5669
|
if (res.modifiedCount === 0) {
|
|
5369
|
-
throw new
|
|
5670
|
+
throw new import_node_server_utils33.InternalServerError(
|
|
5370
5671
|
"Unable to update hygiene schedule task."
|
|
5371
5672
|
);
|
|
5372
5673
|
}
|
|
5373
5674
|
delNamespace().then(() => {
|
|
5374
|
-
|
|
5675
|
+
import_node_server_utils33.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5375
5676
|
}).catch((err) => {
|
|
5376
|
-
|
|
5677
|
+
import_node_server_utils33.logger.error(
|
|
5377
5678
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5378
5679
|
err
|
|
5379
5680
|
);
|
|
@@ -5396,7 +5697,7 @@ function useScheduleTaskRepository() {
|
|
|
5396
5697
|
}
|
|
5397
5698
|
|
|
5398
5699
|
// src/services/hygiene-schedule-task.service.ts
|
|
5399
|
-
var
|
|
5700
|
+
var import_node_server_utils34 = require("@7365admin1/node-server-utils");
|
|
5400
5701
|
function useScheduleTaskService() {
|
|
5401
5702
|
const { createParentChecklist } = useParentChecklistRepo();
|
|
5402
5703
|
const { getAllScheduleTask } = useScheduleTaskRepository();
|
|
@@ -5419,13 +5720,13 @@ function useScheduleTaskService() {
|
|
|
5419
5720
|
const currentDateString = now.toLocaleDateString("en-US", {
|
|
5420
5721
|
timeZone: "Asia/Singapore"
|
|
5421
5722
|
});
|
|
5422
|
-
|
|
5723
|
+
import_node_server_utils34.logger.info(
|
|
5423
5724
|
`Checking schedule ${schedule._id}: Current time ${currentHour}:${currentMinute}, Current date ${currentDateString}, Schedule time ${schedule.time}, Start date ${schedule.startDate}, End date ${schedule.endDate}`
|
|
5424
5725
|
);
|
|
5425
5726
|
const startDate = /* @__PURE__ */ new Date(schedule.startDate + "T00:00:00");
|
|
5426
5727
|
const currentDateOnly = /* @__PURE__ */ new Date(currentDateString + "T00:00:00");
|
|
5427
5728
|
if (currentDateOnly < startDate) {
|
|
5428
|
-
|
|
5729
|
+
import_node_server_utils34.logger.info(
|
|
5429
5730
|
`Schedule ${schedule._id}: Current date ${currentDateString} is before start date ${schedule.startDate}`
|
|
5430
5731
|
);
|
|
5431
5732
|
return false;
|
|
@@ -5433,7 +5734,7 @@ function useScheduleTaskService() {
|
|
|
5433
5734
|
if (schedule.endDate) {
|
|
5434
5735
|
const endDate = /* @__PURE__ */ new Date(schedule.endDate + "T00:00:00");
|
|
5435
5736
|
if (currentDateOnly > endDate) {
|
|
5436
|
-
|
|
5737
|
+
import_node_server_utils34.logger.info(
|
|
5437
5738
|
`Schedule ${schedule._id}: Current date ${currentDateString} is after end date ${schedule.endDate}`
|
|
5438
5739
|
);
|
|
5439
5740
|
return false;
|
|
@@ -5442,17 +5743,17 @@ function useScheduleTaskService() {
|
|
|
5442
5743
|
const [scheduleHour, scheduleMinute] = schedule.time.split(":").map(Number);
|
|
5443
5744
|
const timeMatches = currentHour === scheduleHour && currentMinute === scheduleMinute;
|
|
5444
5745
|
if (!timeMatches) {
|
|
5445
|
-
|
|
5746
|
+
import_node_server_utils34.logger.info(
|
|
5446
5747
|
`Schedule ${schedule._id}: Time does not match. Current: ${currentHour}:${currentMinute}, Expected: ${scheduleHour}:${scheduleMinute}`
|
|
5447
5748
|
);
|
|
5448
5749
|
return false;
|
|
5449
5750
|
}
|
|
5450
|
-
|
|
5751
|
+
import_node_server_utils34.logger.info(
|
|
5451
5752
|
`Schedule ${schedule._id}: All conditions matched - Date is within range and time matches`
|
|
5452
5753
|
);
|
|
5453
5754
|
return true;
|
|
5454
5755
|
} catch (error) {
|
|
5455
|
-
|
|
5756
|
+
import_node_server_utils34.logger.error(
|
|
5456
5757
|
`Error checking schedule conditions for ${schedule._id}:`,
|
|
5457
5758
|
error
|
|
5458
5759
|
);
|
|
@@ -5461,40 +5762,40 @@ function useScheduleTaskService() {
|
|
|
5461
5762
|
}
|
|
5462
5763
|
async function processScheduledTasks(currentDate) {
|
|
5463
5764
|
try {
|
|
5464
|
-
|
|
5765
|
+
import_node_server_utils34.logger.info("Starting scheduled task processing...");
|
|
5465
5766
|
const scheduleTasks = await getAllScheduleTask();
|
|
5466
5767
|
if (!scheduleTasks || scheduleTasks.length === 0) {
|
|
5467
|
-
|
|
5768
|
+
import_node_server_utils34.logger.info("No schedule tasks found to process");
|
|
5468
5769
|
return { processed: 0, validated: 0 };
|
|
5469
5770
|
}
|
|
5470
|
-
|
|
5771
|
+
import_node_server_utils34.logger.info(`Found ${scheduleTasks.length} schedule tasks to check`);
|
|
5471
5772
|
let processedCount = 0;
|
|
5472
5773
|
let validatedCount = 0;
|
|
5473
5774
|
const validatedTasks = [];
|
|
5474
5775
|
for (const scheduleTask of scheduleTasks) {
|
|
5475
5776
|
try {
|
|
5476
|
-
|
|
5777
|
+
import_node_server_utils34.logger.info(
|
|
5477
5778
|
`Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time}, startDate=${scheduleTask.startDate}, endDate=${scheduleTask.endDate}`
|
|
5478
5779
|
);
|
|
5479
5780
|
const shouldRun = checkScheduleConditions(scheduleTask, currentDate);
|
|
5480
5781
|
if (!shouldRun) {
|
|
5481
|
-
|
|
5782
|
+
import_node_server_utils34.logger.info(
|
|
5482
5783
|
`Schedule ${scheduleTask._id} conditions not met, skipping`
|
|
5483
5784
|
);
|
|
5484
5785
|
continue;
|
|
5485
5786
|
}
|
|
5486
|
-
|
|
5787
|
+
import_node_server_utils34.logger.info(
|
|
5487
5788
|
`Schedule ${scheduleTask._id} conditions validated, creating area checklists`
|
|
5488
5789
|
);
|
|
5489
5790
|
if (!scheduleTask._id) {
|
|
5490
|
-
|
|
5791
|
+
import_node_server_utils34.logger.warn(`Schedule ${scheduleTask.title} has no _id, skipping`);
|
|
5491
5792
|
continue;
|
|
5492
5793
|
}
|
|
5493
5794
|
if (!scheduleTask.site) {
|
|
5494
|
-
|
|
5795
|
+
import_node_server_utils34.logger.warn(`Schedule ${scheduleTask._id} has no site, skipping`);
|
|
5495
5796
|
continue;
|
|
5496
5797
|
}
|
|
5497
|
-
|
|
5798
|
+
import_node_server_utils34.logger.info(
|
|
5498
5799
|
`Getting or creating parent checklist for schedule ${scheduleTask._id} in site ${scheduleTask.site}`
|
|
5499
5800
|
);
|
|
5500
5801
|
const parentChecklistIds = await createParentChecklist({
|
|
@@ -5502,7 +5803,7 @@ function useScheduleTaskService() {
|
|
|
5502
5803
|
createdAt: /* @__PURE__ */ new Date()
|
|
5503
5804
|
});
|
|
5504
5805
|
const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
|
|
5505
|
-
|
|
5806
|
+
import_node_server_utils34.logger.info(
|
|
5506
5807
|
`Using parent checklist ${parentChecklistId}, now creating/updating area checklists`
|
|
5507
5808
|
);
|
|
5508
5809
|
for (const area of scheduleTask.areas) {
|
|
@@ -5515,14 +5816,14 @@ function useScheduleTaskService() {
|
|
|
5515
5816
|
unit: unit.unit.toString(),
|
|
5516
5817
|
name: unit.name
|
|
5517
5818
|
}));
|
|
5518
|
-
|
|
5819
|
+
import_node_server_utils34.logger.info(
|
|
5519
5820
|
`Area ${area.name} (${areaId}): Using units from area details: ${JSON.stringify(
|
|
5520
5821
|
units
|
|
5521
5822
|
)}`
|
|
5522
5823
|
);
|
|
5523
5824
|
}
|
|
5524
5825
|
if (units.length === 0) {
|
|
5525
|
-
|
|
5826
|
+
import_node_server_utils34.logger.warn(
|
|
5526
5827
|
`Area ${area.name} (${areaId}): No units found, skipping area.`
|
|
5527
5828
|
);
|
|
5528
5829
|
continue;
|
|
@@ -5533,11 +5834,11 @@ function useScheduleTaskService() {
|
|
|
5533
5834
|
parentChecklistId.toString(),
|
|
5534
5835
|
areaId
|
|
5535
5836
|
);
|
|
5536
|
-
|
|
5837
|
+
import_node_server_utils34.logger.info(
|
|
5537
5838
|
`Area ${area.name} (${areaId}): Existing area checklist found: ${existingAreaChecklist ? "Yes" : "No"}`
|
|
5538
5839
|
);
|
|
5539
5840
|
if (existingAreaChecklist) {
|
|
5540
|
-
|
|
5841
|
+
import_node_server_utils34.logger.info(
|
|
5541
5842
|
`Area ${area.name} (${areaId}): Existing checklist content: ${JSON.stringify(
|
|
5542
5843
|
existingAreaChecklist.checklist
|
|
5543
5844
|
)}`
|
|
@@ -5545,7 +5846,7 @@ function useScheduleTaskService() {
|
|
|
5545
5846
|
}
|
|
5546
5847
|
} catch (error) {
|
|
5547
5848
|
existingAreaChecklist = null;
|
|
5548
|
-
|
|
5849
|
+
import_node_server_utils34.logger.info(
|
|
5549
5850
|
`Area ${area.name} (${areaId}): No existing area checklist found (exception).`
|
|
5550
5851
|
);
|
|
5551
5852
|
}
|
|
@@ -5559,7 +5860,7 @@ function useScheduleTaskService() {
|
|
|
5559
5860
|
...existingAreaChecklist.checklist || [],
|
|
5560
5861
|
newSet
|
|
5561
5862
|
];
|
|
5562
|
-
|
|
5863
|
+
import_node_server_utils34.logger.info(
|
|
5563
5864
|
`Area ${area.name} (${areaId}): Appending new set ${newSet.set} to checklist. Updated checklist: ${JSON.stringify(
|
|
5564
5865
|
updatedChecklist
|
|
5565
5866
|
)}`
|
|
@@ -5567,7 +5868,7 @@ function useScheduleTaskService() {
|
|
|
5567
5868
|
await updateAreaChecklist(existingAreaChecklist._id, {
|
|
5568
5869
|
checklist: updatedChecklist
|
|
5569
5870
|
});
|
|
5570
|
-
|
|
5871
|
+
import_node_server_utils34.logger.info(
|
|
5571
5872
|
`Appended set ${newSet.set} to area checklist for area ${area.name}`
|
|
5572
5873
|
);
|
|
5573
5874
|
try {
|
|
@@ -5575,13 +5876,13 @@ function useScheduleTaskService() {
|
|
|
5575
5876
|
parentChecklistId.toString(),
|
|
5576
5877
|
areaId
|
|
5577
5878
|
);
|
|
5578
|
-
|
|
5879
|
+
import_node_server_utils34.logger.info(
|
|
5579
5880
|
`Area ${area.name} (${areaId}): Checklist after update: ${JSON.stringify(
|
|
5580
5881
|
verifyChecklist.checklist
|
|
5581
5882
|
)}`
|
|
5582
5883
|
);
|
|
5583
5884
|
} catch (verifyError) {
|
|
5584
|
-
|
|
5885
|
+
import_node_server_utils34.logger.warn(
|
|
5585
5886
|
`Area ${area.name} (${areaId}): Error verifying checklist after update:`,
|
|
5586
5887
|
verifyError
|
|
5587
5888
|
);
|
|
@@ -5600,50 +5901,50 @@ function useScheduleTaskService() {
|
|
|
5600
5901
|
],
|
|
5601
5902
|
createdBy: scheduleTask.createdBy
|
|
5602
5903
|
};
|
|
5603
|
-
|
|
5904
|
+
import_node_server_utils34.logger.info(
|
|
5604
5905
|
`Area ${area.name} (${areaId}): Creating new area checklist with data: ${JSON.stringify(
|
|
5605
5906
|
checklistData
|
|
5606
5907
|
)}`
|
|
5607
5908
|
);
|
|
5608
5909
|
await createAreaChecklist(checklistData);
|
|
5609
|
-
|
|
5910
|
+
import_node_server_utils34.logger.info(`Created new area checklist for area ${area.name}`);
|
|
5610
5911
|
try {
|
|
5611
5912
|
const verifyChecklist = await getAreaChecklistByAreaAndSchedule(
|
|
5612
5913
|
parentChecklistId.toString(),
|
|
5613
5914
|
areaId
|
|
5614
5915
|
);
|
|
5615
|
-
|
|
5916
|
+
import_node_server_utils34.logger.info(
|
|
5616
5917
|
`Area ${area.name} (${areaId}): Checklist after creation: ${JSON.stringify(
|
|
5617
5918
|
verifyChecklist.checklist
|
|
5618
5919
|
)}`
|
|
5619
5920
|
);
|
|
5620
5921
|
} catch (verifyError) {
|
|
5621
|
-
|
|
5922
|
+
import_node_server_utils34.logger.warn(
|
|
5622
5923
|
`Area ${area.name} (${areaId}): Error verifying checklist after creation:`,
|
|
5623
5924
|
verifyError
|
|
5624
5925
|
);
|
|
5625
5926
|
}
|
|
5626
5927
|
}
|
|
5627
5928
|
} catch (error) {
|
|
5628
|
-
|
|
5929
|
+
import_node_server_utils34.logger.error(`Error processing area ${area.name}:`, error);
|
|
5629
5930
|
continue;
|
|
5630
5931
|
}
|
|
5631
5932
|
}
|
|
5632
5933
|
processedCount++;
|
|
5633
5934
|
validatedCount++;
|
|
5634
5935
|
validatedTasks.push(scheduleTask);
|
|
5635
|
-
|
|
5936
|
+
import_node_server_utils34.logger.info(
|
|
5636
5937
|
`Successfully processed schedule ${scheduleTask._id}, created/updated area checklists for all areas.`
|
|
5637
5938
|
);
|
|
5638
5939
|
} catch (error) {
|
|
5639
|
-
|
|
5940
|
+
import_node_server_utils34.logger.error(
|
|
5640
5941
|
`Error processing schedule task ${scheduleTask._id}:`,
|
|
5641
5942
|
error
|
|
5642
5943
|
);
|
|
5643
5944
|
continue;
|
|
5644
5945
|
}
|
|
5645
5946
|
}
|
|
5646
|
-
|
|
5947
|
+
import_node_server_utils34.logger.info(
|
|
5647
5948
|
`Scheduled task processing completed. Processed: ${processedCount}, Validated: ${validatedCount} tasks`
|
|
5648
5949
|
);
|
|
5649
5950
|
return {
|
|
@@ -5652,7 +5953,7 @@ function useScheduleTaskService() {
|
|
|
5652
5953
|
tasks: validatedTasks
|
|
5653
5954
|
};
|
|
5654
5955
|
} catch (error) {
|
|
5655
|
-
|
|
5956
|
+
import_node_server_utils34.logger.error("Error processing scheduled tasks:", error);
|
|
5656
5957
|
throw error;
|
|
5657
5958
|
}
|
|
5658
5959
|
}
|
|
@@ -5661,7 +5962,7 @@ function useScheduleTaskService() {
|
|
|
5661
5962
|
|
|
5662
5963
|
// src/controllers/hygiene-schedule-task.controller.ts
|
|
5663
5964
|
var import_joi17 = __toESM(require("joi"));
|
|
5664
|
-
var
|
|
5965
|
+
var import_node_server_utils35 = require("@7365admin1/node-server-utils");
|
|
5665
5966
|
function useScheduleTaskController() {
|
|
5666
5967
|
const {
|
|
5667
5968
|
createScheduleTask: _createScheduleTask,
|
|
@@ -5679,8 +5980,8 @@ function useScheduleTaskController() {
|
|
|
5679
5980
|
const payload = { ...req.body, ...req.params, createdBy };
|
|
5680
5981
|
const { error } = scheduleTaskSchema.validate(payload);
|
|
5681
5982
|
if (error) {
|
|
5682
|
-
|
|
5683
|
-
next(new
|
|
5983
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
5984
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5684
5985
|
return;
|
|
5685
5986
|
}
|
|
5686
5987
|
try {
|
|
@@ -5688,7 +5989,7 @@ function useScheduleTaskController() {
|
|
|
5688
5989
|
res.status(201).json({ message: "Schedule task created successfully.", id });
|
|
5689
5990
|
return;
|
|
5690
5991
|
} catch (error2) {
|
|
5691
|
-
|
|
5992
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5692
5993
|
next(error2);
|
|
5693
5994
|
return;
|
|
5694
5995
|
}
|
|
@@ -5703,8 +6004,8 @@ function useScheduleTaskController() {
|
|
|
5703
6004
|
});
|
|
5704
6005
|
const { error } = validation.validate(query);
|
|
5705
6006
|
if (error) {
|
|
5706
|
-
|
|
5707
|
-
next(new
|
|
6007
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6008
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5708
6009
|
return;
|
|
5709
6010
|
}
|
|
5710
6011
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -5721,7 +6022,7 @@ function useScheduleTaskController() {
|
|
|
5721
6022
|
res.json(data);
|
|
5722
6023
|
return;
|
|
5723
6024
|
} catch (error2) {
|
|
5724
|
-
|
|
6025
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5725
6026
|
next(error2);
|
|
5726
6027
|
return;
|
|
5727
6028
|
}
|
|
@@ -5736,8 +6037,8 @@ function useScheduleTaskController() {
|
|
|
5736
6037
|
});
|
|
5737
6038
|
const { error } = validation.validate(query);
|
|
5738
6039
|
if (error) {
|
|
5739
|
-
|
|
5740
|
-
next(new
|
|
6040
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6041
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5741
6042
|
return;
|
|
5742
6043
|
}
|
|
5743
6044
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -5754,7 +6055,7 @@ function useScheduleTaskController() {
|
|
|
5754
6055
|
res.json(data);
|
|
5755
6056
|
return;
|
|
5756
6057
|
} catch (error2) {
|
|
5757
|
-
|
|
6058
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5758
6059
|
next(error2);
|
|
5759
6060
|
return;
|
|
5760
6061
|
}
|
|
@@ -5764,8 +6065,8 @@ function useScheduleTaskController() {
|
|
|
5764
6065
|
const _id = req.params.id;
|
|
5765
6066
|
const { error, value } = validation.validate(_id);
|
|
5766
6067
|
if (error) {
|
|
5767
|
-
|
|
5768
|
-
next(new
|
|
6068
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6069
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5769
6070
|
return;
|
|
5770
6071
|
}
|
|
5771
6072
|
try {
|
|
@@ -5773,7 +6074,7 @@ function useScheduleTaskController() {
|
|
|
5773
6074
|
res.json(data);
|
|
5774
6075
|
return;
|
|
5775
6076
|
} catch (error2) {
|
|
5776
|
-
|
|
6077
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5777
6078
|
next(error2);
|
|
5778
6079
|
return;
|
|
5779
6080
|
}
|
|
@@ -5796,8 +6097,8 @@ function useScheduleTaskController() {
|
|
|
5796
6097
|
});
|
|
5797
6098
|
const { error } = validation.validate(payload);
|
|
5798
6099
|
if (error) {
|
|
5799
|
-
|
|
5800
|
-
next(new
|
|
6100
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6101
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
5801
6102
|
return;
|
|
5802
6103
|
}
|
|
5803
6104
|
try {
|
|
@@ -5806,7 +6107,7 @@ function useScheduleTaskController() {
|
|
|
5806
6107
|
res.json({ message: "Schedule task updated successfully." });
|
|
5807
6108
|
return;
|
|
5808
6109
|
} catch (error2) {
|
|
5809
|
-
|
|
6110
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
5810
6111
|
next(error2);
|
|
5811
6112
|
return;
|
|
5812
6113
|
}
|
|
@@ -5821,8 +6122,8 @@ function useScheduleTaskController() {
|
|
|
5821
6122
|
}
|
|
5822
6123
|
|
|
5823
6124
|
// src/services/hygiene-qr.service.ts
|
|
5824
|
-
var
|
|
5825
|
-
var
|
|
6125
|
+
var import_node_server_utils36 = require("@7365admin1/node-server-utils");
|
|
6126
|
+
var import_puppeteer2 = require("puppeteer");
|
|
5826
6127
|
var import_qrcode = __toESM(require("qrcode"));
|
|
5827
6128
|
function useQRService() {
|
|
5828
6129
|
async function generateQRDataUrl(qrUrl) {
|
|
@@ -5839,7 +6140,7 @@ function useQRService() {
|
|
|
5839
6140
|
async function generateQRImage(qrUrl) {
|
|
5840
6141
|
try {
|
|
5841
6142
|
const qrDataUrl = await generateQRDataUrl(qrUrl);
|
|
5842
|
-
const browser = await (0,
|
|
6143
|
+
const browser = await (0, import_puppeteer2.launch)({
|
|
5843
6144
|
headless: true,
|
|
5844
6145
|
executablePath: process.env.CHROME_BINARY,
|
|
5845
6146
|
args: [`--no-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`]
|
|
@@ -5892,7 +6193,7 @@ function useQRService() {
|
|
|
5892
6193
|
await browser.close();
|
|
5893
6194
|
return imageBuffer;
|
|
5894
6195
|
} catch (error) {
|
|
5895
|
-
|
|
6196
|
+
import_node_server_utils36.logger.log({
|
|
5896
6197
|
level: "error",
|
|
5897
6198
|
message: `Failed to generate QR image: ${error.message}`
|
|
5898
6199
|
});
|
|
@@ -5902,7 +6203,7 @@ function useQRService() {
|
|
|
5902
6203
|
async function generateQRPDF(qrUrl, title) {
|
|
5903
6204
|
try {
|
|
5904
6205
|
const qrDataUrl = await generateQRDataUrl(qrUrl);
|
|
5905
|
-
const browser = await (0,
|
|
6206
|
+
const browser = await (0, import_puppeteer2.launch)({
|
|
5906
6207
|
headless: true,
|
|
5907
6208
|
executablePath: process.env.CHROME_BINARY,
|
|
5908
6209
|
args: [`--no-sandbox`, `--disable-gpu`, `--disable-dev-shm-usage`]
|
|
@@ -6015,7 +6316,7 @@ function useQRService() {
|
|
|
6015
6316
|
await browser.close();
|
|
6016
6317
|
return pdfBuffer;
|
|
6017
6318
|
} catch (error) {
|
|
6018
|
-
|
|
6319
|
+
import_node_server_utils36.logger.log({
|
|
6019
6320
|
level: "error",
|
|
6020
6321
|
message: `Failed to generate QR PDF: ${error.message}`
|
|
6021
6322
|
});
|
|
@@ -6030,7 +6331,7 @@ function useQRService() {
|
|
|
6030
6331
|
|
|
6031
6332
|
// src/controllers/hygiene-qr.controller.ts
|
|
6032
6333
|
var import_joi18 = __toESM(require("joi"));
|
|
6033
|
-
var
|
|
6334
|
+
var import_node_server_utils37 = require("@7365admin1/node-server-utils");
|
|
6034
6335
|
function useQRController() {
|
|
6035
6336
|
const { generateQRImage: _generateQRImage, generateQRPDF: _generateQRPDF } = useQRService();
|
|
6036
6337
|
async function generateQR(req, res, next) {
|
|
@@ -6043,8 +6344,8 @@ function useQRController() {
|
|
|
6043
6344
|
const query = { ...req.query };
|
|
6044
6345
|
const { error, value } = validation.validate(query);
|
|
6045
6346
|
if (error) {
|
|
6046
|
-
|
|
6047
|
-
next(new
|
|
6347
|
+
import_node_server_utils37.logger.log({ level: "error", message: error.message });
|
|
6348
|
+
next(new import_node_server_utils37.BadRequestError(error.message));
|
|
6048
6349
|
return;
|
|
6049
6350
|
}
|
|
6050
6351
|
try {
|
|
@@ -6079,7 +6380,7 @@ function useQRController() {
|
|
|
6079
6380
|
}
|
|
6080
6381
|
return;
|
|
6081
6382
|
} catch (error2) {
|
|
6082
|
-
|
|
6383
|
+
import_node_server_utils37.logger.log({ level: "error", message: error2.message });
|
|
6083
6384
|
next(error2);
|
|
6084
6385
|
return;
|
|
6085
6386
|
}
|