refactor: inventory cost to nestjs

This commit is contained in:
Ahmed Bouhuolia
2025-03-11 22:12:08 +02:00
parent 40b7daa2e3
commit 67ae7ad037
44 changed files with 1436 additions and 1763 deletions

View File

@@ -6,6 +6,7 @@ import { ItemEntry } from '../TransactionItemEntry/models/ItemEntry';
import { ServiceError } from './ServiceError';
import { IItemEntryDTO } from '../TransactionItemEntry/ItemEntry.types';
import { TenantModelProxy } from '../System/models/TenantBaseModel';
import { entriesAmountDiff } from '@/utils/entries-amount-diff';
const ERRORS = {
ITEMS_NOT_FOUND: 'ITEMS_NOT_FOUND',
@@ -176,21 +177,21 @@ export class ItemsEntriesService {
): Promise<void> {
const opers = [];
// const diffEntries = entriesAmountDiff(
// entries,
// oldEntries,
// 'quantity',
// 'itemId',
// );
// diffEntries.forEach((entry: ItemEntry) => {
// const changeQuantityOper = this.itemRepository.changeNumber(
// { id: entry.itemId, type: 'inventory' },
// 'quantityOnHand',
// entry.quantity,
// );
// opers.push(changeQuantityOper);
// });
// await Promise.all(opers);
const diffEntries = entriesAmountDiff(
entries,
oldEntries,
'quantity',
'itemId',
);
diffEntries.forEach((entry: ItemEntry) => {
const changeQuantityOper = this.itemModel()
.query()
.where({ id: entry.itemId, type: 'inventory' })
.modify('quantityOnHand', entry.quantity);
opers.push(changeQuantityOper);
});
await Promise.all(opers);
}
/**