Before fuck up

This commit is contained in:
al8763be 2024-03-19 19:45:56 +01:00
parent 2b41085865
commit 74285dc1cf

View file

@ -24,6 +24,7 @@ interface API {
login(NewUser: NewUser): Promise<APIResponse<string>>;
/** Renew the token */
renewToken(token: string): Promise<APIResponse<string>>;
/** Promote user to admin */
/** Create a project */
createProject(
project: NewProject,
@ -41,6 +42,10 @@ interface API {
week: string,
token: string,
): Promise<APIResponse<NewWeeklyReport>>;
getWeeklyReportsForProject(
projectName: string,
token: string,
): Promise<APIResponse<NewWeeklyReport[]>>;
/** Gets all the projects of a user*/
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
/** 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<APIResponse<string>> {
try {
const response = await fetch("/api/login", {