style: fix linting issues met Prettier
This commit is contained in:
parent
ed8b5c919d
commit
ea5cf7abf9
26 changed files with 467 additions and 422 deletions
|
@ -1,4 +1,4 @@
|
|||
import type {LearningPathNodeDTO} from "@/data-objects/learning-paths/learning-path.ts";
|
||||
import type { LearningPathNodeDTO } from "@/data-objects/learning-paths/learning-path.ts";
|
||||
|
||||
export interface LearningPathDTO {
|
||||
language: string;
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
import type {Language} from "@/data-objects/language.ts";
|
||||
import type {LearningPathNodeDTO} from "@/data-objects/learning-paths/learning-path.ts";
|
||||
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 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
|
||||
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;
|
||||
|
@ -33,25 +33,28 @@ export class 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
|
||||
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.`);
|
||||
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
|
||||
}
|
||||
default: transDto.default,
|
||||
};
|
||||
}),
|
||||
createdAt: new Date(dto.created_at),
|
||||
updatedAt: new Date(dto.updatedAt),
|
||||
done: dto.done
|
||||
})
|
||||
done: dto.done,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
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";
|
||||
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;
|
||||
|
@ -33,21 +33,21 @@ export class LearningPath {
|
|||
public readonly amountOfNodes: number;
|
||||
public readonly amountOfNodesLeft: number;
|
||||
public readonly keywords: string[];
|
||||
public readonly targetAges: {min: number; max: number};
|
||||
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
|
||||
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;
|
||||
|
@ -66,14 +66,13 @@ export class LearningPath {
|
|||
let currentNode = this.startNode;
|
||||
while (currentNode) {
|
||||
list.push(currentNode);
|
||||
currentNode = currentNode.transitions.find(it => it.default)?.next
|
||||
|| currentNode.transitions[0]?.next;
|
||||
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);
|
||||
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}.`);
|
||||
|
@ -85,10 +84,10 @@ export class LearningPath {
|
|||
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},
|
||||
keywords: dto.keywords.split(" "),
|
||||
targetAges: { min: dto.min_age, max: dto.max_age },
|
||||
startNode: LearningPathNode.fromDTOAndOtherNodes(startNodeDto[0], dto.nodes),
|
||||
image: dto.image
|
||||
image: dto.image,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue