Merge frontend -> dev

This commit is contained in:
Imbus 2024-03-20 17:19:09 +01:00
commit b405b44460
33 changed files with 645 additions and 243 deletions

View file

@ -66,6 +66,8 @@ interface API {
getUserProjects(token: string): Promise<APIResponse<Project[]>>;
/** Gets a project from id*/
getProject(id: number): Promise<APIResponse<Project>>;
/** Gets a project from id*/
getAllUsers(token: string): Promise<APIResponse<string[]>>;
}
// Export an instance of the API
@ -102,7 +104,7 @@ export const api: API = {
token: string,
): Promise<APIResponse<User>> {
try {
const response = await fetch("/api/userdelete", {
const response = await fetch(`/api/userdelete/${username}`, {
method: "POST",
headers: {
"Content-Type": "application/json",
@ -298,7 +300,9 @@ export const api: API = {
if (!response.ok) {
return {
success: false,
message: "Failed to get weekly reports for project",
message:
"Failed to get weekly reports for project: Response code " +
response.status,
};
} else {
const data = (await response.json()) as WeeklyReport[];
@ -307,7 +311,7 @@ export const api: API = {
} catch (e) {
return {
success: false,
message: "fucked again",
message: "Failed to get weekly reports for project, unknown error",
};
}
},
@ -358,4 +362,32 @@ export const api: API = {
};
}
},
// Gets all users
async getAllUsers(token: string): Promise<APIResponse<string[]>> {
try {
const response = await fetch("/api/users/all", {
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
});
if (!response.ok) {
return Promise.resolve({
success: false,
message: "Failed to get users",
});
} else {
const data = (await response.json()) as string[];
return Promise.resolve({ success: true, data });
}
} catch (e) {
return Promise.resolve({
success: false,
message: "API is not ok",
});
}
},
};