@7365admin1/module-hygiene 4.2.0 → 4.4.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 +6 -74
- package/dist/index.js +313 -901
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +320 -911
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -34,7 +34,6 @@ __export(src_exports, {
|
|
|
34
34
|
MAreaChecklist: () => MAreaChecklist,
|
|
35
35
|
MCheckOutItem: () => MCheckOutItem,
|
|
36
36
|
MParentChecklist: () => MParentChecklist,
|
|
37
|
-
MRequestItem: () => MRequestItem,
|
|
38
37
|
MScheduleTask: () => MScheduleTask,
|
|
39
38
|
MStock: () => MStock,
|
|
40
39
|
MSupply: () => MSupply,
|
|
@@ -42,14 +41,12 @@ __export(src_exports, {
|
|
|
42
41
|
allowedCheckOutItemStatus: () => allowedCheckOutItemStatus,
|
|
43
42
|
allowedChecklistStatus: () => allowedChecklistStatus,
|
|
44
43
|
allowedPeriods: () => allowedPeriods,
|
|
45
|
-
allowedRequestItemStatus: () => allowedRequestItemStatus,
|
|
46
44
|
allowedStatus: () => allowedStatus,
|
|
47
45
|
allowedTypes: () => allowedTypes,
|
|
48
46
|
areaChecklistSchema: () => areaChecklistSchema,
|
|
49
47
|
areaSchema: () => areaSchema,
|
|
50
48
|
checkOutItemSchema: () => checkOutItemSchema,
|
|
51
49
|
parentChecklistSchema: () => parentChecklistSchema,
|
|
52
|
-
requestItemSchema: () => requestItemSchema,
|
|
53
50
|
scheduleTaskSchema: () => scheduleTaskSchema,
|
|
54
51
|
stockSchema: () => stockSchema,
|
|
55
52
|
supplySchema: () => supplySchema,
|
|
@@ -67,9 +64,6 @@ __export(src_exports, {
|
|
|
67
64
|
useHygieneDashboardRepository: () => useHygieneDashboardRepository,
|
|
68
65
|
useParentChecklistController: () => useParentChecklistController,
|
|
69
66
|
useParentChecklistRepo: () => useParentChecklistRepo,
|
|
70
|
-
useRequestItemController: () => useRequestItemController,
|
|
71
|
-
useRequestItemRepository: () => useRequestItemRepository,
|
|
72
|
-
useRequestItemService: () => useRequestItemService,
|
|
73
67
|
useScheduleTaskController: () => useScheduleTaskController,
|
|
74
68
|
useScheduleTaskRepository: () => useScheduleTaskRepository,
|
|
75
69
|
useScheduleTaskService: () => useScheduleTaskService,
|
|
@@ -1128,6 +1122,11 @@ function useAreaService() {
|
|
|
1128
1122
|
skippedRows.push(i + 1);
|
|
1129
1123
|
continue;
|
|
1130
1124
|
}
|
|
1125
|
+
if (areaName.startsWith("Sample:")) {
|
|
1126
|
+
import_node_server_utils5.logger.warn(`Skipping row ${i + 1} with sample area: ${areaName}`);
|
|
1127
|
+
skippedRows.push(i + 1);
|
|
1128
|
+
continue;
|
|
1129
|
+
}
|
|
1131
1130
|
try {
|
|
1132
1131
|
const insertedId = await _createArea({
|
|
1133
1132
|
type: areaType,
|
|
@@ -1659,6 +1658,11 @@ function useUnitService() {
|
|
|
1659
1658
|
skippedRows.push(i + 1);
|
|
1660
1659
|
continue;
|
|
1661
1660
|
}
|
|
1661
|
+
if (unitName.startsWith("Sample:")) {
|
|
1662
|
+
import_node_server_utils9.logger.warn(`Skipping row ${i + 1} with sample unit: ${unitName}`);
|
|
1663
|
+
skippedRows.push(i + 1);
|
|
1664
|
+
continue;
|
|
1665
|
+
}
|
|
1662
1666
|
try {
|
|
1663
1667
|
const insertedId = await _createUnit({
|
|
1664
1668
|
name: unitName,
|
|
@@ -4246,27 +4250,24 @@ function useStockController() {
|
|
|
4246
4250
|
};
|
|
4247
4251
|
}
|
|
4248
4252
|
|
|
4249
|
-
// src/models/hygiene-
|
|
4253
|
+
// src/models/hygiene-checkout-item.model.ts
|
|
4250
4254
|
var import_joi14 = __toESM(require("joi"));
|
|
4251
4255
|
var import_mongodb14 = require("mongodb");
|
|
4252
4256
|
var import_node_server_utils25 = require("@7365admin1/node-server-utils");
|
|
4253
|
-
var
|
|
4254
|
-
|
|
4255
|
-
"approved",
|
|
4256
|
-
"disapproved"
|
|
4257
|
-
];
|
|
4258
|
-
var requestItemSchema = import_joi14.default.object({
|
|
4257
|
+
var allowedCheckOutItemStatus = ["pending", "completed"];
|
|
4258
|
+
var checkOutItemSchema = import_joi14.default.object({
|
|
4259
4259
|
site: import_joi14.default.string().hex().required(),
|
|
4260
4260
|
supply: import_joi14.default.string().hex().required(),
|
|
4261
4261
|
supplyName: import_joi14.default.string().required(),
|
|
4262
4262
|
qty: import_joi14.default.number().min(0).required(),
|
|
4263
|
+
attachment: import_joi14.default.array().items(import_joi14.default.string()).optional().allow(null),
|
|
4263
4264
|
createdBy: import_joi14.default.string().hex().required(),
|
|
4264
4265
|
createdByName: import_joi14.default.string().required()
|
|
4265
4266
|
});
|
|
4266
|
-
function
|
|
4267
|
-
const { error } =
|
|
4267
|
+
function MCheckOutItem(value) {
|
|
4268
|
+
const { error } = checkOutItemSchema.validate(value);
|
|
4268
4269
|
if (error) {
|
|
4269
|
-
import_node_server_utils25.logger.info(`Hygiene
|
|
4270
|
+
import_node_server_utils25.logger.info(`Hygiene Check Out Item Model: ${error.message}`);
|
|
4270
4271
|
throw new import_node_server_utils25.BadRequestError(error.message);
|
|
4271
4272
|
}
|
|
4272
4273
|
if (value.site) {
|
|
@@ -4288,7 +4289,7 @@ function MRequestItem(value) {
|
|
|
4288
4289
|
supply: value.supply,
|
|
4289
4290
|
supplyName: value.supplyName,
|
|
4290
4291
|
qty: value.qty,
|
|
4291
|
-
|
|
4292
|
+
attachment: value.attachment || [],
|
|
4292
4293
|
createdBy: value.createdBy,
|
|
4293
4294
|
createdByName: value.createdByName,
|
|
4294
4295
|
status: "pending",
|
|
@@ -4298,15 +4299,15 @@ function MRequestItem(value) {
|
|
|
4298
4299
|
};
|
|
4299
4300
|
}
|
|
4300
4301
|
|
|
4301
|
-
// src/repositories/hygiene-
|
|
4302
|
+
// src/repositories/hygiene-checkout-item.repository.ts
|
|
4302
4303
|
var import_mongodb15 = require("mongodb");
|
|
4303
4304
|
var import_node_server_utils26 = require("@7365admin1/node-server-utils");
|
|
4304
|
-
function
|
|
4305
|
+
function useCheckOutItemRepository() {
|
|
4305
4306
|
const db = import_node_server_utils26.useAtlas.getDb();
|
|
4306
4307
|
if (!db) {
|
|
4307
4308
|
throw new import_node_server_utils26.InternalServerError("Unable to connect to server.");
|
|
4308
4309
|
}
|
|
4309
|
-
const namespace_collection = "site.supply.
|
|
4310
|
+
const namespace_collection = "site.supply.checkouts";
|
|
4310
4311
|
const collection = db.collection(namespace_collection);
|
|
4311
4312
|
const { delNamespace, setCache, getCache } = (0, import_node_server_utils26.useCache)(namespace_collection);
|
|
4312
4313
|
async function createIndex() {
|
|
@@ -4318,7 +4319,7 @@ function useRequestItemRepository() {
|
|
|
4318
4319
|
]);
|
|
4319
4320
|
} catch (error) {
|
|
4320
4321
|
throw new import_node_server_utils26.InternalServerError(
|
|
4321
|
-
"Failed to create index on hygiene
|
|
4322
|
+
"Failed to create index on hygiene check out item."
|
|
4322
4323
|
);
|
|
4323
4324
|
}
|
|
4324
4325
|
}
|
|
@@ -4331,9 +4332,9 @@ function useRequestItemRepository() {
|
|
|
4331
4332
|
);
|
|
4332
4333
|
}
|
|
4333
4334
|
}
|
|
4334
|
-
async function
|
|
4335
|
+
async function createCheckOutItem(value, session) {
|
|
4335
4336
|
try {
|
|
4336
|
-
value =
|
|
4337
|
+
value = MCheckOutItem(value);
|
|
4337
4338
|
const res = await collection.insertOne(value, { session });
|
|
4338
4339
|
delNamespace().then(() => {
|
|
4339
4340
|
import_node_server_utils26.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
@@ -4348,7 +4349,7 @@ function useRequestItemRepository() {
|
|
|
4348
4349
|
throw error;
|
|
4349
4350
|
}
|
|
4350
4351
|
}
|
|
4351
|
-
async function
|
|
4352
|
+
async function getCheckOutItems({
|
|
4352
4353
|
page = 1,
|
|
4353
4354
|
limit = 10,
|
|
4354
4355
|
search = "",
|
|
@@ -4382,9 +4383,38 @@ function useRequestItemRepository() {
|
|
|
4382
4383
|
try {
|
|
4383
4384
|
const items = await collection.aggregate([
|
|
4384
4385
|
{ $match: query },
|
|
4386
|
+
{
|
|
4387
|
+
$lookup: {
|
|
4388
|
+
from: "site.supplies",
|
|
4389
|
+
let: { supplyId: "$supply" },
|
|
4390
|
+
pipeline: [
|
|
4391
|
+
{
|
|
4392
|
+
$match: {
|
|
4393
|
+
$expr: {
|
|
4394
|
+
$and: [
|
|
4395
|
+
{ $ne: ["$$supplyId", ""] },
|
|
4396
|
+
{ $eq: ["$_id", "$$supplyId"] }
|
|
4397
|
+
]
|
|
4398
|
+
}
|
|
4399
|
+
}
|
|
4400
|
+
},
|
|
4401
|
+
{ $project: { qty: 1 } }
|
|
4402
|
+
],
|
|
4403
|
+
as: "supplyDoc"
|
|
4404
|
+
}
|
|
4405
|
+
},
|
|
4406
|
+
{
|
|
4407
|
+
$unwind: {
|
|
4408
|
+
path: "$supplyDoc",
|
|
4409
|
+
preserveNullAndEmptyArrays: true
|
|
4410
|
+
}
|
|
4411
|
+
},
|
|
4385
4412
|
{
|
|
4386
4413
|
$project: {
|
|
4387
4414
|
supplyName: 1,
|
|
4415
|
+
supplyQty: "$supplyDoc.qty",
|
|
4416
|
+
checkOutByName: "$createdByName",
|
|
4417
|
+
checkOutQty: "$qty",
|
|
4388
4418
|
createdAt: 1,
|
|
4389
4419
|
status: 1
|
|
4390
4420
|
}
|
|
@@ -4405,11 +4435,11 @@ function useRequestItemRepository() {
|
|
|
4405
4435
|
throw error;
|
|
4406
4436
|
}
|
|
4407
4437
|
}
|
|
4408
|
-
async function
|
|
4438
|
+
async function getCheckOutItemById(_id, session) {
|
|
4409
4439
|
try {
|
|
4410
4440
|
_id = new import_mongodb15.ObjectId(_id);
|
|
4411
4441
|
} catch (error) {
|
|
4412
|
-
throw new import_node_server_utils26.BadRequestError("Invalid
|
|
4442
|
+
throw new import_node_server_utils26.BadRequestError("Invalid check out item ID format.");
|
|
4413
4443
|
}
|
|
4414
4444
|
const query = { _id };
|
|
4415
4445
|
const cacheKey = (0, import_node_server_utils26.makeCacheKey)(namespace_collection, {
|
|
@@ -4425,35 +4455,39 @@ function useRequestItemRepository() {
|
|
|
4425
4455
|
import_node_server_utils26.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
4426
4456
|
}
|
|
4427
4457
|
try {
|
|
4428
|
-
const data = await collection.aggregate(
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
4440
|
-
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
|
|
4451
|
-
|
|
4458
|
+
const data = await collection.aggregate(
|
|
4459
|
+
[
|
|
4460
|
+
{ $match: query },
|
|
4461
|
+
{
|
|
4462
|
+
$lookup: {
|
|
4463
|
+
from: "site.supply.items",
|
|
4464
|
+
localField: "supply",
|
|
4465
|
+
foreignField: "_id",
|
|
4466
|
+
as: "supplyDetails"
|
|
4467
|
+
}
|
|
4468
|
+
},
|
|
4469
|
+
{
|
|
4470
|
+
$unwind: {
|
|
4471
|
+
path: "$supplyDetails",
|
|
4472
|
+
preserveNullAndEmptyArrays: true
|
|
4473
|
+
}
|
|
4474
|
+
},
|
|
4475
|
+
{
|
|
4476
|
+
$project: {
|
|
4477
|
+
site: 1,
|
|
4478
|
+
supply: 1,
|
|
4479
|
+
supplyName: 1,
|
|
4480
|
+
qty: 1,
|
|
4481
|
+
status: 1,
|
|
4482
|
+
unitOfMeasurement: "$supplyDetails.unitOfMeasurement",
|
|
4483
|
+
attachment: 1
|
|
4484
|
+
}
|
|
4452
4485
|
}
|
|
4453
|
-
|
|
4454
|
-
|
|
4486
|
+
],
|
|
4487
|
+
session ? { session } : void 0
|
|
4488
|
+
).toArray();
|
|
4455
4489
|
if (!data || data.length === 0) {
|
|
4456
|
-
throw new import_node_server_utils26.NotFoundError("
|
|
4490
|
+
throw new import_node_server_utils26.NotFoundError("Check out item not found.");
|
|
4457
4491
|
}
|
|
4458
4492
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
4459
4493
|
import_node_server_utils26.logger.info(`Cache set for key: ${cacheKey}`);
|
|
@@ -4465,49 +4499,15 @@ function useRequestItemRepository() {
|
|
|
4465
4499
|
throw error;
|
|
4466
4500
|
}
|
|
4467
4501
|
}
|
|
4468
|
-
async function
|
|
4469
|
-
try {
|
|
4470
|
-
_id = new import_mongodb15.ObjectId(_id);
|
|
4471
|
-
} catch (error) {
|
|
4472
|
-
throw new import_node_server_utils26.BadRequestError("Invalid request item ID format.");
|
|
4473
|
-
}
|
|
4474
|
-
try {
|
|
4475
|
-
const updateValue = {
|
|
4476
|
-
status: "approved",
|
|
4477
|
-
remarks: remarks || "",
|
|
4478
|
-
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4479
|
-
};
|
|
4480
|
-
const res = await collection.updateOne(
|
|
4481
|
-
{ _id },
|
|
4482
|
-
{ $set: updateValue },
|
|
4483
|
-
{ session }
|
|
4484
|
-
);
|
|
4485
|
-
if (res.modifiedCount === 0) {
|
|
4486
|
-
throw new import_node_server_utils26.InternalServerError("Unable to approve request item.");
|
|
4487
|
-
}
|
|
4488
|
-
delNamespace().then(() => {
|
|
4489
|
-
import_node_server_utils26.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4490
|
-
}).catch((err) => {
|
|
4491
|
-
import_node_server_utils26.logger.error(
|
|
4492
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4493
|
-
err
|
|
4494
|
-
);
|
|
4495
|
-
});
|
|
4496
|
-
return res.modifiedCount;
|
|
4497
|
-
} catch (error) {
|
|
4498
|
-
throw error;
|
|
4499
|
-
}
|
|
4500
|
-
}
|
|
4501
|
-
async function disapproveRequestItem(_id, remarks, session) {
|
|
4502
|
+
async function completeCheckOutItem(_id, session) {
|
|
4502
4503
|
try {
|
|
4503
4504
|
_id = new import_mongodb15.ObjectId(_id);
|
|
4504
4505
|
} catch (error) {
|
|
4505
|
-
throw new import_node_server_utils26.BadRequestError("Invalid
|
|
4506
|
+
throw new import_node_server_utils26.BadRequestError("Invalid check out item ID format.");
|
|
4506
4507
|
}
|
|
4507
4508
|
try {
|
|
4508
4509
|
const updateValue = {
|
|
4509
|
-
status: "
|
|
4510
|
-
remarks: remarks || "",
|
|
4510
|
+
status: "completed",
|
|
4511
4511
|
updatedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
4512
4512
|
};
|
|
4513
4513
|
const res = await collection.updateOne(
|
|
@@ -4516,7 +4516,7 @@ function useRequestItemRepository() {
|
|
|
4516
4516
|
{ session }
|
|
4517
4517
|
);
|
|
4518
4518
|
if (res.modifiedCount === 0) {
|
|
4519
|
-
throw new import_node_server_utils26.InternalServerError("Unable to
|
|
4519
|
+
throw new import_node_server_utils26.InternalServerError("Unable to complete check out item.");
|
|
4520
4520
|
}
|
|
4521
4521
|
delNamespace().then(() => {
|
|
4522
4522
|
import_node_server_utils26.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
@@ -4534,93 +4534,56 @@ function useRequestItemRepository() {
|
|
|
4534
4534
|
return {
|
|
4535
4535
|
createIndex,
|
|
4536
4536
|
createTextIndex,
|
|
4537
|
-
|
|
4538
|
-
|
|
4539
|
-
|
|
4540
|
-
|
|
4541
|
-
disapproveRequestItem
|
|
4537
|
+
createCheckOutItem,
|
|
4538
|
+
getCheckOutItems,
|
|
4539
|
+
getCheckOutItemById,
|
|
4540
|
+
completeCheckOutItem
|
|
4542
4541
|
};
|
|
4543
4542
|
}
|
|
4544
4543
|
|
|
4545
|
-
// src/services/hygiene-
|
|
4544
|
+
// src/services/hygiene-checkout-item.service.ts
|
|
4546
4545
|
var import_core = require("@7365admin1/core");
|
|
4547
4546
|
var import_node_server_utils27 = require("@7365admin1/node-server-utils");
|
|
4548
|
-
function
|
|
4547
|
+
function useCheckOutItemService() {
|
|
4549
4548
|
const {
|
|
4550
|
-
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
|
|
4554
|
-
} = useRequestItemRepository();
|
|
4549
|
+
createCheckOutItem: _createCheckOutItem,
|
|
4550
|
+
getCheckOutItemById: _getCheckOutItemById,
|
|
4551
|
+
completeCheckOutItem
|
|
4552
|
+
} = useCheckOutItemRepository();
|
|
4555
4553
|
const { getSupplyById } = useSupplyRepository();
|
|
4556
4554
|
const { getUserById } = (0, import_core.useUserRepo)();
|
|
4557
4555
|
const { createStock } = useStockService();
|
|
4558
|
-
async function
|
|
4559
|
-
try {
|
|
4560
|
-
const { supply, createdBy } = value;
|
|
4561
|
-
const supplyData = await getSupplyById(supply);
|
|
4562
|
-
const createdByData = await getUserById(createdBy);
|
|
4563
|
-
const createdRequestItem = await _createRequestItem({
|
|
4564
|
-
...value,
|
|
4565
|
-
supplyName: supplyData?.name || "",
|
|
4566
|
-
createdByName: createdByData?.name || ""
|
|
4567
|
-
});
|
|
4568
|
-
return createdRequestItem;
|
|
4569
|
-
} catch (error) {
|
|
4570
|
-
throw error;
|
|
4571
|
-
}
|
|
4572
|
-
}
|
|
4573
|
-
async function createRequestItemByBatch(value) {
|
|
4574
|
-
const session = import_node_server_utils27.useAtlas.getClient()?.startSession();
|
|
4575
|
-
try {
|
|
4576
|
-
session?.startTransaction();
|
|
4577
|
-
const { site, createdBy, items } = value;
|
|
4578
|
-
const createdByData = await getUserById(createdBy);
|
|
4579
|
-
const createdRequestItemIds = [];
|
|
4580
|
-
for (const item of items) {
|
|
4581
|
-
const supplyData = await getSupplyById(item.supply, session);
|
|
4582
|
-
const createdId = await _createRequestItem(
|
|
4583
|
-
{
|
|
4584
|
-
site,
|
|
4585
|
-
supply: item.supply,
|
|
4586
|
-
qty: item.qty,
|
|
4587
|
-
supplyName: supplyData?.name || "",
|
|
4588
|
-
createdBy,
|
|
4589
|
-
createdByName: createdByData?.name || ""
|
|
4590
|
-
},
|
|
4591
|
-
session
|
|
4592
|
-
);
|
|
4593
|
-
createdRequestItemIds.push(createdId);
|
|
4594
|
-
}
|
|
4595
|
-
await session?.commitTransaction();
|
|
4596
|
-
return createdRequestItemIds;
|
|
4597
|
-
} catch (error) {
|
|
4598
|
-
await session?.abortTransaction();
|
|
4599
|
-
throw error;
|
|
4600
|
-
} finally {
|
|
4601
|
-
await session?.endSession();
|
|
4602
|
-
}
|
|
4603
|
-
}
|
|
4604
|
-
async function approveRequestItem(id, remarks) {
|
|
4556
|
+
async function createCheckOutItem(value) {
|
|
4605
4557
|
const session = import_node_server_utils27.useAtlas.getClient()?.startSession();
|
|
4606
4558
|
try {
|
|
4607
4559
|
session?.startTransaction();
|
|
4608
|
-
await
|
|
4609
|
-
const
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4560
|
+
const supplyData = await getSupplyById(value.supply);
|
|
4561
|
+
const createdByData = await getUserById(value.createdBy);
|
|
4562
|
+
const checkOutItemId = await _createCheckOutItem(
|
|
4563
|
+
{
|
|
4564
|
+
...value,
|
|
4565
|
+
supplyName: supplyData?.name || "",
|
|
4566
|
+
createdByName: createdByData?.name || ""
|
|
4567
|
+
},
|
|
4568
|
+
session
|
|
4569
|
+
);
|
|
4570
|
+
const checkOutItem = await _getCheckOutItemById(
|
|
4571
|
+
checkOutItemId.toString(),
|
|
4572
|
+
session
|
|
4573
|
+
);
|
|
4574
|
+
if (!checkOutItem) {
|
|
4575
|
+
throw new import_node_server_utils27.BadRequestError("Failed to create check out item.");
|
|
4614
4576
|
}
|
|
4615
4577
|
const createdStocks = await createStock(
|
|
4616
4578
|
{
|
|
4617
|
-
site:
|
|
4618
|
-
supply:
|
|
4619
|
-
qty:
|
|
4620
|
-
remarks
|
|
4579
|
+
site: checkOutItem.site.toString(),
|
|
4580
|
+
supply: checkOutItem.supply.toString(),
|
|
4581
|
+
qty: checkOutItem.qty
|
|
4621
4582
|
},
|
|
4622
|
-
true
|
|
4583
|
+
true,
|
|
4584
|
+
session
|
|
4623
4585
|
);
|
|
4586
|
+
await completeCheckOutItem(checkOutItemId.toString(), session);
|
|
4624
4587
|
await session?.commitTransaction();
|
|
4625
4588
|
return createdStocks;
|
|
4626
4589
|
} catch (error) {
|
|
@@ -4630,19 +4593,40 @@ function useRequestItemService() {
|
|
|
4630
4593
|
await session?.endSession();
|
|
4631
4594
|
}
|
|
4632
4595
|
}
|
|
4633
|
-
async function
|
|
4596
|
+
async function createCheckOutItemByBatch(value) {
|
|
4634
4597
|
const session = import_node_server_utils27.useAtlas.getClient()?.startSession();
|
|
4635
4598
|
try {
|
|
4636
4599
|
session?.startTransaction();
|
|
4637
|
-
const
|
|
4638
|
-
const
|
|
4639
|
-
|
|
4640
|
-
|
|
4641
|
-
|
|
4600
|
+
const { site, attachment, createdBy, items } = value;
|
|
4601
|
+
const createdByData = await getUserById(createdBy);
|
|
4602
|
+
const createdCheckOutItemIds = [];
|
|
4603
|
+
for (const item of items) {
|
|
4604
|
+
const supplyData = await getSupplyById(item.supply, session);
|
|
4605
|
+
const createdId = await _createCheckOutItem(
|
|
4606
|
+
{
|
|
4607
|
+
site,
|
|
4608
|
+
supply: item.supply,
|
|
4609
|
+
supplyName: supplyData?.name || "",
|
|
4610
|
+
qty: item.qty,
|
|
4611
|
+
attachment,
|
|
4612
|
+
createdBy,
|
|
4613
|
+
createdByName: createdByData?.name || ""
|
|
4614
|
+
},
|
|
4615
|
+
session
|
|
4616
|
+
);
|
|
4617
|
+
await createStock(
|
|
4618
|
+
{
|
|
4619
|
+
site,
|
|
4620
|
+
supply: item.supply,
|
|
4621
|
+
qty: item.qty
|
|
4622
|
+
},
|
|
4623
|
+
true,
|
|
4624
|
+
session
|
|
4642
4625
|
);
|
|
4626
|
+
createdCheckOutItemIds.push(createdId);
|
|
4643
4627
|
}
|
|
4644
4628
|
await session?.commitTransaction();
|
|
4645
|
-
return
|
|
4629
|
+
return createdCheckOutItemIds;
|
|
4646
4630
|
} catch (error) {
|
|
4647
4631
|
await session?.abortTransaction();
|
|
4648
4632
|
throw error;
|
|
@@ -4651,28 +4635,24 @@ function useRequestItemService() {
|
|
|
4651
4635
|
}
|
|
4652
4636
|
}
|
|
4653
4637
|
return {
|
|
4654
|
-
|
|
4655
|
-
|
|
4656
|
-
approveRequestItem,
|
|
4657
|
-
disapproveRequestItem
|
|
4638
|
+
createCheckOutItem,
|
|
4639
|
+
createCheckOutItemByBatch
|
|
4658
4640
|
};
|
|
4659
4641
|
}
|
|
4660
4642
|
|
|
4661
|
-
// src/controllers/hygiene-
|
|
4643
|
+
// src/controllers/hygiene-checkout-item.controller.ts
|
|
4662
4644
|
var import_joi15 = __toESM(require("joi"));
|
|
4663
4645
|
var import_node_server_utils28 = require("@7365admin1/node-server-utils");
|
|
4664
|
-
function
|
|
4646
|
+
function useCheckOutItemController() {
|
|
4665
4647
|
const {
|
|
4666
|
-
|
|
4667
|
-
|
|
4668
|
-
} =
|
|
4648
|
+
getCheckOutItems: _getCheckOutItems,
|
|
4649
|
+
getCheckOutItemById: _getCheckOutItemById
|
|
4650
|
+
} = useCheckOutItemRepository();
|
|
4669
4651
|
const {
|
|
4670
|
-
|
|
4671
|
-
|
|
4672
|
-
|
|
4673
|
-
|
|
4674
|
-
} = useRequestItemService();
|
|
4675
|
-
async function createRequestItem(req, res, next) {
|
|
4652
|
+
createCheckOutItem: _createCheckOutItem,
|
|
4653
|
+
createCheckOutItemByBatch: _createCheckOutItemByBatch
|
|
4654
|
+
} = useCheckOutItemService();
|
|
4655
|
+
async function createCheckOutItem(req, res, next) {
|
|
4676
4656
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
4677
4657
|
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
4678
4658
|
{}
|
|
@@ -4687,6 +4667,7 @@ function useRequestItemController() {
|
|
|
4687
4667
|
site: import_joi15.default.string().hex().required(),
|
|
4688
4668
|
supply: import_joi15.default.string().hex().required(),
|
|
4689
4669
|
qty: import_joi15.default.number().min(0).required(),
|
|
4670
|
+
attachment: import_joi15.default.array().items(import_joi15.default.string()).optional().allow(null),
|
|
4690
4671
|
createdBy: import_joi15.default.string().hex().required()
|
|
4691
4672
|
});
|
|
4692
4673
|
const { error } = validation.validate(payload);
|
|
@@ -4696,8 +4677,8 @@ function useRequestItemController() {
|
|
|
4696
4677
|
return;
|
|
4697
4678
|
}
|
|
4698
4679
|
try {
|
|
4699
|
-
const id = await
|
|
4700
|
-
res.status(201).json({ message: "
|
|
4680
|
+
const id = await _createCheckOutItem(payload);
|
|
4681
|
+
res.status(201).json({ message: "Check out item created successfully.", id });
|
|
4701
4682
|
return;
|
|
4702
4683
|
} catch (error2) {
|
|
4703
4684
|
import_node_server_utils28.logger.log({ level: "error", message: error2.message });
|
|
@@ -4705,7 +4686,7 @@ function useRequestItemController() {
|
|
|
4705
4686
|
return;
|
|
4706
4687
|
}
|
|
4707
4688
|
}
|
|
4708
|
-
async function
|
|
4689
|
+
async function createCheckOutItemByBatch(req, res, next) {
|
|
4709
4690
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
4710
4691
|
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
4711
4692
|
{}
|
|
@@ -4718,6 +4699,7 @@ function useRequestItemController() {
|
|
|
4718
4699
|
};
|
|
4719
4700
|
const validation = import_joi15.default.object({
|
|
4720
4701
|
site: import_joi15.default.string().hex().required(),
|
|
4702
|
+
attachment: import_joi15.default.array().items(import_joi15.default.string()).optional().allow(null),
|
|
4721
4703
|
createdBy: import_joi15.default.string().hex().required(),
|
|
4722
4704
|
items: import_joi15.default.array().items(
|
|
4723
4705
|
import_joi15.default.object({
|
|
@@ -4733,8 +4715,8 @@ function useRequestItemController() {
|
|
|
4733
4715
|
return;
|
|
4734
4716
|
}
|
|
4735
4717
|
try {
|
|
4736
|
-
await
|
|
4737
|
-
res.status(201).json({ message: "
|
|
4718
|
+
await _createCheckOutItemByBatch(payload);
|
|
4719
|
+
res.status(201).json({ message: "Check out items created successfully." });
|
|
4738
4720
|
return;
|
|
4739
4721
|
} catch (error2) {
|
|
4740
4722
|
import_node_server_utils28.logger.log({ level: "error", message: error2.message });
|
|
@@ -4742,7 +4724,7 @@ function useRequestItemController() {
|
|
|
4742
4724
|
return;
|
|
4743
4725
|
}
|
|
4744
4726
|
}
|
|
4745
|
-
async function
|
|
4727
|
+
async function getCheckOutItems(req, res, next) {
|
|
4746
4728
|
const query = { ...req.query, ...req.params };
|
|
4747
4729
|
const validation = import_joi15.default.object({
|
|
4748
4730
|
page: import_joi15.default.number().min(1).optional().allow("", null),
|
|
@@ -4761,7 +4743,7 @@ function useRequestItemController() {
|
|
|
4761
4743
|
const search = req.query.search ?? "";
|
|
4762
4744
|
const site = req.params.site ?? "";
|
|
4763
4745
|
try {
|
|
4764
|
-
const data = await
|
|
4746
|
+
const data = await _getCheckOutItems({
|
|
4765
4747
|
page,
|
|
4766
4748
|
limit,
|
|
4767
4749
|
search,
|
|
@@ -4775,7 +4757,7 @@ function useRequestItemController() {
|
|
|
4775
4757
|
return;
|
|
4776
4758
|
}
|
|
4777
4759
|
}
|
|
4778
|
-
async function
|
|
4760
|
+
async function getCheckOutItemById(req, res, next) {
|
|
4779
4761
|
const validation = import_joi15.default.string().hex().required();
|
|
4780
4762
|
const _id = req.params.id;
|
|
4781
4763
|
const { error, value } = validation.validate(_id);
|
|
@@ -4785,7 +4767,7 @@ function useRequestItemController() {
|
|
|
4785
4767
|
return;
|
|
4786
4768
|
}
|
|
4787
4769
|
try {
|
|
4788
|
-
const data = await
|
|
4770
|
+
const data = await _getCheckOutItemById(value);
|
|
4789
4771
|
res.json(data);
|
|
4790
4772
|
return;
|
|
4791
4773
|
} catch (error2) {
|
|
@@ -4794,608 +4776,44 @@ function useRequestItemController() {
|
|
|
4794
4776
|
return;
|
|
4795
4777
|
}
|
|
4796
4778
|
}
|
|
4797
|
-
async function approveRequestItem(req, res, next) {
|
|
4798
|
-
const payload = { ...req.params, ...req.body };
|
|
4799
|
-
const validation = import_joi15.default.object({
|
|
4800
|
-
id: import_joi15.default.string().hex().required(),
|
|
4801
|
-
remarks: import_joi15.default.string().optional().allow("", null)
|
|
4802
|
-
});
|
|
4803
|
-
const { error } = validation.validate(payload);
|
|
4804
|
-
if (error) {
|
|
4805
|
-
import_node_server_utils28.logger.log({ level: "error", message: error.message });
|
|
4806
|
-
next(new import_node_server_utils28.BadRequestError(error.message));
|
|
4807
|
-
return;
|
|
4808
|
-
}
|
|
4809
|
-
try {
|
|
4810
|
-
await _approveRequestItem(payload.id, payload.remarks);
|
|
4811
|
-
res.json({ message: "Request item approved successfully." });
|
|
4812
|
-
return;
|
|
4813
|
-
} catch (error2) {
|
|
4814
|
-
import_node_server_utils28.logger.log({ level: "error", message: error2.message });
|
|
4815
|
-
next(error2);
|
|
4816
|
-
return;
|
|
4817
|
-
}
|
|
4818
|
-
}
|
|
4819
|
-
async function disapproveRequestItem(req, res, next) {
|
|
4820
|
-
const payload = { ...req.params, ...req.body };
|
|
4821
|
-
const validation = import_joi15.default.object({
|
|
4822
|
-
id: import_joi15.default.string().hex().required(),
|
|
4823
|
-
remarks: import_joi15.default.string().optional().allow("", null)
|
|
4824
|
-
});
|
|
4825
|
-
const { error } = validation.validate(payload);
|
|
4826
|
-
if (error) {
|
|
4827
|
-
import_node_server_utils28.logger.log({ level: "error", message: error.message });
|
|
4828
|
-
next(new import_node_server_utils28.BadRequestError(error.message));
|
|
4829
|
-
return;
|
|
4830
|
-
}
|
|
4831
|
-
try {
|
|
4832
|
-
await _disapproveRequestItem(payload.id, payload.remarks);
|
|
4833
|
-
res.json({ message: "Request item disapproved successfully." });
|
|
4834
|
-
return;
|
|
4835
|
-
} catch (error2) {
|
|
4836
|
-
import_node_server_utils28.logger.log({ level: "error", message: error2.message });
|
|
4837
|
-
next(error2);
|
|
4838
|
-
return;
|
|
4839
|
-
}
|
|
4840
|
-
}
|
|
4841
4779
|
return {
|
|
4842
|
-
|
|
4843
|
-
|
|
4844
|
-
|
|
4845
|
-
|
|
4846
|
-
approveRequestItem,
|
|
4847
|
-
disapproveRequestItem
|
|
4780
|
+
createCheckOutItem,
|
|
4781
|
+
createCheckOutItemByBatch,
|
|
4782
|
+
getCheckOutItems,
|
|
4783
|
+
getCheckOutItemById
|
|
4848
4784
|
};
|
|
4849
4785
|
}
|
|
4850
4786
|
|
|
4851
|
-
// src/models/hygiene-
|
|
4787
|
+
// src/models/hygiene-schedule-task.model.ts
|
|
4788
|
+
var import_node_server_utils29 = require("@7365admin1/node-server-utils");
|
|
4852
4789
|
var import_joi16 = __toESM(require("joi"));
|
|
4853
4790
|
var import_mongodb16 = require("mongodb");
|
|
4854
|
-
var
|
|
4855
|
-
var allowedCheckOutItemStatus = ["pending", "completed"];
|
|
4856
|
-
var checkOutItemSchema = import_joi16.default.object({
|
|
4791
|
+
var scheduleTaskSchema = import_joi16.default.object({
|
|
4857
4792
|
site: import_joi16.default.string().hex().required(),
|
|
4858
|
-
|
|
4859
|
-
|
|
4860
|
-
|
|
4861
|
-
|
|
4862
|
-
|
|
4863
|
-
|
|
4864
|
-
|
|
4865
|
-
|
|
4866
|
-
|
|
4867
|
-
|
|
4868
|
-
|
|
4869
|
-
|
|
4870
|
-
}
|
|
4871
|
-
if (value.site) {
|
|
4872
|
-
try {
|
|
4873
|
-
value.site = new import_mongodb16.ObjectId(value.site);
|
|
4874
|
-
} catch (error2) {
|
|
4875
|
-
throw new import_node_server_utils29.BadRequestError("Invalid site ID format.");
|
|
4876
|
-
}
|
|
4877
|
-
}
|
|
4878
|
-
if (value.supply) {
|
|
4879
|
-
try {
|
|
4880
|
-
value.supply = new import_mongodb16.ObjectId(value.supply);
|
|
4881
|
-
} catch (error2) {
|
|
4882
|
-
throw new import_node_server_utils29.BadRequestError("Invalid supply ID format.");
|
|
4883
|
-
}
|
|
4884
|
-
}
|
|
4885
|
-
return {
|
|
4886
|
-
site: value.site,
|
|
4887
|
-
supply: value.supply,
|
|
4888
|
-
supplyName: value.supplyName,
|
|
4889
|
-
qty: value.qty,
|
|
4890
|
-
attachment: "",
|
|
4891
|
-
createdBy: value.createdBy,
|
|
4892
|
-
createdByName: value.createdByName,
|
|
4893
|
-
status: "pending",
|
|
4894
|
-
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
4895
|
-
updatedAt: "",
|
|
4896
|
-
deletedAt: ""
|
|
4897
|
-
};
|
|
4898
|
-
}
|
|
4899
|
-
|
|
4900
|
-
// src/repositories/hygiene-checkout-item.repository.ts
|
|
4901
|
-
var import_mongodb17 = require("mongodb");
|
|
4902
|
-
var import_node_server_utils30 = require("@7365admin1/node-server-utils");
|
|
4903
|
-
function useCheckOutItemRepository() {
|
|
4904
|
-
const db = import_node_server_utils30.useAtlas.getDb();
|
|
4905
|
-
if (!db) {
|
|
4906
|
-
throw new import_node_server_utils30.InternalServerError("Unable to connect to server.");
|
|
4907
|
-
}
|
|
4908
|
-
const namespace_collection = "site.supply.checkouts";
|
|
4909
|
-
const collection = db.collection(namespace_collection);
|
|
4910
|
-
const { delNamespace, setCache, getCache } = (0, import_node_server_utils30.useCache)(namespace_collection);
|
|
4911
|
-
async function createIndex() {
|
|
4912
|
-
try {
|
|
4913
|
-
await collection.createIndexes([
|
|
4914
|
-
{ key: { site: 1 } },
|
|
4915
|
-
{ key: { supply: 1 } },
|
|
4916
|
-
{ key: { status: 1 } }
|
|
4917
|
-
]);
|
|
4918
|
-
} catch (error) {
|
|
4919
|
-
throw new import_node_server_utils30.InternalServerError(
|
|
4920
|
-
"Failed to create index on hygiene check out item."
|
|
4921
|
-
);
|
|
4922
|
-
}
|
|
4923
|
-
}
|
|
4924
|
-
async function createTextIndex() {
|
|
4925
|
-
try {
|
|
4926
|
-
await collection.createIndex({ supplyName: "text" });
|
|
4927
|
-
} catch (error) {
|
|
4928
|
-
throw new import_node_server_utils30.InternalServerError(
|
|
4929
|
-
"Failed to create text index on hygiene supply."
|
|
4930
|
-
);
|
|
4931
|
-
}
|
|
4932
|
-
}
|
|
4933
|
-
async function createCheckOutItem(value, session) {
|
|
4934
|
-
try {
|
|
4935
|
-
value = MCheckOutItem(value);
|
|
4936
|
-
const res = await collection.insertOne(value, { session });
|
|
4937
|
-
delNamespace().then(() => {
|
|
4938
|
-
import_node_server_utils30.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
4939
|
-
}).catch((err) => {
|
|
4940
|
-
import_node_server_utils30.logger.error(
|
|
4941
|
-
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
4942
|
-
err
|
|
4943
|
-
);
|
|
4944
|
-
});
|
|
4945
|
-
return res.insertedId;
|
|
4946
|
-
} catch (error) {
|
|
4947
|
-
throw error;
|
|
4948
|
-
}
|
|
4949
|
-
}
|
|
4950
|
-
async function getCheckOutItems({
|
|
4951
|
-
page = 1,
|
|
4952
|
-
limit = 10,
|
|
4953
|
-
search = "",
|
|
4954
|
-
site
|
|
4955
|
-
}) {
|
|
4956
|
-
page = page > 0 ? page - 1 : 0;
|
|
4957
|
-
const query = {
|
|
4958
|
-
status: { $ne: "deleted" }
|
|
4959
|
-
};
|
|
4960
|
-
const cacheOptions = {
|
|
4961
|
-
page,
|
|
4962
|
-
limit
|
|
4963
|
-
};
|
|
4964
|
-
try {
|
|
4965
|
-
site = new import_mongodb17.ObjectId(site);
|
|
4966
|
-
query.site = site;
|
|
4967
|
-
cacheOptions.site = site.toString();
|
|
4968
|
-
} catch (error) {
|
|
4969
|
-
throw new import_node_server_utils30.BadRequestError("Invalid site ID format.");
|
|
4970
|
-
}
|
|
4971
|
-
if (search) {
|
|
4972
|
-
query.$text = { $search: search };
|
|
4973
|
-
cacheOptions.search = search;
|
|
4974
|
-
}
|
|
4975
|
-
const cacheKey = (0, import_node_server_utils30.makeCacheKey)(namespace_collection, cacheOptions);
|
|
4976
|
-
const cachedData = await getCache(cacheKey);
|
|
4977
|
-
if (cachedData) {
|
|
4978
|
-
import_node_server_utils30.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
4979
|
-
return cachedData;
|
|
4980
|
-
}
|
|
4981
|
-
try {
|
|
4982
|
-
const items = await collection.aggregate([
|
|
4983
|
-
{ $match: query },
|
|
4984
|
-
{
|
|
4985
|
-
$lookup: {
|
|
4986
|
-
from: "site.supplies",
|
|
4987
|
-
let: { supplyId: "$supply" },
|
|
4988
|
-
pipeline: [
|
|
4989
|
-
{
|
|
4990
|
-
$match: {
|
|
4991
|
-
$expr: {
|
|
4992
|
-
$and: [
|
|
4993
|
-
{ $ne: ["$$supplyId", ""] },
|
|
4994
|
-
{ $eq: ["$_id", "$$supplyId"] }
|
|
4995
|
-
]
|
|
4996
|
-
}
|
|
4997
|
-
}
|
|
4998
|
-
},
|
|
4999
|
-
{ $project: { qty: 1 } }
|
|
5000
|
-
],
|
|
5001
|
-
as: "supplyDoc"
|
|
5002
|
-
}
|
|
5003
|
-
},
|
|
5004
|
-
{
|
|
5005
|
-
$unwind: {
|
|
5006
|
-
path: "$supplyDoc",
|
|
5007
|
-
preserveNullAndEmptyArrays: true
|
|
5008
|
-
}
|
|
5009
|
-
},
|
|
5010
|
-
{
|
|
5011
|
-
$lookup: {
|
|
5012
|
-
from: "users",
|
|
5013
|
-
let: { createdById: "$createdBy" },
|
|
5014
|
-
pipeline: [
|
|
5015
|
-
{
|
|
5016
|
-
$match: {
|
|
5017
|
-
$expr: {
|
|
5018
|
-
$and: [
|
|
5019
|
-
{ $ne: ["$$createdById", ""] },
|
|
5020
|
-
{ $eq: ["$_id", "$$createdById"] }
|
|
5021
|
-
]
|
|
5022
|
-
}
|
|
5023
|
-
}
|
|
5024
|
-
},
|
|
5025
|
-
{ $project: { name: 1 } }
|
|
5026
|
-
],
|
|
5027
|
-
as: "createdByDoc"
|
|
5028
|
-
}
|
|
5029
|
-
},
|
|
5030
|
-
{
|
|
5031
|
-
$unwind: {
|
|
5032
|
-
path: "$createdByDoc",
|
|
5033
|
-
preserveNullAndEmptyArrays: true
|
|
5034
|
-
}
|
|
5035
|
-
},
|
|
5036
|
-
{
|
|
5037
|
-
$project: {
|
|
5038
|
-
supplyName: 1,
|
|
5039
|
-
supplyQty: "$supplyDoc.qty",
|
|
5040
|
-
checkOutByName: "$createdByDoc.name",
|
|
5041
|
-
checkOutQty: "$qty",
|
|
5042
|
-
createdAt: 1,
|
|
5043
|
-
status: 1
|
|
5044
|
-
}
|
|
5045
|
-
},
|
|
5046
|
-
{ $sort: { _id: -1 } },
|
|
5047
|
-
{ $skip: page * limit },
|
|
5048
|
-
{ $limit: limit }
|
|
5049
|
-
]).toArray();
|
|
5050
|
-
const length = await collection.countDocuments(query);
|
|
5051
|
-
const data = (0, import_node_server_utils30.paginate)(items, page, limit, length);
|
|
5052
|
-
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5053
|
-
import_node_server_utils30.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5054
|
-
}).catch((err) => {
|
|
5055
|
-
import_node_server_utils30.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5056
|
-
});
|
|
5057
|
-
return data;
|
|
5058
|
-
} catch (error) {
|
|
5059
|
-
throw error;
|
|
5060
|
-
}
|
|
5061
|
-
}
|
|
5062
|
-
async function getCheckOutItemById(_id, session) {
|
|
5063
|
-
try {
|
|
5064
|
-
_id = new import_mongodb17.ObjectId(_id);
|
|
5065
|
-
} catch (error) {
|
|
5066
|
-
throw new import_node_server_utils30.BadRequestError("Invalid check out item ID format.");
|
|
5067
|
-
}
|
|
5068
|
-
const query = { _id };
|
|
5069
|
-
const cacheKey = (0, import_node_server_utils30.makeCacheKey)(namespace_collection, {
|
|
5070
|
-
_id: _id.toString()
|
|
5071
|
-
});
|
|
5072
|
-
if (!session) {
|
|
5073
|
-
const cachedData = await getCache(cacheKey);
|
|
5074
|
-
if (cachedData) {
|
|
5075
|
-
import_node_server_utils30.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5076
|
-
return cachedData;
|
|
5077
|
-
}
|
|
5078
|
-
} else {
|
|
5079
|
-
import_node_server_utils30.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
5080
|
-
}
|
|
5081
|
-
try {
|
|
5082
|
-
const data = await collection.aggregate([
|
|
5083
|
-
{ $match: query },
|
|
5084
|
-
{
|
|
5085
|
-
$lookup: {
|
|
5086
|
-
from: "site.supply.items",
|
|
5087
|
-
localField: "supply",
|
|
5088
|
-
foreignField: "_id",
|
|
5089
|
-
as: "supplyDetails"
|
|
5090
|
-
}
|
|
5091
|
-
},
|
|
5092
|
-
{
|
|
5093
|
-
$unwind: {
|
|
5094
|
-
path: "$supplyDetails",
|
|
5095
|
-
preserveNullAndEmptyArrays: true
|
|
5096
|
-
}
|
|
5097
|
-
},
|
|
5098
|
-
{
|
|
5099
|
-
$project: {
|
|
5100
|
-
site: 1,
|
|
5101
|
-
supply: 1,
|
|
5102
|
-
supplyName: 1,
|
|
5103
|
-
qty: 1,
|
|
5104
|
-
status: 1,
|
|
5105
|
-
unitOfMeasurement: "$supplyDetails.unitOfMeasurement"
|
|
5106
|
-
}
|
|
5107
|
-
}
|
|
5108
|
-
]).toArray();
|
|
5109
|
-
if (!data || data.length === 0) {
|
|
5110
|
-
throw new import_node_server_utils30.NotFoundError("Check out item not found.");
|
|
5111
|
-
}
|
|
5112
|
-
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
5113
|
-
import_node_server_utils30.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5114
|
-
}).catch((err) => {
|
|
5115
|
-
import_node_server_utils30.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5116
|
-
});
|
|
5117
|
-
return data[0];
|
|
5118
|
-
} catch (error) {
|
|
5119
|
-
throw error;
|
|
5120
|
-
}
|
|
5121
|
-
}
|
|
5122
|
-
return {
|
|
5123
|
-
createIndex,
|
|
5124
|
-
createTextIndex,
|
|
5125
|
-
createCheckOutItem,
|
|
5126
|
-
getCheckOutItems,
|
|
5127
|
-
getCheckOutItemById
|
|
5128
|
-
};
|
|
5129
|
-
}
|
|
5130
|
-
|
|
5131
|
-
// src/services/hygiene-checkout-item.service.ts
|
|
5132
|
-
var import_core2 = require("@7365admin1/core");
|
|
5133
|
-
var import_node_server_utils31 = require("@7365admin1/node-server-utils");
|
|
5134
|
-
function useCheckOutItemService() {
|
|
5135
|
-
const {
|
|
5136
|
-
createCheckOutItem: _createCheckOutItem,
|
|
5137
|
-
getCheckOutItemById: _getCheckOutItemById
|
|
5138
|
-
} = useCheckOutItemRepository();
|
|
5139
|
-
const { getSupplyById } = useSupplyRepository();
|
|
5140
|
-
const { getUserById } = (0, import_core2.useUserRepo)();
|
|
5141
|
-
const { createStock } = useStockService();
|
|
5142
|
-
async function createCheckOutItem(value) {
|
|
5143
|
-
const session = import_node_server_utils31.useAtlas.getClient()?.startSession();
|
|
5144
|
-
try {
|
|
5145
|
-
session?.startTransaction();
|
|
5146
|
-
const supplyData = await getSupplyById(value.supply);
|
|
5147
|
-
const createdByData = await getUserById(value.createdBy);
|
|
5148
|
-
const checkOutItemId = await _createCheckOutItem(
|
|
5149
|
-
{
|
|
5150
|
-
...value,
|
|
5151
|
-
supplyName: supplyData?.name || "",
|
|
5152
|
-
createdByName: createdByData?.name || ""
|
|
5153
|
-
},
|
|
5154
|
-
session
|
|
5155
|
-
);
|
|
5156
|
-
const checkOutItem = await _getCheckOutItemById(checkOutItemId, session);
|
|
5157
|
-
if (!checkOutItem) {
|
|
5158
|
-
throw new import_node_server_utils31.BadRequestError("Failed to create check out item.");
|
|
5159
|
-
}
|
|
5160
|
-
const createdStocks = await createStock(
|
|
5161
|
-
{
|
|
5162
|
-
site: checkOutItem.site.toString(),
|
|
5163
|
-
supply: checkOutItem.supply.toString(),
|
|
5164
|
-
qty: checkOutItem.qty
|
|
5165
|
-
},
|
|
5166
|
-
true,
|
|
5167
|
-
session
|
|
5168
|
-
);
|
|
5169
|
-
await session?.commitTransaction();
|
|
5170
|
-
return createdStocks;
|
|
5171
|
-
} catch (error) {
|
|
5172
|
-
await session?.abortTransaction();
|
|
5173
|
-
throw error;
|
|
5174
|
-
} finally {
|
|
5175
|
-
await session?.endSession();
|
|
5176
|
-
}
|
|
5177
|
-
}
|
|
5178
|
-
async function createCheckOutItemByBatch(value) {
|
|
5179
|
-
const session = import_node_server_utils31.useAtlas.getClient()?.startSession();
|
|
5180
|
-
try {
|
|
5181
|
-
session?.startTransaction();
|
|
5182
|
-
const { site, createdBy, items } = value;
|
|
5183
|
-
const createdByData = await getUserById(createdBy);
|
|
5184
|
-
const createdCheckOutItemIds = [];
|
|
5185
|
-
for (const item of items) {
|
|
5186
|
-
const supplyData = await getSupplyById(item.supply, session);
|
|
5187
|
-
const createdId = await _createCheckOutItem(
|
|
5188
|
-
{
|
|
5189
|
-
site,
|
|
5190
|
-
supply: item.supply,
|
|
5191
|
-
supplyName: supplyData?.name || "",
|
|
5192
|
-
qty: item.qty,
|
|
5193
|
-
attachment: item.attachment || "",
|
|
5194
|
-
createdBy,
|
|
5195
|
-
createdByName: createdByData?.name || ""
|
|
5196
|
-
},
|
|
5197
|
-
session
|
|
5198
|
-
);
|
|
5199
|
-
await createStock(
|
|
5200
|
-
{
|
|
5201
|
-
site,
|
|
5202
|
-
supply: item.supply,
|
|
5203
|
-
qty: item.qty
|
|
5204
|
-
},
|
|
5205
|
-
true,
|
|
5206
|
-
session
|
|
5207
|
-
);
|
|
5208
|
-
createdCheckOutItemIds.push(createdId);
|
|
5209
|
-
}
|
|
5210
|
-
await session?.commitTransaction();
|
|
5211
|
-
return createdCheckOutItemIds;
|
|
5212
|
-
} catch (error) {
|
|
5213
|
-
await session?.abortTransaction();
|
|
5214
|
-
throw error;
|
|
5215
|
-
} finally {
|
|
5216
|
-
await session?.endSession();
|
|
5217
|
-
}
|
|
5218
|
-
}
|
|
5219
|
-
return {
|
|
5220
|
-
createCheckOutItem,
|
|
5221
|
-
createCheckOutItemByBatch
|
|
5222
|
-
};
|
|
5223
|
-
}
|
|
5224
|
-
|
|
5225
|
-
// src/controllers/hygiene-checkout-item.controller.ts
|
|
5226
|
-
var import_joi17 = __toESM(require("joi"));
|
|
5227
|
-
var import_node_server_utils32 = require("@7365admin1/node-server-utils");
|
|
5228
|
-
function useCheckOutItemController() {
|
|
5229
|
-
const {
|
|
5230
|
-
getCheckOutItems: _getCheckOutItems,
|
|
5231
|
-
getCheckOutItemById: _getCheckOutItemById
|
|
5232
|
-
} = useCheckOutItemRepository();
|
|
5233
|
-
const {
|
|
5234
|
-
createCheckOutItem: _createCheckOutItem,
|
|
5235
|
-
createCheckOutItemByBatch: _createCheckOutItemByBatch
|
|
5236
|
-
} = useCheckOutItemService();
|
|
5237
|
-
async function createCheckOutItem(req, res, next) {
|
|
5238
|
-
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
5239
|
-
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
5240
|
-
{}
|
|
5241
|
-
) : {};
|
|
5242
|
-
const createdBy = cookies["user"] || "";
|
|
5243
|
-
const payload = {
|
|
5244
|
-
...req.body,
|
|
5245
|
-
...req.params,
|
|
5246
|
-
createdBy
|
|
5247
|
-
};
|
|
5248
|
-
const validation = import_joi17.default.object({
|
|
5249
|
-
site: import_joi17.default.string().hex().required(),
|
|
5250
|
-
supply: import_joi17.default.string().hex().required(),
|
|
5251
|
-
qty: import_joi17.default.number().min(0).required(),
|
|
5252
|
-
attachment: import_joi17.default.string().optional().allow("", null),
|
|
5253
|
-
createdBy: import_joi17.default.string().hex().required()
|
|
5254
|
-
});
|
|
5255
|
-
const { error } = validation.validate(payload);
|
|
5256
|
-
if (error) {
|
|
5257
|
-
import_node_server_utils32.logger.log({ level: "error", message: error.message });
|
|
5258
|
-
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
5259
|
-
return;
|
|
5260
|
-
}
|
|
5261
|
-
try {
|
|
5262
|
-
const id = await _createCheckOutItem(payload);
|
|
5263
|
-
res.status(201).json({ message: "Check out item created successfully.", id });
|
|
5264
|
-
return;
|
|
5265
|
-
} catch (error2) {
|
|
5266
|
-
import_node_server_utils32.logger.log({ level: "error", message: error2.message });
|
|
5267
|
-
next(error2);
|
|
5268
|
-
return;
|
|
5269
|
-
}
|
|
5270
|
-
}
|
|
5271
|
-
async function createCheckOutItemByBatch(req, res, next) {
|
|
5272
|
-
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
5273
|
-
(acc, [key, value]) => ({ ...acc, [key]: value }),
|
|
5274
|
-
{}
|
|
5275
|
-
) : {};
|
|
5276
|
-
const createdBy = cookies["user"] || "";
|
|
5277
|
-
const payload = {
|
|
5278
|
-
...req.body,
|
|
5279
|
-
...req.params,
|
|
5280
|
-
createdBy
|
|
5281
|
-
};
|
|
5282
|
-
const validation = import_joi17.default.object({
|
|
5283
|
-
site: import_joi17.default.string().hex().required(),
|
|
5284
|
-
createdBy: import_joi17.default.string().hex().required(),
|
|
5285
|
-
items: import_joi17.default.array().items(
|
|
5286
|
-
import_joi17.default.object({
|
|
5287
|
-
supply: import_joi17.default.string().hex().required(),
|
|
5288
|
-
qty: import_joi17.default.number().min(0).required(),
|
|
5289
|
-
attachment: import_joi17.default.string().optional().allow("", null)
|
|
5290
|
-
})
|
|
5291
|
-
).min(1).required()
|
|
5292
|
-
});
|
|
5293
|
-
const { error } = validation.validate(payload);
|
|
5294
|
-
if (error) {
|
|
5295
|
-
import_node_server_utils32.logger.log({ level: "error", message: error.message });
|
|
5296
|
-
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
5297
|
-
return;
|
|
5298
|
-
}
|
|
5299
|
-
try {
|
|
5300
|
-
await _createCheckOutItemByBatch(payload);
|
|
5301
|
-
res.status(201).json({ message: "Check out items created successfully." });
|
|
5302
|
-
return;
|
|
5303
|
-
} catch (error2) {
|
|
5304
|
-
import_node_server_utils32.logger.log({ level: "error", message: error2.message });
|
|
5305
|
-
next(error2);
|
|
5306
|
-
return;
|
|
5307
|
-
}
|
|
5308
|
-
}
|
|
5309
|
-
async function getCheckOutItems(req, res, next) {
|
|
5310
|
-
const query = { ...req.query, ...req.params };
|
|
5311
|
-
const validation = import_joi17.default.object({
|
|
5312
|
-
page: import_joi17.default.number().min(1).optional().allow("", null),
|
|
5313
|
-
limit: import_joi17.default.number().min(1).optional().allow("", null),
|
|
5314
|
-
search: import_joi17.default.string().optional().allow("", null),
|
|
5315
|
-
site: import_joi17.default.string().hex().required()
|
|
5316
|
-
});
|
|
5317
|
-
const { error } = validation.validate(query);
|
|
5318
|
-
if (error) {
|
|
5319
|
-
import_node_server_utils32.logger.log({ level: "error", message: error.message });
|
|
5320
|
-
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
5321
|
-
return;
|
|
5322
|
-
}
|
|
5323
|
-
const page = parseInt(req.query.page) ?? 1;
|
|
5324
|
-
const limit = parseInt(req.query.limit) ?? 10;
|
|
5325
|
-
const search = req.query.search ?? "";
|
|
5326
|
-
const site = req.params.site ?? "";
|
|
5327
|
-
try {
|
|
5328
|
-
const data = await _getCheckOutItems({
|
|
5329
|
-
page,
|
|
5330
|
-
limit,
|
|
5331
|
-
search,
|
|
5332
|
-
site
|
|
5333
|
-
});
|
|
5334
|
-
res.json(data);
|
|
5335
|
-
return;
|
|
5336
|
-
} catch (error2) {
|
|
5337
|
-
import_node_server_utils32.logger.log({ level: "error", message: error2.message });
|
|
5338
|
-
next(error2);
|
|
5339
|
-
return;
|
|
5340
|
-
}
|
|
5341
|
-
}
|
|
5342
|
-
async function getCheckOutItemById(req, res, next) {
|
|
5343
|
-
const validation = import_joi17.default.string().hex().required();
|
|
5344
|
-
const _id = req.params.id;
|
|
5345
|
-
const { error, value } = validation.validate(_id);
|
|
5346
|
-
if (error) {
|
|
5347
|
-
import_node_server_utils32.logger.log({ level: "error", message: error.message });
|
|
5348
|
-
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
5349
|
-
return;
|
|
5350
|
-
}
|
|
5351
|
-
try {
|
|
5352
|
-
const data = await _getCheckOutItemById(value);
|
|
5353
|
-
res.json(data);
|
|
5354
|
-
return;
|
|
5355
|
-
} catch (error2) {
|
|
5356
|
-
import_node_server_utils32.logger.log({ level: "error", message: error2.message });
|
|
5357
|
-
next(error2);
|
|
5358
|
-
return;
|
|
5359
|
-
}
|
|
5360
|
-
}
|
|
5361
|
-
return {
|
|
5362
|
-
createCheckOutItem,
|
|
5363
|
-
createCheckOutItemByBatch,
|
|
5364
|
-
getCheckOutItems,
|
|
5365
|
-
getCheckOutItemById
|
|
5366
|
-
};
|
|
5367
|
-
}
|
|
5368
|
-
|
|
5369
|
-
// src/models/hygiene-schedule-task.model.ts
|
|
5370
|
-
var import_node_server_utils33 = require("@7365admin1/node-server-utils");
|
|
5371
|
-
var import_joi18 = __toESM(require("joi"));
|
|
5372
|
-
var import_mongodb18 = require("mongodb");
|
|
5373
|
-
var scheduleTaskSchema = import_joi18.default.object({
|
|
5374
|
-
site: import_joi18.default.string().hex().required(),
|
|
5375
|
-
title: import_joi18.default.string().required(),
|
|
5376
|
-
time: import_joi18.default.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).required(),
|
|
5377
|
-
startDate: import_joi18.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).required(),
|
|
5378
|
-
endDate: import_joi18.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
|
|
5379
|
-
description: import_joi18.default.string().optional().allow("", null),
|
|
5380
|
-
areas: import_joi18.default.array().min(1).items(
|
|
5381
|
-
import_joi18.default.object({
|
|
5382
|
-
name: import_joi18.default.string().required(),
|
|
5383
|
-
value: import_joi18.default.any().required()
|
|
5384
|
-
})
|
|
5385
|
-
).required(),
|
|
5386
|
-
createdBy: import_joi18.default.string().hex().required()
|
|
4793
|
+
title: import_joi16.default.string().required(),
|
|
4794
|
+
time: import_joi16.default.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).required(),
|
|
4795
|
+
startDate: import_joi16.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).required(),
|
|
4796
|
+
endDate: import_joi16.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
|
|
4797
|
+
description: import_joi16.default.string().optional().allow("", null),
|
|
4798
|
+
areas: import_joi16.default.array().min(1).items(
|
|
4799
|
+
import_joi16.default.object({
|
|
4800
|
+
name: import_joi16.default.string().required(),
|
|
4801
|
+
value: import_joi16.default.any().required()
|
|
4802
|
+
})
|
|
4803
|
+
).required(),
|
|
4804
|
+
createdBy: import_joi16.default.string().hex().required()
|
|
5387
4805
|
});
|
|
5388
4806
|
function MScheduleTask(value) {
|
|
5389
4807
|
const { error } = scheduleTaskSchema.validate(value);
|
|
5390
4808
|
if (error) {
|
|
5391
|
-
|
|
5392
|
-
throw new
|
|
4809
|
+
import_node_server_utils29.logger.info(`Hygiene Schedule Task Model: ${error.message}`);
|
|
4810
|
+
throw new import_node_server_utils29.BadRequestError(error.message);
|
|
5393
4811
|
}
|
|
5394
4812
|
if (value.site) {
|
|
5395
4813
|
try {
|
|
5396
|
-
value.site = new
|
|
4814
|
+
value.site = new import_mongodb16.ObjectId(value.site);
|
|
5397
4815
|
} catch (error2) {
|
|
5398
|
-
throw new
|
|
4816
|
+
throw new import_node_server_utils29.BadRequestError("Invalid site ID format.");
|
|
5399
4817
|
}
|
|
5400
4818
|
}
|
|
5401
4819
|
if (value.areas && Array.isArray(value.areas)) {
|
|
@@ -5403,18 +4821,18 @@ function MScheduleTask(value) {
|
|
|
5403
4821
|
try {
|
|
5404
4822
|
return {
|
|
5405
4823
|
name: area.name,
|
|
5406
|
-
value: new
|
|
4824
|
+
value: new import_mongodb16.ObjectId(area.value.toString())
|
|
5407
4825
|
};
|
|
5408
4826
|
} catch (error2) {
|
|
5409
|
-
throw new
|
|
4827
|
+
throw new import_node_server_utils29.BadRequestError(`Invalid area value format: ${area.name}`);
|
|
5410
4828
|
}
|
|
5411
4829
|
});
|
|
5412
4830
|
}
|
|
5413
4831
|
if (value.createdBy) {
|
|
5414
4832
|
try {
|
|
5415
|
-
value.createdBy = new
|
|
4833
|
+
value.createdBy = new import_mongodb16.ObjectId(value.createdBy);
|
|
5416
4834
|
} catch (error2) {
|
|
5417
|
-
throw new
|
|
4835
|
+
throw new import_node_server_utils29.BadRequestError("Invalid createdBy ID format.");
|
|
5418
4836
|
}
|
|
5419
4837
|
}
|
|
5420
4838
|
return {
|
|
@@ -5434,16 +4852,16 @@ function MScheduleTask(value) {
|
|
|
5434
4852
|
}
|
|
5435
4853
|
|
|
5436
4854
|
// src/repositories/hygiene-schedule-task.repository.ts
|
|
5437
|
-
var
|
|
5438
|
-
var
|
|
4855
|
+
var import_mongodb17 = require("mongodb");
|
|
4856
|
+
var import_node_server_utils30 = require("@7365admin1/node-server-utils");
|
|
5439
4857
|
function useScheduleTaskRepository() {
|
|
5440
|
-
const db =
|
|
4858
|
+
const db = import_node_server_utils30.useAtlas.getDb();
|
|
5441
4859
|
if (!db) {
|
|
5442
|
-
throw new
|
|
4860
|
+
throw new import_node_server_utils30.InternalServerError("Unable to connect to server.");
|
|
5443
4861
|
}
|
|
5444
4862
|
const namespace_collection = "site.schedule-tasks";
|
|
5445
4863
|
const collection = db.collection(namespace_collection);
|
|
5446
|
-
const { delNamespace, setCache, getCache } = (0,
|
|
4864
|
+
const { delNamespace, setCache, getCache } = (0, import_node_server_utils30.useCache)(namespace_collection);
|
|
5447
4865
|
async function createIndex() {
|
|
5448
4866
|
try {
|
|
5449
4867
|
await collection.createIndexes([
|
|
@@ -5451,7 +4869,7 @@ function useScheduleTaskRepository() {
|
|
|
5451
4869
|
{ key: { status: 1 } }
|
|
5452
4870
|
]);
|
|
5453
4871
|
} catch (error) {
|
|
5454
|
-
throw new
|
|
4872
|
+
throw new import_node_server_utils30.InternalServerError(
|
|
5455
4873
|
"Failed to create index on hygiene schedule task."
|
|
5456
4874
|
);
|
|
5457
4875
|
}
|
|
@@ -5460,7 +4878,7 @@ function useScheduleTaskRepository() {
|
|
|
5460
4878
|
try {
|
|
5461
4879
|
await collection.createIndex({ title: "text", description: "text" });
|
|
5462
4880
|
} catch (error) {
|
|
5463
|
-
throw new
|
|
4881
|
+
throw new import_node_server_utils30.InternalServerError(
|
|
5464
4882
|
"Failed to create text index on hygiene schedule task."
|
|
5465
4883
|
);
|
|
5466
4884
|
}
|
|
@@ -5470,9 +4888,9 @@ function useScheduleTaskRepository() {
|
|
|
5470
4888
|
value = MScheduleTask(value);
|
|
5471
4889
|
const res = await collection.insertOne(value, { session });
|
|
5472
4890
|
delNamespace().then(() => {
|
|
5473
|
-
|
|
4891
|
+
import_node_server_utils30.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5474
4892
|
}).catch((err) => {
|
|
5475
|
-
|
|
4893
|
+
import_node_server_utils30.logger.error(
|
|
5476
4894
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5477
4895
|
err
|
|
5478
4896
|
);
|
|
@@ -5497,20 +4915,20 @@ function useScheduleTaskRepository() {
|
|
|
5497
4915
|
limit
|
|
5498
4916
|
};
|
|
5499
4917
|
try {
|
|
5500
|
-
site = new
|
|
4918
|
+
site = new import_mongodb17.ObjectId(site);
|
|
5501
4919
|
query.site = site;
|
|
5502
4920
|
cacheOptions.site = site.toString();
|
|
5503
4921
|
} catch (error) {
|
|
5504
|
-
throw new
|
|
4922
|
+
throw new import_node_server_utils30.BadRequestError("Invalid site ID format.");
|
|
5505
4923
|
}
|
|
5506
4924
|
if (search) {
|
|
5507
4925
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
5508
4926
|
cacheOptions.search = search;
|
|
5509
4927
|
}
|
|
5510
|
-
const cacheKey = (0,
|
|
4928
|
+
const cacheKey = (0, import_node_server_utils30.makeCacheKey)(namespace_collection, cacheOptions);
|
|
5511
4929
|
const cachedData = await getCache(cacheKey);
|
|
5512
4930
|
if (cachedData) {
|
|
5513
|
-
|
|
4931
|
+
import_node_server_utils30.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5514
4932
|
return cachedData;
|
|
5515
4933
|
}
|
|
5516
4934
|
try {
|
|
@@ -5528,11 +4946,11 @@ function useScheduleTaskRepository() {
|
|
|
5528
4946
|
{ $limit: limit }
|
|
5529
4947
|
]).toArray();
|
|
5530
4948
|
const length = await collection.countDocuments(query);
|
|
5531
|
-
const data = (0,
|
|
4949
|
+
const data = (0, import_node_server_utils30.paginate)(items, page, limit, length);
|
|
5532
4950
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5533
|
-
|
|
4951
|
+
import_node_server_utils30.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5534
4952
|
}).catch((err) => {
|
|
5535
|
-
|
|
4953
|
+
import_node_server_utils30.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5536
4954
|
});
|
|
5537
4955
|
return data;
|
|
5538
4956
|
} catch (error) {
|
|
@@ -5565,20 +4983,20 @@ function useScheduleTaskRepository() {
|
|
|
5565
4983
|
limit
|
|
5566
4984
|
};
|
|
5567
4985
|
try {
|
|
5568
|
-
site = new
|
|
4986
|
+
site = new import_mongodb17.ObjectId(site);
|
|
5569
4987
|
query.site = site;
|
|
5570
4988
|
cacheOptions.site = site.toString();
|
|
5571
4989
|
} catch (error) {
|
|
5572
|
-
throw new
|
|
4990
|
+
throw new import_node_server_utils30.BadRequestError("Invalid site ID format.");
|
|
5573
4991
|
}
|
|
5574
4992
|
if (search) {
|
|
5575
4993
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
5576
4994
|
cacheOptions.search = search;
|
|
5577
4995
|
}
|
|
5578
|
-
const cacheKey = (0,
|
|
4996
|
+
const cacheKey = (0, import_node_server_utils30.makeCacheKey)(namespace_collection, cacheOptions);
|
|
5579
4997
|
const cachedData = await getCache(cacheKey);
|
|
5580
4998
|
if (cachedData) {
|
|
5581
|
-
|
|
4999
|
+
import_node_server_utils30.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5582
5000
|
return cachedData;
|
|
5583
5001
|
}
|
|
5584
5002
|
try {
|
|
@@ -5595,11 +5013,11 @@ function useScheduleTaskRepository() {
|
|
|
5595
5013
|
{ $limit: limit }
|
|
5596
5014
|
]).toArray();
|
|
5597
5015
|
const length = await collection.countDocuments(query);
|
|
5598
|
-
const data = (0,
|
|
5016
|
+
const data = (0, import_node_server_utils30.paginate)(items, page, limit, length);
|
|
5599
5017
|
setCache(cacheKey, data, 15 * 60).then(() => {
|
|
5600
|
-
|
|
5018
|
+
import_node_server_utils30.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5601
5019
|
}).catch((err) => {
|
|
5602
|
-
|
|
5020
|
+
import_node_server_utils30.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5603
5021
|
});
|
|
5604
5022
|
return data;
|
|
5605
5023
|
} catch (error) {
|
|
@@ -5608,25 +5026,25 @@ function useScheduleTaskRepository() {
|
|
|
5608
5026
|
}
|
|
5609
5027
|
async function getScheduleTaskById(_id, session) {
|
|
5610
5028
|
try {
|
|
5611
|
-
_id = new
|
|
5029
|
+
_id = new import_mongodb17.ObjectId(_id);
|
|
5612
5030
|
} catch (error) {
|
|
5613
|
-
throw new
|
|
5031
|
+
throw new import_node_server_utils30.BadRequestError("Invalid schedule task ID format.");
|
|
5614
5032
|
}
|
|
5615
5033
|
const query = {
|
|
5616
5034
|
_id,
|
|
5617
5035
|
status: { $ne: "deleted" }
|
|
5618
5036
|
};
|
|
5619
|
-
const cacheKey = (0,
|
|
5037
|
+
const cacheKey = (0, import_node_server_utils30.makeCacheKey)(namespace_collection, {
|
|
5620
5038
|
_id: _id.toString()
|
|
5621
5039
|
});
|
|
5622
5040
|
if (!session) {
|
|
5623
5041
|
const cachedData = await getCache(cacheKey);
|
|
5624
5042
|
if (cachedData) {
|
|
5625
|
-
|
|
5043
|
+
import_node_server_utils30.logger.info(`Cache hit for key: ${cacheKey}`);
|
|
5626
5044
|
return cachedData;
|
|
5627
5045
|
}
|
|
5628
5046
|
} else {
|
|
5629
|
-
|
|
5047
|
+
import_node_server_utils30.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
|
|
5630
5048
|
}
|
|
5631
5049
|
try {
|
|
5632
5050
|
const data = await collection.aggregate([
|
|
@@ -5645,12 +5063,12 @@ function useScheduleTaskRepository() {
|
|
|
5645
5063
|
}
|
|
5646
5064
|
]).toArray();
|
|
5647
5065
|
if (!data || data.length === 0) {
|
|
5648
|
-
throw new
|
|
5066
|
+
throw new import_node_server_utils30.NotFoundError("Schedule task not found.");
|
|
5649
5067
|
}
|
|
5650
5068
|
setCache(cacheKey, data[0], 15 * 60).then(() => {
|
|
5651
|
-
|
|
5069
|
+
import_node_server_utils30.logger.info(`Cache set for key: ${cacheKey}`);
|
|
5652
5070
|
}).catch((err) => {
|
|
5653
|
-
|
|
5071
|
+
import_node_server_utils30.logger.error(`Failed to set cache for key: ${cacheKey}`, err);
|
|
5654
5072
|
});
|
|
5655
5073
|
return data[0];
|
|
5656
5074
|
} catch (error) {
|
|
@@ -5659,19 +5077,19 @@ function useScheduleTaskRepository() {
|
|
|
5659
5077
|
}
|
|
5660
5078
|
async function updateScheduleTask(_id, value, session) {
|
|
5661
5079
|
try {
|
|
5662
|
-
_id = new
|
|
5080
|
+
_id = new import_mongodb17.ObjectId(_id);
|
|
5663
5081
|
} catch (error) {
|
|
5664
|
-
throw new
|
|
5082
|
+
throw new import_node_server_utils30.BadRequestError("Invalid schedule task ID format.");
|
|
5665
5083
|
}
|
|
5666
5084
|
if (value.areas && Array.isArray(value.areas)) {
|
|
5667
5085
|
value.areas = value.areas.map((area) => {
|
|
5668
5086
|
try {
|
|
5669
5087
|
return {
|
|
5670
5088
|
name: area.name,
|
|
5671
|
-
value: new
|
|
5089
|
+
value: new import_mongodb17.ObjectId(area.value.toString())
|
|
5672
5090
|
};
|
|
5673
5091
|
} catch (error) {
|
|
5674
|
-
throw new
|
|
5092
|
+
throw new import_node_server_utils30.BadRequestError(`Invalid area value format: ${area.name}`);
|
|
5675
5093
|
}
|
|
5676
5094
|
});
|
|
5677
5095
|
}
|
|
@@ -5683,14 +5101,14 @@ function useScheduleTaskRepository() {
|
|
|
5683
5101
|
{ session }
|
|
5684
5102
|
);
|
|
5685
5103
|
if (res.modifiedCount === 0) {
|
|
5686
|
-
throw new
|
|
5104
|
+
throw new import_node_server_utils30.InternalServerError(
|
|
5687
5105
|
"Unable to update hygiene schedule task."
|
|
5688
5106
|
);
|
|
5689
5107
|
}
|
|
5690
5108
|
delNamespace().then(() => {
|
|
5691
|
-
|
|
5109
|
+
import_node_server_utils30.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
5692
5110
|
}).catch((err) => {
|
|
5693
|
-
|
|
5111
|
+
import_node_server_utils30.logger.error(
|
|
5694
5112
|
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
5695
5113
|
err
|
|
5696
5114
|
);
|
|
@@ -5713,7 +5131,7 @@ function useScheduleTaskRepository() {
|
|
|
5713
5131
|
}
|
|
5714
5132
|
|
|
5715
5133
|
// src/services/hygiene-schedule-task.service.ts
|
|
5716
|
-
var
|
|
5134
|
+
var import_node_server_utils31 = require("@7365admin1/node-server-utils");
|
|
5717
5135
|
function useScheduleTaskService() {
|
|
5718
5136
|
const { createParentChecklist } = useParentChecklistRepo();
|
|
5719
5137
|
const { getAllScheduleTask } = useScheduleTaskRepository();
|
|
@@ -5736,13 +5154,13 @@ function useScheduleTaskService() {
|
|
|
5736
5154
|
const currentDateString = now.toLocaleDateString("en-US", {
|
|
5737
5155
|
timeZone: "Asia/Singapore"
|
|
5738
5156
|
});
|
|
5739
|
-
|
|
5157
|
+
import_node_server_utils31.logger.info(
|
|
5740
5158
|
`Checking schedule ${schedule._id}: Current time ${currentHour}:${currentMinute}, Current date ${currentDateString}, Schedule time ${schedule.time}, Start date ${schedule.startDate}, End date ${schedule.endDate}`
|
|
5741
5159
|
);
|
|
5742
5160
|
const startDate = /* @__PURE__ */ new Date(schedule.startDate + "T00:00:00");
|
|
5743
5161
|
const currentDateOnly = /* @__PURE__ */ new Date(currentDateString + "T00:00:00");
|
|
5744
5162
|
if (currentDateOnly < startDate) {
|
|
5745
|
-
|
|
5163
|
+
import_node_server_utils31.logger.info(
|
|
5746
5164
|
`Schedule ${schedule._id}: Current date ${currentDateString} is before start date ${schedule.startDate}`
|
|
5747
5165
|
);
|
|
5748
5166
|
return false;
|
|
@@ -5750,7 +5168,7 @@ function useScheduleTaskService() {
|
|
|
5750
5168
|
if (schedule.endDate) {
|
|
5751
5169
|
const endDate = /* @__PURE__ */ new Date(schedule.endDate + "T00:00:00");
|
|
5752
5170
|
if (currentDateOnly > endDate) {
|
|
5753
|
-
|
|
5171
|
+
import_node_server_utils31.logger.info(
|
|
5754
5172
|
`Schedule ${schedule._id}: Current date ${currentDateString} is after end date ${schedule.endDate}`
|
|
5755
5173
|
);
|
|
5756
5174
|
return false;
|
|
@@ -5759,17 +5177,17 @@ function useScheduleTaskService() {
|
|
|
5759
5177
|
const [scheduleHour, scheduleMinute] = schedule.time.split(":").map(Number);
|
|
5760
5178
|
const timeMatches = currentHour === scheduleHour && currentMinute === scheduleMinute;
|
|
5761
5179
|
if (!timeMatches) {
|
|
5762
|
-
|
|
5180
|
+
import_node_server_utils31.logger.info(
|
|
5763
5181
|
`Schedule ${schedule._id}: Time does not match. Current: ${currentHour}:${currentMinute}, Expected: ${scheduleHour}:${scheduleMinute}`
|
|
5764
5182
|
);
|
|
5765
5183
|
return false;
|
|
5766
5184
|
}
|
|
5767
|
-
|
|
5185
|
+
import_node_server_utils31.logger.info(
|
|
5768
5186
|
`Schedule ${schedule._id}: All conditions matched - Date is within range and time matches`
|
|
5769
5187
|
);
|
|
5770
5188
|
return true;
|
|
5771
5189
|
} catch (error) {
|
|
5772
|
-
|
|
5190
|
+
import_node_server_utils31.logger.error(
|
|
5773
5191
|
`Error checking schedule conditions for ${schedule._id}:`,
|
|
5774
5192
|
error
|
|
5775
5193
|
);
|
|
@@ -5778,40 +5196,40 @@ function useScheduleTaskService() {
|
|
|
5778
5196
|
}
|
|
5779
5197
|
async function processScheduledTasks(currentDate) {
|
|
5780
5198
|
try {
|
|
5781
|
-
|
|
5199
|
+
import_node_server_utils31.logger.info("Starting scheduled task processing...");
|
|
5782
5200
|
const scheduleTasks = await getAllScheduleTask();
|
|
5783
5201
|
if (!scheduleTasks || scheduleTasks.length === 0) {
|
|
5784
|
-
|
|
5202
|
+
import_node_server_utils31.logger.info("No schedule tasks found to process");
|
|
5785
5203
|
return { processed: 0, validated: 0 };
|
|
5786
5204
|
}
|
|
5787
|
-
|
|
5205
|
+
import_node_server_utils31.logger.info(`Found ${scheduleTasks.length} schedule tasks to check`);
|
|
5788
5206
|
let processedCount = 0;
|
|
5789
5207
|
let validatedCount = 0;
|
|
5790
5208
|
const validatedTasks = [];
|
|
5791
5209
|
for (const scheduleTask of scheduleTasks) {
|
|
5792
5210
|
try {
|
|
5793
|
-
|
|
5211
|
+
import_node_server_utils31.logger.info(
|
|
5794
5212
|
`Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time}, startDate=${scheduleTask.startDate}, endDate=${scheduleTask.endDate}`
|
|
5795
5213
|
);
|
|
5796
5214
|
const shouldRun = checkScheduleConditions(scheduleTask, currentDate);
|
|
5797
5215
|
if (!shouldRun) {
|
|
5798
|
-
|
|
5216
|
+
import_node_server_utils31.logger.info(
|
|
5799
5217
|
`Schedule ${scheduleTask._id} conditions not met, skipping`
|
|
5800
5218
|
);
|
|
5801
5219
|
continue;
|
|
5802
5220
|
}
|
|
5803
|
-
|
|
5221
|
+
import_node_server_utils31.logger.info(
|
|
5804
5222
|
`Schedule ${scheduleTask._id} conditions validated, creating area checklists`
|
|
5805
5223
|
);
|
|
5806
5224
|
if (!scheduleTask._id) {
|
|
5807
|
-
|
|
5225
|
+
import_node_server_utils31.logger.warn(`Schedule ${scheduleTask.title} has no _id, skipping`);
|
|
5808
5226
|
continue;
|
|
5809
5227
|
}
|
|
5810
5228
|
if (!scheduleTask.site) {
|
|
5811
|
-
|
|
5229
|
+
import_node_server_utils31.logger.warn(`Schedule ${scheduleTask._id} has no site, skipping`);
|
|
5812
5230
|
continue;
|
|
5813
5231
|
}
|
|
5814
|
-
|
|
5232
|
+
import_node_server_utils31.logger.info(
|
|
5815
5233
|
`Getting or creating parent checklist for schedule ${scheduleTask._id} in site ${scheduleTask.site}`
|
|
5816
5234
|
);
|
|
5817
5235
|
const parentChecklistIds = await createParentChecklist({
|
|
@@ -5819,7 +5237,7 @@ function useScheduleTaskService() {
|
|
|
5819
5237
|
createdAt: /* @__PURE__ */ new Date()
|
|
5820
5238
|
});
|
|
5821
5239
|
const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
|
|
5822
|
-
|
|
5240
|
+
import_node_server_utils31.logger.info(
|
|
5823
5241
|
`Using parent checklist ${parentChecklistId}, now creating/updating area checklists`
|
|
5824
5242
|
);
|
|
5825
5243
|
for (const area of scheduleTask.areas) {
|
|
@@ -5832,14 +5250,14 @@ function useScheduleTaskService() {
|
|
|
5832
5250
|
unit: unit.unit.toString(),
|
|
5833
5251
|
name: unit.name
|
|
5834
5252
|
}));
|
|
5835
|
-
|
|
5253
|
+
import_node_server_utils31.logger.info(
|
|
5836
5254
|
`Area ${area.name} (${areaId}): Using units from area details: ${JSON.stringify(
|
|
5837
5255
|
units
|
|
5838
5256
|
)}`
|
|
5839
5257
|
);
|
|
5840
5258
|
}
|
|
5841
5259
|
if (units.length === 0) {
|
|
5842
|
-
|
|
5260
|
+
import_node_server_utils31.logger.warn(
|
|
5843
5261
|
`Area ${area.name} (${areaId}): No units found, skipping area.`
|
|
5844
5262
|
);
|
|
5845
5263
|
continue;
|
|
@@ -5850,11 +5268,11 @@ function useScheduleTaskService() {
|
|
|
5850
5268
|
parentChecklistId.toString(),
|
|
5851
5269
|
areaId
|
|
5852
5270
|
);
|
|
5853
|
-
|
|
5271
|
+
import_node_server_utils31.logger.info(
|
|
5854
5272
|
`Area ${area.name} (${areaId}): Existing area checklist found: ${existingAreaChecklist ? "Yes" : "No"}`
|
|
5855
5273
|
);
|
|
5856
5274
|
if (existingAreaChecklist) {
|
|
5857
|
-
|
|
5275
|
+
import_node_server_utils31.logger.info(
|
|
5858
5276
|
`Area ${area.name} (${areaId}): Existing checklist content: ${JSON.stringify(
|
|
5859
5277
|
existingAreaChecklist.checklist
|
|
5860
5278
|
)}`
|
|
@@ -5862,7 +5280,7 @@ function useScheduleTaskService() {
|
|
|
5862
5280
|
}
|
|
5863
5281
|
} catch (error) {
|
|
5864
5282
|
existingAreaChecklist = null;
|
|
5865
|
-
|
|
5283
|
+
import_node_server_utils31.logger.info(
|
|
5866
5284
|
`Area ${area.name} (${areaId}): No existing area checklist found (exception).`
|
|
5867
5285
|
);
|
|
5868
5286
|
}
|
|
@@ -5876,7 +5294,7 @@ function useScheduleTaskService() {
|
|
|
5876
5294
|
...existingAreaChecklist.checklist || [],
|
|
5877
5295
|
newSet
|
|
5878
5296
|
];
|
|
5879
|
-
|
|
5297
|
+
import_node_server_utils31.logger.info(
|
|
5880
5298
|
`Area ${area.name} (${areaId}): Appending new set ${newSet.set} to checklist. Updated checklist: ${JSON.stringify(
|
|
5881
5299
|
updatedChecklist
|
|
5882
5300
|
)}`
|
|
@@ -5884,7 +5302,7 @@ function useScheduleTaskService() {
|
|
|
5884
5302
|
await updateAreaChecklist(existingAreaChecklist._id, {
|
|
5885
5303
|
checklist: updatedChecklist
|
|
5886
5304
|
});
|
|
5887
|
-
|
|
5305
|
+
import_node_server_utils31.logger.info(
|
|
5888
5306
|
`Appended set ${newSet.set} to area checklist for area ${area.name}`
|
|
5889
5307
|
);
|
|
5890
5308
|
try {
|
|
@@ -5892,13 +5310,13 @@ function useScheduleTaskService() {
|
|
|
5892
5310
|
parentChecklistId.toString(),
|
|
5893
5311
|
areaId
|
|
5894
5312
|
);
|
|
5895
|
-
|
|
5313
|
+
import_node_server_utils31.logger.info(
|
|
5896
5314
|
`Area ${area.name} (${areaId}): Checklist after update: ${JSON.stringify(
|
|
5897
5315
|
verifyChecklist.checklist
|
|
5898
5316
|
)}`
|
|
5899
5317
|
);
|
|
5900
5318
|
} catch (verifyError) {
|
|
5901
|
-
|
|
5319
|
+
import_node_server_utils31.logger.warn(
|
|
5902
5320
|
`Area ${area.name} (${areaId}): Error verifying checklist after update:`,
|
|
5903
5321
|
verifyError
|
|
5904
5322
|
);
|
|
@@ -5917,50 +5335,50 @@ function useScheduleTaskService() {
|
|
|
5917
5335
|
],
|
|
5918
5336
|
createdBy: scheduleTask.createdBy
|
|
5919
5337
|
};
|
|
5920
|
-
|
|
5338
|
+
import_node_server_utils31.logger.info(
|
|
5921
5339
|
`Area ${area.name} (${areaId}): Creating new area checklist with data: ${JSON.stringify(
|
|
5922
5340
|
checklistData
|
|
5923
5341
|
)}`
|
|
5924
5342
|
);
|
|
5925
5343
|
await createAreaChecklist(checklistData);
|
|
5926
|
-
|
|
5344
|
+
import_node_server_utils31.logger.info(`Created new area checklist for area ${area.name}`);
|
|
5927
5345
|
try {
|
|
5928
5346
|
const verifyChecklist = await getAreaChecklistByAreaAndSchedule(
|
|
5929
5347
|
parentChecklistId.toString(),
|
|
5930
5348
|
areaId
|
|
5931
5349
|
);
|
|
5932
|
-
|
|
5350
|
+
import_node_server_utils31.logger.info(
|
|
5933
5351
|
`Area ${area.name} (${areaId}): Checklist after creation: ${JSON.stringify(
|
|
5934
5352
|
verifyChecklist.checklist
|
|
5935
5353
|
)}`
|
|
5936
5354
|
);
|
|
5937
5355
|
} catch (verifyError) {
|
|
5938
|
-
|
|
5356
|
+
import_node_server_utils31.logger.warn(
|
|
5939
5357
|
`Area ${area.name} (${areaId}): Error verifying checklist after creation:`,
|
|
5940
5358
|
verifyError
|
|
5941
5359
|
);
|
|
5942
5360
|
}
|
|
5943
5361
|
}
|
|
5944
5362
|
} catch (error) {
|
|
5945
|
-
|
|
5363
|
+
import_node_server_utils31.logger.error(`Error processing area ${area.name}:`, error);
|
|
5946
5364
|
continue;
|
|
5947
5365
|
}
|
|
5948
5366
|
}
|
|
5949
5367
|
processedCount++;
|
|
5950
5368
|
validatedCount++;
|
|
5951
5369
|
validatedTasks.push(scheduleTask);
|
|
5952
|
-
|
|
5370
|
+
import_node_server_utils31.logger.info(
|
|
5953
5371
|
`Successfully processed schedule ${scheduleTask._id}, created/updated area checklists for all areas.`
|
|
5954
5372
|
);
|
|
5955
5373
|
} catch (error) {
|
|
5956
|
-
|
|
5374
|
+
import_node_server_utils31.logger.error(
|
|
5957
5375
|
`Error processing schedule task ${scheduleTask._id}:`,
|
|
5958
5376
|
error
|
|
5959
5377
|
);
|
|
5960
5378
|
continue;
|
|
5961
5379
|
}
|
|
5962
5380
|
}
|
|
5963
|
-
|
|
5381
|
+
import_node_server_utils31.logger.info(
|
|
5964
5382
|
`Scheduled task processing completed. Processed: ${processedCount}, Validated: ${validatedCount} tasks`
|
|
5965
5383
|
);
|
|
5966
5384
|
return {
|
|
@@ -5969,7 +5387,7 @@ function useScheduleTaskService() {
|
|
|
5969
5387
|
tasks: validatedTasks
|
|
5970
5388
|
};
|
|
5971
5389
|
} catch (error) {
|
|
5972
|
-
|
|
5390
|
+
import_node_server_utils31.logger.error("Error processing scheduled tasks:", error);
|
|
5973
5391
|
throw error;
|
|
5974
5392
|
}
|
|
5975
5393
|
}
|
|
@@ -5977,8 +5395,8 @@ function useScheduleTaskService() {
|
|
|
5977
5395
|
}
|
|
5978
5396
|
|
|
5979
5397
|
// src/controllers/hygiene-schedule-task.controller.ts
|
|
5980
|
-
var
|
|
5981
|
-
var
|
|
5398
|
+
var import_joi17 = __toESM(require("joi"));
|
|
5399
|
+
var import_node_server_utils32 = require("@7365admin1/node-server-utils");
|
|
5982
5400
|
function useScheduleTaskController() {
|
|
5983
5401
|
const {
|
|
5984
5402
|
createScheduleTask: _createScheduleTask,
|
|
@@ -5996,8 +5414,8 @@ function useScheduleTaskController() {
|
|
|
5996
5414
|
const payload = { ...req.body, ...req.params, createdBy };
|
|
5997
5415
|
const { error } = scheduleTaskSchema.validate(payload);
|
|
5998
5416
|
if (error) {
|
|
5999
|
-
|
|
6000
|
-
next(new
|
|
5417
|
+
import_node_server_utils32.logger.log({ level: "error", message: error.message });
|
|
5418
|
+
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
6001
5419
|
return;
|
|
6002
5420
|
}
|
|
6003
5421
|
try {
|
|
@@ -6005,23 +5423,23 @@ function useScheduleTaskController() {
|
|
|
6005
5423
|
res.status(201).json({ message: "Schedule task created successfully.", id });
|
|
6006
5424
|
return;
|
|
6007
5425
|
} catch (error2) {
|
|
6008
|
-
|
|
5426
|
+
import_node_server_utils32.logger.log({ level: "error", message: error2.message });
|
|
6009
5427
|
next(error2);
|
|
6010
5428
|
return;
|
|
6011
5429
|
}
|
|
6012
5430
|
}
|
|
6013
5431
|
async function getScheduleTasks(req, res, next) {
|
|
6014
5432
|
const query = { ...req.query, ...req.params };
|
|
6015
|
-
const validation =
|
|
6016
|
-
page:
|
|
6017
|
-
limit:
|
|
6018
|
-
search:
|
|
6019
|
-
site:
|
|
5433
|
+
const validation = import_joi17.default.object({
|
|
5434
|
+
page: import_joi17.default.number().min(1).optional().allow("", null),
|
|
5435
|
+
limit: import_joi17.default.number().min(1).optional().allow("", null),
|
|
5436
|
+
search: import_joi17.default.string().optional().allow("", null),
|
|
5437
|
+
site: import_joi17.default.string().hex().required()
|
|
6020
5438
|
});
|
|
6021
5439
|
const { error } = validation.validate(query);
|
|
6022
5440
|
if (error) {
|
|
6023
|
-
|
|
6024
|
-
next(new
|
|
5441
|
+
import_node_server_utils32.logger.log({ level: "error", message: error.message });
|
|
5442
|
+
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
6025
5443
|
return;
|
|
6026
5444
|
}
|
|
6027
5445
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -6038,23 +5456,23 @@ function useScheduleTaskController() {
|
|
|
6038
5456
|
res.json(data);
|
|
6039
5457
|
return;
|
|
6040
5458
|
} catch (error2) {
|
|
6041
|
-
|
|
5459
|
+
import_node_server_utils32.logger.log({ level: "error", message: error2.message });
|
|
6042
5460
|
next(error2);
|
|
6043
5461
|
return;
|
|
6044
5462
|
}
|
|
6045
5463
|
}
|
|
6046
5464
|
async function getTasksForScheduleTask(req, res, next) {
|
|
6047
5465
|
const query = { ...req.query, ...req.params };
|
|
6048
|
-
const validation =
|
|
6049
|
-
page:
|
|
6050
|
-
limit:
|
|
6051
|
-
search:
|
|
6052
|
-
site:
|
|
5466
|
+
const validation = import_joi17.default.object({
|
|
5467
|
+
page: import_joi17.default.number().min(1).optional().allow("", null),
|
|
5468
|
+
limit: import_joi17.default.number().min(1).optional().allow("", null),
|
|
5469
|
+
search: import_joi17.default.string().optional().allow("", null),
|
|
5470
|
+
site: import_joi17.default.string().hex().required()
|
|
6053
5471
|
});
|
|
6054
5472
|
const { error } = validation.validate(query);
|
|
6055
5473
|
if (error) {
|
|
6056
|
-
|
|
6057
|
-
next(new
|
|
5474
|
+
import_node_server_utils32.logger.log({ level: "error", message: error.message });
|
|
5475
|
+
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
6058
5476
|
return;
|
|
6059
5477
|
}
|
|
6060
5478
|
const page = parseInt(req.query.page) ?? 1;
|
|
@@ -6071,18 +5489,18 @@ function useScheduleTaskController() {
|
|
|
6071
5489
|
res.json(data);
|
|
6072
5490
|
return;
|
|
6073
5491
|
} catch (error2) {
|
|
6074
|
-
|
|
5492
|
+
import_node_server_utils32.logger.log({ level: "error", message: error2.message });
|
|
6075
5493
|
next(error2);
|
|
6076
5494
|
return;
|
|
6077
5495
|
}
|
|
6078
5496
|
}
|
|
6079
5497
|
async function getScheduleTaskById(req, res, next) {
|
|
6080
|
-
const validation =
|
|
5498
|
+
const validation = import_joi17.default.string().hex().required();
|
|
6081
5499
|
const _id = req.params.id;
|
|
6082
5500
|
const { error, value } = validation.validate(_id);
|
|
6083
5501
|
if (error) {
|
|
6084
|
-
|
|
6085
|
-
next(new
|
|
5502
|
+
import_node_server_utils32.logger.log({ level: "error", message: error.message });
|
|
5503
|
+
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
6086
5504
|
return;
|
|
6087
5505
|
}
|
|
6088
5506
|
try {
|
|
@@ -6090,31 +5508,31 @@ function useScheduleTaskController() {
|
|
|
6090
5508
|
res.json(data);
|
|
6091
5509
|
return;
|
|
6092
5510
|
} catch (error2) {
|
|
6093
|
-
|
|
5511
|
+
import_node_server_utils32.logger.log({ level: "error", message: error2.message });
|
|
6094
5512
|
next(error2);
|
|
6095
5513
|
return;
|
|
6096
5514
|
}
|
|
6097
5515
|
}
|
|
6098
5516
|
async function updateScheduleTask(req, res, next) {
|
|
6099
5517
|
const payload = { id: req.params.id, ...req.body };
|
|
6100
|
-
const validation =
|
|
6101
|
-
id:
|
|
6102
|
-
title:
|
|
6103
|
-
time:
|
|
6104
|
-
startDate:
|
|
6105
|
-
endDate:
|
|
6106
|
-
description:
|
|
6107
|
-
areas:
|
|
6108
|
-
|
|
6109
|
-
name:
|
|
6110
|
-
value:
|
|
5518
|
+
const validation = import_joi17.default.object({
|
|
5519
|
+
id: import_joi17.default.string().hex().required(),
|
|
5520
|
+
title: import_joi17.default.string().optional().allow("", null),
|
|
5521
|
+
time: import_joi17.default.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).optional().allow("", null),
|
|
5522
|
+
startDate: import_joi17.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
|
|
5523
|
+
endDate: import_joi17.default.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
|
|
5524
|
+
description: import_joi17.default.string().optional().allow("", null),
|
|
5525
|
+
areas: import_joi17.default.array().min(1).items(
|
|
5526
|
+
import_joi17.default.object({
|
|
5527
|
+
name: import_joi17.default.string().required(),
|
|
5528
|
+
value: import_joi17.default.any().required()
|
|
6111
5529
|
})
|
|
6112
5530
|
).optional()
|
|
6113
5531
|
});
|
|
6114
5532
|
const { error } = validation.validate(payload);
|
|
6115
5533
|
if (error) {
|
|
6116
|
-
|
|
6117
|
-
next(new
|
|
5534
|
+
import_node_server_utils32.logger.log({ level: "error", message: error.message });
|
|
5535
|
+
next(new import_node_server_utils32.BadRequestError(error.message));
|
|
6118
5536
|
return;
|
|
6119
5537
|
}
|
|
6120
5538
|
try {
|
|
@@ -6123,7 +5541,7 @@ function useScheduleTaskController() {
|
|
|
6123
5541
|
res.json({ message: "Schedule task updated successfully." });
|
|
6124
5542
|
return;
|
|
6125
5543
|
} catch (error2) {
|
|
6126
|
-
|
|
5544
|
+
import_node_server_utils32.logger.log({ level: "error", message: error2.message });
|
|
6127
5545
|
next(error2);
|
|
6128
5546
|
return;
|
|
6129
5547
|
}
|
|
@@ -6142,7 +5560,6 @@ function useScheduleTaskController() {
|
|
|
6142
5560
|
MAreaChecklist,
|
|
6143
5561
|
MCheckOutItem,
|
|
6144
5562
|
MParentChecklist,
|
|
6145
|
-
MRequestItem,
|
|
6146
5563
|
MScheduleTask,
|
|
6147
5564
|
MStock,
|
|
6148
5565
|
MSupply,
|
|
@@ -6150,14 +5567,12 @@ function useScheduleTaskController() {
|
|
|
6150
5567
|
allowedCheckOutItemStatus,
|
|
6151
5568
|
allowedChecklistStatus,
|
|
6152
5569
|
allowedPeriods,
|
|
6153
|
-
allowedRequestItemStatus,
|
|
6154
5570
|
allowedStatus,
|
|
6155
5571
|
allowedTypes,
|
|
6156
5572
|
areaChecklistSchema,
|
|
6157
5573
|
areaSchema,
|
|
6158
5574
|
checkOutItemSchema,
|
|
6159
5575
|
parentChecklistSchema,
|
|
6160
|
-
requestItemSchema,
|
|
6161
5576
|
scheduleTaskSchema,
|
|
6162
5577
|
stockSchema,
|
|
6163
5578
|
supplySchema,
|
|
@@ -6175,9 +5590,6 @@ function useScheduleTaskController() {
|
|
|
6175
5590
|
useHygieneDashboardRepository,
|
|
6176
5591
|
useParentChecklistController,
|
|
6177
5592
|
useParentChecklistRepo,
|
|
6178
|
-
useRequestItemController,
|
|
6179
|
-
useRequestItemRepository,
|
|
6180
|
-
useRequestItemService,
|
|
6181
5593
|
useScheduleTaskController,
|
|
6182
5594
|
useScheduleTaskRepository,
|
|
6183
5595
|
useScheduleTaskService,
|