Changes to SubmitWeeklyReport

This commit is contained in:
al8763be 2024-03-17 16:11:03 +01:00
parent 386f7c3a94
commit d57fe55074

View file

@ -167,32 +167,29 @@ export const api: API = {
token: string, token: string,
): Promise<APIResponse<Project>> { ): Promise<APIResponse<Project>> {
try { try {
return fetch("/api/submitWeeklyReport", { const response = await fetch("/api/submitWeeklyReport", {
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Authorization: "Bearer " + token, Authorization: "Bearer " + token,
}, },
body: JSON.stringify(project), body: JSON.stringify(project),
}) });
.then((response) => {
if (!response.ok) { if (!response.ok) {
return { return {
success: false, success: false,
message: "Failed to submit weekly report", message: "Failed to submit weekly report",
}; };
} else { }
return response.json();
} const data = (await response.json()) as Project;
}) return { success: true, data };
.then((data: Project) => {
return { success: true, data };
});
} catch (e) { } catch (e) {
return Promise.resolve({ return {
success: false, success: false,
message: "Failed to submit weekly report", message: "Failed to submit weekly report",
}); };
} }
}, },