From cd269b3540fb5e3a988c1b59d3763db360b1fb34 Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Tue, 17 Sep 2024 13:20:04 +0100 Subject: many, many changes --- gui/src/types/balanceMap.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 gui/src/types/balanceMap.ts (limited to 'gui/src/types/balanceMap.ts') diff --git a/gui/src/types/balanceMap.ts b/gui/src/types/balanceMap.ts new file mode 100644 index 0000000..760843f --- /dev/null +++ b/gui/src/types/balanceMap.ts @@ -0,0 +1,17 @@ +import { Category } from "./category"; +import Currency from "./currency/currency"; +import { newGbpFromDto } from "./currency/gbp"; + +type BalanceMap = { + [id in T["id"]]: Currency; +}; + +function newCategoryBalanceMapFromDto(dto: unknown): BalanceMap { + return Object.fromEntries( + (dto as { category_id: Category["id"]; balance: number }[]).map( + ({ category_id, balance }) => [category_id, newGbpFromDto(balance)], + ), + ); +} + +export { type BalanceMap, newCategoryBalanceMapFromDto }; -- cgit v1.2.3