From 5f415bb23ea6b6406a8ea400def42545c667edbc Mon Sep 17 00:00:00 2001 From: notnull Date: Sun, 23 Jun 2019 06:31:17 -0400 Subject: [PATCH] updated create and destroy routes --- api/projects.js | 11 ++++++++--- api/tasks.js | 3 +-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/api/projects.js b/api/projects.js index 09b0c2f..dc85907 100644 --- a/api/projects.js +++ b/api/projects.js @@ -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) diff --git a/api/tasks.js b/api/tasks.js index 0e2f170..a6e5c04 100755 --- a/api/tasks.js +++ b/api/tasks.js @@ -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)