fix(backend): Fouten bij types opgelost

This commit is contained in:
Gerald Schmittinger 2025-05-13 21:12:49 +02:00
parent 96821c40ab
commit 63cf60409f
4 changed files with 15 additions and 7 deletions

View file

@ -3,8 +3,8 @@ import mime from 'mime-types';
import {LearningObject} from "../../entities/content/learning-object.entity"; import {LearningObject} from "../../entities/content/learning-object.entity";
import {getAttachmentRepository, getLearningObjectRepository} from "../../data/repositories"; import {getAttachmentRepository, getLearningObjectRepository} from "../../data/repositories";
import {BadRequestException} from "../../exceptions/bad-request-exception"; import {BadRequestException} from "../../exceptions/bad-request-exception";
import {LearningObjectMetadata} from "@dwengo-1/common/dist/interfaces/learning-content"; import {LearningObjectMetadata} from "@dwengo-1/common/interfaces/learning-content";
import { ReturnValue } from '../../entities/content/return-value.entity'; import { DwengoContentType } from './processing/content-type';
const METADATA_PATH_REGEX = /.*[/^]metadata\.json$/; const METADATA_PATH_REGEX = /.*[/^]metadata\.json$/;
const CONTENT_PATH_REGEX = /.*[/^]content\.[a-zA-Z]*$/; const CONTENT_PATH_REGEX = /.*[/^]content\.[a-zA-Z]*$/;
@ -65,11 +65,17 @@ function createLearningObject(
): LearningObject { ): LearningObject {
const learningObjectRepo = getLearningObjectRepository(); const learningObjectRepo = getLearningObjectRepository();
const attachmentRepo = getAttachmentRepository(); const attachmentRepo = getAttachmentRepository();
const returnValue = {
callbackUrl: metadata.return_value?.callback_url ?? "",
callbackSchema: metadata.return_value?.callback_schema ? JSON.stringify(metadata.return_value.callback_schema) : ""
};
const learningObject = learningObjectRepo.create({ const learningObject = learningObjectRepo.create({
admins: [], admins: [],
available: metadata.available ?? true, available: metadata.available ?? true,
content: content, content: content,
contentType: metadata.content_type, contentType: metadata.content_type as DwengoContentType,
copyright: metadata.copyright ?? "", copyright: metadata.copyright ?? "",
description: metadata.description ?? "", description: metadata.description ?? "",
educationalGoals: metadata.educational_goals ?? [], educationalGoals: metadata.educational_goals ?? [],
@ -77,7 +83,7 @@ function createLearningObject(
keywords: metadata.keywords, keywords: metadata.keywords,
language: metadata.language, language: metadata.language,
license: metadata.license ?? "", license: metadata.license ?? "",
returnValue: metadata.return_value ?? new ReturnValue(), returnValue,
skosConcepts: metadata.skos_concepts ?? [], skosConcepts: metadata.skos_concepts ?? [],
teacherExclusive: metadata.teacher_exclusive, teacherExclusive: metadata.teacher_exclusive,
title: metadata.title, title: metadata.title,
@ -93,7 +99,7 @@ function createLearningObject(
return learningObject; return learningObject;
} }
async function processMetadataJson(file: unzipper.File): LearningObjectMetadata { async function processMetadataJson(file: unzipper.File): Promise<LearningObjectMetadata> {
const buf = await file.buffer(); const buf = await file.buffer();
const content = buf.toString(); const content = buf.toString();
return JSON.parse(content); return JSON.parse(content);

View file

@ -117,7 +117,7 @@ async function convertNode(
logger.error(`Transition could not be resolved: ${JSON.stringify(trans)}`); logger.error(`Transition could not be resolved: ${JSON.stringify(trans)}`);
return undefined; // Do not crash on invalid transitions, just ignore them so the rest of the learning path keeps working. return undefined; // Do not crash on invalid transitions, just ignore them so the rest of the learning path keeps working.
} }
}).filter(it => it); }).filter(it => it !== undefined);
return { return {
_id: learningObject.uuid, _id: learningObject.uuid,
language: learningObject.language, language: learningObject.language,

View file

@ -124,7 +124,7 @@ export async function getTeacherQuestions(username: string, full: boolean): Prom
// Find all learning objects that this teacher manages // Find all learning objects that this teacher manages
const learningObjectRepository: LearningObjectRepository = getLearningObjectRepository(); const learningObjectRepository: LearningObjectRepository = getLearningObjectRepository();
const learningObjects: LearningObject[] = await learningObjectRepository.findAllByAdmin(teacher); const learningObjects: LearningObject[] = await learningObjectRepository.findAllByAdmin(teacher.username);
if (!learningObjects || learningObjects.length === 0) { if (!learningObjects || learningObjects.length === 0) {
return []; return [];

View file

@ -79,6 +79,8 @@ export interface LearningObjectMetadata {
target_ages: number[]; target_ages: number[];
content_type: string; // Markdown, image, etc. content_type: string; // Markdown, image, etc.
content_location?: string; content_location?: string;
copyright?: string;
license?: string;
skos_concepts?: string[]; skos_concepts?: string[];
return_value?: ReturnValue; return_value?: ReturnValue;
} }