@7365admin1/module-hygiene 4.1.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/dist/index.js CHANGED
@@ -32,21 +32,21 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  MArea: () => MArea,
34
34
  MAreaChecklist: () => MAreaChecklist,
35
+ MCheckOutItem: () => MCheckOutItem,
35
36
  MParentChecklist: () => MParentChecklist,
36
- MRequestItem: () => MRequestItem,
37
37
  MScheduleTask: () => MScheduleTask,
38
38
  MStock: () => MStock,
39
39
  MSupply: () => MSupply,
40
40
  MUnit: () => MUnit,
41
+ allowedCheckOutItemStatus: () => allowedCheckOutItemStatus,
41
42
  allowedChecklistStatus: () => allowedChecklistStatus,
42
43
  allowedPeriods: () => allowedPeriods,
43
- allowedRequestItemStatus: () => allowedRequestItemStatus,
44
44
  allowedStatus: () => allowedStatus,
45
45
  allowedTypes: () => allowedTypes,
46
46
  areaChecklistSchema: () => areaChecklistSchema,
47
47
  areaSchema: () => areaSchema,
48
+ checkOutItemSchema: () => checkOutItemSchema,
48
49
  parentChecklistSchema: () => parentChecklistSchema,
49
- requestItemSchema: () => requestItemSchema,
50
50
  scheduleTaskSchema: () => scheduleTaskSchema,
51
51
  stockSchema: () => stockSchema,
52
52
  supplySchema: () => supplySchema,
