Merge remote-tracking branch 'origin/dev' into feature/own-learning-objects
# Conflicts: # backend/package.json # backend/src/config.ts # backend/src/controllers/learningObjects.ts # backend/src/controllers/learningPaths.ts # backend/src/data/content/attachment-repository.ts # backend/src/data/content/learning-object-repository.ts # backend/src/data/content/learning-path-repository.ts # backend/src/data/repositories.ts # backend/src/entities/content/learning-path.entity.ts # backend/src/exceptions.ts # backend/src/routes/learning-objects.ts # backend/src/services/learningObjects.ts # backend/src/services/learningPaths.ts # backend/src/util/apiHelper.ts # backend/src/util/envvars.ts # package-lock.json
This commit is contained in:
commit
cd0a3a8a7b
119 changed files with 8837 additions and 1697 deletions
45
backend/src/controllers/learningPaths.ts
Normal file
45
backend/src/controllers/learningPaths.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
|
||||
import { Request, Response } from 'express';
|
||||
import { themes } from '../data/themes.js';
|
||||
import { FALLBACK_LANG } from '../config.js';
|
||||
import { fetchLearningPaths, searchLearningPaths } from '../services/learningPaths.js';
|
||||
import { getLogger } from '../logging/initalize.js';
|
||||
/**
|
||||
* Fetch learning paths based on query parameters.
|
||||
*/
|
||||
export async function getLearningPaths(req: Request, res: Response): Promise<void> {
|
||||
try {
|
||||
const hruids = req.query.hruid;
|
||||
const themeKey = req.query.theme as string;
|
||||
const searchQuery = req.query.search as string;
|
||||
const language = (req.query.language as string) || FALLBACK_LANG;
|
||||
|
||||
let hruidList;
|
||||
|
||||
if (hruids) {
|
||||
hruidList = Array.isArray(hruids) ? hruids.map(String) : [String(hruids)];
|
||||
} else if (themeKey) {
|
||||
const theme = themes.find((t) => t.title === themeKey);
|
||||
if (theme) {
|
||||
hruidList = theme.hruids;
|
||||
} else {
|
||||
res.status(404).json({
|
||||
error: `Theme "${themeKey}" not found.`,
|
||||
});
|
||||
return;
|
||||
}
|
||||
} else if (searchQuery) {
|
||||
const searchResults = await searchLearningPaths(searchQuery, language);
|
||||
res.json(searchResults);
|
||||
return;
|
||||
} else {
|
||||
hruidList = themes.flatMap((theme) => theme.hruids);
|
||||
}
|
||||
|
||||
const learningPaths = await fetchLearningPaths(hruidList, language, `HRUIDs: ${hruidList.join(', ')}`);
|
||||
res.json(learningPaths.data);
|
||||
} catch (error) {
|
||||
getLogger().error('❌ Unexpected error fetching learning paths:', error);
|
||||
res.status(500).json({ error: 'Internal server error' });
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue