fix: lint + format
This commit is contained in:
parent
ac778981e2
commit
acfffda82d
8 changed files with 162 additions and 118 deletions
|
@ -1,5 +1,5 @@
|
|||
import axios from "axios";
|
||||
import { DWENGO_API_BASE } from "../config/config.js";
|
||||
import axios from 'axios';
|
||||
import { DWENGO_API_BASE } from '../config/config.js';
|
||||
|
||||
interface LearningObjectNode {
|
||||
_id: string;
|
||||
|
@ -8,15 +8,47 @@ interface LearningObjectNode {
|
|||
language: string;
|
||||
}
|
||||
|
||||
function filterLearningObjectMetadata(data: any, htmlUrl: string) {
|
||||
return {
|
||||
key: data.hruid,
|
||||
// Hruid learningObject (not path)
|
||||
_id: data._id,
|
||||
uuid: data.uuid,
|
||||
version: data.version,
|
||||
|
||||
export async function getLearningObjectsFromPath(hruid: string, language: string) {
|
||||
title: data.title,
|
||||
html_url: htmlUrl,
|
||||
// Html content object
|
||||
language: data.language,
|
||||
difficulty: data.difficulty,
|
||||
estimated_time: data.estimated_time,
|
||||
available: data.available,
|
||||
teacher_exclusive: data.teacher_exclusive,
|
||||
educational_goals: data.educational_goals,
|
||||
// List with learningObjects
|
||||
keywords: data.keywords,
|
||||
// For search
|
||||
description: data.description,
|
||||
// For search (not an actual description)
|
||||
target_ages: data.target_ages,
|
||||
|
||||
// Skos concepts needed ??
|
||||
// Content type needed ??
|
||||
// Content location ??
|
||||
};
|
||||
}
|
||||
|
||||
export async function getLearningObjectsFromPath(
|
||||
hruid: string,
|
||||
language: string
|
||||
) {
|
||||
try {
|
||||
const learningPathUrl = `${DWENGO_API_BASE}/learningPath/${hruid}/${language}`;
|
||||
const learningPathResponse = await axios.get(learningPathUrl);
|
||||
const nodes = learningPathResponse.data.nodes;
|
||||
|
||||
if (!nodes || nodes.length === 0) {
|
||||
throw new Error("No learning objects found in this learning path.");
|
||||
throw new Error('No learning objects found in this learning path.');
|
||||
}
|
||||
|
||||
return await Promise.all(
|
||||
|
@ -24,44 +56,16 @@ export async function getLearningObjectsFromPath(hruid: string, language: string
|
|||
const metadataUrl = `${DWENGO_API_BASE}/learningObject/getMetadata?hruid=${node.learningobject_hruid}&version=${node.version}&language=${language}`;
|
||||
const metadataResponse = await axios.get(metadataUrl);
|
||||
|
||||
const html_url = `${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(metadataResponse.data, html_url);
|
||||
return filterLearningObjectMetadata(
|
||||
metadataResponse.data,
|
||||
htmlUrl
|
||||
);
|
||||
})
|
||||
);
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error fetching learning objects:", error);
|
||||
throw new Error("Failed to fetch learning objects.");
|
||||
console.error('Error fetching learning objects:', error);
|
||||
throw new Error('Failed to fetch learning objects.');
|
||||
}
|
||||
}
|
||||
|
||||
function filterLearningObjectMetadata(data: any, html_url: String) {
|
||||
return {
|
||||
key: data.hruid,
|
||||
// hruid learningObject (not path)
|
||||
_id: data._id,
|
||||
uuid: data.uuid,
|
||||
version: data.version,
|
||||
|
||||
title: data.title,
|
||||
html_url,
|
||||
// html content object
|
||||
language: data.language,
|
||||
difficulty: data.difficulty,
|
||||
estimated_time: data.estimated_time,
|
||||
available: data.available,
|
||||
teacher_exclusive: data.teacher_exclusive,
|
||||
educational_goals: data.educational_goals,
|
||||
// list with learningObjects
|
||||
keywords: data.keywords,
|
||||
// for search
|
||||
description: data.description,
|
||||
// for search (not an actual description)
|
||||
target_ages: data.target_ages,
|
||||
|
||||
// skos concepts needed ??
|
||||
// content type needed ??
|
||||
// content location ??
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue