mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
start upgrading eslint
This commit is contained in:
@@ -6,27 +6,28 @@ import {
|
||||
|
||||
// Wrapper function to handler `async` route handlers that return promises
|
||||
// It takes the async function, execute it and pass any error to next (args[2])
|
||||
let _wrapAsyncFn = fn => (...args) => fn(...args).catch(args[2]);
|
||||
let noop = (req, res, next) => next();
|
||||
const _wrapAsyncFn = fn => (...args) => fn(...args).catch(args[2]);
|
||||
const noop = (req, res, next) => next();
|
||||
|
||||
export function readController (router, controller, overrides = []) {
|
||||
_.each(controller, (action) => {
|
||||
let {method, url, middlewares = [], handler} = action;
|
||||
_.each(controller, action => {
|
||||
let {
|
||||
method, url, middlewares = [], handler,
|
||||
} = action;
|
||||
|
||||
// Allow to specify a list of routes (METHOD + URL) to skip
|
||||
if (overrides.indexOf(`${method}-${url}`) !== -1) return;
|
||||
|
||||
// If an authentication middleware is used run getUserLanguage after it, otherwise before
|
||||
// for cron instead use it only if an authentication middleware is present
|
||||
let authMiddlewareIndex = _.findIndex(middlewares, middleware => {
|
||||
const authMiddlewareIndex = _.findIndex(middlewares, middleware => {
|
||||
if (middleware.name.indexOf('authWith') === 0) { // authWith{Headers|Session|Url|...}
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
let middlewaresToAdd = [getUserLanguage];
|
||||
const middlewaresToAdd = [getUserLanguage];
|
||||
|
||||
if (action.noLanguage !== true) {
|
||||
if (authMiddlewareIndex !== -1) { // the user will be authenticated, getUserLanguage after authentication
|
||||
@@ -41,7 +42,7 @@ export function readController (router, controller, overrides = []) {
|
||||
}
|
||||
|
||||
method = method.toLowerCase();
|
||||
let fn = handler ? _wrapAsyncFn(handler) : noop;
|
||||
const fn = handler ? _wrapAsyncFn(handler) : noop;
|
||||
|
||||
router[method](url, ...middlewares, fn);
|
||||
});
|
||||
@@ -54,7 +55,7 @@ export function walkControllers (router, filePath, overrides) {
|
||||
if (!fs.statSync(filePath + fileName).isFile()) {
|
||||
walkControllers(router, `${filePath}${fileName}/`, overrides);
|
||||
} else if (fileName.match(/\.js$/)) {
|
||||
let controller = require(filePath + fileName).default; // eslint-disable-line global-require
|
||||
const controller = require(filePath + fileName).default; // eslint-disable-line global-require
|
||||
readController(router, controller, overrides);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user