mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat: pause bank account feeds
This commit is contained in:
@@ -37,7 +37,7 @@ export class PauseBankAccountFeeds {
|
||||
}
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
await PlaidItem.query(trx).findById(oldAccount.plaidItem.id).patch({
|
||||
pausedAt: null,
|
||||
pausedAt: new Date(),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export class ResumeBankAccountFeeds {
|
||||
}
|
||||
return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => {
|
||||
await PlaidItem.query(trx).findById(oldAccount.plaidItem.id).patch({
|
||||
pausedAt: new Date(),
|
||||
pausedAt: null,
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { Inject, Service } from 'typedi';
|
||||
import { PlaidUpdateTransactions } from './PlaidUpdateTransactions';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
|
||||
@Service()
|
||||
export class PlaidWebooks {
|
||||
@Inject()
|
||||
private updateTransactionsService: PlaidUpdateTransactions;
|
||||
|
||||
@Inject()
|
||||
private tenancy: HasTenancyService;
|
||||
|
||||
/**
|
||||
* Listens to Plaid webhooks
|
||||
* @param {number} tenantId - Tenant Id.
|
||||
@@ -61,7 +65,7 @@ export class PlaidWebooks {
|
||||
plaidItemId: string
|
||||
): void {
|
||||
console.log(
|
||||
`WEBHOOK: TRANSACTIONS: ${webhookCode}: Plaid_item_id ${plaidItemId}: ${additionalInfo}`
|
||||
`PLAID WEBHOOK: TRANSACTIONS: ${webhookCode}: Plaid_item_id ${plaidItemId}: ${additionalInfo}`
|
||||
);
|
||||
}
|
||||
|
||||
@@ -78,8 +82,21 @@ export class PlaidWebooks {
|
||||
plaidItemId: string,
|
||||
webhookCode: string
|
||||
): Promise<void> {
|
||||
const { PlaidItem } = this.tenancy.models(tenantId);
|
||||
const plaidItem = await PlaidItem.query()
|
||||
.findById(plaidItemId)
|
||||
.throwIfNotFound();
|
||||
|
||||
switch (webhookCode) {
|
||||
case 'SYNC_UPDATES_AVAILABLE': {
|
||||
if (plaidItem.isPaused) {
|
||||
this.serverLogAndEmitSocket(
|
||||
'Plaid item syncing is paused.',
|
||||
webhookCode,
|
||||
plaidItemId
|
||||
);
|
||||
return;
|
||||
}
|
||||
// Fired when new transactions data becomes available.
|
||||
const { addedCount, modifiedCount, removedCount } =
|
||||
await this.updateTransactionsService.updateTransactions(
|
||||
|
||||
Reference in New Issue
Block a user