mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
add server to monorepo.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { Service, Inject } from 'typedi';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { CashflowTransactionTransformer } from './CashflowTransactionTransformer';
|
||||
import { ERRORS } from './constants';
|
||||
import { ICashflowTransaction } from '@/interfaces';
|
||||
import { ServiceError } from '@/exceptions';
|
||||
import I18nService from '@/services/I18n/I18nService';
|
||||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||
|
||||
@Service()
|
||||
export default class GetCashflowTransactionsService {
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
@Inject()
|
||||
private i18nService: I18nService;
|
||||
|
||||
@Inject()
|
||||
private transfromer: TransformerInjectable;
|
||||
|
||||
/**
|
||||
* Retrieve the given cashflow transaction.
|
||||
* @param {number} tenantId
|
||||
* @param {number} cashflowTransactionId
|
||||
* @returns
|
||||
*/
|
||||
public getCashflowTransaction = async (
|
||||
tenantId: number,
|
||||
cashflowTransactionId: number
|
||||
) => {
|
||||
const { CashflowTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
const cashflowTransaction = await CashflowTransaction.query()
|
||||
.findById(cashflowTransactionId)
|
||||
.withGraphFetched('entries.cashflowAccount')
|
||||
.withGraphFetched('entries.creditAccount')
|
||||
.withGraphFetched('transactions.account')
|
||||
.throwIfNotFound();
|
||||
|
||||
this.throwErrorCashflowTranscationNotFound(cashflowTransaction);
|
||||
|
||||
// Transformes the cashflow transaction model to POJO.
|
||||
return this.transfromer.transform(
|
||||
tenantId,
|
||||
cashflowTransaction,
|
||||
new CashflowTransactionTransformer()
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Throw not found error if the given cashflow undefined.
|
||||
* @param {ICashflowTransaction} cashflowTransaction -
|
||||
*/
|
||||
private throwErrorCashflowTranscationNotFound = (
|
||||
cashflowTransaction: ICashflowTransaction
|
||||
) => {
|
||||
if (!cashflowTransaction) {
|
||||
throw new ServiceError(ERRORS.CASHFLOW_TRANSACTION_NOT_FOUND);
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user