Add accounts list as a provider
This commit is contained in:
41
moneymgr_web/src/api/AccountApi.ts
Normal file
41
moneymgr_web/src/api/AccountApi.ts
Normal 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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user