Revert "Fix give-brownie-points/about API DB queries"

This commit is contained in:
Berkeley Martinez
2016-04-14 17:07:40 -07:00
parent 190a10e190
commit 17915e7ecf
2 changed files with 78 additions and 137 deletions

View File

@@ -1,4 +1,3 @@
import { Observable } from 'rx';
import passport from 'passport';
import { PassportConfigurator } from 'loopback-component-passport';
import passportProviders from './passport-providers';
@@ -71,21 +70,22 @@ PassportConfigurator.prototype.init = function passportInit(noSession) {
});
passport.deserializeUser((id, done) => {
Observable.combineLatest(
this.userModel.findById$(id, { fields }),
this.userModel.getPointsById$(id),
(user, points) => {
if (user) { user.points = points; }
return user;
this.userModel.findById(id, { fields }, (err, user) => {
if (err || !user) {
return done(err, user);
}
)
.doOnNext(user => {
if (!user) { throw new Error('deserialize found no user'); }
})
.subscribe(
user => done(null, user),
done
);
return this.app.dataSources.db.connector
.collection('user')
.aggregate([
{ $match: { _id: user.id } },
{ $project: { points: { $size: '$progressTimestamps' } } }
], function(err, [{ points = 1 } = {}]) {
if (err) { return done(err); }
user.points = points;
return done(null, user);
});
});
});
};