const Task = require('./task.model');

exports.createTask = (req, res, next) => {
    Task.create(req.body)
        .then( task => res.status(201).json(task) )
        .catch( err => res.status(404).json(err) );
};

exports.deleteTask = (req, res, next) => {
    let id = req.params.id;
    Task.findByIdAndRemove(id)
        .then( task => res.status(201).json(task) )
        .catch( err => res.status(404).json(err) );
};

exports.getTaskById = (req, res, next) => {
    let id = req.params.id;
    Task.findById(id)
        .then( task => res.status(200).json(task) )
        .catch( err => res.status(404).json(err) );
};

exports.getTasks = (req, res, next) => {
    Task.find()
        .then( tasks => res.status(200).json(tasks) )
        .catch( err => res.status(404).json(err) );
};

exports.updateTask = (req, res, next) => {
    let id = req.params.id;
    let body = req.body;
    Task.findByIdAndUpdate(id, body)
        .then( task => res.status(200).json(task) )
        .catch( err => res.status(404).json(err) );
};

@@ -884,16 +884,47 @@
 q.body;%0A
+    let options = %7Bnew: true%7D;%0A
     Task
@@ -946,24 +946,33 @@
 ate(id, body
+, options
 )%0A        .t

return the modified data