@@ -57,13 +57,13 @@ __export(src_exports, {
57
57
  useAreaController: () => useAreaController,
58
58
  useAreaRepo: () => useAreaRepo,
59
59
  useAreaService: () => useAreaService,
60
+ useCheckOutItemController: () => useCheckOutItemController,
61
+ useCheckOutItemRepository: () => useCheckOutItemRepository,
62
+ useCheckOutItemService: () => useCheckOutItemService,
60
63
  useHygieneDashboardController: () => useHygieneDashboardController,
61
64
  useHygieneDashboardRepository: () => useHygieneDashboardRepository,
62
65
  useParentChecklistController: () => useParentChecklistController,
63
66
  useParentChecklistRepo: () => useParentChecklistRepo,
64
- useRequestItemController: () => useRequestItemController,
65
- useRequestItemRepository: () => useRequestItemRepository,
66
- useRequestItemService: () => useRequestItemService,
67
67
  useScheduleTaskController: () => useScheduleTaskController,
68
68
  useScheduleTaskRepository: () => useScheduleTaskRepository,
69
69
  useScheduleTaskService: () => useScheduleTaskService,
@@ -4123,10 +4123,15 @@ var import_node_server_utils23 = require("@7365admin1/node-server-utils");
4123
4123
  function useStockService() {
4124
4124
  const { createStock: _createStock } = useStockRepository();
4125
4125
  const { getSupplyById, updateSupply } = useSupplyRepository();
4126
- async function createStock(value, out = false) {
4127
- const session = import_node_server_utils23.useAtlas.getClient()?.startSession();
4126
+ async function createStock(value, out = false, session) {
4127
+ let ownSession = false;
4128
+ if (!session) {
4129
+ session = import_node_server_utils23.useAtlas.getClient()?.startSession();
4130
+ ownSession = true;
4131
+ }
4128
4132
  try {
4129
- session?.startTransaction();
4133
+ if (ownSession)
4134
+ session?.startTransaction();
4130
4135
  const { qty, ...stockData } = value;
4131
4136
  const supply = await getSupplyById(value.supply, session);
4132
4137
  if (!supply || supply.qty === void 0) {
@@ -4148,13 +4153,16 @@ function useStockService() {
4148
4153
  },
4149
4154
  session
4150
4155
  );
4151
- await session?.commitTransaction();
4156
+ if (ownSession)
4157
+ await session?.commitTransaction();
4152
4158
  return createdStock;
4153
4159
  } catch (error) {
4154
- await session?.abortTransaction();
4160
+ if (ownSession)
4161
+ await session?.abortTransaction();
4155
4162
  throw error;
4156
4163
  } finally {
4157
- await session?.endSession();
4164
+ if (ownSession)
4165
+ await session?.endSession();
4158
4166
  }
4159
4167
  }
4160
4168
  return { createStock };
@@ -4232,27 +4240,24 @@ function useStockController() {
4232
4240
  };
4233
4241
  }
4234
4242
 
4235
- // src/models/hygiene-request-item.model.ts
4243
+ // src/models/hygiene-checkout-item.model.ts
4236
4244
  var import_joi14 = __toESM(require("joi"));
4237
4245
  var import_mongodb14 = require("mongodb");
4238
4246
  var import_node_server_utils25 = require("@7365admin1/node-server-utils");
4239
- var allowedRequestItemStatus = [
4240
- "pending",
4241
- "approved",
4242
- "disapproved"
4243
- ];
4244
- var requestItemSchema = import_joi14.default.object({
4247
+ var allowedCheckOutItemStatus = ["pending", "completed"];
4248
+ var checkOutItemSchema = import_joi14.default.object({
4245
4249
  site: import_joi14.default.string().hex().required(),
4246
4250
  supply: import_joi14.default.string().hex().required(),
4247
4251
  supplyName: import_joi14.default.string().required(),
4248
4252
  qty: import_joi14.default.number().min(0).required(),
4253
+ attachment: import_joi14.default.array().items(import_joi14.default.string()).optional().allow(null),
4249
4254
  createdBy: import_joi14.default.string().hex().required(),
4250
4255
  createdByName: import_joi14.default.string().required()
4251
4256
  });
4252
- function MRequestItem(value) {
4253
- const { error } = requestItemSchema.validate(value);
4257
+ function MCheckOutItem(value) {
4258
+ const { error } = checkOutItemSchema.validate(value);
4254
4259
  if (error) {
4255
- import_node_server_utils25.logger.info(`Hygiene Request Item Model: ${error.message}`);
4260
+ import_node_server_utils25.logger.info(`Hygiene Check Out Item Model: ${error.message}`);
4256
4261
  throw new import_node_server_utils25.BadRequestError(error.message);
4257
4262
  }
4258
4263
  if (value.site) {
@@ -4274,7 +4279,7 @@ function MRequestItem(value) {
4274
4279
  supply: value.supply,
4275
4280
  supplyName: value.supplyName,
4276
4281
  qty: value.qty,
4277
- remarks: "",
4282
+ attachment: value.attachment || [],
4278
4283
  createdBy: value.createdBy,
4279
4284
  createdByName: value.createdByName,
4280
4285
  status: "pending",
@@ -4284,15 +4289,15 @@ function MRequestItem(value) {
4284
4289
  };
4285
4290
  }
4286
4291
 
4287
- // src/repositories/hygiene-request-item.repository.ts
4292
+ // src/repositories/hygiene-checkout-item.repository.ts
4288
4293
  var import_mongodb15 = require("mongodb");
4289
4294
  var import_node_server_utils26 = require("@7365admin1/node-server-utils");
4290
- function useRequestItemRepository() {
4295
+ function useCheckOutItemRepository() {
4291
4296
  const db = import_node_server_utils26.useAtlas.getDb();
4292
4297
  if (!db) {
4293
4298
  throw new import_node_server_utils26.InternalServerError("Unable to connect to server.");
4294
4299
  }
4295
- const namespace_collection = "site.supply.requests";
4300
+ const namespace_collection = "site.supply.checkouts";
4296
4301
  const collection = db.collection(namespace_collection);
4297
4302
  const { delNamespace, setCache, getCache } = (0, import_node_server_utils26.useCache)(namespace_collection);
4298
4303
  async function createIndex() {
@@ -4304,7 +4309,7 @@ function useRequestItemRepository() {
4304
4309
  ]);
4305
4310
  } catch (error) {
4306
4311
  throw new import_node_server_utils26.InternalServerError(
4307
- "Failed to create index on hygiene request item."
4312
+ "Failed to create index on hygiene check out item."
4308
4313
  );
4309
4314
  }
4310
4315
  }
@@ -4317,9 +4322,9 @@ function useRequestItemRepository() {
4317
4322
  );
4318
4323
  }
4319
4324
  }
4320
- async function createRequestItem(value, session) {
4325
+ async function createCheckOutItem(value, session) {
4321
4326
  try {
4322
- value = MRequestItem(value);
4327
+ value = MCheckOutItem(value);
4323
4328
  const res = await collection.insertOne(value, { session });
4324
4329
  delNamespace().then(() => {
4325
4330
  import_node_server_utils26.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -4334,7 +4339,7 @@ function useRequestItemRepository() {
4334
4339
  throw error;
4335
4340
  }
4336
4341
  }
4337
- async function getRequestItems({
4342
+ async function getCheckOutItems({
4338
4343
  page = 1,
4339
4344
  limit = 10,
4340
4345
  search = "",
@@ -4368,9 +4373,38 @@ function useRequestItemRepository() {
4368
4373
  try {
4369
4374
  const items = await collection.aggregate([
4370
4375
  { $match: query },
4376
+ {
4377
+ $lookup: {
4378
+ from: "site.supplies",
4379
+ let: { supplyId: "$supply" },
4380
+ pipeline: [
4381
+ {
4382
+ $match: {
4383
+ $expr: {
4384
+ $and: [
4385
+ { $ne: ["$$supplyId", ""] },
4386
+ { $eq: ["$_id", "$$supplyId"] }
4387
+ ]
4388
+ }
4389
+ }
4390
+ },
4391
+ { $project: { qty: 1 } }
4392
+ ],
4393
+ as: "supplyDoc"
4394
+ }
4395
+ },
4396
+ {
4397
+ $unwind: {
4398
+ path: "$supplyDoc",
4399
+ preserveNullAndEmptyArrays: true
4400
+ }
4401
+ },
4371
4402
  {
4372
4403
  $project: {
4373
4404
  supplyName: 1,
4405
+ supplyQty: "$supplyDoc.qty",
4406
+ checkOutByName: "$createdByName",
4407
+ checkOutQty: "$qty",
4374
4408
  createdAt: 1,
4375
4409
  status: 1
4376
4410
  }
@@ -4391,11 +4425,11 @@ function useRequestItemRepository() {
4391
4425
  throw error;
4392
4426
  }
4393
4427
  }
4394
- async function getRequestItemById(_id, session) {
4428
+ async function getCheckOutItemById(_id, session) {
4395
4429
  try {
4396
4430
  _id = new import_mongodb15.ObjectId(_id);
4397
4431
  } catch (error) {
4398
- throw new import_node_server_utils26.BadRequestError("Invalid request item ID format.");
4432
+ throw new import_node_server_utils26.BadRequestError("Invalid check out item ID format.");
4399
4433
  }
4400
4434
  const query = { _id };
4401
4435
  const cacheKey = (0, import_node_server_utils26.makeCacheKey)(namespace_collection, {
@@ -4411,35 +4445,39 @@ function useRequestItemRepository() {
4411
4445
  import_node_server_utils26.logger.info(`Skipping cache during transaction for key: ${cacheKey}`);
4412
4446
  }
4413
4447
  try {
4414
- const data = await collection.aggregate([
4415
- { $match: query },
4416
- {
4417
- $lookup: {
4418
- from: "site.supply.items",
4419
- localField: "supply",
4420
- foreignField: "_id",
4421
- as: "supplyDetails"
4422
- }
4423
- },
4424
- {
4425
- $unwind: {
4426
- path: "$supplyDetails",
4427
- preserveNullAndEmptyArrays: true
4428
- }
4429
- },
4430
- {
4431
- $project: {
4432
- site: 1,
4433
- supply: 1,
4434
- supplyName: 1,
4435
- qty: 1,
4436
- status: 1,
4437
- unitOfMeasurement: "$supplyDetails.unitOfMeasurement"
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
+ }
4438
4475
  }
4439
- }
4440
- ]).toArray();
4476
+ ],
4477
+ session ? { session } : void 0
4478
+ ).toArray();
4441
4479
  if (!data || data.length === 0) {
4442
- throw new import_node_server_utils26.NotFoundError("Request item not found.");
4480
+ throw new import_node_server_utils26.NotFoundError("Check out item not found.");
4443
4481
  }
4444
4482
  setCache(cacheKey, data[0], 15 * 60).then(() => {
4445
4483
  import_node_server_utils26.logger.info(`Cache set for key: ${cacheKey}`);
@@ -4451,49 +4489,15 @@ function useRequestItemRepository() {
4451
4489
  throw error;
4452
4490
  }
4453
4491
  }
4454
- async function approveRequestItem(_id, remarks, session) {
4455
- try {
4456
- _id = new import_mongodb15.ObjectId(_id);
4457
- } catch (error) {
4458
- throw new import_node_server_utils26.BadRequestError("Invalid request item ID format.");
4459
- }
4460
- try {
4461
- const updateValue = {
4462
- status: "approved",
4463
- remarks: remarks || "",
4464
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4465
- };
4466
- const res = await collection.updateOne(
4467
- { _id },
4468
- { $set: updateValue },
4469
- { session }
4470
- );
4471
- if (res.modifiedCount === 0) {
4472
- throw new import_node_server_utils26.InternalServerError("Unable to approve request item.");
4473
- }
4474
- delNamespace().then(() => {
4475
- import_node_server_utils26.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
4476
- }).catch((err) => {
4477
- import_node_server_utils26.logger.error(
4478
- `Failed to clear cache for namespace: ${namespace_collection}`,
4479
- err
4480
- );
4481
- });
4482
- return res.modifiedCount;
4483
- } catch (error) {
4484
- throw error;
4485
- }
4486
- }
4487
- async function disapproveRequestItem(_id, remarks, session) {
4492
+ async function completeCheckOutItem(_id, session) {
4488
4493
  try {
4489
4494
  _id = new import_mongodb15.ObjectId(_id);
4490
4495
  } catch (error) {
4491
- throw new import_node_server_utils26.BadRequestError("Invalid request item ID format.");
4496
+ throw new import_node_server_utils26.BadRequestError("Invalid check out item ID format.");
4492
4497
  }
4493
4498
  try {
4494
4499
  const updateValue = {
4495
- status: "disapproved",
4496
- remarks: remarks || "",
4500
+ status: "completed",
4497
4501
  updatedAt: (/* @__PURE__ */ new Date()).toISOString()
4498
4502
  };
4499
4503
  const res = await collection.updateOne(
@@ -4502,7 +4506,7 @@ function useRequestItemRepository() {
4502
4506
  { session }
4503
4507
  );
4504
4508
  if (res.modifiedCount === 0) {
4505
- throw new import_node_server_utils26.InternalServerError("Unable to disapprove request item.");
4509
+ throw new import_node_server_utils26.InternalServerError("Unable to complete check out item.");
4506
4510
  }
4507
4511
  delNamespace().then(() => {
4508
4512
  import_node_server_utils26.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
@@ -4520,93 +4524,56 @@ function useRequestItemRepository() {
4520
4524
  return {
4521
4525
  createIndex,
4522
4526
  createTextIndex,
4523
- createRequestItem,
4524
- getRequestItems,
4525
- getRequestItemById,
4526
- approveRequestItem,
4527
- disapproveRequestItem
4527
+ createCheckOutItem,
4528
+ getCheckOutItems,
4529
+ getCheckOutItemById,
4530
+ completeCheckOutItem
4528
4531
  };
4529
4532
  }
4530
4533
 
4531
- // src/services/hygiene-request-item.service.ts
4534
+ // src/services/hygiene-checkout-item.service.ts
4532
4535
  var import_core = require("@7365admin1/core");
4533
4536
  var import_node_server_utils27 = require("@7365admin1/node-server-utils");
4534
- function useRequestItemService() {
4537
+ function useCheckOutItemService() {
4535
4538
  const {
4536
- createRequestItem: _createRequestItem,
4537
- getRequestItemById: _getRequestItemById,
4538
- approveRequestItem: _approveRequestItem,
4539
- disapproveRequestItem: _disapproveRequestItem
4540
- } = useRequestItemRepository();
4539
+ createCheckOutItem: _createCheckOutItem,
4540
+ getCheckOutItemById: _getCheckOutItemById,
4541
+ completeCheckOutItem
4542
+ } = useCheckOutItemRepository();
4541
4543
  const { getSupplyById } = useSupplyRepository();
4542
4544
  const { getUserById } = (0, import_core.useUserRepo)();
4543
4545
  const { createStock } = useStockService();
4544
- async function createRequestItem(value) {
4545
- try {
4546
- const { supply, createdBy } = value;
4547
- const supplyData = await getSupplyById(supply);
4548
- const createdByData = await getUserById(createdBy);
4549
- const createdRequestItem = await _createRequestItem({
4550
- ...value,
4551
- supplyName: supplyData?.name || "",
4552
- createdByName: createdByData?.name || ""
4553
- });
4554
- return createdRequestItem;
4555
- } catch (error) {
4556
- throw error;
4557
- }
4558
- }
4559
- async function createRequestItemByBatch(value) {
4546
+ async function createCheckOutItem(value) {
4560
4547
  const session = import_node_server_utils27.useAtlas.getClient()?.startSession();
4561
4548
  try {
4562
4549
  session?.startTransaction();
4563
- const { site, createdBy, items } = value;
4564
- const createdByData = await getUserById(createdBy);
4565
- const createdRequestItemIds = [];
4566
- for (const item of items) {
4567
- const supplyData = await getSupplyById(item.supply, session);
4568
- const createdId = await _createRequestItem(
4569
- {
4570
- site,
4571
- supply: item.supply,
4572
- qty: item.qty,
4573
- supplyName: supplyData?.name || "",
4574
- createdBy,
4575
- createdByName: createdByData?.name || ""
4576
- },
4577
- session
4578
- );
4579
- createdRequestItemIds.push(createdId);
4580
- }
4581
- await session?.commitTransaction();
4582
- return createdRequestItemIds;
4583
- } catch (error) {
4584
- await session?.abortTransaction();
4585
- throw error;
4586
- } finally {
4587
- await session?.endSession();
4588
- }
4589
- }
4590
- async function approveRequestItem(id, remarks) {
4591
- const session = import_node_server_utils27.useAtlas.getClient()?.startSession();
4592
- try {
4593
- session?.startTransaction();
4594
- await _approveRequestItem(id, remarks, session);
4595
- const requestItem = await _getRequestItemById(id, session);
4596
- if (requestItem.status !== "pending") {
4597
- throw new import_node_server_utils27.BadRequestError(
4598
- "Only 'pending' request items can be approved."
4599
- );
4550
+ const supplyData = await getSupplyById(value.supply);
4551
+ const createdByData = await getUserById(value.createdBy);
4552
+ const checkOutItemId = await _createCheckOutItem(
4553
+ {
4554
+ ...value,
4555
+ supplyName: supplyData?.name || "",
4556
+ createdByName: createdByData?.name || ""
4557
+ },
4558
+ session
4559
+ );
4560
+ const checkOutItem = await _getCheckOutItemById(
4561
+ checkOutItemId.toString(),
4562
+ session
4563
+ );
4564
+ if (!checkOutItem) {
4565
+ throw new import_node_server_utils27.BadRequestError("Failed to create check out item.");
4600
4566
  }
4601
4567
  const createdStocks = await createStock(
4602
4568
  {
4603
- site: requestItem.site.toString(),
4604
- supply: requestItem.supply.toString(),
4605
- qty: requestItem.qty,
4606
- remarks
4569
+ site: checkOutItem.site.toString(),
4570
+ supply: checkOutItem.supply.toString(),
4571
+ qty: checkOutItem.qty
4607
4572
  },
4608
- true
4573
+ true,
4574
+ session
4609
4575
  );
4576
+ await completeCheckOutItem(checkOutItemId.toString(), session);
4610
4577
  await session?.commitTransaction();
4611
4578
  return createdStocks;
4612
4579
  } catch (error) {
@@ -4616,19 +4583,40 @@ function useRequestItemService() {
4616
4583
  await session?.endSession();
4617
4584
  }
4618
4585
  }
4619
- async function disapproveRequestItem(id, remarks) {
4586
+ async function createCheckOutItemByBatch(value) {
4620
4587
  const session = import_node_server_utils27.useAtlas.getClient()?.startSession();
4621
4588
  try {
4622
4589
  session?.startTransaction();
4623
- const result = await _disapproveRequestItem(id, remarks, session);
4624
- const requestItem = await _getRequestItemById(id, session);
4625
- if (requestItem.status !== "pending") {
4626
- throw new import_node_server_utils27.BadRequestError(
4627
- "Only 'pending' request items can be disapproved."
4590
+ const { site, attachment, createdBy, items } = value;
4591
+ const createdByData = await getUserById(createdBy);
4592
+ const createdCheckOutItemIds = [];
4593
+ for (const item of items) {
4594
+ const supplyData = await getSupplyById(item.supply, session);
4595
+ const createdId = await _createCheckOutItem(
4596
+ {
4597
+ site,
4598
+ supply: item.supply,
4599
+ supplyName: supplyData?.name || "",
4600
+ qty: item.qty,
4601
+ attachment,
4602
+ createdBy,
4603
+ createdByName: createdByData?.name || ""
4604
+ },
4605
+ session
4606
+ );
4607
+ await createStock(
4608
+ {
4609
+ site,
4610
+ supply: item.supply,
4611
+ qty: item.qty
4612
+ },
4613
+ true,
4614
+ session
4628
4615
  );
4616
+ createdCheckOutItemIds.push(createdId);
4629
4617
  }
4630
4618
  await session?.commitTransaction();
4631
- return result;
4619
+ return createdCheckOutItemIds;
4632
4620
  } catch (error) {
4633
4621
  await session?.abortTransaction();
4634
4622
  throw error;
@@ -4637,28 +4625,24 @@ function useRequestItemService() {
4637
4625
  }
4638
4626
  }
4639
4627
  return {
4640
- createRequestItem,
4641
- createRequestItemByBatch,
4642
- approveRequestItem,
4643
- disapproveRequestItem
4628
+ createCheckOutItem,
4629
+ createCheckOutItemByBatch
4644
4630
  };
4645
4631
  }
4646
4632
 
4647
- // src/controllers/hygiene-request-item.controller.ts
4633
+ // src/controllers/hygiene-checkout-item.controller.ts
4648
4634
  var import_joi15 = __toESM(require("joi"));
4649
4635
  var import_node_server_utils28 = require("@7365admin1/node-server-utils");
4650
- function useRequestItemController() {
4636
+ function useCheckOutItemController() {
4651
4637
  const {
4652
- getRequestItems: _getRequestItems,
4653
- getRequestItemById: _getRequestItemById
4654
- } = useRequestItemRepository();
4638
+ getCheckOutItems: _getCheckOutItems,
4639
+ getCheckOutItemById: _getCheckOutItemById
4640
+ } = useCheckOutItemRepository();
4655
4641
  const {
4656
- createRequestItem: _createRequestItem,
4657
- createRequestItemByBatch: _createRequestItemByBatch,
4658
- approveRequestItem: _approveRequestItem,
4659
- disapproveRequestItem: _disapproveRequestItem
4660
- } = useRequestItemService();
4661
- async function createRequestItem(req, res, next) {
4642
+ createCheckOutItem: _createCheckOutItem,
4643
+ createCheckOutItemByBatch: _createCheckOutItemByBatch
4644
+ } = useCheckOutItemService();
4645
+ async function createCheckOutItem(req, res, next) {
4662
4646
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
4663
4647
  (acc, [key, value]) => ({ ...acc, [key]: value }),
4664
4648
  {}
@@ -4673,6 +4657,7 @@ function useRequestItemController() {
4673
4657
  site: import_joi15.default.string().hex().required(),
4674
4658
  supply: import_joi15.default.string().hex().required(),
4675
4659
  qty: import_joi15.default.number().min(0).required(),
4660
+ attachment: import_joi15.default.array().items(import_joi15.default.string()).optional().allow(null),
4676
4661
  createdBy: import_joi15.default.string().hex().required()
4677
4662
  });
4678
4663
  const { error } = validation.validate(payload);
@@ -4682,8 +4667,8 @@ function useRequestItemController() {
4682
4667
  return;
4683
4668
  }
4684
4669
  try {
4685
- const id = await _createRequestItem(payload);
4686
- res.status(201).json({ message: "Request item created successfully.", id });
4670
+ const id = await _createCheckOutItem(payload);
4671
+ res.status(201).json({ message: "Check out item created successfully.", id });
4687
4672
  return;
4688
4673
  } catch (error2) {
4689
4674
  import_node_server_utils28.logger.log({ level: "error", message: error2.message });
@@ -4691,7 +4676,7 @@ function useRequestItemController() {
4691
4676
  return;
4692
4677
  }
4693
4678
  }
4694
- async function createRequestItemByBatch(req, res, next) {
4679
+ async function createCheckOutItemByBatch(req, res, next) {
4695
4680
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
4696
4681
  (acc, [key, value]) => ({ ...acc, [key]: value }),
4697
4682
  {}
@@ -4704,6 +4689,7 @@ function useRequestItemController() {
4704
4689
  };
4705
4690
  const validation = import_joi15.default.object({
4706
4691
  site: import_joi15.default.string().hex().required(),
4692
+ attachment: import_joi15.default.array().items(import_joi15.default.string()).optional().allow(null),
4707
4693
  createdBy: import_joi15.default.string().hex().required(),
4708
4694
  items: import_joi15.default.array().items(
4709
4695
  import_joi15.default.object({
@@ -4719,8 +4705,8 @@ function useRequestItemController() {
4719
4705
  return;
4720
4706
  }
4721
4707
  try {
4722
- await _createRequestItemByBatch(payload);
4723
- res.status(201).json({ message: "Request items created successfully." });
4708
+ await _createCheckOutItemByBatch(payload);
4709
+ res.status(201).json({ message: "Check out items created successfully." });
4724
4710
  return;
4725
4711
  } catch (error2) {
4726
4712
  import_node_server_utils28.logger.log({ level: "error", message: error2.message });
@@ -4728,7 +4714,7 @@ function useRequestItemController() {
4728
4714
  return;
4729
4715
  }
4730
4716
  }
4731
- async function getRequestItems(req, res, next) {
4717
+ async function getCheckOutItems(req, res, next) {
4732
4718
  const query = { ...req.query, ...req.params };
4733
4719
  const validation = import_joi15.default.object({
4734
4720
  page: import_joi15.default.number().min(1).optional().allow("", null),
@@ -4747,7 +4733,7 @@ function useRequestItemController() {
4747
4733
  const search = req.query.search ?? "";
4748
4734
  const site = req.params.site ?? "";
4749
4735
  try {
4750
- const data = await _getRequestItems({
4736
+ const data = await _getCheckOutItems({
4751
4737
  page,
4752
4738
  limit,
4753
4739
  search,
@@ -4761,7 +4747,7 @@ function useRequestItemController() {
4761
4747
  return;
4762
4748
  }
4763
4749
  }
4764
- async function getRequestItemById(req, res, next) {
4750
+ async function getCheckOutItemById(req, res, next) {
4765
4751
  const validation = import_joi15.default.string().hex().required();
4766
4752
  const _id = req.params.id;
4767
4753
  const { error, value } = validation.validate(_id);
@@ -4771,7 +4757,7 @@ function useRequestItemController() {
4771
4757
  return;
4772
4758
  }
4773
4759
  try {
4774
- const data = await _getRequestItemById(value);
4760
+ const data = await _getCheckOutItemById(value);
4775
4761
  res.json(data);
4776
4762
  return;
4777
4763
  } catch (error2) {
@@ -4780,57 +4766,11 @@ function useRequestItemController() {
4780
4766
  return;
4781
4767
  }
4782
4768
  }
4783
- async function approveRequestItem(req, res, next) {
4784
- const payload = { ...req.params, ...req.body };
4785
- const validation = import_joi15.default.object({
4786
- id: import_joi15.default.string().hex().required(),
4787
- remarks: import_joi15.default.string().optional().allow("", null)
4788
- });
4789
- const { error } = validation.validate(payload);
4790
- if (error) {
4791
- import_node_server_utils28.logger.log({ level: "error", message: error.message });
4792
- next(new import_node_server_utils28.BadRequestError(error.message));
4793
- return;
4794
- }
4795
- try {
4796
- await _approveRequestItem(payload.id, payload.remarks);
4797
- res.json({ message: "Request item approved successfully." });
4798
- return;
4799
- } catch (error2) {
4800
- import_node_server_utils28.logger.log({ level: "error", message: error2.message });
4801
- next(error2);
4802
- return;
4803
- }
4804
- }
4805
- async function disapproveRequestItem(req, res, next) {
4806
- const payload = { ...req.params, ...req.body };
4807
- const validation = import_joi15.default.object({
4808
- id: import_joi15.default.string().hex().required(),
4809
- remarks: import_joi15.default.string().optional().allow("", null)
4810
- });
4811
- const { error } = validation.validate(payload);
4812
- if (error) {
4813
- import_node_server_utils28.logger.log({ level: "error", message: error.message });
4814
- next(new import_node_server_utils28.BadRequestError(error.message));
4815
- return;
4816
- }
4817
- try {
4818
- await _disapproveRequestItem(payload.id, payload.remarks);
4819
- res.json({ message: "Request item disapproved successfully." });
4820
- return;
4821
- } catch (error2) {
4822
- import_node_server_utils28.logger.log({ level: "error", message: error2.message });
4823
- next(error2);
4824
- return;
4825
- }
4826
- }
4827
4769
  return {
4828
- createRequestItem,
4829
- createRequestItemByBatch,
4830
- getRequestItems,
4831
- getRequestItemById,
4832
- approveRequestItem,
4833
- disapproveRequestItem
4770
+ createCheckOutItem,
4771
+ createCheckOutItemByBatch,
4772
+ getCheckOutItems,
4773
+ getCheckOutItemById
4834
4774
  };
4835
4775
  }
4836
4776
 
@@ -5608,21 +5548,21 @@ function useScheduleTaskController() {
5608
5548
  0 && (module.exports = {
5609
5549
  MArea,
5610
5550
  MAreaChecklist,
5551
+ MCheckOutItem,
5611
5552
  MParentChecklist,
5612
- MRequestItem,
5613
5553
  MScheduleTask,
5614
5554
  MStock,
5615
5555
  MSupply,
5616
5556
  MUnit,
5557
+ allowedCheckOutItemStatus,
5617
5558
  allowedChecklistStatus,
5618
5559
  allowedPeriods,
5619
- allowedRequestItemStatus,
5620
5560
  allowedStatus,
5621
5561
  allowedTypes,
5622
5562
  areaChecklistSchema,
5623
5563
  areaSchema,
5564
+ checkOutItemSchema,
5624
5565
  parentChecklistSchema,
5625
- requestItemSchema,
5626
5566
  scheduleTaskSchema,
5627
5567
  stockSchema,
5628
5568
  supplySchema,
@@ -5633,13 +5573,13 @@ function useScheduleTaskController() {
5633
5573
  useAreaController,
5634
5574
  useAreaRepo,
5635
5575
  useAreaService,
5576
+ useCheckOutItemController,
5577
+ useCheckOutItemRepository,
5578
+ useCheckOutItemService,
5636
5579
  useHygieneDashboardController,
5637
5580
  useHygieneDashboardRepository,
5638
5581
  useParentChecklistController,
5639
5582
  useParentChecklistRepo,
5640
- useRequestItemController,
5641
- useRequestItemRepository,
5642
- useRequestItemService,
5643
5583
  useScheduleTaskController,
5644
5584
  useScheduleTaskRepository,
5645
5585
  useScheduleTaskService,