mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 15:48:04 +01:00
halloween: some unlocking bug fixes (appears a markModified was required)
This commit is contained in:
@@ -44,7 +44,7 @@ habitrpg.controller("UserCtrl", ['$rootScope', '$scope', '$location', 'User', '$
|
||||
window.habitrpgShared.helpers.dotSet('preferences.' + pref, val, User.user);
|
||||
} else {
|
||||
if (confirm("Purchase for 2 Gems?") !== true) return;
|
||||
if (User.user.balance < 0.5) return $rootScope.modals.moreGems = true;
|
||||
if (User.user.balance < 0.5) return $rootScope.modals.buyGems = true;
|
||||
User.unlock(path);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -575,16 +575,13 @@ api.unlock = function(req, res) {
|
||||
if (user.balance < 0.5)
|
||||
return res.json(401, {err: 'Not enough gems'});
|
||||
|
||||
// Provide deafult values if !user.purchased
|
||||
_.defaults(user, {purchased:{}});
|
||||
_.defaults(user.purchased, {skin:{}, hair:{}, ads: false});
|
||||
|
||||
var path = req.query.path;
|
||||
if (helpers.dotGet('purchased.' + path, user) === true)
|
||||
return res.json(401, {err: 'User already purchased that'});
|
||||
user.balance -= 2;
|
||||
helpers.dotSet('purchased.' + path, true, user);
|
||||
user.__v++;
|
||||
user.markModified('purchased');
|
||||
user.save(function(err, saved){
|
||||
if (err) res.json(500, {err:err});
|
||||
res.send(200);
|
||||
|
||||
@@ -71,8 +71,8 @@ var UserSchema = new Schema({
|
||||
|
||||
purchased: {
|
||||
ads: {type: Boolean, 'default': false},
|
||||
skin: Schema.Types.Mixed, // eg, {skeleton: true, pumpkin: true, eb052b: true}
|
||||
hair: Schema.Types.Mixed
|
||||
skin: {type: Schema.Types.Mixed, 'default': {}}, // eg, {skeleton: true, pumpkin: true, eb052b: true}
|
||||
hair: {type: Schema.Types.Mixed, 'default': {}}
|
||||
},
|
||||
|
||||
flags: {
|
||||
|
||||
Reference in New Issue
Block a user