fix: specific account transactions.

fix: specific expense associated expense account graph.
fix: specific manual journal associated account and contact graph.
This commit is contained in:
a.bouhuolia
2021-04-25 23:41:54 +02:00
parent fcc95d9e01
commit c75109a975
7 changed files with 102 additions and 4 deletions

View File

@@ -8,7 +8,9 @@ import {
IAccount,
IAccountsFilter,
IFilterMeta,
IAccountResponse
IAccountResponse,
IAccountsTransactionsFilter,
IAccountTransaction
} from 'interfaces';
import {
EventDispatcher,
@@ -317,7 +319,8 @@ export default class AccountsService {
* @param {number} accountId
*/
public async getAccount(tenantId: number, accountId: number) {
return this.getAccountOrThrowError(tenantId, accountId);
const account = await this.getAccountOrThrowError(tenantId, accountId);
return this.transformAccountResponse(tenantId, account);
}
/**
@@ -628,6 +631,45 @@ export default class AccountsService {
};
}
/**
* Retrieve the accounts transactions.
* @param {number} tenantId -
* @param {IAccountsTransactionsFilter} filter -
*/
public async getAccountsTransactions(
tenantId: number,
filter: IAccountsTransactionsFilter,
): Promise<{ transactions: IAccountTransaction }> {
const { AccountTransaction } = this.tenancy.models(tenantId);
this.logger.info('[accounts] trying to get accounts transactions list.');
const transactions = await AccountTransaction.query().onBuild((query) => {
query.orderBy('date', 'DESC');
if (filter.accountId) {
query.where('account_id', filter.accountId);
}
query.withGraphFetched('account');
query.withGraphFetched('contact');
});
return { transactions };
}
/**
* Transformes the account model to specific account response.
*/
private transformAccountResponse(tenantId: number, account: IAccount) {
const settings = this.tenancy.settings(tenantId);
const baseCurrency = settings.get({
group: 'organization',
key: 'base_currency',
});
return {
...account,
currencyCode: baseCurrency,
};
}
/**
* Transformes the accounts models to accounts response.
*/

View File

@@ -641,7 +641,7 @@ export default class ExpensesService implements IExpensesService {
const expense = await expenseRepository.findOneById(expenseId, [
'paymentAccount',
'categories',
'categories.expenseAccount',
]);
if (!expense) {
throw new ServiceError(ERRORS.EXPENSE_NOT_FOUND);

View File

@@ -822,7 +822,8 @@ export default class ManualJournalsService implements IManualJournalsService {
);
const manualJournal = await ManualJournal.query()
.findById(manualJournalId)
.withGraphFetched('entries')
.withGraphFetched('entries.account')
.withGraphFetched('entries.contact')
.withGraphFetched('transactions')
.withGraphFetched('media');