<commit_before>var _ = require('lodash');
var players = require("./players");
var teams = require("./teams");

var ROOT = {id:"ROOT"}
var doBuildTeamPlayersMap = function(parentTeams, existingPlayers, cb) {
    var hashOfPlayers = _.reduce(existingPlayers,
        function(memo, item) {
            memo[item._team] = memo[item._team] || []
            memo[item._team].push({name:item.name});
            return memo;
        }, {});

    var buildNode = function(teams){
        return  _.map(teams, function(team){
            
            var result = {
                team: team.name,
            players: hashOfPlayers[team._id] || []
            };
            if(!_.isEmpty(team.children))
                result.subTeams = buildNode(team.children);
            return result;
        });
    };

    var result = buildNode(parentTeams);

    if (hashOfPlayers[undefined]) {
        result.push({'team': undefined, players : hashOfPlayers[undefined]});
    }

    cb(result);
};


exports.buildTeamPlayersMap = function(callbackWithResult) {
    var found = {};
    var promise = teams.Team.find({parent:null}).exec();

    promise = promise.then(function(foundTeams){
        found.teams = foundTeams;
        return  players.Player.find({}).exec(); 
    }); 
    promise.then(function(foundPlayers){
        found.players = foundPlayers;
        teams.Team.getChildrenTree(function(err, fullTree){
                doBuildTeamPlayersMap(fullTree, found.players, callbackWithResult);
        });
    });    
};
<commit_msg>removing superfluous lines<commit_after>var _ = require('lodash');
var players = require("./players");
var teams = require("./teams");

var ROOT = {id:"ROOT"}
var doBuildTeamPlayersMap = function(parentTeams, existingPlayers, cb) {
    var hashOfPlayers = _.reduce(existingPlayers,
        function(memo, item) {
            memo[item._team] = memo[item._team] || []
            memo[item._team].push({name:item.name});
            return memo;
        }, {});

    var buildNode = function(teams){
        return  _.map(teams, function(team){

            var result = {
                team: team.name,
            players: hashOfPlayers[team._id] || []
            };
            if(!_.isEmpty(team.children))
                result.subTeams = buildNode(team.children);
            return result;
        });
    };

    var result = buildNode(parentTeams);

    if (hashOfPlayers[undefined]) {
        result.push({'team': undefined, players : hashOfPlayers[undefined]});
    }

    cb(result);
};


exports.buildTeamPlayersMap = function(callbackWithResult) {
    players.Player.find({}).exec().then(function(foundPlayers){
      teams.Team.getChildrenTree(function(err, fullTree){
      doBuildTeamPlayersMap(fullTree, foundPlayers, callbackWithResult);
    });
  });
};

{'fraction_non_alphanumeric': 0.14341637010676156, 'fraction_numerical': 0.0, 'mean_word_length': 2.51375, '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': '7216669', 'n_tokens_mistral': 837, 'n_tokens_neox': 805, 'n_words': 137}