fix: lint
This commit is contained in:
parent
6bb8c364b9
commit
5da0720a08
3 changed files with 40 additions and 39 deletions
|
@ -3,6 +3,7 @@ import { themes } from '../data/themes.js';
|
||||||
import {DWENGO_API_BASE, FALLBACK_LANG} from '../config.js';
|
import {DWENGO_API_BASE, FALLBACK_LANG} from '../config.js';
|
||||||
import { fetchWithLogging } from "../util/apiHelper.js";
|
import { fetchWithLogging } from "../util/apiHelper.js";
|
||||||
import { fetchLearningPaths } from "../services/learningPaths.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.
|
* 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<voi
|
||||||
const hruids = req.query.hruids; // Can be string or array
|
const hruids = req.query.hruids; // Can be string or array
|
||||||
const language = (req.query.language as string) || FALLBACK_LANG;
|
const language = (req.query.language as string) || FALLBACK_LANG;
|
||||||
|
|
||||||
let hruidList: string[] = [];
|
let hruidList: string[];
|
||||||
|
|
||||||
if (hruids) {
|
if (hruids) {
|
||||||
hruidList = Array.isArray(hruids) ? hruids.map(String) : [String(hruids)];
|
hruidList = Array.isArray(hruids) ? hruids.map(String) : [String(hruids)];
|
||||||
} else {
|
} else {
|
||||||
// If no hruids are provided, fetch ALL learning paths
|
// If no hruids are provided, fetch ALL learning paths
|
||||||
hruidList = themes.flatMap((theme) => theme.hruids);
|
hruidList = themes.flatMap((theme) => {return theme.hruids});
|
||||||
}
|
}
|
||||||
|
|
||||||
const learningPaths = await fetchLearningPaths(hruidList, language, `HRUIDs: ${hruidList.join(', ')}`);
|
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 themeKey = req.params.theme;
|
||||||
const language = (req.query.language as string) || FALLBACK_LANG;
|
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) {
|
if (!theme) {
|
||||||
console.error(`⚠️ WARNING: Theme "${themeKey}" not found.`);
|
console.error(`⚠️ WARNING: Theme "${themeKey}" not found.`);
|
||||||
res.status(404).json({ error: 'Theme 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 apiUrl = `${DWENGO_API_BASE}/learningPath/search`;
|
||||||
const params = { all: query, language };
|
const params = { all: query, language };
|
||||||
|
|
||||||
const searchResults = await fetchWithLogging<any>(apiUrl, `Search learning paths with query "${query}"`, params);
|
const searchResults = await fetchWithLogging<LearningPath[]>(apiUrl, `Search learning paths with query "${query}"`, params);
|
||||||
res.json(searchResults ?? []);
|
res.json(searchResults ?? []);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('❌ Unexpected error searching learning paths:', error);
|
console.error('❌ Unexpected error searching learning paths:', error);
|
||||||
|
|
|
@ -1,8 +1,23 @@
|
||||||
export interface LearningPathResponse {
|
export interface Transition {
|
||||||
success: boolean;
|
default: boolean;
|
||||||
source: string;
|
_id: string;
|
||||||
data: LearningPath[] | null;
|
next: {
|
||||||
message?: string;
|
_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 {
|
export interface LearningPath {
|
||||||
|
@ -22,26 +37,14 @@ export interface LearningPath {
|
||||||
__order: number;
|
__order: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LearningObjectNode {
|
export interface EducationalGoal {
|
||||||
_id: string;
|
source: string;
|
||||||
learningobject_hruid: string;
|
id: string;
|
||||||
version: number;
|
|
||||||
language: string;
|
|
||||||
start_node?: boolean;
|
|
||||||
transitions: Transition[];
|
|
||||||
created_at: string;
|
|
||||||
updatedAt: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Transition {
|
export interface ReturnValue {
|
||||||
default: boolean;
|
callback_url: string;
|
||||||
_id: string;
|
callback_schema: Record<string, any>;
|
||||||
next: {
|
|
||||||
_id: string;
|
|
||||||
hruid: string;
|
|
||||||
version: number;
|
|
||||||
language: string;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface LearningObjectMetadata {
|
export interface LearningObjectMetadata {
|
||||||
|
@ -65,16 +68,6 @@ export interface LearningObjectMetadata {
|
||||||
return_value?: ReturnValue;
|
return_value?: ReturnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface EducationalGoal {
|
|
||||||
source: string;
|
|
||||||
id: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface ReturnValue {
|
|
||||||
callback_url: string;
|
|
||||||
callback_schema: Record<string, any>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface FilteredLearningObject {
|
export interface FilteredLearningObject {
|
||||||
key: string;
|
key: string;
|
||||||
_id: string;
|
_id: string;
|
||||||
|
@ -96,3 +89,10 @@ export interface FilteredLearningObject {
|
||||||
skosConcepts?: string[];
|
skosConcepts?: string[];
|
||||||
returnValue?: ReturnValue;
|
returnValue?: ReturnValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LearningPathResponse {
|
||||||
|
success: boolean;
|
||||||
|
source: string;
|
||||||
|
data: LearningPath[] | null;
|
||||||
|
message?: string;
|
||||||
|
}
|
||||||
|
|
|
@ -50,12 +50,12 @@ export async function getLearningObjectsFromPath(
|
||||||
`Metadata for Learning Object HRUID "${node.learningobject_hruid}" (version ${node.version}, language ${language})`
|
`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}`;
|
const htmlUrl = `${DWENGO_API_BASE}/learningObject/getRaw?hruid=${node.learningobject_hruid}&version=${node.version}&language=${language}`;
|
||||||
return filterLearningObjectMetadata(metadata, htmlUrl);
|
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) {
|
} catch (error) {
|
||||||
console.error('Error fetching learning objects:', error);
|
console.error('Error fetching learning objects:', error);
|
||||||
return [];
|
return [];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue