fix(backend): Foute entity-structuur van leerpaden verbeterd.
Ook testen geschreven voor LearningPathRepository en LearningObjectRepository.
This commit is contained in:
parent
4d999c78ba
commit
1417907933
24 changed files with 474 additions and 64 deletions
|
@ -2,10 +2,10 @@ import {getAttachmentRepository} from "../../data/repositories";
|
|||
import {Attachment} from "../../entities/content/attachment.entity";
|
||||
import {LearningObjectIdentifier} from "../../interfaces/learning-content";
|
||||
|
||||
const attachmentRepo = getAttachmentRepository();
|
||||
|
||||
const attachmentService = {
|
||||
getAttachment(learningObjectId: LearningObjectIdentifier, attachmentName: string): Promise<Attachment | null> {
|
||||
const attachmentRepo = getAttachmentRepository();
|
||||
|
||||
if (learningObjectId.version) {
|
||||
return attachmentRepo.findByLearningObjectIdAndName({
|
||||
hruid: learningObjectId.hruid,
|
||||
|
|
|
@ -11,8 +11,6 @@ import {getUrlStringForLearningObject} from "../../util/links";
|
|||
import processingService from "./processing/processing-service";
|
||||
import {NotFoundError} from "@mikro-orm/core";
|
||||
|
||||
const learningObjectRepo = getLearningObjectRepository();
|
||||
const learningPathRepo = getLearningPathRepository();
|
||||
|
||||
function convertLearningObject(learningObject: LearningObject | null): FilteredLearningObject | null {
|
||||
if (!learningObject) {
|
||||
|
@ -45,6 +43,8 @@ function convertLearningObject(learningObject: LearningObject | null): FilteredL
|
|||
}
|
||||
|
||||
function findLearningObjectEntityById(id: LearningObjectIdentifier): Promise<LearningObject | null> {
|
||||
const learningObjectRepo = getLearningObjectRepository();
|
||||
|
||||
return learningObjectRepo.findLatestByHruidAndLanguage(
|
||||
id.hruid, id.language as Language
|
||||
);
|
||||
|
@ -66,6 +66,8 @@ const databaseLearningObjectProvider: LearningObjectProvider = {
|
|||
* Obtain a HTML-rendering of the learning object with the given identifier (as a string).
|
||||
*/
|
||||
async getLearningObjectHTML(id: LearningObjectIdentifier): Promise<string | null> {
|
||||
const learningObjectRepo = getLearningObjectRepository();
|
||||
|
||||
const learningObject = await learningObjectRepo.findLatestByHruidAndLanguage(
|
||||
id.hruid, id.language as Language
|
||||
);
|
||||
|
@ -82,6 +84,8 @@ const databaseLearningObjectProvider: LearningObjectProvider = {
|
|||
* Fetch the HRUIDs of all learning objects on this path.
|
||||
*/
|
||||
async getLearningObjectIdsFromPath(id: LearningPathIdentifier): Promise<string[]> {
|
||||
const learningPathRepo = getLearningPathRepository();
|
||||
|
||||
const learningPath = await learningPathRepo.findByHruidAndLanguage(id.hruid, id.language);
|
||||
if (!learningPath) {
|
||||
throw new NotFoundError("The learning path with the given ID could not be found.");
|
||||
|
@ -93,6 +97,8 @@ const databaseLearningObjectProvider: LearningObjectProvider = {
|
|||
* Fetch the full metadata of all learning objects on this path.
|
||||
*/
|
||||
async getLearningObjectsFromPath(id: LearningPathIdentifier): Promise<FilteredLearningObject[]> {
|
||||
const learningPathRepo = getLearningPathRepository();
|
||||
|
||||
const learningPath = await learningPathRepo.findByHruidAndLanguage(id.hruid, id.language);
|
||||
if (!learningPath) {
|
||||
throw new NotFoundError("The learning path with the given ID could not be found.");
|
||||
|
|
|
@ -1,15 +1,20 @@
|
|||
/**
|
||||
* Based on https://github.com/dwengovzw/Learning-Object-Repository/blob/main/app/processors/markdown/learing_object_markdown_renderer.js [sic!]
|
||||
*/
|
||||
import PdfProcessor from "../pdf/pdf-processor.js";
|
||||
import AudioProcessor from "../audio/audio-processor.js";
|
||||
import ExternProcessor from "../extern/extern-processor.js";
|
||||
import InlineImageProcessor from "../image/inline-image-processor.js";
|
||||
import {RendererObject, Tokens} from "marked";
|
||||
import * as marked from "marked";
|
||||
import {getUrlStringForLearningObjectHTML, isValidHttpUrl} from "../../../../util/links";
|
||||
import {ProcessingError} from "../processing-error";
|
||||
import {LearningObjectIdentifier} from "../../../../interfaces/learning-content";
|
||||
import {Language} from "../../../../entities/content/language";
|
||||
import Image = Tokens.Image;
|
||||
import Heading = Tokens.Heading;
|
||||
import Link = Tokens.Link;
|
||||
|
||||
import Image = marked.Tokens.Image;
|
||||
import Heading = marked.Tokens.Heading;
|
||||
import Link = marked.Tokens.Link;
|
||||
import RendererObject = marked.RendererObject;
|
||||
|
||||
const prefixes = {
|
||||
learningObject: '@learning-object',
|
|
@ -1,6 +1,5 @@
|
|||
/**
|
||||
* Based on https://github.com/dwengovzw/Learning-Object-Repository/blob/main/app/processors/markdown/markdown_processor.js
|
||||
* and https://github.com/dwengovzw/Learning-Object-Repository/blob/main/app/processors/markdown/learing_object_markdown_renderer.js [sic!]
|
||||
*/
|
||||
|
||||
import {marked} from 'marked'
|
||||
|
@ -8,7 +7,7 @@ import Processor from '../processor.js';
|
|||
import InlineImageProcessor from '../image/inline-image-processor.js';
|
||||
import {DwengoContentType} from "../content-type";
|
||||
import {ProcessingError} from "../processing-error";
|
||||
import dwengoMarkedRenderer from "./learning-object-markdown-renderer";
|
||||
import dwengoMarkedRenderer from "./dwengo-marked-renderer";
|
||||
|
||||
class MarkdownProcessor extends Processor<string> {
|
||||
constructor() {
|
||||
|
|
|
@ -35,9 +35,9 @@ class ProcessingService {
|
|||
new GiftProcessor()
|
||||
];
|
||||
|
||||
processors.forEach(processor => {
|
||||
this.processors.set(processor.contentType, processor);
|
||||
});
|
||||
this.processors = new Map(
|
||||
processors.map(processor => [processor.contentType, processor])
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -15,8 +15,6 @@ import {getLearningPathRepository} from "../../data/repositories";
|
|||
import {Language} from "../../entities/content/language";
|
||||
import learningObjectService from "../learning-objects/learning-object-service";
|
||||
|
||||
const learningPathRepo = getLearningPathRepository();
|
||||
|
||||
/**
|
||||
* Fetches the corresponding learning object for each of the nodes and creates a map that maps each node to its
|
||||
* corresponding learning object.
|
||||
|
@ -138,6 +136,8 @@ const databaseLearningPathProvider: LearningPathProvider = {
|
|||
* Fetch the learning paths with the given hruids from the database.
|
||||
*/
|
||||
async fetchLearningPaths(hruids: string[], language: Language, source: string): Promise<LearningPathResponse> {
|
||||
const learningPathRepo = getLearningPathRepository();
|
||||
|
||||
const learningPaths = await Promise.all(
|
||||
hruids.map(hruid => learningPathRepo.findByHruidAndLanguage(hruid, language))
|
||||
);
|
||||
|
@ -158,6 +158,8 @@ const databaseLearningPathProvider: LearningPathProvider = {
|
|||
* Search learning paths in the database using the given search string.
|
||||
*/
|
||||
async searchLearningPaths(query: string, language: Language): Promise<LearningPath[]> {
|
||||
const learningPathRepo = getLearningPathRepository();
|
||||
|
||||
const searchResults = await learningPathRepo.findByQueryStringAndLanguage(query, language);
|
||||
return await Promise.all(
|
||||
searchResults.map((result, index) =>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue