From 5e12a4cea4a927e672aa7b5076e2d67adfeba36c Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Sun, 4 Aug 2024 00:36:19 +0200 Subject: [PATCH] feat: pause/resume bank account feeds syncing --- .../Banking/BankAccountsController.ts | 47 ++++++++++++++++++- .../BankAccounts/BankAccountsApplication.tsx | 35 +++++++++++++- .../BankAccounts/PauseBankAccountFeeds.tsx | 9 ++++ .../BankAccounts/ResumeBankAccountFeeds.tsx | 11 +++++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 packages/server/src/services/Banking/BankAccounts/PauseBankAccountFeeds.tsx create mode 100644 packages/server/src/services/Banking/BankAccounts/ResumeBankAccountFeeds.tsx diff --git a/packages/server/src/api/controllers/Banking/BankAccountsController.ts b/packages/server/src/api/controllers/Banking/BankAccountsController.ts index f337c0b38..2a2661216 100644 --- a/packages/server/src/api/controllers/Banking/BankAccountsController.ts +++ b/packages/server/src/api/controllers/Banking/BankAccountsController.ts @@ -1,7 +1,6 @@ import { Inject, Service } from 'typedi'; import { NextFunction, Request, Response, Router } from 'express'; import BaseController from '@/api/controllers/BaseController'; -import { CashflowApplication } from '@/services/Cashflow/CashflowApplication'; import { GetBankAccountSummary } from '@/services/Banking/BankAccounts/GetBankAccountSummary'; import { BankAccountsApplication } from '@/services/Banking/BankAccounts/BankAccountsApplication'; @@ -25,6 +24,14 @@ export class BankAccountsController extends BaseController { this.disconnectBankAccount.bind(this) ); router.post('/:bankAccountId/update', this.refreshBankAccount.bind(this)); + router.post( + '/:bankAccountId/pause_feeds', + this.pauseBankAccountFeeds.bind(this) + ); + router.post( + '/:bankAccountId/resume_feeds', + this.resumeBankAccountFeeds.bind(this) + ); return router; } @@ -109,4 +116,42 @@ export class BankAccountsController extends BaseController { next(error); } } + + async resumeBankAccountFeeds( + req: Request<{ bankAccountId: number }>, + res: Response, + next: NextFunction + ) { + const { bankAccountId } = req.params; + const { tenantId } = req; + + try { + await this.bankAccountsApp.resumeBankAccount(tenantId, bankAccountId); + + return res.status(200).send({ + message: '', + }); + } catch (error) { + next(error); + } + } + + async pauseBankAccountFeeds( + req: Request<{ bankAccountId: number }>, + res: Response, + next: NextFunction + ) { + const { bankAccountId } = req.params; + const { tenantId } = req; + + try { + await this.bankAccountsApp.pauseBankAccount(tenantId, bankAccountId); + + return res.status(200).send({ + message: '', + }); + } catch (error) { + next(error); + } + } } diff --git a/packages/server/src/services/Banking/BankAccounts/BankAccountsApplication.tsx b/packages/server/src/services/Banking/BankAccounts/BankAccountsApplication.tsx index 51c12106e..faef21ac5 100644 --- a/packages/server/src/services/Banking/BankAccounts/BankAccountsApplication.tsx +++ b/packages/server/src/services/Banking/BankAccounts/BankAccountsApplication.tsx @@ -1,6 +1,7 @@ import { Inject, Service } from 'typedi'; import { DisconnectBankAccount } from './DisconnectBankAccount'; import { RefreshBankAccountService } from './RefreshBankAccount'; +import { ResumeBankAccountFeeds } from './PauseBankAccountFeeds'; @Service() export class BankAccountsApplication { @@ -10,6 +11,12 @@ export class BankAccountsApplication { @Inject() private refreshBankAccountService: RefreshBankAccountService; + @Inject() + private resumeBankAccountFeedsService: ResumeBankAccountFeeds; + + @Inject() + private pauseBankAccountFeedsService: ResumeBankAccountFeeds; + /** * Disconnects the given bank account. * @param {number} tenantId @@ -27,7 +34,7 @@ export class BankAccountsApplication { * Refresh the bank transactions of the given bank account. * @param {number} tenantId * @param {number} bankAccountId - * @returns {Promise} + * @returns {Promise} */ async refreshBankAccount(tenantId: number, bankAccountId: number) { return this.refreshBankAccountService.refreshBankAccount( @@ -35,4 +42,30 @@ export class BankAccountsApplication { bankAccountId ); } + + /** + * Pauses the feeds sync of the given bank account. + * @param {number} tenantId + * @param {number} bankAccountId + * @returns {Promise} + */ + async pauseBankAccount(tenantId: number, bankAccountId: number) { + return this.pauseBankAccountFeedsService.resumeBankAccountFeeds( + tenantId, + bankAccountId + ); + } + + /** + * Resumes the feeds sync of the given bank account. + * @param {number} tenantId + * @param {number} bankAccountId + * @returns {Promise} + */ + async resumeBankAccount(tenantId: number, bankAccountId: number) { + return this.resumeBankAccountFeedsService.resumeBankAccountFeeds( + tenantId, + bankAccountId + ); + } } diff --git a/packages/server/src/services/Banking/BankAccounts/PauseBankAccountFeeds.tsx b/packages/server/src/services/Banking/BankAccounts/PauseBankAccountFeeds.tsx new file mode 100644 index 000000000..34cf2664b --- /dev/null +++ b/packages/server/src/services/Banking/BankAccounts/PauseBankAccountFeeds.tsx @@ -0,0 +1,9 @@ +import { Service } from 'typedi'; + +@Service() +export class ResumeBankAccountFeeds { + public resumeBankAccountFeeds(tenantId: number, bankAccountId: number) { + + + } +} diff --git a/packages/server/src/services/Banking/BankAccounts/ResumeBankAccountFeeds.tsx b/packages/server/src/services/Banking/BankAccounts/ResumeBankAccountFeeds.tsx new file mode 100644 index 000000000..7851e0e16 --- /dev/null +++ b/packages/server/src/services/Banking/BankAccounts/ResumeBankAccountFeeds.tsx @@ -0,0 +1,11 @@ +import { Service } from "typedi"; + +@Service() +export class ResumeBankAccountFeeds { + /** + * + * @param {number} tenantId + * @param {number} bankAccountId + */ + public resumeBankAccountFeeds(tenantId: number, bankAccountId: number) {} +}