diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 8fd66d3..6a508b5 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -4,6 +4,7 @@ import { User, Project, NewProject, + WeeklyReport, } from "../Types/goTypes"; // This type of pattern should be hard to misuse @@ -20,10 +21,17 @@ interface API { registerUser(user: NewUser): Promise>; /** Remove a user */ removeUser(username: string, token: string): Promise>; + /** Check if user is project manager */ + checkIfProjectManager( + username: string, + projectName: string, + token: string, + ): Promise>; /** Login */ login(NewUser: NewUser): Promise>; /** Renew the token */ renewToken(token: string): Promise>; + /** Promote user to admin */ /** Create a project */ createProject( project: NewProject, @@ -40,7 +48,12 @@ interface API { projectName: string, week: string, token: string, - ): Promise>; + ): Promise>; + getWeeklyReportsForUser( + username: string, + projectName: string, + token: string, + ): Promise>; /** Gets all the projects of a user*/ getUserProjects(token: string): Promise>; /** Gets a project from id*/ @@ -101,6 +114,35 @@ export const api: API = { } }, + async checkIfProjectManager( + username: string, + projectName: string, + token: string, + ): Promise> { + try { + const response = await fetch("/api/checkIfProjectManager", { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }, + body: JSON.stringify({ username, projectName }), + }); + + 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: "fuck" }; + } + }, + async createProject( project: NewProject, token: string, @@ -210,7 +252,7 @@ export const api: API = { projectName: string, week: string, token: string, - ): Promise> { + ): Promise> { try { const response = await fetch("/api/getWeeklyReport", { method: "GET", @@ -224,7 +266,7 @@ export const api: API = { if (!response.ok) { return { success: false, message: "Failed to get weekly report" }; } else { - const data = (await response.json()) as NewWeeklyReport; + const data = (await response.json()) as WeeklyReport; return { success: true, data }; } } catch (e) { @@ -232,6 +274,37 @@ export const api: API = { } }, + async getWeeklyReportsForUser( + username: string, + projectName: string, + token: string, + ): Promise> { + try { + const response = await fetch(`/api/getWeeklyReportsUser?username=${username}&projectName=${projectName}`, { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }, + }); + + if (!response.ok) { + return { + success: false, + message: "Failed to get weekly reports for project", + }; + } else { + const data = (await response.json()) as WeeklyReport[]; + return { success: true, data }; + } + } catch (e) { + return { + success: false, + message: "fucked again", + }; + } + }, + async login(NewUser: NewUser): Promise> { try { const response = await fetch("/api/login", {