Merge branch 'frontend' into gruppDM
This commit is contained in:
commit
c708ec47ca
4 changed files with 32 additions and 38 deletions
|
@ -1,6 +1,10 @@
|
||||||
import { NewProject, Project } from "../Types/Project";
|
import {
|
||||||
import { NewUser, User } from "../Types/Users";
|
NewWeeklyReport,
|
||||||
import { NewWeeklyReport } from "../Types/goTypes";
|
NewUser,
|
||||||
|
User,
|
||||||
|
Project,
|
||||||
|
NewProject,
|
||||||
|
} from "../Types/goTypes";
|
||||||
|
|
||||||
// This type of pattern should be hard to misuse
|
// This type of pattern should be hard to misuse
|
||||||
interface APIResponse<T> {
|
interface APIResponse<T> {
|
||||||
|
@ -33,6 +37,8 @@ interface API {
|
||||||
username: string,
|
username: string,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<Project[]>>;
|
): Promise<APIResponse<Project[]>>;
|
||||||
|
/** Login */
|
||||||
|
login(NewUser: NewUser): Promise<APIResponse<JSON>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Export an instance of the API
|
// Export an instance of the API
|
||||||
|
@ -156,7 +162,7 @@ export const api: API = {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
submitWeeklyReport: function (
|
async submitWeeklyReport(
|
||||||
project: NewWeeklyReport,
|
project: NewWeeklyReport,
|
||||||
token: string,
|
token: string,
|
||||||
): Promise<APIResponse<Project>> {
|
): Promise<APIResponse<Project>> {
|
||||||
|
@ -179,7 +185,7 @@ export const api: API = {
|
||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then((data) => {
|
.then((data: Project) => {
|
||||||
return { success: true, data };
|
return { success: true, data };
|
||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -189,4 +195,25 @@ export const api: API = {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
async login(NewUser: NewUser): Promise<APIResponse<JSON>> {
|
||||||
|
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" });
|
||||||
|
}
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -1,9 +0,0 @@
|
||||||
export interface TimeReport {
|
|
||||||
week: string;
|
|
||||||
development: string;
|
|
||||||
meeting: string;
|
|
||||||
administration: string;
|
|
||||||
ownwork: string;
|
|
||||||
studies: string;
|
|
||||||
testing: string;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Reference in a new issue