Can set member photo
This commit is contained in:
@ -29,16 +29,31 @@ export class APIClient {
|
||||
method: "GET" | "POST" | "DELETE" | "PATCH" | "PUT";
|
||||
allowFail?: boolean;
|
||||
jsonData?: any;
|
||||
formData?: FormData;
|
||||
}): Promise<APIResponse> {
|
||||
let body = undefined;
|
||||
let headers: any = {
|
||||
"X-auth-token": AuthApi.SignedIn ? AuthApi.AuthToken : "none",
|
||||
};
|
||||
|
||||
// JSON request
|
||||
if (args.jsonData) {
|
||||
headers["Content-Type"] = "application/json";
|
||||
body = JSON.stringify(args.jsonData);
|
||||
}
|
||||
|
||||
// Form data request
|
||||
else if (args.formData) {
|
||||
body = args.formData;
|
||||
}
|
||||
|
||||
const res = await fetch(this.backendURL() + args.uri, {
|
||||
method: args.method,
|
||||
body: args.jsonData ? JSON.stringify(args.jsonData) : undefined,
|
||||
headers: {
|
||||
"X-auth-token": AuthApi.SignedIn ? AuthApi.AuthToken : "none",
|
||||
"Content-Type": args.jsonData ? "application/json" : "text/plain",
|
||||
},
|
||||
body: body,
|
||||
headers: headers,
|
||||
});
|
||||
|
||||
// Process response
|
||||
let data;
|
||||
if (res.headers.get("content-type") === "application/json")
|
||||
data = await res.json();
|
||||
|
@ -106,6 +106,14 @@ export class Member implements MemberDataApi {
|
||||
? this.last_name ?? ""
|
||||
: `${firstName} ${this.last_name ?? ""}`;
|
||||
}
|
||||
|
||||
get hasPhoto(): boolean {
|
||||
return this.photo_id !== null;
|
||||
}
|
||||
|
||||
get photoURL(): string {
|
||||
return `${APIClient.backendURL()}/photo/${this.signed_photo_id}`;
|
||||
}
|
||||
}
|
||||
|
||||
export class MembersList {
|
||||
@ -174,6 +182,19 @@ export class MemberApi {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new photo for a member
|
||||
*/
|
||||
static async SetMemberPhoto(m: Member, b: Blob): Promise<void> {
|
||||
const fd = new FormData();
|
||||
fd.append("photo", b);
|
||||
await APIClient.exec({
|
||||
uri: `/family/${m.family_id}/member/${m.id}/photo`,
|
||||
method: "PUT",
|
||||
formData: fd,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a family member
|
||||
*/
|
||||
|
Reference in New Issue
Block a user