feat(backend): databaseLearningPathProvider.searchLearningPaths geïmplementeerd.
This commit is contained in:
		
							parent
							
								
									34af354a33
								
							
						
					
					
						commit
						4d999c78ba
					
				
					 2 changed files with 26 additions and 2 deletions
				
			
		|  | @ -9,5 +9,24 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath> | ||||||
|     ): Promise<LearningPath | null> { |     ): Promise<LearningPath | null> { | ||||||
|         return this.findOne({ hruid: hruid, language: language }); |         return this.findOne({ hruid: hruid, language: language }); | ||||||
|     } |     } | ||||||
|  | 
 | ||||||
|  |     /** | ||||||
|  |      * Returns all learning paths which have the given language and whose title OR description contains the | ||||||
|  |      * query string. | ||||||
|  |      * | ||||||
|  |      * @param query The query string we want to seach for in the title or description. | ||||||
|  |      * @param language The language of the learning paths we want to find. | ||||||
|  |      */ | ||||||
|  |     public findByQueryStringAndLanguage(query: string, language: Language): Promise<LearningPath[]> { | ||||||
|  |         return this.findAll({ | ||||||
|  |             where: { | ||||||
|  |                 language: language, | ||||||
|  |                 $or: [ | ||||||
|  |                     { title: { $like: `%${query}%`} }, | ||||||
|  |                     { description: { $like: `%${query}%`} } | ||||||
|  |                 ] | ||||||
|  |             } | ||||||
|  |         }); | ||||||
|  |     } | ||||||
|     // This repository is read-only for now since creating own learning object is an extension feature.
 |     // This repository is read-only for now since creating own learning object is an extension feature.
 | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -157,8 +157,13 @@ const databaseLearningPathProvider: LearningPathProvider = { | ||||||
|     /** |     /** | ||||||
|      * Search learning paths in the database using the given search string. |      * Search learning paths in the database using the given search string. | ||||||
|      */ |      */ | ||||||
|     searchLearningPaths(query: string, language: string): Promise<LearningPath[]> { |     async searchLearningPaths(query: string, language: Language): Promise<LearningPath[]> { | ||||||
|         return Promise.resolve([]); // TODO
 |         const searchResults = await learningPathRepo.findByQueryStringAndLanguage(query, language); | ||||||
|  |         return await Promise.all( | ||||||
|  |             searchResults.map((result, index) => | ||||||
|  |                 convertLearningPath(result, index) | ||||||
|  |             ) | ||||||
|  |         ); | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gerald Schmittinger
						Gerald Schmittinger