fixed task api route

This commit is contained in:
notnull 2019-07-08 14:43:35 -04:00
parent 7b876caf36
commit 3c09d935e1

View File

@ -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)