diff --git a/packages/server/src/services/Banking/BankAccounts/PauseBankAccountFeeds.tsx b/packages/server/src/services/Banking/BankAccounts/PauseBankAccountFeeds.tsx index 3108bebf5..4a4f24a6c 100644 --- a/packages/server/src/services/Banking/BankAccounts/PauseBankAccountFeeds.tsx +++ b/packages/server/src/services/Banking/BankAccounts/PauseBankAccountFeeds.tsx @@ -2,6 +2,8 @@ import { Inject, Service } from 'typedi'; import { Knex } from 'knex'; import HasTenancyService from '@/services/Tenancy/TenancyService'; import UnitOfWork from '@/services/UnitOfWork'; +import { ServiceError } from '@/exceptions'; +import { ERRORS } from './types'; @Service() export class PauseBankAccountFeeds { @@ -22,10 +24,19 @@ export class PauseBankAccountFeeds { const oldAccount = await Account.query() .findById(bankAccountId) - .withGraphFetched('plaidItem'); + .withGraphFetched('plaidItem') + .throwIfNotFound(); + // Can't continue if the bank account is not connected. + if (!oldAccount.plaidItem) { + throw new ServiceError(ERRORS.BANK_ACCOUNT_NOT_CONNECTED); + } + // Cannot continue if the bank account feeds is already paused. + if (oldAccount.plaidItem.isPaused) { + throw new ServiceError(ERRORS.BANK_ACCOUNT_FEEDS_ALREADY_PAUSED); + } return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => { - await PlaidItem.query().findById(oldAccount.plaidItem.id).patch({ + await PlaidItem.query(trx).findById(oldAccount.plaidItem.id).patch({ pausedAt: null, }); }); diff --git a/packages/server/src/services/Banking/BankAccounts/ResumeBankAccountFeeds.tsx b/packages/server/src/services/Banking/BankAccounts/ResumeBankAccountFeeds.tsx index 680568470..0808782c6 100644 --- a/packages/server/src/services/Banking/BankAccounts/ResumeBankAccountFeeds.tsx +++ b/packages/server/src/services/Banking/BankAccounts/ResumeBankAccountFeeds.tsx @@ -1,6 +1,9 @@ +import { Inject, Service } from 'typedi'; +import { Knex } from 'knex'; import HasTenancyService from '@/services/Tenancy/TenancyService'; import UnitOfWork from '@/services/UnitOfWork'; -import { Inject, Service } from 'typedi'; +import { ServiceError } from '@/exceptions'; +import { ERRORS } from './types'; @Service() export class ResumeBankAccountFeeds { @@ -23,8 +26,16 @@ export class ResumeBankAccountFeeds { .findById(bankAccountId) .withGraphFetched('plaidItem'); + // Can't continue if the bank account is not connected. + if (!oldAccount.plaidItem) { + throw new ServiceError(ERRORS.BANK_ACCOUNT_NOT_CONNECTED); + } + // Cannot continue if the bank account feeds is already paused. + if (!oldAccount.plaidItem.isPaused) { + throw new ServiceError(ERRORS.BANK_ACCOUNT_FEEDS_ALREADY_RESUMED); + } return this.uow.withTransaction(tenantId, async (trx: Knex.Transaction) => { - await PlaidItem.query().findById(oldAccount.plaidItem.id).patch({ + await PlaidItem.query(trx).findById(oldAccount.plaidItem.id).patch({ pausedAt: new Date(), }); }); diff --git a/packages/server/src/services/Banking/BankAccounts/types.ts b/packages/server/src/services/Banking/BankAccounts/types.ts index d3198cc5c..cd21e490c 100644 --- a/packages/server/src/services/Banking/BankAccounts/types.ts +++ b/packages/server/src/services/Banking/BankAccounts/types.ts @@ -14,4 +14,6 @@ export interface IBankAccountDisconnectedEventPayload { export const ERRORS = { BANK_ACCOUNT_NOT_CONNECTED: 'BANK_ACCOUNT_NOT_CONNECTED', + BANK_ACCOUNT_FEEDS_ALREADY_PAUSED: 'BANK_ACCOUNT_FEEDS_ALREADY_PAUSED', + BANK_ACCOUNT_FEEDS_ALREADY_RESUMED: 'BANK_ACCOUNT_FEEDS_ALREADY_RESUMED', }; diff --git a/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsActionsBar.tsx b/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsActionsBar.tsx index f01427c43..bbbc8a187 100644 --- a/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsActionsBar.tsx +++ b/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsActionsBar.tsx @@ -197,12 +197,15 @@ function AccountTransactionsActionsBar({ // Handle resume bank feeds syncing. const handleResumeFeedsSyncing = () => { - openAlert('resume-feeds-syncing-bank-accounnt'); + openAlert('resume-feeds-syncing-bank-accounnt', { + bankAccountId: accountId, + }); }; - // Handles pause bank feeds syncing. const handlePauseFeedsSyncing = () => { - openAlert('pause-feeds-syncing-bank-accounnt'); + openAlert('pause-feeds-syncing-bank-accounnt', { + bankAccountId: accountId, + }); }; return ( @@ -298,14 +301,21 @@ function AccountTransactionsActionsBar({ }} content={ - - + + + + + + + + + diff --git a/packages/webapp/src/containers/CashFlow/AccountTransactions/alerts/PauseFeedsBankAccount.tsx b/packages/webapp/src/containers/CashFlow/AccountTransactions/alerts/PauseFeedsBankAccount.tsx index 5c4dbaf60..6bf930712 100644 --- a/packages/webapp/src/containers/CashFlow/AccountTransactions/alerts/PauseFeedsBankAccount.tsx +++ b/packages/webapp/src/containers/CashFlow/AccountTransactions/alerts/PauseFeedsBankAccount.tsx @@ -1,6 +1,5 @@ // @ts-nocheck import React from 'react'; -import intl from 'react-intl-universal'; import { Intent, Alert } from '@blueprintjs/core'; import { AppToaster, FormattedMessage as T } from '@/components'; @@ -30,10 +29,9 @@ function PauseFeedsBankAccountAlert({ const handleCancelActivateItem = () => { closeAlert(name); }; - // Handle confirm item activated. const handleConfirmItemActivate = () => { - pauseBankAccountFeeds(bankAccountId) + pauseBankAccountFeeds({ bankAccountId }) .then(() => { AppToaster.show({ message: 'The bank feeds of the bank account has been paused.', @@ -49,14 +47,17 @@ function PauseFeedsBankAccountAlert({ return ( } - confirmButtonText={} + confirmButtonText={'Pause bank feeds'} intent={Intent.WARNING} isOpen={isOpen} onCancel={handleCancelActivateItem} loading={isLoading} onConfirm={handleConfirmItemActivate} > -

Are you sure.

+

+ Are you sure want to pause bank feeds syncing of this bank account, you + can always resume it again? +

); } diff --git a/packages/webapp/src/containers/CashFlow/AccountTransactions/alerts/ResumeFeedsBankAccount.tsx b/packages/webapp/src/containers/CashFlow/AccountTransactions/alerts/ResumeFeedsBankAccount.tsx index 23a867349..32a10bace 100644 --- a/packages/webapp/src/containers/CashFlow/AccountTransactions/alerts/ResumeFeedsBankAccount.tsx +++ b/packages/webapp/src/containers/CashFlow/AccountTransactions/alerts/ResumeFeedsBankAccount.tsx @@ -33,7 +33,7 @@ function ResumeFeedsBankAccountAlert({ // Handle confirm item activated. const handleConfirmItemActivate = () => { - resumeFeedsBankAccount(bankAccountId) + resumeFeedsBankAccount({ bankAccountId }) .then(() => { AppToaster.show({ message: 'The bank feeds of the bank account has been resumed.', @@ -49,14 +49,17 @@ function ResumeFeedsBankAccountAlert({ return ( } - confirmButtonText={} - intent={Intent.WARNING} + confirmButtonText={'Resume bank feeds'} + intent={Intent.SUCCESS} isOpen={isOpen} onCancel={handleCancelActivateItem} loading={isLoading} onConfirm={handleConfirmItemActivate} > -

Are you sure.

+

+ Are you sure want to resume bank feeds syncing of this bank account, you + can always pause it again? +

); }