From e6b7b51956bd0e8964a4fb5c12fe45c5641a1ff6 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Tue, 29 Dec 2015 10:46:57 +0200 Subject: [PATCH] getHomePageRoutes --- src/controllers/accounts/settings.js | 99 +++++++++++++++------------- 1 file changed, 55 insertions(+), 44 deletions(-) diff --git a/src/controllers/accounts/settings.js b/src/controllers/accounts/settings.js index c56fd10c1e..7d6ebfdeef 100644 --- a/src/controllers/accounts/settings.js +++ b/src/controllers/accounts/settings.js @@ -39,50 +39,7 @@ settingsController.get = function(req, res, callback) { languages.list(next); }, homePageRoutes: function(next) { - async.waterfall([ - function(next) { - db.getSortedSetRange('cid:0:children', 0, -1, next); - }, - function(cids, next) { - privileges.categories.filterCids('find', cids, 0, next); - }, - function(cids, next) { - categories.getCategoriesFields(cids, ['name', 'slug'], next); - }, - function(categoryData, next) { - categoryData = categoryData.map(function(category) { - return { - route: 'category/' + category.slug, - name: 'Category: ' + category.name - }; - }); - next(null, categoryData); - } - ], function(err, categoryData) { - if (err || !categoryData) categoryData = []; - - plugins.fireHook('filter:homepage.get', {routes: [ - { - route: 'categories', - name: 'Categories' - }, - { - route: 'recent', - name: 'Recent' - }, - { - route: 'popular', - name: 'Popular' - } - ].concat(categoryData)}, function(err, data) { - data.routes.push({ - route: 'custom', - name: 'Custom' - }); - - next(null, data.routes); - }); - }); + getHomePageRoutes(next); }, sessions: async.apply(user.auth.getSessions, userData.uid, req.sessionID) }, next); @@ -161,5 +118,59 @@ settingsController.get = function(req, res, callback) { }; +function getHomePageRoutes(callback) { + async.waterfall([ + function (next) { + db.getSortedSetRange('cid:0:children', 0, -1, next); + }, + function (cids, next) { + privileges.categories.filterCids('find', cids, 0, next); + }, + function (cids, next) { + categories.getCategoriesFields(cids, ['name', 'slug'], next); + }, + function (categoryData, next) { + categoryData = categoryData.map(function(category) { + return { + route: 'category/' + category.slug, + name: 'Category: ' + category.name + }; + }); + next(null, categoryData); + } + ], function(err, categoryData) { + if (err) { + return callback(err); + } + categoryData = categoryData || []; + + plugins.fireHook('filter:homepage.get', {routes: [ + { + route: 'categories', + name: 'Categories' + }, + { + route: 'recent', + name: 'Recent' + }, + { + route: 'popular', + name: 'Popular' + } + ].concat(categoryData)}, function(err, data) { + if (err) { + return callback(err); + } + + data.routes.push({ + route: 'custom', + name: 'Custom' + }); + + callback(null, data.routes); + }); + }); +} + module.exports = settingsController; \ No newline at end of file