Skip to content

Commit

Permalink
ensure account stats are numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
powerpaul17 committed Oct 27, 2022
1 parent a547553 commit 01f9a8d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## [Unreleased]

### Changed

- Ensure account balances returned from the backend are numbers

## [0.8.0] - 2022-10-26

### Changed
Expand Down
19 changes: 16 additions & 3 deletions src/services/accountApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 01f9a8d

Please sign in to comment.