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:
@ -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
1
config/misc.js
Normal file
@ -0,0 +1 @@
|
||||
exports.oldDataVizId = '561add10cb82ac38a17513b3';
|
Reference in New Issue
Block a user