@@ -41,22 +41,31 @@ app.get('/api/mlb/scores/:dt', (req, res) => {
4141
4242app . get ( '/api/nba/scores/:dt' , ( req , res ) => {
4343 const { dt } = req . params
44- const url = `http://data.nba.com/data/5s/json/cms/noseason/scoreboard/${ dt } /games.json`
45- const url2 = `http://data.nba.net/data/10s/prod/v2/${ dt } /scoreboard.json`
44+ const gamesUrl = `http://data.nba.net/prod/v2/${ dt } /scoreboard.json`
45+ const teamsUrl = `https://data.nba.net/prod/v2/2019/teams.json`
46+
4647 return axios
47- . all ( [ axios . get ( url ) , axios . get ( url2 ) ] )
48+ . all ( [ axios . get ( gamesUrl ) , axios . get ( teamsUrl ) ] )
4849 . then (
49- axios . spread ( ( games , standings ) => {
50- const scores = { }
51- scores . year =
52- games . data . sports_content . sports_meta . season_meta . season_year
53- scores . games = games . data . sports_content . games . game . reduce (
54- ( arr , el , i ) => {
55- arr . push ( Object . assign ( { } , el , standings . data . games [ i ] ) )
56- return arr
57- } ,
58- [ ]
50+ axios . spread ( ( games , teams ) => {
51+ const nbaTeams = teams . data . league . standard . filter (
52+ team => team . isNBAFranchise === true
5953 )
54+ const scores = { }
55+ scores . year = dt . slice ( 0 , 4 )
56+ scores . games = games . data . games
57+
58+ scores . games . forEach ( game => {
59+ game . vTeam = {
60+ ...game . vTeam ,
61+ ...nbaTeams . find ( team => team . teamId === game . vTeam . teamId )
62+ }
63+ game . hTeam = {
64+ ...game . hTeam ,
65+ ...nbaTeams . find ( team => team . teamId === game . hTeam . teamId )
66+ }
67+ } )
68+
6069 res . send ( scores )
6170 } )
6271 )
@@ -65,7 +74,7 @@ app.get('/api/nba/scores/:dt', (req, res) => {
6574
6675app . get ( '/api/nba/scores/:dt/details/:id' , ( req , res ) => {
6776 const { dt, id } = req . params
68- const url = `http://data.nba.com/data/10s/json/cms/noseason/game/ ${ dt } /${ id } /boxscore .json`
77+ const url = `http://data.nba.com/prod/v1/ ${ dt } /${ id } _boxscore .json`
6978 return axios
7079 . get ( url )
7180 . then ( scores => res . send ( scores . data ) )
0 commit comments