@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/dist/index.mjs CHANGED
@@ -1062,6 +1062,11 @@ function useAreaService() {
1062
1062
  skippedRows.push(i + 1);
1063
1063
  continue;
1064
1064
  }
1065
+ if (areaName.startsWith("Sample:")) {
1066
+ logger5.warn(`Skipping row ${i + 1} with sample area: ${areaName}`);
1067
+ skippedRows.push(i + 1);
1068
+ continue;
1069
+ }
1065
1070
  try {
1066
1071
  const insertedId = await _createArea({
1067
1072
  type: areaType,
@@ -1606,6 +1611,11 @@ function useUnitService() {
1606
1611
  skippedRows.push(i + 1);
1607
1612
  continue;
1608
1613
  }
1614
+ if (unitName.startsWith("Sample:")) {
1615
+ logger9.warn(`Skipping row ${i + 1} with sample unit: ${unitName}`);
1616
+ skippedRows.push(i + 1);
1617
+ continue;
1618
+ }
1609
1619
  try {
1610
1620
  const insertedId = await _createUnit({
1611
1621
  name: unitName,
@@ -4230,27 +4240,24 @@ function useStockController() {
4230
4240
  };
4231
4241
  }
4232
4242
 
4233
- // src/models/hygiene-request-item.model.ts
4243
+ // src/models/hygiene-checkout-item.model.ts
4234
4244
  import Joi14 from "joi";
4235
4245
  import { ObjectId as ObjectId14 } from "mongodb";
4236
4246
  import { BadRequestError as BadRequestError24, logger as logger24 } from "@7365admin1/node-server-utils";
4237
- var allowedRequestItemStatus = [
4238
- "pending",
4239
- "approved",
4240
- "disapproved"
4241
- ];
4242
- var requestItemSchema = Joi14.object({
4247
+ var allowedCheckOutItemStatus = ["pending", "completed"];
4248
+ var checkOutItemSchema = Joi14.object({
4243
4249
  site: Joi14.string().hex().required(),
4244
4250
  supply: Joi14.string().hex().required(),
4245
4251
  supplyName: Joi14.string().required(),
4246
4252
  qty: Joi14.number().min(0).required(),
4253
+ attachment: Joi14.array().items(Joi14.string()).optional().allow(null),
4247
4254
  createdBy: Joi14.string().hex().required(),
4248
4255
  createdByName: Joi14.string().required()
4249
4256
  });
4250
- function MRequestItem(value) {
4251
- const { error } = requestItemSchema.validate(value);
4257
+ function MCheckOutItem(value) {
4258
+ const { error } = checkOutItemSchema.validate(value);
4252
4259
  if (error) {
4253
- logger24.info(`Hygiene Request Item Model: ${error.message}`);
4260
+ logger24.info(`Hygiene Check Out Item Model: ${error.message}`);
4254
4261
  throw new BadRequestError24(error.message);
4255
4262
  }
4256
4263
  if (value.site) {
@@ -4272,7 +4279,7 @@ function MRequestItem(value) {
4272
4279
  supply: value.supply,
4273
4280
  supplyName: value.supplyName,
4274
4281
  qty: value.qty,
4275
- remarks: "",
4282
+ attachment: value.attachment || [],
4276
4283
  createdBy: value.createdBy,
4277
4284
  createdByName: value.createdByName,
4278
4285
  status: "pending",
@@ -4282,7 +4289,7 @@ function MRequestItem(value) {
4282
4289
  };
4283
4290
  }
4284
4291
 
4285
- // src/repositories/hygiene-request-item.repository.ts
4292
+ // src/repositories/hygiene-checkout-item.repository.ts
4286
4293
  import { ObjectId as ObjectId15 } from "mongodb";
4287
4294
  import {
4288
4295
  useAtlas as useAtlas11,
@@ -4294,12 +4301,12 @@ import {
4294
4301
  BadRequestError as BadRequestError25,
4295
4302
  NotFoundError as NotFoundError6
4296
4303
  } from "@7365admin1/node-server-utils";
4297
- function useRequestItemRepository() {
4304
+ function useCheckOutItemRepository() {
4298
4305
  const db = useAtlas11.getDb();
4299
4306
  if (!db) {
4300
4307
  throw new InternalServerError8("Unable to connect to server.");
4301
4308
  }
4302
- const namespace_collection = "site.supply.requests";
4309
+ const namespace_collection = "site.supply.checkouts";
4303
4310
  const collection = db.collection(namespace_collection);
4304
4311
  const { delNamespace, setCache, getCache } = useCache8(namespace_collection);
4305
4312
  async function createIndex() {
@@ -4311,7 +4318,7 @@ function useRequestItemRepository() {
4311
4318
  ]);
4312
4319
  } catch (error) {
4313
4320
  throw new InternalServerError8(
4314
- "Failed to create index on hygiene request item."
4321
+ "Failed to create index on hygiene check out item."
4315
4322
  );
4316
4323
  }
4317
4324
  }
@@ -4324,9 +4331,9 @@ function useRequestItemRepository() {
4324
4331
  );
4325
4332
  }
4326
4333
  }
4327
- async function createRequestItem(value, session) {
4334
+ async function createCheckOutItem(value, session) {
4328
4335
  try {
4329
- value = MRequestItem(value);
4336
+ value = MCheckOutItem(value);
4330
4337
  const res = await collection.insertOne(value, { session });
4331
4338
  delNamespace().then(() => {
4332
4339
  logger25.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -4341,7 +4348,7 @@ function useRequestItemRepository() {
4341
4348
  throw error;
4342
4349
  }
4343
4350
  }
4344
- async function getRequestItems({
4351
+ async function getCheckOutItems({
4345
4352
  page = 1,
4346
4353
  limit = 10,
4347
4354
  search = "",
@@ -4375,9 +4382,38 @@ function useRequestItemRepository() {
4375
4382
  try {
4376
4383
  const items = await collection.aggregate([
4377
4384
  { $match: query },
4385
+ {
4386
+ $lookup: {
4387
+ from: "site.supplies",
4388
+ let: { supplyId: "$supply" },
4389
+ pipeline: [
4390
+ {
4391
+ $match: {
4392
+ $expr: {
4393
+ $and: [
4394
+ { $ne: ["$$supplyId", ""] },
4395
+ { $eq: ["$_id", "$$supplyId"] }
4396
+ ]
4397
+ }
4398
+ }
4399
+ },
4400
+ { $project: { qty: 1 } }
4401
+ ],
4402
+ as: "supplyDoc"
4403
+ }
4404
+ },
4405
+ {
4406
+ $unwind: {
4407
+ path: "$supplyDoc",
4408
+ preserveNullAndEmptyArrays: true
4409
+ }
4410
+ },
4378
4411
  {
4379
4412
  $project: {
4380
4413
  supplyName: 1,
4414
+ supplyQty: "$supplyDoc.qty",
4415
+ checkOutByName: "$createdByName",
4416
+ checkOutQty: "$qty",
4381
4417
  createdAt: 1,
4382
4418
  status: 1
4383
4419
  }
@@ -4398,11 +4434,11 @@ function useRequestItemRepository() {
4398
4434
  throw error;
4399
4435
  }
4400
4436
  }
4401
- async function getRequestItemById(_id, session) {
4437
+ async function getCheckOutItemById(_id, session) {
4402
4438
  try {
4403
4439
  _id = new ObjectId15(_id);
4404
4440
  } catch (error) {
4405
- throw new BadRequestError25("Invalid request item ID format.");
4441
+ throw new BadRequestError25("Invalid check out item ID format.");
4406
4442
  }
4407
4443
  const query = { _id };
4408
4444
  const cacheKey = makeCacheKey8(namespace_collection, {
@@ -4418,35 +4454,39 @@ function useRequestItemRepository() {
4418
4454
  logger25.info(`Skipping cache during transaction for key: ${cacheKey}`);
4419
4455
  }
4420
4456
  try {
4421
- const data = await collection.aggregate([
4422
- { $match: query },
4423
- {
4424
- $lookup: {
4425
- from: "site.supply.items",
4426
- localField: "supply",
4427
- foreignField: "_id",
4428
- as: "supplyDetails"
4429
- }
4430
- },
4431
- {
4432
- $unwind: {
4433
- path: "$supplyDetails",
4434
- preserveNullAndEmptyArrays: true
4435
- }
4436
- },
4437
- {
4438
- $project: {
4439
- site: 1,
4440
- supply: 1,
4441
- supplyName: 1,
4442
- qty: 1,
4443
- status: 1,
4444
- unitOfMeasurement: "$supplyDetails.unitOfMeasurement"
4457
+ const data = await collection.aggregate(
4458
+ [
4459
+ { $match: query },
4460
+ {
4461
+ $lookup: {
4462
+ from: "site.supply.items",
4463
+ localField: "supply",
4464
+ foreignField: "_id",
4465
+ as: "supplyDetails"
4466
+ }
4467
+ },
4468
+ {
4469
+ $unwind: {
4470
+ path: "$supplyDetails",
4471
+ preserveNullAndEmptyArrays: true
4472
+ }
4473
+ },
4474
+ {
4475
+ $project: {
4476
+ site: 1,
4477
+ supply: 1,
4478
+ supplyName: 1,
4479
+ qty: 1,
4480
+ status: 1,
4481
+ unitOfMeasurement: "$supplyDetails.unitOfMeasurement",
4482
+ attachment: 1
4483
+ }
4445
4484
  }
4446
- }
4447
- ]).toArray();
4485
+ ],
4486
+ session ? { session } : void 0
4487
+ ).toArray();
4448
4488
  if (!data || data.length === 0) {
4449
- throw new NotFoundError6("Request item not found.");
4489
+ throw new NotFoundError6("Check out item not found.");
4450
4490
  }
4451
4491
  setCache(cacheKey, data[0], 15 * 60).then(() => {
4452
4492
  logger25.info(`Cache set for key: ${cacheKey}`);
@@ -4458,49 +4498,15 @@ function useRequestItemRepository() {
4458
4498
  throw error;
4459
4499
  }
4460
4500
  }
4461
- async function approveRequestItem(_id, remarks, session) {
4462
- try {
4463
- _id = new ObjectId15(_id);
4464
- } catch (error) {
4465
- throw new BadRequestError25("Invalid request item ID format.");
4466
- }
4467
- try {
4468
- const updateValue = {
4469
- status: "approved",
4470
- remarks: remarks || "",
4471
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4472
- };
4473
- const res = await collection.updateOne(
4474
- { _id },
4475
- { $set: updateValue },
4476
- { session }
4477
- );
4478
- if (res.modifiedCount === 0) {
4479
- throw new InternalServerError8("Unable to approve request item.");
4480
- }
4481
- delNamespace().then(() => {
4482
- logger25.info(`Cache cleared for namespace: ${namespace_collection}`);
4483
- }).catch((err) => {
4484
- logger25.error(
4485
- `Failed to clear cache for namespace: ${namespace_collection}`,
4486
- err
4487
- );
4488
- });
4489
- return res.modifiedCount;
4490
- } catch (error) {
4491
- throw error;
4492
- }
4493
- }
4494
- async function disapproveRequestItem(_id, remarks, session) {
4501
+ async function completeCheckOutItem(_id, session) {
4495
4502
  try {
4496
4503
  _id = new ObjectId15(_id);
4497
4504
  } catch (error) {
4498
- throw new BadRequestError25("Invalid request item ID format.");
4505
+ throw new BadRequestError25("Invalid check out item ID format.");
4499
4506
  }
4500
4507
  try {
4501
4508
  const updateValue = {
4502
- status: "disapproved",
4503
- remarks: remarks || "",
4509
+ status: "completed",
4504
4510
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4505
4511
  };
4506
4512
  const res = await collection.updateOne(
@@ -4509,7 +4515,7 @@ function useRequestItemRepository() {
4509
4515
  { session }
4510
4516
  );
4511
4517
  if (res.modifiedCount === 0) {
4512
- throw new InternalServerError8("Unable to disapprove request item.");
4518
+ throw new InternalServerError8("Unable to complete check out item.");
4513
4519
  }
4514
4520
  delNamespace().then(() => {
4515
4521
  logger25.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -4527,93 +4533,56 @@ function useRequestItemRepository() {
4527
4533
  return {
4528
4534
  createIndex,
4529
4535
  createTextIndex,
4530
- createRequestItem,
4531
- getRequestItems,
4532
- getRequestItemById,
4533
- approveRequestItem,
4534
- disapproveRequestItem
4536
+ createCheckOutItem,
4537
+ getCheckOutItems,
4538
+ getCheckOutItemById,
4539
+ completeCheckOutItem
4535
4540
  };
4536
4541
  }
4537
4542
 
4538
- // src/services/hygiene-request-item.service.ts
4543
+ // src/services/hygiene-checkout-item.service.ts
4539
4544
  import { useUserRepo } from "@7365admin1/core";
4540
4545
  import { BadRequestError as BadRequestError26, useAtlas as useAtlas12 } from "@7365admin1/node-server-utils";
4541
- function useRequestItemService() {
4546
+ function useCheckOutItemService() {
4542
4547
  const {
4543
- createRequestItem: _createRequestItem,
4544
- getRequestItemById: _getRequestItemById,
4545
- approveRequestItem: _approveRequestItem,
4546
- disapproveRequestItem: _disapproveRequestItem
4547
- } = useRequestItemRepository();
4548
+ createCheckOutItem: _createCheckOutItem,
4549
+ getCheckOutItemById: _getCheckOutItemById,
4550
+ completeCheckOutItem
4551
+ } = useCheckOutItemRepository();
4548
4552
  const { getSupplyById } = useSupplyRepository();
4549
4553
  const { getUserById } = useUserRepo();
4550
4554
  const { createStock } = useStockService();
4551
- async function createRequestItem(value) {
4552
- try {
4553
- const { supply, createdBy } = value;
4554
- const supplyData = await getSupplyById(supply);
4555
- const createdByData = await getUserById(createdBy);
4556
- const createdRequestItem = await _createRequestItem({
4557
- ...value,
4558
- supplyName: supplyData?.name || "",
4559
- createdByName: createdByData?.name || ""
4560
- });
4561
- return createdRequestItem;
4562
- } catch (error) {
4563
- throw error;
4564
- }
4565
- }
4566
- async function createRequestItemByBatch(value) {
4567
- const session = useAtlas12.getClient()?.startSession();
4568
- try {
4569
- session?.startTransaction();
4570
- const { site, createdBy, items } = value;
4571
- const createdByData = await getUserById(createdBy);
4572
- const createdRequestItemIds = [];
4573
- for (const item of items) {
4574
- const supplyData = await getSupplyById(item.supply, session);
4575
- const createdId = await _createRequestItem(
4576
- {
4577
- site,
4578
- supply: item.supply,
4579
- qty: item.qty,
4580
- supplyName: supplyData?.name || "",
4581
- createdBy,
4582
- createdByName: createdByData?.name || ""
4583
- },
4584
- session
4585
- );
4586
- createdRequestItemIds.push(createdId);
4587
- }
4588
- await session?.commitTransaction();
4589
- return createdRequestItemIds;
4590
- } catch (error) {
4591
- await session?.abortTransaction();
4592
- throw error;
4593
- } finally {
4594
- await session?.endSession();
4595
- }
4596
- }
4597
- async function approveRequestItem(id, remarks) {
4555
+ async function createCheckOutItem(value) {
4598
4556
  const session = useAtlas12.getClient()?.startSession();
4599
4557
  try {
4600
4558
  session?.startTransaction();
4601
- await _approveRequestItem(id, remarks, session);
4602
- const requestItem = await _getRequestItemById(id, session);
4603
- if (requestItem.status !== "pending") {
4604
- throw new BadRequestError26(
4605
- "Only 'pending' request items can be approved."
4606
- );
4559
+ const supplyData = await getSupplyById(value.supply);
4560
+ const createdByData = await getUserById(value.createdBy);
4561
+ const checkOutItemId = await _createCheckOutItem(
4562
+ {
4563
+ ...value,
4564
+ supplyName: supplyData?.name || "",
4565
+ createdByName: createdByData?.name || ""
4566
+ },
4567
+ session
4568
+ );
4569
+ const checkOutItem = await _getCheckOutItemById(
4570
+ checkOutItemId.toString(),
4571
+ session
4572
+ );
4573
+ if (!checkOutItem) {
4574
+ throw new BadRequestError26("Failed to create check out item.");
4607
4575
  }
4608
4576
  const createdStocks = await createStock(
4609
4577
  {
4610
- site: requestItem.site.toString(),
4611
- supply: requestItem.supply.toString(),
4612
- qty: requestItem.qty,
4613
- remarks
4578
+ site: checkOutItem.site.toString(),
4579
+ supply: checkOutItem.supply.toString(),
4580
+ qty: checkOutItem.qty
4614
4581
  },
4615
- true
4582
+ true,
4583
+ session
4616
4584
  );
4585
+ await completeCheckOutItem(checkOutItemId.toString(), session);
4617
4586
  await session?.commitTransaction();
4618
4587
  return createdStocks;
4619
4588
  } catch (error) {
@@ -4623,19 +4592,40 @@ function useRequestItemService() {
4623
4592
  await session?.endSession();
4624
4593
  }
4625
4594
  }
4626
- async function disapproveRequestItem(id, remarks) {
4595
+ async function createCheckOutItemByBatch(value) {
4627
4596
  const session = useAtlas12.getClient()?.startSession();
4628
4597
  try {
4629
4598
  session?.startTransaction();
4630
- const result = await _disapproveRequestItem(id, remarks, session);
4631
- const requestItem = await _getRequestItemById(id, session);
4632
- if (requestItem.status !== "pending") {
4633
- throw new BadRequestError26(
4634
- "Only 'pending' request items can be disapproved."
4599
+ const { site, attachment, createdBy, items } = value;
4600
+ const createdByData = await getUserById(createdBy);
4601
+ const createdCheckOutItemIds = [];
4602
+ for (const item of items) {
4603
+ const supplyData = await getSupplyById(item.supply, session);
4604
+ const createdId = await _createCheckOutItem(
4605
+ {
4606
+ site,
4607
+ supply: item.supply,
4608
+ supplyName: supplyData?.name || "",
4609
+ qty: item.qty,
4610
+ attachment,
4611
+ createdBy,
4612
+ createdByName: createdByData?.name || ""
4613
+ },
4614
+ session
4615
+ );
4616
+ await createStock(
4617
+ {
4618
+ site,
4619
+ supply: item.supply,
4620
+ qty: item.qty
4621
+ },
4622
+ true,
4623
+ session
4635
4624
  );
4625
+ createdCheckOutItemIds.push(createdId);
4636
4626
  }
4637
4627
  await session?.commitTransaction();
4638
- return result;
4628
+ return createdCheckOutItemIds;
4639
4629
  } catch (error) {
4640
4630
  await session?.abortTransaction();
4641
4631
  throw error;
@@ -4644,28 +4634,24 @@ function useRequestItemService() {
4644
4634
  }
4645
4635
  }
4646
4636
  return {
4647
- createRequestItem,
4648
- createRequestItemByBatch,
4649
- approveRequestItem,
4650
- disapproveRequestItem
4637
+ createCheckOutItem,
4638
+ createCheckOutItemByBatch
4651
4639
  };
4652
4640
  }
4653
4641
 
4654
- // src/controllers/hygiene-request-item.controller.ts
4642
+ // src/controllers/hygiene-checkout-item.controller.ts
4655
4643
  import Joi15 from "joi";
4656
4644
  import { BadRequestError as BadRequestError27, logger as logger26 } from "@7365admin1/node-server-utils";
4657
- function useRequestItemController() {
4645
+ function useCheckOutItemController() {
4658
4646
  const {
4659
- getRequestItems: _getRequestItems,
4660
- getRequestItemById: _getRequestItemById
4661
- } = useRequestItemRepository();
4647
+ getCheckOutItems: _getCheckOutItems,
4648
+ getCheckOutItemById: _getCheckOutItemById
4649
+ } = useCheckOutItemRepository();
4662
4650
  const {
4663
- createRequestItem: _createRequestItem,
4664
- createRequestItemByBatch: _createRequestItemByBatch,
4665
- approveRequestItem: _approveRequestItem,
4666
- disapproveRequestItem: _disapproveRequestItem
4667
- } = useRequestItemService();
4668
- async function createRequestItem(req, res, next) {
4651
+ createCheckOutItem: _createCheckOutItem,
4652
+ createCheckOutItemByBatch: _createCheckOutItemByBatch
4653
+ } = useCheckOutItemService();
4654
+ async function createCheckOutItem(req, res, next) {
4669
4655
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
4670
4656
  (acc, [key, value]) => ({ ...acc, [key]: value }),
4671
4657
  {}
@@ -4680,6 +4666,7 @@ function useRequestItemController() {
4680
4666
  site: Joi15.string().hex().required(),
4681
4667
  supply: Joi15.string().hex().required(),
4682
4668
  qty: Joi15.number().min(0).required(),
4669
+ attachment: Joi15.array().items(Joi15.string()).optional().allow(null),
4683
4670
  createdBy: Joi15.string().hex().required()
4684
4671
  });
4685
4672
  const { error } = validation.validate(payload);
@@ -4689,8 +4676,8 @@ function useRequestItemController() {
4689
4676
  return;
4690
4677
  }
4691
4678
  try {
4692
- const id = await _createRequestItem(payload);
4693
- res.status(201).json({ message: "Request item created successfully.", id });
4679
+ const id = await _createCheckOutItem(payload);
4680
+ res.status(201).json({ message: "Check out item created successfully.", id });
4694
4681
  return;
4695
4682
  } catch (error2) {
4696
4683
  logger26.log({ level: "error", message: error2.message });
@@ -4698,7 +4685,7 @@ function useRequestItemController() {
4698
4685
  return;
4699
4686
  }
4700
4687
  }
4701
- async function createRequestItemByBatch(req, res, next) {
4688
+ async function createCheckOutItemByBatch(req, res, next) {
4702
4689
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
4703
4690
  (acc, [key, value]) => ({ ...acc, [key]: value }),
4704
4691
  {}
@@ -4711,6 +4698,7 @@ function useRequestItemController() {
4711
4698
  };
4712
4699
  const validation = Joi15.object({
4713
4700
  site: Joi15.string().hex().required(),
4701
+ attachment: Joi15.array().items(Joi15.string()).optional().allow(null),
4714
4702
  createdBy: Joi15.string().hex().required(),
4715
4703
  items: Joi15.array().items(
4716
4704
  Joi15.object({
@@ -4726,8 +4714,8 @@ function useRequestItemController() {
4726
4714
  return;
4727
4715
  }
4728
4716
  try {
4729
- await _createRequestItemByBatch(payload);
4730
- res.status(201).json({ message: "Request items created successfully." });
4717
+ await _createCheckOutItemByBatch(payload);
4718
+ res.status(201).json({ message: "Check out items created successfully." });
4731
4719
  return;
4732
4720
  } catch (error2) {
4733
4721
  logger26.log({ level: "error", message: error2.message });
@@ -4735,7 +4723,7 @@ function useRequestItemController() {
4735
4723
  return;
4736
4724
  }
4737
4725
  }
4738
- async function getRequestItems(req, res, next) {
4726
+ async function getCheckOutItems(req, res, next) {
4739
4727
  const query = { ...req.query, ...req.params };
4740
4728
  const validation = Joi15.object({
4741
4729
  page: Joi15.number().min(1).optional().allow("", null),
@@ -4754,7 +4742,7 @@ function useRequestItemController() {
4754
4742
  const search = req.query.search ?? "";
4755
4743
  const site = req.params.site ?? "";
4756
4744
  try {
4757
- const data = await _getRequestItems({
4745
+ const data = await _getCheckOutItems({
4758
4746
  page,
4759
4747
  limit,
4760
4748
  search,
@@ -4768,7 +4756,7 @@ function useRequestItemController() {
4768
4756
  return;
4769
4757
  }
4770
4758
  }
4771
- async function getRequestItemById(req, res, next) {
4759
+ async function getCheckOutItemById(req, res, next) {
4772
4760
  const validation = Joi15.string().hex().required();
4773
4761
  const _id = req.params.id;
4774
4762
  const { error, value } = validation.validate(_id);
@@ -4778,7 +4766,7 @@ function useRequestItemController() {
4778
4766
  return;
4779
4767
  }
4780
4768
  try {
4781
- const data = await _getRequestItemById(value);
4769
+ const data = await _getCheckOutItemById(value);
4782
4770
  res.json(data);
4783
4771
  return;
4784
4772
  } catch (error2) {
@@ -4787,617 +4775,44 @@ function useRequestItemController() {
4787
4775
  return;
4788
4776
  }
4789
4777
  }
4790
- async function approveRequestItem(req, res, next) {
4791
- const payload = { ...req.params, ...req.body };
4792
- const validation = Joi15.object({
4793
- id: Joi15.string().hex().required(),
4794
- remarks: Joi15.string().optional().allow("", null)
4795
- });
4796
- const { error } = validation.validate(payload);
4797
- if (error) {
4798
- logger26.log({ level: "error", message: error.message });
4799
- next(new BadRequestError27(error.message));
4800
- return;
4801
- }
4802
- try {
4803
- await _approveRequestItem(payload.id, payload.remarks);
4804
- res.json({ message: "Request item approved successfully." });
4805
- return;
4806
- } catch (error2) {
4807
- logger26.log({ level: "error", message: error2.message });
4808
- next(error2);
4809
- return;
4810
- }
4811
- }
4812
- async function disapproveRequestItem(req, res, next) {
4813
- const payload = { ...req.params, ...req.body };
4814
- const validation = Joi15.object({
4815
- id: Joi15.string().hex().required(),
4816
- remarks: Joi15.string().optional().allow("", null)
4817
- });
4818
- const { error } = validation.validate(payload);
4819
- if (error) {
4820
- logger26.log({ level: "error", message: error.message });
4821
- next(new BadRequestError27(error.message));
4822
- return;
4823
- }
4824
- try {
4825
- await _disapproveRequestItem(payload.id, payload.remarks);
4826
- res.json({ message: "Request item disapproved successfully." });
4827
- return;
4828
- } catch (error2) {
4829
- logger26.log({ level: "error", message: error2.message });
4830
- next(error2);
4831
- return;
4832
- }
4833
- }
4834
4778
  return {
4835
- createRequestItem,
4836
- createRequestItemByBatch,
4837
- getRequestItems,
4838
- getRequestItemById,
4839
- approveRequestItem,
4840
- disapproveRequestItem
4779
+ createCheckOutItem,
4780
+ createCheckOutItemByBatch,
4781
+ getCheckOutItems,
4782
+ getCheckOutItemById
4841
4783
  };
4842
4784
  }
4843
4785
 
4844
- // src/models/hygiene-checkout-item.model.ts
4786
+ // src/models/hygiene-schedule-task.model.ts
4787
+ import { BadRequestError as BadRequestError28, logger as logger27 } from "@7365admin1/node-server-utils";
4845
4788
  import Joi16 from "joi";
4846
4789
  import { ObjectId as ObjectId16 } from "mongodb";
4847
- import { BadRequestError as BadRequestError28, logger as logger27 } from "@7365admin1/node-server-utils";
4848
- var allowedCheckOutItemStatus = ["pending", "completed"];
4849
- var checkOutItemSchema = Joi16.object({
4790
+ var scheduleTaskSchema = Joi16.object({
4850
4791
  site: Joi16.string().hex().required(),
4851
- supply: Joi16.string().hex().required(),
4852
- supplyName: Joi16.string().required(),
4853
- qty: Joi16.number().min(0).required(),
4854
- attachment: Joi16.string().optional().allow("", null),
4855
- createdBy: Joi16.string().hex().required(),
4856
- createdByName: Joi16.string().required()
4857
- });
4858
- function MCheckOutItem(value) {
4859
- const { error } = checkOutItemSchema.validate(value);
4860
- if (error) {
4861
- logger27.info(`Hygiene Check Out Item Model: ${error.message}`);
4862
- throw new BadRequestError28(error.message);
4863
- }
4864
- if (value.site) {
4865
- try {
4866
- value.site = new ObjectId16(value.site);
4867
- } catch (error2) {
4868
- throw new BadRequestError28("Invalid site ID format.");
4869
- }
4870
- }
4871
- if (value.supply) {
4872
- try {
4873
- value.supply = new ObjectId16(value.supply);
4874
- } catch (error2) {
4875
- throw new BadRequestError28("Invalid supply ID format.");
4876
- }
4877
- }
4878
- return {
4879
- site: value.site,
4880
- supply: value.supply,
4881
- supplyName: value.supplyName,
4882
- qty: value.qty,
4883
- attachment: "",
4884
- createdBy: value.createdBy,
4885
- createdByName: value.createdByName,
4886
- status: "pending",
4887
- createdAt: (/* @__PURE__ */ new Date()).toISOString(),
4888
- updatedAt: "",
4889
- deletedAt: ""
4890
- };
4891
- }
4892
-
4893
- // src/repositories/hygiene-checkout-item.repository.ts
4894
- import { ObjectId as ObjectId17 } from "mongodb";
4895
- import {
4896
- useAtlas as useAtlas13,
4897
- InternalServerError as InternalServerError9,
4898
- useCache as useCache9,
4899
- logger as logger28,
4900
- makeCacheKey as makeCacheKey9,
4901
- paginate as paginate8,
4902
- BadRequestError as BadRequestError29,
4903
- NotFoundError as NotFoundError7
4904
- } from "@7365admin1/node-server-utils";
4905
- function useCheckOutItemRepository() {
4906
- const db = useAtlas13.getDb();
4907
- if (!db) {
4908
- throw new InternalServerError9("Unable to connect to server.");
4909
- }
4910
- const namespace_collection = "site.supply.checkouts";
4911
- const collection = db.collection(namespace_collection);
4912
- const { delNamespace, setCache, getCache } = useCache9(namespace_collection);
4913
- async function createIndex() {
4914
- try {
4915
- await collection.createIndexes([
4916
- { key: { site: 1 } },
4917
- { key: { supply: 1 } },
4918
- { key: { status: 1 } }
4919
- ]);
4920
- } catch (error) {
4921
- throw new InternalServerError9(
4922
- "Failed to create index on hygiene check out item."
4923
- );
4924
- }
4925
- }
4926
- async function createTextIndex() {
4927
- try {
4928
- await collection.createIndex({ supplyName: "text" });
4929
- } catch (error) {
4930
- throw new InternalServerError9(
4931
- "Failed to create text index on hygiene supply."
4932
- );
4933
- }
4934
- }
4935
- async function createCheckOutItem(value, session) {
4936
- try {
4937
- value = MCheckOutItem(value);
4938
- const res = await collection.insertOne(value, { session });
4939
- delNamespace().then(() => {
4940
- logger28.info(`Cache cleared for namespace: ${namespace_collection}`);
4941
- }).catch((err) => {
4942
- logger28.error(
4943
- `Failed to clear cache for namespace: ${namespace_collection}`,
4944
- err
4945
- );
4946
- });
4947
- return res.insertedId;
4948
- } catch (error) {
4949
- throw error;
4950
- }
4951
- }
4952
- async function getCheckOutItems({
4953
- page = 1,
4954
- limit = 10,
4955
- search = "",
4956
- site
4957
- }) {
4958
- page = page > 0 ? page - 1 : 0;
4959
- const query = {
4960
- status: { $ne: "deleted" }
4961
- };
4962
- const cacheOptions = {
4963
- page,
4964
- limit
4965
- };
4966
- try {
4967
- site = new ObjectId17(site);
4968
- query.site = site;
4969
- cacheOptions.site = site.toString();
4970
- } catch (error) {
4971
- throw new BadRequestError29("Invalid site ID format.");
4972
- }
4973
- if (search) {
4974
- query.$text = { $search: search };
4975
- cacheOptions.search = search;
4976
- }
4977
- const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
4978
- const cachedData = await getCache(cacheKey);
4979
- if (cachedData) {
4980
- logger28.info(`Cache hit for key: ${cacheKey}`);
4981
- return cachedData;
4982
- }
4983
- try {
4984
- const items = await collection.aggregate([
4985
- { $match: query },
4986
- {
4987
- $lookup: {
4988
- from: "site.supplies",
4989
- let: { supplyId: "$supply" },
4990
- pipeline: [
4991
- {
4992
- $match: {
4993
- $expr: {
4994
- $and: [
4995
- { $ne: ["$$supplyId", ""] },
4996
- { $eq: ["$_id", "$$supplyId"] }
4997
- ]
4998
- }
4999
- }
5000
- },
5001
- { $project: { qty: 1 } }
5002
- ],
5003
- as: "supplyDoc"
5004
- }
5005
- },
5006
- {
5007
- $unwind: {
5008
- path: "$supplyDoc",
5009
- preserveNullAndEmptyArrays: true
5010
- }
5011
- },
5012
- {
5013
- $lookup: {
5014
- from: "users",
5015
- let: { createdById: "$createdBy" },
5016
- pipeline: [
5017
- {
5018
- $match: {
5019
- $expr: {
5020
- $and: [
5021
- { $ne: ["$$createdById", ""] },
5022
- { $eq: ["$_id", "$$createdById"] }
5023
- ]
5024
- }
5025
- }
5026
- },
5027
- { $project: { name: 1 } }
5028
- ],
5029
- as: "createdByDoc"
5030
- }
5031
- },
5032
- {
5033
- $unwind: {
5034
- path: "$createdByDoc",
5035
- preserveNullAndEmptyArrays: true
5036
- }
5037
- },
5038
- {
5039
- $project: {
5040
- supplyName: 1,
5041
- supplyQty: "$supplyDoc.qty",
5042
- checkOutByName: "$createdByDoc.name",
5043
- checkOutQty: "$qty",
5044
- createdAt: 1,
5045
- status: 1
5046
- }
5047
- },
5048
- { $sort: { _id: -1 } },
5049
- { $skip: page * limit },
5050
- { $limit: limit }
5051
- ]).toArray();
5052
- const length = await collection.countDocuments(query);
5053
- const data = paginate8(items, page, limit, length);
5054
- setCache(cacheKey, data, 15 * 60).then(() => {
5055
- logger28.info(`Cache set for key: ${cacheKey}`);
5056
- }).catch((err) => {
5057
- logger28.error(`Failed to set cache for key: ${cacheKey}`, err);
5058
- });
5059
- return data;
5060
- } catch (error) {
5061
- throw error;
5062
- }
5063
- }
5064
- async function getCheckOutItemById(_id, session) {
5065
- try {
5066
- _id = new ObjectId17(_id);
5067
- } catch (error) {
5068
- throw new BadRequestError29("Invalid check out item ID format.");
5069
- }
5070
- const query = { _id };
5071
- const cacheKey = makeCacheKey9(namespace_collection, {
5072
- _id: _id.toString()
5073
- });
5074
- if (!session) {
5075
- const cachedData = await getCache(cacheKey);
5076
- if (cachedData) {
5077
- logger28.info(`Cache hit for key: ${cacheKey}`);
5078
- return cachedData;
5079
- }
5080
- } else {
5081
- logger28.info(`Skipping cache during transaction for key: ${cacheKey}`);
5082
- }
5083
- try {
5084
- const data = await collection.aggregate([
5085
- { $match: query },
5086
- {
5087
- $lookup: {
5088
- from: "site.supply.items",
5089
- localField: "supply",
5090
- foreignField: "_id",
5091
- as: "supplyDetails"
5092
- }
5093
- },
5094
- {
5095
- $unwind: {
5096
- path: "$supplyDetails",
5097
- preserveNullAndEmptyArrays: true
5098
- }
5099
- },
5100
- {
5101
- $project: {
5102
- site: 1,
5103
- supply: 1,
5104
- supplyName: 1,
5105
- qty: 1,
5106
- status: 1,
5107
- unitOfMeasurement: "$supplyDetails.unitOfMeasurement"
5108
- }
5109
- }
5110
- ]).toArray();
5111
- if (!data || data.length === 0) {
5112
- throw new NotFoundError7("Check out item not found.");
5113
- }
5114
- setCache(cacheKey, data[0], 15 * 60).then(() => {
5115
- logger28.info(`Cache set for key: ${cacheKey}`);
5116
- }).catch((err) => {
5117
- logger28.error(`Failed to set cache for key: ${cacheKey}`, err);
5118
- });
5119
- return data[0];
5120
- } catch (error) {
5121
- throw error;
5122
- }
5123
- }
5124
- return {
5125
- createIndex,
5126
- createTextIndex,
5127
- createCheckOutItem,
5128
- getCheckOutItems,
5129
- getCheckOutItemById
5130
- };
5131
- }
5132
-
5133
- // src/services/hygiene-checkout-item.service.ts
5134
- import { useUserRepo as useUserRepo2 } from "@7365admin1/core";
5135
- import { BadRequestError as BadRequestError30, useAtlas as useAtlas14 } from "@7365admin1/node-server-utils";
5136
- function useCheckOutItemService() {
5137
- const {
5138
- createCheckOutItem: _createCheckOutItem,
5139
- getCheckOutItemById: _getCheckOutItemById
5140
- } = useCheckOutItemRepository();
5141
- const { getSupplyById } = useSupplyRepository();
5142
- const { getUserById } = useUserRepo2();
5143
- const { createStock } = useStockService();
5144
- async function createCheckOutItem(value) {
5145
- const session = useAtlas14.getClient()?.startSession();
5146
- try {
5147
- session?.startTransaction();
5148
- const supplyData = await getSupplyById(value.supply);
5149
- const createdByData = await getUserById(value.createdBy);
5150
- const checkOutItemId = await _createCheckOutItem(
5151
- {
5152
- ...value,
5153
- supplyName: supplyData?.name || "",
5154
- createdByName: createdByData?.name || ""
5155
- },
5156
- session
5157
- );
5158
- const checkOutItem = await _getCheckOutItemById(checkOutItemId, session);
5159
- if (!checkOutItem) {
5160
- throw new BadRequestError30("Failed to create check out item.");
5161
- }
5162
- const createdStocks = await createStock(
5163
- {
5164
- site: checkOutItem.site.toString(),
5165
- supply: checkOutItem.supply.toString(),
5166
- qty: checkOutItem.qty
5167
- },
5168
- true,
5169
- session
5170
- );
5171
- await session?.commitTransaction();
5172
- return createdStocks;
5173
- } catch (error) {
5174
- await session?.abortTransaction();
5175
- throw error;
5176
- } finally {
5177
- await session?.endSession();
5178
- }
5179
- }
5180
- async function createCheckOutItemByBatch(value) {
5181
- const session = useAtlas14.getClient()?.startSession();
5182
- try {
5183
- session?.startTransaction();
5184
- const { site, createdBy, items } = value;
5185
- const createdByData = await getUserById(createdBy);
5186
- const createdCheckOutItemIds = [];
5187
- for (const item of items) {
5188
- const supplyData = await getSupplyById(item.supply, session);
5189
- const createdId = await _createCheckOutItem(
5190
- {
5191
- site,
5192
- supply: item.supply,
5193
- supplyName: supplyData?.name || "",
5194
- qty: item.qty,
5195
- attachment: item.attachment || "",
5196
- createdBy,
5197
- createdByName: createdByData?.name || ""
5198
- },
5199
- session
5200
- );
5201
- await createStock(
5202
- {
5203
- site,
5204
- supply: item.supply,
5205
- qty: item.qty
5206
- },
5207
- true,
5208
- session
5209
- );
5210
- createdCheckOutItemIds.push(createdId);
5211
- }
5212
- await session?.commitTransaction();
5213
- return createdCheckOutItemIds;
5214
- } catch (error) {
5215
- await session?.abortTransaction();
5216
- throw error;
5217
- } finally {
5218
- await session?.endSession();
5219
- }
5220
- }
5221
- return {
5222
- createCheckOutItem,
5223
- createCheckOutItemByBatch
5224
- };
5225
- }
5226
-
5227
- // src/controllers/hygiene-checkout-item.controller.ts
5228
- import Joi17 from "joi";
5229
- import { BadRequestError as BadRequestError31, logger as logger29 } from "@7365admin1/node-server-utils";
5230
- function useCheckOutItemController() {
5231
- const {
5232
- getCheckOutItems: _getCheckOutItems,
5233
- getCheckOutItemById: _getCheckOutItemById
5234
- } = useCheckOutItemRepository();
5235
- const {
5236
- createCheckOutItem: _createCheckOutItem,
5237
- createCheckOutItemByBatch: _createCheckOutItemByBatch
5238
- } = useCheckOutItemService();
5239
- async function createCheckOutItem(req, res, next) {
5240
- const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
5241
- (acc, [key, value]) => ({ ...acc, [key]: value }),
5242
- {}
5243
- ) : {};
5244
- const createdBy = cookies["user"] || "";
5245
- const payload = {
5246
- ...req.body,
5247
- ...req.params,
5248
- createdBy
5249
- };
5250
- const validation = Joi17.object({
5251
- site: Joi17.string().hex().required(),
5252
- supply: Joi17.string().hex().required(),
5253
- qty: Joi17.number().min(0).required(),
5254
- attachment: Joi17.string().optional().allow("", null),
5255
- createdBy: Joi17.string().hex().required()
5256
- });
5257
- const { error } = validation.validate(payload);
5258
- if (error) {
5259
- logger29.log({ level: "error", message: error.message });
5260
- next(new BadRequestError31(error.message));
5261
- return;
5262
- }
5263
- try {
5264
- const id = await _createCheckOutItem(payload);
5265
- res.status(201).json({ message: "Check out item created successfully.", id });
5266
- return;
5267
- } catch (error2) {
5268
- logger29.log({ level: "error", message: error2.message });
5269
- next(error2);
5270
- return;
5271
- }
5272
- }
5273
- async function createCheckOutItemByBatch(req, res, next) {
5274
- const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
5275
- (acc, [key, value]) => ({ ...acc, [key]: value }),
5276
- {}
5277
- ) : {};
5278
- const createdBy = cookies["user"] || "";
5279
- const payload = {
5280
- ...req.body,
5281
- ...req.params,
5282
- createdBy
5283
- };
5284
- const validation = Joi17.object({
5285
- site: Joi17.string().hex().required(),
5286
- createdBy: Joi17.string().hex().required(),
5287
- items: Joi17.array().items(
5288
- Joi17.object({
5289
- supply: Joi17.string().hex().required(),
5290
- qty: Joi17.number().min(0).required(),
5291
- attachment: Joi17.string().optional().allow("", null)
5292
- })
5293
- ).min(1).required()
5294
- });
5295
- const { error } = validation.validate(payload);
5296
- if (error) {
5297
- logger29.log({ level: "error", message: error.message });
5298
- next(new BadRequestError31(error.message));
5299
- return;
5300
- }
5301
- try {
5302
- await _createCheckOutItemByBatch(payload);
5303
- res.status(201).json({ message: "Check out items created successfully." });
5304
- return;
5305
- } catch (error2) {
5306
- logger29.log({ level: "error", message: error2.message });
5307
- next(error2);
5308
- return;
5309
- }
5310
- }
5311
- async function getCheckOutItems(req, res, next) {
5312
- const query = { ...req.query, ...req.params };
5313
- const validation = Joi17.object({
5314
- page: Joi17.number().min(1).optional().allow("", null),
5315
- limit: Joi17.number().min(1).optional().allow("", null),
5316
- search: Joi17.string().optional().allow("", null),
5317
- site: Joi17.string().hex().required()
5318
- });
5319
- const { error } = validation.validate(query);
5320
- if (error) {
5321
- logger29.log({ level: "error", message: error.message });
5322
- next(new BadRequestError31(error.message));
5323
- return;
5324
- }
5325
- const page = parseInt(req.query.page) ?? 1;
5326
- const limit = parseInt(req.query.limit) ?? 10;
5327
- const search = req.query.search ?? "";
5328
- const site = req.params.site ?? "";
5329
- try {
5330
- const data = await _getCheckOutItems({
5331
- page,
5332
- limit,
5333
- search,
5334
- site
5335
- });
5336
- res.json(data);
5337
- return;
5338
- } catch (error2) {
5339
- logger29.log({ level: "error", message: error2.message });
5340
- next(error2);
5341
- return;
5342
- }
5343
- }
5344
- async function getCheckOutItemById(req, res, next) {
5345
- const validation = Joi17.string().hex().required();
5346
- const _id = req.params.id;
5347
- const { error, value } = validation.validate(_id);
5348
- if (error) {
5349
- logger29.log({ level: "error", message: error.message });
5350
- next(new BadRequestError31(error.message));
5351
- return;
5352
- }
5353
- try {
5354
- const data = await _getCheckOutItemById(value);
5355
- res.json(data);
5356
- return;
5357
- } catch (error2) {
5358
- logger29.log({ level: "error", message: error2.message });
5359
- next(error2);
5360
- return;
5361
- }
5362
- }
5363
- return {
5364
- createCheckOutItem,
5365
- createCheckOutItemByBatch,
5366
- getCheckOutItems,
5367
- getCheckOutItemById
5368
- };
5369
- }
5370
-
5371
- // src/models/hygiene-schedule-task.model.ts
5372
- import { BadRequestError as BadRequestError32, logger as logger30 } from "@7365admin1/node-server-utils";
5373
- import Joi18 from "joi";
5374
- import { ObjectId as ObjectId18 } from "mongodb";
5375
- var scheduleTaskSchema = Joi18.object({
5376
- site: Joi18.string().hex().required(),
5377
- title: Joi18.string().required(),
5378
- time: Joi18.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).required(),
5379
- startDate: Joi18.string().pattern(/^\d{4}-\d{2}-\d{2}$/).required(),
5380
- endDate: Joi18.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
5381
- description: Joi18.string().optional().allow("", null),
5382
- areas: Joi18.array().min(1).items(
5383
- Joi18.object({
5384
- name: Joi18.string().required(),
5385
- value: Joi18.any().required()
5386
- })
5387
- ).required(),
5388
- createdBy: Joi18.string().hex().required()
4792
+ title: Joi16.string().required(),
4793
+ time: Joi16.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).required(),
4794
+ startDate: Joi16.string().pattern(/^\d{4}-\d{2}-\d{2}$/).required(),
4795
+ endDate: Joi16.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
4796
+ description: Joi16.string().optional().allow("", null),
4797
+ areas: Joi16.array().min(1).items(
4798
+ Joi16.object({
4799
+ name: Joi16.string().required(),
4800
+ value: Joi16.any().required()
4801
+ })
4802
+ ).required(),
4803
+ createdBy: Joi16.string().hex().required()
5389
4804
  });
5390
4805
  function MScheduleTask(value) {
5391
4806
  const { error } = scheduleTaskSchema.validate(value);
5392
4807
  if (error) {
5393
- logger30.info(`Hygiene Schedule Task Model: ${error.message}`);
5394
- throw new BadRequestError32(error.message);
4808
+ logger27.info(`Hygiene Schedule Task Model: ${error.message}`);
4809
+ throw new BadRequestError28(error.message);
5395
4810
  }
5396
4811
  if (value.site) {
5397
4812
  try {
5398
- value.site = new ObjectId18(value.site);
4813
+ value.site = new ObjectId16(value.site);
5399
4814
  } catch (error2) {
5400
- throw new BadRequestError32("Invalid site ID format.");
4815
+ throw new BadRequestError28("Invalid site ID format.");
5401
4816
  }
5402
4817
  }
5403
4818
  if (value.areas && Array.isArray(value.areas)) {
@@ -5405,18 +4820,18 @@ function MScheduleTask(value) {
5405
4820
  try {
5406
4821
  return {
5407
4822
  name: area.name,
5408
- value: new ObjectId18(area.value.toString())
4823
+ value: new ObjectId16(area.value.toString())
5409
4824
  };
5410
4825
  } catch (error2) {
5411
- throw new BadRequestError32(`Invalid area value format: ${area.name}`);
4826
+ throw new BadRequestError28(`Invalid area value format: ${area.name}`);
5412
4827
  }
5413
4828
  });
5414
4829
  }
5415
4830
  if (value.createdBy) {
5416
4831
  try {
5417
- value.createdBy = new ObjectId18(value.createdBy);
4832
+ value.createdBy = new ObjectId16(value.createdBy);
5418
4833
  } catch (error2) {
5419
- throw new BadRequestError32("Invalid createdBy ID format.");
4834
+ throw new BadRequestError28("Invalid createdBy ID format.");
5420
4835
  }
5421
4836
  }
5422
4837
  return {
@@ -5436,25 +4851,25 @@ function MScheduleTask(value) {
5436
4851
  }
5437
4852
 
5438
4853
  // src/repositories/hygiene-schedule-task.repository.ts
5439
- import { ObjectId as ObjectId19 } from "mongodb";
4854
+ import { ObjectId as ObjectId17 } from "mongodb";
5440
4855
  import {
5441
- useAtlas as useAtlas15,
5442
- InternalServerError as InternalServerError10,
5443
- paginate as paginate9,
5444
- BadRequestError as BadRequestError33,
5445
- useCache as useCache10,
5446
- logger as logger31,
5447
- makeCacheKey as makeCacheKey10,
5448
- NotFoundError as NotFoundError8
4856
+ useAtlas as useAtlas13,
4857
+ InternalServerError as InternalServerError9,
4858
+ paginate as paginate8,
4859
+ BadRequestError as BadRequestError29,
4860
+ useCache as useCache9,
4861
+ logger as logger28,
4862
+ makeCacheKey as makeCacheKey9,
4863
+ NotFoundError as NotFoundError7
5449
4864
  } from "@7365admin1/node-server-utils";
5450
4865
  function useScheduleTaskRepository() {
5451
- const db = useAtlas15.getDb();
4866
+ const db = useAtlas13.getDb();
5452
4867
  if (!db) {
5453
- throw new InternalServerError10("Unable to connect to server.");
4868
+ throw new InternalServerError9("Unable to connect to server.");
5454
4869
  }
5455
4870
  const namespace_collection = "site.schedule-tasks";
5456
4871
  const collection = db.collection(namespace_collection);
5457
- const { delNamespace, setCache, getCache } = useCache10(namespace_collection);
4872
+ const { delNamespace, setCache, getCache } = useCache9(namespace_collection);
5458
4873
  async function createIndex() {
5459
4874
  try {
5460
4875
  await collection.createIndexes([
@@ -5462,7 +4877,7 @@ function useScheduleTaskRepository() {
5462
4877
  { key: { status: 1 } }
5463
4878
  ]);
5464
4879
  } catch (error) {
5465
- throw new InternalServerError10(
4880
+ throw new InternalServerError9(
5466
4881
  "Failed to create index on hygiene schedule task."
5467
4882
  );
5468
4883
  }
@@ -5471,7 +4886,7 @@ function useScheduleTaskRepository() {
5471
4886
  try {
5472
4887
  await collection.createIndex({ title: "text", description: "text" });
5473
4888
  } catch (error) {
5474
- throw new InternalServerError10(
4889
+ throw new InternalServerError9(
5475
4890
  "Failed to create text index on hygiene schedule task."
5476
4891
  );
5477
4892
  }
@@ -5481,9 +4896,9 @@ function useScheduleTaskRepository() {
5481
4896
  value = MScheduleTask(value);
5482
4897
  const res = await collection.insertOne(value, { session });
5483
4898
  delNamespace().then(() => {
5484
- logger31.info(`Cache cleared for namespace: ${namespace_collection}`);
4899
+ logger28.info(`Cache cleared for namespace: ${namespace_collection}`);
5485
4900
  }).catch((err) => {
5486
- logger31.error(
4901
+ logger28.error(
5487
4902
  `Failed to clear cache for namespace: ${namespace_collection}`,
5488
4903
  err
5489
4904
  );
@@ -5508,20 +4923,20 @@ function useScheduleTaskRepository() {
5508
4923
  limit
5509
4924
  };
5510
4925
  try {
5511
- site = new ObjectId19(site);
4926
+ site = new ObjectId17(site);
5512
4927
  query.site = site;
5513
4928
  cacheOptions.site = site.toString();
5514
4929
  } catch (error) {
5515
- throw new BadRequestError33("Invalid site ID format.");
4930
+ throw new BadRequestError29("Invalid site ID format.");
5516
4931
  }
5517
4932
  if (search) {
5518
4933
  query.$or = [{ name: { $regex: search, $options: "i" } }];
5519
4934
  cacheOptions.search = search;
5520
4935
  }
5521
- const cacheKey = makeCacheKey10(namespace_collection, cacheOptions);
4936
+ const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
5522
4937
  const cachedData = await getCache(cacheKey);
5523
4938
  if (cachedData) {
5524
- logger31.info(`Cache hit for key: ${cacheKey}`);
4939
+ logger28.info(`Cache hit for key: ${cacheKey}`);
5525
4940
  return cachedData;
5526
4941
  }
5527
4942
  try {
@@ -5539,11 +4954,11 @@ function useScheduleTaskRepository() {
5539
4954
  { $limit: limit }
5540
4955
  ]).toArray();
5541
4956
  const length = await collection.countDocuments(query);
5542
- const data = paginate9(items, page, limit, length);
4957
+ const data = paginate8(items, page, limit, length);
5543
4958
  setCache(cacheKey, data, 15 * 60).then(() => {
5544
- logger31.info(`Cache set for key: ${cacheKey}`);
4959
+ logger28.info(`Cache set for key: ${cacheKey}`);
5545
4960
  }).catch((err) => {
5546
- logger31.error(`Failed to set cache for key: ${cacheKey}`, err);
4961
+ logger28.error(`Failed to set cache for key: ${cacheKey}`, err);
5547
4962
  });
5548
4963
  return data;
5549
4964
  } catch (error) {
@@ -5576,20 +4991,20 @@ function useScheduleTaskRepository() {
5576
4991
  limit
5577
4992
  };
5578
4993
  try {
5579
- site = new ObjectId19(site);
4994
+ site = new ObjectId17(site);
5580
4995
  query.site = site;
5581
4996
  cacheOptions.site = site.toString();
5582
4997
  } catch (error) {
5583
- throw new BadRequestError33("Invalid site ID format.");
4998
+ throw new BadRequestError29("Invalid site ID format.");
5584
4999
  }
5585
5000
  if (search) {
5586
5001
  query.$or = [{ name: { $regex: search, $options: "i" } }];
5587
5002
  cacheOptions.search = search;
5588
5003
  }
5589
- const cacheKey = makeCacheKey10(namespace_collection, cacheOptions);
5004
+ const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
5590
5005
  const cachedData = await getCache(cacheKey);
5591
5006
  if (cachedData) {
5592
- logger31.info(`Cache hit for key: ${cacheKey}`);
5007
+ logger28.info(`Cache hit for key: ${cacheKey}`);
5593
5008
  return cachedData;
5594
5009
  }
5595
5010
  try {
@@ -5606,11 +5021,11 @@ function useScheduleTaskRepository() {
5606
5021
  { $limit: limit }
5607
5022
  ]).toArray();
5608
5023
  const length = await collection.countDocuments(query);
5609
- const data = paginate9(items, page, limit, length);
5024
+ const data = paginate8(items, page, limit, length);
5610
5025
  setCache(cacheKey, data, 15 * 60).then(() => {
5611
- logger31.info(`Cache set for key: ${cacheKey}`);
5026
+ logger28.info(`Cache set for key: ${cacheKey}`);
5612
5027
  }).catch((err) => {
5613
- logger31.error(`Failed to set cache for key: ${cacheKey}`, err);
5028
+ logger28.error(`Failed to set cache for key: ${cacheKey}`, err);
5614
5029
  });
5615
5030
  return data;
5616
5031
  } catch (error) {
@@ -5619,25 +5034,25 @@ function useScheduleTaskRepository() {
5619
5034
  }
5620
5035
  async function getScheduleTaskById(_id, session) {
5621
5036
  try {
5622
- _id = new ObjectId19(_id);
5037
+ _id = new ObjectId17(_id);
5623
5038
  } catch (error) {
5624
- throw new BadRequestError33("Invalid schedule task ID format.");
5039
+ throw new BadRequestError29("Invalid schedule task ID format.");
5625
5040
  }
5626
5041
  const query = {
5627
5042
  _id,
5628
5043
  status: { $ne: "deleted" }
5629
5044
  };
5630
- const cacheKey = makeCacheKey10(namespace_collection, {
5045
+ const cacheKey = makeCacheKey9(namespace_collection, {
5631
5046
  _id: _id.toString()
5632
5047
  });
5633
5048
  if (!session) {
5634
5049
  const cachedData = await getCache(cacheKey);
5635
5050
  if (cachedData) {
5636
- logger31.info(`Cache hit for key: ${cacheKey}`);
5051
+ logger28.info(`Cache hit for key: ${cacheKey}`);
5637
5052
  return cachedData;
5638
5053
  }
5639
5054
  } else {
5640
- logger31.info(`Skipping cache during transaction for key: ${cacheKey}`);
5055
+ logger28.info(`Skipping cache during transaction for key: ${cacheKey}`);
5641
5056
  }
5642
5057
  try {
5643
5058
  const data = await collection.aggregate([
@@ -5656,12 +5071,12 @@ function useScheduleTaskRepository() {
5656
5071
  }
5657
5072
  ]).toArray();
5658
5073
  if (!data || data.length === 0) {
5659
- throw new NotFoundError8("Schedule task not found.");
5074
+ throw new NotFoundError7("Schedule task not found.");
5660
5075
  }
5661
5076
  setCache(cacheKey, data[0], 15 * 60).then(() => {
5662
- logger31.info(`Cache set for key: ${cacheKey}`);
5077
+ logger28.info(`Cache set for key: ${cacheKey}`);
5663
5078
  }).catch((err) => {
5664
- logger31.error(`Failed to set cache for key: ${cacheKey}`, err);
5079
+ logger28.error(`Failed to set cache for key: ${cacheKey}`, err);
5665
5080
  });
5666
5081
  return data[0];
5667
5082
  } catch (error) {
@@ -5670,19 +5085,19 @@ function useScheduleTaskRepository() {
5670
5085
  }
5671
5086
  async function updateScheduleTask(_id, value, session) {
5672
5087
  try {
5673
- _id = new ObjectId19(_id);
5088
+ _id = new ObjectId17(_id);
5674
5089
  } catch (error) {
5675
- throw new BadRequestError33("Invalid schedule task ID format.");
5090
+ throw new BadRequestError29("Invalid schedule task ID format.");
5676
5091
  }
5677
5092
  if (value.areas && Array.isArray(value.areas)) {
5678
5093
  value.areas = value.areas.map((area) => {
5679
5094
  try {
5680
5095
  return {
5681
5096
  name: area.name,
5682
- value: new ObjectId19(area.value.toString())
5097
+ value: new ObjectId17(area.value.toString())
5683
5098
  };
5684
5099
  } catch (error) {
5685
- throw new BadRequestError33(`Invalid area value format: ${area.name}`);
5100
+ throw new BadRequestError29(`Invalid area value format: ${area.name}`);
5686
5101
  }
5687
5102
  });
5688
5103
  }
@@ -5694,14 +5109,14 @@ function useScheduleTaskRepository() {
5694
5109
  { session }
5695
5110
  );
5696
5111
  if (res.modifiedCount === 0) {
5697
- throw new InternalServerError10(
5112
+ throw new InternalServerError9(
5698
5113
  "Unable to update hygiene schedule task."
5699
5114
  );
5700
5115
  }
5701
5116
  delNamespace().then(() => {
5702
- logger31.info(`Cache cleared for namespace: ${namespace_collection}`);
5117
+ logger28.info(`Cache cleared for namespace: ${namespace_collection}`);
5703
5118
  }).catch((err) => {
5704
- logger31.error(
5119
+ logger28.error(
5705
5120
  `Failed to clear cache for namespace: ${namespace_collection}`,
5706
5121
  err
5707
5122
  );
@@ -5724,7 +5139,7 @@ function useScheduleTaskRepository() {
5724
5139
  }
5725
5140
 
5726
5141
  // src/services/hygiene-schedule-task.service.ts
5727
- import { logger as logger32 } from "@7365admin1/node-server-utils";
5142
+ import { logger as logger29 } from "@7365admin1/node-server-utils";
5728
5143
  function useScheduleTaskService() {
5729
5144
  const { createParentChecklist } = useParentChecklistRepo();
5730
5145
  const { getAllScheduleTask } = useScheduleTaskRepository();
@@ -5747,13 +5162,13 @@ function useScheduleTaskService() {
5747
5162
  const currentDateString = now.toLocaleDateString("en-US", {
5748
5163
  timeZone: "Asia/Singapore"
5749
5164
  });
5750
- logger32.info(
5165
+ logger29.info(
5751
5166
  `Checking schedule ${schedule._id}: Current time ${currentHour}:${currentMinute}, Current date ${currentDateString}, Schedule time ${schedule.time}, Start date ${schedule.startDate}, End date ${schedule.endDate}`
5752
5167
  );
5753
5168
  const startDate = /* @__PURE__ */ new Date(schedule.startDate + "T00:00:00");
5754
5169
  const currentDateOnly = /* @__PURE__ */ new Date(currentDateString + "T00:00:00");
5755
5170
  if (currentDateOnly < startDate) {
5756
- logger32.info(
5171
+ logger29.info(
5757
5172
  `Schedule ${schedule._id}: Current date ${currentDateString} is before start date ${schedule.startDate}`
5758
5173
  );
5759
5174
  return false;
@@ -5761,7 +5176,7 @@ function useScheduleTaskService() {
5761
5176
  if (schedule.endDate) {
5762
5177
  const endDate = /* @__PURE__ */ new Date(schedule.endDate + "T00:00:00");
5763
5178
  if (currentDateOnly > endDate) {
5764
- logger32.info(
5179
+ logger29.info(
5765
5180
  `Schedule ${schedule._id}: Current date ${currentDateString} is after end date ${schedule.endDate}`
5766
5181
  );
5767
5182
  return false;
@@ -5770,17 +5185,17 @@ function useScheduleTaskService() {
5770
5185
  const [scheduleHour, scheduleMinute] = schedule.time.split(":").map(Number);
5771
5186
  const timeMatches = currentHour === scheduleHour && currentMinute === scheduleMinute;
5772
5187
  if (!timeMatches) {
5773
- logger32.info(
5188
+ logger29.info(
5774
5189
  `Schedule ${schedule._id}: Time does not match. Current: ${currentHour}:${currentMinute}, Expected: ${scheduleHour}:${scheduleMinute}`
5775
5190
  );
5776
5191
  return false;
5777
5192
  }
5778
- logger32.info(
5193
+ logger29.info(
5779
5194
  `Schedule ${schedule._id}: All conditions matched - Date is within range and time matches`
5780
5195
  );
5781
5196
  return true;
5782
5197
  } catch (error) {
5783
- logger32.error(
5198
+ logger29.error(
5784
5199
  `Error checking schedule conditions for ${schedule._id}:`,
5785
5200
  error
5786
5201
  );
@@ -5789,40 +5204,40 @@ function useScheduleTaskService() {
5789
5204
  }
5790
5205
  async function processScheduledTasks(currentDate) {
5791
5206
  try {
5792
- logger32.info("Starting scheduled task processing...");
5207
+ logger29.info("Starting scheduled task processing...");
5793
5208
  const scheduleTasks = await getAllScheduleTask();
5794
5209
  if (!scheduleTasks || scheduleTasks.length === 0) {
5795
- logger32.info("No schedule tasks found to process");
5210
+ logger29.info("No schedule tasks found to process");
5796
5211
  return { processed: 0, validated: 0 };
5797
5212
  }
5798
- logger32.info(`Found ${scheduleTasks.length} schedule tasks to check`);
5213
+ logger29.info(`Found ${scheduleTasks.length} schedule tasks to check`);
5799
5214
  let processedCount = 0;
5800
5215
  let validatedCount = 0;
5801
5216
  const validatedTasks = [];
5802
5217
  for (const scheduleTask of scheduleTasks) {
5803
5218
  try {
5804
- logger32.info(
5219
+ logger29.info(
5805
5220
  `Checking schedule ${scheduleTask._id} - ${scheduleTask.title}: time=${scheduleTask.time}, startDate=${scheduleTask.startDate}, endDate=${scheduleTask.endDate}`
5806
5221
  );
5807
5222
  const shouldRun = checkScheduleConditions(scheduleTask, currentDate);
5808
5223
  if (!shouldRun) {
5809
- logger32.info(
5224
+ logger29.info(
5810
5225
  `Schedule ${scheduleTask._id} conditions not met, skipping`
5811
5226
  );
5812
5227
  continue;
5813
5228
  }
5814
- logger32.info(
5229
+ logger29.info(
5815
5230
  `Schedule ${scheduleTask._id} conditions validated, creating area checklists`
5816
5231
  );
5817
5232
  if (!scheduleTask._id) {
5818
- logger32.warn(`Schedule ${scheduleTask.title} has no _id, skipping`);
5233
+ logger29.warn(`Schedule ${scheduleTask.title} has no _id, skipping`);
5819
5234
  continue;
5820
5235
  }
5821
5236
  if (!scheduleTask.site) {
5822
- logger32.warn(`Schedule ${scheduleTask._id} has no site, skipping`);
5237
+ logger29.warn(`Schedule ${scheduleTask._id} has no site, skipping`);
5823
5238
  continue;
5824
5239
  }
5825
- logger32.info(
5240
+ logger29.info(
5826
5241
  `Getting or creating parent checklist for schedule ${scheduleTask._id} in site ${scheduleTask.site}`
5827
5242
  );
5828
5243
  const parentChecklistIds = await createParentChecklist({
@@ -5830,7 +5245,7 @@ function useScheduleTaskService() {
5830
5245
  createdAt: /* @__PURE__ */ new Date()
5831
5246
  });
5832
5247
  const parentChecklistId = Array.isArray(parentChecklistIds) ? parentChecklistIds[0] : parentChecklistIds;
5833
- logger32.info(
5248
+ logger29.info(
5834
5249
  `Using parent checklist ${parentChecklistId}, now creating/updating area checklists`
5835
5250
  );
5836
5251
  for (const area of scheduleTask.areas) {
@@ -5843,14 +5258,14 @@ function useScheduleTaskService() {
5843
5258
  unit: unit.unit.toString(),
5844
5259
  name: unit.name
5845
5260
  }));
5846
- logger32.info(
5261
+ logger29.info(
5847
5262
  `Area ${area.name} (${areaId}): Using units from area details: ${JSON.stringify(
5848
5263
  units
5849
5264
  )}`
5850
5265
  );
5851
5266
  }
5852
5267
  if (units.length === 0) {
5853
- logger32.warn(
5268
+ logger29.warn(
5854
5269
  `Area ${area.name} (${areaId}): No units found, skipping area.`
5855
5270
  );
5856
5271
  continue;
@@ -5861,11 +5276,11 @@ function useScheduleTaskService() {
5861
5276
  parentChecklistId.toString(),
5862
5277
  areaId
5863
5278
  );
5864
- logger32.info(
5279
+ logger29.info(
5865
5280
  `Area ${area.name} (${areaId}): Existing area checklist found: ${existingAreaChecklist ? "Yes" : "No"}`
5866
5281
  );
5867
5282
  if (existingAreaChecklist) {
5868
- logger32.info(
5283
+ logger29.info(
5869
5284
  `Area ${area.name} (${areaId}): Existing checklist content: ${JSON.stringify(
5870
5285
  existingAreaChecklist.checklist
5871
5286
  )}`
@@ -5873,7 +5288,7 @@ function useScheduleTaskService() {
5873
5288
  }
5874
5289
  } catch (error) {
5875
5290
  existingAreaChecklist = null;
5876
- logger32.info(
5291
+ logger29.info(
5877
5292
  `Area ${area.name} (${areaId}): No existing area checklist found (exception).`
5878
5293
  );
5879
5294
  }
@@ -5887,7 +5302,7 @@ function useScheduleTaskService() {
5887
5302
  ...existingAreaChecklist.checklist || [],
5888
5303
  newSet
5889
5304
  ];
5890
- logger32.info(
5305
+ logger29.info(
5891
5306
  `Area ${area.name} (${areaId}): Appending new set ${newSet.set} to checklist. Updated checklist: ${JSON.stringify(
5892
5307
  updatedChecklist
5893
5308
  )}`
@@ -5895,7 +5310,7 @@ function useScheduleTaskService() {
5895
5310
  await updateAreaChecklist(existingAreaChecklist._id, {
5896
5311
  checklist: updatedChecklist
5897
5312
  });
5898
- logger32.info(
5313
+ logger29.info(
5899
5314
  `Appended set ${newSet.set} to area checklist for area ${area.name}`
5900
5315
  );
5901
5316
  try {
@@ -5903,13 +5318,13 @@ function useScheduleTaskService() {
5903
5318
  parentChecklistId.toString(),
5904
5319
  areaId
5905
5320
  );
5906
- logger32.info(
5321
+ logger29.info(
5907
5322
  `Area ${area.name} (${areaId}): Checklist after update: ${JSON.stringify(
5908
5323
  verifyChecklist.checklist
5909
5324
  )}`
5910
5325
  );
5911
5326
  } catch (verifyError) {
5912
- logger32.warn(
5327
+ logger29.warn(
5913
5328
  `Area ${area.name} (${areaId}): Error verifying checklist after update:`,
5914
5329
  verifyError
5915
5330
  );
@@ -5928,50 +5343,50 @@ function useScheduleTaskService() {
5928
5343
  ],
5929
5344
  createdBy: scheduleTask.createdBy
5930
5345
  };
5931
- logger32.info(
5346
+ logger29.info(
5932
5347
  `Area ${area.name} (${areaId}): Creating new area checklist with data: ${JSON.stringify(
5933
5348
  checklistData
5934
5349
  )}`
5935
5350
  );
5936
5351
  await createAreaChecklist(checklistData);
5937
- logger32.info(`Created new area checklist for area ${area.name}`);
5352
+ logger29.info(`Created new area checklist for area ${area.name}`);
5938
5353
  try {
5939
5354
  const verifyChecklist = await getAreaChecklistByAreaAndSchedule(
5940
5355
  parentChecklistId.toString(),
5941
5356
  areaId
5942
5357
  );
5943
- logger32.info(
5358
+ logger29.info(
5944
5359
  `Area ${area.name} (${areaId}): Checklist after creation: ${JSON.stringify(
5945
5360
  verifyChecklist.checklist
5946
5361
  )}`
5947
5362
  );
5948
5363
  } catch (verifyError) {
5949
- logger32.warn(
5364
+ logger29.warn(
5950
5365
  `Area ${area.name} (${areaId}): Error verifying checklist after creation:`,
5951
5366
  verifyError
5952
5367
  );
5953
5368
  }
5954
5369
  }
5955
5370
  } catch (error) {
5956
- logger32.error(`Error processing area ${area.name}:`, error);
5371
+ logger29.error(`Error processing area ${area.name}:`, error);
5957
5372
  continue;
5958
5373
  }
5959
5374
  }
5960
5375
  processedCount++;
5961
5376
  validatedCount++;
5962
5377
  validatedTasks.push(scheduleTask);
5963
- logger32.info(
5378
+ logger29.info(
5964
5379
  `Successfully processed schedule ${scheduleTask._id}, created/updated area checklists for all areas.`
5965
5380
  );
5966
5381
  } catch (error) {
5967
- logger32.error(
5382
+ logger29.error(
5968
5383
  `Error processing schedule task ${scheduleTask._id}:`,
5969
5384
  error
5970
5385
  );
5971
5386
  continue;
5972
5387
  }
5973
5388
  }
5974
- logger32.info(
5389
+ logger29.info(
5975
5390
  `Scheduled task processing completed. Processed: ${processedCount}, Validated: ${validatedCount} tasks`
5976
5391
  );
5977
5392
  return {
@@ -5980,7 +5395,7 @@ function useScheduleTaskService() {
5980
5395
  tasks: validatedTasks
5981
5396
  };
5982
5397
  } catch (error) {
5983
- logger32.error("Error processing scheduled tasks:", error);
5398
+ logger29.error("Error processing scheduled tasks:", error);
5984
5399
  throw error;
5985
5400
  }
5986
5401
  }
@@ -5988,8 +5403,8 @@ function useScheduleTaskService() {
5988
5403
  }
5989
5404
 
5990
5405
  // src/controllers/hygiene-schedule-task.controller.ts
5991
- import Joi19 from "joi";
5992
- import { BadRequestError as BadRequestError34, logger as logger33 } from "@7365admin1/node-server-utils";
5406
+ import Joi17 from "joi";
5407
+ import { BadRequestError as BadRequestError30, logger as logger30 } from "@7365admin1/node-server-utils";
5993
5408
  function useScheduleTaskController() {
5994
5409
  const {
5995
5410
  createScheduleTask: _createScheduleTask,
@@ -6007,8 +5422,8 @@ function useScheduleTaskController() {
6007
5422
  const payload = { ...req.body, ...req.params, createdBy };
6008
5423
  const { error } = scheduleTaskSchema.validate(payload);
6009
5424
  if (error) {
6010
- logger33.log({ level: "error", message: error.message });
6011
- next(new BadRequestError34(error.message));
5425
+ logger30.log({ level: "error", message: error.message });
5426
+ next(new BadRequestError30(error.message));
6012
5427
  return;
6013
5428
  }
6014
5429
  try {
@@ -6016,23 +5431,23 @@ function useScheduleTaskController() {
6016
5431
  res.status(201).json({ message: "Schedule task created successfully.", id });
6017
5432
  return;
6018
5433
  } catch (error2) {
6019
- logger33.log({ level: "error", message: error2.message });
5434
+ logger30.log({ level: "error", message: error2.message });
6020
5435
  next(error2);
6021
5436
  return;
6022
5437
  }
6023
5438
  }
6024
5439
  async function getScheduleTasks(req, res, next) {
6025
5440
  const query = { ...req.query, ...req.params };
6026
- const validation = Joi19.object({
6027
- page: Joi19.number().min(1).optional().allow("", null),
6028
- limit: Joi19.number().min(1).optional().allow("", null),
6029
- search: Joi19.string().optional().allow("", null),
6030
- site: Joi19.string().hex().required()
5441
+ const validation = Joi17.object({
5442
+ page: Joi17.number().min(1).optional().allow("", null),
5443
+ limit: Joi17.number().min(1).optional().allow("", null),
5444
+ search: Joi17.string().optional().allow("", null),
5445
+ site: Joi17.string().hex().required()
6031
5446
  });
6032
5447
  const { error } = validation.validate(query);
6033
5448
  if (error) {
6034
- logger33.log({ level: "error", message: error.message });
6035
- next(new BadRequestError34(error.message));
5449
+ logger30.log({ level: "error", message: error.message });
5450
+ next(new BadRequestError30(error.message));
6036
5451
  return;
6037
5452
  }
6038
5453
  const page = parseInt(req.query.page) ?? 1;
@@ -6049,23 +5464,23 @@ function useScheduleTaskController() {
6049
5464
  res.json(data);
6050
5465
  return;
6051
5466
  } catch (error2) {
6052
- logger33.log({ level: "error", message: error2.message });
5467
+ logger30.log({ level: "error", message: error2.message });
6053
5468
  next(error2);
6054
5469
  return;
6055
5470
  }
6056
5471
  }
6057
5472
  async function getTasksForScheduleTask(req, res, next) {
6058
5473
  const query = { ...req.query, ...req.params };
6059
- const validation = Joi19.object({
6060
- page: Joi19.number().min(1).optional().allow("", null),
6061
- limit: Joi19.number().min(1).optional().allow("", null),
6062
- search: Joi19.string().optional().allow("", null),
6063
- site: Joi19.string().hex().required()
5474
+ const validation = Joi17.object({
5475
+ page: Joi17.number().min(1).optional().allow("", null),
5476
+ limit: Joi17.number().min(1).optional().allow("", null),
5477
+ search: Joi17.string().optional().allow("", null),
5478
+ site: Joi17.string().hex().required()
6064
5479
  });
6065
5480
  const { error } = validation.validate(query);
6066
5481
  if (error) {
6067
- logger33.log({ level: "error", message: error.message });
6068
- next(new BadRequestError34(error.message));
5482
+ logger30.log({ level: "error", message: error.message });
5483
+ next(new BadRequestError30(error.message));
6069
5484
  return;
6070
5485
  }
6071
5486
  const page = parseInt(req.query.page) ?? 1;
@@ -6082,18 +5497,18 @@ function useScheduleTaskController() {
6082
5497
  res.json(data);
6083
5498
  return;
6084
5499
  } catch (error2) {
6085
- logger33.log({ level: "error", message: error2.message });
5500
+ logger30.log({ level: "error", message: error2.message });
6086
5501
  next(error2);
6087
5502
  return;
6088
5503
  }
6089
5504
  }
6090
5505
  async function getScheduleTaskById(req, res, next) {
6091
- const validation = Joi19.string().hex().required();
5506
+ const validation = Joi17.string().hex().required();
6092
5507
  const _id = req.params.id;
6093
5508
  const { error, value } = validation.validate(_id);
6094
5509
  if (error) {
6095
- logger33.log({ level: "error", message: error.message });
6096
- next(new BadRequestError34(error.message));
5510
+ logger30.log({ level: "error", message: error.message });
5511
+ next(new BadRequestError30(error.message));
6097
5512
  return;
6098
5513
  }
6099
5514
  try {
@@ -6101,31 +5516,31 @@ function useScheduleTaskController() {
6101
5516
  res.json(data);
6102
5517
  return;
6103
5518
  } catch (error2) {
6104
- logger33.log({ level: "error", message: error2.message });
5519
+ logger30.log({ level: "error", message: error2.message });
6105
5520
  next(error2);
6106
5521
  return;
6107
5522
  }
6108
5523
  }
6109
5524
  async function updateScheduleTask(req, res, next) {
6110
5525
  const payload = { id: req.params.id, ...req.body };
6111
- const validation = Joi19.object({
6112
- id: Joi19.string().hex().required(),
6113
- title: Joi19.string().optional().allow("", null),
6114
- time: Joi19.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).optional().allow("", null),
6115
- startDate: Joi19.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
6116
- endDate: Joi19.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
6117
- description: Joi19.string().optional().allow("", null),
6118
- areas: Joi19.array().min(1).items(
6119
- Joi19.object({
6120
- name: Joi19.string().required(),
6121
- value: Joi19.any().required()
5526
+ const validation = Joi17.object({
5527
+ id: Joi17.string().hex().required(),
5528
+ title: Joi17.string().optional().allow("", null),
5529
+ time: Joi17.string().pattern(/^([0-1]\d|2[0-3]):([0-5]\d)$/).optional().allow("", null),
5530
+ startDate: Joi17.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
5531
+ endDate: Joi17.string().pattern(/^\d{4}-\d{2}-\d{2}$/).optional().allow("", null),
5532
+ description: Joi17.string().optional().allow("", null),
5533
+ areas: Joi17.array().min(1).items(
5534
+ Joi17.object({
5535
+ name: Joi17.string().required(),
5536
+ value: Joi17.any().required()
6122
5537
  })
6123
5538
  ).optional()
6124
5539
  });
6125
5540
  const { error } = validation.validate(payload);
6126
5541
  if (error) {
6127
- logger33.log({ level: "error", message: error.message });
6128
- next(new BadRequestError34(error.message));
5542
+ logger30.log({ level: "error", message: error.message });
5543
+ next(new BadRequestError30(error.message));
6129
5544
  return;
6130
5545
  }
6131
5546
  try {
@@ -6134,7 +5549,7 @@ function useScheduleTaskController() {
6134
5549
  res.json({ message: "Schedule task updated successfully." });
6135
5550
  return;
6136
5551
  } catch (error2) {
6137
- logger33.log({ level: "error", message: error2.message });
5552
+ logger30.log({ level: "error", message: error2.message });
6138
5553
  next(error2);
6139
5554
  return;
6140
5555
  }
@@ -6152,7 +5567,6 @@ export {
6152
5567
  MAreaChecklist,
6153
5568
  MCheckOutItem,
6154
5569
  MParentChecklist,
6155
- MRequestItem,
6156
5570
  MScheduleTask,
6157
5571
  MStock,
6158
5572
  MSupply,
@@ -6160,14 +5574,12 @@ export {
6160
5574
  allowedCheckOutItemStatus,
6161
5575
  allowedChecklistStatus,
6162
5576
  allowedPeriods,
6163
- allowedRequestItemStatus,
6164
5577
  allowedStatus,
6165
5578
  allowedTypes,
6166
5579
  areaChecklistSchema,
6167
5580
  areaSchema,
6168
5581
  checkOutItemSchema,
6169
5582
  parentChecklistSchema,
6170
- requestItemSchema,
6171
5583
  scheduleTaskSchema,
6172
5584
  stockSchema,
6173
5585
  supplySchema,
@@ -6185,9 +5597,6 @@ export {
6185
5597
  useHygieneDashboardRepository,
6186
5598
  useParentChecklistController,
6187
5599
  useParentChecklistRepo,
6188
- useRequestItemController,
6189
- useRequestItemRepository,
6190
- useRequestItemService,
6191
5600
  useScheduleTaskController,
6192
5601
  useScheduleTaskRepository,
6193
5602
  useScheduleTaskService,