feat(api): decouple api from curriculum (#40703)
This commit is contained in:
committed by
GitHub
parent
f4bbe3f34c
commit
c077ffe4b9
@@ -1,30 +0,0 @@
|
||||
import { flatten } from 'lodash';
|
||||
|
||||
import { getChallengesForLang } from '../../../curriculum/getChallenges';
|
||||
|
||||
// TODO: this caching is handy if we want to field requests that need to 'query'
|
||||
// the curriculum, but if we force the client to handle
|
||||
// redirectToCurrentChallenge and, instead, only report the current challenge
|
||||
// id via the user object, then we should *not* store this so it can be garbage
|
||||
// collected.
|
||||
|
||||
let curriculum;
|
||||
export async function getCurriculum() {
|
||||
// NOTE: this is always 'english' because we are only interested in the slugs
|
||||
// and those should not change between the languages.
|
||||
curriculum = curriculum ? curriculum : getChallengesForLang('english');
|
||||
return curriculum;
|
||||
}
|
||||
|
||||
export async function getChallenges() {
|
||||
return getCurriculum().then(curriculum => {
|
||||
return Object.keys(curriculum)
|
||||
.map(key => curriculum[key].blocks)
|
||||
.reduce((challengeArray, superBlock) => {
|
||||
const challengesForBlock = Object.keys(superBlock).map(
|
||||
key => superBlock[key].challenges
|
||||
);
|
||||
return [...challengeArray, ...flatten(challengesForBlock)];
|
||||
}, []);
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user