fix: item-batch validation

This commit is contained in:
akshayitzme
2023-01-18 17:32:26 +05:30
parent fc75a8b536
commit 81d84f4220
3 changed files with 53 additions and 3 deletions
+21 -3
View File
@@ -132,6 +132,26 @@ export class BespokeQueries {
`);
}
static async itemHasTransactions(
db: DatabaseCore,
item: string
): Promise<boolean> {
/*
* to check if an item of given name is present in the SLE
* taking the count of items from SLE which has the given item name
* if the count is greater than 0 considers item exists in SLE, returns true
* if the count is lesser than 0 considers item does not exist in SLE, returns false
*/
const query = db.knex!(ModelNameEnum.StockLedgerEntry)
.select('item')
.where('item', item);
const value = (await query) as Record<string, string | null>[];
if (!value) return false;
return true;
}
static async getStockQuantity(
db: DatabaseCore,
item: string,
@@ -167,6 +187,4 @@ export class BespokeQueries {
return value[0][Object.keys(value[0])[0]];
}
}
//
}