Skip to content

Instantly share code, notes, and snippets.

@mattLummus
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattLummus/9555868 to your computer and use it in GitHub Desktop.
Save mattLummus/9555868 to your computer and use it in GitHub Desktop.
DB population for teams in Find My Fans project
//admin.js (browser)
Team.requestInfo(sport, fn){
//calls ESPN for [team objects] by sport
fn(record)
}
//teams.js (routes)
Team.pullData(data, sport, leagueName, leagueShortName){
var object = {};
object._id = data.uid //ONLY IF APPLICABLE! DECIDE LATER!
object.name = data.name;
object.sportName = sport;
object.leagueShortName = leagueShortName;
object.leagueName = leagueName;
object.city = data.location;
object.color = data.color;
object.schedule = []; //WATCH FOR BUGS LATER!
Team.create(object);
}
Team.populate(sport)
Team.requestInfo(sport, function(record){
var leagueName = sport.leagues[0].name;
var leagueShortName = sport.leagues[0].shortName;
var teams = record.sports[0].leagues[0].teams;
for(var i=0; i<teams.length; i++){
team.pullData(teams[i], sport, leagueName, leagueShortName);
}
});
}
//team.js (models)
Team.create(object, function(){
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment