refactor(backend): Types

This commit is contained in:
Tibo De Peuter 2025-03-23 11:14:32 +01:00
parent 6ad7fbf208
commit 25f9eb2af2
Signed by: tdpeuter
GPG key ID: 38297DE43F75FFE2
31 changed files with 92 additions and 86 deletions

View file

@ -1,7 +1,6 @@
import { LearningObjectProvider } from './learning-object-provider.js';
import { FilteredLearningObject, LearningObjectIdentifier, LearningPathIdentifier } from '../../interfaces/learning-content.js';
import { getLearningObjectRepository, getLearningPathRepository } from '../../data/repositories.js';
import { Language } from '../../entities/content/language.js';
import { LearningObject } from '../../entities/content/learning-object.entity.js';
import { getUrlStringForLearningObject } from '../../util/links.js';
import processingService from './processing/processing-service.js';
@ -44,7 +43,7 @@ function convertLearningObject(learningObject: LearningObject | null): FilteredL
async function findLearningObjectEntityById(id: LearningObjectIdentifier): Promise<LearningObject | null> {
const learningObjectRepo = getLearningObjectRepository();
return learningObjectRepo.findLatestByHruidAndLanguage(id.hruid, id.language as Language);
return learningObjectRepo.findLatestByHruidAndLanguage(id.hruid, id.language);
}
/**
@ -65,7 +64,7 @@ const databaseLearningObjectProvider: LearningObjectProvider = {
async getLearningObjectHTML(id: LearningObjectIdentifier): Promise<string | null> {
const learningObjectRepo = getLearningObjectRepository();
const learningObject = await learningObjectRepo.findLatestByHruidAndLanguage(id.hruid, id.language as Language);
const learningObject = await learningObjectRepo.findLatestByHruidAndLanguage(id.hruid, id.language);
if (!learningObject) {
return null;
}

View file

@ -8,6 +8,7 @@ import { DwengoContentType } from '../content-type.js';
import dwengoMarkedRenderer from './dwengo-marked-renderer.js';
import { StringProcessor } from '../string-processor.js';
import { ProcessingError } from '../processing-error.js';
import { YAMLException } from 'js-yaml';
class MarkdownProcessor extends StringProcessor {
constructor() {
@ -19,8 +20,12 @@ class MarkdownProcessor extends StringProcessor {
marked.use({ renderer: dwengoMarkedRenderer });
const html = marked(mdText, { async: false });
return this.replaceLinks(html); // Replace html image links path
} catch (e: any) {
throw new ProcessingError(e.message);
} catch (e: unknown) {
if (e instanceof YAMLException) {
throw new ProcessingError(e.message);
}
throw new ProcessingError('Unknown error while processing markdown: ' + e);
}
}

View file

@ -21,7 +21,7 @@ const EMBEDDED_LEARNING_OBJECT_PLACEHOLDER = /<learning-object hruid="([^"]+)" l
const LEARNING_OBJECT_DOES_NOT_EXIST = "<div class='non-existing-learning-object' />";
class ProcessingService {
private processors!: Map<DwengoContentType, Processor<any>>;
private processors!: Map<DwengoContentType, Processor<DwengoContentType>>;
constructor() {
const processors = [

View file

@ -25,7 +25,7 @@ async function getLearningObjectsForNodes(nodes: LearningPathNode[]): Promise<Ma
version: node.version,
language: node.language,
})
.then((learningObject) => <[LearningPathNode, FilteredLearningObject | null]>[node, learningObject])
.then((learningObject) => ([node, learningObject] as [LearningPathNode, FilteredLearningObject | null]))
)
)
);