updated create and destroy routes
This commit is contained in:
parent
80ad0c3261
commit
5f415bb23e
@ -1,5 +1,5 @@
|
|||||||
const router = require('express').Router()
|
const router = require('express').Router()
|
||||||
const { Project } = require('../db/models')
|
const { Project, Task } = require('../db/models')
|
||||||
module.exports = router
|
module.exports = router
|
||||||
|
|
||||||
/* CREATE */
|
/* CREATE */
|
||||||
@ -35,7 +35,7 @@ router.get('/:id', async (req, res, next) => {
|
|||||||
router.put('/:id', async (req, res, next) => {
|
router.put('/:id', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const project = await Project.findByPk(req.params.id)
|
const project = await Project.findByPk(req.params.id)
|
||||||
await project.update({ name: req.body.name })
|
await project.update(req.body)
|
||||||
res.json(project)
|
res.json(project)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err)
|
next(err)
|
||||||
@ -46,7 +46,12 @@ router.put('/:id', async (req, res, next) => {
|
|||||||
router.post('/:id/delete', async (req, res, next) => {
|
router.post('/:id/delete', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const project = await Project.findByPk(req.params.id)
|
const project = await Project.findByPk(req.params.id)
|
||||||
project.destroy()
|
project.destroy({ force: true })
|
||||||
|
await Task.destroy({
|
||||||
|
where: {
|
||||||
|
projectId: req.params.id,
|
||||||
|
},
|
||||||
|
})
|
||||||
res.json(project)
|
res.json(project)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err)
|
next(err)
|
||||||
|
@ -4,7 +4,6 @@ module.exports = router
|
|||||||
|
|
||||||
/* CREATE */
|
/* CREATE */
|
||||||
router.post('/', async (req, res, next) => {
|
router.post('/', async (req, res, next) => {
|
||||||
console.log(req.body)
|
|
||||||
const project = await Project.findOne({
|
const project = await Project.findOne({
|
||||||
where: { name: req.body.projectName },
|
where: { name: req.body.projectName },
|
||||||
})
|
})
|
||||||
@ -42,7 +41,7 @@ router.get('/:id', async (req, res, next) => {
|
|||||||
router.put('/:id', async (req, res, next) => {
|
router.put('/:id', async (req, res, next) => {
|
||||||
try {
|
try {
|
||||||
const task = await Task.findByPk(req.params.id)
|
const task = await Task.findByPk(req.params.id)
|
||||||
await task.update({ name: req.body.name })
|
await task.update(req.body)
|
||||||
res.json(task)
|
res.json(task)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
next(err)
|
next(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user