diff --git a/backend/src/controllers/learningPaths.ts b/backend/src/controllers/learningPaths.ts index cf084e2b..8c86f0d2 100644 --- a/backend/src/controllers/learningPaths.ts +++ b/backend/src/controllers/learningPaths.ts @@ -3,6 +3,7 @@ import { themes } from '../data/themes.js'; import {DWENGO_API_BASE, FALLBACK_LANG} from '../config.js'; import { fetchWithLogging } from "../util/apiHelper.js"; import { fetchLearningPaths } from "../services/learningPaths.js"; +import {LearningPath} from "../interfaces/learningPath"; /** * Fetch learning paths based on HRUIDs or return all if no HRUIDs are provided. @@ -14,13 +15,13 @@ export async function getLearningPaths(req: Request, res: Response): Promise theme.hruids); + hruidList = themes.flatMap((theme) => {return theme.hruids}); } const learningPaths = await fetchLearningPaths(hruidList, language, `HRUIDs: ${hruidList.join(', ')}`); @@ -41,7 +42,7 @@ export async function getLearningPathsByTheme(req: Request, res: Response): Prom const themeKey = req.params.theme; const language = (req.query.language as string) || FALLBACK_LANG; - const theme = themes.find((t) => t.title === themeKey); + const theme = themes.find((t) => {return t.title === themeKey}); if (!theme) { console.error(`⚠️ WARNING: Theme "${themeKey}" not found.`); res.status(404).json({ error: 'Theme not found' }); @@ -75,7 +76,7 @@ export async function searchLearningPaths(req: Request, res: Response): Promise< const apiUrl = `${DWENGO_API_BASE}/learningPath/search`; const params = { all: query, language }; - const searchResults = await fetchWithLogging(apiUrl, `Search learning paths with query "${query}"`, params); + const searchResults = await fetchWithLogging(apiUrl, `Search learning paths with query "${query}"`, params); res.json(searchResults ?? []); } catch (error) { console.error('❌ Unexpected error searching learning paths:', error); diff --git a/backend/src/interfaces/learningPath.ts b/backend/src/interfaces/learningPath.ts index 6f187bec..1e2cc6ef 100644 --- a/backend/src/interfaces/learningPath.ts +++ b/backend/src/interfaces/learningPath.ts @@ -1,8 +1,23 @@ -export interface LearningPathResponse { - success: boolean; - source: string; - data: LearningPath[] | null; - message?: string; +export interface Transition { + default: boolean; + _id: string; + next: { + _id: string; + hruid: string; + version: number; + language: string; + }; +} + +export interface LearningObjectNode { + _id: string; + learningobject_hruid: string; + version: number; + language: string; + start_node?: boolean; + transitions: Transition[]; + created_at: string; + updatedAt: string; } export interface LearningPath { @@ -22,26 +37,14 @@ export interface LearningPath { __order: number; } -export interface LearningObjectNode { - _id: string; - learningobject_hruid: string; - version: number; - language: string; - start_node?: boolean; - transitions: Transition[]; - created_at: string; - updatedAt: string; +export interface EducationalGoal { + source: string; + id: string; } -export interface Transition { - default: boolean; - _id: string; - next: { - _id: string; - hruid: string; - version: number; - language: string; - }; +export interface ReturnValue { + callback_url: string; + callback_schema: Record; } export interface LearningObjectMetadata { @@ -65,16 +68,6 @@ export interface LearningObjectMetadata { return_value?: ReturnValue; } -export interface EducationalGoal { - source: string; - id: string; -} - -export interface ReturnValue { - callback_url: string; - callback_schema: Record; -} - export interface FilteredLearningObject { key: string; _id: string; @@ -96,3 +89,10 @@ export interface FilteredLearningObject { skosConcepts?: string[]; returnValue?: ReturnValue; } + +export interface LearningPathResponse { + success: boolean; + source: string; + data: LearningPath[] | null; + message?: string; +} diff --git a/backend/src/services/learningObjects.ts b/backend/src/services/learningObjects.ts index e753ad26..f4da4faf 100644 --- a/backend/src/services/learningObjects.ts +++ b/backend/src/services/learningObjects.ts @@ -50,12 +50,12 @@ export async function getLearningObjectsFromPath( `Metadata for Learning Object HRUID "${node.learningobject_hruid}" (version ${node.version}, language ${language})` ); - if (!metadata) return null; + if (!metadata) {return null;} const htmlUrl = `${DWENGO_API_BASE}/learningObject/getRaw?hruid=${node.learningobject_hruid}&version=${node.version}&language=${language}`; return filterLearningObjectMetadata(metadata, htmlUrl); }) - ).then((objects) => objects.filter((obj): obj is FilteredLearningObject => obj !== null)); + ).then((objects) => {return objects.filter((obj): obj is FilteredLearningObject => {return obj !== null})}); } catch (error) { console.error('Error fetching learning objects:', error); return [];