var express = require('express');
var router = express.Router();
var Organization = require('../models/organization/index');

var passport = require('passport');

router.use(passport.authenticate('bearer', { session: false }));

router.route('/organizations')
    .get(function(req, res) {
        Organization.all(function(err, data) {
            if(err) {
                return res.send(500, err);
            }
            return res.send(data);
        });
    })
    .post(function(req, res) {
	req.body.admins = [{user: req.user._id, role: "creator"}]
        Organization.create(req, function(err, newOrganization) {
            if(err) {
                return res.send(500, err);
            }
            return res.json(newOrganization);
        });
    });
router.route('/organizations/:id')
    .put(function(req, res) {
        Organization.put(req, function(err, organization) {
            if(err) {
                res.send(err);
            }
            res.json(organization);
        });
    })
    .get(function(req, res) {
        Organization.get(req.params.id, function(err, organization) {
            if(err) {
                res.send(err);
            }
       		res.json(organization);
        });
    })
    .delete(function(req, res) {
        Organization.delete(req.params.id, function(err) {
            if(err) {
                res.send(err);
            }
            res.json('Deleted!');
        });
    });

module.exports = router;

@@ -118,16 +118,62 @@
 ndex');%0A
+var User = require('./../models/users/index');
 %0Avar pas
@@ -736,32 +736,118 @@
 ;%0A            %7D%0A
+%09    req.user.admin.push(newOrganization._id);%0A%09    req.user.save(function(err,user)%7B%0A
             retu
@@ -868,32 +868,41 @@
 wOrganization);%0A
+%09   %7D);%0A%0A
         %7D);%0A    

add created organization to user