From 5cb2f19360170f8cdbfcda65f9d6835061b76819 Mon Sep 17 00:00:00 2001 From: Jon Toye Date: Sat, 18 May 2024 07:33:36 -0400 Subject: [PATCH] add cursor value to transactionsSync to prevent exceeding endpoint rate limit --- lib/actions/bank.actions.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/actions/bank.actions.ts b/lib/actions/bank.actions.ts index 84d0e4e..d86891a 100644 --- a/lib/actions/bank.actions.ts +++ b/lib/actions/bank.actions.ts @@ -150,6 +150,7 @@ export const getInstitution = async ({ export const getTransactions = async ({ accessToken, }: getTransactionsProps) => { + let cursor = undefined; let hasMore = true; let transactions: any = []; @@ -158,6 +159,7 @@ export const getTransactions = async ({ while (hasMore) { const response = await plaidClient.transactionsSync({ access_token: accessToken, + cursor }); const data = response.data; @@ -176,10 +178,11 @@ export const getTransactions = async ({ })); hasMore = data.has_more; + cursor = data.next_cursor; } return parseStringify(transactions); } catch (error) { - console.error("An error occurred while getting the accounts:", error); + console.error("An error occurred while getting the transactions:", error); } }; \ No newline at end of file