added more logging and missing err handler in subscription updater

This commit is contained in:
Henry Oswald 2016-03-31 17:28:03 +01:00
parent 5a201153c7
commit d80191c03b
2 changed files with 7 additions and 1 deletions

View file

@ -35,7 +35,7 @@ module.exports = ReferalAllocator =
query = _id: user_id
User.findOne query, (error, user) ->
return callback(error) if error
return callback(new Error("user not found")) if !user?
return callback(new Error("user not found #{user_id} for assignBonus")) if !user?
logger.log user_id: user_id, refered_user_count: user.refered_user_count, "assigning bonus"
if user.refered_user_count? and user.refered_user_count > 0
newFeatures = ReferalAllocator._calculateFeatures(user)

View file

@ -84,12 +84,18 @@ module.exports = SubscriptionUpdater =
groupSubscription: (cb)->
SubscriptionLocator.getGroupSubscriptionMemberOf user_id, cb
async.series jobs, (err, results)->
if err?
logger.err err:err, user_id:user, "error getting subscription or group for _setUsersMinimumFeatures"
return callback(err)
{subscription, groupSubscription} = results
if subscription? and subscription.planCode?
logger.log user_id:user_id, "using users subscription plan code for features"
UserFeaturesUpdater.updateFeatures user_id, subscription.planCode, callback
else if groupSubscription? and groupSubscription.planCode?
logger.log user_id:user_id, "using group which user is memor of for features"
UserFeaturesUpdater.updateFeatures user_id, groupSubscription.planCode, callback
else
logger.log user_id:user_id, "using default features for user with no subscription or group"
UserFeaturesUpdater.updateFeatures user_id, Settings.defaultPlanCode, (err)->
if err?
logger.err err:err, user_id:user_id, "Error setting minimum user feature"