diff options
| author | Joe Carstairs <me@joeac.net> | 2024-09-17 13:20:04 +0100 |
|---|---|---|
| committer | Joe Carstairs <me@joeac.net> | 2024-09-17 13:20:04 +0100 |
| commit | cd269b3540fb5e3a988c1b59d3763db360b1fb34 (patch) | |
| tree | a728403d8d5708ad29eeed2b391706b09a93fe4c /gui/src/types/budgetMap.ts | |
| parent | f0e3e0cfb183253e03b1a61ddecb7b9330d47fdb (diff) | |
many, many changes
Diffstat (limited to 'gui/src/types/budgetMap.ts')
| -rw-r--r-- | gui/src/types/budgetMap.ts | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/gui/src/types/budgetMap.ts b/gui/src/types/budgetMap.ts new file mode 100644 index 0000000..5fa09f2 --- /dev/null +++ b/gui/src/types/budgetMap.ts @@ -0,0 +1,16 @@ +import { Budget, newBudgetFromDto } from "./budget"; +import { Category } from "./category"; + +type BudgetMap<T extends { id: any }> = { + [id in T["id"]]: Budget | null; +}; + +function newCategoryBudgetMapFromDto(dto: unknown): BudgetMap<Category> { + return Object.fromEntries( + (dto as { category_id: number; budget: unknown }[]).map( + ({ category_id, budget }) => [category_id, newBudgetFromDto(budget)], + ), + ); +} + +export { type BudgetMap, newCategoryBudgetMapFromDto as newBudgetMapFromDto }; |
