Implemented test run editor's test case selection

This commit is contained in:
Takeshi Kimata
2024-04-13 23:36:52 +09:00
parent f78308343e
commit aa35d28801
3 changed files with 106 additions and 15 deletions

View File

@@ -0,0 +1,31 @@
function defineRunCase(sequelize, DataTypes) {
const RunCase = sequelize.define("RunCase", {
runId: {
type: DataTypes.INTEGER,
allowNull: false,
},
caseId: {
type: DataTypes.INTEGER,
allowNull: false,
},
status: {
type: DataTypes.INTEGER,
allowNull: false,
},
});
RunCase.associate = (models) => {
RunCase.belongsTo(models.Run, {
foreignKey: "runId",
onDelete: "CASCADE",
});
RunCase.belongsTo(models.Case, {
foreignKey: "caseId",
onDelete: "CASCADE",
});
};
return RunCase;
}
module.exports = defineRunCase;

View File

@@ -1,10 +1,14 @@
const express = require("express");
const router = express.Router();
const defineRun = require("../../models/runs");
const defineCase = require("../../models/cases");
const { DataTypes } = require("sequelize");
module.exports = function (sequelize) {
const Run = defineRun(sequelize, DataTypes);
const Case = defineCase(sequelize, DataTypes);
Run.belongsToMany(Case, { through: "runCases" });
Case.belongsToMany(Run, { through: "runCases" });
router.get("/:runId", async (req, res) => {
const runId = req.params.runId;
@@ -14,7 +18,13 @@ module.exports = function (sequelize) {
}
try {
const project = await Run.findByPk(runId);
const project = await Run.findByPk(runId, {
include: [
{
model: Case,
},
],
});
if (!project) {
return res.status(404).send("Run not found");
}