diff --git a/frontend/src/API/API.ts b/frontend/src/API/API.ts index 52fd5b9..f1bef85 100644 --- a/frontend/src/API/API.ts +++ b/frontend/src/API/API.ts @@ -1,6 +1,10 @@ -import { NewProject, Project } from "../Types/Project"; -import { NewUser, User } from "../Types/Users"; -import { NewWeeklyReport } from "../Types/goTypes"; +import { + NewWeeklyReport, + NewUser, + User, + Project, + NewProject, +} from "../Types/goTypes"; // This type of pattern should be hard to misuse interface APIResponse { @@ -33,6 +37,8 @@ interface API { username: string, token: string, ): Promise>; + /** Login */ + login(NewUser: NewUser): Promise>; } // Export an instance of the API @@ -156,7 +162,7 @@ export const api: API = { } }, - submitWeeklyReport: function ( + async submitWeeklyReport( project: NewWeeklyReport, token: string, ): Promise> { @@ -179,7 +185,7 @@ export const api: API = { return response.json(); } }) - .then((data) => { + .then((data: Project) => { return { success: true, data }; }); } catch (e) { @@ -189,4 +195,25 @@ export const api: API = { }); } }, + + async login(NewUser: NewUser): Promise> { + try { + const response = await fetch("/api/login", { + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify(NewUser), + }); + + if (!response.ok) { + return { success: false, message: "Failed to login" }; + } else { + const data = (await response.json()) as JSON; + return { success: true, data }; + } + } catch (e) { + return Promise.resolve({ success: false, message: "Failed to login" }); + } + }, }; diff --git a/frontend/src/Types/Project.ts b/frontend/src/Types/Project.ts deleted file mode 100644 index bb4f8c7..0000000 --- a/frontend/src/Types/Project.ts +++ /dev/null @@ -1,13 +0,0 @@ -export interface Project { - id: number; - name: string; - description: string; - owner: string; - created: string; // This is a date -} - -export interface NewProject { - name: string; - description: string; - owner: string; -} diff --git a/frontend/src/Types/TimeReport.ts b/frontend/src/Types/TimeReport.ts deleted file mode 100644 index 9685964..0000000 --- a/frontend/src/Types/TimeReport.ts +++ /dev/null @@ -1,9 +0,0 @@ -export interface TimeReport { - week: string; - development: string; - meeting: string; - administration: string; - ownwork: string; - studies: string; - testing: string; -} diff --git a/frontend/src/Types/Users.ts b/frontend/src/Types/Users.ts deleted file mode 100644 index 8323b2e..0000000 --- a/frontend/src/Types/Users.ts +++ /dev/null @@ -1,11 +0,0 @@ -// This is how the API responds -export interface User { - id: number; - userName: string; -} - -// Used to create a new user -export interface NewUser { - userName: string; - password: string; -}