refactoring: media system.

This commit is contained in:
Ahmed Bouhuolia
2020-10-07 21:30:16 +02:00
parent 681fa0560e
commit 15dca0a7d2
14 changed files with 572 additions and 173 deletions

View File

@@ -48,7 +48,7 @@ export default class ExpensesService implements IExpensesService {
this.logger.info('[expenses] trying to get the given payment account.', { tenantId, paymentAccountId });
const { accountRepository } = this.tenancy.repositories(tenantId);
const paymentAccount = await accountRepository.getById(paymentAccountId)
const paymentAccount = await accountRepository.findById(paymentAccountId)
if (!paymentAccount) {
this.logger.info('[expenses] the given payment account not found.', { tenantId, paymentAccountId });
@@ -460,4 +460,24 @@ export default class ExpensesService implements IExpensesService {
dynamicFilter.getResponseMeta(),
};
}
/**
* Retrieve expense details.
* @param {number} tenantId
* @param {number} expenseId
* @return {Promise<IExpense>}
*/
public async getExpense(tenantId: number, expenseId: number): Promise<IExpense> {
const { Expense } = this.tenancy.models(tenantId);
const expense = await Expense.query().findById(expenseId)
.withGraphFetched('paymentAccount')
.withGraphFetched('media')
.withGraphFetched('categories');
if (!expense) {
throw new ServiceError(ERRORS.EXPENSE_NOT_FOUND);
}
return expense;
}
}