feat: added route for learningObjects

This commit is contained in:
Gabriellvl 2025-02-28 17:04:52 +01:00
parent e8e1d94e5b
commit d401136d3a
7 changed files with 116 additions and 10 deletions

View file

@ -0,0 +1,20 @@
import { Request, Response } from "express";
import { getLearningObjectsFromPath } from "../services/learningObjects.js";
export async function getAllLearningObjects(req: Request, res: Response): Promise<void> {
try {
const { hruid } = req.params;
const language = req.query.language as string || "nl"; // Default to Dutch;
if (!language) {
res.status(400).json({ error: "Language query parameter is required." });
return;
}
const learningObjects = await getLearningObjectsFromPath(hruid, language);
res.json(learningObjects);
} catch (error) {
console.error("Error fetching learning objects:", error);
res.status(500).json({ error: "Internal server error" });
}
}

View file

@ -1,16 +1,7 @@
import { Request, Response } from "express";
import axios from "axios";
import { themes } from "../data/themes.js";
import dotenv from "dotenv";
// Load environment variables
dotenv.config();
// Get API base URL from environment variables
const DWENGO_API_BASE = process.env.DWENGO_API_BASE as string;
if (!DWENGO_API_BASE) {
throw new Error("DWENGO_API_BASE is not defined in the .env file");
}
import { DWENGO_API_BASE } from "../config/config.js";
/**
* Fetch learning paths for a given list of HRUIDs.