var express = require('express');
var router = express.Router();

var users = require('./api/user');
var projects = require('./api/project');
var auth = require('../controllers/auth');

function isIdValid(id) {
  return id.match(/^[0-9a-fA-F]{24}$/);
}

router.route('/authenticate')
  .get(auth.authenticate, function(req, res, next) {
    users.getUserByName(req, res, req.user.username, next);
  });

/* User routes */
router.route('/users')
  .post(function(req, res, next) {
    users.addUser(req, res, next)
  })
  .get(function(req, res, next) {
    users.getUsers(req, res, next)
  });

/* Single user routes */
router.route('/users/:user_id')
  .get(function(req, res, next) {
    if (!isIdValid(req.params.user_id)) return res.sendStatus(404);
    users.getUser(req, res, req.params.user_id, next)
  })
  .put(auth.authenticate, function(req, res, next) {
    if (!isIdValid(req.params.user_id)) return res.sendStatus(404);
    users.updateUser(req, res, req.params.user_id, next)
  })
  .delete(auth.authenticate, function(req, res, next) {
    if (!isIdValid(req.params.user_id)) return res.sendStatus(404);
    users.deleteUser(req, res, req.params.user_id, next)
  });

/* Project routes */
router.route('/projects')
  .post(auth.authenticate, function(req, res, next) {
    projects.addProject(req,res, next)
  })
  .get(auth.authenticate, function(req, res, next) {
    projects.getProjects(req,res, next)
  });

/* Single project routes */
router.route('/projects/:project_id')
  .get(auth.authenticate, function(req, res, next) {
    if (!isIdValid(req.params.project_id)) return res.sendStatus(404);
    projects.getProject(req, res, req.params.project_id, next)
  })
  .put(auth.authenticate, function(req, res, next) {
    if (!isIdValid(req.params.project_id)) return res.sendStatus(404);
    projects.updateProject(req, res, req.params.project_id, next)
  })
  .delete(auth.authenticate, function(req, res, next) {
    if (!isIdValid(req.params.project_id)) return res.sendStatus(404);
    projects.deleteProject(req, res, req.params.project_id, next)
  });

router.route('/projects/:project_id/join')
  .post(auth.authenticate, function(req, res, next) {
    if (!isIdValid(req.params.project_id)) return res.sendStatus(404);
    projects.joinProject(req, res, req.params.project_id, next)
  });

router.route('/projects/:project_id/leave')
  .delete(auth.authenticate, function(req,res, next) {
    if (!isIdValid(req.params.project_id)) return res.sendStatus(404);
    projects.leaveProject(req, res, req.params.project_id, next)
  });

module.exports = router;


@@ -498,33 +498,34 @@
 (req, res, next)
+;
 %0A
-
   %7D)%0A  .get(func
@@ -573,32 +573,33 @@
 (req, res, next)
+;
 %0A  %7D);%0A%0A/* Singl
@@ -794,32 +794,33 @@
 s.user_id, next)
+;
 %0A  %7D)%0A  .put(aut
@@ -978,32 +978,33 @@
 s.user_id, next)
+;
 %0A  %7D)%0A  .delete(
@@ -1165,32 +1165,33 @@
 s.user_id, next)
+;
 %0A  %7D);%0A%0A/* Proje
@@ -1307,24 +1307,25 @@
 Project(req,
+ 
 res, next)%0A 
@@ -1318,24 +1318,25 @@
 , res, next)
+;
 %0A  %7D)%0A  .get
@@ -1407,24 +1407,25 @@
 rojects(req,
+ 
 res, next)%0A 
@@ -1418,24 +1418,25 @@
 , res, next)
+;
 %0A  %7D);%0A%0A/* S
@@ -1675,32 +1675,33 @@
 roject_id, next)
+;
 %0A  %7D)%0A  .put(aut
@@ -1875,24 +1875,25 @@
 ct_id, next)
+;
 %0A  %7D)%0A  .del
@@ -2070,32 +2070,33 @@
 roject_id, next)
+;
 %0A  %7D);%0A%0Arouter.r
@@ -2247,32 +2247,32 @@
 endStatus(404);%0A
-
     projects.joi
@@ -2310,32 +2310,33 @@
 roject_id, next)
+;
 %0A  %7D);%0A%0Arouter.r

add some semicolons