fix(path-map): Refactor pathMigrationMap for new curriculum package

This commit is contained in:
Bouncey
2018-10-07 08:52:41 +01:00
committed by mrugesh mohapatra
parent bc9b3b4ddd
commit d52ba8c6fd
3 changed files with 143 additions and 0 deletions

View File

@ -0,0 +1,25 @@
const { flatten } = require('lodash');
const { dasherize } = require('../../../api-server/server/utils');
function createPathMigrationMap(curriculum) {
return Object.keys(curriculum)
.map(key => curriculum[key].blocks)
.reduce((challenges, current) => {
const superChallenges = Object.keys(current).map(
key => current[key].challenges
);
return challenges.concat(flatten(superChallenges));
}, [])
.filter(({ isPrivate }) => !isPrivate)
.reduce((map, challenge) => {
const { title, block, superBlock } = challenge;
const dashedTitle = dasherize(title);
map[dashedTitle] = `/learn/${dasherize(superBlock)}/${dasherize(
block
)}/${dashedTitle}`;
return map;
}, {});
}
exports.createPathMigrationMap = createPathMigrationMap;