2020-11-01 18:50:03 +00:00
|
|
|
const { Controller } = require('libflitter')
|
|
|
|
|
2020-11-08 18:34:50 +00:00
|
|
|
/**
|
2020-11-01 18:50:03 +00:00
|
|
|
* Home Controller
|
|
|
|
* -------------------------------------------------------------
|
|
|
|
* Controller for the main homepage of this Flitter app. Methods here
|
|
|
|
* are used as handlers for routes specified in the route files.
|
2020-11-08 18:34:50 +00:00
|
|
|
*
|
|
|
|
* @extends Controller
|
2020-11-01 18:50:03 +00:00
|
|
|
*/
|
|
|
|
class Home extends Controller {
|
2020-11-08 16:51:08 +00:00
|
|
|
static get services() {
|
|
|
|
return [...super.services, 'sports_data']
|
|
|
|
}
|
2020-11-01 18:50:03 +00:00
|
|
|
|
2020-11-08 18:34:50 +00:00
|
|
|
/**
|
2020-11-01 18:50:03 +00:00
|
|
|
* Serve the main welcome page.
|
2020-11-08 18:34:50 +00:00
|
|
|
* @param req
|
|
|
|
* @param res
|
2020-11-01 18:50:03 +00:00
|
|
|
*/
|
|
|
|
welcome(req, res){
|
2020-11-05 02:31:52 +00:00
|
|
|
if ( req.user ) {
|
|
|
|
return res.redirect('/app')
|
|
|
|
} else {
|
|
|
|
return res.redirect('/auth/login')
|
|
|
|
}
|
2020-11-01 18:50:03 +00:00
|
|
|
}
|
2020-11-08 16:51:08 +00:00
|
|
|
|
2020-11-08 18:34:50 +00:00
|
|
|
/**
|
|
|
|
* Return the current session's status (including team information and
|
|
|
|
* information about the current stage of gameplay).
|
|
|
|
* @param req
|
|
|
|
* @param res
|
|
|
|
* @param next
|
|
|
|
* @return {Promise<*>}
|
|
|
|
*/
|
2020-11-08 16:51:08 +00:00
|
|
|
async get_status(req, res, next) {
|
|
|
|
return res.api({
|
|
|
|
team_id: req.user_team.id,
|
|
|
|
team_name: req.user_team.team_name,
|
|
|
|
current_week: await this.sports_data.current_play_week(),
|
|
|
|
is_draft_stage: await this.sports_data.is_draft_stage(),
|
|
|
|
})
|
|
|
|
}
|
2020-11-01 18:50:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Home
|