mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-04-26 14:03:28 -04:00
User stats now go through Mongoose middleware
This commit is contained in:
parent
601c4e2731
commit
246c39b558
1 changed files with 6 additions and 5 deletions
|
@ -128,12 +128,13 @@ UserSchema.statics.statsMapping =
|
|||
'level.system': 'stats.levelSystemMiscPatches'
|
||||
'thang.type': 'stats.thangTypeMiscPatches'
|
||||
|
||||
# TODO Ruben make this not use update in order to go through the middleware
|
||||
UserSchema.statics.incrementStat = (id, statName, done, inc=1) ->
|
||||
update = $inc: {}
|
||||
update.$inc[statName] = inc
|
||||
@update {_id:id}, update, {}, (err) ->
|
||||
done err if done?
|
||||
@findById id, (err, User) ->
|
||||
User.incrementStat statName, done, inc=1
|
||||
|
||||
UserSchema.methods.incrementStat = (statName, done, inc=1) ->
|
||||
@set statName, (@get(statName) or 0) + inc
|
||||
@save (err) -> done err if done?
|
||||
|
||||
UserSchema.pre('save', (next) ->
|
||||
@set('emailLower', @get('email')?.toLowerCase())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue