Add API endpoint to fetch team
This commit is contained in:
@@ -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
|
||||
27
app/routing/middleware/InjectUserTeam.middleware.js
Normal file
27
app/routing/middleware/InjectUserTeam.middleware.js
Normal file
@@ -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
|
||||
Reference in New Issue
Block a user