mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 15:20:34 +00:00
feat: tweaks in disconnecting bank account
This commit is contained in:
@@ -7,6 +7,7 @@ import HasTenancyService from '@/services/Tenancy/TenancyService';
|
|||||||
import UnitOfWork from '@/services/UnitOfWork';
|
import UnitOfWork from '@/services/UnitOfWork';
|
||||||
import events from '@/subscribers/events';
|
import events from '@/subscribers/events';
|
||||||
import { ERRORS } from './types';
|
import { ERRORS } from './types';
|
||||||
|
import { ACCOUNT_TYPE } from '@/data/AccountTypes';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class DisconnectBankAccount {
|
export class DisconnectBankAccount {
|
||||||
@@ -31,7 +32,7 @@ export class DisconnectBankAccount {
|
|||||||
// Retrieve the bank account or throw not found error.
|
// Retrieve the bank account or throw not found error.
|
||||||
const account = await Account.query()
|
const account = await Account.query()
|
||||||
.findById(bankAccountId)
|
.findById(bankAccountId)
|
||||||
.whereIn('account_type', ['bank', 'cash'])
|
.whereIn('account_type', [ACCOUNT_TYPE.CASH, ACCOUNT_TYPE.BANK])
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
const oldPlaidItem = await PlaidItem.query().findById(account.plaidItemId);
|
const oldPlaidItem = await PlaidItem.query().findById(account.plaidItemId);
|
||||||
|
|||||||
@@ -1,19 +1,19 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
import { PlaidClientWrapper } from '@/lib/Plaid';
|
import { PlaidClientWrapper } from '@/lib/Plaid';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import UnitOfWork from '@/services/UnitOfWork';
|
import { ERRORS } from './types';
|
||||||
import { Inject } from 'typedi';
|
|
||||||
|
@Service()
|
||||||
export class RefreshBankAccountService {
|
export class RefreshBankAccountService {
|
||||||
@Inject()
|
@Inject()
|
||||||
private tenancy: HasTenancyService;
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
@Inject()
|
|
||||||
private uow: UnitOfWork;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Asks Plaid to trigger syncing the given bank account.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {number} bankAccountId
|
* @param {number} bankAccountId
|
||||||
|
* @returns {Promise<void>}
|
||||||
*/
|
*/
|
||||||
public async refreshBankAccount(tenantId: number, bankAccountId: number) {
|
public async refreshBankAccount(tenantId: number, bankAccountId: number) {
|
||||||
const { Account } = this.tenancy.models(tenantId);
|
const { Account } = this.tenancy.models(tenantId);
|
||||||
@@ -23,17 +23,14 @@ export class RefreshBankAccountService {
|
|||||||
.withGraphFetched('plaidItem')
|
.withGraphFetched('plaidItem')
|
||||||
.throwIfNotFound();
|
.throwIfNotFound();
|
||||||
|
|
||||||
|
// Can't continue if the given account is not linked with Plaid item.
|
||||||
if (!bankAccount.plaidItem) {
|
if (!bankAccount.plaidItem) {
|
||||||
throw new ServiceError('');
|
throw new ServiceError(ERRORS.BANK_ACCOUNT_NOT_CONNECTED);
|
||||||
}
|
}
|
||||||
const plaidInstance = new PlaidClientWrapper();
|
const plaidInstance = new PlaidClientWrapper();
|
||||||
|
|
||||||
const data = await plaidInstance.transactionsRefresh({
|
await plaidInstance.transactionsRefresh({
|
||||||
access_token: bankAccount.plaidItem.plaidAccessToken,
|
access_token: bankAccount.plaidItem.plaidAccessToken,
|
||||||
});
|
});
|
||||||
await Account.query().findById(bankAccountId).patch({
|
|
||||||
isFeedsActive: true,
|
|
||||||
lastFeedsUpdatedAt: new Date(),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
import { IAccountEventDeletedPayload } from '@/interfaces';
|
import { IAccountEventDeletedPayload } from '@/interfaces';
|
||||||
import { PlaidClientWrapper } from '@/lib/Plaid';
|
import { PlaidClientWrapper } from '@/lib/Plaid';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import events from '@/subscribers/events';
|
import events from '@/subscribers/events';
|
||||||
import { Inject, Service } from 'typedi';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class DisconnectPlaidItemOnAccountDeleted {
|
export class DisconnectPlaidItemOnAccountDeleted {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ function AccountTransactionsActionsBar({
|
|||||||
addSetting,
|
addSetting,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { accountId } = useAccountTransactionsContext();
|
const { accountId, currentAccount } = useAccountTransactionsContext();
|
||||||
|
|
||||||
// Refresh cashflow infinity transactions hook.
|
// Refresh cashflow infinity transactions hook.
|
||||||
const { refresh } = useRefreshCashflowTransactionsInfinity();
|
const { refresh } = useRefreshCashflowTransactionsInfinity();
|
||||||
@@ -65,6 +65,8 @@ function AccountTransactionsActionsBar({
|
|||||||
const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []);
|
const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []);
|
||||||
const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []);
|
const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []);
|
||||||
|
|
||||||
|
const isFeedsActive = !!currentAccount.is_feeds_active;
|
||||||
|
|
||||||
// Handle table row size change.
|
// Handle table row size change.
|
||||||
const handleTableRowSizeChange = (size) => {
|
const handleTableRowSizeChange = (size) => {
|
||||||
addSetting('cashflowTransactions', 'tableSize', size);
|
addSetting('cashflowTransactions', 'tableSize', size);
|
||||||
@@ -94,8 +96,6 @@ function AccountTransactionsActionsBar({
|
|||||||
history.push(`/bank-rules?accountId=${accountId}`);
|
history.push(`/bank-rules?accountId=${accountId}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const isConnected = true;
|
|
||||||
|
|
||||||
// Handles the bank account disconnect click.
|
// Handles the bank account disconnect click.
|
||||||
const handleDisconnectClick = () => {
|
const handleDisconnectClick = () => {
|
||||||
disconnectBankAccount({ bankAccountId: accountId })
|
disconnectBankAccount({ bankAccountId: accountId })
|
||||||
@@ -177,14 +177,18 @@ function AccountTransactionsActionsBar({
|
|||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
|
|
||||||
<Tooltip
|
<Tooltip
|
||||||
content={'The bank syncing is active'}
|
content={
|
||||||
|
isFeedsActive
|
||||||
|
? 'The bank syncing is active'
|
||||||
|
: 'The bank syncing is disconnected'
|
||||||
|
}
|
||||||
minimal={true}
|
minimal={true}
|
||||||
position={Position.BOTTOM}
|
position={Position.BOTTOM}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
icon={<Icon icon="feed" iconSize={16} color="#238C2C" />}
|
icon={<Icon icon="feed" iconSize={16} />}
|
||||||
intent={Intent.SUCCESS}
|
intent={isFeedsActive ? Intent.SUCCESS : Intent.DANGER}
|
||||||
/>
|
/>
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</NavbarGroup>
|
</NavbarGroup>
|
||||||
@@ -199,13 +203,15 @@ function AccountTransactionsActionsBar({
|
|||||||
}}
|
}}
|
||||||
content={
|
content={
|
||||||
<Menu>
|
<Menu>
|
||||||
{isConnected && (
|
{isFeedsActive && (
|
||||||
|
<>
|
||||||
<MenuItem onClick={handleBankUpdateClick} text={'Update'} />
|
<MenuItem onClick={handleBankUpdateClick} text={'Update'} />
|
||||||
)}
|
|
||||||
<MenuDivider />
|
<MenuDivider />
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<MenuItem onClick={handleBankRulesClick} text={'Bank rules'} />
|
<MenuItem onClick={handleBankRulesClick} text={'Bank rules'} />
|
||||||
|
|
||||||
{isConnected && (
|
{isFeedsActive && (
|
||||||
<MenuItem onClick={handleDisconnectClick} text={'Disconnect'} />
|
<MenuItem onClick={handleDisconnectClick} text={'Disconnect'} />
|
||||||
)}
|
)}
|
||||||
</Menu>
|
</Menu>
|
||||||
|
|||||||
Reference in New Issue
Block a user