Add endpoint for fetching matchups & hook up to matchups interface
This commit is contained in:
24
app/controllers/Scores.controller.js
Normal file
24
app/controllers/Scores.controller.js
Normal 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
|
||||
Reference in New Issue
Block a user