(levels, isCh1)
| 10 | |
| 11 | // group course/campaign levels by module number |
| 12 | const buildLevelsListByModule = function (levels, isCh1) { |
| 13 | let introBeforeLastCapstoneStageOriginal |
| 14 | if (isCh1 == null) { isCh1 = false } |
| 15 | const levelsModuleMap = {} |
| 16 | // Find the intro before the last capstone stage for CH1 |
| 17 | // since CH1 capstone needs to be placed after that in the levels list |
| 18 | if (isCh1 && levels.find(l => l.isCapstone())) { |
| 19 | const capstoneOriginal = levels.find(l => l.isCapstone()).get('original') |
| 20 | const totalCapstoneStages = 10 // Hardcoding the num of stages since its not available in level data, TODO refactor later |
| 21 | if (capstoneOriginal) { |
| 22 | const introBeforeLastCapstoneStage = levels.find(l => { |
| 23 | const nextLevel = Object.values(l.get('nextLevels') || {})[0] || {} |
| 24 | return (nextLevel.original === capstoneOriginal) && (nextLevel.nextLevelStage === totalCapstoneStages) |
| 25 | }) |
| 26 | introBeforeLastCapstoneStageOriginal = introBeforeLastCapstoneStage != null ? introBeforeLastCapstoneStage.get('original') : undefined |
| 27 | } |
| 28 | } |
| 29 | let capstoneLevel = {} |
| 30 | levels.forEach(l => { |
| 31 | const moduleNumber = l.get('moduleNum') || 1 |
| 32 | if (isCh1 && l.isCapstone()) { |
| 33 | capstoneLevel = new Level(l.attributes) |
| 34 | return capstoneLevel |
| 35 | } else { |
| 36 | if (levelsModuleMap[moduleNumber] == null) { levelsModuleMap[moduleNumber] = [] } |
| 37 | levelsModuleMap[moduleNumber].push(l) |
| 38 | if (isCh1 && introBeforeLastCapstoneStageOriginal && (l.get('original') === introBeforeLastCapstoneStageOriginal)) { |
| 39 | return levelsModuleMap[moduleNumber].push(capstoneLevel) |
| 40 | } |
| 41 | } |
| 42 | }) |
| 43 | return levelsModuleMap |
| 44 | } |
| 45 | |
| 46 | module.exports = { |
| 47 | buildLevelsListByModule |
nothing calls this directly
no test coverage detected