fix(frontend): Frontend kan nu omgaan met foutieve leerpaden
- Geen of meerdere startnodes - Transities naar een leerobject dat niet voorkomt - Transities naar een leerobject dat meer dan één keer voorkomt.
This commit is contained in:
		
							parent
							
								
									bb359b6c48
								
							
						
					
					
						commit
						a047558f95
					
				
					 2 changed files with 19 additions and 18 deletions
				
			
		|  | @ -34,24 +34,21 @@ export class LearningPathNode { | |||
|             version: dto.version, | ||||
|             language: dto.language, | ||||
|             transitions: dto.transitions.map((transDto) => { | ||||
|                 const nextNodeDto = otherNodes.filter( | ||||
|                 const nextNodeDto = otherNodes.find( | ||||
|                     (it) => | ||||
|                         it.learningobject_hruid === transDto.next.hruid && | ||||
|                         it.language === transDto.next.language && | ||||
|                         it.version === transDto.next.version, | ||||
|                 ); | ||||
|                 if (nextNodeDto.length !== 1) { | ||||
|                     throw new Error( | ||||
|                         `Invalid learning path! There is a transition to node` + | ||||
|                             `${transDto.next.hruid}/${transDto.next.language}/${transDto.next.version}, but there are` + | ||||
|                             `${nextNodeDto.length} such nodes.`, | ||||
|                     ); | ||||
|                 } | ||||
|                 if (nextNodeDto) { | ||||
|                     return { | ||||
|                     next: LearningPathNode.fromDTOAndOtherNodes(nextNodeDto[0], otherNodes), | ||||
|                         next: LearningPathNode.fromDTOAndOtherNodes(nextNodeDto, otherNodes), | ||||
|                         default: transDto.default, | ||||
|                     }; | ||||
|             }), | ||||
|                 } else { | ||||
|                     return undefined | ||||
|                 } | ||||
|             }).filter(it => it !== undefined), | ||||
|             createdAt: new Date(dto.created_at), | ||||
|             updatedAt: new Date(dto.updatedAt), | ||||
|             done: dto.done, | ||||
|  |  | |||
|  | @ -72,11 +72,6 @@ export class LearningPath { | |||
|     } | ||||
| 
 | ||||
|     static fromDTO(dto: LearningPathDTO): LearningPath { | ||||
|         const startNodeDto = dto.nodes.filter((it) => it.start_node === true); | ||||
|         if (startNodeDto.length !== 1) { | ||||
|             throw new Error(`Invalid learning path: ${dto.hruid}/${dto.language}!
 | ||||
|                                 Expected precisely one start node, but there were ${startNodeDto.length}.`);
 | ||||
|         } | ||||
|         return new LearningPath({ | ||||
|             language: dto.language, | ||||
|             hruid: dto.hruid, | ||||
|  | @ -86,8 +81,17 @@ export class LearningPath { | |||
|             amountOfNodesLeft: dto.num_nodes_left, | ||||
|             keywords: dto.keywords.split(" "), | ||||
|             targetAges: { min: dto.min_age, max: dto.max_age }, | ||||
|             startNode: LearningPathNode.fromDTOAndOtherNodes(startNodeDto[0], dto.nodes), | ||||
|             startNode: LearningPathNode.fromDTOAndOtherNodes(LearningPath.getStartNode(dto), dto.nodes), | ||||
|             image: dto.image, | ||||
|         }); | ||||
|     } | ||||
| 
 | ||||
|     static getStartNode(dto: LearningPathDTO): LearningPathNodeDTO { | ||||
|         const startNodeDtos = dto.nodes.filter((it) => it.start_node === true); | ||||
|         if (startNodeDtos.length < 1) { // The learning path has no starting node -> use the first node.
 | ||||
|             return dto.nodes[0]; | ||||
|         } else { // The learning path has 1 or more starting nodes -> use the first start node.
 | ||||
|             return startNodeDtos[0]; | ||||
|         } | ||||
|     } | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger