From 3a3c5486b7d8aa308b7b2cd7957e8000bd365635 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Sun, 11 Oct 2015 23:31:33 -0400 Subject: [PATCH] expose method --- src/middleware/middleware.js | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/middleware/middleware.js b/src/middleware/middleware.js index bcb62d9b41..fa06d7f910 100644 --- a/src/middleware/middleware.js +++ b/src/middleware/middleware.js @@ -64,7 +64,7 @@ middleware.pageView = function(req, res, next) { middleware.pluginHooks = function(req, res, next) { async.each(plugins.loadedHooks['filter:router.page'] || [], function(hookObj, next) { hookObj.method(req, res, next); - }, function(req, res) { + }, function() { // If it got here, then none of the subscribed hooks did anything, or there were no hooks next(); }); @@ -180,33 +180,26 @@ middleware.privateTagListing = function(req, res, next) { }; middleware.exposeGroupName = function(req, res, next) { - if (!req.params.hasOwnProperty('slug')) { - return next(); - } - - groups.getGroupNameByGroupSlug(req.params.slug, function(err, groupName) { - if (err) { - return next(err); - } - - res.locals.groupName = groupName; - next(); - }); + expose('groupName', groups.getGroupNameByGroupSlug, 'slug', req, res, next); }; middleware.exposeUid = function(req, res, next) { - if (!req.params.hasOwnProperty('userslug')) { + expose('uid', user.getUidByUserslug, 'userslug', req, res, next); +}; + +function expose(exposedField, method, field, req, res, next) { + if (!req.params.hasOwnProperty(field)) { return next(); } - user.getUidByUserslug(req.params.userslug, function(err, uid) { + method(req.params[field], function(err, id) { if (err) { return next(err); } - res.locals.uid = uid; + res.locals[exposedField] = id; next(); }); -}; +} middleware.requireUser = function(req, res, next) { if (req.user) {