Merge branch 'dev' into refactor/common

This commit is contained in:
Tibo De Peuter 2025-04-03 07:34:47 +02:00
commit 52bc02a9f9
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
39 changed files with 1272 additions and 88 deletions

View file

@ -1,12 +1,16 @@
import { Request, Response } from 'express';
import { FALLBACK_LANG } from '../config.js';
import learningObjectService from '../services/learning-objects/learning-object-service.js';
import { envVars, getEnvVar } from '../util/envVars.js';
import { Language } from '@dwengo-1/common/util/language';
import attachmentService from '../services/learning-objects/attachment-service.js';
import { NotFoundError } from '@mikro-orm/core';
import { BadRequestException } from '../exceptions/bad-request-exception.js';
import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from '@dwengo-1/common/interfaces/learning-content';
import { NotFoundException } from '../exceptions/not-found-exception.js';
import { envVars, getEnvVar } from '../util/envVars.js';
import {
FilteredLearningObject,
LearningObjectIdentifier,
LearningPathIdentifier,
} from '@dwengo-1/common/interfaces/learning-content';
function getLearningObjectIdentifierFromRequest(req: Request): LearningObjectIdentifier {
if (!req.params.hruid) {
@ -47,6 +51,11 @@ export async function getLearningObject(req: Request, res: Response): Promise<vo
const learningObjectId = getLearningObjectIdentifierFromRequest(req);
const learningObject = await learningObjectService.getLearningObjectById(learningObjectId);
if (!learningObject) {
throw new NotFoundException('Learning object not found');
}
res.json(learningObject);
}
@ -63,7 +72,7 @@ export async function getAttachment(req: Request, res: Response): Promise<void>
const attachment = await attachmentService.getAttachment(learningObjectId, name);
if (!attachment) {
throw new NotFoundError(`Attachment ${name} not found`);
throw new NotFoundException(`Attachment ${name} not found`);
}
res.setHeader('Content-Type', attachment.mimeType).send(attachment.content);
}