Add on certification, complete goal and stop pledge

This commit is contained in:
Berkeley Martinez
2015-10-06 21:08:24 -07:00
parent 49c06b266e
commit 2864f607cc
4 changed files with 62 additions and 25 deletions

View File

@ -18,6 +18,10 @@ import {
fullStackChallangeId fullStackChallangeId
} from '../utils/constantStrings.json'; } from '../utils/constantStrings.json';
import {
completeCommitment$
} from '../utils/commit';
const debug = debugFactory('freecc:certification'); const debug = debugFactory('freecc:certification');
const sendMessageToNonUser = ifNoUserSend( const sendMessageToNonUser = ifNoUserSend(
'must be logged in to complete.' 'must be logged in to complete.'
@ -114,7 +118,20 @@ export default function certificate(app) {
completedDate: new Date(), completedDate: new Date(),
challengeType challengeType
}); });
return saveUser(user); return saveUser(user)
// If user has commited to nonprofit,
// this will complete his pledge
.flatMap(
user => completeCommitment$(user),
(user, pledgeOrMessage) => {
if (typeof pledgeOrMessage === 'string') {
debug(pledgeOrMessage);
}
// we are only interested in the user object
// so we ignore return from completeCommitment$
return user;
}
);
} }
return Observable.just(user); return Observable.just(user);
}) })

View File

@ -4,7 +4,10 @@ import debugFactory from 'debug';
import dedent from 'dedent'; import dedent from 'dedent';
import nonprofits from '../utils/commit.json'; import nonprofits from '../utils/commit.json';
import commitGoals from '../utils/commit-goals.json'; import {
commitGoals,
completeCommitment$
} from '../utils/commit';
import { import {
unDasherize unDasherize
@ -116,7 +119,7 @@ export default function commit(app) {
const { const {
nonprofit: nonprofitName = 'girl develop it', nonprofit: nonprofitName = 'girl develop it',
amount = '5', amount = '5',
goal = 'Front End Development Certification' goal = commitGoals.frontEndCert
} = req.query; } = req.query;
const nonprofit = findNonprofit(nonprofitName); const nonprofit = findNonprofit(nonprofitName);
@ -166,27 +169,8 @@ export default function commit(app) {
function completeCommitment(req, res, next) { function completeCommitment(req, res, next) {
const { user } = req; const { user } = req;
const { isFrontEndCert, isFullStackCert } = user;
observeQuery(user, 'pledge') return completeCommitment$(user)
.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( .subscribe(
msgOrPledge => { msgOrPledge => {
if (typeof msgOrPledge === 'string') { if (typeof msgOrPledge === 'string') {

36
server/utils/commit.js Normal file
View File

@ -0,0 +1,36 @@
import dedent from 'dedent';
import debugFactory from 'debug';
import { Observable } from 'rx';
import commitGoals from './commit-goals.json';
const debug = debugFactory('freecc:utils/commit');
export { commitGoals };
export function completeCommitment$(user) {
const { isFrontEndCert, isFullStackCert } = user;
return Observable.fromNodeCallback(user.pledge, user)()
.flatMap(pledge => {
if (!pledge) {
return Observable.just('No pledge found');
}
const { goal } = pledge;
if (
isFrontEndCert && goal === commitGoals.frontEndCert ||
isFullStackCert && goal === commitGoals.fullStackCert
) {
debug('marking goal complete');
pledge.isCompleted = true;
pledge.dateEnded = new Date();
pledge.formerUserId = pledge.userId;
pledge.userId = null;
return Observable.fromNodeCallback(pledge.save, pledge)();
}
return Observable.just(dedent`
You have not yet reached your goal of completing the ${goal}
Please retry when you have met the requirements.
`);
});
}

View File

@ -23,10 +23,10 @@ block content
h4 Choose your goal: h4 Choose your goal:
.btn-group.btn-group-justified(data-toggle='buttons' role='group') .btn-group.btn-group-justified(data-toggle='buttons' role='group')
label.btn.btn-primary.btn-lg.active label.btn.btn-primary.btn-lg.active
input(type='radio' id=frontEndCert value='Front End Development Certification' name='goal' checked="checked") input(type='radio' id=frontEndCert value=frontEndCert name='goal' checked="checked")
| Front End Development Certificate (takes about 400 hours) | Front End Development Certificate (takes about 400 hours)
label.btn.btn-primary.btn-lg label.btn.btn-primary.btn-lg
input(type='radio' id=fullStackCert value='Full Stack Development Certification' name='goal') input(type='radio' id=fullStackCert value=fullStackCert name='goal')
| Full Stack Development Certificate (takes about 800 hours) | Full Stack Development Certificate (takes about 800 hours)
.spacer .spacer
.row .row