From 2694beb0e8d80a95565b2f6a14c46e07e30f4464 Mon Sep 17 00:00:00 2001 From: Peter KW Date: Thu, 21 Mar 2024 03:36:57 +0100 Subject: [PATCH] AddUserToProject API --- frontend/src/API/API.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 70e36c9..7920e0e 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -7,6 +7,7 @@ import { UserProjectMember, WeeklyReport, StrNameChange, + NewProjMember, } from "../Types/goTypes"; /** @@ -144,6 +145,10 @@ interface API { data: StrNameChange, token: string, ): Promise>; + addUserToProject( + user: NewProjMember, + token: string, + ): Promise>; } /** An instance of the API */ @@ -254,6 +259,30 @@ export const api: API = { } }, + async addUserToProject( + user: NewProjMember, + token: string, + ): Promise> { + 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> { try { const response = await fetch("/api/loginrenew", { @@ -353,9 +382,7 @@ export const api: API = { if (!response.ok) { return { success: false, message: "Failed to get weekly report" }; } else { - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment const data = (await response.json()) as WeeklyReport; - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment return { success: true, data }; } } catch (e) {