From 4d999c78bab59e5d1ba0277c531f9f0e898e692c Mon Sep 17 00:00:00 2001 From: Gerald Schmittinger Date: Sat, 8 Mar 2025 18:26:10 +0100 Subject: [PATCH] =?UTF-8?q?feat(backend):=20databaseLearningPathProvider.s?= =?UTF-8?q?earchLearningPaths=20ge=C3=AFmplementeerd.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../data/content/learning-path-repository.ts | 19 +++++++++++++++++++ .../database-learning-path-provider.ts | 9 +++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/backend/src/data/content/learning-path-repository.ts b/backend/src/data/content/learning-path-repository.ts index 3ffb1e7f..4204a2ce 100644 --- a/backend/src/data/content/learning-path-repository.ts +++ b/backend/src/data/content/learning-path-repository.ts @@ -9,5 +9,24 @@ export class LearningPathRepository extends DwengoEntityRepository ): Promise { 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 { + 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. } diff --git a/backend/src/services/learning-paths/database-learning-path-provider.ts b/backend/src/services/learning-paths/database-learning-path-provider.ts index 11f6e1bc..c3ed6863 100644 --- a/backend/src/services/learning-paths/database-learning-path-provider.ts +++ b/backend/src/services/learning-paths/database-learning-path-provider.ts @@ -157,8 +157,13 @@ const databaseLearningPathProvider: LearningPathProvider = { /** * Search learning paths in the database using the given search string. */ - searchLearningPaths(query: string, language: string): Promise { - return Promise.resolve([]); // TODO + async searchLearningPaths(query: string, language: Language): Promise { + const searchResults = await learningPathRepo.findByQueryStringAndLanguage(query, language); + return await Promise.all( + searchResults.map((result, index) => + convertLearningPath(result, index) + ) + ); } }