mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50: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
|
* @param {PlaidItemDTO} itemDTO
|
||||||
* @returns {Promise<void>}
|
* @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 { PlaidItem } = this.tenancy.models(tenantId);
|
||||||
const { publicToken, institutionId } = itemDTO;
|
const { publicToken, institutionId } = itemDTO;
|
||||||
|
|
||||||
|
|||||||
@@ -9,8 +9,11 @@ import {
|
|||||||
transformPlaidTrxsToCashflowCreate,
|
transformPlaidTrxsToCashflowCreate,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import NewCashflowTransactionService from '@/services/Cashflow/NewCashflowTransactionService';
|
import NewCashflowTransactionService from '@/services/Cashflow/NewCashflowTransactionService';
|
||||||
|
import DeleteCashflowTransactionService from '@/services/Cashflow/DeleteCashflowTransactionService';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
|
|
||||||
|
const CONCURRENCY_ASYNC = 10;
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class PlaidSyncDb {
|
export class PlaidSyncDb {
|
||||||
@Inject()
|
@Inject()
|
||||||
@@ -22,6 +25,9 @@ export class PlaidSyncDb {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private createCashflowTransactionService: NewCashflowTransactionService;
|
private createCashflowTransactionService: NewCashflowTransactionService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private deleteCashflowTransactionService: DeleteCashflowTransactionService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Syncs the plaid accounts to the system accounts.
|
* Syncs the plaid accounts to the system accounts.
|
||||||
* @param {number} tenantId Tenant ID.
|
* @param {number} tenantId Tenant ID.
|
||||||
@@ -39,7 +45,7 @@ export class PlaidSyncDb {
|
|||||||
accountCreateDTOs,
|
accountCreateDTOs,
|
||||||
(createAccountDTO: any) =>
|
(createAccountDTO: any) =>
|
||||||
this.createAccountService.createAccount(tenantId, createAccountDTO),
|
this.createAccountService.createAccount(tenantId, createAccountDTO),
|
||||||
{ concurrency: 10 }
|
{ concurrency: CONCURRENCY_ASYNC }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +85,7 @@ export class PlaidSyncDb {
|
|||||||
tenantId,
|
tenantId,
|
||||||
cashflowDTO
|
cashflowDTO
|
||||||
),
|
),
|
||||||
{ concurrency: 10 }
|
{ concurrency: CONCURRENCY_ASYNC }
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -104,7 +110,35 @@ export class PlaidSyncDb {
|
|||||||
plaidTransactions
|
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);
|
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,
|
tenantId,
|
||||||
added.concat(modified)
|
added.concat(modified)
|
||||||
);
|
);
|
||||||
|
await this.plaidSync.syncRemoveTransactions(tenantId, removed);
|
||||||
await this.plaidSync.syncTransactionsCursor(tenantId, plaidItemId, cursor);
|
await this.plaidSync.syncTransactionsCursor(tenantId, plaidItemId, cursor);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user