DeleteProject Handler + API function, ber till gud att denna funkar first try

This commit is contained in:
al8763be 2024-04-09 19:08:22 +02:00
parent a5e3d4259d
commit 67723bfccc
7 changed files with 172 additions and 0 deletions

View file

@ -248,6 +248,16 @@ interface API {
* @param {string} token Your token
*/
getUsername(id: number, token: string): Promise<APIResponse<string>>;
/**
* Deletes a WeeklyReport from the database
* @param {number} reportId The id of the report to delete
* @param {string} token The authentication token
*/
deleteWeeklyReport(
reportId: number,
token: string,
): Promise<APIResponse<string>>;
}
/** An instance of the API */
@ -929,4 +939,27 @@ export const api: API = {
return { success: false, message: "Failed to get username" };
}
},
async deleteWeeklyReport(
reportId: number,
token: string,
): Promise<APIResponse<string>> {
try {
const response = await fetch(`/api/deleteReport/${reportId}`, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + token,
},
});
if (!response.ok) {
return { success: false, message: "Failed to delete report" };
} else {
return { success: true, message: "Report deleted" };
}
} catch (e) {
return { success: false, message: "Failed to delete report" };
}
},
};