From b26bf9f22de530477a0d9e4e7b4a22850eb2f0a8 Mon Sep 17 00:00:00 2001 From: psychobunny Date: Fri, 20 Feb 2015 14:45:07 -0500 Subject: [PATCH] rewards: bug fixes and cleanup, pretty much done part 1 ;) --- src/rewards/index.js | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/rewards/index.js b/src/rewards/index.js index 6a2f224640..30ef85b11a 100644 --- a/src/rewards/index.js +++ b/src/rewards/index.js @@ -41,7 +41,7 @@ rewards.checkConditionAndRewardUser = function(uid, condition, method, callback) } checkCondition(reward, method, next); - }, function(err, eligible) { + }, function(eligible) { if (!eligible) { return next(false); } @@ -73,35 +73,29 @@ function filterIncompleteIDs(uid, ids, callback) { } function getRewardDataByIDs(ids, callback) { - ids = ids.map(function(id) { + db.getObjects(ids.map(function(id) { return 'rewards:id:' + id; - }); - - db.getObjects(ids, function(err, objs) { - callback(err, objs); - }); + }), callback); } function getRewardsByRewardData(rewards, callback) { - rewards = rewards.map(function(reward) { + db.getObjects(rewards.map(function(reward) { return 'rewards:id:' + reward.id + ':rewards'; - }); - - db.getObjects(rewards, callback); + }), callback); } function checkCondition(reward, method, callback) { method(function(err, value) { - plugins.fireHook('filter:rewards.checkConditional:' + reward.conditional, {left: value, right: reward.value}, callback); + plugins.fireHook('filter:rewards.checkConditional:' + reward.conditional, {left: value, right: reward.value}, function(err, bool) { + callback(bool); + }); }); } function giveRewards(uid, rewards, callback) { getRewardsByRewardData(rewards, function(err, rewardData) { async.each(rewards, function(reward, next) { - var index = rewards.indexOf(reward); - - plugins.fireHook('action:rewards.award:' + reward.rid, {uid: uid, reward: rewardData[index]}); + plugins.fireHook('action:rewards.award:' + reward.rid, {uid: uid, reward: rewardData[rewards.indexOf(reward)]}); }); }); }