From bd7c6cf2c04d5839dbaea34c13135fde22734cc6 Mon Sep 17 00:00:00 2001 From: Gerald Schmittinger Date: Fri, 16 May 2025 01:31:29 +0200 Subject: [PATCH] =?UTF-8?q?feat(backend):=20Checks=20dat=20alle=20leerobje?= =?UTF-8?q?cten=20op=20het=20ge=C3=BCpload=20leerpad=20bestaan.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../learning-paths/learning-path-service.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/src/services/learning-paths/learning-path-service.ts b/backend/src/services/learning-paths/learning-path-service.ts index e273c98a..41dec92c 100644 --- a/backend/src/services/learning-paths/learning-path-service.ts +++ b/backend/src/services/learning-paths/learning-path-service.ts @@ -14,6 +14,7 @@ import { mapToTeacher } from '../../interfaces/teacher.js'; import { Collection } from '@mikro-orm/core'; import { NotFoundException } from '../../exceptions/not-found-exception.js'; import { BadRequestException } from '../../exceptions/bad-request-exception.js'; +import learningObjectService from '../learning-objects/learning-object-service.js'; const userContentPrefix = getEnvVar(envVars.UserContentPrefix); const allProviders = [dwengoApiLearningPathProvider, databaseLearningPathProvider]; @@ -137,6 +138,21 @@ const learningPathService = { } const path = mapToLearningPath(dto, admins); + + // Verify that all specified learning objects actually exist. + const learningObjectsOnPath = await Promise.all( + path.nodes.map(async node => + learningObjectService.getLearningObjectById({ + hruid: node.learningObjectHruid, + language: node.language, + version: node.version + }) + ) + ); + if (learningObjectsOnPath.some(it => !it)) { + throw new BadRequestException("At least one of the specified learning objects does not exist.") + } + try { await repo.save(path, { preventOverwrite: true }); } catch (e: unknown) {