Skip to content

Commit

Permalink
cleanly await each iteration of initCategories
Browse files Browse the repository at this point in the history
  • Loading branch information
whatuserever committed Feb 12, 2025
1 parent c05bdb6 commit bb3a7e7
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions packages/main/src/backend/export/outputVendors/ynab/ynab.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, YnabCategory>();
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<string, YnabCategory>();
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(
Expand Down

0 comments on commit bb3a7e7

Please sign in to comment.