feat(backend): SearchByAdmins service

This commit is contained in:
Tibo De Peuter 2025-05-17 18:14:02 +02:00
parent 0d2b486a2c
commit 1639fbdabf
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
7 changed files with 99 additions and 17 deletions

View file

@ -1,21 +1,35 @@
import { DwengoEntityRepository } from '../dwengo-entity-repository.js';
import { LearningPath } from '../../entities/content/learning-path.entity.js';
import { Language } from '@dwengo-1/common/util/language';
import { MatchMode } from '@dwengo-1/common/util/match-mode';
import { LearningPathNode } from '../../entities/content/learning-path-node.entity.js';
import { RequiredEntityData } from '@mikro-orm/core';
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity.js';
import { EntityAlreadyExistsException } from '../../exceptions/entity-already-exists-exception.js';
import { Teacher } from '../../entities/users/teacher.entity';
export class LearningPathRepository extends DwengoEntityRepository<LearningPath> {
public async findByHruidAndLanguage(hruid: string, language: Language): Promise<LearningPath | null> {
return this.findOne({ hruid: hruid, language: language }, { populate: ['nodes', 'nodes.transitions'] });
}
public async findByAdmins(admins: Teacher[], language: Language, _matchMode?: MatchMode): Promise<LearningPath[]> {
return this.findAll({
where: {
language: language,
admins: {
$in: admins,
},
},
populate: ['nodes', 'nodes.transitions'],
});
}
/**
* 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 query The query string we want to search for in the title or description.
* @param language The language of the learning paths we want to find.
*/
public async findByQueryStringAndLanguage(query: string, language: Language): Promise<LearningPath[]> {