mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 06:40:31 +00:00
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:
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user