2015-10-07 04:08:24 +00:00
|
|
|
import dedent from 'dedent';
|
|
|
|
import debugFactory from 'debug';
|
|
|
|
import { Observable } from 'rx';
|
|
|
|
import commitGoals from './commit-goals.json';
|
2016-06-24 03:05:30 +00:00
|
|
|
|
2016-01-27 19:34:44 +00:00
|
|
|
const debug = debugFactory('fcc:utils/commit');
|
2015-10-07 04:08:24 +00:00
|
|
|
|
|
|
|
export { commitGoals };
|
|
|
|
|
|
|
|
export function completeCommitment$(user) {
|
2016-01-11 23:58:37 +00:00
|
|
|
const {
|
|
|
|
isFrontEndCert,
|
|
|
|
isDataVisCert,
|
|
|
|
isBackEndCert,
|
|
|
|
isFullStackCert
|
|
|
|
} = user;
|
|
|
|
|
2015-10-07 04:08:24 +00:00
|
|
|
return Observable.fromNodeCallback(user.pledge, user)()
|
|
|
|
.flatMap(pledge => {
|
|
|
|
if (!pledge) {
|
|
|
|
return Observable.just('No pledge found');
|
|
|
|
}
|
|
|
|
|
|
|
|
const { goal } = pledge;
|
|
|
|
|
|
|
|
if (
|
2016-01-11 23:58:37 +00:00
|
|
|
(isFrontEndCert && goal === commitGoals.frontEndCert) ||
|
|
|
|
(isDataVisCert && goal === commitGoals.dataVisCert) ||
|
|
|
|
(isBackEndCert && goal === commitGoals.backEndCert) ||
|
|
|
|
(isFullStackCert && goal === commitGoals.fullStackCert)
|
2015-10-07 04:08:24 +00:00
|
|
|
) {
|
|
|
|
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.
|
|
|
|
`);
|
|
|
|
});
|
|
|
|
}
|