From 74285dc1cfb4d60e95b63bb0dced87855f8e4c87 Mon Sep 17 00:00:00 2001 From: al8763be Date: Tue, 19 Mar 2024 19:45:56 +0100 Subject: [PATCH 1/8] Before fuck up --- frontend/src/API/API.ts | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 8fd66d3..0fc29a0 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -24,6 +24,7 @@ interface API { login(NewUser: NewUser): Promise>; /** Renew the token */ renewToken(token: string): Promise>; + /** Promote user to admin */ /** Create a project */ createProject( project: NewProject, @@ -41,6 +42,10 @@ interface API { week: string, token: string, ): Promise>; + getWeeklyReportsForProject( + projectName: string, + token: string, + ): Promise>; /** Gets all the projects of a user*/ getUserProjects(token: string): Promise>; /** Gets a project from id*/ @@ -232,6 +237,34 @@ export const api: API = { } }, + async getWeeklyReportsForProject(projectName: string, token: string) { + try { + const response = await fetch("/api/getWeeklyReportsForProject", { + method: "GET", + headers: { + "Content-Type": "application/json", + Authorization: "Bearer " + token, + }, + body: JSON.stringify({ projectName }), + }); + + if (!response.ok) { + return { + success: false, + message: "Failed to get weekly reports for project", + }; + } else { + const data = (await response.json()) as NewWeeklyReport[]; + return { success: true, data }; + } + } catch (e) { + return { + success: false, + message: "Failed to get weekly reports for project", + }; + } + }, + async login(NewUser: NewUser): Promise> { try { const response = await fetch("/api/login", { From e48bf5d98cdbb468690473a06f0dca364d668a19 Mon Sep 17 00:00:00 2001 From: al8763be Date: Tue, 19 Mar 2024 20:25:26 +0100 Subject: [PATCH 2/8] Added checkIfProjectManager, hope it works --- frontend/src/API/API.ts | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 0fc29a0..a1ecfde 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -20,6 +20,12 @@ 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 */ @@ -106,6 +112,30 @@ export const api: API = { } }, + async checkIfProjectManager(token: string): Promise> { + try { + const response = await fetch("/api/checkIfProjectManager", { + 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: "fuck" }; + } + }, + async createProject( project: NewProject, token: string, From 0b6edd359ecaa6b19986b520618225c65203223b Mon Sep 17 00:00:00 2001 From: al8763be Date: Tue, 19 Mar 2024 20:29:36 +0100 Subject: [PATCH 3/8] Bumfix for BumCode on checkIfProjectManager --- frontend/src/API/API.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index a1ecfde..fc2367b 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -112,7 +112,11 @@ export const api: API = { } }, - async checkIfProjectManager(token: string): Promise> { + async checkIfProjectManager( + username: string, + projectName: string, + token: string, + ): Promise> { try { const response = await fetch("/api/checkIfProjectManager", { method: "GET", @@ -120,6 +124,7 @@ export const api: API = { "Content-Type": "application/json", Authorization: "Bearer " + token, }, + body: JSON.stringify({ username, projectName }), }); if (!response.ok) { From d41bfcf8886b6c0d63df8cd7e1a0ab4a75179948 Mon Sep 17 00:00:00 2001 From: al8763be Date: Wed, 20 Mar 2024 14:00:00 +0100 Subject: [PATCH 4/8] Fix for getWeeklyReportsForUser --- frontend/src/API/API.ts | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index fc2367b..c4a9e43 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 @@ -47,11 +48,12 @@ interface API { projectName: string, week: string, token: string, - ): Promise>; + ): Promise>; getWeeklyReportsForProject( + username: string, projectName: string, token: string, - ): Promise>; + ): Promise>; /** Gets all the projects of a user*/ getUserProjects(token: string): Promise>; /** Gets a project from id*/ @@ -250,7 +252,7 @@ export const api: API = { projectName: string, week: string, token: string, - ): Promise> { + ): Promise> { try { const response = await fetch("/api/getWeeklyReport", { method: "GET", @@ -264,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) { @@ -272,15 +274,19 @@ export const api: API = { } }, - async getWeeklyReportsForProject(projectName: string, token: string) { + async getWeeklyReportsForProject( + username: string, + projectName: string, + token: string + ): Promise> { try { - const response = await fetch("/api/getWeeklyReportsForProject", { + const response = await fetch("/api/getWeeklyReportsUser", { method: "GET", headers: { "Content-Type": "application/json", Authorization: "Bearer " + token, }, - body: JSON.stringify({ projectName }), + body: JSON.stringify({ username, projectName }), }); if (!response.ok) { @@ -289,7 +295,7 @@ export const api: API = { message: "Failed to get weekly reports for project", }; } else { - const data = (await response.json()) as NewWeeklyReport[]; + const data = (await response.json()) as WeeklyReport[]; return { success: true, data }; } } catch (e) { From 74e134716250fa07ab056f652cda812ba9febdd9 Mon Sep 17 00:00:00 2001 From: al8763be Date: Wed, 20 Mar 2024 14:02:34 +0100 Subject: [PATCH 5/8] Changed error message --- frontend/src/API/API.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index c4a9e43..1e90174 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -277,7 +277,7 @@ export const api: API = { async getWeeklyReportsForProject( username: string, projectName: string, - token: string + token: string, ): Promise> { try { const response = await fetch("/api/getWeeklyReportsUser", { @@ -301,7 +301,7 @@ export const api: API = { } catch (e) { return { success: false, - message: "Failed to get weekly reports for project", + message: "fucked again", }; } }, From a84c2c6129ed6d1daca8369030a3ddd81b101c0f Mon Sep 17 00:00:00 2001 From: Imbus <> Date: Wed, 20 Mar 2024 14:54:22 +0100 Subject: [PATCH 6/8] Rename GetWeeklyReportsForProject -> GetWeeklyReportsForUser --- frontend/src/API/API.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 1e90174..a3c4e92 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -49,7 +49,7 @@ interface API { week: string, token: string, ): Promise>; - getWeeklyReportsForProject( + getWeeklyReportsForUser( username: string, projectName: string, token: string, @@ -274,7 +274,7 @@ export const api: API = { } }, - async getWeeklyReportsForProject( + async getWeeklyReportsForUser( username: string, projectName: string, token: string, From 771118f85ead09aac4619f7870593b7456da804c Mon Sep 17 00:00:00 2001 From: al8763be Date: Wed, 20 Mar 2024 15:13:00 +0100 Subject: [PATCH 7/8] Update API.ts --- frontend/src/API/API.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index a3c4e92..d6a4b23 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -286,7 +286,7 @@ export const api: API = { "Content-Type": "application/json", Authorization: "Bearer " + token, }, - body: JSON.stringify({ username, projectName }), + body: JSON.stringify({ username: username, projectName: projectName}), }); if (!response.ok) { From af5813681d11500c0cfe723af1b8d2522bf277d2 Mon Sep 17 00:00:00 2001 From: al8763be Date: Wed, 20 Mar 2024 15:17:00 +0100 Subject: [PATCH 8/8] Jag avskyr denna handlern --- frontend/src/API/API.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index d6a4b23..6a508b5 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -280,13 +280,12 @@ export const api: API = { token: string, ): Promise> { try { - const response = await fetch("/api/getWeeklyReportsUser", { + const response = await fetch(`/api/getWeeklyReportsUser?username=${username}&projectName=${projectName}`, { method: "GET", headers: { "Content-Type": "application/json", Authorization: "Bearer " + token, }, - body: JSON.stringify({ username: username, projectName: projectName}), }); if (!response.ok) {