stonecircle/express-autoroute-json

View on GitHub
lib/authorisation.js

Summary

Maintainability
A
35 mins
Test Coverage
A
100%
var _ = require('lodash');
 
var mergeQueries = require('./helpers/mergeQueries');
 
Function `exports` has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
module.exports = function(options, blockType) {
return function(req, res, next) {
let query;
 
if (options && options[blockType] && options[blockType].authorisation) {
query = options[blockType].authorisation(req);
} else if (options && options.authorisation) {
query = options.authorisation(req);
}
 
if (query) {
_.assign(req, {
autorouteQuery: mergeQueries(req.autorouteQuery, query),
});
}
 
next();
};
};