From 3c09d935e17c8eed15297cf1df75775e120262b9 Mon Sep 17 00:00:00 2001 From: notnull Date: Mon, 8 Jul 2019 14:43:35 -0400 Subject: [PATCH] fixed task api route --- api/tasks.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/api/tasks.js b/api/tasks.js index a6e5c04..5ac1e7c 100755 --- a/api/tasks.js +++ b/api/tasks.js @@ -4,14 +4,15 @@ module.exports = router /* CREATE */ router.post('/', async (req, res, next) => { - const project = await Project.findOne({ - where: { name: req.body.projectName }, - }) - await console.log('Project\n', project.id) try { const task = await Task.create(req.body) - await task.setProject(project.id) - await console.log('task.projectId:', task.projectId) + + if (req.body.projectId) { + const project = await Project.findOne({ + where: { id: req.body.projectId }, + }) + await task.setProject(project.id) + } res.json(task) } catch (err) { next(err)