fix(backend): Testen DatabaseLearningObjectProvider gerepareerd na refactoring.
This commit is contained in:
		
							parent
							
								
									ee9afab6ca
								
							
						
					
					
						commit
						51268af79c
					
				
					 20 changed files with 72 additions and 210 deletions
				
			
		|  | @ -1,4 +1,4 @@ | |||
| import { Embedded, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property } from '@mikro-orm/core'; | ||||
| import {ArrayType, Embedded, Entity, Enum, ManyToMany, OneToMany, PrimaryKey, Property} from '@mikro-orm/core'; | ||||
| import { Attachment } from './attachment.entity.js'; | ||||
| import { Teacher } from '../users/teacher.entity.js'; | ||||
| import { DwengoContentType } from '../../services/learning-objects/processing/content-type.js'; | ||||
|  | @ -42,7 +42,7 @@ export class LearningObject { | |||
|     @Property({ type: 'array' }) | ||||
|     keywords: string[] = []; | ||||
| 
 | ||||
|     @Property({ type: 'array', nullable: true }) | ||||
|     @Property({ type: new ArrayType(i => +i), nullable: true }) | ||||
|     targetAges?: number[] = []; | ||||
| 
 | ||||
|     @Property({ type: 'bool' }) | ||||
|  |  | |||
|  | @ -9,7 +9,7 @@ export class LearningPathNode { | |||
|     learningPath!: Rel<LearningPath>; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'integer', autoincrement: true }) | ||||
|     nodeNumber!: number; | ||||
|     nodeNumber?: number; | ||||
| 
 | ||||
|     @Property({ type: 'string' }) | ||||
|     learningObjectHruid!: string; | ||||
|  |  | |||
|  | @ -8,12 +8,13 @@ import { | |||
|     LearningPathResponse, | ||||
| } from '@dwengo-1/common/interfaces/learning-content'; | ||||
| import { getLogger } from '../logging/initalize.js'; | ||||
| import {v4} from "uuid"; | ||||
| 
 | ||||
| function filterData(data: LearningObjectMetadata, htmlUrl: string): FilteredLearningObject { | ||||
|     return { | ||||
|         key: data.hruid, // Hruid learningObject (not path)
 | ||||
|         _id: data._id, | ||||
|         uuid: data.uuid, | ||||
|         uuid: data.uuid || v4(), | ||||
|         version: data.version, | ||||
|         title: data.title, | ||||
|         htmlUrl, // Url to fetch html content
 | ||||
|  |  | |||
|  | @ -32,7 +32,8 @@ function convertLearningObject(learningObject: LearningObject | null): FilteredL | |||
|         educationalGoals: learningObject.educationalGoals, | ||||
|         returnValue: { | ||||
|             callback_url: learningObject.returnValue.callbackUrl, | ||||
|             callback_schema: JSON.parse(learningObject.returnValue.callbackSchema), | ||||
|             callback_schema: learningObject.returnValue.callbackSchema === "" ? "" | ||||
|                                 : JSON.parse(learningObject.returnValue.callbackSchema), | ||||
|         }, | ||||
|         skosConcepts: learningObject.skosConcepts, | ||||
|         targetAges: learningObject.targetAges || [], | ||||
|  |  | |||
|  | @ -11,6 +11,7 @@ import { | |||
|     LearningPathIdentifier, | ||||
|     LearningPathResponse, | ||||
| } from '@dwengo-1/common/interfaces/learning-content'; | ||||
| import {v4} from "uuid"; | ||||
| 
 | ||||
| const logger: Logger = getLogger(); | ||||
| 
 | ||||
|  | @ -23,7 +24,7 @@ function filterData(data: LearningObjectMetadata): FilteredLearningObject { | |||
|     return { | ||||
|         key: data.hruid, // Hruid learningObject (not path)
 | ||||
|         _id: data._id, | ||||
|         uuid: data.uuid, | ||||
|         uuid: data.uuid ?? v4(), | ||||
|         version: data.version, | ||||
|         title: data.title, | ||||
|         htmlUrl: `/learningObject/${data.hruid}/html?language=${data.language}&version=${data.version}`, // Url to fetch html content
 | ||||
|  |  | |||
|  | @ -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, | ||||
|  |  | |||
|  | @ -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; | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger