Fix Mongoose 4 update change the right way for completing level achievement calculations

This commit is contained in:
Nick Winter 2015-12-09 12:08:16 -08:00
parent 7269dc85d4
commit 2db3145e19

View file

@ -60,11 +60,10 @@ LevelSessionSchema.pre 'save', (next) ->
update = $inc: {'stats.gamesCompleted': 1}
for concept in level?.concepts ? []
update.$inc["stats.concepts.#{concept}"] = 1
User.findByIdAndUpdate userID, update, {}, (err, user) ->
User.findByIdAndUpdate userID, update, {new: true}, (err, user) ->
log.error err if err?
oldCopy = user.toObject()
oldCopy.stats = _.clone oldCopy.stats
oldCopy.stats ?= {gamesCompleted: 0}
--oldCopy.stats.gamesCompleted
oldCopy.stats.concepts ?= {}
for concept in level?.concepts ? []