diff --git a/src/user.js b/src/user.js index 0a7bd11196..482e9a4cfd 100644 --- a/src/user.js +++ b/src/user.js @@ -196,14 +196,14 @@ var async = require('async'), }; User.setUserField = function(uid, field, value, callback) { - plugins.fireHook('action:user.set', field, value, 'set'); + plugins.fireHook('action:user.set', {field: field, value: value, type: 'set'}); db.setObjectField('user:' + uid, field, value, callback); }; User.setUserFields = function(uid, data, callback) { for (var field in data) { if (data.hasOwnProperty(field)) { - plugins.fireHook('action:user.set', field, data[field], 'set'); + plugins.fireHook('action:user.set', {field: field, value: data[field], type: 'set'}); } } @@ -211,22 +211,26 @@ var async = require('async'), }; User.incrementUserFieldBy = function(uid, field, value, callback) { + callback = callback || function() {}; db.incrObjectFieldBy('user:' + uid, field, value, function(err, value) { - plugins.fireHook('action:user.set', field, value, 'increment'); - - if (typeof callback === 'function') { - callback(err, value); + if (err) { + return callback(err); } + plugins.fireHook('action:user.set', {field: field, value: value, type: 'increment'}); + + callback(null, value); }); }; User.decrementUserFieldBy = function(uid, field, value, callback) { + callback = callback || function() {}; db.incrObjectFieldBy('user:' + uid, field, -value, function(err, value) { - plugins.fireHook('action:user.set', field, value, 'decrement'); - - if (typeof callback === 'function') { - callback(err, value); + if (err) { + return callback(err); } + plugins.fireHook('action:user.set', {field: field, value: value, type: 'decrement'}); + + callback(null, value); }); };