feat(backend): Controller en route voor het aanmaken van leerobjecten aangemaakt.

This commit is contained in:
Gerald Schmittinger 2025-05-05 23:38:18 +02:00
parent 86ba4ea11e
commit 78353d6b65
6 changed files with 81 additions and 6 deletions

View file

@ -9,6 +9,7 @@ import {
} from '@dwengo-1/common/interfaces/learning-content';
import {getLearningObjectRepository} from "../../data/repositories";
import {processLearningObjectZip} from "./learning-object-zip-processing-service";
import {BadRequestException} from "../../exceptions/bad-request-exception";
function getProvider(id: LearningObjectIdentifierDTO): LearningObjectProvider {
if (id.hruid.startsWith(getEnvVar(envVars.UserContentPrefix))) {
@ -58,7 +59,7 @@ const learningObjectService = {
const learningObject = await processLearningObjectZip(learningObjectPath);
if (!learningObject.hruid.startsWith(getEnvVar(envVars.UserContentPrefix))) {
throw Error("Learning object name must start with the user content prefix!");
throw new BadRequestException("Learning object name must start with the user content prefix!");
}
await learningObjectRepository.save(learningObject, {preventOverwrite: true});

View file

@ -1,8 +1,9 @@
import unzipper from 'unzipper';
import mime from 'mime-types';
import {LearningObjectMetadata} from "@dwengo-1/common/dist/interfaces/learning-content";
import {LearningObject} from "../../entities/content/learning-object.entity";
import {getAttachmentRepository, getLearningObjectRepository} from "../../data/repositories";
import {BadRequestException} from "../../exceptions/bad-request-exception";
import {LearningObjectMetadata} from "@dwengo-1/common/dist/interfaces/learning-content";
/**
* Process an uploaded zip file and construct a LearningObject from its contents.
@ -20,7 +21,7 @@ export async function processLearningObjectZip(filePath: string): Promise<Learni
for (const file of zip.files) {
if (file.type === "Directory") {
throw Error("The learning object zip file should not contain directories.");
throw new BadRequestException("The learning object zip file should not contain directories.");
} else if (file.path === "metadata.json") {
metadata = await processMetadataJson(file);
} else if (file.path.startsWith("index.")) {
@ -34,10 +35,10 @@ export async function processLearningObjectZip(filePath: string): Promise<Learni
}
if (!metadata) {
throw Error("Missing metadata.json file");
throw new BadRequestException("Missing metadata.json file");
}
if (!content) {
throw Error("Missing index file");
throw new BadRequestException("Missing index file");
}
const learningObject = learningObjectRepo.create(metadata);