|
| 1 | +import * as d from 'date-fns'; |
| 2 | +import { |
| 3 | + sortByBookingDateOrValueDate, |
| 4 | + amountToInteger, |
| 5 | + printIban, |
| 6 | +} from '../utils.js'; |
| 7 | + |
| 8 | +/** @type {import('./bank.interface.js').IBank} */ |
| 9 | +export default { |
| 10 | + institutionIds: ['SEB_ESSESESS_PRIVATE'], |
| 11 | + normalizeAccount(account) { |
| 12 | + console.log( |
| 13 | + 'Available account properties for new institution integration', |
| 14 | + { account: JSON.stringify(account) }, |
| 15 | + ); |
| 16 | + |
| 17 | + return { |
| 18 | + account_id: account.id, |
| 19 | + institution: account.institution, |
| 20 | + mask: (account?.iban || '0000').slice(-4), |
| 21 | + iban: account?.iban || null, |
| 22 | + name: [account.name, printIban(account), account.currency] |
| 23 | + .filter(Boolean) |
| 24 | + .join(' '), |
| 25 | + official_name: `integration-${account.institution_id}`, |
| 26 | + type: 'checking', |
| 27 | + }; |
| 28 | + }, |
| 29 | + |
| 30 | + normalizeTransaction(transaction, _booked) { |
| 31 | + const date = |
| 32 | + transaction.bookingDate || |
| 33 | + transaction.bookingDateTime || |
| 34 | + transaction.valueDate || |
| 35 | + transaction.valueDateTime; |
| 36 | + // If we couldn't find a valid date field we filter out this transaction |
| 37 | + // and hope that we will import it again once the bank has processed the |
| 38 | + // transaction further. |
| 39 | + if (!date) { |
| 40 | + return null; |
| 41 | + } |
| 42 | + return { |
| 43 | + ...transaction, |
| 44 | + // Creditor name is stored in additionInformation for SEB |
| 45 | + creditorName: transaction.additionalInformation, |
| 46 | + date: d.format(d.parseISO(date), 'yyyy-MM-dd'), |
| 47 | + }; |
| 48 | + }, |
| 49 | + |
| 50 | + sortTransactions(transactions = []) { |
| 51 | + console.log( |
| 52 | + 'Available (first 10) transactions properties for new integration of institution in sortTransactions function', |
| 53 | + { top10Transactions: JSON.stringify(transactions.slice(0, 10)) }, |
| 54 | + ); |
| 55 | + return sortByBookingDateOrValueDate(transactions); |
| 56 | + }, |
| 57 | + |
| 58 | + calculateStartingBalance(sortedTransactions = [], balances = []) { |
| 59 | + const currentBalance = balances.find( |
| 60 | + (balance) => 'interimBooked' === balance.balanceType, |
| 61 | + ); |
| 62 | + |
| 63 | + return sortedTransactions.reduce((total, trans) => { |
| 64 | + return total - amountToInteger(trans.transactionAmount.amount); |
| 65 | + }, amountToInteger(currentBalance.balanceAmount.amount)); |
| 66 | + }, |
| 67 | +}; |
0 commit comments