A local-first personal finance app
Only pull single account data from SimpleFIN if syncing one account (#483)
Robert Dyerb5f8aa4d0549
diff --git a/src/app-simplefin/app-simplefin.js b/src/app-simplefin/app-simplefin.jsindex a1729b1ce8..7c123166f1 100644--- a/src/app-simplefin/app-simplefin.js+++ b/src/app-simplefin/app-simplefin.js@@ -48,7 +48,7 @@ app.post(}try {- const accounts = await getAccounts(accessKey, null, null, true);+ const accounts = await getAccounts(accessKey, null, null, null, true);res.send({status: 'ok',@@ -91,7 +91,11 @@ app.post(: startDate;let results;try {- results = await getTransactions(accessKey, new Date(earliestStartDate));+ results = await getTransactions(+ accessKey,+ Array.isArray(accountId) ? accountId : [accountId],+ new Date(earliestStartDate),+ );} catch (e) {if (e.message === 'Forbidden') {invalidToken(res);@@ -293,12 +297,12 @@ async function getAccessKey(base64Token) {});}-async function getTransactions(accessKey, startDate, endDate) {+async function getTransactions(accessKey, accounts, startDate, endDate) {const now = new Date();startDate = startDate || new Date(now.getFullYear(), now.getMonth(), 1);endDate = endDate || new Date(now.getFullYear(), now.getMonth() + 1, 1);console.log(`${getDate(startDate)} - ${getDate(endDate)}`);- return await getAccounts(accessKey, startDate, endDate);+ return await getAccounts(accessKey, accounts, startDate, endDate);}function getDate(date) {@@ -311,6 +315,7 @@ function normalizeDate(date) {async function getAccounts(accessKey,+ accounts,startDate,endDate,noTransactions = false,@@ -337,6 +342,12 @@ async function getAccounts(params.push(`balances-only=1`);}+ if (accounts) {+ accounts.forEach((id) => {+ params.push(`account=${encodeURIComponent(id)}`);+ });+ }+let queryString = '';if (params.length > 0) {queryString += '?' + params.join('&');diff --git a/upcoming-release-notes/483.md b/upcoming-release-notes/483.mdnew file mode 100644index 0000000000..d21ec94198--- /dev/null+++ b/upcoming-release-notes/483.md@@ -0,0 +1,6 @@+---+category: Enhancements+authors: [psybers]+---++SimpleFIN: when sync'ing a single account, only pull transactions for that account.