2023-06-27 15:13:12 +00:00
|
|
|
import { APIClient } from "./ApiClient";
|
|
|
|
|
|
|
|
export interface Family {}
|
|
|
|
|
2023-06-27 16:52:49 +00:00
|
|
|
export enum JoinFamilyResult {
|
|
|
|
TooManyRequests,
|
|
|
|
InvalidCode,
|
|
|
|
AlreadyMember,
|
|
|
|
Error,
|
|
|
|
Success,
|
|
|
|
}
|
|
|
|
|
2023-06-27 15:13:12 +00:00
|
|
|
export class FamilyApi {
|
|
|
|
/**
|
|
|
|
* Create a new family
|
|
|
|
*/
|
|
|
|
static async CreateFamily(name: string): Promise<void> {
|
|
|
|
await APIClient.exec({
|
|
|
|
method: "POST",
|
|
|
|
uri: "/family/create",
|
|
|
|
jsonData: { name: name },
|
|
|
|
});
|
|
|
|
}
|
2023-06-27 16:52:49 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Join an existing family
|
|
|
|
*/
|
|
|
|
static async JoinFamily(code: string): Promise<JoinFamilyResult> {
|
|
|
|
const res = await APIClient.exec({
|
|
|
|
method: "POST",
|
|
|
|
uri: "/family/join",
|
|
|
|
allowFail: true,
|
|
|
|
jsonData: { code: code },
|
|
|
|
});
|
|
|
|
|
|
|
|
if (res.status >= 200 && res.status < 300) return JoinFamilyResult.Success;
|
|
|
|
|
|
|
|
switch (res.status) {
|
|
|
|
case 429:
|
|
|
|
return JoinFamilyResult.TooManyRequests;
|
|
|
|
case 404:
|
|
|
|
return JoinFamilyResult.InvalidCode;
|
|
|
|
case 409:
|
|
|
|
return JoinFamilyResult.AlreadyMember;
|
|
|
|
default:
|
|
|
|
return JoinFamilyResult.Error;
|
|
|
|
}
|
|
|
|
}
|
2023-06-27 15:13:12 +00:00
|
|
|
}
|