fix: lint + format
This commit is contained in:
parent
ac778981e2
commit
acfffda82d
8 changed files with 162 additions and 118 deletions
|
@ -1,19 +1,24 @@
|
|||
import { Request, Response } from "express";
|
||||
import axios from "axios";
|
||||
import { themes } from "../data/themes.js";
|
||||
import { DWENGO_API_BASE } from "../config/config.js";
|
||||
import { Request, Response } from 'express';
|
||||
import axios from 'axios';
|
||||
import { themes } from '../data/themes.js';
|
||||
import { DWENGO_API_BASE } from '../config/config.js';
|
||||
|
||||
/**
|
||||
* Fetch learning paths for a given list of HRUIDs.
|
||||
* This function sends a request to the Dwengo API with the provided HRUIDs.
|
||||
*/
|
||||
export async function getLearningPathsFromIds(req: Request, res: Response): Promise<void> {
|
||||
export async function getLearningPathsFromIds(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const { hruids } = req.query;
|
||||
const language = (req.query.language as string) || "nl"; // Default to Dutch
|
||||
const language = (req.query.language as string) || 'nl'; // Default to Dutch
|
||||
|
||||
if (!hruids) {
|
||||
res.status(400).json({ error: "Missing required parameter: hruids" });
|
||||
res.status(400).json({
|
||||
error: 'Missing required parameter: hruids',
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -21,17 +26,20 @@ export async function getLearningPathsFromIds(req: Request, res: Response): Prom
|
|||
const hruidList = Array.isArray(hruids) ? hruids : [hruids];
|
||||
|
||||
// Request learning paths from Dwengo API
|
||||
const response = await axios.get(`${DWENGO_API_BASE}/learningPath/getPathsFromIdList`, {
|
||||
params: {
|
||||
pathIdList: JSON.stringify({ hruids: hruidList }),
|
||||
language
|
||||
const response = await axios.get(
|
||||
`${DWENGO_API_BASE}/learningPath/getPathsFromIdList`,
|
||||
{
|
||||
params: {
|
||||
pathIdList: JSON.stringify({ hruids: hruidList }),
|
||||
language,
|
||||
},
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
res.json(response.data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching learning paths:", error);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
console.error('Error fetching learning paths:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,16 +48,21 @@ export async function getLearningPathsFromIds(req: Request, res: Response): Prom
|
|||
* First retrieves the HRUIDs associated with the theme,
|
||||
* then fetches the corresponding learning paths from the Dwengo API.
|
||||
*/
|
||||
export async function getLearningPathsByTheme(req: Request, res: Response): Promise<void> {
|
||||
export async function getLearningPathsByTheme(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const themeKey = req.params.theme;
|
||||
const language = (req.query.language as string) || "nl"; // Default to Dutch
|
||||
const language = (req.query.language as string) || 'nl'; // Default to Dutch
|
||||
|
||||
// Find the theme by its title
|
||||
const theme = themes.find((t) => t.title === themeKey);
|
||||
const theme = themes.find((t) => {
|
||||
return t.title === themeKey;
|
||||
});
|
||||
|
||||
if (!theme) {
|
||||
res.status(404).json({ error: "Theme not found" });
|
||||
res.status(404).json({ error: 'Theme not found' });
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -57,69 +70,85 @@ export async function getLearningPathsByTheme(req: Request, res: Response): Prom
|
|||
const hruidList = theme.hruids;
|
||||
|
||||
// Request learning paths from Dwengo API using the extracted HRUIDs
|
||||
const response = await axios.get(`${DWENGO_API_BASE}/learningPath/getPathsFromIdList`, {
|
||||
params: {
|
||||
pathIdList: JSON.stringify({ hruids: hruidList }),
|
||||
language
|
||||
const response = await axios.get(
|
||||
`${DWENGO_API_BASE}/learningPath/getPathsFromIdList`,
|
||||
{
|
||||
params: {
|
||||
pathIdList: JSON.stringify({ hruids: hruidList }),
|
||||
language,
|
||||
},
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
res.json({
|
||||
theme: themeKey,
|
||||
hruids: hruidList,
|
||||
learningPaths: response.data
|
||||
learningPaths: response.data,
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error("Error fetching learning paths for theme:", error);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
console.error('Error fetching learning paths for theme:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
export async function searchLearningPaths(req: Request, res: Response): Promise<void> {
|
||||
export async function searchLearningPaths(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const query = req.query.query as string;
|
||||
const language = (req.query.language as string) || "nl";
|
||||
const language = (req.query.language as string) || 'nl';
|
||||
|
||||
if (!query) {
|
||||
res.status(400).json({ error: "Missing search query" });
|
||||
res.status(400).json({ error: 'Missing search query' });
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await axios.get(`${DWENGO_API_BASE}/learningPath/search`, {
|
||||
params: { all: query, language }
|
||||
});
|
||||
const response = await axios.get(
|
||||
`${DWENGO_API_BASE}/learningPath/search`,
|
||||
{
|
||||
params: { all: query, language },
|
||||
}
|
||||
);
|
||||
|
||||
res.json(response.data);
|
||||
} catch (error) {
|
||||
console.error("Error searching learning paths:", error);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
console.error('Error searching learning paths:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
||||
export async function getAllLearningPaths(req: Request, res: Response): Promise<void> {
|
||||
export async function getAllLearningPaths(
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> {
|
||||
try {
|
||||
const language = (req.query.language as string) || "nl"; // Default to Dutch
|
||||
const language = (req.query.language as string) || 'nl'; // Default to Dutch
|
||||
|
||||
// Collect all HRUIDs from all themes
|
||||
const allHruids: string[] = themes.flatMap(theme => theme.hruids);
|
||||
const allHruids: string[] = themes.flatMap((theme) => {
|
||||
return theme.hruids;
|
||||
});
|
||||
|
||||
if (allHruids.length === 0) {
|
||||
res.status(404).json({ error: "No HRUIDs found in themes" });
|
||||
res.status(404).json({ error: 'No HRUIDs found in themes' });
|
||||
return;
|
||||
}
|
||||
|
||||
// Call the Dwengo API with all HRUIDs combined
|
||||
const response = await axios.get(`${DWENGO_API_BASE}/learningPath/getPathsFromIdList`, {
|
||||
params: {
|
||||
pathIdList: JSON.stringify({ hruids: allHruids }),
|
||||
language
|
||||
const response = await axios.get(
|
||||
`${DWENGO_API_BASE}/learningPath/getPathsFromIdList`,
|
||||
{
|
||||
params: {
|
||||
pathIdList: JSON.stringify({ hruids: allHruids }),
|
||||
language,
|
||||
},
|
||||
}
|
||||
});
|
||||
);
|
||||
|
||||
res.json(response.data);
|
||||
} catch (error) {
|
||||
console.error("Error fetching all learning paths:", error);
|
||||
res.status(500).json({ error: "Internal server error" });
|
||||
console.error('Error fetching all learning paths:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue