feat: gebruik interface voor learning objects
This commit is contained in:
parent
13f563bb56
commit
008e2e1c2c
2 changed files with 77 additions and 43 deletions
|
@ -1,7 +1,7 @@
|
||||||
export interface LearningPathResponse {
|
export interface LearningPathResponse {
|
||||||
success: boolean;
|
success: boolean;
|
||||||
source: string;
|
source: string;
|
||||||
data: any[] | null;
|
data: LearningPath[] | null;
|
||||||
message?: string;
|
message?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,8 +22,7 @@ export interface LearningPath {
|
||||||
__order: number;
|
__order: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LearningObjectNode {
|
||||||
interface LearningObjectNode {
|
|
||||||
_id: string;
|
_id: string;
|
||||||
learningobject_hruid: string;
|
learningobject_hruid: string;
|
||||||
version: number;
|
version: number;
|
||||||
|
@ -34,7 +33,7 @@ interface LearningObjectNode {
|
||||||
updatedAt: string;
|
updatedAt: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Transition {
|
export interface Transition {
|
||||||
default: boolean;
|
default: boolean;
|
||||||
_id: string;
|
_id: string;
|
||||||
next: {
|
next: {
|
||||||
|
@ -44,3 +43,56 @@ interface Transition {
|
||||||
language: string;
|
language: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LearningObjectMetadata {
|
||||||
|
_id: string;
|
||||||
|
uuid: string;
|
||||||
|
hruid: string;
|
||||||
|
version: number;
|
||||||
|
language: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
difficulty: number;
|
||||||
|
estimated_time: number;
|
||||||
|
available: boolean;
|
||||||
|
teacher_exclusive: boolean;
|
||||||
|
educational_goals: EducationalGoal[];
|
||||||
|
keywords: string[];
|
||||||
|
target_ages: number[];
|
||||||
|
content_type: string; // Markdown, image, etc.
|
||||||
|
content_location?: string;
|
||||||
|
skos_concepts?: string[];
|
||||||
|
return_value?: ReturnValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface EducationalGoal {
|
||||||
|
source: string;
|
||||||
|
id: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ReturnValue {
|
||||||
|
callback_url: string;
|
||||||
|
callback_schema: Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface FilteredLearningObject {
|
||||||
|
key: string;
|
||||||
|
_id: string;
|
||||||
|
uuid: string;
|
||||||
|
version: number;
|
||||||
|
title: string;
|
||||||
|
htmlUrl: string;
|
||||||
|
language: string;
|
||||||
|
difficulty: number;
|
||||||
|
estimatedTime: number;
|
||||||
|
available: boolean;
|
||||||
|
teacherExclusive: boolean;
|
||||||
|
educationalGoals: EducationalGoal[];
|
||||||
|
keywords: string[];
|
||||||
|
description: string;
|
||||||
|
targetAges: number[];
|
||||||
|
contentType: string;
|
||||||
|
contentLocation?: string;
|
||||||
|
skosConcepts?: string[];
|
||||||
|
returnValue?: ReturnValue;
|
||||||
|
}
|
||||||
|
|
|
@ -1,70 +1,51 @@
|
||||||
import axios from 'axios';
|
|
||||||
import { DWENGO_API_BASE } from '../config/config.js';
|
import { DWENGO_API_BASE } from '../config/config.js';
|
||||||
import { fetchWithLogging } from "../util/apiHelper.js";
|
import { fetchWithLogging } from "../util/apiHelper.js";
|
||||||
|
import {FilteredLearningObject, LearningObjectMetadata, LearningObjectNode} from "../interfaces/learningPath.js";
|
||||||
|
import {fetchLearningPaths} from "./learningPaths.js";
|
||||||
|
|
||||||
interface LearningObjectNode {
|
|
||||||
_id: string;
|
|
||||||
learningobject_hruid: string;
|
|
||||||
version: number;
|
|
||||||
language: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
function filterLearningObjectMetadata(data: any, htmlUrl: string) {
|
function filterLearningObjectMetadata(data: LearningObjectMetadata, htmlUrl: string) : FilteredLearningObject {
|
||||||
return {
|
return {
|
||||||
key: data.hruid,
|
key: data.hruid, // Hruid learningObject (not path)
|
||||||
// Hruid learningObject (not path)
|
|
||||||
_id: data._id,
|
_id: data._id,
|
||||||
uuid: data.uuid,
|
uuid: data.uuid,
|
||||||
version: data.version,
|
version: data.version,
|
||||||
|
|
||||||
title: data.title,
|
title: data.title,
|
||||||
htmlUrl,
|
htmlUrl, // Url to fetch html content
|
||||||
// Url to fetch html content
|
|
||||||
language: data.language,
|
language: data.language,
|
||||||
difficulty: data.difficulty,
|
difficulty: data.difficulty,
|
||||||
estimatedTime: data.estimated_time,
|
estimatedTime: data.estimated_time,
|
||||||
available: data.available,
|
available: data.available,
|
||||||
teacherExclusive: data.teacher_exclusive,
|
teacherExclusive: data.teacher_exclusive,
|
||||||
educationalGoals: data.educational_goals,
|
educationalGoals: data.educational_goals, // List with learningObjects
|
||||||
// List with learningObjects
|
keywords: data.keywords, // For search
|
||||||
keywords: data.keywords,
|
description: data.description, // For search (not an actual description)
|
||||||
// For search
|
|
||||||
description: data.description,
|
|
||||||
// For search (not an actual description)
|
|
||||||
targetAges: data.target_ages,
|
targetAges: data.target_ages,
|
||||||
contentType: data.content_type,
|
contentType: data.content_type, // Markdown, image, audio, etc.
|
||||||
// Text/plain, text/md, image/image-block,
|
contentLocation: data.content_location, // If content type extern
|
||||||
// Image/image/, audio/mpeg or extern
|
skosConcepts: data.skos_concepts,
|
||||||
contentLocation: data.content_location,
|
returnValue: data.return_value, // Callback response information
|
||||||
// If content type extern
|
|
||||||
|
|
||||||
// Skos concepts needed ??
|
|
||||||
// Return value needed ??
|
|
||||||
// Callback_url to send response
|
|
||||||
// Callback_scheme
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getLearningObjectsFromPath(
|
export async function getLearningObjectsFromPath(
|
||||||
hruid: string,
|
hruid: string,
|
||||||
language: string
|
language: string
|
||||||
) {
|
): Promise<FilteredLearningObject[]> {
|
||||||
try {
|
try {
|
||||||
const learningPathUrl = `${DWENGO_API_BASE}/learningPath/${hruid}/${language}`;
|
const learningPathResponse = await fetchLearningPaths([hruid], language, `Learning path for HRUID "${hruid}"`);
|
||||||
const learningPathData = await fetchWithLogging<{ nodes: LearningObjectNode[] }>(
|
|
||||||
learningPathUrl,
|
|
||||||
`Learning path for HRUID "${hruid}" in language "${language}"`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!learningPathData || !learningPathData.nodes || learningPathData.nodes.length === 0) {
|
if (!learningPathResponse.success || !learningPathResponse.data || learningPathResponse.data.length === 0) {
|
||||||
console.error(`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`);
|
console.error(`⚠️ WARNING: Learning path "${hruid}" exists but contains no learning objects.`);
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const nodes: LearningObjectNode[] = learningPathResponse.data[0].nodes;
|
||||||
|
|
||||||
return await Promise.all(
|
return await Promise.all(
|
||||||
learningPathData.nodes.map(async (node: LearningObjectNode) => {
|
nodes.map(async (node) => {
|
||||||
const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${node.learningobject_hruid}&version=${node.version}&language=${language}`;
|
const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${node.learningobject_hruid}&version=${node.version}&language=${language}`;
|
||||||
const metadata = await fetchWithLogging(
|
const metadata = await fetchWithLogging<LearningObjectMetadata>(
|
||||||
metadataUrl,
|
metadataUrl,
|
||||||
`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})`
|
||||||
);
|
);
|
||||||
|
@ -74,8 +55,9 @@ export async function getLearningObjectsFromPath(
|
||||||
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));
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching learning objects:', error);
|
console.error('Error fetching learning objects:', error);
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue