bug fix on delete

This commit is contained in:
JBB0807 2025-05-08 00:14:10 -07:00
parent a494cd4f0a
commit 06a6e9b8a5
3 changed files with 14 additions and 7 deletions

View file

@ -236,11 +236,13 @@ app.put("/assignments/:id", async (req, res) => {
app.delete("/assignments/:id", async (req, res) => {
try {
const { id } = req.params;
console.log("Deleting assignment with ID:", id);
await prisma.assignments.delete({
where: { assignmentid: parseInt(id) },
});
console.log("Assignment deleted successfully:", id);
res.json({ message: "Assignment deleted successfully" });
} catch (err) {
console.error("Error deleting assignment:", err.message);

View file

@ -196,7 +196,6 @@ intructorRouter.delete(
// Delete the Battlesnake API
if(assignmentData.appname){
console.log(`Deleting Battlesnake API: ${assignmentData.appname}`);
console.log("DEPLOY_API_URL:", DEPLOY_API_URL, assignmentData.appname);
const deployResponse = await axios.post(`${DEPLOY_API_URL}/${assignmentData.appname}/delete`, {
"appName": assignmentData.appname
});
@ -208,9 +207,11 @@ intructorRouter.delete(
console.log('Response from DEPLOY_API_URL:', deployResponse.data);
}
console.log("Deleting assignment from database:", assignmentId);
const response = await axios.delete(
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`
);
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
res.status(response.status).json(response.data);
} catch (error) {
res.status(error.response?.status || 500).json({ error: error.message });

View file

@ -230,17 +230,21 @@ app.post("/:appName/delete", async (req, res) => {
//check if the app exists
console.log("Checking if app exists:", appName);
const appCheck = await fly.get(`/apps/${appName}`);
console.log("App check response:", appCheck.status);
if (appCheck.status !== 200) {
console.log("App not found:", appName);
return res.json({ status: "App not found", app: appName });
}
await fly.delete(`/apps/${appName}`);
return res.json({ status: "deleted", app: appName });
} catch (err) {
//handle the 404 error and not treat it as a failure (no app to delete)
if (err.response?.status === 404) {
console.log("App not found, nothing to delete:", appName);
return res.status(200).json({ error: "App not found" });
}
const errorData = err.response?.data || err.stack || err.message;
console.error("App deletion error:", errorData);
return res.status(500).json({ errorData });