Add accounts list as a provider

This commit is contained in:
2025-04-07 22:12:26 +02:00
parent 90bb4db806
commit ad4c0d2885
4 changed files with 146 additions and 30 deletions

View File

@ -0,0 +1,41 @@
import { APIClient } from "./ApiClient";
export interface Account {
id: number;
name: string;
user_id: number;
time_create: number;
time_update: number;
default_account: boolean;
}
export class AccountsList {
list: Account[];
constructor(list: Account[]) {
this.list = list;
}
/**
* Get a single account by its id
*/
get(id: number): Account | null {
return this.list.find((a) => a.id === id) ?? null;
}
}
export class AccountApi {
/**
* Get the current list of accounts of the user
*/
static async GetList(): Promise<AccountsList> {
const array = (
await APIClient.exec({
uri: "/accounts",
method: "GET",
})
).data;
return new AccountsList(array);
}
}