Cretate delete project confirm dialog
This commit is contained in:
@@ -25,7 +25,7 @@ module.exports = {
|
|||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
references: {
|
references: {
|
||||||
model: 'Projects',
|
model: 'projects',
|
||||||
key: 'id',
|
key: 'id',
|
||||||
onDelete: 'CASCADE',
|
onDelete: 'CASCADE',
|
||||||
onUpdate: 'CASCADE',
|
onUpdate: 'CASCADE',
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ module.exports = {
|
|||||||
type: Sequelize.INTEGER,
|
type: Sequelize.INTEGER,
|
||||||
allowNull: false,
|
allowNull: false,
|
||||||
references: {
|
references: {
|
||||||
model: 'Projects',
|
model: 'projects',
|
||||||
key: 'id',
|
key: 'id',
|
||||||
},
|
},
|
||||||
onUpdate: 'CASCADE',
|
onUpdate: 'CASCADE',
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ function defineFolder(sequelize, DataTypes) {
|
|||||||
|
|
||||||
Folder.associate = (models) => {
|
Folder.associate = (models) => {
|
||||||
Folder.belongsTo(models.Project, { foreignKey: 'projectId', onDelete: 'CASCADE' });
|
Folder.belongsTo(models.Project, { foreignKey: 'projectId', onDelete: 'CASCADE' });
|
||||||
|
Folder.hasMany(models.Case, { foreignKey: 'folderId' });
|
||||||
};
|
};
|
||||||
|
|
||||||
return Folder;
|
return Folder;
|
||||||
|
|||||||
@@ -24,7 +24,9 @@ function defineProject(sequelize, DataTypes) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
Project.associate = (models) => {
|
Project.associate = (models) => {
|
||||||
Project.hasMany(models.Folder, { foreignKey: 'projectId' });
|
Project.belongsTo(models.User, { foreignKey: 'userId', onDelete: 'CASCADE' });
|
||||||
|
Project.hasMany(models.Folder, { foreignKey: 'projectId', onDelete: 'CASCADE' });
|
||||||
|
Project.hasMany(models.Run, { foreignKey: 'projectId', onDelete: 'CASCADE' });
|
||||||
};
|
};
|
||||||
|
|
||||||
return Project;
|
return Project;
|
||||||
|
|||||||
@@ -1,23 +1,37 @@
|
|||||||
const express = require('express');
|
const express = require('express');
|
||||||
const router = express.Router();
|
const router = express.Router();
|
||||||
const defineProject = require('../../models/projects');
|
const defineProject = require('../../models/projects');
|
||||||
|
const defineFolder = require('../../models/folders');
|
||||||
|
const defineRun = require('../../models/runs');
|
||||||
const { DataTypes } = require('sequelize');
|
const { DataTypes } = require('sequelize');
|
||||||
|
|
||||||
module.exports = function (sequelize) {
|
module.exports = function (sequelize) {
|
||||||
const { verifySignedIn, verifyProjectOwner } = require('../../middleware/auth')(sequelize);
|
const { verifySignedIn, verifyProjectOwner } = require('../../middleware/auth')(sequelize);
|
||||||
const Project = defineProject(sequelize, DataTypes);
|
const Project = defineProject(sequelize, DataTypes);
|
||||||
|
const Folder = defineFolder(sequelize, DataTypes);
|
||||||
|
const Run = defineRun(sequelize, DataTypes);
|
||||||
|
|
||||||
router.delete('/:projectId', verifySignedIn, verifyProjectOwner, async (req, res) => {
|
router.delete('/:projectId', verifySignedIn, verifyProjectOwner, async (req, res) => {
|
||||||
const projectId = req.params.projectId;
|
const projectId = req.params.projectId;
|
||||||
|
const t = await sequelize.transaction();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const project = await Project.findByPk(projectId);
|
const project = await Project.findByPk(projectId);
|
||||||
if (!project) {
|
if (!project) {
|
||||||
|
await t.rollback();
|
||||||
return res.status(404).send('Project not found');
|
return res.status(404).send('Project not found');
|
||||||
}
|
}
|
||||||
await project.destroy();
|
|
||||||
|
await Folder.destroy({ where: { projectId: projectId }, transaction: t });
|
||||||
|
await Run.destroy({ where: { projectId: projectId }, transaction: t });
|
||||||
|
|
||||||
|
await project.destroy({ transaction: t });
|
||||||
|
|
||||||
|
await t.commit();
|
||||||
res.status(204).send();
|
res.status(204).send();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
await t.rollback();
|
||||||
res.status(500).send('Internal Server Error');
|
res.status(500).send('Internal Server Error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ module.exports = {
|
|||||||
const hashedPassword = await bcrypt.hash('password', 10);
|
const hashedPassword = await bcrypt.hash('password', 10);
|
||||||
|
|
||||||
// Add projects table records
|
// Add projects table records
|
||||||
await queryInterface.bulkInsert('Users', [
|
await queryInterface.bulkInsert('users', [
|
||||||
{
|
{
|
||||||
email: 'admin@testplat.com',
|
email: 'admin@testplat.com',
|
||||||
password: hashedPassword,
|
password: hashedPassword,
|
||||||
@@ -20,7 +20,7 @@ module.exports = {
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
// Add projects table records
|
// Add projects table records
|
||||||
await queryInterface.bulkInsert('Projects', [
|
await queryInterface.bulkInsert('projects', [
|
||||||
{
|
{
|
||||||
name: 'TestPlat Test',
|
name: 'TestPlat Test',
|
||||||
detail: "Test Plat's Manual test",
|
detail: "Test Plat's Manual test",
|
||||||
|
|||||||
@@ -72,9 +72,9 @@ const TokenProvider = ({ locale, children }: TokenProps) => {
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// check current path is private. pravate path is '/account/*' or '/projects/*'
|
// check current path is private. pravate path is '/account' or '/projects/*'
|
||||||
const isPrivatePath = (pathname: string) => {
|
const isPrivatePath = (pathname: string) => {
|
||||||
return /^\/(account|projects)\/.*/.test(pathname);
|
return /^\/account(\/)?$/.test(pathname) || /^\/projects(\/)?$/.test(pathname);
|
||||||
};
|
};
|
||||||
|
|
||||||
const checkSignInPage = () => {
|
const checkSignInPage = () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user