Merge branch 'dev' into refactor/common
This commit is contained in:
commit
52bc02a9f9
39 changed files with 1272 additions and 88 deletions
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue