style: fix linting issues met Prettier
This commit is contained in:
		
							parent
							
								
									bdbfe380be
								
							
						
					
					
						commit
						6624dacabd
					
				
					 4 changed files with 41 additions and 31 deletions
				
			
		|  | @ -6,11 +6,7 @@ import { Language } from '../../entities/content/language'; | |||
| import learningObjectService from '../learning-objects/learning-object-service'; | ||||
| import { LearningPathNode } from '../../entities/content/learning-path-node.entity'; | ||||
| import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity'; | ||||
| import { | ||||
|     getLastSubmissionForCustomizationTarget, | ||||
|     isTransitionPossible, | ||||
|     PersonalizationTarget | ||||
| } from "./learning-path-personalization-util"; | ||||
| import { getLastSubmissionForCustomizationTarget, isTransitionPossible, PersonalizationTarget } from './learning-path-personalization-util'; | ||||
| 
 | ||||
| /** | ||||
|  * Fetches the corresponding learning object for each of the nodes and creates a map that maps each node to its | ||||
|  | @ -69,7 +65,7 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb | |||
|         title: learningPath.title, | ||||
|         nodes: convertedNodes, | ||||
|         num_nodes: learningPath.nodes.length, | ||||
|         num_nodes_left: convertedNodes.filter(it => !it.done).length, | ||||
|         num_nodes_left: convertedNodes.filter((it) => !it.done).length, | ||||
|         keywords: keywords.join(' '), | ||||
|         target_ages: targetAges, | ||||
|         max_age: Math.max(...targetAges), | ||||
|  | @ -83,10 +79,13 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb | |||
|  * @param nodesToLearningObjects | ||||
|  * @param personalizedFor | ||||
|  */ | ||||
| async function convertNodes(nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>, personalizedFor?: PersonalizationTarget): Promise<LearningObjectNode[]> { | ||||
| async function convertNodes( | ||||
|     nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>, | ||||
|     personalizedFor?: PersonalizationTarget | ||||
| ): Promise<LearningObjectNode[]> { | ||||
|     const nodesPromise = nodesToLearningObjects | ||||
|         .entries() | ||||
|         .map(async(entry) => { | ||||
|         .map(async (entry) => { | ||||
|             const [node, learningObject] = entry; | ||||
|             const lastSubmission = personalizedFor ? await getLastSubmissionForCustomizationTarget(node, personalizedFor) : null; | ||||
|             return { | ||||
|  | @ -98,7 +97,7 @@ async function convertNodes(nodesToLearningObjects: Map<LearningPathNode, Filter | |||
|                 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.
 | ||||
|                     .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
 | ||||
|             }; | ||||
|         }) | ||||
|  | @ -143,14 +142,17 @@ const databaseLearningPathProvider: LearningPathProvider = { | |||
|     /** | ||||
|      * Fetch the learning paths with the given hruids from the database. | ||||
|      */ | ||||
|     async fetchLearningPaths(hruids: string[], language: Language, source: string, personalizedFor?: PersonalizationTarget): Promise<LearningPathResponse> { | ||||
|     async fetchLearningPaths( | ||||
|         hruids: string[], | ||||
|         language: Language, | ||||
|         source: string, | ||||
|         personalizedFor?: PersonalizationTarget | ||||
|     ): Promise<LearningPathResponse> { | ||||
|         const learningPathRepo = getLearningPathRepository(); | ||||
| 
 | ||||
|         const learningPaths = ( | ||||
|             await Promise.all( | ||||
|                 hruids.map((hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language)) | ||||
|             ) | ||||
|         ).filter((learningPath) => learningPath !== null); | ||||
|         const learningPaths = (await Promise.all(hruids.map((hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language)))).filter( | ||||
|             (learningPath) => learningPath !== null | ||||
|         ); | ||||
|         const filteredLearningPaths = await Promise.all( | ||||
|             learningPaths.map((learningPath, index) => convertLearningPath(learningPath, index, personalizedFor)) | ||||
|         ); | ||||
|  |  | |||
|  | @ -1,11 +1,11 @@ | |||
| import {LearningPathNode} from "../../entities/content/learning-path-node.entity"; | ||||
| import {Student} from "../../entities/users/student.entity"; | ||||
| import {Group} from "../../entities/assignments/group.entity"; | ||||
| import {Submission} from "../../entities/assignments/submission.entity"; | ||||
| import {getSubmissionRepository} from "../../data/repositories"; | ||||
| import {LearningObjectIdentifier} from "../../entities/content/learning-object-identifier"; | ||||
| import {LearningPathTransition} from "../../entities/content/learning-path-transition.entity"; | ||||
| import {JSONPath} from "jsonpath-plus"; | ||||
| import { LearningPathNode } from '../../entities/content/learning-path-node.entity'; | ||||
| import { Student } from '../../entities/users/student.entity'; | ||||
| import { Group } from '../../entities/assignments/group.entity'; | ||||
| import { Submission } from '../../entities/assignments/submission.entity'; | ||||
| import { getSubmissionRepository } from '../../data/repositories'; | ||||
| import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier'; | ||||
| import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity'; | ||||
| import { JSONPath } from 'jsonpath-plus'; | ||||
| 
 | ||||
| export type PersonalizationTarget = { type: 'student'; student: Student } | { type: 'group'; group: Group }; | ||||
| /** | ||||
|  | @ -20,12 +20,10 @@ export async function getLastSubmissionForCustomizationTarget(node: LearningPath | |||
|     }; | ||||
|     if (pathFor.type === 'group') { | ||||
|         return await submissionRepo.findMostRecentSubmissionForGroup(learningObjectId, pathFor.group); | ||||
|     }  | ||||
|         return await submissionRepo.findMostRecentSubmissionForStudent(learningObjectId, pathFor.student); | ||||
|      | ||||
|     } | ||||
|     return await submissionRepo.findMostRecentSubmissionForStudent(learningObjectId, pathFor.student); | ||||
| } | ||||
| 
 | ||||
| 
 | ||||
| /** | ||||
|  * Checks whether the condition of the given transaction is fulfilled by the given submission. | ||||
|  * @param transition | ||||
|  |  | |||
|  | @ -1,6 +1,6 @@ | |||
| import { LearningPath, LearningPathResponse } from '../../interfaces/learning-content'; | ||||
| import { Language } from '../../entities/content/language'; | ||||
| import {PersonalizationTarget} from "./learning-path-personalizing-service"; | ||||
| import { PersonalizationTarget } from './learning-path-personalizing-service'; | ||||
| 
 | ||||
| /** | ||||
|  * Generic interface for a service which provides access to learning paths from a data source. | ||||
|  |  | |||
|  | @ -3,7 +3,7 @@ import dwengoApiLearningPathProvider from './dwengo-api-learning-path-provider'; | |||
| import databaseLearningPathProvider from './database-learning-path-provider'; | ||||
| import { EnvVars, getEnvVar } from '../../util/envvars'; | ||||
| import { Language } from '../../entities/content/language'; | ||||
| import {PersonalizationTarget} from "./learning-path-personalizing-service"; | ||||
| import { PersonalizationTarget } from './learning-path-personalizing-service'; | ||||
| 
 | ||||
| const userContentPrefix = getEnvVar(EnvVars.UserContentPrefix); | ||||
| const allProviders = [dwengoApiLearningPathProvider, databaseLearningPathProvider]; | ||||
|  | @ -19,12 +19,22 @@ const learningPathService = { | |||
|      * @param source | ||||
|      * @param personalizedFor If this is set, a learning path personalized for the given group or student will be returned. | ||||
|      */ | ||||
|     async fetchLearningPaths(hruids: string[], language: Language, source: string, personalizedFor?: PersonalizationTarget): Promise<LearningPathResponse> { | ||||
|     async fetchLearningPaths( | ||||
|         hruids: string[], | ||||
|         language: Language, | ||||
|         source: string, | ||||
|         personalizedFor?: PersonalizationTarget | ||||
|     ): Promise<LearningPathResponse> { | ||||
|         const userContentHruids = hruids.filter((hruid) => hruid.startsWith(userContentPrefix)); | ||||
|         const nonUserContentHruids = hruids.filter((hruid) => !hruid.startsWith(userContentPrefix)); | ||||
| 
 | ||||
|         const userContentLearningPaths = await databaseLearningPathProvider.fetchLearningPaths(userContentHruids, language, source, personalizedFor); | ||||
|         const nonUserContentLearningPaths = await dwengoApiLearningPathProvider.fetchLearningPaths(nonUserContentHruids, language, source, personalizedFor); | ||||
|         const nonUserContentLearningPaths = await dwengoApiLearningPathProvider.fetchLearningPaths( | ||||
|             nonUserContentHruids, | ||||
|             language, | ||||
|             source, | ||||
|             personalizedFor | ||||
|         ); | ||||
| 
 | ||||
|         const result = (userContentLearningPaths.data || []).concat(nonUserContentLearningPaths.data || []); | ||||
| 
 | ||||
|  |  | |||
		Reference in a new issue
	
	 Lint Action
						Lint Action