refactor: warehouse transfers

This commit is contained in:
Ahmed Bouhuolia
2025-03-13 02:40:09 +02:00
parent cf496909a5
commit 197d173db9
6 changed files with 37 additions and 25 deletions

View File

@@ -4,18 +4,18 @@ import { Inject, Injectable } from '@nestjs/common';
import { InventoryTransaction } from '../models/InventoryTransaction';
import { InventoryCostLotTracker } from '../models/InventoryCostLotTracker';
import { Item } from '../../Items/models/Item';
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
@Injectable()
export class InventoryItemCostService {
constructor(
@Inject(InventoryTransaction.name)
private readonly inventoryTransactionModel: typeof InventoryTransaction,
@Inject(InventoryCostLotTracker.name)
private readonly inventoryCostLotTrackerModel: typeof InventoryCostLotTracker,
private readonly inventoryCostLotTrackerModel: TenantModelProxy<
typeof InventoryCostLotTracker
>,
@Inject(Item.name)
private readonly itemModel: typeof Item,
private readonly itemModel: TenantModelProxy<typeof Item>,
) {}
/**
@@ -64,12 +64,12 @@ export class InventoryItemCostService {
builder.groupBy('item_id');
builder.select(['item_id']);
};
const INValuationOper = this.inventoryCostLotTrackerModel
const INValuationOper = this.inventoryCostLotTrackerModel()
.query()
.onBuild(commonBuilder)
.where('direction', 'IN');
const OUTValuationOper = this.inventoryCostLotTrackerModel
const OUTValuationOper = this.inventoryCostLotTrackerModel()
.query()
.onBuild(commonBuilder)
.where('direction', 'OUT');
@@ -104,7 +104,7 @@ export class InventoryItemCostService {
date: Date,
): Promise<Map<number, IInventoryItemCostMeta>> => {
// Retrieves the inventory items.
const items = await this.itemModel
const items = await this.itemModel()
.query()
.whereIn('id', itemsId)
.where('type', 'inventory');

View File

@@ -12,6 +12,9 @@ import { TenantModelProxy } from '../../System/models/TenantBaseModel';
*/
@Injectable()
export class InventoryItemsQuantitySyncService {
/**
* @param {TenantModelProxy<typeof Item>} itemModel - Item model.
*/
constructor(
@Inject(Item.name)
private readonly itemModel: TenantModelProxy<typeof Item>,

View File

@@ -15,14 +15,23 @@ import { IItemEntryTransactionType } from '../../TransactionItemEntry/ItemEntry.
import { ItemEntry } from '../../TransactionItemEntry/models/ItemEntry';
export class InventoryTransactionsService {
/**
* @param {EventEmitter2} eventEmitter - Event emitter.
* @param {TenantModelProxy<typeof InventoryTransaction>} inventoryTransactionModel - Inventory transaction model.
* @param {TenantModelProxy<typeof InventoryCostLotTracker>} inventoryCostLotTracker - Inventory cost lot tracker model.
*/
constructor(
private readonly eventEmitter: EventEmitter2,
@Inject(InventoryTransaction.name)
private readonly inventoryTransactionModel: typeof InventoryTransaction,
private readonly inventoryTransactionModel: TenantModelProxy<
typeof InventoryTransaction
>,
@Inject(InventoryCostLotTracker.name)
private readonly inventoryCostLotTracker: typeof InventoryCostLotTracker,
private readonly inventoryCostLotTracker: TenantModelProxy<
typeof InventoryCostLotTracker
>,
) {}
/**
@@ -75,9 +84,11 @@ export class InventoryTransactionsService {
trx,
);
}
return this.inventoryTransactionModel.query(trx).insertGraph({
...inventoryEntry,
});
return this.inventoryTransactionModel()
.query(trx)
.insertGraph({
...inventoryEntry,
});
}
/**
@@ -137,7 +148,7 @@ export class InventoryTransactionsService {
.where({ transactionId, transactionType });
// Deletes the inventory transactions by the given transaction type and id.
await this.inventoryTransactionModel
await this.inventoryTransactionModel()
.query(trx)
.where({ transactionType, transactionId })
.delete();