feat(server): sync Plaid transactions to uncategorized transactions

This commit is contained in:
Ahmed Bouhuolia
2024-03-04 13:42:17 +02:00
parent 9db03350e0
commit f23e8d98f6
10 changed files with 113 additions and 24 deletions

View File

@@ -11,6 +11,7 @@ import {
import NewCashflowTransactionService from '@/services/Cashflow/NewCashflowTransactionService';
import { DeleteCashflowTransaction } from '@/services/Cashflow/DeleteCashflowTransactionService';
import HasTenancyService from '@/services/Tenancy/TenancyService';
import { CashflowApplication } from '@/services/Cashflow/CashflowApplication';
const CONCURRENCY_ASYNC = 10;
@@ -22,6 +23,9 @@ export class PlaidSyncDb {
@Inject()
private createAccountService: CreateAccount;
@Inject()
private cashflowApp: CashflowApplication;
@Inject()
private createCashflowTransactionService: NewCashflowTransactionService;
@@ -75,15 +79,16 @@ export class PlaidSyncDb {
cashflowAccount.id,
openingEquityBalance.id
);
const accountsCashflowDTO = R.map(transformTransaction)(plaidTranasctions);
const uncategorizedTransDTOs =
R.map(transformTransaction)(plaidTranasctions);
// Creating account transaction queue.
await bluebird.map(
accountsCashflowDTO,
(cashflowDTO) =>
this.createCashflowTransactionService.newCashflowTransaction(
uncategorizedTransDTOs,
(uncategoriedDTO) =>
this.cashflowApp.createUncategorizedTransaction(
tenantId,
cashflowDTO
uncategoriedDTO
),
{ concurrency: CONCURRENCY_ASYNC }
);

View File

@@ -1,7 +1,9 @@
import * as R from 'ramda';
import {
CreateUncategorizedTransactionDTO,
IAccountCreateDTO,
ICashflowNewCommandDTO,
IUncategorizedCashflowTransaction,
PlaidAccount,
PlaidTransaction,
} from '@/interfaces';
@@ -32,30 +34,22 @@ export const transformPlaidAccountToCreateAccount = (
* @param {number} cashflowAccountId - Cashflow account ID.
* @param {number} creditAccountId - Credit account ID.
* @param {PlaidTransaction} plaidTranasction - Plaid transaction.
* @returns {ICashflowNewCommandDTO}
* @returns {CreateUncategorizedTransactionDTO}
*/
export const transformPlaidTrxsToCashflowCreate = R.curry(
(
cashflowAccountId: number,
creditAccountId: number,
plaidTranasction: PlaidTransaction
): ICashflowNewCommandDTO => {
): CreateUncategorizedTransactionDTO => {
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;
accountId: cashflowAccountId,
referenceNo: plaidTranasction.payment_meta?.reference_number,
plaidTransactionId: plaidTranasction.transaction_id,
publish: true,
};
}
);