diff --git a/app/controllers/DraftBoard.controller.js b/app/controllers/DraftBoard.controller.js index 773365f..2dd712f 100644 --- a/app/controllers/DraftBoard.controller.js +++ b/app/controllers/DraftBoard.controller.js @@ -1,10 +1,21 @@ const { Controller } = require('libflitter') - +/** + * DraftBoard controller + * @extends Controller + * ------------------------------------------------------------------------ + */ class DraftBoard extends Controller { static get services() { return [...super.services, 'models'] } + /** + * Returns the API data containing the players available to draft + * @param req + * @param res + * @param next + * @returns + */ async get_available_players(req, res, next) { const Player = this.models.get('Player') const players = await Player.get_unobligated_players() @@ -17,6 +28,13 @@ class DraftBoard extends Controller { return res.api(api_data) } + /** + * adds the selected player to the team + * @param req + * @param res + * @param next + * @returns + */ async draft_player_to_team(req, res, next) { if ( !req.body.player_id ) { return res.status(400) diff --git a/app/controllers/Scores.controller.js b/app/controllers/Scores.controller.js index a9933c2..bdd5961 100644 --- a/app/controllers/Scores.controller.js +++ b/app/controllers/Scores.controller.js @@ -1,10 +1,21 @@ const { Controller } = require('libflitter') - +/** + * ScoresController + * @extends Controller + * ---------------------------------------------------------------------- + */ class ScoresController extends Controller { static get services() { return [...super.services, 'models', 'sports_data'] } + /** + * Returns the weekly scores + * @param req + * @param res + * @param next + * @returns + */ async get_weekly_scores(req, res, next) { const Matchup = this.models.get('Matchup') diff --git a/app/models/Matchup.model.js b/app/models/Matchup.model.js index 4d2cc5a..1d8556c 100644 --- a/app/models/Matchup.model.js +++ b/app/models/Matchup.model.js @@ -1,10 +1,17 @@ const { Model } = require('flitter-orm') - +/** + * Matchup + * @extends Model + * --------------------------------------------------------------------------- + */ class Matchup extends Model { static get services() { return [...super.services, 'models'] } + /** + * define the schema of the model + */ static get schema() { return { home_team_id: String, @@ -16,16 +23,25 @@ class Matchup extends Model { } } + /** + * @returns the data of the home team + */ async home_team() { const Team = this.models.get('Team') return Team.findById(this.home_team_id) } + /** + * @returns the data of the visitor team + */ async visitor_team() { const Team = this.models.get('Team') return Team.findById(this.visitor_team_id) } + /** + * updates the API's data + */ async to_api() { const home_team = await this.home_team() const visitor_team = await this.visitor_team() diff --git a/app/models/Player.model.js b/app/models/Player.model.js index 6a267ab..b1c248d 100644 --- a/app/models/Player.model.js +++ b/app/models/Player.model.js @@ -67,6 +67,9 @@ class Player extends Model { return new this(model_data) } + /** + * returns the id's of the unobligated players + */ static async get_unobligated_players() { const Team = this.prototype.models.get('Team') let obligated_player_ids = [] @@ -83,11 +86,20 @@ class Player extends Model { }) } + /** + * + * @param week_num + * @returns the points scored of that week + */ async points_for_week(week_num) { const WeeklyPlayerStat = this.models.get('WeeklyPlayerStat') return WeeklyPlayerStat.findOne({ week_num, player_id: this.id }) } + /** + * @returns true if the player is obligated + * @returns false if the player is not obligates + */ async is_obligated() { const Team = this.models.get('Team') const teams = await Team.find() @@ -98,6 +110,11 @@ class Player extends Model { return false } + /** + * + * @param with_stats + * @returns updates the API's data + */ async to_api(with_stats = false) { const stat = with_stats ? await this.points_for_week() : undefined diff --git a/app/models/Team.model.js b/app/models/Team.model.js index 9f23afb..90b64cf 100644 --- a/app/models/Team.model.js +++ b/app/models/Team.model.js @@ -50,11 +50,17 @@ class Team extends Model { return new_team } + /** + * returns the lineup + */ async lineup() { const Lineup = this.models.get('Lineup') return Lineup.get_and_update_for_team(this) } + /** + * + */ async players() { const Player = this.models.get('Player') return Player.find({ @@ -64,6 +70,9 @@ class Team extends Model { }) } + /** + * updates the API's data + */ async to_api() { const User = this.models.get('auth:User') diff --git a/app/models/WeeklyPlayerStat.model.js b/app/models/WeeklyPlayerStat.model.js index fdad60e..7cb5a2e 100644 --- a/app/models/WeeklyPlayerStat.model.js +++ b/app/models/WeeklyPlayerStat.model.js @@ -1,10 +1,17 @@ const { Model } = require('flitter-orm') - +/** + * WeeklyPlayerStat model + * @extends Model + * ----------------------------------------------------------------------- + */ class WeeklyPlayerStat extends Model { static get services() { return [...super.services, 'models'] } + /** + * defines the schema of the particular model + */ static get schema() { return { player_id: String, @@ -21,6 +28,9 @@ class WeeklyPlayerStat extends Model { } } + /** + * updates the API's data + */ async to_api() { return { 'Passing Attempts': this.passing_attempts, diff --git a/app/models/WeeklyTeamStat.model.js b/app/models/WeeklyTeamStat.model.js index 681f24b..075dc42 100644 --- a/app/models/WeeklyTeamStat.model.js +++ b/app/models/WeeklyTeamStat.model.js @@ -1,10 +1,17 @@ const { Model } = require('flitter-orm') - +/** + * Weekly Team Stat model + * @extends Model + * --------------------------------------------------------------------------- + */ class WeeklyTeamStat extends Model { static get services() { return [...super.services, 'models'] } + /** + * defines the schema of the particular model + */ static get schema() { return { team_id: String,