'use strict';

var _ = require('lodash');
var tasks = require('../../models/tasks');


module.exports = function (router) {
    router.get('/', function (req, res) {
        tasks.get(function (err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        });
    });

    router.post('/', function(req, res) {
        var newTask = req.body;

        tasks.post(newTask, function (err, results) {
            if (err) {
                res.sendStatus(500);
                throw err;
            }

            res.status(200);
            res.send(results);
        });
    });

    router.get('/:taskID', function(req, res) {

    });

    router.post('/:taskID', function(req, res) {

    });

    router.put('/:taskID', function(req, res) {

    });

    router.delete('/:taskID', function(req, res) {

    });
};

@@ -113,24 +113,381 @@
  (router) %7B%0A
+    var onTaskPostOrPut = function(req, res) %7B%0A        var taskID = req.params.taskID;%0A        var task = req.body;%0A%0A        tasks.put(taskID, task, function (err, results) %7B%0A            if (err) %7B%0A                res.sendStatus(500);%0A                throw err;%0A            %7D%0A%0A            res.status(200);%0A            res.send(results);%0A        %7D);%0A    %7D;%0A%0A
     router.g
@@ -1107,44 +1107,73 @@
 ) %7B%0A
-%0A
     
-%7D);%0A%0A    router.post('/:
+    var taskID = req.params.taskID;%0A%0A        tasks.get(
 taskID
-'
 , fu
@@ -1182,45 +1182,318 @@
 tion
-(req, res) %7B%0A%0A    %7D);%0A%0A    router.put
+ (err, results) %7B%0A            if (err) %7B%0A                res.sendStatus(500);%0A                throw err;%0A            %7D%0A%0A            res.status(200);%0A            res.send(results);%0A        %7D)%0A    %7D);%0A%0A    router.post('/:taskID', onTaskPostOrPut);%0A%0A    router.put('/:taskID', onTaskPostOrPut);%0A%0A    router.delete
 ('/:
@@ -1526,36 +1526,70 @@
 ) %7B%0A
-%0A
     
-%7D);%0A%0A    router
+    var taskID = req.params.taskID;%0A%0A        tasks
 .delete(
 '/:t
@@ -1580,34 +1580,30 @@
 asks.delete(
-'/:
 taskID
-'
 , function(r
@@ -1601,28 +1601,205 @@
 unction(
-req
+err
 , res
-) %7B%0A
+ults) %7B%0A            if (err) %7B%0A                res.sendStatus(500);%0A                throw err;%0A            %7D%0A%0A            res.status(200);%0A            res.send(results);%0A        %7D);
 %0A    %7D);

add REST calls for /tasks/:taskID endpoint