From bb3a7e7993c67bb535560b23719b4d7fa35c54b6 Mon Sep 17 00:00:00 2001 From: whatuserever <83753332+whatuserever@users.noreply.github.com> Date: Wed, 12 Feb 2025 11:09:41 +0200 Subject: [PATCH] cleanly await each iteration of initCategories --- .../backend/export/outputVendors/ynab/ynab.ts | 34 ++++++++++--------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/main/src/backend/export/outputVendors/ynab/ynab.ts b/packages/main/src/backend/export/outputVendors/ynab/ynab.ts index 72dbd9ab..4b1ce2e5 100644 --- a/packages/main/src/backend/export/outputVendors/ynab/ynab.ts +++ b/packages/main/src/backend/export/outputVendors/ynab/ynab.ts @@ -202,22 +202,24 @@ function getYnabCategoryIdFromCategoryName(budgetId: string, categoryName?: stri export async function initCategories() { const budgetIds = Object.values(ynabConfig!.options.accountNumbersToYnabAccountIds).map((v) => v.ynabBudgetId); - budgetIds.forEach(async (budgetId) => { - const categories = await ynabAPI!.categories.getCategories(budgetId); - const categoriesMap = new Map(); - categories.data.category_groups.forEach((categoryGroup) => { - categoryGroup.categories - .map((category) => ({ - id: category.id, - name: category.name, - category_group_id: category.category_group_id, - })) - .forEach((category) => { - categoriesMap.set(category.name, category); - }); - }); - budgetCategoriesMap.set(budgetId, categoriesMap); - }); + await Promise.all( + budgetIds.map(async (budgetId) => { + const categories = await ynabAPI!.categories.getCategories(budgetId); + const categoriesMap = new Map(); + categories.data.category_groups.forEach((categoryGroup) => { + categoryGroup.categories + .map((category) => ({ + id: category.id, + name: category.name, + category_group_id: category.category_group_id, + })) + .forEach((category) => { + categoriesMap.set(category.name, category); + }); + }); + budgetCategoriesMap.set(budgetId, categoriesMap); + }), + ); } async function filterOnlyTransactionsThatDontExistInYnabAlready(