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.');
}
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> {
const nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject> = await getLearningObjectsForNodes(learningPath.nodes);
const targetAges = nodesToLearningObjects
.values()
.flatMap((it) => it.targetAges || [])
.toArray();
const targetAges = Array.from(nodesToLearningObjects.values())
.flatMap((it) => it.targetAges || []);
const keywords = nodesToLearningObjects
.values()
.flatMap((it) => it.keywords || [])
.toArray();
const keywords = Array.from(nodesToLearningObjects.values())
.flatMap((it) => it.keywords || []);
const image = learningPath.image ? learningPath.image.toString('base64') : undefined;
@ -83,8 +79,7 @@ async function convertNodes(
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>,
personalizedFor?: PersonalizationTarget
): Promise<LearningObjectNode[]> {
const nodesPromise = nodesToLearningObjects
.entries()
const nodesPromise = Array.from(nodesToLearningObjects.entries())
.map(async (entry) => {
const [node, learningObject] = entry;
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
};
})
.toArray();
});
return await Promise.all(nodesPromise);
}