From 387385fec4607fb875c3859a276731f2c52f597e Mon Sep 17 00:00:00 2001 From: Takeshi Kimata <117462761+kimatata@users.noreply.github.com> Date: Sat, 13 Apr 2024 13:40:37 +0900 Subject: [PATCH] Implemented test run update --- backend/index.js | 2 ++ backend/routes/runs/edit.js | 28 +++++++++++++++++++ .../projects/[projectId]/runs/runsControl.ts | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 backend/routes/runs/edit.js 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);