Submit simple project (previously known as video challegnes)
This commit is contained in:
@ -129,10 +129,49 @@ function submitProject(type, state, { solution, githubLink }) {
|
|||||||
return Observable.merge(saveChallenge$, challengeCompleted$);
|
return Observable.merge(saveChallenge$, challengeCompleted$);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function submitSimpleProject(type, state) {
|
||||||
|
const {
|
||||||
|
challenge: { id }
|
||||||
|
} = challengeSelector(state);
|
||||||
|
const {
|
||||||
|
app: { isSignedIn, csrfToken }
|
||||||
|
} = state;
|
||||||
|
const body = {
|
||||||
|
id,
|
||||||
|
_csrf: csrfToken
|
||||||
|
};
|
||||||
|
const saveChallenge$ = postJSON$('/challenge-completed', body)
|
||||||
|
.retry(3)
|
||||||
|
.flatMap(({ alreadyCompleted, points }) => {
|
||||||
|
return Observable.of(
|
||||||
|
makeToast({
|
||||||
|
message:
|
||||||
|
'Challenge saved.' +
|
||||||
|
(alreadyCompleted ? '' : ' First time Completed!'),
|
||||||
|
title: 'Saved',
|
||||||
|
type: 'info'
|
||||||
|
}),
|
||||||
|
updatePoints(points)
|
||||||
|
);
|
||||||
|
})
|
||||||
|
.catch(createErrorObservable);
|
||||||
|
|
||||||
|
const challengeCompleted$ = Observable.of(
|
||||||
|
makeToast({
|
||||||
|
title: randomCompliment(),
|
||||||
|
message: isSignedIn ? ' Saving...' : 'Moving on to next challenge.',
|
||||||
|
type: 'success'
|
||||||
|
})
|
||||||
|
// moveToNextChallenge()
|
||||||
|
);
|
||||||
|
return Observable.merge(saveChallenge$, challengeCompleted$);
|
||||||
|
}
|
||||||
|
|
||||||
const submitTypes = {
|
const submitTypes = {
|
||||||
tests: submitModern,
|
tests: submitModern,
|
||||||
'project.frontEnd': submitProject,
|
'project.frontEnd': submitProject,
|
||||||
'project.backEnd': submitProject
|
'project.backEnd': submitProject,
|
||||||
|
'project.simple': submitSimpleProject
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function completionSaga(actions$, getState) {
|
export default function completionSaga(actions$, getState) {
|
||||||
|
@ -68,12 +68,20 @@ module.exports = function(app) {
|
|||||||
modernChallengeCompleted
|
modernChallengeCompleted
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// deprecate endpoint
|
||||||
|
// remove once new endpoint is live
|
||||||
router.post(
|
router.post(
|
||||||
'/completed-challenge',
|
'/completed-challenge',
|
||||||
send200toNonUser,
|
send200toNonUser,
|
||||||
completedChallenge
|
completedChallenge
|
||||||
);
|
);
|
||||||
|
|
||||||
|
router.post(
|
||||||
|
'/challenge-completed',
|
||||||
|
send200toNonUser,
|
||||||
|
completedChallenge
|
||||||
|
);
|
||||||
|
|
||||||
// deprecate endpoint
|
// deprecate endpoint
|
||||||
// remove once new endpoint is live
|
// remove once new endpoint is live
|
||||||
router.post(
|
router.post(
|
||||||
@ -144,11 +152,7 @@ module.exports = function(app) {
|
|||||||
|
|
||||||
function completedChallenge(req, res, next) {
|
function completedChallenge(req, res, next) {
|
||||||
req.checkBody('id', 'id must be an ObjectId').isMongoId();
|
req.checkBody('id', 'id must be an ObjectId').isMongoId();
|
||||||
req.checkBody('challengeType', 'challengeType must be an integer')
|
|
||||||
.isNumber();
|
|
||||||
|
|
||||||
const type = accepts(req).type('html', 'json', 'text');
|
const type = accepts(req).type('html', 'json', 'text');
|
||||||
|
|
||||||
const errors = req.validationErrors(true);
|
const errors = req.validationErrors(true);
|
||||||
|
|
||||||
if (errors) {
|
if (errors) {
|
||||||
|
Reference in New Issue
Block a user