fix: opslitsing learningpath controller met extra service + api helper

This commit is contained in:
Gabriellvl 2025-03-01 17:52:55 +01:00
parent 91eb374b7e
commit f7d6cbce65
4 changed files with 98 additions and 116 deletions

View file

@ -64,14 +64,15 @@ export async function getLearningObjectsFromPath(
return await Promise.all(
learningPathData.nodes.map(async (node: LearningObjectNode) => {
const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${node.learningobject_hruid}&version=${node.version}&language=${language}`;
const metadataResponse = await axios.get(metadataUrl);
const metadata = await fetchWithLogging(
metadataUrl,
`Metadata for Learning Object HRUID "${node.learningobject_hruid}" (version ${node.version}, language ${language})`
);
if (!metadata) return null;
const htmlUrl = `${DWENGO_API_BASE}/learningObject/getRaw?hruid=${node.learningobject_hruid}&version=${node.version}&language=${language}`;
return filterLearningObjectMetadata(
metadataResponse.data,
htmlUrl
);
return filterLearningObjectMetadata(metadata, htmlUrl);
})
);
} catch (error) {

View file

@ -0,0 +1,45 @@
import { fetchWithLogging } from "../util/apiHelper.js";
import { DWENGO_API_BASE } from "../config/config.js";
interface LearningPathResponse {
success: boolean;
source: string;
data: any[] | null;
message?: string;
}
export async function fetchLearningPaths(
hruids: string[],
language: string,
source: string
): Promise<LearningPathResponse> {
if (hruids.length === 0) {
return {
success: false,
source,
data: null,
message: `No HRUIDs provided for ${source}.`,
};
}
const apiUrl = `${DWENGO_API_BASE}/learningPath/getPathsFromIdList`;
const params = { pathIdList: JSON.stringify({ hruids }), language };
const learningPaths = await fetchWithLogging<any>(apiUrl, `Learning paths for ${source}`, params);
if (!learningPaths || learningPaths.length === 0) {
console.error(`⚠️ WARNING: No learning paths found for ${source}.`);
return {
success: false,
source,
data: [],
message: `No learning paths found for ${source}.`,
};
}
return {
success: true,
source,
data: learningPaths,
};
}