diff --git a/server/boot/commit.js b/server/boot/commit.js index ef2ce5d6ba..b15a02468b 100644 --- a/server/boot/commit.js +++ b/server/boot/commit.js @@ -2,7 +2,9 @@ import _ from 'lodash'; import { Observable } from 'rx'; import debugFactory from 'debug'; import dedent from 'dedent'; + import nonprofits from '../utils/commit.json'; +import commitGoals from '../utils/commit-goals.json'; import { unDasherize @@ -57,6 +59,12 @@ export default function commit(app) { stopCommit ); + router.post( + '/commit/complete-goal', + sendNonUserToCommit, + completeCommitment + ); + app.use(router); function commitToNonprofit(req, res, next) { @@ -90,7 +98,9 @@ export default function commit(app) { Object.assign( { title: 'Commit to a nonprofit. Commit to your goal.', - pledge + pledge, + frontEndCert: commitGoals.frontEndCert, + fullStackCert: commitGoals.fullStackCert }, nonprofit ) @@ -154,6 +164,40 @@ export default function commit(app) { ); } + function completeCommitment(req, res, next) { + const { user } = req; + const { isFrontEndCert, isFullStackCert } = user; + + observeQuery(user, 'pledge') + .flatMap(pledge => { + const { goal } = pledge; + if (!pledge) { + return Observable.just('No pledge found'); + } + if ( + isFrontEndCert && goal === commitGoals.frontEndCert || + isFullStackCert && goal === commitGoals.fullStackCert + ) { + pledge.isCompleted = true; + pledge.dateEnded = new Date(); + return saveInstance(pledge); + } + return Observable.just(dedent` + You have not yet reached your goal of completing the ${goal} + Please retry when you have met the requirements. + `); + }) + .subscribe( + msgOrPledge => { + if (typeof msgOrPledge === 'string') { + return res.send(msgOrPledge); + } + return res.send(true); + }, + next + ); + } + function stopCommit(req, res, next) { const { user } = req; diff --git a/server/utils/commit-goals.json b/server/utils/commit-goals.json new file mode 100644 index 0000000000..8391145e6b --- /dev/null +++ b/server/utils/commit-goals.json @@ -0,0 +1,4 @@ +{ + "frontEndCert": "front-end-development-certificate", + "fullStackCert": "full-stack-development-certificate" +} diff --git a/server/views/commit/index.jade b/server/views/commit/index.jade index 014275a608..591c285919 100644 --- a/server/views/commit/index.jade +++ b/server/views/commit/index.jade @@ -23,10 +23,10 @@ block content h4 Choose your goal: .btn-group.btn-group-justified(data-toggle='buttons' role='group') label.btn.btn-primary.btn-lg.active - input(type='radio' id='front-end-development-certificate' value='Front End Development Certification' name='goal' checked="checked") + input(type='radio' id=frontEndCert value='Front End Development Certification' name='goal' checked="checked") | Front End Development Certificate (takes about 400 hours) label.btn.btn-primary.btn-lg - input(type='radio' id='full-stack-development-certificate' value='Full Stack Development Certification' name='goal') + input(type='radio' id=fullStackCert value='Full Stack Development Certification' name='goal') | Full Stack Development Certificate (takes about 800 hours) .spacer .row