@7365admin1/module-hygiene 4.25.0 → 4.27.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.js +39 -50
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +39 -50
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -2505,6 +2505,7 @@ function MParentChecklist(value) {
|
|
|
2505
2505
|
|
|
2506
2506
|
// src/repositories/hygiene-parent-checklist.repository.ts
|
|
2507
2507
|
import { ObjectId as ObjectId7 } from "mongodb";
|
|
2508
|
+
import moment2 from "moment-timezone";
|
|
2508
2509
|
import {
|
|
2509
2510
|
useAtlas as useAtlas5,
|
|
2510
2511
|
InternalServerError as InternalServerError4,
|
|
@@ -2807,19 +2808,28 @@ function useParentChecklistRepo() {
|
|
|
2807
2808
|
query.$text = { $search: search };
|
|
2808
2809
|
cacheOptions.search = search;
|
|
2809
2810
|
}
|
|
2811
|
+
const singaporeTz = "Asia/Singapore";
|
|
2812
|
+
const normalizedStartDate = typeof startDate === "string" ? startDate : moment2(startDate).tz(singaporeTz).format("YYYY-MM-DD");
|
|
2813
|
+
const normalizedEndDate = typeof endDate === "string" ? endDate : moment2(endDate).tz(singaporeTz).format("YYYY-MM-DD");
|
|
2810
2814
|
if (startDate && endDate) {
|
|
2815
|
+
const startOfDay = moment2.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate();
|
|
2816
|
+
const endOfDay = moment2.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate();
|
|
2811
2817
|
query.createdAt = {
|
|
2812
|
-
$gte:
|
|
2813
|
-
$lte:
|
|
2818
|
+
$gte: startOfDay,
|
|
2819
|
+
$lte: endOfDay
|
|
2814
2820
|
};
|
|
2815
|
-
cacheOptions.startDate =
|
|
2816
|
-
cacheOptions.endDate =
|
|
2821
|
+
cacheOptions.startDate = normalizedStartDate;
|
|
2822
|
+
cacheOptions.endDate = normalizedEndDate;
|
|
2817
2823
|
} else if (startDate) {
|
|
2818
|
-
query.createdAt = {
|
|
2819
|
-
|
|
2824
|
+
query.createdAt = {
|
|
2825
|
+
$gte: moment2.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate()
|
|
2826
|
+
};
|
|
2827
|
+
cacheOptions.startDate = normalizedStartDate;
|
|
2820
2828
|
} else if (endDate) {
|
|
2821
|
-
query.createdAt = {
|
|
2822
|
-
|
|
2829
|
+
query.createdAt = {
|
|
2830
|
+
$lte: moment2.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate()
|
|
2831
|
+
};
|
|
2832
|
+
cacheOptions.endDate = normalizedEndDate;
|
|
2823
2833
|
}
|
|
2824
2834
|
if (status && status !== "all") {
|
|
2825
2835
|
query.status = status;
|
|
@@ -3235,6 +3245,14 @@ function useAreaChecklistRepo() {
|
|
|
3235
3245
|
const namespace_collection = "site.cleaning.schedule.areas";
|
|
3236
3246
|
const collection = db.collection(namespace_collection);
|
|
3237
3247
|
const { delNamespace, setCache, getCache } = useCache5(namespace_collection);
|
|
3248
|
+
async function invalidateNamespaceCache(context) {
|
|
3249
|
+
try {
|
|
3250
|
+
await delNamespace();
|
|
3251
|
+
logger17.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
3252
|
+
} catch (err) {
|
|
3253
|
+
logger17.error(`Failed to clear cache for ${context}`, err);
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3238
3256
|
async function createIndex() {
|
|
3239
3257
|
try {
|
|
3240
3258
|
await collection.createIndexes([
|
|
@@ -3289,14 +3307,7 @@ function useAreaChecklistRepo() {
|
|
|
3289
3307
|
}
|
|
3290
3308
|
const processedValue = MAreaChecklist(value);
|
|
3291
3309
|
const result = await collection.insertOne(processedValue, { session });
|
|
3292
|
-
|
|
3293
|
-
logger17.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
3294
|
-
}).catch((err) => {
|
|
3295
|
-
logger17.error(
|
|
3296
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
3297
|
-
err
|
|
3298
|
-
);
|
|
3299
|
-
});
|
|
3310
|
+
await invalidateNamespaceCache("area checklist create");
|
|
3300
3311
|
return result.insertedId;
|
|
3301
3312
|
} catch (error) {
|
|
3302
3313
|
if (error?.code === 11e3) {
|
|
@@ -4033,14 +4044,7 @@ function useAreaChecklistRepo() {
|
|
|
4033
4044
|
if (res.modifiedCount === 0) {
|
|
4034
4045
|
throw new InternalServerError5("Unable to update area checklist unit.");
|
|
4035
4046
|
}
|
|
4036
|
-
|
|
4037
|
-
logger17.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4038
|
-
}).catch((err) => {
|
|
4039
|
-
logger17.error(
|
|
4040
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4041
|
-
err
|
|
4042
|
-
);
|
|
4043
|
-
});
|
|
4047
|
+
await invalidateNamespaceCache("area checklist unit update");
|
|
4044
4048
|
return res.modifiedCount;
|
|
4045
4049
|
} catch (error) {
|
|
4046
4050
|
logger17.error("Error updating area checklist unit:", error.message);
|
|
@@ -4066,14 +4070,7 @@ function useAreaChecklistRepo() {
|
|
|
4066
4070
|
if (res.modifiedCount === 0) {
|
|
4067
4071
|
throw new InternalServerError5("Unable to update area checklist.");
|
|
4068
4072
|
}
|
|
4069
|
-
|
|
4070
|
-
logger17.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4071
|
-
}).catch((err) => {
|
|
4072
|
-
logger17.error(
|
|
4073
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4074
|
-
err
|
|
4075
|
-
);
|
|
4076
|
-
});
|
|
4073
|
+
await invalidateNamespaceCache("area checklist update");
|
|
4077
4074
|
return res.modifiedCount;
|
|
4078
4075
|
} catch (error) {
|
|
4079
4076
|
throw error;
|
|
@@ -4103,14 +4100,7 @@ function useAreaChecklistRepo() {
|
|
|
4103
4100
|
"Unable to update area checklist status."
|
|
4104
4101
|
);
|
|
4105
4102
|
}
|
|
4106
|
-
|
|
4107
|
-
logger17.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4108
|
-
}).catch((err) => {
|
|
4109
|
-
logger17.error(
|
|
4110
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4111
|
-
err
|
|
4112
|
-
);
|
|
4113
|
-
});
|
|
4103
|
+
await invalidateNamespaceCache("area checklist status update");
|
|
4114
4104
|
return res.modifiedCount;
|
|
4115
4105
|
} catch (error) {
|
|
4116
4106
|
throw error;
|
|
@@ -4523,16 +4513,14 @@ function useAreaChecklistService() {
|
|
|
4523
4513
|
if (allUnitsResult && allUnitsResult.items && allUnitsResult.items.length > 0) {
|
|
4524
4514
|
const sets = allUnitsResult.items;
|
|
4525
4515
|
const allUnits = sets.flatMap((set2) => set2.units || []);
|
|
4526
|
-
const openCount = allUnits.filter(
|
|
4527
|
-
(unit) => unit.status === "Open"
|
|
4528
|
-
).length;
|
|
4529
|
-
const completedCount = allUnits.filter(
|
|
4530
|
-
(unit) => unit.status === "Completed"
|
|
4531
|
-
).length;
|
|
4532
4516
|
const totalCount = allUnits.length;
|
|
4533
|
-
|
|
4517
|
+
const actionedCount = allUnits.filter((unit) => {
|
|
4518
|
+
const status = String(unit.status ?? "").toLowerCase();
|
|
4519
|
+
return unit.approve === true || unit.reject === true || status === "completed" || status === "closed";
|
|
4520
|
+
}).length;
|
|
4521
|
+
if (totalCount > 0 && actionedCount === totalCount) {
|
|
4534
4522
|
areaStatus = "completed";
|
|
4535
|
-
} else if (
|
|
4523
|
+
} else if (actionedCount === 0) {
|
|
4536
4524
|
areaStatus = "open";
|
|
4537
4525
|
} else {
|
|
4538
4526
|
areaStatus = "ongoing";
|
|
@@ -4551,11 +4539,12 @@ function useAreaChecklistService() {
|
|
|
4551
4539
|
);
|
|
4552
4540
|
if (allAreasResult && allAreasResult.items && allAreasResult.items.length > 0) {
|
|
4553
4541
|
const areas = allAreasResult.items;
|
|
4542
|
+
const normalizeStatus = (status) => String(status ?? "").toLowerCase();
|
|
4554
4543
|
const openAreasCount = areas.filter(
|
|
4555
|
-
(area) => area.status === "
|
|
4544
|
+
(area) => normalizeStatus(area.status) === "open"
|
|
4556
4545
|
).length;
|
|
4557
4546
|
const completedAreasCount = areas.filter(
|
|
4558
|
-
(area) => area.status === "
|
|
4547
|
+
(area) => normalizeStatus(area.status) === "completed"
|
|
4559
4548
|
).length;
|
|
4560
4549
|
const totalAreasCount = areas.length;
|
|
4561
4550
|
let parentStatus = "open";
|