From 2f5bb333dbaefc9bb66b85729edf46fae736e217 Mon Sep 17 00:00:00 2001 From: Tibo De Peuter Date: Sat, 17 May 2025 19:56:46 +0200 Subject: [PATCH] chore(backend): Verwijder redundante methoden --- backend/src/controllers/learning-paths.ts | 2 +- .../src/data/content/learning-path-repository.ts | 14 -------------- .../database-learning-path-provider.ts | 15 +++++---------- .../dwengo-api-learning-path-provider.ts | 14 ++------------ .../learning-paths/learning-path-provider.ts | 5 ----- .../learning-paths/learning-path-service.ts | 16 ---------------- 6 files changed, 8 insertions(+), 58 deletions(-) diff --git a/backend/src/controllers/learning-paths.ts b/backend/src/controllers/learning-paths.ts index 69408df7..88d1ad5d 100644 --- a/backend/src/controllers/learning-paths.ts +++ b/backend/src/controllers/learning-paths.ts @@ -66,7 +66,7 @@ export async function getLearningPaths(req: AuthenticatedRequest, res: Response) if (req.auth) { const adminUsername = req.auth.username; - const userLearningPaths = await learningPathService.searchLearningPathsByAdmin([adminUsername], language as Language, forGroup) || []; + const userLearningPaths = await learningPathService.getLearningPathsAdministratedBy(adminUsername) || []; allLearningPaths = apiLearningPaths.concat(userLearningPaths); } diff --git a/backend/src/data/content/learning-path-repository.ts b/backend/src/data/content/learning-path-repository.ts index ea42cab9..6910476e 100644 --- a/backend/src/data/content/learning-path-repository.ts +++ b/backend/src/data/content/learning-path-repository.ts @@ -1,11 +1,9 @@ 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 { Teacher } from '../../entities/users/teacher.entity'; export class LearningPathRepository extends DwengoEntityRepository { public async findByHruidAndLanguage(hruid: string, language: Language): Promise { @@ -15,18 +13,6 @@ export class LearningPathRepository extends DwengoEntityRepository }, { populate: ['nodes', 'nodes.transitions', 'admins'] }); } - public async findByAdmins(admins: Teacher[], language: Language, _matchMode?: MatchMode): Promise { - 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. 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 a3bd5bf3..ff4f9e4d 100644 --- a/backend/src/services/learning-paths/database-learning-path-provider.ts +++ b/backend/src/services/learning-paths/database-learning-path-provider.ts @@ -4,7 +4,11 @@ import { getLearningPathRepository } from '../../data/repositories.js'; import learningObjectService from '../learning-objects/learning-object-service.js'; import { LearningPathNode } from '../../entities/content/learning-path-node.entity.js'; import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity.js'; -import { getLastSubmissionForGroup, idFromLearningPathNode, isTransitionPossible } from './learning-path-personalization-util.js'; +import { + getLastSubmissionForGroup, + idFromLearningPathNode, + isTransitionPossible, +} from './learning-path-personalization-util.js'; import { FilteredLearningObject, LearningObjectNode, @@ -13,12 +17,10 @@ import { Transition, } from '@dwengo-1/common/interfaces/learning-content'; import { Language } from '@dwengo-1/common/util/language'; -import { MatchMode } from '@dwengo-1/common/util/match-mode'; import { Group } from '../../entities/assignments/group.entity'; import { Collection } from '@mikro-orm/core'; import { v4 } from 'uuid'; import { getLogger } from '../../logging/initalize.js'; -import { Teacher } from '../../entities/users/teacher.entity'; const logger = getLogger(); @@ -235,13 +237,6 @@ const databaseLearningPathProvider: LearningPathProvider = { const searchResults = await learningPathRepo.findByQueryStringAndLanguage(query, language); return await Promise.all(searchResults.map(async (result, index) => convertLearningPath(result, index, personalizedFor))); }, - - async searchLearningPathsByAdmin(admins: Teacher[], language: Language, personalizedFor?: Group, matchMode?: MatchMode): Promise { - const learningPathRepo = getLearningPathRepository(); - - const searchResults = await learningPathRepo.findByAdmins(admins, language, matchMode); - return await Promise.all(searchResults.map(async (result, index) => convertLearningPath(result, index, personalizedFor))); - }, }; export default databaseLearningPathProvider; diff --git a/backend/src/services/learning-paths/dwengo-api-learning-path-provider.ts b/backend/src/services/learning-paths/dwengo-api-learning-path-provider.ts index 4c57f055..d4a59b96 100644 --- a/backend/src/services/learning-paths/dwengo-api-learning-path-provider.ts +++ b/backend/src/services/learning-paths/dwengo-api-learning-path-provider.ts @@ -3,8 +3,6 @@ import { DWENGO_API_BASE } from '../../config.js'; import { LearningPathProvider } from './learning-path-provider.js'; import { getLogger, Logger } from '../../logging/initalize.js'; import { LearningPath, LearningPathResponse } from '@dwengo-1/common/interfaces/learning-content'; -import { Teacher } from '../../entities/users/teacher.entity'; -import { Language } from '@dwengo-1/common/util/language'; import { Group } from '../../entities/assignments/group.entity.js'; import { getLastSubmissionForGroup, idFromLearningObjectNode } from './learning-path-personalization-util.js'; @@ -21,7 +19,7 @@ async function addProgressToLearningPath(learningPath: LearningPath, personalize learningPath.nodes.map(async (node) => { const lastSubmission = personalizedFor ? await getLastSubmissionForGroup(idFromLearningObjectNode(node), personalizedFor) : null; node.done = Boolean(lastSubmission); - }) + }), ); learningPath.num_nodes = learningPath.nodes.length; @@ -78,16 +76,8 @@ const dwengoApiLearningPathProvider: LearningPathProvider = { }, async getLearningPathsAdministratedBy(_adminUsername: string) { - return []; // Learning paths fetched from the Dwengo API cannot be administrated by a user. - }, - - async searchLearningPathsByAdmin(admins: Teacher[], language: string): Promise { - if (!admins || admins.length === 0) { - return this.searchLearningPaths('', language as Language); - } - // Dwengo API does not have the concept of admins, so we cannot filter by them. - return [] + return []; }, }; diff --git a/backend/src/services/learning-paths/learning-path-provider.ts b/backend/src/services/learning-paths/learning-path-provider.ts index c781f134..ee783b35 100644 --- a/backend/src/services/learning-paths/learning-path-provider.ts +++ b/backend/src/services/learning-paths/learning-path-provider.ts @@ -22,9 +22,4 @@ export interface LearningPathProvider { * Get all learning paths which have the teacher with the given user as an administrator. */ getLearningPathsAdministratedBy(adminUsername: string): Promise; - - /** - * Fetch the learning paths for the given admins from the data source. - */ - searchLearningPathsByAdmin(admins: Teacher[], language: Language, personalizedFor?: Group, matchMode?: MatchMode): Promise; } diff --git a/backend/src/services/learning-paths/learning-path-service.ts b/backend/src/services/learning-paths/learning-path-service.ts index 35c46704..16e9d2d0 100644 --- a/backend/src/services/learning-paths/learning-path-service.ts +++ b/backend/src/services/learning-paths/learning-path-service.ts @@ -129,22 +129,6 @@ const learningPathService = { return providerResponses.flat(); }, - /** - * Fetch the learning paths for the given admins from the data source. - */ - async searchLearningPathsByAdmin(adminsIds: string[], language: Language, personalizedFor?: Group): Promise { - const teacherRepo = getTeacherRepository(); - const admins = await Promise.all( - adminsIds .map(async (adminId) => await teacherRepo.findByUsername(adminId)) - ); - const adminsNotNull: Teacher[] = admins.filter((admin) => admin !== undefined) as Teacher[]; - - const providerResponses = await Promise.all( - allProviders.map(async (provider) => provider.searchLearningPathsByAdmin(adminsNotNull, language, personalizedFor)), - ); - return providerResponses.flat(); - }, - /** * Add a new learning path to the database. * @param dto Learning path DTO from which the learning path will be created.