From bdbfe380bedf4dd97166a7425fe17dd9250aaa9a Mon Sep 17 00:00:00 2001 From: Lint Action Date: Tue, 11 Mar 2025 05:14:04 +0000 Subject: [PATCH 1/2] style: fix linting issues met ESLint --- backend/src/interfaces/learning-content.ts | 2 +- .../learning-paths/database-learning-path-provider.ts | 2 +- .../learning-paths/learning-path-personalization-util.ts | 4 ++-- backend/src/services/learning-paths/learning-path-service.ts | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/backend/src/interfaces/learning-content.ts b/backend/src/interfaces/learning-content.ts index a558dd9c..997865ef 100644 --- a/backend/src/interfaces/learning-content.ts +++ b/backend/src/interfaces/learning-content.ts @@ -26,7 +26,7 @@ export interface LearningObjectNode { transitions: Transition[]; 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. + done?: boolean; // True if a submission exists for this node by the user for whom the learning path is customized. } export interface LearningPath { diff --git a/backend/src/services/learning-paths/database-learning-path-provider.ts b/backend/src/services/learning-paths/database-learning-path-provider.ts index d804ad64..2a784daf 100644 --- a/backend/src/services/learning-paths/database-learning-path-provider.ts +++ b/backend/src/services/learning-paths/database-learning-path-provider.ts @@ -99,7 +99,7 @@ async function convertNodes(nodesToLearningObjects: Map !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 }; }) .toArray(); diff --git a/backend/src/services/learning-paths/learning-path-personalization-util.ts b/backend/src/services/learning-paths/learning-path-personalization-util.ts index 9217fa34..df268735 100644 --- a/backend/src/services/learning-paths/learning-path-personalization-util.ts +++ b/backend/src/services/learning-paths/learning-path-personalization-util.ts @@ -20,9 +20,9 @@ export async function getLastSubmissionForCustomizationTarget(node: LearningPath }; if (pathFor.type === 'group') { return await submissionRepo.findMostRecentSubmissionForGroup(learningObjectId, pathFor.group); - } else { + } return await submissionRepo.findMostRecentSubmissionForStudent(learningObjectId, pathFor.student); - } + } diff --git a/backend/src/services/learning-paths/learning-path-service.ts b/backend/src/services/learning-paths/learning-path-service.ts index c204872c..f2372672 100644 --- a/backend/src/services/learning-paths/learning-path-service.ts +++ b/backend/src/services/learning-paths/learning-path-service.ts @@ -26,7 +26,7 @@ const learningPathService = { const userContentLearningPaths = await databaseLearningPathProvider.fetchLearningPaths(userContentHruids, language, source, personalizedFor); const nonUserContentLearningPaths = await dwengoApiLearningPathProvider.fetchLearningPaths(nonUserContentHruids, language, source, personalizedFor); - let result = (userContentLearningPaths.data || []).concat(nonUserContentLearningPaths.data || []); + const result = (userContentLearningPaths.data || []).concat(nonUserContentLearningPaths.data || []); return { data: result, From 6624dacabda649bedee8a9796d5ab203d27c21d8 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Tue, 11 Mar 2025 05:14:08 +0000 Subject: [PATCH 2/2] style: fix linting issues met Prettier --- .../database-learning-path-provider.ts | 32 ++++++++++--------- .../learning-path-personalization-util.ts | 22 ++++++------- .../learning-paths/learning-path-provider.ts | 2 +- .../learning-paths/learning-path-service.ts | 16 ++++++++-- 4 files changed, 41 insertions(+), 31 deletions(-) diff --git a/backend/src/services/learning-paths/database-learning-path-provider.ts b/backend/src/services/learning-paths/database-learning-path-provider.ts index 2a784daf..36ab58a9 100644 --- a/backend/src/services/learning-paths/database-learning-path-provider.ts +++ b/backend/src/services/learning-paths/database-learning-path-provider.ts @@ -6,11 +6,7 @@ import { Language } from '../../entities/content/language'; import learningObjectService from '../learning-objects/learning-object-service'; import { LearningPathNode } from '../../entities/content/learning-path-node.entity'; import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity'; -import { - getLastSubmissionForCustomizationTarget, - isTransitionPossible, - PersonalizationTarget -} from "./learning-path-personalization-util"; +import { 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 @@ -69,7 +65,7 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb title: learningPath.title, nodes: convertedNodes, 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(' '), target_ages: targetAges, max_age: Math.max(...targetAges), @@ -83,10 +79,13 @@ async function convertLearningPath(learningPath: LearningPathEntity, order: numb * @param nodesToLearningObjects * @param personalizedFor */ -async function convertNodes(nodesToLearningObjects: Map, personalizedFor?: PersonalizationTarget): Promise { +async function convertNodes( + nodesToLearningObjects: Map, + personalizedFor?: PersonalizationTarget +): Promise { const nodesPromise = nodesToLearningObjects .entries() - .map(async(entry) => { + .map(async (entry) => { const [node, learningObject] = entry; const lastSubmission = personalizedFor ? await getLastSubmissionForCustomizationTarget(node, personalizedFor) : null; return { @@ -98,7 +97,7 @@ async function convertNodes(nodesToLearningObjects: Map !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 }; }) @@ -143,14 +142,17 @@ const databaseLearningPathProvider: LearningPathProvider = { /** * Fetch the learning paths with the given hruids from the database. */ - async fetchLearningPaths(hruids: string[], language: Language, source: string, personalizedFor?: PersonalizationTarget): Promise { + async fetchLearningPaths( + hruids: string[], + language: Language, + source: string, + personalizedFor?: PersonalizationTarget + ): Promise { const learningPathRepo = getLearningPathRepository(); - const learningPaths = ( - await Promise.all( - hruids.map((hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language)) - ) - ).filter((learningPath) => learningPath !== null); + const learningPaths = (await Promise.all(hruids.map((hruid) => learningPathRepo.findByHruidAndLanguage(hruid, language)))).filter( + (learningPath) => learningPath !== null + ); const filteredLearningPaths = await Promise.all( learningPaths.map((learningPath, index) => convertLearningPath(learningPath, index, personalizedFor)) ); diff --git a/backend/src/services/learning-paths/learning-path-personalization-util.ts b/backend/src/services/learning-paths/learning-path-personalization-util.ts index df268735..533ef15c 100644 --- a/backend/src/services/learning-paths/learning-path-personalization-util.ts +++ b/backend/src/services/learning-paths/learning-path-personalization-util.ts @@ -1,11 +1,11 @@ -import {LearningPathNode} from "../../entities/content/learning-path-node.entity"; -import {Student} from "../../entities/users/student.entity"; -import {Group} from "../../entities/assignments/group.entity"; -import {Submission} from "../../entities/assignments/submission.entity"; -import {getSubmissionRepository} from "../../data/repositories"; -import {LearningObjectIdentifier} from "../../entities/content/learning-object-identifier"; -import {LearningPathTransition} from "../../entities/content/learning-path-transition.entity"; -import {JSONPath} from "jsonpath-plus"; +import { LearningPathNode } from '../../entities/content/learning-path-node.entity'; +import { Student } from '../../entities/users/student.entity'; +import { Group } from '../../entities/assignments/group.entity'; +import { Submission } from '../../entities/assignments/submission.entity'; +import { getSubmissionRepository } from '../../data/repositories'; +import { LearningObjectIdentifier } from '../../entities/content/learning-object-identifier'; +import { LearningPathTransition } from '../../entities/content/learning-path-transition.entity'; +import { JSONPath } from 'jsonpath-plus'; 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') { 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. * @param transition diff --git a/backend/src/services/learning-paths/learning-path-provider.ts b/backend/src/services/learning-paths/learning-path-provider.ts index 571c231a..8736df21 100644 --- a/backend/src/services/learning-paths/learning-path-provider.ts +++ b/backend/src/services/learning-paths/learning-path-provider.ts @@ -1,6 +1,6 @@ import { LearningPath, LearningPathResponse } from '../../interfaces/learning-content'; 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. diff --git a/backend/src/services/learning-paths/learning-path-service.ts b/backend/src/services/learning-paths/learning-path-service.ts index f2372672..b7c7e794 100644 --- a/backend/src/services/learning-paths/learning-path-service.ts +++ b/backend/src/services/learning-paths/learning-path-service.ts @@ -3,7 +3,7 @@ import dwengoApiLearningPathProvider from './dwengo-api-learning-path-provider'; import databaseLearningPathProvider from './database-learning-path-provider'; import { EnvVars, getEnvVar } from '../../util/envvars'; 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 allProviders = [dwengoApiLearningPathProvider, databaseLearningPathProvider]; @@ -19,12 +19,22 @@ const learningPathService = { * @param source * @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 { + async fetchLearningPaths( + hruids: string[], + language: Language, + source: string, + personalizedFor?: PersonalizationTarget + ): Promise { const userContentHruids = hruids.filter((hruid) => hruid.startsWith(userContentPrefix)); const nonUserContentHruids = hruids.filter((hruid) => !hruid.startsWith(userContentPrefix)); 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 || []);