fix(backend): Fouten in isTransitionPossible en het opzetten van de testdata verbeterd.
This commit is contained in:
		
							parent
							
								
									b539c28d8c
								
							
						
					
					
						commit
						fc46e79d05
					
				
					 10 changed files with 249 additions and 68 deletions
				
			
		|  | @ -15,8 +15,8 @@ export class Submission { | |||
|     }) | ||||
|     learningObjectLanguage!: Language; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'string' }) | ||||
|     learningObjectVersion: string = '1'; | ||||
|     @PrimaryKey({ type: 'numeric' }) | ||||
|     learningObjectVersion: number = 1; | ||||
| 
 | ||||
|     @PrimaryKey({ type: 'integer' }) | ||||
|     submissionNumber!: number; | ||||
|  |  | |||
|  | @ -47,7 +47,7 @@ export class LearningObject { | |||
|     teacherExclusive: boolean = false; | ||||
| 
 | ||||
|     @Property({ type: 'array' }) | ||||
|     skosConcepts!: string[]; | ||||
|     skosConcepts: string[] = []; | ||||
| 
 | ||||
|     @Embedded({ | ||||
|         entity: () => EducationalGoal, | ||||
|  | @ -64,8 +64,8 @@ export class LearningObject { | |||
|     @Property({ type: 'smallint', nullable: true }) | ||||
|     difficulty?: number; | ||||
| 
 | ||||
|     @Property({ type: 'integer' }) | ||||
|     estimatedTime!: number; | ||||
|     @Property({ type: 'integer', nullable: true }) | ||||
|     estimatedTime?: number; | ||||
| 
 | ||||
|     @Embedded({ | ||||
|         entity: () => ReturnValue, | ||||
|  |  | |||
|  | @ -97,14 +97,26 @@ async function convertNodes( | |||
|                 learningobject_hruid: node.learningObjectHruid, | ||||
|                 version: learningObject.version, | ||||
|                 transitions: node.transitions | ||||
|                     .filter((trans) => !personalizedFor || isTransitionPossible(trans, lastSubmission)) // If we want a personalized learning path, remove all transitions that aren't possible.
 | ||||
|                     .map((trans, i) => convertTransition(trans, i, nodesToLearningObjects)), // Then convert all the transition
 | ||||
|                     .filter((trans) => | ||||
|                         !personalizedFor || isTransitionPossible(trans, optionalJsonStringToObject(lastSubmission?.content))  // If we want a personalized learning path, remove all transitions that aren't possible.
 | ||||
|                     ).map((trans, i) => convertTransition(trans, i, nodesToLearningObjects)), // Then convert all the transition
 | ||||
|             }; | ||||
|         }) | ||||
|         .toArray(); | ||||
|     return await Promise.all(nodesPromise); | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Helper method to convert a json string to an object, or null if it is undefined. | ||||
|  */ | ||||
| function optionalJsonStringToObject(jsonString?: string): object | null { | ||||
|     if (!jsonString) { | ||||
|         return null; | ||||
|     } else { | ||||
|         return JSON.parse(jsonString); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| /** | ||||
|  * Helper function which converts a transition in the database representation to a transition in the representation | ||||
|  * the Dwengo API uses. | ||||
|  |  | |||
|  | @ -36,5 +36,6 @@ export function isTransitionPossible(transition: LearningPathTransition, submitt | |||
|     if (submitted === null) { | ||||
|         return false; // If the transition is not unconditional and there was no submission, the transition is not possible.
 | ||||
|     } | ||||
|     return JSONPath({ path: transition.condition, json: submitted }).length === 0; | ||||
|     const match = JSONPath({ path: transition.condition, json: {submission: submitted} }) | ||||
|     return match.length === 1; | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger