diff --git a/CHANGELOG.md b/CHANGELOG.md index f324e677..57ddb4de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ## [Unreleased] +### Changed + +- Ensure account balances returned from the backend are numbers + ## [0.8.0] - 2022-10-26 ### Changed diff --git a/src/services/accountApiService.ts b/src/services/accountApiService.ts index c6b394ed..57b7d403 100644 --- a/src/services/accountApiService.ts +++ b/src/services/accountApiService.ts @@ -42,17 +42,30 @@ export const useAccountApiService = defineStore('accountApiService', () => { function createAccountFromResponseData( data: AccountApiResponseData ): Account { + // TODO fix in API controller + ensureNumbersInAccountStatsData(data.stats); + return { - id: Number(data.id), // TODO in API controller + id: Number(data.id), // TODO fix in API controller name: data.name, description: data.description, currency: data.currency, - type: Number(data.type), // TODO in API controller - balance: Number(data.balance), // TODO in API controller + type: Number(data.type), // TODO fix in API controller + balance: Number(data.balance), // fix TODO in API controller stats: data.stats }; } + function ensureNumbersInAccountStatsData( + stats: AccountApiResponseData['stats'] + ): void { + for (const [ year, months ] of Object.entries(stats)) { + for (const [ month, value ] of Object.entries(months)) { + stats[year][month] = Number(value); + } + } + } + return { getAccount, getAccounts,