fix: database-learning-path-provider type errors gefixt

This commit is contained in:
Adriaan Jacquet 2025-03-13 19:40:41 +01:00
parent 8c7d5e965c
commit f84c716fd3

View file

@ -29,7 +29,7 @@ async function getLearningObjectsForNodes(nodes: LearningPathNode[]): Promise<Ma
) )
) )
); );
if (nullableNodesToLearningObjects.values().some((it) => it === null)) { if (Array.from(nullableNodesToLearningObjects.values()).some((it) => it === null)) {
throw new Error('At least one of the learning objects on this path could not be found.'); throw new Error('At least one of the learning objects on this path could not be found.');
} }
return nullableNodesToLearningObjects as Map<LearningPathNode, FilteredLearningObject>; return nullableNodesToLearningObjects as Map<LearningPathNode, FilteredLearningObject>;
@ -41,15 +41,11 @@ async function getLearningObjectsForNodes(nodes: LearningPathNode[]): Promise<Ma
async function convertLearningPath(learningPath: LearningPathEntity, order: number, personalizedFor?: PersonalizationTarget): Promise<LearningPath> { async function convertLearningPath(learningPath: LearningPathEntity, order: number, personalizedFor?: PersonalizationTarget): Promise<LearningPath> {
const nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject> = await getLearningObjectsForNodes(learningPath.nodes); const nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject> = await getLearningObjectsForNodes(learningPath.nodes);
const targetAges = nodesToLearningObjects const targetAges = Array.from(nodesToLearningObjects.values())
.values() .flatMap((it) => it.targetAges || []);
.flatMap((it) => it.targetAges || [])
.toArray();
const keywords = nodesToLearningObjects const keywords = Array.from(nodesToLearningObjects.values())
.values() .flatMap((it) => it.keywords || []);
.flatMap((it) => it.keywords || [])
.toArray();
const image = learningPath.image ? learningPath.image.toString('base64') : undefined; const image = learningPath.image ? learningPath.image.toString('base64') : undefined;
@ -83,8 +79,7 @@ async function convertNodes(
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>, nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>,
personalizedFor?: PersonalizationTarget personalizedFor?: PersonalizationTarget
): Promise<LearningObjectNode[]> { ): Promise<LearningObjectNode[]> {
const nodesPromise = nodesToLearningObjects const nodesPromise = Array.from(nodesToLearningObjects.entries())
.entries()
.map(async (entry) => { .map(async (entry) => {
const [node, learningObject] = entry; const [node, learningObject] = entry;
const lastSubmission = personalizedFor ? await getLastSubmissionForCustomizationTarget(node, personalizedFor) : null; const lastSubmission = personalizedFor ? await getLastSubmissionForCustomizationTarget(node, personalizedFor) : null;
@ -102,8 +97,7 @@ async function convertNodes(
) )
.map((trans, i) => convertTransition(trans, i, nodesToLearningObjects)), // Then convert all the transition .map((trans, i) => convertTransition(trans, i, nodesToLearningObjects)), // Then convert all the transition
}; };
}) });
.toArray();
return await Promise.all(nodesPromise); return await Promise.all(nodesPromise);
} }