Add logic for saving draft picks to team and fetching draft & team from server for frontend

This commit is contained in:
2020-11-05 21:53:35 -06:00
parent fc5b90a938
commit a207cd0a11
6 changed files with 102 additions and 4 deletions

View File

@@ -65,6 +65,32 @@ class Player extends Model {
return new this(model_data)
}
static async get_unobligated_players() {
const Team = this.prototype.models.get('Team')
let obligated_player_ids = []
const teams = await Team.find()
for ( const team of teams ) {
obligated_player_ids = obligated_player_ids.concat(team.player_ids)
}
return this.find({
_id: {
$nin: obligated_player_ids.map(x => this.to_object_id(x))
}
})
}
async is_obligated() {
const Team = this.models.get('Team')
const teams = await Team.find()
for ( const team of teams ) {
if ( team.player_ids.includes(this.id) ) return true
}
return false
}
async to_api() {
return {
id: this.id,

View File

@@ -6,6 +6,10 @@ const AuthUser = require('flitter-auth/model/User')
* properties here as you need.
*/
class User extends AuthUser {
static get services() {
return [...super.services, 'models']
}
static get schema() {
return {...super.schema, ...{
// other schema fields here
@@ -13,6 +17,10 @@ class User extends AuthUser {
}
// Other members and methods here
async team() {
const Team = this.models.get('Team')
return Team.getForUser(this)
}
}
module.exports = exports = User