diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 8fd66d3..37db463 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -20,7 +20,23 @@ interface API { registerUser(user: NewUser): Promise>; /** Remove a user */ removeUser(username: string, token: string): Promise>; - /** Login */ + + /** + * Check if user is project manager. + * @param {string} username The username of the user. + * @param {string} projectName The name of the project. + * @param {string} token The authentication token. + * @returns {Promise>} A promise containing the API response indicating if the user is a project manager. + */ + checkIfProjectManager( + projectName: string, + token: string, + ): Promise>; + + /** Logs in a user with the provided credentials. + * @param {NewUser} NewUser The user object containing username and password. + * @returns {Promise>} A promise resolving to an API response with a token. + */ login(NewUser: NewUser): Promise>; /** Renew the token */ renewToken(token: string): Promise>; @@ -101,6 +117,36 @@ export const api: API = { } }, + async checkIfProjectManager( + projectName: string, + token: string, + ): Promise> { + try { + const response = await fetch( + `/api/checkIfProjectManager?projectName=${projectName}`, + { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }, + }, + ); + + if (!response.ok) { + return { + success: false, + message: "Failed to check if project manager", + }; + } else { + const data = (await response.json()) as boolean; + return { success: true, data }; + } + } catch (e) { + return { success: false, message: "Failed to check if project manager" }; + } + }, + async createProject( project: NewProject, token: string,