diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index f6e5979..32c5eb2 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -33,13 +33,14 @@ interface API { submitWeeklyReport( project: NewWeeklyReport, token: string, - ): Promise>; + ): Promise>; /**Gets a weekly report*/ getWeeklyReport( username: string, projectName: string, week: string, - ): Promise>; + token: string, + ): Promise>; /** Gets all the projects of a user*/ getUserProjects( username: string, @@ -169,9 +170,9 @@ export const api: API = { }, async submitWeeklyReport( - project: NewWeeklyReport, + weeklyReport: NewWeeklyReport, token: string, - ): Promise> { + ): Promise> { try { const response = await fetch("/api/submitWeeklyReport", { method: "POST", @@ -179,7 +180,7 @@ export const api: API = { "Content-Type": "application/json", Authorization: "Bearer " + token, }, - body: JSON.stringify(project), + body: JSON.stringify(weeklyReport), }); if (!response.ok) { @@ -189,7 +190,7 @@ export const api: API = { }; } - const data = (await response.json()) as Project; + const data = (await response.json()) as NewWeeklyReport; return { success: true, data }; } catch (e) { return { @@ -199,6 +200,33 @@ export const api: API = { } }, + async getWeeklyReport( + username: string, + projectName: string, + week: string, + token: string, + ): Promise> { + try { + const response = await fetch("/api/getWeeklyReport", { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }, + body: JSON.stringify({ username, projectName, week }), + }); + + if (!response.ok) { + return { success: false, message: "Failed to get weekly report" }; + } else { + const data = (await response.json()) as NewWeeklyReport; + return { success: true, data }; + } + } catch (e) { + return { success: false, message: "Failed to get weekly report" }; + } + }, + async login(NewUser: NewUser): Promise> { try { const response = await fetch("/api/login", {