refactor(services/use): Simplify logic declaritively
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
import debug from 'debug';
|
||||
import _ from 'lodash';
|
||||
// import debug from 'debug';
|
||||
// use old rxjs
|
||||
import { Observable } from 'rx';
|
||||
|
||||
const publicUserProps = [
|
||||
'id',
|
||||
@ -35,21 +37,20 @@ const publicUserProps = [
|
||||
'currentChallengeId',
|
||||
'challengeMap'
|
||||
];
|
||||
const log = debug('fcc:services:user');
|
||||
|
||||
// const log = debug('fcc:services:user');
|
||||
|
||||
export default function userServices() {
|
||||
return {
|
||||
name: 'user',
|
||||
read: (req, resource, params, config, cb) => {
|
||||
let { user } = req;
|
||||
if (user) {
|
||||
log('user is signed in');
|
||||
return user.getChallengeMap$()
|
||||
const { user } = req;
|
||||
Observable.if(
|
||||
() => !user,
|
||||
Observable.of({}),
|
||||
user.getChallengeMap$()
|
||||
.map(challengeMap => ({ ...user.toJSON(), challengeMap }))
|
||||
.subscribe(
|
||||
user => cb(
|
||||
null,
|
||||
{
|
||||
.map(user => ({
|
||||
entities: {
|
||||
user: {
|
||||
[user.username]: {
|
||||
@ -60,16 +61,12 @@ export default function userServices() {
|
||||
}
|
||||
},
|
||||
result: user.username
|
||||
}
|
||||
),
|
||||
}))
|
||||
)
|
||||
.subscribe(
|
||||
user => cb(null, user),
|
||||
cb
|
||||
);
|
||||
}
|
||||
debug('user is not signed in');
|
||||
// Zalgo!!!
|
||||
return process.nextTick(() => {
|
||||
cb(null, {});
|
||||
});
|
||||
}
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user