diff --git a/lib/routes/api/v2/projects/index.js b/lib/routes/api/v2/projects/index.js index ca3e8d98..5a3ce0ea 100644 --- a/lib/routes/api/v2/projects/index.js +++ b/lib/routes/api/v2/projects/index.js @@ -78,6 +78,16 @@ var canCreateProject = function(req, res, next){ }; +var validateProject = function(project) { + if (!project.title){ + return { error: "title_required" }; + } + + if (!project.description){ + return { error: "description_required" }; + } +} + var createProject = function(req, res, next){ if(req.body.link && req.body.link.indexOf('http') != 0) { @@ -103,12 +113,9 @@ var createProject = function(req, res, next){ , domain: req.body.domain }); - if (!project.title){ - return res.json(500, { error: "title_required" }); - } - - if (!project.description){ - return res.json(500, { error: "description_required" }); + var err = validateProject(project); + if (err) { + return res.json(500, err); } project.save(function(err, project){ @@ -180,12 +187,9 @@ var updateProject = function(req, res, next) { //add trim - if (!project.title){ - return res.json(500, { error: "title_required" }); - } - - if (!project.description){ - return res.json(500, { error: "description_required" }); + var err = validateProject(project); + if (err) { + return res.json(500, err); } project.save(function(err, project){