diff --git a/backend/index.js b/backend/index.js index 1ce917a..b02c8f1 100644 --- a/backend/index.js +++ b/backend/index.js @@ -81,10 +81,12 @@ app.use("/attachments", attachmentsDownloadRoute); const runsIndexRoute = require("./routes/runs/index")(sequelize); const runsShowRoute = require("./routes/runs/show")(sequelize); const runsNewRoute = require("./routes/runs/new")(sequelize); +const runsEditRoute = require("./routes/runs/edit")(sequelize); const runDeleteRoute = require("./routes/runs/delete")(sequelize); app.use("/runs", runsIndexRoute); app.use("/runs", runsShowRoute); app.use("/runs", runsNewRoute); +app.use("/runs", runsEditRoute); app.use("/runs", runDeleteRoute); const PORT = process.env.PORT || 3001; diff --git a/backend/routes/runs/edit.js b/backend/routes/runs/edit.js new file mode 100644 index 0000000..63e7a26 --- /dev/null +++ b/backend/routes/runs/edit.js @@ -0,0 +1,28 @@ +const express = require("express"); +const router = express.Router(); +const defineRun = require("../../models/runs"); +const { DataTypes } = require("sequelize"); + +module.exports = function (sequelize) { + const Run = defineRun(sequelize, DataTypes); + + router.put("/:runId", async (req, res) => { + const runId = req.params.runId; + const updateRun = req.body; + try { + const testrun = await Run.findByPk(runId); + if (!testrun) { + return res.status(404).send("Run not found"); + } + + delete updateRun.Steps; + await testrun.update(updateRun); + res.json(testrun); + } catch (error) { + console.error(error); + res.status(500).send("Internal Server Error"); + } + }); + + return router; +}; diff --git a/frontend/app/projects/[projectId]/runs/runsControl.ts b/frontend/app/projects/[projectId]/runs/runsControl.ts index 0b485b9..f14bbb0 100644 --- a/frontend/app/projects/[projectId]/runs/runsControl.ts +++ b/frontend/app/projects/[projectId]/runs/runsControl.ts @@ -87,7 +87,7 @@ async function updateRun(updateTestRun: RunType) { body: JSON.stringify(updateTestRun), }; - const url = `${apiServer}/cases/${updateTestRun.id}`; + const url = `${apiServer}/runs/${updateTestRun.id}`; try { const response = await fetch(url, fetchOptions);