AddUserToProject API

This commit is contained in:
Peter KW 2024-03-21 03:36:57 +01:00
parent a73432669c
commit 2694beb0e8

View file

@ -7,6 +7,7 @@ import {
UserProjectMember, UserProjectMember,
WeeklyReport, WeeklyReport,
StrNameChange, StrNameChange,
NewProjMember,
} from "../Types/goTypes"; } from "../Types/goTypes";
/** /**
@ -144,6 +145,10 @@ interface API {
data: StrNameChange, data: StrNameChange,
token: string, token: string,
): Promise<APIResponse<void>>; ): Promise<APIResponse<void>>;
addUserToProject(
user: NewProjMember,
token: string,
): Promise<APIResponse<NewProjMember>>;
} }
/** An instance of the API */ /** An instance of the API */
@ -254,6 +259,30 @@ export const api: API = {
} }
}, },
async addUserToProject(
user: NewProjMember,
token: string,
): Promise<APIResponse<NewProjMember>> {
try {
const response = await fetch("/api/addUserToProject", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
body: JSON.stringify(user),
});
if (!response.ok) {
return { success: false, message: "Failed to add member" };
} else {
return { success: true, message: "Added member" };
}
} catch (e) {
return { success: false, message: "Failed to add member" };
}
},
async renewToken(token: string): Promise<APIResponse<string>> { async renewToken(token: string): Promise<APIResponse<string>> {
try { try {
const response = await fetch("/api/loginrenew", { const response = await fetch("/api/loginrenew", {
@ -353,9 +382,7 @@ export const api: API = {
if (!response.ok) { if (!response.ok) {
return { success: false, message: "Failed to get weekly report" }; return { success: false, message: "Failed to get weekly report" };
} else { } else {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const data = (await response.json()) as WeeklyReport; const data = (await response.json()) as WeeklyReport;
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
return { success: true, data }; return { success: true, data };
} }
} catch (e) { } catch (e) {