Skip to content

Commit

Permalink
add delete todo function
Browse files Browse the repository at this point in the history
  • Loading branch information
ellenlee authored and Carrot7712 committed Sep 10, 2020
1 parent 38716fe commit cbada51
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 cbada51

Please sign in to comment.