Add endpoint for fetching my-team/players
This commit is contained in:
parent
19567dcfb0
commit
33c37f6855
@ -21,6 +21,13 @@ class Teams extends Controller {
|
||||
return res.api(await req.user_team.to_api())
|
||||
}
|
||||
|
||||
async get_my_team_players(req, res, next) {
|
||||
const players = await req.user_team.players()
|
||||
console.log(players)
|
||||
console.log(await players[0].to_api())
|
||||
return res.api(await Promise.all(players.map(x => x.to_api())))
|
||||
}
|
||||
|
||||
async list_all_teams(req, res) {
|
||||
const TeamModel = this.models.get('Team')
|
||||
const teams = await TeamModel.find()
|
||||
|
@ -67,11 +67,12 @@ class Player extends Model {
|
||||
|
||||
async to_api() {
|
||||
return {
|
||||
player_number: this.player_number,
|
||||
player_name: this.player_name,
|
||||
player_position: this.player_position,
|
||||
team_name: this.team_name,
|
||||
image_url: this.image_url,
|
||||
number: this.player_number,
|
||||
name: this.full_name,
|
||||
position: this.fantasy_position,
|
||||
team_name: this.patch_data.patch_team_name,
|
||||
image: this.photo_url,
|
||||
stats: {}, // TODO - populate some stats!
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -50,6 +50,15 @@ class Team extends Model {
|
||||
return new_team
|
||||
}
|
||||
|
||||
async players() {
|
||||
const Player = this.models.get('Player')
|
||||
return Player.find({
|
||||
_id: {
|
||||
$in: this.player_ids.map(x => Player.to_object_id(x))
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
async to_api() {
|
||||
const User = this.models.get('auth:User')
|
||||
|
||||
|
@ -48,6 +48,7 @@ const index = {
|
||||
],
|
||||
|
||||
'/my-team': ['controller::Teams.get_my_team'],
|
||||
'/my-team/players': ['controller::Teams.get_my_team_players'],
|
||||
},
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user