mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
feat: ability to remove the removed Plaid transactions in updating
This commit is contained in:
@@ -23,7 +23,7 @@ export class PlaidItemService {
|
||||
* @param {PlaidItemDTO} itemDTO
|
||||
* @returns {Promise<void>}
|
||||
*/
|
||||
public async item(tenantId: number, itemDTO: PlaidItemDTO) {
|
||||
public async item(tenantId: number, itemDTO: PlaidItemDTO): Promise<void> {
|
||||
const { PlaidItem } = this.tenancy.models(tenantId);
|
||||
const { publicToken, institutionId } = itemDTO;
|
||||
|
||||
|
||||
@@ -9,8 +9,11 @@ import {
|
||||
transformPlaidTrxsToCashflowCreate,
|
||||
} from './utils';
|
||||
import NewCashflowTransactionService from '@/services/Cashflow/NewCashflowTransactionService';
|
||||
import DeleteCashflowTransactionService from '@/services/Cashflow/DeleteCashflowTransactionService';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
|
||||
const CONCURRENCY_ASYNC = 10;
|
||||
|
||||
@Service()
|
||||
export class PlaidSyncDb {
|
||||
@Inject()
|
||||
@@ -22,6 +25,9 @@ export class PlaidSyncDb {
|
||||
@Inject()
|
||||
private createCashflowTransactionService: NewCashflowTransactionService;
|
||||
|
||||
@Inject()
|
||||
private deleteCashflowTransactionService: DeleteCashflowTransactionService;
|
||||
|
||||
/**
|
||||
* Syncs the plaid accounts to the system accounts.
|
||||
* @param {number} tenantId Tenant ID.
|
||||
@@ -39,7 +45,7 @@ export class PlaidSyncDb {
|
||||
accountCreateDTOs,
|
||||
(createAccountDTO: any) =>
|
||||
this.createAccountService.createAccount(tenantId, createAccountDTO),
|
||||
{ concurrency: 10 }
|
||||
{ concurrency: CONCURRENCY_ASYNC }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -79,7 +85,7 @@ export class PlaidSyncDb {
|
||||
tenantId,
|
||||
cashflowDTO
|
||||
),
|
||||
{ concurrency: 10 }
|
||||
{ concurrency: CONCURRENCY_ASYNC }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -104,7 +110,35 @@ export class PlaidSyncDb {
|
||||
plaidTransactions
|
||||
);
|
||||
},
|
||||
{ concurrency: 10 }
|
||||
{ concurrency: CONCURRENCY_ASYNC }
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Syncs the removed Plaid transactions ids from the cashflow system transactions.
|
||||
* @param {string[]} plaidTransactionsIds - Plaid Transactions IDs.
|
||||
*/
|
||||
public async syncRemoveTransactions(
|
||||
tenantId: number,
|
||||
plaidTransactionsIds: string[]
|
||||
) {
|
||||
const { CashflowTransaction } = this.tenancy.models(tenantId);
|
||||
|
||||
const cashflowTransactions = await CashflowTransaction.query().whereIn(
|
||||
'plaidTransactionId',
|
||||
plaidTransactionsIds
|
||||
);
|
||||
const cashflowTransactionsIds = cashflowTransactions.map(
|
||||
(trans) => trans.id
|
||||
);
|
||||
await bluebird.map(
|
||||
cashflowTransactionsIds,
|
||||
(transactionId: number) =>
|
||||
this.deleteCashflowTransactionService.deleteCashflowTransaction(
|
||||
tenantId,
|
||||
transactionId
|
||||
),
|
||||
{ concurrency: CONCURRENCY_ASYNC }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -121,6 +155,6 @@ export class PlaidSyncDb {
|
||||
) {
|
||||
const { PlaidItem } = this.tenancy.models(tenantId);
|
||||
|
||||
await PlaidItem.query().findById(plaidItemId).patch({ lastCursor });
|
||||
await PlaidItem.query().findOne({ plaidItemId }).patch({ lastCursor });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ export class PlaidUpdateTransactions {
|
||||
tenantId,
|
||||
added.concat(modified)
|
||||
);
|
||||
await this.plaidSync.syncRemoveTransactions(tenantId, removed);
|
||||
await this.plaidSync.syncTransactionsCursor(tenantId, plaidItemId, cursor);
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user