<commit_before>var mongoose = require('mongoose'),
  async = require('async'),
  League = mongoose.model('League'),
  Team = mongoose.model('Team'),
  passport = require('passport');


/**
 * List Leagues
 */
exports.allLeagues = function(req, res){

  League
    .find({})
    .populate('teams')
    .exec(function(err, results){
      res.jsonp(results);
    });

};

/**
 * Get League on any route with LeagueId
 */
exports.getLeague = function (req, res, next, id){

  League
    .findOne({_id: id})
    .populate('teams')
    .exec(function (err, league) {
      if (err) { return next(err); }
      if (!league) { return next(new Error('Failed to load league ' + id)); }

      req.league = league;
      next();
    });

};

/**
 * Show League
 */
exports.showLeague = function(req, res){
  res.jsonp(req.league);
};


/**
 * Create League
 */
exports.createLeague = function (req, res) {

  var newLeague = new League(req.body);
  var teamId = req.body.teamId;

  newLeague.save(function(err) {
    if (err) {return res.json(500, err);}

    //find team record and add league
    Team
      .update({_id: teamId},
      {$push: {leagues: newLeague._id}},
      {multi: false},
      function(err){
        //check for errors
        if (err) {return res.json(400, err);}

        League
          .find({})
          .populate('teams')
          .exec(function(err, results){
            res.jsonp(results);
          });
      });

  });
};


exports.addmessage = function(req, res){

  var leagueId;
  leagueId = req.body.leagueId;

  var teamId;
  teamId = req.body.teamId;

  var chatMessage = {};
  chatMessage.message = req.body.message;
  chatMessage.user = req.user._id;
  chatMessage.name = req.user.name;

//  console.log('user id?: ' + req.user._id);
//  console.log('message?: ' + req.body.message);
//  console.log('leagueId?: ' + leagueId);
  console.log(chatMessage.name);

  //update team and league in parallel
  async.parallel([
      function(callback){

        //find league and add chat
        League
          .update({_id: leagueId},<commit_msg>don't push league into team<commit_after>var mongoose = require('mongoose'),
  async = require('async'),
  League = mongoose.model('League'),
  Team = mongoose.model('Team'),
  passport = require('passport');


/**
 * List Leagues
 */
exports.allLeagues = function(req, res){

  League
    .find({})
    .populate('teams')
    .exec(function(err, results){
      res.jsonp(results);
    });

};

/**
 * Get League on any route with LeagueId
 */
exports.getLeague = function (req, res, next, id){

  League
    .findOne({_id: id})
    .populate('teams')
    .exec(function (err, league) {
      if (err) { return next(err); }
      if (!league) { return next(new Error('Failed to load league ' + id)); }

      req.league = league;
      next();
    });

};

/**
 * Show League
 */
exports.showLeague = function(req, res){
  res.jsonp(req.league);
};


/**
 * Create League
 */
exports.createLeague = function (req, res) {

  var newLeague = new League(req.body);
  //var teamId = req.body.teamId;

  newLeague.save(function(err) {
    if (err) {return res.json(500, err);}

    League
      .find({})
      .populate('teams')
      .exec(function(err, results){
        res.jsonp(results);
      });

  });
};


exports.addmessage = function(req, res){

  var leagueId;
  leagueId = req.body.leagueId;

  var teamId;
  teamId = req.body.teamId;

  var chatMessage = {};
  chatMessage.message = req.body.message;
  chatMessage.user = req.user._id;
  chatMessage.name = req.user.name;

//  console.log('user id?: ' + req.user._id);
//  console.log('message?: ' + req.body.message);
//  console.log('leagueId?: ' + leagueId);
  console.log(chatMessage.name);

  //update team and league in parallel
  async.parallel([
      function(callback){

        //find league and add chat
        League
          .update({_id: leagueId},
{'fraction_non_alphanumeric': 0.16880122950819673, 'fraction_numerical': 0.002305327868852459, 'mean_word_length': 2.7014218009478674, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2195397', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1290, 'n_words': 290}