Change verify cert to back end

This commit is contained in:
Berkeley Martinez
2015-12-09 14:34:33 -08:00
parent c8e7b7d682
commit 107f42e8f4

View File

@@ -14,8 +14,8 @@ import {
} from '../utils/rx'; } from '../utils/rx';
import { import {
frontEndChallangeId, frontEndChallengeId,
fullStackChallangeId backEndChallengeId
} from '../utils/constantStrings.json'; } from '../utils/constantStrings.json';
import { import {
@@ -27,11 +27,8 @@ const sendMessageToNonUser = ifNoUserSend(
'must be logged in to complete.' 'must be logged in to complete.'
); );
function isCertified(frontEndIds, { completedChallenges, isFrontEndCert }) { function isCertified(ids, { completedChallenges }) {
if (isFrontEndCert) { return _.every(ids, ({ id }) => {
return true;
}
return _.every(frontEndIds, ({ id }) => {
return _.some(completedChallenges, (challenge) => { return _.some(completedChallenges, (challenge) => {
return challenge.id === id || challenge._id === id; return challenge.id === id || challenge._id === id;
}); });
@@ -42,10 +39,10 @@ export default function certificate(app) {
const router = app.loopback.Router(); const router = app.loopback.Router();
const { Challenge } = app.models; const { Challenge } = app.models;
const frontEndChallangeIds$ = observeQuery( const frontEndChallengeIds$ = observeQuery(
Challenge, Challenge,
'findById', 'findById',
frontEndChallangeId, frontEndChallengeId,
{ {
id: true, id: true,
tests: true, tests: true,
@@ -55,10 +52,10 @@ export default function certificate(app) {
) )
.shareReplay(); .shareReplay();
const fullStackChallangeIds$ = observeQuery( const backEndChallengeIds$ = observeQuery(
Challenge, Challenge,
'findById', 'findById',
fullStackChallangeId, backEndChallengeId,
{ {
id: true, id: true,
tests: true, tests: true,
@@ -75,7 +72,7 @@ export default function certificate(app) {
); );
router.post( router.post(
'/certificate/verify/full-stack', '/certificate/verify/back-end',
ifNoUser401, ifNoUser401,
verifyCert verifyCert
); );
@@ -93,9 +90,9 @@ export default function certificate(app) {
Observable.just({}) Observable.just({})
.flatMap(() => { .flatMap(() => {
if (isFront) { if (isFront) {
return frontEndChallangeIds$; return frontEndChallengeIds$;
} }
return fullStackChallangeIds$; return backEndChallengeIds$;
}) })
.flatMap(challenge => { .flatMap(challenge => {
const { user } = req; const { user } = req;
@@ -106,14 +103,21 @@ export default function certificate(app) {
challengeType challengeType
} = challenge; } = challenge;
if ( if (
isFront && !user.isFrontEndCert && isCertified(tests, user) ||
!isFront && !user.isFullStackCert && isCertified(tests, user) isFront &&
!user.isFrontEndCert &&
isCertified(tests, user) ||
!isFront &&
!user.isBackEndCert &&
isCertified(tests, user)
) { ) {
debug('certified'); debug('certified');
if (isFront) { if (isFront) {
user.isFrontEndCert = true; user.isFrontEndCert = true;
} else { } else {
user.isFullStackCert = true; user.isBackEndCert = true;
} }
user.completedChallenges.push({ user.completedChallenges.push({
@@ -143,7 +147,7 @@ export default function certificate(app) {
user => { user => {
if ( if (
isFront && user.isFrontEndCert || isFront && user.isFrontEndCert ||
!isFront && user.isFullStackCert !isFront && user.isBackEndCert
) { ) {
return res.status(200).send(true); return res.status(200).send(true);
} }