Create families list screen
This commit is contained in:
@ -1,6 +1,15 @@
|
||||
import { APIClient } from "./ApiClient";
|
||||
|
||||
export interface Family {}
|
||||
export interface Family {
|
||||
user_id: number;
|
||||
family_id: number;
|
||||
name: string;
|
||||
time_create: number;
|
||||
is_admin: boolean;
|
||||
invitation_code: string;
|
||||
count_members: number;
|
||||
count_admins: number;
|
||||
}
|
||||
|
||||
export enum JoinFamilyResult {
|
||||
TooManyRequests,
|
||||
@ -50,10 +59,29 @@ export class FamilyApi {
|
||||
/**
|
||||
* Get the list of families
|
||||
*/
|
||||
static async GetList():Promise<Family[]> {
|
||||
return (await APIClient.exec({
|
||||
method: "GET",
|
||||
uri: "/family/list",
|
||||
static async GetList(): Promise<Family[]> {
|
||||
return (
|
||||
await APIClient.exec({
|
||||
method: "GET",
|
||||
uri: "/family/list",
|
||||
})
|
||||
).data;
|
||||
}
|
||||
|
||||
})).data
|
||||
}}
|
||||
/**
|
||||
* Check if the current user user can leave a family
|
||||
*/
|
||||
static CanLeaveFamily(f: Family): boolean {
|
||||
return !f.is_admin || f.count_admins > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to leave a family
|
||||
*/
|
||||
static async LeaveFamily(id: number): Promise<void> {
|
||||
await APIClient.exec({
|
||||
method: "POST",
|
||||
uri: `/family/${id}/leave`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user