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,12 +2,64 @@ import { LearningPathNode } from '../../entities/content/learning-path-node.enti
|
|||
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 {
|
||||
getClassRepository,
|
||||
getGroupRepository,
|
||||
getStudentRepository,
|
||||
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 };
|
||||
|
||||
/**
|
||||
* Shortcut function to easily create a PersonalizationTarget object for a student by his/her username.
|
||||
* @param username Username of the student we want to generate a personalized learning path for.
|
||||
* If there is no student with this username, return undefined.
|
||||
*/
|
||||
export async function personalizedForStudent(username: string): Promise<PersonalizationTarget | undefined> {
|
||||
const student = await getStudentRepository().findByUsername(username);
|
||||
if (student) {
|
||||
return {
|
||||
type: "student",
|
||||
student: student
|
||||
}
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Shortcut function to easily create a PersonalizationTarget object for a group by class name, assignment number and
|
||||
* group number.
|
||||
* @param classId Id of the class in which this group was created
|
||||
* @param assignmentNumber Number of the assignment for which this group was created
|
||||
* @param groupNumber Number of the group for which we want to personalize the learning path.
|
||||
*/
|
||||
export async function personalizedForGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<PersonalizationTarget | undefined> {
|
||||
const clazz = await getClassRepository().findById(classId);
|
||||
if (!clazz) {
|
||||
return undefined;
|
||||
}
|
||||
const group = await getGroupRepository().findOne({
|
||||
assignment: {
|
||||
within: clazz,
|
||||
id: assignmentNumber,
|
||||
},
|
||||
groupNumber: groupNumber
|
||||
})
|
||||
if (group) {
|
||||
return {
|
||||
type: "group",
|
||||
group: group
|
||||
}
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the last submission for the learning object associated with the given node and for the student or group
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue