@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/CHANGELOG.md +12 -0
- package/dist/index.d.ts +41 -31
- package/dist/index.js +145 -46
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +145 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1240,11 +1240,13 @@ function useUnitRepository() {
|
|
|
1240
1240
|
}) {
|
|
1241
1241
|
page = page > 0 ? page - 1 : 0;
|
|
1242
1242
|
const query = {
|
|
1243
|
-
status: { $ne: "deleted" }
|
|
1243
|
+
status: { $ne: "deleted" },
|
|
1244
|
+
serviceType
|
|
1244
1245
|
};
|
|
1245
1246
|
const cacheOptions = {
|
|
1246
1247
|
page,
|
|
1247
|
-
limit
|
|
1248
|
+
limit,
|
|
1249
|
+
serviceType
|
|
1248
1250
|
};
|
|
1249
1251
|
try {
|
|
1250
1252
|
site = new import_mongodb5.ObjectId(site);
|
|
@@ -1253,10 +1255,6 @@ function useUnitRepository() {
|
|
|
1253
1255
|
} catch (error) {
|
|
1254
1256
|
throw new import_node_server_utils7.BadRequestError("Invalid site ID format.");
|
|
1255
1257
|
}
|
|
1256
|
-
if (serviceType) {
|
|
1257
|
-
query.serviceType = serviceType;
|
|
1258
|
-
cacheOptions.serviceType = serviceType;
|
|
1259
|
-
}
|
|
1260
1258
|
if (search) {
|
|
1261
1259
|
query.$or = [{ name: { $regex: search, $options: "i" } }];
|
|
1262
1260
|
cacheOptions.search = search;
|
|
@@ -2678,6 +2676,7 @@ function useParentChecklistRepo() {
|
|
|
2678
2676
|
getAllParentChecklist,
|
|
2679
2677
|
getParentChecklistById,
|
|
2680
2678
|
updateParentChecklistStatuses,
|
|
2679
|
+
getHygieneSiteIds,
|
|
2681
2680
|
closeExpiredParentChecklists,
|
|
2682
2681
|
getTodayParentChecklists,
|
|
2683
2682
|
getTodayParentChecklistsForAreaGen
|
|
@@ -2694,7 +2693,12 @@ function useParentChecklistController() {
|
|
|
2694
2693
|
} = useParentChecklistRepo();
|
|
2695
2694
|
async function createParentChecklist(req, res, next) {
|
|
2696
2695
|
const payload = req.body;
|
|
2697
|
-
const
|
|
2696
|
+
const validation = import_joi7.default.object({
|
|
2697
|
+
createdAt: import_joi7.default.alternatives().try(import_joi7.default.date(), import_joi7.default.string()).optional().allow("", null),
|
|
2698
|
+
site: import_joi7.default.string().hex().required(),
|
|
2699
|
+
serviceType: import_joi7.default.string().valid(...Object.values(ServiceType)).optional().allow("", null)
|
|
2700
|
+
});
|
|
2701
|
+
const { error } = validation.validate(payload);
|
|
2698
2702
|
if (error) {
|
|
2699
2703
|
import_node_server_utils15.logger.log({ level: "error", message: error.message });
|
|
2700
2704
|
next(new import_node_server_utils15.BadRequestError(error.message));
|
|
@@ -2768,7 +2772,7 @@ var import_node_server_utils16 = require("@7365admin1/node-server-utils");
|
|
|
2768
2772
|
var allowedChecklistStatus = ["open", "completed", "closed"];
|
|
2769
2773
|
var areaChecklistSchema = import_joi8.default.object({
|
|
2770
2774
|
schedule: import_joi8.default.string().hex().required(),
|
|
2771
|
-
serviceType: import_joi8.default.string().valid(...Object.values(ServiceType)).
|
|
2775
|
+
serviceType: import_joi8.default.string().valid(...Object.values(ServiceType)).required(),
|
|
2772
2776
|
area: import_joi8.default.string().hex().required(),
|
|
2773
2777
|
name: import_joi8.default.string().required(),
|
|
2774
2778
|
type: import_joi8.default.string().valid(...allowedTypes).required(),
|
|
@@ -2949,10 +2953,11 @@ function useAreaChecklistRepo() {
|
|
|
2949
2953
|
serviceType
|
|
2950
2954
|
}, session) {
|
|
2951
2955
|
page = page > 0 ? page - 1 : 0;
|
|
2952
|
-
const query = {};
|
|
2956
|
+
const query = { serviceType };
|
|
2953
2957
|
const cacheOptions = {
|
|
2954
2958
|
page,
|
|
2955
|
-
limit
|
|
2959
|
+
limit,
|
|
2960
|
+
serviceType
|
|
2956
2961
|
};
|
|
2957
2962
|
try {
|
|
2958
2963
|
query.schedule = new import_mongodb9.ObjectId(schedule);
|
|
@@ -2960,10 +2965,6 @@ function useAreaChecklistRepo() {
|
|
|
2960
2965
|
} catch (error) {
|
|
2961
2966
|
throw new import_node_server_utils17.BadRequestError("Invalid parent checklist ID format.");
|
|
2962
2967
|
}
|
|
2963
|
-
if (serviceType) {
|
|
2964
|
-
query.serviceType = serviceType;
|
|
2965
|
-
cacheOptions.serviceType = serviceType;
|
|
2966
|
-
}
|
|
2967
2968
|
if (type && type !== "all") {
|
|
2968
2969
|
query.type = type;
|
|
2969
2970
|
cacheOptions.type = type;
|
|
@@ -3363,10 +3364,11 @@ function useAreaChecklistRepo() {
|
|
|
3363
3364
|
_id
|
|
3364
3365
|
}, session) {
|
|
3365
3366
|
page = page > 0 ? page - 1 : 0;
|
|
3366
|
-
const query = {};
|
|
3367
|
+
const query = { serviceType };
|
|
3367
3368
|
const cacheOptions = {
|
|
3368
3369
|
page,
|
|
3369
|
-
limit
|
|
3370
|
+
limit,
|
|
3371
|
+
serviceType
|
|
3370
3372
|
};
|
|
3371
3373
|
try {
|
|
3372
3374
|
query._id = new import_mongodb9.ObjectId(_id);
|
|
@@ -3374,10 +3376,6 @@ function useAreaChecklistRepo() {
|
|
|
3374
3376
|
} catch (error) {
|
|
3375
3377
|
throw new import_node_server_utils17.BadRequestError("Invalid area checklist ID format.");
|
|
3376
3378
|
}
|
|
3377
|
-
if (serviceType) {
|
|
3378
|
-
query.serviceType = serviceType;
|
|
3379
|
-
cacheOptions.serviceType = serviceType;
|
|
3380
|
-
}
|
|
3381
3379
|
if (search) {
|
|
3382
3380
|
query.$text = { $search: search };
|
|
3383
3381
|
cacheOptions.search = search;
|
|
@@ -3591,7 +3589,16 @@ function useAreaChecklistRepo() {
|
|
|
3591
3589
|
try {
|
|
3592
3590
|
const area = await collection.findOne(
|
|
3593
3591
|
{ _id },
|
|
3594
|
-
{
|
|
3592
|
+
{
|
|
3593
|
+
projection: {
|
|
3594
|
+
schedule: 1,
|
|
3595
|
+
serviceType: 1,
|
|
3596
|
+
name: 1,
|
|
3597
|
+
type: 1,
|
|
3598
|
+
status: 1
|
|
3599
|
+
},
|
|
3600
|
+
session
|
|
3601
|
+
}
|
|
3595
3602
|
);
|
|
3596
3603
|
if (!area) {
|
|
3597
3604
|
throw new import_node_server_utils17.BadRequestError("Area checklist not found.");
|
|
@@ -4150,10 +4157,14 @@ function useAreaChecklistService() {
|
|
|
4150
4157
|
);
|
|
4151
4158
|
}
|
|
4152
4159
|
await _updateAreaChecklistUnits(_id, set, unitId, value, session);
|
|
4160
|
+
const currentArea = await getAreaChecklistById(_id, session);
|
|
4161
|
+
const scheduleId = currentArea.schedule;
|
|
4162
|
+
const serviceType = currentArea.serviceType;
|
|
4153
4163
|
const allUnitsResult = await getAreaChecklistUnits(
|
|
4154
4164
|
{
|
|
4155
4165
|
page: 1,
|
|
4156
4166
|
limit: 1e3,
|
|
4167
|
+
serviceType,
|
|
4157
4168
|
_id: _id.toString()
|
|
4158
4169
|
},
|
|
4159
4170
|
session
|
|
@@ -4178,14 +4189,13 @@ function useAreaChecklistService() {
|
|
|
4178
4189
|
}
|
|
4179
4190
|
}
|
|
4180
4191
|
await updateAreaChecklistStatus(_id, areaStatus, session);
|
|
4181
|
-
const currentArea = await getAreaChecklistById(_id, session);
|
|
4182
|
-
const scheduleId = currentArea.schedule;
|
|
4183
4192
|
if (scheduleId) {
|
|
4184
4193
|
const allAreasResult = await getAllAreaChecklist(
|
|
4185
4194
|
{
|
|
4186
4195
|
page: 1,
|
|
4187
4196
|
limit: 1e3,
|
|
4188
|
-
schedule: scheduleId.toString()
|
|
4197
|
+
schedule: scheduleId.toString(),
|
|
4198
|
+
serviceType
|
|
4189
4199
|
},
|
|
4190
4200
|
session
|
|
4191
4201
|
);
|
|
@@ -4735,6 +4745,7 @@ var import_mongodb12 = require("mongodb");
|
|
|
4735
4745
|
var import_node_server_utils21 = require("@7365admin1/node-server-utils");
|
|
4736
4746
|
var supplySchema = import_joi10.default.object({
|
|
4737
4747
|
site: import_joi10.default.string().hex().required(),
|
|
4748
|
+
serviceType: import_joi10.default.string().valid(...Object.values(ServiceType)).required(),
|
|
4738
4749
|
name: import_joi10.default.string().required(),
|
|
4739
4750
|
unitOfMeasurement: import_joi10.default.string().required()
|
|
4740
4751
|
});
|
|
@@ -4753,6 +4764,7 @@ function MSupply(value) {
|
|
|
4753
4764
|
}
|
|
4754
4765
|
return {
|
|
4755
4766
|
site: value.site,
|
|
4767
|
+
serviceType: value.serviceType,
|
|
4756
4768
|
name: value.name,
|
|
4757
4769
|
unitOfMeasurement: value.unitOfMeasurement,
|
|
4758
4770
|
qty: 0,
|
|
@@ -4776,7 +4788,10 @@ function useSupplyRepository() {
|
|
|
4776
4788
|
const { delNamespace, setCache, getCache } = (0, import_node_server_utils22.useCache)(namespace_collection);
|
|
4777
4789
|
async function createIndex() {
|
|
4778
4790
|
try {
|
|
4779
|
-
await collection.createIndexes([
|
|
4791
|
+
await collection.createIndexes([
|
|
4792
|
+
{ key: { site: 1 } },
|
|
4793
|
+
{ key: { serviceType: 1 } }
|
|
4794
|
+
]);
|
|
4780
4795
|
} catch (error) {
|
|
4781
4796
|
throw new import_node_server_utils22.InternalServerError(
|
|
4782
4797
|
"Failed to create index on hygiene supply."
|
|
@@ -4829,15 +4844,18 @@ function useSupplyRepository() {
|
|
|
4829
4844
|
page = 1,
|
|
4830
4845
|
limit = 10,
|
|
4831
4846
|
search = "",
|
|
4832
|
-
site
|
|
4847
|
+
site,
|
|
4848
|
+
serviceType
|
|
4833
4849
|
}) {
|
|
4834
4850
|
page = page > 0 ? page - 1 : 0;
|
|
4835
4851
|
const query = {
|
|
4836
|
-
status: { $ne: "deleted" }
|
|
4852
|
+
status: { $ne: "deleted" },
|
|
4853
|
+
serviceType
|
|
4837
4854
|
};
|
|
4838
4855
|
const cacheOptions = {
|
|
4839
4856
|
page,
|
|
4840
|
-
limit
|
|
4857
|
+
limit,
|
|
4858
|
+
serviceType
|
|
4841
4859
|
};
|
|
4842
4860
|
try {
|
|
4843
4861
|
site = new import_mongodb13.ObjectId(site);
|
|
@@ -5041,7 +5059,8 @@ function useSupplyController() {
|
|
|
5041
5059
|
page: import_joi11.default.number().min(1).optional().allow("", null),
|
|
5042
5060
|
limit: import_joi11.default.number().min(1).optional().allow("", null),
|
|
5043
5061
|
search: import_joi11.default.string().optional().allow("", null),
|
|
5044
|
-
site: import_joi11.default.string().hex().required()
|
|
5062
|
+
site: import_joi11.default.string().hex().required(),
|
|
5063
|
+
serviceType: import_joi11.default.string().valid(...Object.values(ServiceType)).required()
|
|
5045
5064
|
});
|
|
5046
5065
|
const { error } = validation.validate(query);
|
|
5047
5066
|
if (error) {
|
|
@@ -5053,12 +5072,14 @@ function useSupplyController() {
|
|
|
5053
5072
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
5054
5073
|
const search = req.query.search ?? "";
|
|
5055
5074
|
const site = req.params.site ?? "";
|
|
5075
|
+
const serviceType = req.query.serviceType ?? "";
|
|
5056
5076
|
try {
|
|
5057
5077
|
const data = await _getSupplies({
|
|
5058
5078
|
page,
|
|
5059
5079
|
limit,
|
|
5060
5080
|
search,
|
|
5061
|
-
site
|
|
5081
|
+
site,
|
|
5082
|
+
serviceType
|
|
5062
5083
|
});
|
|
5063
5084
|
res.json(data);
|
|
5064
5085
|
return;
|
|
@@ -5114,10 +5135,8 @@ function useSupplyController() {
|
|
|
5114
5135
|
}
|
|
5115
5136
|
async function deleteSupply(req, res, next) {
|
|
5116
5137
|
const id = req.params.id;
|
|
5117
|
-
const validation = import_joi11.default.
|
|
5118
|
-
|
|
5119
|
-
});
|
|
5120
|
-
const { error, value } = validation.validate({ id });
|
|
5138
|
+
const validation = import_joi11.default.string().hex().required();
|
|
5139
|
+
const { error, value } = validation.validate(id);
|
|
5121
5140
|
if (error) {
|
|
5122
5141
|
import_node_server_utils23.logger.log({ level: "error", message: error.message });
|
|
5123
5142
|
next(new import_node_server_utils23.BadRequestError(error.message));
|
|
@@ -5148,6 +5167,7 @@ var import_mongodb14 = require("mongodb");
|
|
|
5148
5167
|
var import_node_server_utils24 = require("@7365admin1/node-server-utils");
|
|
5149
5168
|
var stockSchema = import_joi12.default.object({
|
|
5150
5169
|
site: import_joi12.default.string().hex().required(),
|
|
5170
|
+
serviceType: import_joi12.default.string().valid(...Object.values(ServiceType)).required(),
|
|
5151
5171
|
supply: import_joi12.default.string().hex().required(),
|
|
5152
5172
|
in: import_joi12.default.number().min(0).optional(),
|
|
5153
5173
|
out: import_joi12.default.number().min(0).optional(),
|
|
@@ -5176,6 +5196,7 @@ function MStock(value) {
|
|
|
5176
5196
|
}
|
|
5177
5197
|
return {
|
|
5178
5198
|
site: value.site,
|
|
5199
|
+
serviceType: value.serviceType,
|
|
5179
5200
|
supply: value.supply,
|
|
5180
5201
|
in: value.in ?? 0,
|
|
5181
5202
|
out: value.out ?? 0,
|
|
@@ -5205,6 +5226,7 @@ function useStockRepository() {
|
|
|
5205
5226
|
try {
|
|
5206
5227
|
await collection.createIndexes([
|
|
5207
5228
|
{ key: { site: 1 } },
|
|
5229
|
+
{ key: { serviceType: 1 } },
|
|
5208
5230
|
{ key: { supply: 1 } },
|
|
5209
5231
|
{ key: { balance: 1 } },
|
|
5210
5232
|
{ key: { status: 1 } }
|
|
@@ -5243,15 +5265,18 @@ function useStockRepository() {
|
|
|
5243
5265
|
limit = 10,
|
|
5244
5266
|
search = "",
|
|
5245
5267
|
site,
|
|
5268
|
+
serviceType,
|
|
5246
5269
|
supply
|
|
5247
5270
|
}) {
|
|
5248
5271
|
page = page > 0 ? page - 1 : 0;
|
|
5249
5272
|
const query = {
|
|
5250
|
-
status: { $ne: "deleted" }
|
|
5273
|
+
status: { $ne: "deleted" },
|
|
5274
|
+
serviceType
|
|
5251
5275
|
};
|
|
5252
5276
|
const cacheOptions = {
|
|
5253
5277
|
page,
|
|
5254
|
-
limit
|
|
5278
|
+
limit,
|
|
5279
|
+
serviceType
|
|
5255
5280
|
};
|
|
5256
5281
|
try {
|
|
5257
5282
|
site = new import_mongodb15.ObjectId(site);
|
|
@@ -5371,6 +5396,7 @@ function useStockController() {
|
|
|
5371
5396
|
const payload = { ...req.body, ...req.params };
|
|
5372
5397
|
const validation = import_joi13.default.object({
|
|
5373
5398
|
site: import_joi13.default.string().hex().required(),
|
|
5399
|
+
serviceType: import_joi13.default.string().valid(...Object.values(ServiceType)).required(),
|
|
5374
5400
|
supply: import_joi13.default.string().hex().required(),
|
|
5375
5401
|
qty: import_joi13.default.number().min(0).required(),
|
|
5376
5402
|
remarks: import_joi13.default.string().optional().allow("", null)
|
|
@@ -5398,6 +5424,7 @@ function useStockController() {
|
|
|
5398
5424
|
limit: import_joi13.default.number().min(1).optional().allow("", null),
|
|
5399
5425
|
search: import_joi13.default.string().optional().allow("", null),
|
|
5400
5426
|
site: import_joi13.default.string().hex().required(),
|
|
5427
|
+
serviceType: import_joi13.default.string().valid(...Object.values(ServiceType)).required(),
|
|
5401
5428
|
supply: import_joi13.default.string().hex().required()
|
|
5402
5429
|
});
|
|
5403
5430
|
const { error } = validation.validate(query);
|
|
@@ -5410,6 +5437,7 @@ function useStockController() {
|
|
|
5410
5437
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
5411
5438
|
const search = req.query.search ?? "";
|
|
5412
5439
|
const site = req.params.site ?? "";
|
|
5440
|
+
const serviceType = req.query.serviceType ?? "";
|
|
5413
5441
|
const supply = req.params.supply ?? "";
|
|
5414
5442
|
try {
|
|
5415
5443
|
const data = await _getStocksBySupplyId({
|
|
@@ -5417,6 +5445,7 @@ function useStockController() {
|
|
|
5417
5445
|
limit,
|
|
5418
5446
|
search,
|
|
5419
5447
|
site,
|
|
5448
|
+
serviceType,
|
|
5420
5449
|
supply
|
|
5421
5450
|
});
|
|
5422
5451
|
res.json(data);
|
|
@@ -5440,6 +5469,7 @@ var import_node_server_utils28 = require("@7365admin1/node-server-utils");
|
|
|
5440
5469
|
var allowedCheckOutItemStatus = ["pending", "completed"];
|
|
5441
5470
|
var checkOutItemSchema = import_joi14.default.object({
|
|
5442
5471
|
site: import_joi14.default.string().hex().required(),
|
|
5472
|
+
serviceType: import_joi14.default.string().valid(...Object.values(ServiceType)).required(),
|
|
5443
5473
|
supply: import_joi14.default.string().hex().required(),
|
|
5444
5474
|
supplyName: import_joi14.default.string().required(),
|
|
5445
5475
|
qty: import_joi14.default.number().min(0).required(),
|
|
@@ -5469,6 +5499,7 @@ function MCheckOutItem(value) {
|
|
|
5469
5499
|
}
|
|
5470
5500
|
return {
|
|
5471
5501
|
site: value.site,
|
|
5502
|
+
serviceType: value.serviceType,
|
|
5472
5503
|
supply: value.supply,
|
|
5473
5504
|
supplyName: value.supplyName,
|
|
5474
5505
|
qty: value.qty,
|
|
@@ -5497,6 +5528,7 @@ function useCheckOutItemRepository() {
|
|
|
5497
5528
|
try {
|
|
5498
5529
|
await collection.createIndexes([
|
|
5499
5530
|
{ key: { site: 1 } },
|
|
5531
|
+
{ key: { serviceType: 1 } },
|
|
5500
5532
|
{ key: { supply: 1 } },
|
|
5501
5533
|
{ key: { status: 1 } }
|
|
5502
5534
|
]);
|
|
@@ -5536,15 +5568,18 @@ function useCheckOutItemRepository() {
|
|
|
5536
5568
|
page = 1,
|
|
5537
5569
|
limit = 10,
|
|
5538
5570
|
search = "",
|
|
5539
|
-
site
|
|
5571
|
+
site,
|
|
5572
|
+
serviceType
|
|
5540
5573
|
}) {
|
|
5541
5574
|
page = page > 0 ? page - 1 : 0;
|
|
5542
5575
|
const query = {
|
|
5543
|
-
status: { $ne: "deleted" }
|
|
5576
|
+
status: { $ne: "deleted" },
|
|
5577
|
+
serviceType
|
|
5544
5578
|
};
|
|
5545
5579
|
const cacheOptions = {
|
|
5546
5580
|
page,
|
|
5547
|
-
limit
|
|
5581
|
+
limit,
|
|
5582
|
+
serviceType
|
|
5548
5583
|
};
|
|
5549
5584
|
try {
|
|
5550
5585
|
site = new import_mongodb17.ObjectId(site);
|
|
@@ -5658,6 +5693,7 @@ function useCheckOutItemRepository() {
|
|
|
5658
5693
|
{
|
|
5659
5694
|
$project: {
|
|
5660
5695
|
site: 1,
|
|
5696
|
+
serviceType: 1,
|
|
5661
5697
|
supply: 1,
|
|
5662
5698
|
supplyName: 1,
|
|
5663
5699
|
qty: 1,
|
|
@@ -5760,6 +5796,7 @@ function useCheckOutItemService() {
|
|
|
5760
5796
|
const createdStocks = await createStock(
|
|
5761
5797
|
{
|
|
5762
5798
|
site: checkOutItem.site.toString(),
|
|
5799
|
+
serviceType: checkOutItem.serviceType,
|
|
5763
5800
|
supply: checkOutItem.supply.toString(),
|
|
5764
5801
|
qty: checkOutItem.qty
|
|
5765
5802
|
},
|
|
@@ -5780,7 +5817,7 @@ function useCheckOutItemService() {
|
|
|
5780
5817
|
const session = import_node_server_utils30.useAtlas.getClient()?.startSession();
|
|
5781
5818
|
try {
|
|
5782
5819
|
session?.startTransaction();
|
|
5783
|
-
const { site, createdBy, items } = value;
|
|
5820
|
+
const { site, serviceType, createdBy, items } = value;
|
|
5784
5821
|
const createdByData = await getUserById(createdBy);
|
|
5785
5822
|
const createdCheckOutItemIds = [];
|
|
5786
5823
|
for (const item of items) {
|
|
@@ -5788,6 +5825,7 @@ function useCheckOutItemService() {
|
|
|
5788
5825
|
const createdId = await _createCheckOutItem(
|
|
5789
5826
|
{
|
|
5790
5827
|
site,
|
|
5828
|
+
serviceType,
|
|
5791
5829
|
supply: item.supply,
|
|
5792
5830
|
supplyName: supplyData?.name || "",
|
|
5793
5831
|
qty: item.qty,
|
|
@@ -5800,6 +5838,7 @@ function useCheckOutItemService() {
|
|
|
5800
5838
|
await createStock(
|
|
5801
5839
|
{
|
|
5802
5840
|
site,
|
|
5841
|
+
serviceType,
|
|
5803
5842
|
supply: item.supply,
|
|
5804
5843
|
qty: item.qty
|
|
5805
5844
|
},
|
|
@@ -5848,6 +5887,7 @@ function useCheckOutItemController() {
|
|
|
5848
5887
|
};
|
|
5849
5888
|
const validation = import_joi15.default.object({
|
|
5850
5889
|
site: import_joi15.default.string().hex().required(),
|
|
5890
|
+
serviceType: import_joi15.default.string().valid(...Object.values(ServiceType)).required(),
|
|
5851
5891
|
supply: import_joi15.default.string().hex().required(),
|
|
5852
5892
|
qty: import_joi15.default.number().min(0).required(),
|
|
5853
5893
|
attachment: import_joi15.default.array().items(import_joi15.default.string()).optional().allow(null),
|
|
@@ -5882,6 +5922,7 @@ function useCheckOutItemController() {
|
|
|
5882
5922
|
};
|
|
5883
5923
|
const validation = import_joi15.default.object({
|
|
5884
5924
|
site: import_joi15.default.string().hex().required(),
|
|
5925
|
+
serviceType: import_joi15.default.string().valid(...Object.values(ServiceType)).required(),
|
|
5885
5926
|
createdBy: import_joi15.default.string().hex().required(),
|
|
5886
5927
|
items: import_joi15.default.array().items(
|
|
5887
5928
|
import_joi15.default.object({
|
|
@@ -5913,7 +5954,8 @@ function useCheckOutItemController() {
|
|
|
5913
5954
|
page: import_joi15.default.number().min(1).optional().allow("", null),
|
|
5914
5955
|
limit: import_joi15.default.number().min(1).optional().allow("", null),
|
|
5915
5956
|
search: import_joi15.default.string().optional().allow("", null),
|
|
5916
|
-
site: import_joi15.default.string().hex().required()
|
|
5957
|
+
site: import_joi15.default.string().hex().required(),
|
|
5958
|
+
serviceType: import_joi15.default.string().valid(...Object.values(ServiceType)).required()
|
|
5917
5959
|
});
|
|
5918
5960
|
const { error } = validation.validate(query);
|
|
5919
5961
|
if (error) {
|
|
@@ -5925,12 +5967,14 @@ function useCheckOutItemController() {
|
|
|
5925
5967
|
const limit = parseInt(req.query.limit) ?? 10;
|
|
5926
5968
|
const search = req.query.search ?? "";
|
|
5927
5969
|
const site = req.params.site ?? "";
|
|
5970
|
+
const serviceType = req.query.serviceType ?? "";
|
|
5928
5971
|
try {
|
|
5929
5972
|
const data = await _getCheckOutItems({
|
|
5930
5973
|
page,
|
|
5931
5974
|
limit,
|
|
5932
5975
|
search,
|
|
5933
|
-
site
|
|
5976
|
+
site,
|
|
5977
|
+
serviceType
|
|
5934
5978
|
});
|
|
5935
5979
|
res.json(data);
|
|
5936
5980
|
return;
|
|
@@ -6111,7 +6155,7 @@ function useScheduleTaskRepository() {
|
|
|
6111
6155
|
throw new import_node_server_utils33.BadRequestError("Invalid site ID format.");
|
|
6112
6156
|
}
|
|
6113
6157
|
if (search) {
|
|
6114
|
-
query.$or = [{
|
|
6158
|
+
query.$or = [{ title: { $regex: search, $options: "i" } }];
|
|
6115
6159
|
cacheOptions.search = search;
|
|
6116
6160
|
}
|
|
6117
6161
|
const cacheKey = (0, import_node_server_utils33.makeCacheKey)(namespace_collection, cacheOptions);
|
|
@@ -6250,6 +6294,39 @@ function useScheduleTaskRepository() {
|
|
|
6250
6294
|
throw error;
|
|
6251
6295
|
}
|
|
6252
6296
|
}
|
|
6297
|
+
async function deleteScheduleTask(_id, session) {
|
|
6298
|
+
try {
|
|
6299
|
+
_id = new import_mongodb19.ObjectId(_id);
|
|
6300
|
+
} catch (error) {
|
|
6301
|
+
throw new import_node_server_utils33.BadRequestError("Invalid schedule task ID format.");
|
|
6302
|
+
}
|
|
6303
|
+
try {
|
|
6304
|
+
const updateValue = {
|
|
6305
|
+
status: "deleted",
|
|
6306
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
6307
|
+
deletedAt: /* @__PURE__ */ new Date()
|
|
6308
|
+
};
|
|
6309
|
+
const res = await collection.updateOne(
|
|
6310
|
+
{ _id },
|
|
6311
|
+
{ $set: updateValue },
|
|
6312
|
+
{ session }
|
|
6313
|
+
);
|
|
6314
|
+
if (res.modifiedCount === 0) {
|
|
6315
|
+
throw new import_node_server_utils33.InternalServerError("Unable to delete schedule task.");
|
|
6316
|
+
}
|
|
6317
|
+
delNamespace().then(() => {
|
|
6318
|
+
import_node_server_utils33.logger.info(`Cache cleared for namespace: ${namespace_collection}`);
|
|
6319
|
+
}).catch((err) => {
|
|
6320
|
+
import_node_server_utils33.logger.error(
|
|
6321
|
+
`Failed to clear cache for namespace: ${namespace_collection}`,
|
|
6322
|
+
err
|
|
6323
|
+
);
|
|
6324
|
+
});
|
|
6325
|
+
return res.modifiedCount;
|
|
6326
|
+
} catch (error) {
|
|
6327
|
+
throw error;
|
|
6328
|
+
}
|
|
6329
|
+
}
|
|
6253
6330
|
return {
|
|
6254
6331
|
createIndex,
|
|
6255
6332
|
createTextIndex,
|
|
@@ -6257,7 +6334,8 @@ function useScheduleTaskRepository() {
|
|
|
6257
6334
|
getScheduleTasks,
|
|
6258
6335
|
getAllScheduleTask,
|
|
6259
6336
|
getScheduleTaskById,
|
|
6260
|
-
updateScheduleTask
|
|
6337
|
+
updateScheduleTask,
|
|
6338
|
+
deleteScheduleTask
|
|
6261
6339
|
};
|
|
6262
6340
|
}
|
|
6263
6341
|
|
|
@@ -6560,7 +6638,8 @@ function useScheduleTaskController() {
|
|
|
6560
6638
|
createScheduleTask: _createScheduleTask,
|
|
6561
6639
|
getScheduleTasks: _getScheduleTasks,
|
|
6562
6640
|
getScheduleTaskById: _getScheduleTaskById,
|
|
6563
|
-
updateScheduleTask: _updateScheduleTask
|
|
6641
|
+
updateScheduleTask: _updateScheduleTask,
|
|
6642
|
+
deleteScheduleTask: _deleteScheduleTask
|
|
6564
6643
|
} = useScheduleTaskRepository();
|
|
6565
6644
|
async function createScheduleTask(req, res, next) {
|
|
6566
6645
|
const cookies = req.headers.cookie ? req.headers.cookie.split(";").map((cookie) => cookie.trim().split("=")).reduce(
|
|
@@ -6674,11 +6753,31 @@ function useScheduleTaskController() {
|
|
|
6674
6753
|
return;
|
|
6675
6754
|
}
|
|
6676
6755
|
}
|
|
6756
|
+
async function deleteScheduleTask(req, res, next) {
|
|
6757
|
+
const validation = import_joi17.default.string().hex().required();
|
|
6758
|
+
const _id = req.params.id;
|
|
6759
|
+
const { error, value } = validation.validate(_id);
|
|
6760
|
+
if (error) {
|
|
6761
|
+
import_node_server_utils35.logger.log({ level: "error", message: error.message });
|
|
6762
|
+
next(new import_node_server_utils35.BadRequestError(error.message));
|
|
6763
|
+
return;
|
|
6764
|
+
}
|
|
6765
|
+
try {
|
|
6766
|
+
const data = await _deleteScheduleTask(value);
|
|
6767
|
+
res.json(data);
|
|
6768
|
+
return;
|
|
6769
|
+
} catch (error2) {
|
|
6770
|
+
import_node_server_utils35.logger.log({ level: "error", message: error2.message });
|
|
6771
|
+
next(error2);
|
|
6772
|
+
return;
|
|
6773
|
+
}
|
|
6774
|
+
}
|
|
6677
6775
|
return {
|
|
6678
6776
|
createScheduleTask,
|
|
6679
6777
|
getScheduleTasks,
|
|
6680
6778
|
getScheduleTaskById,
|
|
6681
|
-
updateScheduleTask
|
|
6779
|
+
updateScheduleTask,
|
|
6780
|
+
deleteScheduleTask
|
|
6682
6781
|
};
|
|
6683
6782
|
}
|
|
6684
6783
|
|