Skip to content

Commit

Permalink
cohort 17 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
danbrud committed Jul 12, 2020
1 parent fc54d15 commit 2cd99f6
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"skipFiles": [
"<node_internals>/**"
],
"program": "${file}"
"program": "${workSpaceFolder}/server.js"
}
]
}
5 changes: 4 additions & 1 deletion dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
<p class="name">{{firstName}} {{lastName}}</p>
<p class="number">{{jersey}}</p>
<div class="player-image">
<img src="https://nba-players.herokuapp.com/players/{{lastName}}/{{firstName}}" onerror="setDefaultImg(this)">
<img
src="{{img}}"
onerror="setDefaultImg(this)"
>
</div>
<p class="pos">{{pos}}</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion dist/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const render = function (roster) {

const fetch = function () {
const input = $(`#input`).val().toLowerCase()
$.get(`/teams/${input}`, function (response) {
$.get(`/api/teams/${input}`, function (response) {
render(response)
})
}
Expand Down
7 changes: 3 additions & 4 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const express = require('express')
const path = require('path')
const bodyParser = require('body-parser')
const api = require('./server/routes/api')

const app = express()


Expand All @@ -11,11 +12,9 @@ app.use(express.static(path.join(__dirname, 'node_modules')))
app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: false }))

app.use('/', api)
app.use('/api', api)

const port = 3000
app.listen(port, function () {
console.log(`Running server on port ${port}`)
})


})
30 changes: 24 additions & 6 deletions server/routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,31 @@ urllib.request('http://data.nba.net/10s/prod/v1/2018/players.json', (err, res) =
})

router.get(`/teams/:teamName`, (req, res) => {
const teamID = teamToIDs[req.params.teamName]
// const teamName = req.params.teamName
const { teamName } = req.params
const [a, b] = ['shobbi', 'doobi']

if (teamToIDs[teamName]) {

const teamID = teamToIDs[teamName]

const team = json.data
.filter(p => p.teamId === teamID && p.isActive)
.map(p => {
return {
firstName: p.firstName,
lastName: p.lastName,
jersey: p.jersey || 'unavailable',
pos: p.pos,
img:`https:nba-players.herokuapp.com/players/${p.lastName}/${p.firstName}`
}
})

res.send(team)
} else {
res.send({ error: 'not found' })
}

const team = json.data
.filter(p => p.teamId === teamID && p.isActive)
.map(p => { return { firstName: p.firstName, lastName: p.lastName, jersey: p.jersey, pos: p.pos } })

res.send(team)
})

module.exports = router
Expand Down

0 comments on commit 2cd99f6

Please sign in to comment.