var express = require('express');
var bodyParser = require('body-parser');

var leaderRouter = express.Router();
leaderRouter.use(bodyParser.json());

leaderRouter.route('/')
    .all(function(req,res,next) {
          res.writeHead(200, { 'Content-Type': 'text/plain' });
          next();
    })

    .get(function(req,res,next){
            res.end('Will send all the leaders to you!');
    })

    .post(function(req, res, next){
        res.end('Will add the leader: ' + req.body.name + ' with details: ' + req.body.description);
    })

    .delete(function(req, res, next){
            res.end('Deleting all leaders');
    });

leaderRouter.route('/:leaderId')
    .all(function(req,res,next) {
          res.writeHead(200, { 'Content-Type': 'text/plain' });
          next();
    })

    .get(function(req,res,next){
            res.end('Will send details of the leader: ' + req.params.leaderId +' to you!');
    })

    .put(function(req, res, next){
            res.write('Updating the leader: ' + req.params.leaderId + '\n');
        res.end('Will update the leader: ' + req.body.name +
                ' with details: ' + req.body.description);
    })

    .delete(function(req, res, next){
            res.end('Deleting leader: ' + req.params.leaderId);
    });

module.exports = leaderRouter;

@@ -67,16 +67,100 @@
 arser');
+%0Avar mongoose = require('mongoose');%0A%0Avar Leaders = require('../models/leadership');
 %0A%0Avar le
@@ -252,24 +252,20 @@
 te('/')%0A
-    .all
+.get
 (functio
@@ -261,33 +261,36 @@
 get(function
+ 
 (req,
+ 
 res,
+ 
 next) %7B%0A    
@@ -293,101 +293,116 @@
     
-      res.writeHead(200, %7B 'Content-Type': 'text/plain' %7D);%0A          next();%0A    %7D)%0A%0A    .ge
+Leaders.find(%7B%7D, function (err, dish) %7B%0A        if (err) throw err;%0A        res.json(dish);%0A    %7D);%0A%7D)%0A%0A.pos
 t(fu
@@ -411,77 +411,143 @@
 tion
+ 
 (req,
+ 
 res,
+ 
 next)
+ 
 %7B%0A    
-        res.end('Will send all the leaders to you
+Leaders.create(req.body, function (err, dish) %7B%0A        if (err) throw err;%0A        console.log('Leader created
 !');
@@ -555,47 +555,115 @@
     
+   
-%7D)%0A%0A    .post(function(req, res, next)%7B
+ var id = Leader._id;%0A%0A        res.writeHead(200, %7B%0A            'Content-Type': 'text/plain'%0A        %7D);
 %0A   
@@ -680,89 +680,40 @@
 nd('
-Will ad
+Adde
 d the 
-l
+L
 eader
-: ' + req.body.name + ' with details: ' + req.body.description
+ with id: ' + id
 );%0A 
@@ -709,38 +709,38 @@
  ' + id);%0A    %7D)
-%0A%0A    
+;%0A%7D)%0A%0A
 .delete(function
@@ -731,32 +731,33 @@
 .delete(function
+ 
 (req, res, next)
@@ -760,52 +760,106 @@
 ext)
+ 
 %7B%0A    
-        res.end('Deleting all leaders'
+Leaders.remove(%7B%7D, function (err, resp) %7B%0A        if (err) throw err;%0A        res.json(resp
 );%0A 
@@ -865,23 +865,25 @@
     %7D);%0A
-%0Aleader
+%7D);%0A%0Adish
 Router.r
@@ -894,27 +894,21 @@
 ('/:
-leaderId')%0A    .all
+dishId')%0A.get
 (fun
@@ -908,33 +908,36 @@
 get(function
+ 
 (req,
+ 
 res,
+ 
 next) %7B%0A    
@@ -940,216 +940,122 @@
     
-   
-   res.writeHead(200, %7B 'Content-Type': 'text/plain' %7D);%0A          next();%0A    %7D)%0A%0A    .get(function(req,res,next)%7B%0A            res.end('Will send details of the leader: ' + req.params.leaderId +' to you!'
+Leaders.findById(req.params.LeaderId, function (err, leader) %7B%0A        if (err) throw err;%0A        res.json(leader
 );%0A 
@@ -1059,22 +1059,22 @@
 ;%0A    %7D)
-%0A%0A    
+;%0A%7D)%0A%0A
 .put(fun
@@ -1070,32 +1070,33 @@
 )%0A%0A.put(function
+ 
 (req, res, next)
@@ -1099,204 +1099,197 @@
 ext)
+ 
 %7B%0A    
-        res.write('Updating the leader: ' + req.params.leaderId + '%5Cn');%0A        res.end('Will update the leader: ' + req.body.name +%0A                ' with details: ' + req.body.description
+Leaders.findByIdAndUpdate(req.params.leaderId, %7B%0A        $set: req.body%0A    %7D, %7B%0A        new: true%0A    %7D, function (err, leader) %7B%0A        if (err) throw err;%0A        res.json(leader
 );%0A 
@@ -1293,22 +1293,22 @@
 ;%0A    %7D)
-%0A%0A    
+;%0A%7D)%0A%0A
 .delete(
@@ -1315,16 +1315,17 @@
 function
+ 
 (req, re
@@ -1336,71 +1336,133 @@
 ext)
+ 
 %7B%0A    
-        res.end('Deleting leader: ' + req.params.leaderId
+Leaders.findByIdAndRemove(req.params.leaderId, function (err, resp) %7B        if (err) throw err;%0A        res.json(resp
 );%0A 
@@ -1467,16 +1467,20 @@
 %0A    %7D);
+%0A%7D);
 %0A%0Amodule

update leader to use mongoose