style: fix linting issues met Prettier

This commit is contained in:
Lint Action 2025-03-11 05:14:08 +00:00
parent bdbfe380be
commit 6624dacabd
4 changed files with 41 additions and 31 deletions

View file

@ -6,11 +6,7 @@ import { Language } from '../../entities/content/language';
import learningObjectService from '../learning-objects/learning-object-service'; import learningObjectService from '../learning-objects/learning-object-service';
import { LearningPathNode } from '../../entities/content/learning-path-node.entity'; import { LearningPathNode } from '../../entities/content/learning-path-node.entity';
import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity'; import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity';
import { import { getLastSubmissionForCustomizationTarget, isTransitionPossible, PersonalizationTarget } from './learning-path-personalization-util';
getLastSubmissionForCustomizationTarget,
isTransitionPossible,
PersonalizationTarget
} from "./learning-path-personalization-util";
/** /**
* Fetches the corresponding learning object for each of the nodes and creates a map that maps each node to its * Fetches the corresponding learning object for each of the nodes and creates a map that maps each node to its
@ -69,7 +65,7 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb
title: learningPath.title, title: learningPath.title,
nodes: convertedNodes, nodes: convertedNodes,
num_nodes: learningPath.nodes.length, num_nodes: learningPath.nodes.length,
num_nodes_left: convertedNodes.filter(it => !it.done).length, num_nodes_left: convertedNodes.filter((it) => !it.done).length,
keywords: keywords.join(' '), keywords: keywords.join(' '),
target_ages: targetAges, target_ages: targetAges,
max_age: Math.max(...targetAges), max_age: Math.max(...targetAges),
@ -83,10 +79,13 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb
* @param nodesToLearningObjects * @param nodesToLearningObjects
* @param personalizedFor * @param personalizedFor
*/ */
async function convertNodes(nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>, personalizedFor?: PersonalizationTarget): Promise<LearningObjectNode[]> { async function convertNodes(
nodesToLearningObjects: Map<LearningPathNode, FilteredLearningObject>,
personalizedFor?: PersonalizationTarget
): Promise<LearningObjectNode[]> {
const nodesPromise = nodesToLearningObjects const nodesPromise = nodesToLearningObjects
.entries() .entries()
.map(async(entry) => { .map(async (entry) => {
const [node, learningObject] = entry; const [node, learningObject] = entry;
const lastSubmission = personalizedFor ? await getLastSubmissionForCustomizationTarget(node, personalizedFor) : null; const lastSubmission = personalizedFor ? await getLastSubmissionForCustomizationTarget(node, personalizedFor) : null;
return { return {
@ -98,7 +97,7 @@ async function convertNodes(nodesToLearningObjects: Map<LearningPathNode, Filter
learningobject_hruid: node.learningObjectHruid, learningobject_hruid: node.learningObjectHruid,
version: learningObject.version, version: learningObject.version,
transitions: node.transitions transitions: node.transitions
.filter(trans => !personalizedFor || isTransitionPossible(trans, lastSubmission)) // If we want a personalized learning path, remove all transitions that aren't possible. .filter((trans) => !personalizedFor || isTransitionPossible(trans, lastSubmission)) // If we want a personalized learning path, remove all transitions that aren't possible.
.map((trans, i) => convertTransition(trans, i, nodesToLearningObjects)), // Then convert all the transition .map((trans, i) => convertTransition(trans, i, nodesToLearningObjects)), // Then convert all the transition
}; };
}) })
@ -143,14 +142,17 @@ const databaseLearningPathProvider: LearningPathProvider = {
/** /**
* Fetch the learning paths with the given hruids from the database. * Fetch the learning paths with the given hruids from the database.
*/ */
async fetchLearningPaths(hruids: string[], language: Language, source: string, personalizedFor?: PersonalizationTarget): Promise<LearningPathResponse> { async fetchLearningPaths(
hruids: string[],
language: Language,
source: string,
personalizedFor?: PersonalizationTarget
): Promise<LearningPathResponse> {
const learningPathRepo = getLearningPathRepository(); const learningPathRepo = getLearningPathRepository();
const learningPaths = ( const learningPaths = (await Promise.all(hruids.map((hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language)))).filter(
await Promise.all( (learningPath) => learningPath !== null
hruids.map((hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language)) );
)
).filter((learningPath) => learningPath !== null);
const filteredLearningPaths = await Promise.all( const filteredLearningPaths = await Promise.all(
learningPaths.map((learningPath, index) => convertLearningPath(learningPath, index, personalizedFor)) learningPaths.map((learningPath, index) => convertLearningPath(learningPath, index, personalizedFor))
); );

View file

@ -1,11 +1,11 @@
import {LearningPathNode} from "../../entities/content/learning-path-node.entity"; import { LearningPathNode } from '../../entities/content/learning-path-node.entity';
import {Student} from "../../entities/users/student.entity"; import { Student } from '../../entities/users/student.entity';
import {Group} from "../../entities/assignments/group.entity"; import { Group } from '../../entities/assignments/group.entity';
import {Submission} from "../../entities/assignments/submission.entity"; import { Submission } from '../../entities/assignments/submission.entity';
import {getSubmissionRepository} from "../../data/repositories"; import { getSubmissionRepository } from '../../data/repositories';
import {LearningObjectIdentifier} from "../../entities/content/learning-object-identifier"; import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier';
import {LearningPathTransition} from "../../entities/content/learning-path-transition.entity"; import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity';
import {JSONPath} from "jsonpath-plus"; import { JSONPath } from 'jsonpath-plus';
export type PersonalizationTarget = { type: 'student'; student: Student } | { type: 'group'; group: Group }; export type PersonalizationTarget = { type: 'student'; student: Student } | { type: 'group'; group: Group };
/** /**
@ -20,12 +20,10 @@ export async function getLastSubmissionForCustomizationTarget(node: LearningPath
}; };
if (pathFor.type === 'group') { if (pathFor.type === 'group') {
return await submissionRepo.findMostRecentSubmissionForGroup(learningObjectId, pathFor.group); return await submissionRepo.findMostRecentSubmissionForGroup(learningObjectId, pathFor.group);
} }
return await submissionRepo.findMostRecentSubmissionForStudent(learningObjectId, pathFor.student); return await submissionRepo.findMostRecentSubmissionForStudent(learningObjectId, pathFor.student);
} }
/** /**
* Checks whether the condition of the given transaction is fulfilled by the given submission. * Checks whether the condition of the given transaction is fulfilled by the given submission.
* @param transition * @param transition

View file

@ -1,6 +1,6 @@
import { LearningPath, LearningPathResponse } from '../../interfaces/learning-content'; import { LearningPath, LearningPathResponse } from '../../interfaces/learning-content';
import { Language } from '../../entities/content/language'; import { Language } from '../../entities/content/language';
import {PersonalizationTarget} from "./learning-path-personalizing-service"; import { PersonalizationTarget } from './learning-path-personalizing-service';
/** /**
* Generic interface for a service which provides access to learning paths from a data source. * Generic interface for a service which provides access to learning paths from a data source.

View file

@ -3,7 +3,7 @@ import dwengoApiLearningPathProvider from './dwengo-api-learning-path-provider';
import databaseLearningPathProvider from './database-learning-path-provider'; import databaseLearningPathProvider from './database-learning-path-provider';
import { EnvVars, getEnvVar } from '../../util/envvars'; import { EnvVars, getEnvVar } from '../../util/envvars';
import { Language } from '../../entities/content/language'; import { Language } from '../../entities/content/language';
import {PersonalizationTarget} from "./learning-path-personalizing-service"; import { PersonalizationTarget } from './learning-path-personalizing-service';
const userContentPrefix = getEnvVar(EnvVars.UserContentPrefix); const userContentPrefix = getEnvVar(EnvVars.UserContentPrefix);
const allProviders = [dwengoApiLearningPathProvider, databaseLearningPathProvider]; const allProviders = [dwengoApiLearningPathProvider, databaseLearningPathProvider];
@ -19,12 +19,22 @@ const learningPathService = {
* @param source * @param source
* @param personalizedFor If this is set, a learning path personalized for the given group or student will be returned. * @param personalizedFor If this is set, a learning path personalized for the given group or student will be returned.
*/ */
async fetchLearningPaths(hruids: string[], language: Language, source: string, personalizedFor?: PersonalizationTarget): Promise<LearningPathResponse> { async fetchLearningPaths(
hruids: string[],
language: Language,
source: string,
personalizedFor?: PersonalizationTarget
): Promise<LearningPathResponse> {
const userContentHruids = hruids.filter((hruid) => hruid.startsWith(userContentPrefix)); const userContentHruids = hruids.filter((hruid) => hruid.startsWith(userContentPrefix));
const nonUserContentHruids = hruids.filter((hruid) => !hruid.startsWith(userContentPrefix)); const nonUserContentHruids = hruids.filter((hruid) => !hruid.startsWith(userContentPrefix));
const userContentLearningPaths = await databaseLearningPathProvider.fetchLearningPaths(userContentHruids, language, source, personalizedFor); const userContentLearningPaths = await databaseLearningPathProvider.fetchLearningPaths(userContentHruids, language, source, personalizedFor);
const nonUserContentLearningPaths = await dwengoApiLearningPathProvider.fetchLearningPaths(nonUserContentHruids, language, source, personalizedFor); const nonUserContentLearningPaths = await dwengoApiLearningPathProvider.fetchLearningPaths(
nonUserContentHruids,
language,
source,
personalizedFor
);
const result = (userContentLearningPaths.data || []).concat(nonUserContentLearningPaths.data || []); const result = (userContentLearningPaths.data || []).concat(nonUserContentLearningPaths.data || []);