feat(backend): Gepersonaliseerde leerpaden via API
Mogelijkheid toegevoegd om via de API optioneel een gepersonaliseerde variant van een leerpad voor een student of groep aan te vragen.
This commit is contained in:
parent
31f994167d
commit
3f04d2fd4d
2 changed files with 77 additions and 4 deletions
|
@ -2,7 +2,12 @@ import { Request, Response } from 'express';
|
|||
import { themes } from '../data/themes.js';
|
||||
import { FALLBACK_LANG } from '../config.js';
|
||||
import learningPathService from '../services/learning-paths/learning-path-service';
|
||||
import { NotFoundException } from '../exceptions';
|
||||
import {BadRequestException, NotFoundException} from '../exceptions';
|
||||
import {Language} from "../entities/content/language";
|
||||
import {
|
||||
PersonalizationTarget, personalizedForGroup,
|
||||
personalizedForStudent
|
||||
} from "../services/learning-paths/learning-path-personalization-util";
|
||||
|
||||
/**
|
||||
* Fetch learning paths based on query parameters.
|
||||
|
@ -13,6 +18,22 @@ export async function getLearningPaths(req: Request, res: Response): Promise<voi
|
|||
const searchQuery = req.query.search as string;
|
||||
const language = (req.query.language as string) || FALLBACK_LANG;
|
||||
|
||||
const forStudent = req.query.forStudent as string;
|
||||
const forGroupNo = req.query.forGroup as string;
|
||||
const assignmentNo = req.query.assignmentNo as string;
|
||||
const classId = req.query.classId as string;
|
||||
|
||||
let personalizationTarget: PersonalizationTarget | undefined;
|
||||
|
||||
if (forStudent) {
|
||||
personalizationTarget = await personalizedForStudent(forStudent)
|
||||
} else if (forGroupNo) {
|
||||
if (!assignmentNo || !classId) {
|
||||
throw new BadRequestException("If forGroupNo is specified, assignmentNo and classId must also be specified.");
|
||||
}
|
||||
personalizationTarget = await personalizedForGroup(classId, parseInt(assignmentNo), parseInt(forGroupNo));
|
||||
}
|
||||
|
||||
let hruidList;
|
||||
|
||||
if (hruids) {
|
||||
|
@ -25,13 +46,13 @@ export async function getLearningPaths(req: Request, res: Response): Promise<voi
|
|||
throw new NotFoundException(`Theme "${themeKey}" not found.`);
|
||||
}
|
||||
} else if (searchQuery) {
|
||||
const searchResults = await learningPathService.searchLearningPaths(searchQuery, language);
|
||||
const searchResults = await learningPathService.searchLearningPaths(searchQuery, language as Language, personalizationTarget);
|
||||
res.json(searchResults);
|
||||
return;
|
||||
} else {
|
||||
hruidList = themes.flatMap((theme) => theme.hruids);
|
||||
}
|
||||
|
||||
const learningPaths = await learningPathService.fetchLearningPaths(hruidList, language, `HRUIDs: ${hruidList.join(', ')}`);
|
||||
const learningPaths = await learningPathService.fetchLearningPaths(hruidList, language as Language, `HRUIDs: ${hruidList.join(', ')}`, personalizationTarget);
|
||||
res.json(learningPaths.data);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue