create cases table
This commit is contained in:
30
backend/routes/cases/index.js
Normal file
30
backend/routes/cases/index.js
Normal file
@@ -0,0 +1,30 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const defineCase = require("../../models/cases");
|
||||
const { DataTypes } = require('sequelize');
|
||||
|
||||
module.exports = function(sequelize) {
|
||||
const Run = defineCase(sequelize, DataTypes)
|
||||
|
||||
router.get("/", async (req, res) => {
|
||||
const { folderId } = req.query;
|
||||
|
||||
if (!folderId) {
|
||||
return res.status(400).json({ error: 'folderId is required' });
|
||||
}
|
||||
|
||||
try {
|
||||
const runs = await Run.findAll({
|
||||
where: {
|
||||
folderId: folderId
|
||||
}
|
||||
});
|
||||
res.json(runs);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
res.status(500).send("Internal Server Error");
|
||||
}
|
||||
});
|
||||
|
||||
return router;
|
||||
};
|
||||
36
backend/routes/cases/new.js
Normal file
36
backend/routes/cases/new.js
Normal file
@@ -0,0 +1,36 @@
|
||||
const express = require("express");
|
||||
const router = express.Router();
|
||||
const defineCase = require("../../models/cases");
|
||||
const { DataTypes } = require("sequelize");
|
||||
|
||||
module.exports = function (sequelize) {
|
||||
const Case = defineCase(sequelize, DataTypes);
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
try {
|
||||
const { title, state, priority, type, automationStatus, description, template, preConditions, expectedResults, folderId } = req.body;
|
||||
if (!title || !state || !priority || !type || !automationStatus || !template || !folderId) {
|
||||
return res.status(400).json({ error: "Title, state, priority, type, automationStatus, template, and folderId are required" });
|
||||
}
|
||||
|
||||
const newCase = await Case.create({
|
||||
title,
|
||||
state,
|
||||
priority,
|
||||
type,
|
||||
automationStatus,
|
||||
description,
|
||||
template,
|
||||
preConditions,
|
||||
expectedResults,
|
||||
folderId,
|
||||
});
|
||||
|
||||
res.json(newCase);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
}
|
||||
});
|
||||
|
||||
return router;
|
||||
};
|
||||
Reference in New Issue
Block a user