feat(backend): databaseLearningPathProvider.searchLearningPaths geïmplementeerd.

This commit is contained in:
Gerald Schmittinger 2025-03-08 18:26:10 +01:00
parent 34af354a33
commit 4d999c78ba
2 changed files with 26 additions and 2 deletions

View file

@ -9,5 +9,24 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
): Promise<LearningPath | null> {
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.
}

View file

@ -157,8 +157,13 @@ const databaseLearningPathProvider: LearningPathProvider = {
/**
* Search learning paths in the database using the given search string.
*/
searchLearningPaths(query: string, language: string): Promise<LearningPath[]> {
return Promise.resolve([]); // TODO
async searchLearningPaths(query: string, language: Language): Promise<LearningPath[]> {
const searchResults = await learningPathRepo.findByQueryStringAndLanguage(query, language);
return await Promise.all(
searchResults.map((result, index) =>
convertLearningPath(result, index)
)
);
}
}