Display accounts balances

This commit is contained in:
2025-04-21 12:31:00 +02:00
parent 6ee250d872
commit 1621fe41e2
5 changed files with 60 additions and 3 deletions

View File

@ -1,4 +1,5 @@
import { APIClient } from "./ApiClient";
import { Balances } from "./MovementsApi";
import { ServerApi } from "./ServerApi";
export interface Account {
@ -9,6 +10,7 @@ export interface Account {
time_update: number;
type: string;
default_account: boolean;
balance: number;
}
export class AccountsList {
@ -32,6 +34,18 @@ export class AccountsList {
get(id: number): Account | null {
return this.list.find((a) => a.id === id) ?? null;
}
/**
* Update all accounts balances
*/
mapBalances(balances: Balances): AccountsList {
return new AccountsList(
this.list.map((a) => {
a.balance = balances[a.id] ?? 0;
return a;
})
);
}
}
export class AccountApi {
@ -41,7 +55,7 @@ export class AccountApi {
static async GetList(): Promise<AccountsList> {
const array = (
await APIClient.exec({
uri: "/accounts",
uri: `/accounts?include_balances=true`,
method: "GET",
})
).data;

View File

@ -0,0 +1,19 @@
import { APIClient } from "./ApiClient";
export interface Balances {
[key: number]: number;
}
export class MovementApi {
/**
* Get all accounts balances
*/
static async GetAllBalances(): Promise<Balances> {
return (
await APIClient.exec({
uri: `/accounts/balances`,
method: "GET",
})
).data;
}
}