Skip to content

Commit

Permalink
add delete todo function
Browse files Browse the repository at this point in the history
  • Loading branch information
ellenlee committed Jun 18, 2020
1 parent c270aa0 commit 56f6b8f
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions routes/modules/todos.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,14 @@ router.put('/:id', (req, res) => {
.catch(error => console.log(error))
})

router.delete('/:id', (req, res) => {
const UserId = req.user.id
const id = req.params.id

return Todo.findOne({ where: { id, UserId } })
.then(todo => todo.destroy())
.then(() => res.redirect('/'))
.catch(error => console.log(error))
})

module.exports = router

0 comments on commit 56f6b8f

Please sign in to comment.