Implemented test run editor's bulk test case selection

This commit is contained in:
Takeshi Kimata
2024-04-21 12:28:30 +09:00
parent 41133f8270
commit d6cba787e2
7 changed files with 197 additions and 11 deletions

View File

@@ -0,0 +1,49 @@
const express = require("express");
const router = express.Router();
const defineRunCase = require("../../models/runCases");
const { DataTypes, Op } = require("sequelize");
module.exports = function (sequelize) {
const RunCase = defineRunCase(sequelize, DataTypes);
router.post("/bulkdelete", async (req, res) => {
const recordsToDelete = req.body;
try {
const existingRunCases = await RunCase.findAll({
where: {
[Op.or]: recordsToDelete.map((condition) => ({
runId: condition.runId,
caseId: condition.caseId,
})),
},
});
console.log("######bulkDelete")
console.log(recordsToDelete)
if (existingRunCases.length === 0) {
return res.status(400).send("No records found to delete");
}
// await RunCase.destroy({
// where: recordsToDelete,
// });
await RunCase.destroy({
where: {
[Op.or]: recordsToDelete.map((condition) => ({
runId: condition.runId,
caseId: condition.caseId,
})),
},
});
res.status(200).send("Records deleted successfully");
} catch (error) {
console.error("Error deleting run cases:", error);
res.status(500).send("Internal Server Error");
}
});
return router;
};

View File

@@ -0,0 +1,47 @@
const express = require("express");
const router = express.Router();
const defineRunCase = require("../../models/runCases");
const { DataTypes, Op } = require("sequelize");
module.exports = function (sequelize) {
const RunCase = defineRunCase(sequelize, DataTypes);
router.post("/bulknew", async (req, res) => {
const recordsToCreate = req.body;
try {
const existingRunCases = await RunCase.findAll({
where: {
[Op.or]: recordsToCreate.map((record) => ({
runId: record.runId,
caseId: record.caseId,
})),
},
});
// Filter out records that already exist
const recordsToCreateFiltered = recordsToCreate.filter((record) => {
return !existingRunCases.some(
(existingRecord) =>
existingRecord.runId === record.runId &&
existingRecord.caseId === record.caseId
);
});
console.log(recordsToCreateFiltered)
const newRunCases = await RunCase.bulkCreate(
recordsToCreateFiltered.map((record) => ({
runId: record.runId,
caseId: record.caseId,
status: 0,
}))
);
res.json(newRunCases);
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
}
});
return router;
};

View File

@@ -11,6 +11,18 @@ module.exports = function (sequelize) {
const caseId = req.query.caseId;
try {
// Check if the record already exists
const existingRunCase = await RunCase.findOne({
where: {
runId: runId,
caseId: caseId
}
});
if (existingRunCase) {
return res.status(400).send("Record already exists");
}
const newRunCase = await RunCase.create(
{
runId: runId,