Fix cert look up causing crash
This commit is contained in:
@ -307,14 +307,8 @@ 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)
|
return findUserByUsername$(username, {
|
||||||
.flatMap(user => {
|
|
||||||
if (user && user.username === username) {
|
|
||||||
return Observable.just(user);
|
|
||||||
}
|
|
||||||
return findUserByUsername$(username, {
|
|
||||||
isGithubCool: true,
|
isGithubCool: true,
|
||||||
isCheater: true,
|
isCheater: true,
|
||||||
isLocked: true,
|
isLocked: 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],
|
||||||
|
Reference in New Issue
Block a user