mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-15 12:20:31 +00:00
59 lines
1.9 KiB
TypeScript
59 lines
1.9 KiB
TypeScript
import * as R from 'ramda';
|
|
import {
|
|
CreateUncategorizedTransactionDTO,
|
|
IAccountCreateDTO,
|
|
PlaidAccount,
|
|
PlaidTransaction,
|
|
} from '@/interfaces';
|
|
|
|
/**
|
|
* Transformes the Plaid account to create cashflow account DTO.
|
|
* @param {PlaidAccount} plaidAccount
|
|
* @returns {IAccountCreateDTO}
|
|
*/
|
|
export const transformPlaidAccountToCreateAccount = R.curry(
|
|
(institution: any, plaidAccount: PlaidAccount): IAccountCreateDTO => {
|
|
return {
|
|
name: `${institution.name} - ${plaidAccount.name}`,
|
|
code: '',
|
|
description: plaidAccount.official_name,
|
|
currencyCode: plaidAccount.balances.iso_currency_code,
|
|
accountType: 'cash',
|
|
active: true,
|
|
plaidAccountId: plaidAccount.account_id,
|
|
bankBalance: plaidAccount.balances.current,
|
|
accountMask: plaidAccount.mask,
|
|
};
|
|
}
|
|
);
|
|
|
|
/**
|
|
* Transformes the plaid transaction to cashflow create DTO.
|
|
* @param {number} cashflowAccountId - Cashflow account ID.
|
|
* @param {number} creditAccountId - Credit account ID.
|
|
* @param {PlaidTransaction} plaidTranasction - Plaid transaction.
|
|
* @returns {CreateUncategorizedTransactionDTO}
|
|
*/
|
|
export const transformPlaidTrxsToCashflowCreate = R.curry(
|
|
(
|
|
cashflowAccountId: number,
|
|
plaidTranasction: PlaidTransaction
|
|
): CreateUncategorizedTransactionDTO => {
|
|
return {
|
|
date: plaidTranasction.date,
|
|
|
|
// Plaid: Positive values when money moves out of the account; negative values
|
|
// when money moves in. For example, debit card purchases are positive;
|
|
// credit card payments, direct deposits, and refunds are negative.
|
|
amount: -1 * plaidTranasction.amount,
|
|
|
|
description: plaidTranasction.name,
|
|
payee: plaidTranasction.payment_meta?.payee,
|
|
currencyCode: plaidTranasction.iso_currency_code,
|
|
accountId: cashflowAccountId,
|
|
referenceNo: plaidTranasction.payment_meta?.reference_number,
|
|
plaidTransactionId: plaidTranasction.transaction_id,
|
|
};
|
|
}
|
|
);
|