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