test(backend): Testen voor DatabaseLearningPathProvider.fetchLearningPaths afgewerkt

Hierbij optredende problemen opgelost.
This commit is contained in:
Gerald Schmittinger 2025-03-10 21:14:40 +01:00
parent 1f9e9ed70a
commit 7018a8822d
10 changed files with 139 additions and 32 deletions

View file

@ -7,21 +7,30 @@ export class LearningObjectRepository extends DwengoEntityRepository<LearningObj
public findByIdentifier(
identifier: LearningObjectIdentifier
): Promise<LearningObject | null> {
return this.findOne({
hruid: identifier.hruid,
language: identifier.language,
version: identifier.version,
});
return this.findOne(
{
hruid: identifier.hruid,
language: identifier.language,
version: identifier.version,
},
{
populate: ["keywords"]
}
);
}
public findLatestByHruidAndLanguage(hruid: string, language: Language) {
return this.findOne({
hruid: hruid,
language: language
}, {
orderBy: {
version: "DESC"
return this.findOne(
{
hruid: hruid,
language: language
},
{
populate: ["keywords"],
orderBy: {
version: "DESC"
}
}
});
);
}
}

View file

@ -7,7 +7,10 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
hruid: string,
language: Language
): Promise<LearningPath | null> {
return this.findOne({ hruid: hruid, language: language });
return this.findOne(
{ hruid: hruid, language: language },
{ populate: ["nodes", "nodes.transitions"] }
);
}
/**
@ -25,8 +28,8 @@ export class LearningPathRepository extends DwengoEntityRepository<LearningPath>
{ title: { $like: `%${query}%`} },
{ description: { $like: `%${query}%`} }
]
}
},
populate: ["nodes", "nodes.transitions"]
});
}
// This repository is read-only for now since creating own learning object is an extension feature.
}

View file

@ -33,6 +33,8 @@ import { LearningPath } from '../entities/content/learning-path.entity.js';
import { LearningPathRepository } from './content/learning-path-repository.js';
import { AttachmentRepository } from './content/attachment-repository.js';
import { Attachment } from '../entities/content/attachment.entity.js';
import {LearningPathNode} from "../entities/content/learning-path-node.entity";
import {LearningPathTransition} from "../entities/content/learning-path-transition.entity";
let entityManager: EntityManager | undefined;
@ -113,6 +115,8 @@ export const getLearningPathRepository = repositoryGetter<
LearningPath,
LearningPathRepository
>(LearningPath);
export const getLearningPathNodeRepository = repositoryGetter(LearningPathNode);
export const getLearningPathTransitionRepository = repositoryGetter(LearningPathTransition);
export const getAttachmentRepository = repositoryGetter<
Attachment,
AttachmentRepository

View file

@ -5,10 +5,11 @@ import {LearningPathTransition} from "./learning-path-transition.entity";
@Entity()
export class LearningPathNode {
@ManyToOne({ entity: () => LearningPath, primary: true })
learningPath!: LearningPath;
@PrimaryKey({ type: "numeric", autoincrement: true })
@PrimaryKey({ type: "integer", autoincrement: true })
nodeNumber!: number;
@Property({ type: 'string' })

View file

@ -3,7 +3,7 @@ import {LearningPathNode} from "./learning-path-node.entity";
@Entity()
export class LearningPathTransition {
@ManyToOne({entity: () => LearningPathNode })
@ManyToOne({entity: () => LearningPathNode, primary: true })
node!: LearningPathNode;
@PrimaryKey({ type: 'numeric' })

View file

@ -21,7 +21,7 @@ export interface LearningObjectNode {
_id: string;
learningobject_hruid: string;
version: number;
language: string;
language: Language;
start_node?: boolean;
transitions: Transition[];
created_at: string;
@ -88,7 +88,7 @@ export interface FilteredLearningObject {
version: number;
title: string;
htmlUrl: string;
language: string;
language: Language;
difficulty: number;
estimatedTime: number;
available: boolean;