@7365admin1/module-hygiene 4.14.0 → 4.15.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.ts +21 -13
- package/dist/index.js +111 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +111 -22
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -4707,6 +4707,7 @@ import { ObjectId as ObjectId12 } from "mongodb";
|
|
|
4707
4707
|
import { BadRequestError as BadRequestError17, logger as logger21 } from "@7365admin1/node-server-utils";
|
|
4708
4708
|
var supplySchema = Joi10.object({
|
|
4709
4709
|
site: Joi10.string().hex().required(),
|
|
4710
|
+
serviceType: Joi10.string().valid(...Object.values(ServiceType)).required(),
|
|
4710
4711
|
name: Joi10.string().required(),
|
|
4711
4712
|
unitOfMeasurement: Joi10.string().required()
|
|
4712
4713
|
});
|
|
@@ -4725,6 +4726,7 @@ function MSupply(value) {
|
|
|
4725
4726
|
}
|
|
4726
4727
|
return {
|
|
4727
4728
|
site: value.site,
|
|
4729
|
+
serviceType: value.serviceType,
|
|
4728
4730
|
name: value.name,
|
|
4729
4731
|
unitOfMeasurement: value.unitOfMeasurement,
|
|
4730
4732
|
qty: 0,
|
|
@@ -4757,7 +4759,10 @@ function useSupplyRepository() {
|
|
|
4757
4759
|
const { delNamespace, setCache, getCache } = useCache6(namespace_collection);
|
|
4758
4760
|
async function createIndex() {
|
|
4759
4761
|
try {
|
|
4760
|
-
await collection.createIndexes([
|
|
4762
|
+
await collection.createIndexes([
|
|
4763
|
+
{ key: { site: 1 } },
|
|
4764
|
+
{ key: { serviceType: 1 } }
|
|
4765
|
+
]);
|
|
4761
4766
|
} catch (error) {
|
|
4762
4767
|
throw new InternalServerError8(
|
|
4763
4768
|
"Failed to create index on hygiene supply."
|
|
@@ -4810,15 +4815,18 @@ function useSupplyRepository() {
|
|
|
4810
4815
|
page = 1,
|
|
4811
4816
|
limit = 10,
|
|
4812
4817
|
search = "",
|
|
4813
|
-
site
|
|
4818
|
+
site,
|
|
4819
|
+
serviceType
|
|
4814
4820
|
}) {
|
|
4815
4821
|
page = page > 0 ? page - 1 : 0;
|
|
4816
4822
|
const query = {
|
|
4817
|
-
status: { $ne: "deleted" }
|
|
4823
|
+
status: { $ne: "deleted" },
|
|
4824
|
+
serviceType
|
|
4818
4825
|
};
|
|
4819
4826
|
const cacheOptions = {
|
|
4820
4827
|
page,
|
|
4821
|
-
limit
|
|
4828
|
+
limit,
|
|
4829
|
+
serviceType
|
|
4822
4830
|
};
|
|
4823
4831
|
try {
|
|
4824
4832
|
site = new ObjectId13(site);
|
|
@@ -5022,7 +5030,8 @@ function useSupplyController() {
|
|
|
5022
5030
|
page: Joi11.number().min(1).optional().allow("", null),
|
|
5023
5031
|
limit: Joi11.number().min(1).optional().allow("", null),
|
|
5024
5032
|
search: Joi11.string().optional().allow("", null),
|
|
5025
|
-
site: Joi11.string().hex().required()
|
|
5033
|
+
site: Joi11.string().hex().required(),
|
|
5034
|
+
serviceType: Joi11.string().valid(...Object.values(ServiceType)).required()
|
|
5026
5035
|
});
|
|
5027
5036
|
const { error } = validation.validate(query);
|
|
5028
5037
|
if (error) {
|
|
@@ -5034,12 +5043,14 @@ function useSupplyController() {
|
|
|
5034
5043
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
5035
5044
|
const search = req.query.search ?? "";
|
|
5036
5045
|
const site = req.params.site ?? "";
|
|
5046
|
+
const serviceType = req.query.serviceType ?? "";
|
|
5037
5047
|
try {
|
|
5038
5048
|
const data = await _getSupplies({
|
|
5039
5049
|
page,
|
|
5040
5050
|
limit,
|
|
5041
5051
|
search,
|
|
5042
|
-
site
|
|
5052
|
+
site,
|
|
5053
|
+
serviceType
|
|
5043
5054
|
});
|
|
5044
5055
|
res.json(data);
|
|
5045
5056
|
return;
|
|
@@ -5095,10 +5106,8 @@ function useSupplyController() {
|
|
|
5095
5106
|
}
|
|
5096
5107
|
async function deleteSupply(req, res, next) {
|
|
5097
5108
|
const id = req.params.id;
|
|
5098
|
-
const validation = Joi11.
|
|
5099
|
-
|
|
5100
|
-
});
|
|
5101
|
-
const { error, value } = validation.validate({ id });
|
|
5109
|
+
const validation = Joi11.string().hex().required();
|
|
5110
|
+
const { error, value } = validation.validate(id);
|
|
5102
5111
|
if (error) {
|
|
5103
5112
|
logger23.log({ level: "error", message: error.message });
|
|
5104
5113
|
next(new BadRequestError19(error.message));
|
|
@@ -5129,6 +5138,7 @@ import { ObjectId as ObjectId14 } from "mongodb";
|
|
|
5129
5138
|
import { BadRequestError as BadRequestError20, logger as logger24 } from "@7365admin1/node-server-utils";
|
|
5130
5139
|
var stockSchema = Joi12.object({
|
|
5131
5140
|
site: Joi12.string().hex().required(),
|
|
5141
|
+
serviceType: Joi12.string().valid(...Object.values(ServiceType)).required(),
|
|
5132
5142
|
supply: Joi12.string().hex().required(),
|
|
5133
5143
|
in: Joi12.number().min(0).optional(),
|
|
5134
5144
|
out: Joi12.number().min(0).optional(),
|
|
@@ -5157,6 +5167,7 @@ function MStock(value) {
|
|
|
5157
5167
|
}
|
|
5158
5168
|
return {
|
|
5159
5169
|
site: value.site,
|
|
5170
|
+
serviceType: value.serviceType,
|
|
5160
5171
|
supply: value.supply,
|
|
5161
5172
|
in: value.in ?? 0,
|
|
5162
5173
|
out: value.out ?? 0,
|
|
@@ -5194,6 +5205,7 @@ function useStockRepository() {
|
|
|
5194
5205
|
try {
|
|
5195
5206
|
await collection.createIndexes([
|
|
5196
5207
|
{ key: { site: 1 } },
|
|
5208
|
+
{ key: { serviceType: 1 } },
|
|
5197
5209
|
{ key: { supply: 1 } },
|
|
5198
5210
|
{ key: { balance: 1 } },
|
|
5199
5211
|
{ key: { status: 1 } }
|
|
@@ -5232,15 +5244,18 @@ function useStockRepository() {
|
|
|
5232
5244
|
limit = 10,
|
|
5233
5245
|
search = "",
|
|
5234
5246
|
site,
|
|
5247
|
+
serviceType,
|
|
5235
5248
|
supply
|
|
5236
5249
|
}) {
|
|
5237
5250
|
page = page > 0 ? page - 1 : 0;
|
|
5238
5251
|
const query = {
|
|
5239
|
-
status: { $ne: "deleted" }
|
|
5252
|
+
status: { $ne: "deleted" },
|
|
5253
|
+
serviceType
|
|
5240
5254
|
};
|
|
5241
5255
|
const cacheOptions = {
|
|
5242
5256
|
page,
|
|
5243
|
-
limit
|
|
5257
|
+
limit,
|
|
5258
|
+
serviceType
|
|
5244
5259
|
};
|
|
5245
5260
|
try {
|
|
5246
5261
|
site = new ObjectId15(site);
|
|
@@ -5364,6 +5379,7 @@ function useStockController() {
|
|
|
5364
5379
|
const payload = { ...req.body, ...req.params };
|
|
5365
5380
|
const validation = Joi13.object({
|
|
5366
5381
|
site: Joi13.string().hex().required(),
|
|
5382
|
+
serviceType: Joi13.string().valid(...Object.values(ServiceType)).required(),
|
|
5367
5383
|
supply: Joi13.string().hex().required(),
|
|
5368
5384
|
qty: Joi13.number().min(0).required(),
|
|
5369
5385
|
remarks: Joi13.string().optional().allow("", null)
|
|
@@ -5391,6 +5407,7 @@ function useStockController() {
|
|
|
5391
5407
|
limit: Joi13.number().min(1).optional().allow("", null),
|
|
5392
5408
|
search: Joi13.string().optional().allow("", null),
|
|
5393
5409
|
site: Joi13.string().hex().required(),
|
|
5410
|
+
serviceType: Joi13.string().valid(...Object.values(ServiceType)).required(),
|
|
5394
5411
|
supply: Joi13.string().hex().required()
|
|
5395
5412
|
});
|
|
5396
5413
|
const { error } = validation.validate(query);
|
|
@@ -5403,6 +5420,7 @@ function useStockController() {
|
|
|
5403
5420
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
5404
5421
|
const search = req.query.search ?? "";
|
|
5405
5422
|
const site = req.params.site ?? "";
|
|
5423
|
+
const serviceType = req.query.serviceType ?? "";
|
|
5406
5424
|
const supply = req.params.supply ?? "";
|
|
5407
5425
|
try {
|
|
5408
5426
|
const data = await _getStocksBySupplyId({
|
|
@@ -5410,6 +5428,7 @@ function useStockController() {
|
|
|
5410
5428
|
limit,
|
|
5411
5429
|
search,
|
|
5412
5430
|
site,
|
|
5431
|
+
serviceType,
|
|
5413
5432
|
supply
|
|
5414
5433
|
});
|
|
5415
5434
|
res.json(data);
|
|
@@ -5433,6 +5452,7 @@ import { BadRequestError as BadRequestError24, logger as logger27 } from "@7365a
|
|
|
5433
5452
|
var allowedCheckOutItemStatus = ["pending", "completed"];
|
|
5434
5453
|
var checkOutItemSchema = Joi14.object({
|
|
5435
5454
|
site: Joi14.string().hex().required(),
|
|
5455
|
+
serviceType: Joi14.string().valid(...Object.values(ServiceType)).required(),
|
|
5436
5456
|
supply: Joi14.string().hex().required(),
|
|
5437
5457
|
supplyName: Joi14.string().required(),
|
|
5438
5458
|
qty: Joi14.number().min(0).required(),
|
|
@@ -5462,6 +5482,7 @@ function MCheckOutItem(value) {
|
|
|
5462
5482
|
}
|
|
5463
5483
|
return {
|
|
5464
5484
|
site: value.site,
|
|
5485
|
+
serviceType: value.serviceType,
|
|
5465
5486
|
supply: value.supply,
|
|
5466
5487
|
supplyName: value.supplyName,
|
|
5467
5488
|
qty: value.qty,
|
|
@@ -5499,6 +5520,7 @@ function useCheckOutItemRepository() {
|
|
|
5499
5520
|
try {
|
|
5500
5521
|
await collection.createIndexes([
|
|
5501
5522
|
{ key: { site: 1 } },
|
|
5523
|
+
{ key: { serviceType: 1 } },
|
|
5502
5524
|
{ key: { supply: 1 } },
|
|
5503
5525
|
{ key: { status: 1 } }
|
|
5504
5526
|
]);
|
|
@@ -5538,15 +5560,18 @@ function useCheckOutItemRepository() {
|
|
|
5538
5560
|
page = 1,
|
|
5539
5561
|
limit = 10,
|
|
5540
5562
|
search = "",
|
|
5541
|
-
site
|
|
5563
|
+
site,
|
|
5564
|
+
serviceType
|
|
5542
5565
|
}) {
|
|
5543
5566
|
page = page > 0 ? page - 1 : 0;
|
|
5544
5567
|
const query = {
|
|
5545
|
-
status: { $ne: "deleted" }
|
|
5568
|
+
status: { $ne: "deleted" },
|
|
5569
|
+
serviceType
|
|
5546
5570
|
};
|
|
5547
5571
|
const cacheOptions = {
|
|
5548
5572
|
page,
|
|
5549
|
-
limit
|
|
5573
|
+
limit,
|
|
5574
|
+
serviceType
|
|
5550
5575
|
};
|
|
5551
5576
|
try {
|
|
5552
5577
|
site = new ObjectId17(site);
|
|
@@ -5660,6 +5685,7 @@ function useCheckOutItemRepository() {
|
|
|
5660
5685
|
{
|
|
5661
5686
|
$project: {
|
|
5662
5687
|
site: 1,
|
|
5688
|
+
serviceType: 1,
|
|
5663
5689
|
supply: 1,
|
|
5664
5690
|
supplyName: 1,
|
|
5665
5691
|
qty: 1,
|
|
@@ -5762,6 +5788,7 @@ function useCheckOutItemService() {
|
|
|
5762
5788
|
const createdStocks = await createStock(
|
|
5763
5789
|
{
|
|
5764
5790
|
site: checkOutItem.site.toString(),
|
|
5791
|
+
serviceType: checkOutItem.serviceType,
|
|
5765
5792
|
supply: checkOutItem.supply.toString(),
|
|
5766
5793
|
qty: checkOutItem.qty
|
|
5767
5794
|
},
|
|
@@ -5782,7 +5809,7 @@ function useCheckOutItemService() {
|
|
|
5782
5809
|
const session = useAtlas13.getClient()?.startSession();
|
|
5783
5810
|
try {
|
|
5784
5811
|
session?.startTransaction();
|
|
5785
|
-
const { site, createdBy, items } = value;
|
|
5812
|
+
const { site, serviceType, createdBy, items } = value;
|
|
5786
5813
|
const createdByData = await getUserById(createdBy);
|
|
5787
5814
|
const createdCheckOutItemIds = [];
|
|
5788
5815
|
for (const item of items) {
|
|
@@ -5790,6 +5817,7 @@ function useCheckOutItemService() {
|
|
|
5790
5817
|
const createdId = await _createCheckOutItem(
|
|
5791
5818
|
{
|
|
5792
5819
|
site,
|
|
5820
|
+
serviceType,
|
|
5793
5821
|
supply: item.supply,
|
|
5794
5822
|
supplyName: supplyData?.name || "",
|
|
5795
5823
|
qty: item.qty,
|
|
@@ -5802,6 +5830,7 @@ function useCheckOutItemService() {
|
|
|
5802
5830
|
await createStock(
|
|
5803
5831
|
{
|
|
5804
5832
|
site,
|
|
5833
|
+
serviceType,
|
|
5805
5834
|
supply: item.supply,
|
|
5806
5835
|
qty: item.qty
|
|
5807
5836
|
},
|
|
@@ -5850,6 +5879,7 @@ function useCheckOutItemController() {
|
|
|
5850
5879
|
};
|
|
5851
5880
|
const validation = Joi15.object({
|
|
5852
5881
|
site: Joi15.string().hex().required(),
|
|
5882
|
+
serviceType: Joi15.string().valid(...Object.values(ServiceType)).required(),
|
|
5853
5883
|
supply: Joi15.string().hex().required(),
|
|
5854
5884
|
qty: Joi15.number().min(0).required(),
|
|
5855
5885
|
attachment: Joi15.array().items(Joi15.string()).optional().allow(null),
|
|
@@ -5884,6 +5914,7 @@ function useCheckOutItemController() {
|
|
|
5884
5914
|
};
|
|
5885
5915
|
const validation = Joi15.object({
|
|
5886
5916
|
site: Joi15.string().hex().required(),
|
|
5917
|
+
serviceType: Joi15.string().valid(...Object.values(ServiceType)).required(),
|
|
5887
5918
|
createdBy: Joi15.string().hex().required(),
|
|
5888
5919
|
items: Joi15.array().items(
|
|
5889
5920
|
Joi15.object({
|
|
@@ -5915,7 +5946,8 @@ function useCheckOutItemController() {
|
|
|
5915
5946
|
page: Joi15.number().min(1).optional().allow("", null),
|
|
5916
5947
|
limit: Joi15.number().min(1).optional().allow("", null),
|
|
5917
5948
|
search: Joi15.string().optional().allow("", null),
|
|
5918
|
-
site: Joi15.string().hex().required()
|
|
5949
|
+
site: Joi15.string().hex().required(),
|
|
5950
|
+
serviceType: Joi15.string().valid(...Object.values(ServiceType)).required()
|
|
5919
5951
|
});
|
|
5920
5952
|
const { error } = validation.validate(query);
|
|
5921
5953
|
if (error) {
|
|
@@ -5927,12 +5959,14 @@ function useCheckOutItemController() {
|
|
|
5927
5959
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
5928
5960
|
const search = req.query.search ?? "";
|
|
5929
5961
|
const site = req.params.site ?? "";
|
|
5962
|
+
const serviceType = req.query.serviceType ?? "";
|
|
5930
5963
|
try {
|
|
5931
5964
|
const data = await _getCheckOutItems({
|
|
5932
5965
|
page,
|
|
5933
5966
|
limit,
|
|
5934
5967
|
search,
|
|
5935
|
-
site
|
|
5968
|
+
site,
|
|
5969
|
+
serviceType
|
|
5936
5970
|
});
|
|
5937
5971
|
res.json(data);
|
|
5938
5972
|
return;
|
|
@@ -6122,7 +6156,7 @@ function useScheduleTaskRepository() {
|
|
|
6122
6156
|
throw new BadRequestError29("Invalid site ID format.");
|
|
6123
6157
|
}
|
|
6124
6158
|
if (search) {
|
|
6125
|
-
query.$or = [{
|
|
6159
|
+
query.$or = [{ title: { $regex: search, $options: "i" } }];
|
|
6126
6160
|
cacheOptions.search = search;
|
|
6127
6161
|
}
|
|
6128
6162
|
const cacheKey = makeCacheKey9(namespace_collection, cacheOptions);
|
|
@@ -6261,6 +6295,39 @@ function useScheduleTaskRepository() {
|
|
|
6261
6295
|
throw error;
|
|
6262
6296
|
}
|
|
6263
6297
|
}
|
|
6298
|
+
async function deleteScheduleTask(_id, session) {
|
|
6299
|
+
try {
|
|
6300
|
+
_id = new ObjectId19(_id);
|
|
6301
|
+
} catch (error) {
|
|
6302
|
+
throw new BadRequestError29("Invalid schedule task ID format.");
|
|
6303
|
+
}
|
|
6304
|
+
try {
|
|
6305
|
+
const updateValue = {
|
|
6306
|
+
status: "deleted",
|
|
6307
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
6308
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
6309
|
+
};
|
|
6310
|
+
const res = await collection.updateOne(
|
|
6311
|
+
{ _id },
|
|
6312
|
+
{ $set: updateValue },
|
|
6313
|
+
{ session }
|
|
6314
|
+
);
|
|
6315
|
+
if (res.modifiedCount === 0) {
|
|
6316
|
+
throw new InternalServerError11("Unable to delete schedule task.");
|
|
6317
|
+
}
|
|
6318
|
+
delNamespace().then(() => {
|
|
6319
|
+
logger31.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
6320
|
+
}).catch((err) => {
|
|
6321
|
+
logger31.error(
|
|
6322
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
6323
|
+
err
|
|
6324
|
+
);
|
|
6325
|
+
});
|
|
6326
|
+
return res.modifiedCount;
|
|
6327
|
+
} catch (error) {
|
|
6328
|
+
throw error;
|
|
6329
|
+
}
|
|
6330
|
+
}
|
|
6264
6331
|
return {
|
|
6265
6332
|
createIndex,
|
|
6266
6333
|
createTextIndex,
|
|
@@ -6268,7 +6335,8 @@ function useScheduleTaskRepository() {
|
|
|
6268
6335
|
getScheduleTasks,
|
|
6269
6336
|
getAllScheduleTask,
|
|
6270
6337
|
getScheduleTaskById,
|
|
6271
|
-
updateScheduleTask
|
|
6338
|
+
updateScheduleTask,
|
|
6339
|
+
deleteScheduleTask
|
|
6272
6340
|
};
|
|
6273
6341
|
}
|
|
6274
6342
|
|
|
@@ -6571,7 +6639,8 @@ function useScheduleTaskController() {
|
|
|
6571
6639
|
createScheduleTask: _createScheduleTask,
|
|
6572
6640
|
getScheduleTasks: _getScheduleTasks,
|
|
6573
6641
|
getScheduleTaskById: _getScheduleTaskById,
|
|
6574
|
-
updateScheduleTask: _updateScheduleTask
|
|
6642
|
+
updateScheduleTask: _updateScheduleTask,
|
|
6643
|
+
deleteScheduleTask: _deleteScheduleTask
|
|
6575
6644
|
} = useScheduleTaskRepository();
|
|
6576
6645
|
async function createScheduleTask(req, res, next) {
|
|
6577
6646
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
@@ -6685,11 +6754,31 @@ function useScheduleTaskController() {
|
|
|
6685
6754
|
return;
|
|
6686
6755
|
}
|
|
6687
6756
|
}
|
|
6757
|
+
async function deleteScheduleTask(req, res, next) {
|
|
6758
|
+
const validation = Joi17.string().hex().required();
|
|
6759
|
+
const _id = req.params.id;
|
|
6760
|
+
const { error, value } = validation.validate(_id);
|
|
6761
|
+
if (error) {
|
|
6762
|
+
logger33.log({ level: "error", message: error.message });
|
|
6763
|
+
next(new BadRequestError30(error.message));
|
|
6764
|
+
return;
|
|
6765
|
+
}
|
|
6766
|
+
try {
|
|
6767
|
+
const data = await _deleteScheduleTask(value);
|
|
6768
|
+
res.json(data);
|
|
6769
|
+
return;
|
|
6770
|
+
} catch (error2) {
|
|
6771
|
+
logger33.log({ level: "error", message: error2.message });
|
|
6772
|
+
next(error2);
|
|
6773
|
+
return;
|
|
6774
|
+
}
|
|
6775
|
+
}
|
|
6688
6776
|
return {
|
|
6689
6777
|
createScheduleTask,
|
|
6690
6778
|
getScheduleTasks,
|
|
6691
6779
|
getScheduleTaskById,
|
|
6692
|
-
updateScheduleTask
|
|
6780
|
+
updateScheduleTask,
|
|
6781
|
+
deleteScheduleTask
|
|
6693
6782
|
};
|
|
6694
6783
|
}
|
|
6695
6784
|
|