Fix remove bonfire save endpoint
fix completedChallenge saving solution remove unnecessary code.
This commit is contained in:
@ -78,14 +78,10 @@ window.common = (function(global) {
|
||||
var publicURL = $('#public-url').val() || null;
|
||||
var githubURL = $('#github-url').val() || null;
|
||||
switch (common.challengeType) {
|
||||
case common.challengeTypes.HTML:
|
||||
case common.challengeTypes.JS:
|
||||
case common.challengeTypes.VIDEO:
|
||||
data = {
|
||||
challengeInfo: {
|
||||
challengeId: common.challengeId,
|
||||
challengeName: common.challengeName
|
||||
}
|
||||
id: common.challengeId,
|
||||
name: common.challengeName
|
||||
};
|
||||
$.post('/completed-challenge/', data)
|
||||
.success(function(res) {
|
||||
|
@ -16,7 +16,7 @@ window.common = (function(global) {
|
||||
common.challengeName + ', Time: ' + time + ', Attempts: ' + 0
|
||||
);
|
||||
|
||||
var bonfireSolution = common.editor.getValue();
|
||||
var solution = common.editor.getValue();
|
||||
var didCompleteWith = $('#completed-with').val() || null;
|
||||
|
||||
$('#complete-courseware-dialog').modal('show');
|
||||
@ -46,23 +46,20 @@ window.common = (function(global) {
|
||||
next();
|
||||
});
|
||||
|
||||
$.post(
|
||||
'/completed-bonfire/', {
|
||||
challengeInfo: {
|
||||
challengeId: common.challengeId,
|
||||
challengeName: common.challengeName,
|
||||
const data = {
|
||||
id: common.challengeId,
|
||||
name: common.challengeName,
|
||||
completedWith: didCompleteWith,
|
||||
challengeType: common.challengeType,
|
||||
solution: bonfireSolution
|
||||
}
|
||||
},
|
||||
function(res) {
|
||||
solution
|
||||
};
|
||||
|
||||
$.post('/completed-challenge/', data, function(res) {
|
||||
if (res) {
|
||||
window.location =
|
||||
'/challenges/next-challenge?id=' + common.challengeId;
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -169,12 +169,10 @@ window.common = (function({ $, common = { init: [] }}) {
|
||||
});
|
||||
|
||||
$.post(
|
||||
'/completed-bonfire/', {
|
||||
challengeInfo: {
|
||||
challengeId: common.challengeId,
|
||||
challengeName: common.challengeName,
|
||||
'/completed-challenge/', {
|
||||
id: common.challengeId,
|
||||
name: common.challengeName,
|
||||
challengeType: common.challengeType
|
||||
}
|
||||
},
|
||||
function(res) {
|
||||
if (res) {
|
||||
|
@ -41,14 +41,6 @@ const challengeView = {
|
||||
7: 'coursewares/showStep'
|
||||
};
|
||||
|
||||
/*
|
||||
function makeChallengesUnique(challengeArr) {
|
||||
// clone and reverse challenges
|
||||
// then filter by unique id's
|
||||
// then reverse again
|
||||
return _.uniq(challengeArr.slice().reverse(), 'id').reverse();
|
||||
}
|
||||
*/
|
||||
function numberWithCommas(x) {
|
||||
return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
||||
}
|
||||
@ -56,14 +48,6 @@ function numberWithCommas(x) {
|
||||
function updateUserProgress(user, challengeId, completedChallenge) {
|
||||
let { completedChallenges } = user;
|
||||
|
||||
// migrate user challenges object to remove
|
||||
/* if (!user.isUniqMigrated) {
|
||||
user.isUniqMigrated = true;
|
||||
|
||||
completedChallenges = user.completedChallenges =
|
||||
makeChallengesUnique(completedChallenges);
|
||||
}*/
|
||||
|
||||
const indexOfChallenge = _.findIndex(completedChallenges, {
|
||||
id: challengeId
|
||||
});
|
||||
@ -153,11 +137,6 @@ module.exports = function(app) {
|
||||
send200toNonUser,
|
||||
completedZiplineOrBasejump
|
||||
);
|
||||
router.post(
|
||||
'/completed-bonfire',
|
||||
send200toNonUser,
|
||||
completedBonfire
|
||||
);
|
||||
|
||||
router.get('/map', challengeMap);
|
||||
router.get(
|
||||
@ -342,95 +321,25 @@ module.exports = function(app) {
|
||||
);
|
||||
}
|
||||
|
||||
function completedBonfire(req, res, next) {
|
||||
debug('compltedBonfire');
|
||||
var completedWith = req.body.challengeInfo.completedWith || false;
|
||||
var challengeId = req.body.challengeInfo.challengeId;
|
||||
|
||||
var challengeData = {
|
||||
id: challengeId,
|
||||
name: req.body.challengeInfo.challengeName || '',
|
||||
completedDate: Math.round(+new Date()),
|
||||
solution: req.body.challengeInfo.solution,
|
||||
challengeType: 5
|
||||
};
|
||||
|
||||
observeQuery(
|
||||
User,
|
||||
'findOne',
|
||||
{ where: { username: ('' + completedWith).toLowerCase() } }
|
||||
)
|
||||
.doOnNext(function(pairedWith) {
|
||||
debug('paired with ', pairedWith);
|
||||
if (pairedWith) {
|
||||
updateUserProgress(
|
||||
pairedWith,
|
||||
challengeId,
|
||||
assign({ completedWith: req.user.id }, challengeData)
|
||||
);
|
||||
}
|
||||
})
|
||||
.withLatestFrom(
|
||||
Observable.just(req.user),
|
||||
function(pairedWith, user) {
|
||||
return {
|
||||
user: user,
|
||||
pairedWith: pairedWith
|
||||
};
|
||||
}
|
||||
)
|
||||
// side effects should always be done in do's and taps
|
||||
.doOnNext(function(dats) {
|
||||
updateUserProgress(
|
||||
dats.user,
|
||||
challengeId,
|
||||
dats.pairedWith ?
|
||||
// paired programmer found and adding to data
|
||||
assign({ completedWith: dats.pairedWith.id }, challengeData) :
|
||||
// user said they paired, but pair wasn't found
|
||||
challengeData
|
||||
);
|
||||
})
|
||||
// iterate users
|
||||
.flatMap(function(dats) {
|
||||
debug('flatmap');
|
||||
return Observable.from([dats.user, dats.pairedWith]);
|
||||
})
|
||||
// save user
|
||||
.flatMap(function(user) {
|
||||
// save user will do nothing if user is falsey
|
||||
return saveUser(user);
|
||||
})
|
||||
.subscribe(
|
||||
function(user) {
|
||||
debug('onNext');
|
||||
if (user) {
|
||||
debug('user %s saved', user.username);
|
||||
}
|
||||
},
|
||||
next,
|
||||
function() {
|
||||
debug('completed');
|
||||
return res.status(200).send(true);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
function completedChallenge(req, res, next) {
|
||||
|
||||
const completedDate = Math.round(+new Date());
|
||||
const { id, name } = req.body;
|
||||
const { challengeId, challengeName } = req.body.challengeInfo || {};
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
challengeType,
|
||||
solution
|
||||
} = req.body;
|
||||
|
||||
updateUserProgress(
|
||||
req.user,
|
||||
id || challengeId,
|
||||
id,
|
||||
{
|
||||
id: id || challengeId,
|
||||
completedDate: completedDate,
|
||||
name: name || challengeName || '',
|
||||
solution: null,
|
||||
githubLink: null,
|
||||
id,
|
||||
challengeType,
|
||||
solution,
|
||||
name,
|
||||
completedDate,
|
||||
verified: true
|
||||
}
|
||||
);
|
||||
|
Reference in New Issue
Block a user