Skip to content
This repository was archived by the owner on Feb 10, 2025. It is now read-only.

Commit b5f8aa4

Browse files
Only pull single account data from SimpleFIN if syncing one account (#483)
* only pull single account data from SimpleFIN if syncing one account * add release note * fix linter * remove debug print * Update src/app-simplefin/app-simplefin.js Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent e659ccf commit b5f8aa4

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

src/app-simplefin/app-simplefin.js

+15-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ app.post(
4848
}
4949

5050
try {
51-
const accounts = await getAccounts(accessKey, null, null, true);
51+
const accounts = await getAccounts(accessKey, null, null, null, true);
5252

5353
res.send({
5454
status: 'ok',
@@ -91,7 +91,11 @@ app.post(
9191
: startDate;
9292
let results;
9393
try {
94-
results = await getTransactions(accessKey, new Date(earliestStartDate));
94+
results = await getTransactions(
95+
accessKey,
96+
Array.isArray(accountId) ? accountId : [accountId],
97+
new Date(earliestStartDate),
98+
);
9599
} catch (e) {
96100
if (e.message === 'Forbidden') {
97101
invalidToken(res);
@@ -293,12 +297,12 @@ async function getAccessKey(base64Token) {
293297
});
294298
}
295299

296-
async function getTransactions(accessKey, startDate, endDate) {
300+
async function getTransactions(accessKey, accounts, startDate, endDate) {
297301
const now = new Date();
298302
startDate = startDate || new Date(now.getFullYear(), now.getMonth(), 1);
299303
endDate = endDate || new Date(now.getFullYear(), now.getMonth() + 1, 1);
300304
console.log(`${getDate(startDate)} - ${getDate(endDate)}`);
301-
return await getAccounts(accessKey, startDate, endDate);
305+
return await getAccounts(accessKey, accounts, startDate, endDate);
302306
}
303307

304308
function getDate(date) {
@@ -311,6 +315,7 @@ function normalizeDate(date) {
311315

312316
async function getAccounts(
313317
accessKey,
318+
accounts,
314319
startDate,
315320
endDate,
316321
noTransactions = false,
@@ -337,6 +342,12 @@ async function getAccounts(
337342
params.push(`balances-only=1`);
338343
}
339344

345+
if (accounts) {
346+
accounts.forEach((id) => {
347+
params.push(`account=${encodeURIComponent(id)}`);
348+
});
349+
}
350+
340351
let queryString = '';
341352
if (params.length > 0) {
342353
queryString += '?' + params.join('&');

upcoming-release-notes/483.md

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
category: Enhancements
3+
authors: [psybers]
4+
---
5+
6+
SimpleFIN: when sync'ing a single account, only pull transactions for that account.

0 commit comments

Comments
 (0)