fix(purchases): Handle undefined/null balance

This commit is contained in:
Sabe Jones 2015-05-13 15:15:40 -05:00
parent 68ce9a8457
commit 6e27b7af9d

View file

@ -750,7 +750,7 @@ api.wrap = (user, main=true) ->
item = content[type][key] item = content[type][key]
price = item.value / 4 price = item.value / 4
return cb?({code:404,message:":key not found for Content.#{type}"},req) unless item return cb?({code:404,message:":key not found for Content.#{type}"},req) unless item
return cb?({code:401, message: i18n.t('notEnoughGems', req.language)}) if user.balance < price return cb?({code:401, message: i18n.t('notEnoughGems', req.language)}) if (user.balance < price) or !user.balance
user.balance -= price user.balance -= price
if type is 'gear' then user.items.gear.owned[key] = true if type is 'gear' then user.items.gear.owned[key] = true
else else