@7365admin1/module-hygiene 4.27.2-staging.3 → 4.27.2-staging.5
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.d.ts +4 -2
- package/dist/index.js +32 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +32 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -519,6 +519,7 @@ type TCheckOutItem = {
|
|
|
519
519
|
serviceType: TAppServiceType;
|
|
520
520
|
supply: string | ObjectId;
|
|
521
521
|
supplyName: string;
|
|
522
|
+
supplyQty: number;
|
|
522
523
|
qty: number;
|
|
523
524
|
attachment?: string[];
|
|
524
525
|
createdBy: string | ObjectId;
|
|
@@ -528,7 +529,7 @@ type TCheckOutItem = {
|
|
|
528
529
|
updatedAt?: string;
|
|
529
530
|
deletedAt?: string;
|
|
530
531
|
};
|
|
531
|
-
type TCheckOutItemCreate = Pick<TCheckOutItem, "site" | "serviceType" | "supply" | "supplyName" | "qty" | "attachment" | "createdBy" | "createdByName">;
|
|
532
|
+
type TCheckOutItemCreate = Pick<TCheckOutItem, "site" | "serviceType" | "supply" | "supplyName" | "supplyQty" | "qty" | "attachment" | "createdBy" | "createdByName">;
|
|
532
533
|
type TCheckOutItemCreateService = Pick<TCheckOutItem, "site" | "serviceType" | "supply" | "qty" | "attachment" | "createdBy">;
|
|
533
534
|
type TCheckOutItemCreateByBatchService = Pick<TCheckOutItem, "site" | "serviceType" | "createdBy"> & {
|
|
534
535
|
items: Pick<TCheckOutItem, "supply" | "qty" | "attachment">[];
|
|
@@ -538,7 +539,7 @@ type TCheckOutItemGetQuery = {
|
|
|
538
539
|
limit?: number;
|
|
539
540
|
search?: string;
|
|
540
541
|
} & Pick<TCheckOutItem, "site" | "serviceType">;
|
|
541
|
-
type TCheckOutItemGetById = Pick<TCheckOutItem, "_id" | "site" | "serviceType" | "supply" | "supplyName" | "qty" | "status"> & {
|
|
542
|
+
type TCheckOutItemGetById = Pick<TCheckOutItem, "_id" | "site" | "serviceType" | "supply" | "supplyName" | "supplyQty" | "qty" | "status"> & {
|
|
542
543
|
unitOfMeasurement?: string;
|
|
543
544
|
};
|
|
544
545
|
declare const checkOutItemSchema: Joi.ObjectSchema<any>;
|
|
@@ -547,6 +548,7 @@ declare function MCheckOutItem(value: TCheckOutItemCreate): {
|
|
|
547
548
|
serviceType: AppServiceType;
|
|
548
549
|
supply: string | ObjectId;
|
|
549
550
|
supplyName: string;
|
|
551
|
+
supplyQty: number;
|
|
550
552
|
qty: number;
|
|
551
553
|
attachment: string[];
|
|
552
554
|
createdBy: string | ObjectId;
|
package/dist/index.js
CHANGED
|
@@ -3314,7 +3314,19 @@ function useAreaChecklistRepo() {
|
|
|
3314
3314
|
}
|
|
3315
3315
|
async function createUniqueIndex() {
|
|
3316
3316
|
try {
|
|
3317
|
-
await collection.createIndex(
|
|
3317
|
+
await collection.createIndex(
|
|
3318
|
+
{ schedule: 1, area: 1, serviceType: 1 },
|
|
3319
|
+
{ unique: true }
|
|
3320
|
+
);
|
|
3321
|
+
const legacyIndex = (await collection.indexes()).find((index) => {
|
|
3322
|
+
return index.unique === true && JSON.stringify(index.key) === JSON.stringify({ schedule: 1, area: 1 });
|
|
3323
|
+
});
|
|
3324
|
+
if (legacyIndex?.name) {
|
|
3325
|
+
await collection.dropIndex(legacyIndex.name);
|
|
3326
|
+
import_node_server_utils17.logger.info(
|
|
3327
|
+
`Dropped legacy hygiene area checklist unique index: ${legacyIndex.name}`
|
|
3328
|
+
);
|
|
3329
|
+
}
|
|
3318
3330
|
} catch (error) {
|
|
3319
3331
|
throw new import_node_server_utils17.InternalServerError(
|
|
3320
3332
|
"Failed to create unique index on hygiene checklist area."
|
|
@@ -3326,7 +3338,7 @@ function useAreaChecklistRepo() {
|
|
|
3326
3338
|
const parentChecklistId = new import_mongodb9.ObjectId(value.schedule);
|
|
3327
3339
|
const areaId = new import_mongodb9.ObjectId(value.area);
|
|
3328
3340
|
const existingChecklist = await collection.findOne(
|
|
3329
|
-
{ schedule: parentChecklistId, area: areaId },
|
|
3341
|
+
{ schedule: parentChecklistId, area: areaId, serviceType: value.serviceType },
|
|
3330
3342
|
{ session }
|
|
3331
3343
|
);
|
|
3332
3344
|
if (existingChecklist) {
|
|
@@ -3344,7 +3356,8 @@ function useAreaChecklistRepo() {
|
|
|
3344
3356
|
import_node_server_utils17.logger.info(`Duplicate area checklist skipped for area ${value.name}`);
|
|
3345
3357
|
const existing = await collection.findOne({
|
|
3346
3358
|
schedule: new import_mongodb9.ObjectId(value.schedule),
|
|
3347
|
-
area: new import_mongodb9.ObjectId(value.area)
|
|
3359
|
+
area: new import_mongodb9.ObjectId(value.area),
|
|
3360
|
+
serviceType: value.serviceType
|
|
3348
3361
|
});
|
|
3349
3362
|
return existing._id;
|
|
3350
3363
|
}
|
|
@@ -5180,9 +5193,18 @@ function useSupplyRepository() {
|
|
|
5180
5193
|
async function createUniqueIndex() {
|
|
5181
5194
|
try {
|
|
5182
5195
|
await collection.createIndex(
|
|
5183
|
-
{ site: 1, name: 1, deletedAt: 1 },
|
|
5196
|
+
{ site: 1, serviceType: 1, name: 1, deletedAt: 1 },
|
|
5184
5197
|
{ unique: true }
|
|
5185
5198
|
);
|
|
5199
|
+
const legacyIndex = (await collection.indexes()).find((index) => {
|
|
5200
|
+
return index.unique === true && JSON.stringify(index.key) === JSON.stringify({ site: 1, name: 1, deletedAt: 1 });
|
|
5201
|
+
});
|
|
5202
|
+
if (legacyIndex?.name) {
|
|
5203
|
+
await collection.dropIndex(legacyIndex.name);
|
|
5204
|
+
import_node_server_utils22.logger.info(
|
|
5205
|
+
`Dropped legacy hygiene supply unique index: ${legacyIndex.name}`
|
|
5206
|
+
);
|
|
5207
|
+
}
|
|
5186
5208
|
} catch (error) {
|
|
5187
5209
|
throw new import_node_server_utils22.InternalServerError(
|
|
5188
5210
|
"Failed to create unique index on hygiene supply."
|
|
@@ -5849,6 +5871,7 @@ var checkOutItemSchema = import_joi14.default.object({
|
|
|
5849
5871
|
serviceType: import_joi14.default.string().valid(...Object.values(import_core16.AppServiceType)).required(),
|
|
5850
5872
|
supply: import_joi14.default.string().hex().required(),
|
|
5851
5873
|
supplyName: import_joi14.default.string().required(),
|
|
5874
|
+
supplyQty: import_joi14.default.number().min(0).required(),
|
|
5852
5875
|
qty: import_joi14.default.number().min(0).required(),
|
|
5853
5876
|
attachment: import_joi14.default.array().items(import_joi14.default.string()).optional().allow(null),
|
|
5854
5877
|
createdBy: import_joi14.default.string().hex().required(),
|
|
@@ -5879,6 +5902,7 @@ function MCheckOutItem(value) {
|
|
|
5879
5902
|
serviceType: value.serviceType,
|
|
5880
5903
|
supply: value.supply,
|
|
5881
5904
|
supplyName: value.supplyName,
|
|
5905
|
+
supplyQty: value.supplyQty,
|
|
5882
5906
|
qty: value.qty,
|
|
5883
5907
|
attachment: value.attachment || [],
|
|
5884
5908
|
createdBy: value.createdBy,
|
|
@@ -5983,32 +6007,6 @@ function useCheckOutItemRepository() {
|
|
|
5983
6007
|
try {
|
|
5984
6008
|
const items = await collection.aggregate([
|
|
5985
6009
|
{ $match: query },
|
|
5986
|
-
{
|
|
5987
|
-
$lookup: {
|
|
5988
|
-
from: "site.supplies",
|
|
5989
|
-
let: { supplyId: "$supply" },
|
|
5990
|
-
pipeline: [
|
|
5991
|
-
{
|
|
5992
|
-
$match: {
|
|
5993
|
-
$expr: {
|
|
5994
|
-
$and: [
|
|
5995
|
-
{ $ne: ["$$supplyId", ""] },
|
|
5996
|
-
{ $eq: ["$_id", "$$supplyId"] }
|
|
5997
|
-
]
|
|
5998
|
-
}
|
|
5999
|
-
}
|
|
6000
|
-
},
|
|
6001
|
-
{ $project: { qty: 1 } }
|
|
6002
|
-
],
|
|
6003
|
-
as: "supplyDoc"
|
|
6004
|
-
}
|
|
6005
|
-
},
|
|
6006
|
-
{
|
|
6007
|
-
$unwind: {
|
|
6008
|
-
path: "$supplyDoc",
|
|
6009
|
-
preserveNullAndEmptyArrays: true
|
|
6010
|
-
}
|
|
6011
|
-
},
|
|
6012
6010
|
{
|
|
6013
6011
|
$lookup: {
|
|
6014
6012
|
from: "users",
|
|
@@ -6035,7 +6033,7 @@ function useCheckOutItemRepository() {
|
|
|
6035
6033
|
{
|
|
6036
6034
|
$project: {
|
|
6037
6035
|
supplyName: 1,
|
|
6038
|
-
supplyQty:
|
|
6036
|
+
supplyQty: 1,
|
|
6039
6037
|
checkOutByName: "$createdByName",
|
|
6040
6038
|
profile: "$createdByDoc.profile",
|
|
6041
6039
|
checkOutQty: "$qty",
|
|
@@ -6105,7 +6103,7 @@ function useCheckOutItemRepository() {
|
|
|
6105
6103
|
qty: 1,
|
|
6106
6104
|
status: 1,
|
|
6107
6105
|
unitOfMeasurement: "$supplyDetails.unitOfMeasurement",
|
|
6108
|
-
stockQty: "$
|
|
6106
|
+
stockQty: "$supplyQty",
|
|
6109
6107
|
attachment: 1
|
|
6110
6108
|
}
|
|
6111
6109
|
}
|
|
@@ -6189,6 +6187,7 @@ function useCheckOutItemService() {
|
|
|
6189
6187
|
{
|
|
6190
6188
|
...value,
|
|
6191
6189
|
supplyName: supplyData?.name || "",
|
|
6190
|
+
supplyQty: Math.max((supplyData?.qty || 0) - value.qty, 0),
|
|
6192
6191
|
createdByName: createdByData?.name || ""
|
|
6193
6192
|
},
|
|
6194
6193
|
session
|
|
@@ -6235,6 +6234,7 @@ function useCheckOutItemService() {
|
|
|
6235
6234
|
serviceType,
|
|
6236
6235
|
supply: item.supply,
|
|
6237
6236
|
supplyName: supplyData?.name || "",
|
|
6237
|
+
supplyQty: Math.max((supplyData?.qty || 0) - item.qty, 0),
|
|
6238
6238
|
qty: item.qty,
|
|
6239
6239
|
attachment: item.attachment,
|
|
6240
6240
|
createdBy,
|