fix(frontend): Linting errors/warnings opgelost

This commit is contained in:
Gerald Schmittinger 2025-04-01 15:00:47 +02:00
parent b2e6b33716
commit 4d98be78c1
26 changed files with 272 additions and 258 deletions

View file

@ -0,0 +1,4 @@
export interface EducationalGoal {
source: string;
id: string;
}

View file

@ -1,14 +1,6 @@
import type {Language} from "@/data-objects/language.ts";
export interface EducationalGoal {
source: string;
id: string;
}
export interface ReturnValue {
callback_url: string;
callback_schema: Record<string, any>;
}
import type {ReturnValue} from "@/data-objects/learning-objects/return-value.ts";
import type {EducationalGoal} from "@/data-objects/learning-objects/educational-goal.ts";
export interface LearningObject {
key: string;

View file

@ -0,0 +1,4 @@
export interface ReturnValue {
callback_url: string;
callback_schema: Record<string, unknown>;
}

View file

@ -1,128 +0,0 @@
import type {Language} from "@/data-objects/language.ts";
export interface LearningPathDTO {
language: string;
hruid: string;
title: string;
description: string;
image?: string; // Image might be missing, so it's optional
num_nodes: number;
num_nodes_left: number;
nodes: LearningPathNodeDTO[];
keywords: string;
target_ages: number[];
min_age: number;
max_age: number;
__order: number;
}
interface LearningPathNodeDTO {
_id: string;
learningobject_hruid: string;
version: number;
language: Language;
start_node?: boolean;
transitions: LearningPathTransitionDTO[];
created_at: string;
updatedAt: string;
done?: boolean; // True if a submission exists for this node by the user for whom the learning path is customized.
}
interface LearningPathTransitionDTO {
default: boolean;
_id: string;
next: {
_id: string;
hruid: string;
version: number;
language: string;
};
}
export class LearningPathNode {
constructor(
public readonly learningobjectHruid: string,
public readonly version: number,
public readonly language: Language,
public readonly transitions: {next: LearningPathNode, default: boolean}[],
public readonly createdAt: Date,
public readonly updatedAt: Date,
public readonly done: boolean = false
) {
}
static fromDTOAndOtherNodes(dto: LearningPathNodeDTO, otherNodes: LearningPathNodeDTO[]): LearningPathNode {
return new LearningPathNode(
dto.learningobject_hruid,
dto.version,
dto.language,
dto.transitions.map(transDto => {
let nextNodeDto = otherNodes.filter(it =>
it.learningobject_hruid === transDto.next.hruid
&& it.language === transDto.next.language
&& it.version === transDto.next.version
);
if (nextNodeDto.length !== 1) {
throw new Error(`Invalid learning path! There is a transition to node`
+ `${transDto.next.hruid}/${transDto.next.language}/${transDto.next.version}, but there are`
+ `${nextNodeDto.length} such nodes.`);
}
return {
next: LearningPathNode.fromDTOAndOtherNodes(nextNodeDto[0], otherNodes),
default: transDto.default
}
}),
new Date(dto.created_at),
new Date(dto.updatedAt),
dto.done
)
}
}
export class LearningPath {
constructor(
public readonly language: string,
public readonly hruid: string,
public readonly title: string,
public readonly description: string,
public readonly amountOfNodes: number,
public readonly amountOfNodesLeft: number,
public readonly keywords: string[],
public readonly targetAges: {min: number; max: number},
public readonly startNode: LearningPathNode,
public readonly image?: string // Image might be missing, so it's optional
) {
}
public get nodesAsList(): LearningPathNode[] {
let list: LearningPathNode[] = [];
let currentNode = this.startNode;
while (currentNode) {
list.push(currentNode);
currentNode = currentNode.transitions.filter(it => it.default)[0]?.next
|| currentNode.transitions[0]?.next;
}
return list;
}
static fromDTO(dto: LearningPathDTO): LearningPath {
let startNodeDto = dto.nodes.filter(it => it.start_node === true);
if (startNodeDto.length !== 1) {
throw new Error(`Invalid learning path: ${dto.hruid}/${dto.language}!
Expected precisely one start node, but there were ${startNodeDto.length}.`);
}
return new LearningPath(
dto.language,
dto.hruid,
dto.title,
dto.description,
dto.num_nodes,
dto.num_nodes_left,
dto.keywords.split(' '),
{min: dto.min_age, max: dto.max_age},
LearningPathNode.fromDTOAndOtherNodes(startNodeDto[0], dto.nodes),
dto.image
)
}
}

View file

@ -0,0 +1,17 @@
import type {LearningPathNodeDTO} from "@/data-objects/learning-paths/learning-path.ts";
export interface LearningPathDTO {
language: string;
hruid: string;
title: string;
description: string;
image?: string; // Image might be missing, so it's optional
num_nodes: number;
num_nodes_left: number;
nodes: LearningPathNodeDTO[];
keywords: string;
target_ages: number[];
min_age: number;
max_age: number;
__order: number;
}

View file

@ -0,0 +1,57 @@
import type {Language} from "@/data-objects/language.ts";
import type {LearningPathNodeDTO} from "@/data-objects/learning-paths/learning-path.ts";
export class LearningPathNode {
public readonly learningobjectHruid: string;
public readonly version: number;
public readonly language: Language;
public readonly transitions: { next: LearningPathNode, default: boolean }[];
public readonly createdAt: Date;
public readonly updatedAt: Date;
public readonly done: boolean;
constructor(options: {
learningobjectHruid: string,
version: number,
language: Language,
transitions: { next: LearningPathNode, default: boolean }[],
createdAt: Date,
updatedAt: Date,
done?: boolean
}) {
this.learningobjectHruid = options.learningobjectHruid;
this.version = options.version;
this.language = options.language;
this.transitions = options.transitions;
this.createdAt = options.createdAt;
this.updatedAt = options.updatedAt;
this.done = options.done || false;
}
static fromDTOAndOtherNodes(dto: LearningPathNodeDTO, otherNodes: LearningPathNodeDTO[]): LearningPathNode {
return new LearningPathNode({
learningobjectHruid: dto.learningobject_hruid,
version: dto.version,
language: dto.language,
transitions: dto.transitions.map(transDto => {
const nextNodeDto = otherNodes.filter(it =>
it.learningobject_hruid === transDto.next.hruid
&& it.language === transDto.next.language
&& it.version === transDto.next.version
);
if (nextNodeDto.length !== 1) {
throw new Error(`Invalid learning path! There is a transition to node`
+ `${transDto.next.hruid}/${transDto.next.language}/${transDto.next.version}, but there are`
+ `${nextNodeDto.length} such nodes.`);
}
return {
next: LearningPathNode.fromDTOAndOtherNodes(nextNodeDto[0], otherNodes),
default: transDto.default
}
}),
createdAt: new Date(dto.created_at),
updatedAt: new Date(dto.updatedAt),
done: dto.done
})
}
}

View file

@ -0,0 +1,94 @@
import type {Language} from "@/data-objects/language.ts";
import {LearningPathNode} from "@/data-objects/learning-paths/learning-path-node.ts";
import type {LearningPathDTO} from "@/data-objects/learning-paths/learning-path-dto.ts";
export interface LearningPathNodeDTO {
_id: string;
learningobject_hruid: string;
version: number;
language: Language;
start_node?: boolean;
transitions: LearningPathTransitionDTO[];
created_at: string;
updatedAt: string;
done?: boolean; // True if a submission exists for this node by the user for whom the learning path is customized.
}
export interface LearningPathTransitionDTO {
default: boolean;
_id: string;
next: {
_id: string;
hruid: string;
version: number;
language: string;
};
}
export class LearningPath {
public readonly language: string;
public readonly hruid: string;
public readonly title: string;
public readonly description: string;
public readonly amountOfNodes: number;
public readonly amountOfNodesLeft: number;
public readonly keywords: string[];
public readonly targetAges: {min: number; max: number};
public readonly startNode: LearningPathNode;
public readonly image?: string; // Image might be missing, so it's optional
constructor(options: {
language: string,
hruid: string,
title: string,
description: string,
amountOfNodes: number,
amountOfNodesLeft: number,
keywords: string[],
targetAges: {min: number; max: number},
startNode: LearningPathNode,
image?: string // Image might be missing, so it's optional
}) {
this.language = options.language;
this.hruid = options.hruid;
this.title = options.title;
this.description = options.description;
this.amountOfNodes = options.amountOfNodes;
this.amountOfNodesLeft = options.amountOfNodesLeft;
this.keywords = options.keywords;
this.targetAges = options.targetAges;
this.startNode = options.startNode;
this.image = options.image;
}
public get nodesAsList(): LearningPathNode[] {
const list: LearningPathNode[] = [];
let currentNode = this.startNode;
while (currentNode) {
list.push(currentNode);
currentNode = currentNode.transitions.find(it => it.default)?.next
|| currentNode.transitions[0]?.next;
}
return list;
}
static fromDTO(dto: LearningPathDTO): LearningPath {
const startNodeDto = dto.nodes.filter(it => it.start_node === true);
if (startNodeDto.length !== 1) {
throw new Error(`Invalid learning path: ${dto.hruid}/${dto.language}!
Expected precisely one start node, but there were ${startNodeDto.length}.`);
}
return new LearningPath({
language: dto.language,
hruid: dto.hruid,
title: dto.title,
description: dto.description,
amountOfNodes: dto.num_nodes,
amountOfNodesLeft: dto.num_nodes_left,
keywords: dto.keywords.split(' '),
targetAges: {min: dto.min_age, max: dto.max_age},
startNode: LearningPathNode.fromDTOAndOtherNodes(startNodeDto[0], dto.nodes),
image: dto.image
});
}
}