bug fix on delete
This commit is contained in:
parent
a494cd4f0a
commit
06a6e9b8a5
3 changed files with 14 additions and 7 deletions
|
|
@ -236,11 +236,13 @@ app.put("/assignments/:id", async (req, res) => {
|
||||||
app.delete("/assignments/:id", async (req, res) => {
|
app.delete("/assignments/:id", async (req, res) => {
|
||||||
try {
|
try {
|
||||||
const { id } = req.params;
|
const { id } = req.params;
|
||||||
|
console.log("Deleting assignment with ID:", id);
|
||||||
|
|
||||||
await prisma.assignments.delete({
|
await prisma.assignments.delete({
|
||||||
where: { assignmentid: parseInt(id) },
|
where: { assignmentid: parseInt(id) },
|
||||||
});
|
});
|
||||||
|
|
||||||
|
console.log("Assignment deleted successfully:", id);
|
||||||
res.json({ message: "Assignment deleted successfully" });
|
res.json({ message: "Assignment deleted successfully" });
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error deleting assignment:", err.message);
|
console.error("Error deleting assignment:", err.message);
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ intructorRouter.post(
|
||||||
const updatedAssignmentData = {
|
const updatedAssignmentData = {
|
||||||
assignmenturl: `${PROXY_URL}/${ipv6}`,
|
assignmenturl: `${PROXY_URL}/${ipv6}`,
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Updating assignment with deployment details:", updatedAssignmentData);
|
console.log("Updating assignment with deployment details:", updatedAssignmentData);
|
||||||
const updateRespone = await axios.put(
|
const updateRespone = await axios.put(
|
||||||
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`,
|
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`,
|
||||||
|
|
@ -196,7 +196,6 @@ intructorRouter.delete(
|
||||||
// Delete the Battlesnake API
|
// Delete the Battlesnake API
|
||||||
if(assignmentData.appname){
|
if(assignmentData.appname){
|
||||||
console.log(`Deleting Battlesnake API: ${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`, {
|
const deployResponse = await axios.post(`${DEPLOY_API_URL}/${assignmentData.appname}/delete`, {
|
||||||
"appName": assignmentData.appname
|
"appName": assignmentData.appname
|
||||||
});
|
});
|
||||||
|
|
@ -208,9 +207,11 @@ intructorRouter.delete(
|
||||||
console.log('Response from DEPLOY_API_URL:', deployResponse.data);
|
console.log('Response from DEPLOY_API_URL:', deployResponse.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("Deleting assignment from database:", assignmentId);
|
||||||
const response = await axios.delete(
|
const response = await axios.delete(
|
||||||
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`
|
`${DB_ASSIGNMENT_SERVICE_URL}/assignments/${assignmentId}`
|
||||||
);
|
);
|
||||||
|
console.log("Response from DB_ASSIGNMENT_SERVICE_URL:", response.data);
|
||||||
res.status(response.status).json(response.data);
|
res.status(response.status).json(response.data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
res.status(error.response?.status || 500).json({ error: error.message });
|
res.status(error.response?.status || 500).json({ error: error.message });
|
||||||
|
|
|
||||||
|
|
@ -230,17 +230,21 @@ app.post("/:appName/delete", async (req, res) => {
|
||||||
|
|
||||||
//check if the app exists
|
//check if the app exists
|
||||||
console.log("Checking if app exists:", appName);
|
console.log("Checking if app exists:", appName);
|
||||||
|
|
||||||
const appCheck = await fly.get(`/apps/${appName}`);
|
const appCheck = await fly.get(`/apps/${appName}`);
|
||||||
console.log("App check response:", appCheck.status);
|
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}`);
|
await fly.delete(`/apps/${appName}`);
|
||||||
|
|
||||||
return res.json({ status: "deleted", app: appName });
|
return res.json({ status: "deleted", app: appName });
|
||||||
} catch (err) {
|
} 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;
|
const errorData = err.response?.data || err.stack || err.message;
|
||||||
console.error("App deletion error:", errorData);
|
console.error("App deletion error:", errorData);
|
||||||
return res.status(500).json({ errorData });
|
return res.status(500).json({ errorData });
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue