Add endpoint for fetching matchups & hook up to matchups interface

This commit is contained in:
2020-11-07 16:36:43 -06:00
parent d85570600a
commit ccf0792ac4
5 changed files with 64 additions and 205 deletions

View File

@@ -0,0 +1,24 @@
const { Controller } = require('libflitter')
class ScoresController extends Controller {
static get services() {
return [...super.services, 'models', 'sports_data']
}
async get_weekly_scores(req, res, next) {
const Matchup = this.models.get('Matchup')
const current_week = await this.sports_data.current_play_week()
const weekly_data = []
for ( let i = 1; i <= current_week; i += 1 ) {
const matchups = await Matchup.find({ week_num: i })
const api_data = await Promise.all(matchups.map(x => x.to_api()))
weekly_data.push(api_data)
}
return res.api(weekly_data)
}
}
module.exports = exports = ScoresController