@7365admin1/module-hygiene 4.14.0 → 4.16.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
@@ -1183,11 +1183,13 @@ function useUnitRepository() {
1183
1183
  }) {
1184
1184
  page = page > 0 ? page - 1 : 0;
1185
1185
  const query = {
1186
- status: { $ne: "deleted" }
1186
+ status: { $ne: "deleted" },
1187
+ serviceType
1187
1188
  };
1188
1189
  const cacheOptions = {
1189
1190
  page,
1190
- limit
1191
+ limit,
1192
+ serviceType
1191
1193
  };
1192
1194
  try {
1193
1195
  site = new ObjectId5(site);
@@ -1196,10 +1198,6 @@ function useUnitRepository() {
1196
1198
  } catch (error) {
1197
1199
  throw new BadRequestError6("Invalid site ID format.");
1198
1200
  }
1199
- if (serviceType) {
1200
- query.serviceType = serviceType;
1201
- cacheOptions.serviceType = serviceType;
1202
- }
1203
1201
  if (search) {
1204
1202
  query.$or = [{ name: { $regex: search, $options: "i" } }];
1205
1203
  cacheOptions.search = search;
@@ -2634,6 +2632,7 @@ function useParentChecklistRepo() {
2634
2632
  getAllParentChecklist,
2635
2633
  getParentChecklistById,
2636
2634
  updateParentChecklistStatuses,
2635
+ getHygieneSiteIds,
2637
2636
  closeExpiredParentChecklists,
2638
2637
  getTodayParentChecklists,
2639
2638
  getTodayParentChecklistsForAreaGen
@@ -2650,7 +2649,12 @@ function useParentChecklistController() {
2650
2649
  } = useParentChecklistRepo();
2651
2650
  async function createParentChecklist(req, res, next) {
2652
2651
  const payload = req.body;
2653
- const { error } = parentChecklistSchema.validate(payload);
2652
+ const validation = Joi7.object({
2653
+ createdAt: Joi7.alternatives().try(Joi7.date(), Joi7.string()).optional().allow("", null),
2654
+ site: Joi7.string().hex().required(),
2655
+ serviceType: Joi7.string().valid(...Object.values(ServiceType)).optional().allow("", null)
2656
+ });
2657
+ const { error } = validation.validate(payload);
2654
2658
  if (error) {
2655
2659
  logger15.log({ level: "error", message: error.message });
2656
2660
  next(new BadRequestError13(error.message));
@@ -2724,7 +2728,7 @@ import { BadRequestError as BadRequestError14, logger as logger16 } from "@7365a
2724
2728
  var allowedChecklistStatus = ["open", "completed", "closed"];
2725
2729
  var areaChecklistSchema = Joi8.object({
2726
2730
  schedule: Joi8.string().hex().required(),
2727
- serviceType: Joi8.string().valid(...Object.values(ServiceType)).optional(),
2731
+ serviceType: Joi8.string().valid(...Object.values(ServiceType)).required(),
2728
2732
  area: Joi8.string().hex().required(),
2729
2733
  name: Joi8.string().required(),
2730
2734
  type: Joi8.string().valid(...allowedTypes).required(),
@@ -2917,10 +2921,11 @@ function useAreaChecklistRepo() {
2917
2921
  serviceType
2918
2922
  }, session) {
2919
2923
  page = page > 0 ? page - 1 : 0;
2920
- const query = {};
2924
+ const query = { serviceType };
2921
2925
  const cacheOptions = {
2922
2926
  page,
2923
- limit
2927
+ limit,
2928
+ serviceType
2924
2929
  };
2925
2930
  try {
2926
2931
  query.schedule = new ObjectId9(schedule);
@@ -2928,10 +2933,6 @@ function useAreaChecklistRepo() {
2928
2933
  } catch (error) {
2929
2934
  throw new BadRequestError15("Invalid parent checklist ID format.");
2930
2935
  }
2931
- if (serviceType) {
2932
- query.serviceType = serviceType;
2933
- cacheOptions.serviceType = serviceType;
2934
- }
2935
2936
  if (type && type !== "all") {
2936
2937
  query.type = type;
2937
2938
  cacheOptions.type = type;
@@ -3331,10 +3332,11 @@ function useAreaChecklistRepo() {
3331
3332
  _id
3332
3333
  }, session) {
3333
3334
  page = page > 0 ? page - 1 : 0;
3334
- const query = {};
3335
+ const query = { serviceType };
3335
3336
  const cacheOptions = {
3336
3337
  page,
3337
- limit
3338
+ limit,
3339
+ serviceType
3338
3340
  };
3339
3341
  try {
3340
3342
  query._id = new ObjectId9(_id);
@@ -3342,10 +3344,6 @@ function useAreaChecklistRepo() {
3342
3344
  } catch (error) {
3343
3345
  throw new BadRequestError15("Invalid area checklist ID format.");
3344
3346
  }
3345
- if (serviceType) {
3346
- query.serviceType = serviceType;
3347
- cacheOptions.serviceType = serviceType;
3348
- }
3349
3347
  if (search) {
3350
3348
  query.$text = { $search: search };
3351
3349
  cacheOptions.search = search;
@@ -3559,7 +3557,16 @@ function useAreaChecklistRepo() {
3559
3557
  try {
3560
3558
  const area = await collection.findOne(
3561
3559
  { _id },
3562
- { projection: { schedule: 1, name: 1, type: 1, status: 1 }, session }
3560
+ {
3561
+ projection: {
3562
+ schedule: 1,
3563
+ serviceType: 1,
3564
+ name: 1,
3565
+ type: 1,
3566
+ status: 1
3567
+ },
3568
+ session
3569
+ }
3563
3570
  );
3564
3571
  if (!area) {
3565
3572
  throw new BadRequestError15("Area checklist not found.");
@@ -4118,10 +4125,14 @@ function useAreaChecklistService() {
4118
4125
  );
4119
4126
  }
4120
4127
  await _updateAreaChecklistUnits(_id, set, unitId, value, session);
4128
+ const currentArea = await getAreaChecklistById(_id, session);
4129
+ const scheduleId = currentArea.schedule;
4130
+ const serviceType = currentArea.serviceType;
4121
4131
  const allUnitsResult = await getAreaChecklistUnits(
4122
4132
  {
4123
4133
  page: 1,
4124
4134
  limit: 1e3,
4135
+ serviceType,
4125
4136
  _id: _id.toString()
4126
4137
  },
4127
4138
  session
@@ -4146,14 +4157,13 @@ function useAreaChecklistService() {
4146
4157
  }
4147
4158
  }
4148
4159
  await updateAreaChecklistStatus(_id, areaStatus, session);
4149
- const currentArea = await getAreaChecklistById(_id, session);
4150
- const scheduleId = currentArea.schedule;
4151
4160
  if (scheduleId) {
4152
4161
  const allAreasResult = await getAllAreaChecklist(
4153
4162
  {
4154
4163
  page: 1,
4155
4164
  limit: 1e3,
4156
- schedule: scheduleId.toString()
4165
+ schedule: scheduleId.toString(),
4166
+ serviceType
4157
4167
  },
4158
4168
  session
4159
4169
  );
@@ -4707,6 +4717,7 @@ import { ObjectId as ObjectId12 } from "mongodb";
4707
4717
  import { BadRequestError as BadRequestError17, logger as logger21 } from "@7365admin1/node-server-utils";
4708
4718
  var supplySchema = Joi10.object({
4709
4719
  site: Joi10.string().hex().required(),
4720
+ serviceType: Joi10.string().valid(...Object.values(ServiceType)).required(),
4710
4721
  name: Joi10.string().required(),
4711
4722
  unitOfMeasurement: Joi10.string().required()
4712
4723
  });
@@ -4725,6 +4736,7 @@ function MSupply(value) {
4725
4736
  }
4726
4737
  return {
4727
4738
  site: value.site,
4739
+ serviceType: value.serviceType,
4728
4740
  name: value.name,
4729
4741
  unitOfMeasurement: value.unitOfMeasurement,
4730
4742
  qty: 0,
@@ -4757,7 +4769,10 @@ function useSupplyRepository() {
4757
4769
  const { delNamespace, setCache, getCache } = useCache6(namespace_collection);
4758
4770
  async function createIndex() {
4759
4771
  try {
4760
- await collection.createIndexes([{ key: { site: 1 } }]);
4772
+ await collection.createIndexes([
4773
+ { key: { site: 1 } },
4774
+ { key: { serviceType: 1 } }
4775
+ ]);
4761
4776
  } catch (error) {
4762
4777
  throw new InternalServerError8(
4763
4778
  "Failed to create index on hygiene supply."
@@ -4810,15 +4825,18 @@ function useSupplyRepository() {
4810
4825
  page = 1,
4811
4826
  limit = 10,
4812
4827
  search = "",
4813
- site
4828
+ site,
4829
+ serviceType
4814
4830
  }) {
4815
4831
  page = page > 0 ? page - 1 : 0;
4816
4832
  const query = {
4817
- status: { $ne: "deleted" }
4833
+ status: { $ne: "deleted" },
4834
+ serviceType
4818
4835
  };
4819
4836
  const cacheOptions = {
4820
4837
  page,
4821
- limit
4838
+ limit,
4839
+ serviceType
4822
4840
  };
4823
4841
  try {
4824
4842
  site = new ObjectId13(site);
@@ -5022,7 +5040,8 @@ function useSupplyController() {
5022
5040
  page: Joi11.number().min(1).optional().allow("", null),
5023
5041
  limit: Joi11.number().min(1).optional().allow("", null),
5024
5042
  search: Joi11.string().optional().allow("", null),
5025
- site: Joi11.string().hex().required()
5043
+ site: Joi11.string().hex().required(),
5044
+ serviceType: Joi11.string().valid(...Object.values(ServiceType)).required()
5026
5045
  });
5027
5046
  const { error } = validation.validate(query);
5028
5047
  if (error) {
@@ -5034,12 +5053,14 @@ function useSupplyController() {
5034
5053
  const limit = parseInt(req.query.limit) ?? 10;
5035
5054
  const search = req.query.search ?? "";
5036
5055
  const site = req.params.site ?? "";
5056
+ const serviceType = req.query.serviceType ?? "";
5037
5057
  try {
5038
5058
  const data = await _getSupplies({
5039
5059
  page,
5040
5060
  limit,
5041
5061
  search,
5042
- site
5062
+ site,
5063
+ serviceType
5043
5064
  });
5044
5065
  res.json(data);
5045
5066
  return;
@@ -5095,10 +5116,8 @@ function useSupplyController() {
5095
5116
  }
5096
5117
  async function deleteSupply(req, res, next) {
5097
5118
  const id = req.params.id;
5098
- const validation = Joi11.object({
5099
- id: Joi11.string().hex().required()
5100
- });
5101
- const { error, value } = validation.validate({ id });
5119
+ const validation = Joi11.string().hex().required();
5120
+ const { error, value } = validation.validate(id);
5102
5121
  if (error) {
5103
5122
  logger23.log({ level: "error", message: error.message });
5104
5123
  next(new BadRequestError19(error.message));
@@ -5129,6 +5148,7 @@ import { ObjectId as ObjectId14 } from "mongodb";
5129
5148
  import { BadRequestError as BadRequestError20, logger as logger24 } from "@7365admin1/node-server-utils";
5130
5149
  var stockSchema = Joi12.object({
5131
5150
  site: Joi12.string().hex().required(),
5151
+ serviceType: Joi12.string().valid(...Object.values(ServiceType)).required(),
5132
5152
  supply: Joi12.string().hex().required(),
5133
5153
  in: Joi12.number().min(0).optional(),
5134
5154
  out: Joi12.number().min(0).optional(),
@@ -5157,6 +5177,7 @@ function MStock(value) {
5157
5177
  }
5158
5178
  return {
5159
5179
  site: value.site,
5180
+ serviceType: value.serviceType,
5160
5181
  supply: value.supply,
5161
5182
  in: value.in ?? 0,
5162
5183
  out: value.out ?? 0,
@@ -5194,6 +5215,7 @@ function useStockRepository() {
5194
5215
  try {
5195
5216
  await collection.createIndexes([
5196
5217
  { key: { site: 1 } },
5218
+ { key: { serviceType: 1 } },
5197
5219
  { key: { supply: 1 } },
5198
5220
  { key: { balance: 1 } },
5199
5221
  { key: { status: 1 } }
@@ -5232,15 +5254,18 @@ function useStockRepository() {
5232
5254
  limit = 10,
5233
5255
  search = "",
5234
5256
  site,
5257
+ serviceType,
5235
5258
  supply
5236
5259
  }) {
5237
5260
  page = page > 0 ? page - 1 : 0;
5238
5261
  const query = {
5239
- status: { $ne: "deleted" }
5262
+ status: { $ne: "deleted" },
5263
+ serviceType
5240
5264
  };
5241
5265
  const cacheOptions = {
5242
5266
  page,
5243
- limit
5267
+ limit,
5268
+ serviceType
5244
5269
  };
5245
5270
  try {
5246
5271
  site = new ObjectId15(site);
@@ -5364,6 +5389,7 @@ function useStockController() {
5364
5389
  const payload = { ...req.body, ...req.params };
5365
5390
  const validation = Joi13.object({
5366
5391
  site: Joi13.string().hex().required(),
5392
+ serviceType: Joi13.string().valid(...Object.values(ServiceType)).required(),
5367
5393
  supply: Joi13.string().hex().required(),
5368
5394
  qty: Joi13.number().min(0).required(),
5369
5395
  remarks: Joi13.string().optional().allow("", null)
@@ -5391,6 +5417,7 @@ function useStockController() {
5391
5417
  limit: Joi13.number().min(1).optional().allow("", null),
5392
5418
  search: Joi13.string().optional().allow("", null),
5393
5419
  site: Joi13.string().hex().required(),
5420
+ serviceType: Joi13.string().valid(...Object.values(ServiceType)).required(),
5394
5421
  supply: Joi13.string().hex().required()
5395
5422
  });
5396
5423
  const { error } = validation.validate(query);
@@ -5403,6 +5430,7 @@ function useStockController() {
5403
5430
  const limit = parseInt(req.query.limit) ?? 10;
5404
5431
  const search = req.query.search ?? "";
5405
5432
  const site = req.params.site ?? "";
5433
+ const serviceType = req.query.serviceType ?? "";
5406
5434
  const supply = req.params.supply ?? "";
5407
5435
  try {
5408
5436
  const data = await _getStocksBySupplyId({
@@ -5410,6 +5438,7 @@ function useStockController() {
5410
5438
  limit,
5411
5439
  search,
5412
5440
  site,
5441
+ serviceType,
5413
5442
  supply
5414
5443
  });
5415
5444
  res.json(data);
@@ -5433,6 +5462,7 @@ import { BadRequestError as BadRequestError24, logger as logger27 } from "@7365a
5433
5462
  var allowedCheckOutItemStatus = ["pending", "completed"];
5434
5463
  var checkOutItemSchema = Joi14.object({
5435
5464
  site: Joi14.string().hex().required(),
5465
+ serviceType: Joi14.string().valid(...Object.values(ServiceType)).required(),
5436
5466
  supply: Joi14.string().hex().required(),
5437
5467
  supplyName: Joi14.string().required(),
5438
5468
  qty: Joi14.number().min(0).required(),
@@ -5462,6 +5492,7 @@ function MCheckOutItem(value) {
5462
5492
  }
5463
5493
  return {
5464
5494
  site: value.site,
5495
+ serviceType: value.serviceType,
5465
5496
  supply: value.supply,
5466
5497
  supplyName: value.supplyName,
5467
5498
  qty: value.qty,
@@ -5499,6 +5530,7 @@ function useCheckOutItemRepository() {
5499
5530
  try {
5500
5531
  await collection.createIndexes([
5501
5532
  { key: { site: 1 } },
5533
+ { key: { serviceType: 1 } },
5502
5534
  { key: { supply: 1 } },
5503
5535
  { key: { status: 1 } }
5504
5536
  ]);
@@ -5538,15 +5570,18 @@ function useCheckOutItemRepository() {
5538
5570
  page = 1,
5539
5571
  limit = 10,
5540
5572
  search = "",
5541
- site
5573
+ site,
5574
+ serviceType
5542
5575
  }) {
5543
5576
  page = page > 0 ? page - 1 : 0;
5544
5577
  const query = {
5545
- status: { $ne: "deleted" }
5578
+ status: { $ne: "deleted" },
5579
+ serviceType
5546
5580
  };
5547
5581
  const cacheOptions = {
5548
5582
  page,
5549
- limit
5583
+ limit,
5584
+ serviceType
5550
5585
  };
5551
5586
  try {
5552
5587
  site = new ObjectId17(site);
@@ -5660,6 +5695,7 @@ function useCheckOutItemRepository() {
5660
5695
  {
5661
5696
  $project: {
5662
5697
  site: 1,
5698
+ serviceType: 1,
5663
5699
  supply: 1,
5664
5700
  supplyName: 1,
5665
5701
  qty: 1,
@@ -5762,6 +5798,7 @@ function useCheckOutItemService() {
5762
5798
  const createdStocks = await createStock(
5763
5799
  {
5764
5800
  site: checkOutItem.site.toString(),
5801
+ serviceType: checkOutItem.serviceType,
5765
5802
  supply: checkOutItem.supply.toString(),
5766
5803
  qty: checkOutItem.qty
5767
5804
  },
@@ -5782,7 +5819,7 @@ function useCheckOutItemService() {
5782
5819
  const session = useAtlas13.getClient()?.startSession();
5783
5820
  try {
5784
5821
  session?.startTransaction();
5785
- const { site, createdBy, items } = value;
5822
+ const { site, serviceType, createdBy, items } = value;
5786
5823
  const createdByData = await getUserById(createdBy);
5787
5824
  const createdCheckOutItemIds = [];
5788
5825
  for (const item of items) {
@@ -5790,6 +5827,7 @@ function useCheckOutItemService() {
5790
5827
  const createdId = await _createCheckOutItem(
5791
5828
  {
5792
5829
  site,
5830
+ serviceType,
5793
5831
  supply: item.supply,
5794
5832
  supplyName: supplyData?.name || "",
5795
5833
  qty: item.qty,
@@ -5802,6 +5840,7 @@ function useCheckOutItemService() {
5802
5840
  await createStock(
5803
5841
  {
5804
5842
  site,
5843
+ serviceType,
5805
5844
  supply: item.supply,
5806
5845
  qty: item.qty
5807
5846
  },
@@ -5850,6 +5889,7 @@ function useCheckOutItemController() {
5850
5889
  };
5851
5890
  const validation = Joi15.object({
5852
5891
  site: Joi15.string().hex().required(),
5892
+ serviceType: Joi15.string().valid(...Object.values(ServiceType)).required(),
5853
5893
  supply: Joi15.string().hex().required(),
5854
5894
  qty: Joi15.number().min(0).required(),
5855
5895
  attachment: Joi15.array().items(Joi15.string()).optional().allow(null),
@@ -5884,6 +5924,7 @@ function useCheckOutItemController() {
5884
5924
  };
5885
5925
  const validation = Joi15.object({
5886
5926
  site: Joi15.string().hex().required(),
5927
+ serviceType: Joi15.string().valid(...Object.values(ServiceType)).required(),
5887
5928
  createdBy: Joi15.string().hex().required(),
5888
5929
  items: Joi15.array().items(
5889
5930
  Joi15.object({
@@ -5915,7 +5956,8 @@ function useCheckOutItemController() {
5915
5956
  page: Joi15.number().min(1).optional().allow("", null),
5916
5957
  limit: Joi15.number().min(1).optional().allow("", null),
5917
5958
  search: Joi15.string().optional().allow("", null),
5918
- site: Joi15.string().hex().required()
5959
+ site: Joi15.string().hex().required(),
5960
+ serviceType: Joi15.string().valid(...Object.values(ServiceType)).required()
5919
5961
  });
5920
5962
  const { error } = validation.validate(query);
5921
5963
  if (error) {
@@ -5927,12 +5969,14 @@ function useCheckOutItemController() {
5927
5969
  const limit = parseInt(req.query.limit) ?? 10;
5928
5970
  const search = req.query.search ?? "";
5929
5971
  const site = req.params.site ?? "";
5972
+ const serviceType = req.query.serviceType ?? "";
5930
5973
  try {
5931
5974
  const data = await _getCheckOutItems({
5932
5975
  page,
5933
5976
  limit,
5934
5977
  search,
5935
- site
5978
+ site,
5979
+ serviceType
5936
5980
  });
5937
5981
  res.json(data);
5938
5982
  return;
@@ -6122,7 +6166,7 @@ function useScheduleTaskRepository() {
6122
6166
  throw new BadRequestError29("Invalid site ID format.");
6123
6167
  }
6124
6168
  if (search) {
6125
- query.$or = [{ name: { $regex: search, $options: "i" } }];
6169
+ query.$or = [{ title: { $regex: search, $options: "i" } }];
6126
6170
  cacheOptions.search = search;
6127
6171
  }
6128
6172
  const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
@@ -6261,6 +6305,39 @@ function useScheduleTaskRepository() {
6261
6305
  throw error;
6262
6306
  }
6263
6307
  }
6308
+ async function deleteScheduleTask(_id, session) {
6309
+ try {
6310
+ _id = new ObjectId19(_id);
6311
+ } catch (error) {
6312
+ throw new BadRequestError29("Invalid schedule task ID format.");
6313
+ }
6314
+ try {
6315
+ const updateValue = {
6316
+ status: "deleted",
6317
+ updatedAt: /* @__PURE__ */ new Date(),
6318
+ deletedAt: /* @__PURE__ */ new Date()
6319
+ };
6320
+ const res = await collection.updateOne(
6321
+ { _id },
6322
+ { $set: updateValue },
6323
+ { session }
6324
+ );
6325
+ if (res.modifiedCount === 0) {
6326
+ throw new InternalServerError11("Unable to delete schedule task.");
6327
+ }
6328
+ delNamespace().then(() => {
6329
+ logger31.info(`Cache cleared for namespace: ${namespace_collection}`);
6330
+ }).catch((err) => {
6331
+ logger31.error(
6332
+ `Failed to clear cache for namespace: ${namespace_collection}`,
6333
+ err
6334
+ );
6335
+ });
6336
+ return res.modifiedCount;
6337
+ } catch (error) {
6338
+ throw error;
6339
+ }
6340
+ }
6264
6341
  return {
6265
6342
  createIndex,
6266
6343
  createTextIndex,
@@ -6268,7 +6345,8 @@ function useScheduleTaskRepository() {
6268
6345
  getScheduleTasks,
6269
6346
  getAllScheduleTask,
6270
6347
  getScheduleTaskById,
6271
- updateScheduleTask
6348
+ updateScheduleTask,
6349
+ deleteScheduleTask
6272
6350
  };
6273
6351
  }
6274
6352
 
@@ -6571,7 +6649,8 @@ function useScheduleTaskController() {
6571
6649
  createScheduleTask: _createScheduleTask,
6572
6650
  getScheduleTasks: _getScheduleTasks,
6573
6651
  getScheduleTaskById: _getScheduleTaskById,
6574
- updateScheduleTask: _updateScheduleTask
6652
+ updateScheduleTask: _updateScheduleTask,
6653
+ deleteScheduleTask: _deleteScheduleTask
6575
6654
  } = useScheduleTaskRepository();
6576
6655
  async function createScheduleTask(req, res, next) {
6577
6656
  const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
@@ -6685,11 +6764,31 @@ function useScheduleTaskController() {
6685
6764
  return;
6686
6765
  }
6687
6766
  }
6767
+ async function deleteScheduleTask(req, res, next) {
6768
+ const validation = Joi17.string().hex().required();
6769
+ const _id = req.params.id;
6770
+ const { error, value } = validation.validate(_id);
6771
+ if (error) {
6772
+ logger33.log({ level: "error", message: error.message });
6773
+ next(new BadRequestError30(error.message));
6774
+ return;
6775
+ }
6776
+ try {
6777
+ const data = await _deleteScheduleTask(value);
6778
+ res.json(data);
6779
+ return;
6780
+ } catch (error2) {
6781
+ logger33.log({ level: "error", message: error2.message });
6782
+ next(error2);
6783
+ return;
6784
+ }
6785
+ }
6688
6786
  return {
6689
6787
  createScheduleTask,
6690
6788
  getScheduleTasks,
6691
6789
  getScheduleTaskById,
6692
- updateScheduleTask
6790
+ updateScheduleTask,
6791
+ deleteScheduleTask
6693
6792
  };
6694
6793
  }
6695
6794