mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 22:00:31 +00:00
refactor: tenant proxy providers
This commit is contained in:
@@ -15,9 +15,8 @@ const models = [
|
||||
];
|
||||
|
||||
@Module({
|
||||
imports: [LedgerModule],
|
||||
imports: [LedgerModule, ...models],
|
||||
providers: [
|
||||
...models,
|
||||
InventoryCostGLBeforeWriteSubscriber,
|
||||
InventoryCostGLStorage,
|
||||
InventoryItemsQuantitySyncService,
|
||||
|
||||
@@ -2,11 +2,14 @@ import { Knex } from 'knex';
|
||||
import { Inject } from '@nestjs/common';
|
||||
import { omit } from 'lodash';
|
||||
import { InventoryCostLotTracker } from './models/InventoryCostLotTracker';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
|
||||
export class InventoryCostMethod {
|
||||
constructor(
|
||||
@Inject(InventoryCostLotTracker.name)
|
||||
private readonly inventoryCostLotTracker: typeof InventoryCostLotTracker,
|
||||
private readonly inventoryCostLotTracker: TenantModelProxy<
|
||||
typeof InventoryCostLotTracker
|
||||
>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -23,16 +26,18 @@ export class InventoryCostMethod {
|
||||
|
||||
costLotsTransactions.forEach((transaction: any) => {
|
||||
if (transaction.lotTransId && transaction.decrement) {
|
||||
const decrementOper = this.inventoryCostLotTracker
|
||||
const decrementOper = this.inventoryCostLotTracker()
|
||||
.query(trx)
|
||||
.where('id', transaction.lotTransId)
|
||||
.decrement('remaining', transaction.decrement);
|
||||
|
||||
opers.push(decrementOper);
|
||||
} else if (!transaction.lotTransId) {
|
||||
const operation = this.inventoryCostLotTracker.query(trx).insert({
|
||||
...omit(transaction, ['decrement', 'invTransId', 'lotTransId']),
|
||||
});
|
||||
const operation = this.inventoryCostLotTracker()
|
||||
.query(trx)
|
||||
.insert({
|
||||
...omit(transaction, ['decrement', 'invTransId', 'lotTransId']),
|
||||
});
|
||||
opers.push(operation);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -5,6 +5,7 @@ import { Inject } from '@nestjs/common';
|
||||
import { Item } from '../Items/models/Item';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InventoryTransaction } from './models/InventoryTransaction';
|
||||
import { TenantModelProxy } from '../System/models/TenantBaseModel';
|
||||
|
||||
/**
|
||||
* Syncs the inventory transactions with inventory items quantity.
|
||||
@@ -12,7 +13,8 @@ import { InventoryTransaction } from './models/InventoryTransaction';
|
||||
@Injectable()
|
||||
export class InventoryItemsQuantitySyncService {
|
||||
constructor(
|
||||
@Inject(Item.name) private readonly itemModel: typeof Item,
|
||||
@Inject(Item.name)
|
||||
private readonly itemModel: TenantModelProxy<typeof Item>,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -84,7 +86,7 @@ export class InventoryItemsQuantitySyncService {
|
||||
const opers = [];
|
||||
|
||||
itemsQuantity.forEach((itemQuantity: IItemsQuantityChanges) => {
|
||||
const changeQuantityOper = this.itemModel
|
||||
const changeQuantityOper = this.itemModel()
|
||||
.query(trx)
|
||||
.where({ id: itemQuantity.itemId, type: 'inventory' })
|
||||
.modify('quantityOnHand', itemQuantity.balanceChange);
|
||||
|
||||
Reference in New Issue
Block a user