Fix cert look up causing crash

This commit is contained in:
Berkeley Martinez
2016-02-11 13:46:11 -08:00
parent 93489c3fd9
commit ee1f1c3d5c

View File

@ -307,13 +307,7 @@ module.exports = function(app) {
function showCert(certType, req, res, next) { function showCert(certType, req, res, next) {
const username = req.params.username.toLowerCase(); const username = req.params.username.toLowerCase();
const { user } = req;
const certId = certIds[certType]; const certId = certIds[certType];
Observable.just(user)
.flatMap(user => {
if (user && user.username === username) {
return Observable.just(user);
}
return findUserByUsername$(username, { return findUserByUsername$(username, {
isGithubCool: true, isGithubCool: true,
isCheater: true, isCheater: true,
@ -325,11 +319,10 @@ module.exports = function(app) {
isHonest: true, isHonest: true,
username: true, username: true,
name: true, name: true,
[ `challengesMap.${certId}` ]: true challengeMap: true
});
}) })
.subscribe( .subscribe(
(user) => { user => {
if (!user) { if (!user) {
req.flash('errors', { req.flash('errors', {
msg: `We couldn't find the user with the username ${username}` msg: `We couldn't find the user with the username ${username}`
@ -378,8 +371,8 @@ module.exports = function(app) {
if (user[certType]) { if (user[certType]) {
const { completedDate = new Date() } = const { challengeMap = {} } = user;
user.challengeMap[certId] || {}; const { completedDate = new Date() } = challengeMap[certId] || {};
return res.render( return res.render(
certViews[certType], certViews[certType],