user: load the resource with middleware
This commit is contained in:
@@ -265,10 +265,11 @@ function update(userId, user, callback) {
|
||||
}
|
||||
args.push(userId);
|
||||
|
||||
database.query('UPDATE users SET ' + fields.join(', ') + ' WHERE id = ?', args, function (error) {
|
||||
database.query('UPDATE users SET ' + fields.join(', ') + ' WHERE id = ?', args, function (error, result) {
|
||||
if (error && error.code === 'ER_DUP_ENTRY' && error.sqlMessage.indexOf('users_email') !== -1) return callback(new BoxError(BoxError.ALREADY_EXISTS, 'email already exists'));
|
||||
if (error && error.code === 'ER_DUP_ENTRY' && error.sqlMessage.indexOf('users_username') !== -1) return callback(new BoxError(BoxError.ALREADY_EXISTS, 'username already exists'));
|
||||
if (error) return callback(new BoxError(BoxError.DATABASE_ERROR, error));
|
||||
if (result.affectedRows !== 1) return callback(new BoxError(BoxError.NOT_FOUND, 'User not found'));
|
||||
|
||||
return callback(null);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user