UNPKG

@accounter/server

Version:
35 lines 1.34 kB
import { GraphQLError } from 'graphql'; import { formatAmount } from '../../../../shared/helpers/index.js'; import { TransactionsProvider } from '../../../transactions/providers/transactions.provider.js'; export const missingConversionInfoSuggestions = async (DbCharge, _, { injector }) => { const transactions = await injector .get(TransactionsProvider) .transactionsByChargeIDLoader.load(DbCharge.id); let fromCurrency; let toCurrency; for (const transaction of transactions) { if (transaction.is_fee) continue; const amount = formatAmount(transaction.amount); if (amount > 0) { if (toCurrency) { throw new GraphQLError('Multiple destination currencies in Kraken conversion'); } toCurrency = transaction.currency; } if (amount < 0) { if (fromCurrency) { throw new GraphQLError('Multiple source currencies in Kraken conversion'); } fromCurrency = transaction.currency; } if (fromCurrency && toCurrency) { return { description: `${fromCurrency} to ${toCurrency} conversion`, tags: [], }; } } return null; }; //# sourceMappingURL=conversion-suggeestions.resolver.js.map