parent
d1d12663a7
commit
3befe69f30
@ -0,0 +1,36 @@
|
|||||||
|
const { Model } = require('flitter-orm')
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Player Model
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
*/
|
||||||
|
class Player extends Model {
|
||||||
|
static get services() {
|
||||||
|
return [...super.services, 'output', 'models']
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define the flitter-orm schema of the model.
|
||||||
|
*/
|
||||||
|
static get schema() {
|
||||||
|
return {
|
||||||
|
player_number: String,
|
||||||
|
player_name: String,
|
||||||
|
player_position: String,
|
||||||
|
team_name: String,
|
||||||
|
image_url: String,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async to_api() {
|
||||||
|
return {
|
||||||
|
player_number: this.player_number,
|
||||||
|
player_name: this.player_name,
|
||||||
|
player_position: this.player_position,
|
||||||
|
team_name: this.team_name,
|
||||||
|
image_url: this.image_url,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = Player
|
@ -1,32 +0,0 @@
|
|||||||
const { Middleware } = require('libflitter')
|
|
||||||
|
|
||||||
/*
|
|
||||||
* HomeLogger Middleware
|
|
||||||
* -------------------------------------------------------------
|
|
||||||
* This is a sample middleware. It simply prints a console message when
|
|
||||||
* the route that it is tied to is accessed. By default, it is called if
|
|
||||||
* the '/' route is accessed. It can be injected in routes globally using
|
|
||||||
* the middlewares service.
|
|
||||||
*/
|
|
||||||
class HomeLogger extends Middleware {
|
|
||||||
static get services() {
|
|
||||||
return [...super.services, 'output']
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Run the middleware test.
|
|
||||||
* This method is required by all Flitter middleware.
|
|
||||||
* It should either call the next function in the stack,
|
|
||||||
* or it should handle the response accordingly.
|
|
||||||
*/
|
|
||||||
test(req, res, next, args) {
|
|
||||||
this.output.debug('Home was accessed!')
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Call the next function in the stack.
|
|
||||||
*/
|
|
||||||
next()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
module.exports = HomeLogger
|
|
@ -0,0 +1,27 @@
|
|||||||
|
const { Middleware } = require('libflitter')
|
||||||
|
|
||||||
|
/*
|
||||||
|
* InjectUserTeam Middleware
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
* For the authenticated user, looks up the associated Team instance
|
||||||
|
* and injects it as request.team.
|
||||||
|
*/
|
||||||
|
class InjectUserTeam extends Middleware {
|
||||||
|
static get services() {
|
||||||
|
return [...super.services, 'models']
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Run the middleware test.
|
||||||
|
*/
|
||||||
|
async test(req, res, next, args = {}){
|
||||||
|
if ( !req.user ) return res.redirect('/auth/login')
|
||||||
|
|
||||||
|
const Team = this.models.get('Team')
|
||||||
|
req.user_team = await Team.getForUser(req.user)
|
||||||
|
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = InjectUserTeam
|
@ -0,0 +1,68 @@
|
|||||||
|
/*
|
||||||
|
* API Routes
|
||||||
|
* -------------------------------------------------------------
|
||||||
|
* These routes are related to the AJAX API used by the front-end.
|
||||||
|
*/
|
||||||
|
const index = {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define the prefix applied to each of these routes.
|
||||||
|
* For example, if prefix is '/auth':
|
||||||
|
* '/' becomes '/auth'
|
||||||
|
* '/login' becomes '/auth/login'
|
||||||
|
*/
|
||||||
|
prefix: '/api/v1',
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define middleware that should be applied to all
|
||||||
|
* routes defined in this file. Middleware should be
|
||||||
|
* included using its non-prefixed canonical name.
|
||||||
|
*
|
||||||
|
* You can pass arguments along to a middleware by
|
||||||
|
* specifying it as an array where the first element
|
||||||
|
* is the canonical name of the middleware and the
|
||||||
|
* second element is the argument passed to the
|
||||||
|
* handler's test() method.
|
||||||
|
*/
|
||||||
|
middleware: [
|
||||||
|
// Require an authenticated user
|
||||||
|
'auth:UserOnly',
|
||||||
|
|
||||||
|
// Inject the user's team
|
||||||
|
'InjectUserTeam',
|
||||||
|
],
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define GET routes.
|
||||||
|
* These routes are registered as GET methods.
|
||||||
|
* Handlers for these routes should be specified as
|
||||||
|
* an array of canonical references to controller methods
|
||||||
|
* or middleware that are applied in order.
|
||||||
|
*/
|
||||||
|
get: {
|
||||||
|
// handlers should be a list of either controller:: or middleware:: references
|
||||||
|
// e.g. middleware::HomeLogger
|
||||||
|
// e.g. controller::Home.welcome
|
||||||
|
'/': [
|
||||||
|
'controller::Home.welcome'
|
||||||
|
],
|
||||||
|
|
||||||
|
'/my-team': ['controller::Teams.get_my_team'],
|
||||||
|
},
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Define POST routes.
|
||||||
|
* These routes are registered as POST methods.
|
||||||
|
* Handlers for these routes should be specified as
|
||||||
|
* an array of canonical references to controller methods
|
||||||
|
* or middleware that are applied in order.
|
||||||
|
*/
|
||||||
|
post: {
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
// You can include other HTTP verbs here.
|
||||||
|
// Supported ones are: get, post, put, delete, copy, patch
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = exports = index
|
Loading…
Reference in new issue