challenge/user router now works with challengeMap

This commit is contained in:
Berkeley Martinez
2016-02-09 14:33:25 -08:00
parent 07d54a455c
commit 76cfbdf752
4 changed files with 204 additions and 212 deletions

View File

@ -52,6 +52,12 @@ module.exports = function(User) {
User.validatesUniquenessOf('username');
User.settings.emailVerificationRequired = false;
User.on('dataSourceAttached', () => {
User.findOne$ = Observable.fromNodeCallback(User.findOne, User);
User.update$ = Observable.fromNodeCallback(User.updateAll, User);
User.count$ = Observable.fromNodeCallback(User.count, User);
});
User.observe('before save', function({ instance: user }, next) {
if (user) {
user.username = user.username.trim().toLowerCase();
@ -416,4 +422,21 @@ module.exports = function(User) {
}
}
);
// user.updateTo$(updateData: Object) => Observable[Number]
User.prototype.update$ = function update$(updateData) {
const id = this.getId();
const updateOptions = { allowExtendedOperators: true };
if (
!updateData ||
typeof updateData !== 'object' ||
Object.keys(updateData).length > 0
) {
return Observable.throw(new Error(
`updateData must be an object with at least on key,
but got ${updateData}`.split('\n').join(' ')
));
}
return this.constructor.update$({ id }, updateData, updateOptions);
};
};