From 4c14e3f3965be359936fc05006773d9031ebc25d Mon Sep 17 00:00:00 2001 From: Ahmad Abdolsaheb Date: Thu, 26 Mar 2020 11:57:15 +0300 Subject: [PATCH] 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 Co-authored-by: Oliver Eyton-Williams --- api-server/server/boot/certificate.js | 16 +++++++++++++--- config/misc.js | 1 + 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 config/misc.js diff --git a/api-server/server/boot/certificate.js b/api-server/server/boot/certificate.js index 3e0b91b39b..d5ca128c5c 100644 --- a/api-server/server/boot/certificate.js +++ b/api-server/server/boot/certificate.js @@ -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, diff --git a/config/misc.js b/config/misc.js new file mode 100644 index 0000000000..8ecedeef31 --- /dev/null +++ b/config/misc.js @@ -0,0 +1 @@ +exports.oldDataVizId = '561add10cb82ac38a17513b3';