Skip to content

Instantly share code, notes, and snippets.

@mphuget
Created February 11, 2020 07:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mphuget/a1de065302f5ad83a124fb817f806082 to your computer and use it in GitHub Desktop.
Save mphuget/a1de065302f5ad83a124fb817f806082 to your computer and use it in GitHub Desktop.
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