mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2025-05-04 09:53:55 -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'
|
'level.system': 'stats.levelSystemMiscPatches'
|
||||||
'thang.type': 'stats.thangTypeMiscPatches'
|
'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) ->
|
UserSchema.statics.incrementStat = (id, statName, done, inc=1) ->
|
||||||
update = $inc: {}
|
@findById id, (err, User) ->
|
||||||
update.$inc[statName] = inc
|
User.incrementStat statName, done, inc=1
|
||||||
@update {_id:id}, update, {}, (err) ->
|
|
||||||
done err if done?
|
UserSchema.methods.incrementStat = (statName, done, inc=1) ->
|
||||||
|
@set statName, (@get(statName) or 0) + inc
|
||||||
|
@save (err) -> done err if done?
|
||||||
|
|
||||||
UserSchema.pre('save', (next) ->
|
UserSchema.pre('save', (next) ->
|
||||||
@set('emailLower', @get('email')?.toLowerCase())
|
@set('emailLower', @get('email')?.toLowerCase())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue