@accounter/server
Version:
28 lines • 1.09 kB
JavaScript
import { FinancialAccountsProvider } from '../providers/financial-accounts.provider.js';
export const commonFinancialAccountFields = {
id: DbAccount => DbAccount.id,
type: DbAccount => DbAccount.type,
};
export const commonTransactionFields = {
account: async (DbTransaction, _, { injector }) => {
if (!DbTransaction.account_id) {
throw new Error(`Transaction ID="${DbTransaction.id}" is missing account_id`);
}
const account = await injector
.get(FinancialAccountsProvider)
.getFinancialAccountByAccountIDLoader.load(DbTransaction.account_id);
if (!account) {
throw new Error(`Account ID "${DbTransaction.account_id}" is missing`);
}
return account;
},
};
export const commonFinancialEntityFields = {
accounts: async (DbBusiness, _, { injector }) => {
const accounts = await injector
.get(FinancialAccountsProvider)
.getFinancialAccountsByOwnerIdLoader.load(DbBusiness.id);
return accounts;
},
};
//# sourceMappingURL=common.js.map