create cases table
This commit is contained in:
@@ -41,6 +41,12 @@ const runsNewRoute = require('./routes/runs/new')(sequelize);
|
||||
app.use('/runs', runsIndexRoute);
|
||||
app.use('/runs', runsNewRoute);
|
||||
|
||||
// "/cases"
|
||||
const casesIndexRoute = require('./routes/cases/index')(sequelize);
|
||||
const casesNewRoute = require('./routes/cases/new')(sequelize);
|
||||
app.use('/cases', casesIndexRoute);
|
||||
app.use('/cases', casesNewRoute);
|
||||
|
||||
const PORT = process.env.PORT || 3001;
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server is running on port ${PORT}`);
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
up: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.createTable('Projects', {
|
||||
await queryInterface.createTable('projects', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
@@ -29,6 +29,6 @@ module.exports = {
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
await queryInterface.dropTable('Projects');
|
||||
await queryInterface.dropTable('projects');
|
||||
},
|
||||
};
|
||||
72
backend/migrations/20240212084228-create-cases.js
Normal file
72
backend/migrations/20240212084228-create-cases.js
Normal file
@@ -0,0 +1,72 @@
|
||||
'use strict';
|
||||
|
||||
/** @type {import('sequelize-cli').Migration} */
|
||||
module.exports = {
|
||||
async up (queryInterface, Sequelize) {
|
||||
await queryInterface.createTable('cases', {
|
||||
id: {
|
||||
type: Sequelize.INTEGER,
|
||||
primaryKey: true,
|
||||
autoIncrement: true,
|
||||
},
|
||||
folderId: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'folders',
|
||||
key: 'id',
|
||||
},
|
||||
onUpdate: 'CASCADE',
|
||||
onDelete: 'CASCADE',
|
||||
},
|
||||
title: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
state: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
priority: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
type: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
automationStatus: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
description: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
template: {
|
||||
type: Sequelize.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
preConditions: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
expectedResults: {
|
||||
type: Sequelize.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
createdAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
},
|
||||
updatedAt: {
|
||||
allowNull: false,
|
||||
type: Sequelize.DATE
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
async down (queryInterface, Sequelize) {
|
||||
await queryInterface.dropTable('cases');
|
||||
}
|
||||
};
|
||||
57
backend/models/cases.js
Normal file
57
backend/models/cases.js
Normal file
@@ -0,0 +1,57 @@
|
||||
function defineCase(sequelize, DataTypes) {
|
||||
const Case = sequelize.define('Case', {
|
||||
title: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
state: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
priority: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
type: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
automationStatus: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
description: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
template: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
preConditions: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
expectedResults: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: true,
|
||||
},
|
||||
folderId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'folder',
|
||||
key: 'id'
|
||||
},
|
||||
onDelete: 'CASCADE'
|
||||
}
|
||||
});
|
||||
|
||||
Case.associate = (models) => {
|
||||
Case.belongsTo(models.folder, { foreignKey: 'folderId', onDelete: 'CASCADE' });
|
||||
};
|
||||
|
||||
return Case;
|
||||
}
|
||||
|
||||
module.exports = defineCase;
|
||||
@@ -15,9 +15,18 @@ function defineFolder(sequelize, DataTypes) {
|
||||
projectId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'project',
|
||||
key: 'id'
|
||||
},
|
||||
onDelete: 'CASCADE'
|
||||
}
|
||||
});
|
||||
|
||||
Folder.associate = (models) => {
|
||||
Folder.belongsTo(models.Project, { foreignKey: 'projectId', onDelete: 'CASCADE' });
|
||||
};
|
||||
|
||||
return Folder;
|
||||
}
|
||||
|
||||
|
||||
@@ -19,9 +19,18 @@ function defineRun(sequelize, DataTypes) {
|
||||
projectId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
references: {
|
||||
model: 'project',
|
||||
key: 'id'
|
||||
},
|
||||
onDelete: 'CASCADE'
|
||||
}
|
||||
});
|
||||
|
||||
Run.associate = (models) => {
|
||||
Run.belongsTo(models.Project, { foreignKey: 'projectId', onDelete: 'CASCADE' });
|
||||
};
|
||||
|
||||
return Run;
|
||||
}
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
@@ -75,6 +75,38 @@ module.exports = {
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
]);
|
||||
|
||||
// Add cases table records
|
||||
await queryInterface.bulkInsert('cases', [
|
||||
{
|
||||
title: 'Sample Case 1',
|
||||
state: 1,
|
||||
priority: 1,
|
||||
type: 1,
|
||||
automationStatus: 1,
|
||||
description: 'Sample description for case 1',
|
||||
template: 1,
|
||||
preConditions: 'Sample pre-conditions for case 1',
|
||||
expectedResults: 'Sample expected results for case 1',
|
||||
folderId: 1,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
{
|
||||
title: 'Sample Case 2',
|
||||
state: 1,
|
||||
priority: 1,
|
||||
type: 1,
|
||||
automationStatus: 1,
|
||||
description: 'Sample description for case 2',
|
||||
template: 1,
|
||||
preConditions: 'Sample pre-conditions for case 2',
|
||||
expectedResults: 'Sample expected results for case 2',
|
||||
folderId: 1,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
},
|
||||
]);
|
||||
},
|
||||
|
||||
down: async (queryInterface, Sequelize) => {
|
||||
|
||||
Reference in New Issue
Block a user