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/account.ts | |
| parent | f0e3e0cfb183253e03b1a61ddecb7b9330d47fdb (diff) | |
many, many changes
Diffstat (limited to 'gui/src/types/account.ts')
| -rw-r--r-- | gui/src/types/account.ts | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/gui/src/types/account.ts b/gui/src/types/account.ts index 4a3626c..a463304 100644 --- a/gui/src/types/account.ts +++ b/gui/src/types/account.ts @@ -1,5 +1,27 @@ -import { Moment } from "moment"; +import moment, { Moment } from "moment"; import Currency from "./currency/currency"; +import Gbp from "./currency/gbp"; + +function newAccountFromDto(dto: unknown): Account { + const dtoDangerous = dto as AccountDto; + return { + id: dtoDangerous.id, + name: dtoDangerous.name, + openingBalance: new Gbp( + Math.floor(Math.abs(dtoDangerous.opening_balance) / 100), + Math.abs(dtoDangerous.opening_balance) % 100, + dtoDangerous.opening_balance < 0 ? -1 : 1, + ), + openingDate: moment(dtoDangerous.opening_date), + }; +} + +interface AccountDto { + readonly id: number; + readonly name: string; + readonly opening_balance: number; + readonly opening_date: string; +} interface Account { readonly id: number; @@ -8,4 +30,4 @@ interface Account { readonly openingDate: Moment; } -export default Account; +export { type Account, newAccountFromDto }; |
