delete project

This commit is contained in:
Takeshi Kimata
2024-02-18 11:06:02 +09:00
parent d752b4a3b0
commit a44c50df29
5 changed files with 133 additions and 27 deletions

View File

@@ -0,0 +1,29 @@
const express = require("express");
const router = express.Router();
const defineProject = require("../../models/projects");
const { DataTypes } = require("sequelize");
module.exports = function (sequelize) {
const Project = defineProject(sequelize, DataTypes);
router.delete("/:projectId", async (req, res) => {
const projectId = req.params.projectId;
try {
const project = await Project.findOne({
where: {
id: projectId,
},
});
if (!project) {
return res.status(404).send("Project not found");
}
await project.destroy();
res.status(204).send();
} catch (error) {
console.error(error);
res.status(500).send("Internal Server Error");
}
});
return router;
};