Skip to content

Instantly share code, notes, and snippets.

@funador
Created January 20, 2019 19:17
Show Gist options
  • Save funador/301290299530e552b43b34a2d09b669a to your computer and use it in GitHub Desktop.
Save funador/301290299530e552b43b34a2d09b669a to your computer and use it in GitHub Desktop.
const Todo = require('./model')
exports.addTodo = (req, res) => {
Todo
.create(req.body)
.then(todo => {
res.json(todo)
})
}
exports.getTodos = (req, res) => {
Todo
.find()
.then(todos => {
res.json(todos)
})
}
exports.deleteTodo = (req, res) => {
Todo
.findByIdAndRemove(req.params.id)
.then(todo => {
res.json({id: todo._id})
})
}
exports.updateTodo = (req, res) => {
Todo.
findByIdAndUpdate(req.params.id, req.body, {new: true})
.then(todo => {
res.json(todo)
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment