From a986c7a2500004578519311cba714889b2410832 Mon Sep 17 00:00:00 2001 From: Ahmed Bouhuolia Date: Wed, 7 Aug 2024 20:08:59 +0200 Subject: [PATCH] fix: Banking api account and page query. --- .../Banking/ExcludeBankTransactionsController.ts | 8 ++++++-- .../Banking/RecognizedTransactionsController.ts | 12 +++++++++++- .../RecognizedTransactionsTableBoot.tsx | 1 + packages/webapp/src/hooks/query/bank-rules.ts | 14 +++++--------- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/packages/server/src/api/controllers/Banking/ExcludeBankTransactionsController.ts b/packages/server/src/api/controllers/Banking/ExcludeBankTransactionsController.ts index 9d4ddec22..e425247d2 100644 --- a/packages/server/src/api/controllers/Banking/ExcludeBankTransactionsController.ts +++ b/packages/server/src/api/controllers/Banking/ExcludeBankTransactionsController.ts @@ -42,7 +42,11 @@ export class ExcludeBankTransactionsController extends BaseController { ); router.get( '/excluded', - [], + [ + query('account_id').optional().isNumeric().toInt(), + query('page').optional().isNumeric().toInt(), + query('page_size').optional().isNumeric().toInt(), + ], this.validationResult, this.getExcludedBankTransactions.bind(this) ); @@ -177,7 +181,7 @@ export class ExcludeBankTransactionsController extends BaseController { next: NextFunction ): Promise { const { tenantId } = req; - const filter = this.matchedBodyData(req); + const filter = this.matchedQueryData(req); try { const data = diff --git a/packages/server/src/api/controllers/Banking/RecognizedTransactionsController.ts b/packages/server/src/api/controllers/Banking/RecognizedTransactionsController.ts index b87662f14..b52c4ebe1 100644 --- a/packages/server/src/api/controllers/Banking/RecognizedTransactionsController.ts +++ b/packages/server/src/api/controllers/Banking/RecognizedTransactionsController.ts @@ -1,5 +1,6 @@ import { Inject, Service } from 'typedi'; import { NextFunction, Request, Response, Router } from 'express'; +import { query } from 'express-validator'; import BaseController from '@/api/controllers/BaseController'; import { CashflowApplication } from '@/services/Cashflow/CashflowApplication'; @@ -14,7 +15,16 @@ export class RecognizedTransactionsController extends BaseController { router() { const router = Router(); - router.get('/', this.getRecognizedTransactions.bind(this)); + router.get( + '/', + [ + query('page').optional().isNumeric().toInt(), + query('page_size').optional().isNumeric().toInt(), + query('account_id').optional().isNumeric().toInt(), + ], + this.validationResult, + this.getRecognizedTransactions.bind(this) + ); router.get( '/transactions/:uncategorizedTransactionId', this.getRecognizedTransaction.bind(this) diff --git a/packages/webapp/src/containers/CashFlow/AccountTransactions/RecognizedTransactions/RecognizedTransactionsTableBoot.tsx b/packages/webapp/src/containers/CashFlow/AccountTransactions/RecognizedTransactions/RecognizedTransactionsTableBoot.tsx index bd9a88507..5d99b4a45 100644 --- a/packages/webapp/src/containers/CashFlow/AccountTransactions/RecognizedTransactions/RecognizedTransactionsTableBoot.tsx +++ b/packages/webapp/src/containers/CashFlow/AccountTransactions/RecognizedTransactions/RecognizedTransactionsTableBoot.tsx @@ -43,6 +43,7 @@ function RecognizedTransactionsTableBoot({ hasNextPage: hasUncategorizedTransactionsNextPage, } = useRecognizedBankTransactionsInfinity({ page_size: 50, + account_id: accountId, }); // Memorized the cashflow account transactions. const recognizedTransactions = React.useMemo( diff --git a/packages/webapp/src/hooks/query/bank-rules.ts b/packages/webapp/src/hooks/query/bank-rules.ts index 512f6e423..71697ec7e 100644 --- a/packages/webapp/src/hooks/query/bank-rules.ts +++ b/packages/webapp/src/hooks/query/bank-rules.ts @@ -276,6 +276,11 @@ const onValidateExcludeUncategorizedTransaction = (queryClient) => { // invalidate bank account summary. queryClient.invalidateQueries(BANK_QUERY_KEY.BANK_ACCOUNT_SUMMARY_META); + + // Invalidate the recognized transactions. + queryClient.invalidateQueries([ + BANK_QUERY_KEY.RECOGNIZED_BANK_TRANSACTIONS_INFINITY, + ]); }; type ExcludeUncategorizedTransactionValue = number; @@ -312,10 +317,6 @@ export function useExcludeUncategorizedTransaction( { onSuccess: (res, id) => { onValidateExcludeUncategorizedTransaction(queryClient); - queryClient.invalidateQueries([ - BANK_QUERY_KEY.BANK_ACCOUNT_SUMMARY_META, - id, - ]); }, ...options, }, @@ -357,10 +358,6 @@ export function useUnexcludeUncategorizedTransaction( { onSuccess: (res, id) => { onValidateExcludeUncategorizedTransaction(queryClient); - queryClient.invalidateQueries([ - BANK_QUERY_KEY.BANK_ACCOUNT_SUMMARY_META, - id, - ]); }, ...options, }, @@ -649,7 +646,6 @@ export function useRecognizedBankTransactionsInfinity( getPreviousPageParam: (firstPage) => firstPage.pagination.page - 1, getNextPageParam: (lastPage) => { const { pagination } = lastPage; - return pagination.total > pagination.page_size * pagination.page ? lastPage.pagination.page + 1 : undefined;