Created
February 11, 2020 07:24
-
-
Save mphuget/a1de065302f5ad83a124fb817f806082 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getAllTodos(req, res) { | |
const Todo = require('../../todo/models'); | |
Todo.find({}, function(err, todos) { | |
if (err) throw err; | |
res.json(todos); | |
}); | |
} | |
function getOneTodo(req, res) { | |
const Todo = require('../../todo/models'); | |
Todo.find({_id : req.params.id}, function(err, todo) { | |
if (err) throw err; | |
res.json(todo); | |
}); | |
} | |
function createTodo(req, res) { | |
const Todo = require('../../todo/models'); | |
const newTodo = Todo ({ | |
title: req.body.title, | |
description : req.body.description | |
}); | |
newTodo.save(function(err) { | |
if (err) throw err; | |
res.json({info: 'Success'}); | |
}); | |
} | |
function modifyTodo(req, res) { | |
const Todo = require('../../todo/models'); | |
Todo.findOneAndUpdate( | |
{_id : req.params.id}, | |
{ title: req.body.title, | |
description : req.body.description | |
}, function(err, user) { | |
if (err) throw err; | |
res.json({info: 'Success'}); | |
}); | |
} | |
function deleteTodo(req, res) { | |
const Todo = require('../../todo/models'); | |
Todo.findOneAndRemove( | |
{_id : req.params.id}, function(err, todo) { | |
if (err) throw err; | |
res.json({info: 'Success'}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment