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