mirror of
https://github.com/stolksdorf/homebrewery.git
synced 2025-12-24 07:31:28 +00:00
Added in full test coverage of current spec
This commit is contained in:
@@ -2,6 +2,7 @@ const _ = require('lodash');
|
||||
const jwt = require('jwt-simple');
|
||||
const config = require('nconf');
|
||||
|
||||
const Error = require('./error.js');
|
||||
const BrewData = require('./brew.data.js');
|
||||
|
||||
const Middleware = {
|
||||
@@ -15,13 +16,11 @@ const Middleware = {
|
||||
},
|
||||
admin : (req, res, next) => {
|
||||
if(req.query.admin_key === config.get('admin_key')){
|
||||
delete req.admin_key;
|
||||
req.isAdmin = true;
|
||||
req.admin = true;
|
||||
}
|
||||
return next();
|
||||
},
|
||||
|
||||
|
||||
//Filters
|
||||
devOnly : (req, res, next) => {
|
||||
const env = process.env.NODE_ENV;
|
||||
@@ -29,20 +28,27 @@ const Middleware = {
|
||||
return res.sendStatus(404);
|
||||
},
|
||||
adminOnly : (req, res, next) => {
|
||||
if(req.isAdmin) return next();
|
||||
return res.sendStatus(401);
|
||||
if(req.admin) return next();
|
||||
return next(Error.noAuth());
|
||||
},
|
||||
|
||||
|
||||
//Loaders
|
||||
loadBrew : (req, res, next) => {
|
||||
//Loads a brew by edit id
|
||||
|
||||
//TODO: move validate into hurrr
|
||||
BrewData.getByEdit(req.params.editId)
|
||||
.then((brew) => {
|
||||
req.brew = brew;
|
||||
return next()
|
||||
})
|
||||
.catch(next);
|
||||
},
|
||||
viewBrew : (req, res, next) => {
|
||||
//load by share
|
||||
//increase view count
|
||||
BrewData.getByShare(req.params.shareId)
|
||||
.then((brew) => {
|
||||
req.brew = brew;
|
||||
return next()
|
||||
})
|
||||
.catch(next);
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user