refactor: split the services to multiple service classes (#202)

This commit is contained in:
Ahmed Bouhuolia
2023-08-10 20:29:39 +02:00
committed by GitHub
parent ffef627dc3
commit 26c6ca9e36
150 changed files with 7188 additions and 5007 deletions

View File

@@ -41,13 +41,16 @@ export default class AllocateLandedCost extends BaseLandedCostService {
allocateCostDTO: ILandedCostDTO,
billId: number
): Promise<IBillLandedCost> => {
const { BillLandedCost } = this.tenancy.models(tenantId);
const { BillLandedCost, Bill } = this.tenancy.models(tenantId);
// Retrieve total cost of allocated items.
const amount = this.getAllocateItemsCostTotal(allocateCostDTO);
// Retrieve the purchase invoice or throw not found error.
const bill = await this.billsService.getBillOrThrowError(tenantId, billId);
const bill = await Bill.query()
.findById(billId)
.withGraphFetched('entries')
.throwIfNotFound();
// Retrieve landed cost transaction or throw not found service error.
const costTransaction = await this.getLandedCostOrThrowError(

View File

@@ -1,6 +1,5 @@
import { Inject, Service } from 'typedi';
import { difference, sumBy } from 'lodash';
import BillsService from '../Bills';
import { ServiceError } from '@/exceptions';
import {
IItemEntry,
@@ -13,14 +12,10 @@ import {
} from '@/interfaces';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import TransactionLandedCost from './TransctionLandedCost';
import { ERRORS } from './utils';
import { CONFIG } from './utils';
import { ERRORS, CONFIG } from './utils';
@Service()
export default class BaseLandedCostService {
@Inject()
public billsService: BillsService;
@Inject()
public tenancy: HasTenancyService;

View File

@@ -9,7 +9,7 @@ import LandedCostSyncCostTransactions from './LandedCostSyncCostTransactions';
@Service()
export default class LandedCostSyncCostTransactionsSubscriber {
@Inject()
landedCostSyncCostTransaction: LandedCostSyncCostTransactions;
private landedCostSyncCostTransaction: LandedCostSyncCostTransactions;
/**
* Attaches events with handlers.

View File

@@ -9,20 +9,12 @@ import {
ILandedCostTransactionEntryDOJO,
} from '@/interfaces';
import TransactionLandedCost from './TransctionLandedCost';
import BillsService from '../Bills';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { formatNumber } from 'utils';
@Service()
export default class LandedCostTranasctions {
@Inject()
transactionLandedCost: TransactionLandedCost;
@Inject()
billsService: BillsService;
@Inject()
tenancy: HasTenancyService;
private transactionLandedCost: TransactionLandedCost;
/**
* Retrieve the landed costs based on the given query.

View File

@@ -16,13 +16,13 @@ import { ERRORS } from './utils';
@Service()
export default class TransactionLandedCost {
@Inject()
billLandedCost: BillLandedCost;
private billLandedCost: BillLandedCost;
@Inject()
expenseLandedCost: ExpenseLandedCost;
private expenseLandedCost: ExpenseLandedCost;
@Inject()
tenancy: HasTenancyService;
private tenancy: HasTenancyService;
/**
* Retrieve the cost transaction code model.