@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/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -2555,6 +2555,7 @@ function MParentChecklist(value) {
|
|
|
2555
2555
|
|
|
2556
2556
|
// src/repositories/hygiene-parent-checklist.repository.ts
|
|
2557
2557
|
var import_mongodb7 = require("mongodb");
|
|
2558
|
+
var import_moment_timezone2 = __toESM(require("moment-timezone"));
|
|
2558
2559
|
var import_node_server_utils14 = require("@7365admin1/node-server-utils");
|
|
2559
2560
|
var import_core7 = require("@7365admin1/core");
|
|
2560
2561
|
function useParentChecklistRepo() {
|
|
@@ -2849,19 +2850,28 @@ function useParentChecklistRepo() {
|
|
|
2849
2850
|
query.$text = { $search: search };
|
|
2850
2851
|
cacheOptions.search = search;
|
|
2851
2852
|
}
|
|
2853
|
+
const singaporeTz = "Asia/Singapore";
|
|
2854
|
+
const normalizedStartDate = typeof startDate === "string" ? startDate : (0, import_moment_timezone2.default)(startDate).tz(singaporeTz).format("YYYY-MM-DD");
|
|
2855
|
+
const normalizedEndDate = typeof endDate === "string" ? endDate : (0, import_moment_timezone2.default)(endDate).tz(singaporeTz).format("YYYY-MM-DD");
|
|
2852
2856
|
if (startDate && endDate) {
|
|
2857
|
+
const startOfDay = import_moment_timezone2.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate();
|
|
2858
|
+
const endOfDay = import_moment_timezone2.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate();
|
|
2853
2859
|
query.createdAt = {
|
|
2854
|
-
$gte:
|
|
2855
|
-
$lte:
|
|
2860
|
+
$gte: startOfDay,
|
|
2861
|
+
$lte: endOfDay
|
|
2856
2862
|
};
|
|
2857
|
-
cacheOptions.startDate =
|
|
2858
|
-
cacheOptions.endDate =
|
|
2863
|
+
cacheOptions.startDate = normalizedStartDate;
|
|
2864
|
+
cacheOptions.endDate = normalizedEndDate;
|
|
2859
2865
|
} else if (startDate) {
|
|
2860
|
-
query.createdAt = {
|
|
2861
|
-
|
|
2866
|
+
query.createdAt = {
|
|
2867
|
+
$gte: import_moment_timezone2.default.tz(normalizedStartDate, "YYYY-MM-DD", singaporeTz).startOf("day").toDate()
|
|
2868
|
+
};
|
|
2869
|
+
cacheOptions.startDate = normalizedStartDate;
|
|
2862
2870
|
} else if (endDate) {
|
|
2863
|
-
query.createdAt = {
|
|
2864
|
-
|
|
2871
|
+
query.createdAt = {
|
|
2872
|
+
$lte: import_moment_timezone2.default.tz(normalizedEndDate, "YYYY-MM-DD", singaporeTz).endOf("day").toDate()
|
|
2873
|
+
};
|
|
2874
|
+
cacheOptions.endDate = normalizedEndDate;
|
|
2865
2875
|
}
|
|
2866
2876
|
if (status && status !== "all") {
|
|
2867
2877
|
query.status = status;
|
|
@@ -3265,6 +3275,14 @@ function useAreaChecklistRepo() {
|
|
|
3265
3275
|
const namespace_collection = "site.cleaning.schedule.areas";
|
|
3266
3276
|
const collection = db.collection(namespace_collection);
|
|
3267
3277
|
const { delNamespace, setCache, getCache } = (0, import_node_server_utils17.useCache)(namespace_collection);
|
|
3278
|
+
async function invalidateNamespaceCache(context) {
|
|
3279
|
+
try {
|
|
3280
|
+
await delNamespace();
|
|
3281
|
+
import_node_server_utils17.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
3282
|
+
} catch (err) {
|
|
3283
|
+
import_node_server_utils17.logger.error(`Failed to clear cache for ${context}`, err);
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
3268
3286
|
async function createIndex() {
|
|
3269
3287
|
try {
|
|
3270
3288
|
await collection.createIndexes([
|
|
@@ -3319,14 +3337,7 @@ function useAreaChecklistRepo() {
|
|
|
3319
3337
|
}
|
|
3320
3338
|
const processedValue = MAreaChecklist(value);
|
|
3321
3339
|
const result = await collection.insertOne(processedValue, { session });
|
|
3322
|
-
|
|
3323
|
-
import_node_server_utils17.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
3324
|
-
}).catch((err) => {
|
|
3325
|
-
import_node_server_utils17.logger.error(
|
|
3326
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
3327
|
-
err
|
|
3328
|
-
);
|
|
3329
|
-
});
|
|
3340
|
+
await invalidateNamespaceCache("area checklist create");
|
|
3330
3341
|
return result.insertedId;
|
|
3331
3342
|
} catch (error) {
|
|
3332
3343
|
if (error?.code === 11e3) {
|
|
@@ -4063,14 +4074,7 @@ function useAreaChecklistRepo() {
|
|
|
4063
4074
|
if (res.modifiedCount === 0) {
|
|
4064
4075
|
throw new import_node_server_utils17.InternalServerError("Unable to update area checklist unit.");
|
|
4065
4076
|
}
|
|
4066
|
-
|
|
4067
|
-
import_node_server_utils17.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4068
|
-
}).catch((err) => {
|
|
4069
|
-
import_node_server_utils17.logger.error(
|
|
4070
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4071
|
-
err
|
|
4072
|
-
);
|
|
4073
|
-
});
|
|
4077
|
+
await invalidateNamespaceCache("area checklist unit update");
|
|
4074
4078
|
return res.modifiedCount;
|
|
4075
4079
|
} catch (error) {
|
|
4076
4080
|
import_node_server_utils17.logger.error("Error updating area checklist unit:", error.message);
|
|
@@ -4096,14 +4100,7 @@ function useAreaChecklistRepo() {
|
|
|
4096
4100
|
if (res.modifiedCount === 0) {
|
|
4097
4101
|
throw new import_node_server_utils17.InternalServerError("Unable to update area checklist.");
|
|
4098
4102
|
}
|
|
4099
|
-
|
|
4100
|
-
import_node_server_utils17.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4101
|
-
}).catch((err) => {
|
|
4102
|
-
import_node_server_utils17.logger.error(
|
|
4103
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4104
|
-
err
|
|
4105
|
-
);
|
|
4106
|
-
});
|
|
4103
|
+
await invalidateNamespaceCache("area checklist update");
|
|
4107
4104
|
return res.modifiedCount;
|
|
4108
4105
|
} catch (error) {
|
|
4109
4106
|
throw error;
|
|
@@ -4133,14 +4130,7 @@ function useAreaChecklistRepo() {
|
|
|
4133
4130
|
"Unable to update area checklist status."
|
|
4134
4131
|
);
|
|
4135
4132
|
}
|
|
4136
|
-
|
|
4137
|
-
import_node_server_utils17.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4138
|
-
}).catch((err) => {
|
|
4139
|
-
import_node_server_utils17.logger.error(
|
|
4140
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4141
|
-
err
|
|
4142
|
-
);
|
|
4143
|
-
});
|
|
4133
|
+
await invalidateNamespaceCache("area checklist status update");
|
|
4144
4134
|
return res.modifiedCount;
|
|
4145
4135
|
} catch (error) {
|
|
4146
4136
|
throw error;
|
|
@@ -4553,16 +4543,14 @@ function useAreaChecklistService() {
|
|
|
4553
4543
|
if (allUnitsResult && allUnitsResult.items && allUnitsResult.items.length > 0) {
|
|
4554
4544
|
const sets = allUnitsResult.items;
|
|
4555
4545
|
const allUnits = sets.flatMap((set2) => set2.units || []);
|
|
4556
|
-
const openCount = allUnits.filter(
|
|
4557
|
-
(unit) => unit.status === "Open"
|
|
4558
|
-
).length;
|
|
4559
|
-
const completedCount = allUnits.filter(
|
|
4560
|
-
(unit) => unit.status === "Completed"
|
|
4561
|
-
).length;
|
|
4562
4546
|
const totalCount = allUnits.length;
|
|
4563
|
-
|
|
4547
|
+
const actionedCount = allUnits.filter((unit) => {
|
|
4548
|
+
const status = String(unit.status ?? "").toLowerCase();
|
|
4549
|
+
return unit.approve === true || unit.reject === true || status === "completed" || status === "closed";
|
|
4550
|
+
}).length;
|
|
4551
|
+
if (totalCount > 0 && actionedCount === totalCount) {
|
|
4564
4552
|
areaStatus = "completed";
|
|
4565
|
-
} else if (
|
|
4553
|
+
} else if (actionedCount === 0) {
|
|
4566
4554
|
areaStatus = "open";
|
|
4567
4555
|
} else {
|
|
4568
4556
|
areaStatus = "ongoing";
|
|
@@ -4581,11 +4569,12 @@ function useAreaChecklistService() {
|
|
|
4581
4569
|
);
|
|
4582
4570
|
if (allAreasResult && allAreasResult.items && allAreasResult.items.length > 0) {
|
|
4583
4571
|
const areas = allAreasResult.items;
|
|
4572
|
+
const normalizeStatus = (status) => String(status ?? "").toLowerCase();
|
|
4584
4573
|
const openAreasCount = areas.filter(
|
|
4585
|
-
(area) => area.status === "
|
|
4574
|
+
(area) => normalizeStatus(area.status) === "open"
|
|
4586
4575
|
).length;
|
|
4587
4576
|
const completedAreasCount = areas.filter(
|
|
4588
|
-
(area) => area.status === "
|
|
4577
|
+
(area) => normalizeStatus(area.status) === "completed"
|
|
4589
4578
|
).length;
|
|
4590
4579
|
const totalAreasCount = areas.length;
|
|
4591
4580
|
let parentStatus = "open";
|