mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
feat(server): move updating plaid transactions to background job
This commit is contained in:
54
packages/server/src/services/Banking/Plaid/utils.ts
Normal file
54
packages/server/src/services/Banking/Plaid/utils.ts
Normal file
@@ -0,0 +1,54 @@
|
||||
import * as R from 'ramda';
|
||||
import { IAccountCreateDTO, ICashflowNewCommandDTO } from '@/interfaces';
|
||||
import { PlaidAccount, PlaidTransaction } from './_types';
|
||||
|
||||
/**
|
||||
* Transformes the Plaid account to create cashflow account DTO.
|
||||
* @param {PlaidAccount} plaidAccount
|
||||
* @returns {IAccountCreateDTO}
|
||||
*/
|
||||
export const transformPlaidAccountToCreateAccount = (
|
||||
plaidAccount: PlaidAccount
|
||||
): IAccountCreateDTO => {
|
||||
return {
|
||||
name: plaidAccount.name,
|
||||
code: '',
|
||||
description: plaidAccount.official_name,
|
||||
currencyCode: plaidAccount.balances.iso_currency_code,
|
||||
accountType: 'cash',
|
||||
active: true,
|
||||
plaidAccountId: plaidAccount.account_id,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* 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 {ICashflowNewCommandDTO}
|
||||
*/
|
||||
export const transformPlaidTrxsToCashflowCreate = R.curry(
|
||||
(
|
||||
cashflowAccountId: number,
|
||||
creditAccountId: number,
|
||||
plaidTranasction: PlaidTransaction
|
||||
): ICashflowNewCommandDTO => {
|
||||
return {
|
||||
date: plaidTranasction.date,
|
||||
|
||||
transactionType: 'OwnerContribution',
|
||||
description: plaidTranasction.name,
|
||||
|
||||
amount: plaidTranasction.amount,
|
||||
exchangeRate: 1,
|
||||
currencyCode: plaidTranasction.iso_currency_code,
|
||||
creditAccountId,
|
||||
cashflowAccountId,
|
||||
|
||||
// transactionNumber: string;
|
||||
// referenceNo: string;
|
||||
publish: true,
|
||||
};
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user