diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 7f5c420..f05d698 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -4,6 +4,7 @@ import { User, Project, NewProject, + PublicUser, } from "../Types/goTypes"; // This type of pattern should be hard to misuse @@ -45,8 +46,13 @@ interface API { getUserProjects(token: string): Promise>; /** Gets a project from id*/ getProject(id: number): Promise>; - /** Gets a project from id*/ + /** Gets all users*/ getAllUsers(token: string): Promise>; + /** Gets all users in a project from name*/ + getAllUsersProject( + projectName: string, + token: string, + ): Promise>; } // Export an instance of the API @@ -308,4 +314,34 @@ export const api: API = { }); } }, + //Gets all users in a project + async getAllUsersProject( + projectName: string, + token: string, + ): Promise> { + try { + const response = await fetch(`/api/getUsersProject/${projectName}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }, + }); + + if (!response.ok) { + return Promise.resolve({ + success: false, + message: "Failed to get users", + }); + } else { + const data = (await response.json()) as User[]; + return Promise.resolve({ success: true, data }); + } + } catch (e) { + return Promise.resolve({ + success: false, + message: "API is not ok", + }); + } + }, };