Skip to content

Commit

Permalink
Merge pull request #568 from bigcapitalhq/fix-banking-api-query
Browse files Browse the repository at this point in the history
fix: Banking API account and page query.
  • Loading branch information
abouolia authored Aug 7, 2024
2 parents 37e25a8 + a986c7a commit 3fcc70c
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
);
Expand Down Expand Up @@ -177,7 +181,7 @@ export class ExcludeBankTransactionsController extends BaseController {
next: NextFunction
): Promise<Response | void> {
const { tenantId } = req;
const filter = this.matchedBodyData(req);
const filter = this.matchedQueryData(req);

try {
const data =
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ function RecognizedTransactionsTableBoot({
hasNextPage: hasUncategorizedTransactionsNextPage,
} = useRecognizedBankTransactionsInfinity({
page_size: 50,
account_id: accountId,
});
// Memorized the cashflow account transactions.
const recognizedTransactions = React.useMemo(
Expand Down
14 changes: 5 additions & 9 deletions packages/webapp/src/hooks/query/bank-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -312,10 +317,6 @@ export function useExcludeUncategorizedTransaction(
{
onSuccess: (res, id) => {
onValidateExcludeUncategorizedTransaction(queryClient);
queryClient.invalidateQueries([
BANK_QUERY_KEY.BANK_ACCOUNT_SUMMARY_META,
id,
]);
},
...options,
},
Expand Down Expand Up @@ -357,10 +358,6 @@ export function useUnexcludeUncategorizedTransaction(
{
onSuccess: (res, id) => {
onValidateExcludeUncategorizedTransaction(queryClient);
queryClient.invalidateQueries([
BANK_QUERY_KEY.BANK_ACCOUNT_SUMMARY_META,
id,
]);
},
...options,
},
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3fcc70c

Please sign in to comment.