Fix(routing): add protections against malformed data

This commit is contained in:
Berkeley Martinez
2016-08-05 14:49:23 -07:00
parent 91a50b4843
commit 3d05eee0ea
4 changed files with 84 additions and 55 deletions

View File

@@ -0,0 +1,44 @@
import emptyProtector from '../app/utils/empty-protector';
export function checkMapData(
{
entities: {
challenge,
block,
superBlock,
challengeIdToName
},
result
}
) {
if (
!challenge ||
!block ||
!superBlock ||
!challengeIdToName ||
!result ||
!result.length
) {
throw new Error(
'entities not found, db may not be properly seeded. Crashing hard'
);
}
}
// getFirstChallenge(
// map: {
// entities: { challenge: Object, block: Object, superBlock: Object },
// result: [...superBlockDashedName: String]
// }
// ) => Challenge|Void
export function getFirstChallenge({
entities: { superBlock, block, challenge },
result
}) {
return challenge[
emptyProtector(block[
emptyProtector(superBlock[
result[0]
]).blocks[0]
]).challenges[0]
];
}