fix(backend): Testen DatabaseLearningObjectProvider gerepareerd na refactoring.

This commit is contained in:
Gerald Schmittinger 2025-04-16 07:58:55 +02:00
parent ee9afab6ca
commit 51268af79c
20 changed files with 72 additions and 210 deletions

View file

@ -15,6 +15,7 @@ import {
import { Language } from '@dwengo-1/common/util/language';
import {Group} from "../../entities/assignments/group.entity";
import {Collection} from "@mikro-orm/core";
import {v4} from "uuid";
/**
* Fetches the corresponding learning object for each of the nodes and creates a map that maps each node to its
@ -163,7 +164,7 @@ function convertTransition(
_id: String(index), // Retained for backwards compatibility. The index uniquely identifies the transition within the learning path.
default: false, // We don't work with default transitions but retain this for backwards compatibility.
next: {
_id: nextNode._id + index, // Construct a unique ID for the transition for backwards compatibility.
_id: nextNode._id ? (nextNode._id + index) : v4(), // Construct a unique ID for the transition for backwards compatibility.
hruid: transition.next.learningObjectHruid,
language: nextNode.language,
version: nextNode.version,

View file

@ -29,14 +29,13 @@ export function mapToLearningPath(
admins,
image: dto.image ? Buffer.from(base64ToArrayBuffer(dto.image)) : null
});
const nodes = dto.nodes.map((nodeDto: LearningObjectNode, i: number) =>
const nodes = dto.nodes.map((nodeDto: LearningObjectNode) =>
repo.createNode({
learningPath: path,
learningObjectHruid: nodeDto.learningobject_hruid,
language: nodeDto.language,
version: nodeDto.version,
startNode: nodeDto.start_node ?? false,
nodeNumber: i,
createdAt: new Date(),
updatedAt: new Date()
})
@ -66,10 +65,10 @@ export function mapToLearningPath(
}
}).filter(it => it).map(it => it!);
fromNode.transitions = new Collection<LearningPathTransition>(transitions);
fromNode.transitions = new Collection<LearningPathTransition>(fromNode, transitions);
});
path.nodes = new Collection<LearningPathNode>(nodes);
path.nodes = new Collection<LearningPathNode>(path, nodes);
return path;
}