Add on certification, complete goal and stop pledge
This commit is contained in:
@ -18,6 +18,10 @@ import {
|
||||
fullStackChallangeId
|
||||
} from '../utils/constantStrings.json';
|
||||
|
||||
import {
|
||||
completeCommitment$
|
||||
} from '../utils/commit';
|
||||
|
||||
const debug = debugFactory('freecc:certification');
|
||||
const sendMessageToNonUser = ifNoUserSend(
|
||||
'must be logged in to complete.'
|
||||
@ -114,7 +118,20 @@ export default function certificate(app) {
|
||||
completedDate: new Date(),
|
||||
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);
|
||||
})
|
||||
|
@ -4,7 +4,10 @@ import debugFactory from 'debug';
|
||||
import dedent from 'dedent';
|
||||
|
||||
import nonprofits from '../utils/commit.json';
|
||||
import commitGoals from '../utils/commit-goals.json';
|
||||
import {
|
||||
commitGoals,
|
||||
completeCommitment$
|
||||
} from '../utils/commit';
|
||||
|
||||
import {
|
||||
unDasherize
|
||||
@ -116,7 +119,7 @@ export default function commit(app) {
|
||||
const {
|
||||
nonprofit: nonprofitName = 'girl develop it',
|
||||
amount = '5',
|
||||
goal = 'Front End Development Certification'
|
||||
goal = commitGoals.frontEndCert
|
||||
} = req.query;
|
||||
|
||||
const nonprofit = findNonprofit(nonprofitName);
|
||||
@ -166,27 +169,8 @@ 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.
|
||||
`);
|
||||
})
|
||||
return completeCommitment$(user)
|
||||
.subscribe(
|
||||
msgOrPledge => {
|
||||
if (typeof msgOrPledge === 'string') {
|
||||
|
36
server/utils/commit.js
Normal file
36
server/utils/commit.js
Normal 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.
|
||||
`);
|
||||
});
|
||||
}
|
@ -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=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)
|
||||
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)
|
||||
.spacer
|
||||
.row
|
||||
|
Reference in New Issue
Block a user