var Project = require('../models/project');
var express = require('express');
var router = express.Router();

router.route('/projects').post(createProject);
router.route('/projects').get(getProjects);
router.route('/projects/:project_id').get(getProject);
router.route('/projects/:project_id').put(editProject);
router.route('/projects/:project_id').delete(deleteProject);

module.exports = router;

function createProject(req, res)
{        
    var project = new Project();
    
    if (!("name" in req.body)){
        res.json({message : "Error : No name given !"});
        return ;
    }
    else
        project.name = req.body.name;

    project.save(function(err)
    {
        if (err) res.send(err);
        res.json({ message: 'Project created !' });
    });
}

function getProjects(req, res)
{
    Project.find(function(err, projects)
    {
        if (err) res.send(err);
        res.json(projects);
    });
}

function getProject(req, res)
{
    Project.findById(req.params.project_id, function(err, project)
    {
        if (err) res.send(err);
        res.json(project);
    });
}

function editProject(req, res)
{
    // use our bear model to find the bear we want
    Project.findById(req.params.project_id, function(err, project)
    {
        if (err) res.send(err);
        project.name = req.body.name;  // update the bears info

        // save the bear
        project.save(function(err)
        {
            if (err) res.send(err);
            res.json({ message: 'Project updated!' });
        });

    });
}
function deleteProject(req, res)
{
    Project.remove({_id: req.params.project_id}, function(err, project)
    {
        if (err) res.send(err);
        res.json({ message: 'Project deleted!' });
    });
}
@@ -33,24 +33,62 @@
 /project');%0A
+var User = require('../models/user');%0A
 var express 
@@ -105,24 +105,24 @@
 'express');%0A
-
 var router =
@@ -623,20 +623,16 @@
  ;%0A    %7D
-%0A   
  else%0A  
@@ -671,46 +671,661 @@
 me;%0A
+    
 %0A    
-project.save(function(err)%0A    %7B%0A
+if (!(%22type%22 in req.body))%7B%0A        res.json(%7Bmessage : %22Error : No type given !%22%7D);%0A        return ;%0A    %7D else%0A        project.type = req.body.type;%0A    %0A    if (!(%22author_id%22 in req.body))%7B%0A        res.json(%7Bmessage : %22Error : No author_id given !%22%7D);%0A        return ;%0A    %7D%0A    else %7B%0A        User.findOne(%7Busername : req.body.author_id%7D, function(err, user)%7B%0A            if (err) %7B%0A                res.send(err);%0A            %7D else if (user === null)%7B%0A                res.send(%7Bmessage : %22Error : author_id not found !%22%7D);%0A            %7D else %7B%0A                project.author = user;%0A                project.save(function(err)%7B%0A            
     
@@ -1344,32 +1344,44 @@
  res.send(err);%0A
+            
         res.json
@@ -1416,27 +1416,71 @@
  !' %7D);%0A    
-%7D);
+            %7D);%0A            %7D%0A        %7D);%0A    %7D
 %0A%7D%0A%0Afunction

Add checking parameters during creation