diff --git a/packages/server/src/services/Banking/BankAccounts/DisconnectBankAccount.tsx b/packages/server/src/services/Banking/BankAccounts/DisconnectBankAccount.tsx index 3169e47ac..f04b2f90a 100644 --- a/packages/server/src/services/Banking/BankAccounts/DisconnectBankAccount.tsx +++ b/packages/server/src/services/Banking/BankAccounts/DisconnectBankAccount.tsx @@ -7,6 +7,7 @@ import HasTenancyService from '@/services/Tenancy/TenancyService'; import UnitOfWork from '@/services/UnitOfWork'; import events from '@/subscribers/events'; import { ERRORS } from './types'; +import { ACCOUNT_TYPE } from '@/data/AccountTypes'; @Service() export class DisconnectBankAccount { @@ -31,7 +32,7 @@ export class DisconnectBankAccount { // Retrieve the bank account or throw not found error. const account = await Account.query() .findById(bankAccountId) - .whereIn('account_type', ['bank', 'cash']) + .whereIn('account_type', [ACCOUNT_TYPE.CASH, ACCOUNT_TYPE.BANK]) .throwIfNotFound(); const oldPlaidItem = await PlaidItem.query().findById(account.plaidItemId); diff --git a/packages/server/src/services/Banking/BankAccounts/RefreshBankAccount.tsx b/packages/server/src/services/Banking/BankAccounts/RefreshBankAccount.tsx index 814d00c75..282ce06fd 100644 --- a/packages/server/src/services/Banking/BankAccounts/RefreshBankAccount.tsx +++ b/packages/server/src/services/Banking/BankAccounts/RefreshBankAccount.tsx @@ -1,19 +1,19 @@ +import { Inject, Service } from 'typedi'; import { ServiceError } from '@/exceptions'; import { PlaidClientWrapper } from '@/lib/Plaid'; import HasTenancyService from '@/services/Tenancy/TenancyService'; -import UnitOfWork from '@/services/UnitOfWork'; -import { Inject } from 'typedi'; +import { ERRORS } from './types'; + +@Service() export class RefreshBankAccountService { @Inject() private tenancy: HasTenancyService; - @Inject() - private uow: UnitOfWork; - /** - * + * Asks Plaid to trigger syncing the given bank account. * @param {number} tenantId * @param {number} bankAccountId + * @returns {Promise} */ public async refreshBankAccount(tenantId: number, bankAccountId: number) { const { Account } = this.tenancy.models(tenantId); @@ -23,17 +23,14 @@ export class RefreshBankAccountService { .withGraphFetched('plaidItem') .throwIfNotFound(); + // Can't continue if the given account is not linked with Plaid item. if (!bankAccount.plaidItem) { - throw new ServiceError(''); + throw new ServiceError(ERRORS.BANK_ACCOUNT_NOT_CONNECTED); } const plaidInstance = new PlaidClientWrapper(); - const data = await plaidInstance.transactionsRefresh({ + await plaidInstance.transactionsRefresh({ access_token: bankAccount.plaidItem.plaidAccessToken, }); - await Account.query().findById(bankAccountId).patch({ - isFeedsActive: true, - lastFeedsUpdatedAt: new Date(), - }); } } diff --git a/packages/server/src/services/Banking/BankAccounts/events/DisconnectPlaidItemOnAccountDeleted.ts b/packages/server/src/services/Banking/BankAccounts/events/DisconnectPlaidItemOnAccountDeleted.ts index 958fa0bb3..16d19e222 100644 --- a/packages/server/src/services/Banking/BankAccounts/events/DisconnectPlaidItemOnAccountDeleted.ts +++ b/packages/server/src/services/Banking/BankAccounts/events/DisconnectPlaidItemOnAccountDeleted.ts @@ -1,8 +1,8 @@ +import { Inject, Service } from 'typedi'; import { IAccountEventDeletedPayload } from '@/interfaces'; import { PlaidClientWrapper } from '@/lib/Plaid'; import HasTenancyService from '@/services/Tenancy/TenancyService'; import events from '@/subscribers/events'; -import { Inject, Service } from 'typedi'; @Service() export class DisconnectPlaidItemOnAccountDeleted { diff --git a/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsActionsBar.tsx b/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsActionsBar.tsx index e9635524c..e6c3a6a3c 100644 --- a/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsActionsBar.tsx +++ b/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsActionsBar.tsx @@ -53,7 +53,7 @@ function AccountTransactionsActionsBar({ addSetting, }) { const history = useHistory(); - const { accountId } = useAccountTransactionsContext(); + const { accountId, currentAccount } = useAccountTransactionsContext(); // Refresh cashflow infinity transactions hook. const { refresh } = useRefreshCashflowTransactionsInfinity(); @@ -65,6 +65,8 @@ function AccountTransactionsActionsBar({ const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []); const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []); + const isFeedsActive = !!currentAccount.is_feeds_active; + // Handle table row size change. const handleTableRowSizeChange = (size) => { addSetting('cashflowTransactions', 'tableSize', size); @@ -94,8 +96,6 @@ function AccountTransactionsActionsBar({ history.push(`/bank-rules?accountId=${accountId}`); }; - const isConnected = true; - // Handles the bank account disconnect click. const handleDisconnectClick = () => { disconnectBankAccount({ bankAccountId: accountId }) @@ -177,14 +177,18 @@ function AccountTransactionsActionsBar({