From 202d0fa0683e1351ceace18fe8bb129ede23026b Mon Sep 17 00:00:00 2001 From: Berkeley Martinez Date: Mon, 5 Oct 2015 19:58:44 -0700 Subject: [PATCH] Fix add to completed challenges on cert verify --- server/boot/certificate.js | 42 ++++++++++++++++++++----------- server/utils/constantStrings.json | 4 ++- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/server/boot/certificate.js b/server/boot/certificate.js index ba28cb8a16..b084d9f4b8 100644 --- a/server/boot/certificate.js +++ b/server/boot/certificate.js @@ -13,8 +13,11 @@ import { observeQuery } from '../utils/rx'; -const frontEndChallangeId = '561add10cb82ac38a17513be'; -const fullStackChallangeId = '660add10cb82ac38a17513be'; +import { + frontEndChallangeId, + fullStackChallangeId +} from '../utils/constantStrings.json'; + const debug = debugFactory('freecc:certification'); const sendMessageToNonUser = ifNoUserSend( 'must be logged in to complete.' @@ -36,10 +39,12 @@ export default function certificate(app) { 'findById', frontEndChallangeId, { - tests: true + id: true, + tests: true, + name: true, + challengeType: true } ) - .map(({ tests = [] }) => tests) .shareReplay(); const fullStackChallangeIds$ = observeQuery( @@ -47,10 +52,12 @@ export default function certificate(app) { 'findById', fullStackChallangeId, { - tests: true + id: true, + tests: true, + name: true, + challengeType: true } ) - .map(({ tests = [] }) => tests) .shareReplay(); router.post( @@ -82,8 +89,14 @@ export default function certificate(app) { } return fullStackChallangeIds$; }) - .flatMap((tests) => { + .flatMap(challenge => { const { user } = req; + const { + id, + tests, + name, + challengeType + } = challenge; if ( isFront && !user.isFrontEndCert && isCertified(tests, user) || !isFront && !user.isFullStackCert && isCertified(tests, user) @@ -91,17 +104,16 @@ export default function certificate(app) { debug('certified'); if (isFront) { user.isFrontEndCert = true; - user.completedChallenges.push({ - completedDate: new Date(), - id: frontEndChallangeId - }) } else { user.isFullStackCert = true; - user.completedChallenges.push({ - completedDate: new Date(), - id: fullStackChallangeId - }) } + + user.completedChallenges.push({ + id, + name, + completedDate: new Date(), + challengeType + }); return saveUser(user); } return Observable.just(user); diff --git a/server/utils/constantStrings.json b/server/utils/constantStrings.json index 70f5d9766c..a2f5b29df8 100644 --- a/server/utils/constantStrings.json +++ b/server/utils/constantStrings.json @@ -1,3 +1,5 @@ { - "gitHubUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36" + "gitHubUserAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36", + "frontEndChallangeId": "561add10cb82ac38a17513be", + "fullStackChallangeId": "660add10cb82ac38a17513be" }