From 17e5d72815a1bde6d6caaadbb08d3156fda14c65 Mon Sep 17 00:00:00 2001 From: Dustin Falgout Date: Sun, 6 Dec 2015 09:30:33 -0600 Subject: [PATCH] fix waterfall Signed-off-by: Dustin Falgout --- src/controllers/api.js | 62 ++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 30 deletions(-) diff --git a/src/controllers/api.js b/src/controllers/api.js index 3d4532b1a9..aebf4a746e 100644 --- a/src/controllers/api.js +++ b/src/controllers/api.js @@ -195,50 +195,52 @@ apiController.getUserByUID = function(req, res, next) { }; -apiController.getUserByUsername = function (req, res, next) { +apiController.getUserByUsername = function(req, res, next) { var username = req.params.username ? req.params.username : 0; async.waterfall([ - function (next) { + function(next) { user.getUidByUsername(username, next); }, - async.parallel({ - userData: async.apply(user.getUserData, uid), - settings: async.apply(user.getSettings, uid) - }, function (err, results) { - if (err || !results.userData) { - return next(err); - } - results.userData.email = results.settings.showemail ? results.userData.email : undefined; - results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined; - - res.json(results.userData); - }) - + function(uid, next) { + async.parallel({ + userData: async.apply(user.getUserData, uid), + settings: async.apply(user.getSettings, uid) + }, function(err, results) { + if (err || !results.userData) { + return next(err); + } + results.userData.email = results.settings.showemail ? results.userData.email : undefined; + results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined; + + res.json(results.userData); + }); + } ], next); }; -apiController.getUserByEmail = function (req, res, next) { +apiController.getUserByEmail = function(req, res, next) { var email = req.params.email ? req.params.email : 0; async.waterfall([ - function (next) { + function(next) { user.getUidByEmail(email, next); }, - async.parallel({ - userData: async.apply(user.getUserData, uid), - settings: async.apply(user.getSettings, uid) - }, function (err, results) { - if (err || !results.userData) { - return next(err); - } - results.userData.email = results.settings.showemail ? results.userData.email : undefined; - results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined; - - res.json(results.userData); - }) - + function(uid, next) { + async.parallel({ + userData: async.apply(user.getUserData, uid), + settings: async.apply(user.getSettings, uid) + }, function(err, results) { + if (err || !results.userData) { + return next(err); + } + results.userData.email = results.settings.showemail ? results.userData.email : undefined; + results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined; + + res.json(results.userData); + }); + } ], next); };