fix: add a fallback for fullstack cert (#37065)

* fix: add a fallback for fullstack cert completion

* fix: optimize loop over completedChallengs

* fix: try to make more declarative

* fix: move variable to config

* fix: use node exports

Co-authored-by: moT01 <tmondloch01@gmail.com>
Co-authored-by: Oliver Eyton-Williams <ojeytonwilliams@gmail.com>
This commit is contained in:
Ahmad Abdolsaheb
2020-03-26 11:57:15 +03:00
committed by GitHub
parent 2b1e02daf3
commit 4c14e3f396
2 changed files with 14 additions and 3 deletions

View File

@ -21,6 +21,7 @@ import {
infosecQaId,
fullStackId
} from '../utils/constantStrings.json';
import { oldDataVizId } from '../../../config/misc';
import certTypes from '../utils/certTypes.json';
import superBlockCertTypeMap from '../utils/superBlockCertTypeMap';
import { completeCommitment$ } from '../utils/commit';
@ -437,12 +438,10 @@ function createShowCert(app) {
let { completedDate = new Date() } = certChallenge || {};
// the challenge id has been rotated for isDataVisCert
// so we need to check for id 561add10cb82ac38a17513b3
if (certType === 'isDataVisCert' && !certChallenge) {
console.log('olderId');
let oldDataVisIdChall = _.find(
completedChallenges,
({ id }) => '561add10cb82ac38a17513b3' === id
({ id }) => oldDataVizId === id
);
if (oldDataVisIdChall) {
@ -450,6 +449,17 @@ function createShowCert(app) {
}
}
// if fullcert is not found, return the latest completedDate
if (certType === 'isFullStackCert' && !certChallenge) {
var chalIds = [...Object.values(certIds), oldDataVizId];
const latestCertDate = completedChallenges
.filter(chal => chalIds.includes(chal.id))
.sort((a, b) => a.completedDate < b.completedDate)[0].completedDate;
completedDate = latestCertDate ? latestCertDate : completedDate;
}
const { username, name } = user;
return res.json({
certTitle,

1
config/misc.js Normal file
View File

@ -0,0 +1 @@
exports.oldDataVizId = '561add10cb82ac38a17513b3';