Comment all the things!
This commit is contained in:
@@ -1,30 +0,0 @@
|
||||
const { Model } = require('flitter-orm')
|
||||
|
||||
/*
|
||||
* Example Model
|
||||
* -------------------------------------------------------------
|
||||
* This is a sample model. The schema or structure of the model should
|
||||
* be specified here. It is then passed to flitter-orm and can be accessed
|
||||
* globally using the canonical models service.
|
||||
*/
|
||||
class Example extends Model {
|
||||
static get services() {
|
||||
return [...super.services, 'output']
|
||||
}
|
||||
|
||||
/*
|
||||
* Define the flitter-orm schema of the model.
|
||||
*/
|
||||
static get schema() {
|
||||
return {
|
||||
name: String,
|
||||
create_date: {type: Date, default: () => new Date},
|
||||
}
|
||||
}
|
||||
|
||||
log_name() {
|
||||
this.output.info(`[Example Model] ${this.name}`)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = exports = Example
|
||||
@@ -32,6 +32,10 @@ class Lineup extends Model {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate the fantasy points scored by the starting players on this lineup.
|
||||
* @return {Promise<number>}
|
||||
*/
|
||||
async calculate_fantasy_points() {
|
||||
const starting_players = await this.players_in_starting()
|
||||
let points = 0
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
const { Model } = require('flitter-orm')
|
||||
/**
|
||||
* Matchup
|
||||
* @extends Model
|
||||
* ---------------------------------------------------------------------------
|
||||
* A model representing a single scheduled match-up between two teams.
|
||||
*
|
||||
* @extends Model
|
||||
*/
|
||||
class Matchup extends Model {
|
||||
static get services() {
|
||||
@@ -40,7 +42,8 @@ class Matchup extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the API's data
|
||||
* Format this matchup to be compatible with the API output.
|
||||
* @returns Promise<object>
|
||||
*/
|
||||
async to_api() {
|
||||
const home_team = await this.home_team()
|
||||
|
||||
@@ -1,22 +1,27 @@
|
||||
const { Model } = require('flitter-orm')
|
||||
const ActiveScope = require('./scopes/Active.scope')
|
||||
|
||||
/*
|
||||
/**
|
||||
* Player Model
|
||||
* -------------------------------------------------------------
|
||||
* A model representing a single player in the game.
|
||||
*
|
||||
* @extends Model
|
||||
*/
|
||||
class Player extends Model {
|
||||
static get services() {
|
||||
return [...super.services, 'output', 'models', 'sports_data']
|
||||
}
|
||||
|
||||
// Enable soft-deletes using the active scope
|
||||
static scopes = [new ActiveScope()]
|
||||
|
||||
/*
|
||||
/**
|
||||
* Define the flitter-orm schema of the model.
|
||||
*/
|
||||
static get schema() {
|
||||
return {
|
||||
// Data used by the patches internally, but not exposed to the API
|
||||
patch_data: {
|
||||
patch_team_id: Number,
|
||||
patch_team_name: String,
|
||||
@@ -24,6 +29,7 @@ class Player extends Model {
|
||||
player_id: Number,
|
||||
draft_position: Number,
|
||||
},
|
||||
|
||||
player_number: Number,
|
||||
first_name: String,
|
||||
last_name: String,
|
||||
@@ -38,6 +44,7 @@ class Player extends Model {
|
||||
age: Number,
|
||||
photo_url: String,
|
||||
|
||||
// Statistics pre-generated for the player to optimize performance
|
||||
seed_stats: Object,
|
||||
|
||||
// False if the player doesn't have any week-1 stats.
|
||||
@@ -74,7 +81,8 @@ class Player extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the id's of the unobligated players
|
||||
* returns all of the unobligated players across all teams
|
||||
* @return Promise<Array<Player>>
|
||||
*/
|
||||
static async get_unobligated_players() {
|
||||
const Team = this.prototype.models.get('Team')
|
||||
@@ -93,9 +101,9 @@ class Player extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param week_num
|
||||
* @returns the points scored of that week
|
||||
* Returns the stats for the player for the given week.
|
||||
* @param {number} week_num
|
||||
* @returns Promise<WeeklyPlayerStat>
|
||||
*/
|
||||
async points_for_week(week_num) {
|
||||
const WeeklyPlayerStat = this.models.get('WeeklyPlayerStat')
|
||||
@@ -103,8 +111,8 @@ class Player extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns true if the player is obligated
|
||||
* @returns false if the player is not obligates
|
||||
* Determine whether the player belongs to a team or not.
|
||||
* @returns {Promise<boolean>} - true if the player is obligated
|
||||
*/
|
||||
async is_obligated() {
|
||||
const Team = this.models.get('Team')
|
||||
@@ -117,12 +125,13 @@ class Player extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param with_stats
|
||||
* @returns updates the API's data
|
||||
* Cast the player to a format compatible with the API.
|
||||
* @param {boolean} [with_stats = false] - if true, look up the player's weekly stats
|
||||
* @returns Promise<object>
|
||||
*/
|
||||
async to_api(with_stats = false) {
|
||||
const stat = with_stats ? await this.points_for_week() : undefined
|
||||
const current_week = await this.sports_data.current_play_week()
|
||||
const stat = with_stats ? await this.points_for_week(current_week) : undefined
|
||||
|
||||
return {
|
||||
id: this.id,
|
||||
|
||||
@@ -1,15 +1,18 @@
|
||||
const { Model } = require('flitter-orm')
|
||||
|
||||
/*
|
||||
/**
|
||||
* Team Model
|
||||
* -------------------------------------------------------------
|
||||
* A model representing a single team in the game.
|
||||
*
|
||||
* @extends Model
|
||||
*/
|
||||
class Team extends Model {
|
||||
static get services() {
|
||||
return [...super.services, 'output', 'models']
|
||||
}
|
||||
|
||||
/*
|
||||
/**
|
||||
* Define the flitter-orm schema of the model.
|
||||
*/
|
||||
static get schema() {
|
||||
@@ -52,6 +55,7 @@ class Team extends Model {
|
||||
|
||||
/**
|
||||
* returns the lineup
|
||||
* @return Promise<Lineup>
|
||||
*/
|
||||
async lineup() {
|
||||
const Lineup = this.models.get('Lineup')
|
||||
@@ -60,6 +64,7 @@ class Team extends Model {
|
||||
|
||||
/**
|
||||
* Returns the players associated with the team.
|
||||
* @return Promise<Array<Player>>
|
||||
*/
|
||||
async players() {
|
||||
const Player = this.models.get('Player')
|
||||
@@ -116,7 +121,8 @@ class Team extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the API's data
|
||||
* Cast the team to the format expected for the API.
|
||||
* @return Promise<object>
|
||||
*/
|
||||
async to_api() {
|
||||
let user
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
const { Model } = require('flitter-orm')
|
||||
/**
|
||||
* WeeklyPlayerStat model
|
||||
* @extends Model
|
||||
* -----------------------------------------------------------------------
|
||||
* A record containing the statistics for a single player for a single week.
|
||||
*
|
||||
* @extends Model
|
||||
*/
|
||||
class WeeklyPlayerStat extends Model {
|
||||
static get services() {
|
||||
@@ -29,7 +31,8 @@ class WeeklyPlayerStat extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
* updates the API's data
|
||||
* Cast the stats to a format expected by the API.
|
||||
* @return Promise<object>
|
||||
*/
|
||||
async to_api() {
|
||||
return {
|
||||
|
||||
@@ -1,8 +1,10 @@
|
||||
const { Model } = require('flitter-orm')
|
||||
/**
|
||||
* Weekly Team Stat model
|
||||
* @extends Model
|
||||
* ---------------------------------------------------------------------------
|
||||
* A record containing the stats for a single team for a single lineup for a single week.
|
||||
*
|
||||
* @extends Model
|
||||
*/
|
||||
class WeeklyTeamStat extends Model {
|
||||
static get services() {
|
||||
|
||||
@@ -17,6 +17,8 @@ const Model = require('flitter-auth/model/KeyAction')
|
||||
*
|
||||
* See: module:flitter-auth/SecurityContext~SecurityContext#keyaction
|
||||
* See: module:flitter-auth/model/KeyAction~KeyAction
|
||||
*
|
||||
* This file was automatically generated by the Flitter Framework.
|
||||
*/
|
||||
class KeyAction extends Model {
|
||||
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
const AuthUser = require('flitter-auth/model/User')
|
||||
|
||||
/*
|
||||
/**
|
||||
* Auth user model. This inherits fields and methods from the default
|
||||
* flitter-auth/model/User model, however you can override methods and
|
||||
* properties here as you need.
|
||||
*
|
||||
* This file was automatically generated by the Flitter Framework.
|
||||
*
|
||||
* @extends AuthUser
|
||||
*/
|
||||
class User extends AuthUser {
|
||||
static get services() {
|
||||
@@ -17,6 +21,11 @@ class User extends AuthUser {
|
||||
}
|
||||
|
||||
// Other members and methods here
|
||||
|
||||
/**
|
||||
* Get the team associated with this user.
|
||||
* @return {Promise<Team>}
|
||||
*/
|
||||
async team() {
|
||||
const Team = this.models.get('Team')
|
||||
return Team.getForUser(this)
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
const Scope = require('flitter-orm/src/model/Scope')
|
||||
|
||||
/**
|
||||
* This is a model scope which excludes any models without is_active = true.
|
||||
* In effect, this provides a mechanism for soft-deletes.
|
||||
*
|
||||
* @extends Scope
|
||||
*/
|
||||
class ActiveScope extends Scope {
|
||||
/**
|
||||
* Apply this scope's conditions to a model filter.
|
||||
* @param to_filter
|
||||
* @return {Promise<*>}
|
||||
*/
|
||||
async filter(to_filter) {
|
||||
return to_filter.equal('is_active', true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user