blob: a46330450804fa97e6507e9c8272caf25eed8aec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
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;
readonly name: string;
readonly openingBalance: Currency;
readonly openingDate: Moment;
}
export { type Account, newAccountFromDto };
|