Add complete commit endpoint
This commit is contained in:
@ -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;
|
||||
|
||||
|
4
server/utils/commit-goals.json
Normal file
4
server/utils/commit-goals.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"frontEndCert": "front-end-development-certificate",
|
||||
"fullStackCert": "full-stack-development-certificate"
|
||||
}
|
@ -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
|
||||
|
Reference in New Issue
Block a user