refactor get user by x

v1.18.x
barisusakli 9 years ago
parent 69bc870017
commit 7b21760f00

@ -179,18 +179,11 @@ apiController.getObject = function(req, res, next) {
apiController.getUserByUID = function(req, res, next) {
var uid = req.params.uid ? req.params.uid : 0;
async.parallel({
userData: async.apply(user.getUserData, uid),
settings: async.apply(user.getSettings, uid)
}, function(err, results) {
if (err || !results.userData) {
getUserByUID(uid, function(err, userData) {
if (err || !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);
res.json(userData);
});
};
@ -203,20 +196,14 @@ apiController.getUserByUsername = function(req, res, next) {
user.getUidByUsername(username, next);
},
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);
});
getUserByUID(uid, next);
}
], function(err, userData) {
if (err || !userData) {
return next(err);
}
], next);
res.json(userData);
});
};
@ -228,23 +215,33 @@ apiController.getUserByEmail = function(req, res, next) {
user.getUidByEmail(email, next);
},
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);
});
getUserByUID(uid, next);
}
], function(err, userData) {
if (err || !userData) {
return next(err);
}
], next);
res.json(userData);
});
};
function getUserByUID(uid, callback) {
async.parallel({
userData: async.apply(user.getUserData, uid),
settings: async.apply(user.getSettings, uid)
}, function(err, results) {
if (err || !results.userData) {
return callback(err, null);
}
results.userData.email = results.settings.showemail ? results.userData.email : undefined;
results.userData.fullname = results.settings.showfullname ? results.userData.fullname : undefined;
callback(null, results.userData);
});
}
apiController.getModerators = function(req, res, next) {
categories.getModerators(req.params.cid, function(err, moderators) {
if (err) {

Loading…
Cancel
Save