feat(backend): Added support for customized learning paths to the database learning path provider.

This commit is contained in:
Gerald Schmittinger 2025-03-11 06:13:29 +01:00
parent 466b9b8d17
commit a69e2625af
7 changed files with 84 additions and 86 deletions

View file

@ -0,0 +1,42 @@
import {LearningPathNode} from "../../entities/content/learning-path-node.entity";
import {Student} from "../../entities/users/student.entity";
import {Group} from "../../entities/assignments/group.entity";
import {Submission} from "../../entities/assignments/submission.entity";
import {getSubmissionRepository} from "../../data/repositories";
import {LearningObjectIdentifier} from "../../entities/content/learning-object-identifier";
import {LearningPathTransition} from "../../entities/content/learning-path-transition.entity";
import {JSONPath} from "jsonpath-plus";
export type PersonalizationTarget = { type: 'student'; student: Student } | { type: 'group'; group: Group };
/**
* Returns the last submission for the learning object associated with the given node and for the student or group
*/
export async function getLastSubmissionForCustomizationTarget(node: LearningPathNode, pathFor: PersonalizationTarget): Promise<Submission | null> {
const submissionRepo = getSubmissionRepository();
const learningObjectId: LearningObjectIdentifier = {
hruid: node.learningObjectHruid,
language: node.language,
version: node.version,
};
if (pathFor.type === 'group') {
return await submissionRepo.findMostRecentSubmissionForGroup(learningObjectId, pathFor.group);
} else {
return await submissionRepo.findMostRecentSubmissionForStudent(learningObjectId, pathFor.student);
}
}
/**
* Checks whether the condition of the given transaction is fulfilled by the given submission.
* @param transition
* @param submitted
*/
export function isTransitionPossible(transition: LearningPathTransition, submitted: object | null): boolean {
if (transition.condition === 'true' || !transition.condition) {
return true; // If the transition is unconditional, we can go on.
}
if (submitted === null) {
return false; // If the transition is not unconditional and there was no submission, the transition is not possible.
}
return JSONPath({ path: transition.condition, json: submitted }).length === 0;
}