feat(backend): Vragen kunnen nu per leerobject, assignment en optioneel groepslid opgevraagd worden

This commit is contained in:
Gerald Schmittinger 2025-04-08 00:26:59 +02:00
parent 64fd66a1de
commit c863dc627f
7 changed files with 181 additions and 22 deletions

View file

@ -6,6 +6,9 @@ export class AssignmentRepository extends DwengoEntityRepository<Assignment> {
public async findByClassAndId(within: Class, id: number): Promise<Assignment | null> {
return this.findOne({ within: within, id: id });
}
public async findByClassIdAndAssignmentId(withinClass: string, id: number): Promise<Assignment | null> {
return this.findOne({ within: { classId: withinClass }, id: id });
}
public async findAllByResponsibleTeacher(teacherUsername: string): Promise<Assignment[]> {
return this.findAll({
where: {

View file

@ -4,6 +4,7 @@ import { LearningObjectIdentifier } from '../../entities/content/learning-object
import { Student } from '../../entities/users/student.entity.js';
import { LearningObject } from '../../entities/content/learning-object.entity.js';
import {Group} from "../../entities/assignments/group.entity";
import {Assignment} from "../../entities/assignments/assignment.entity";
export class QuestionRepository extends DwengoEntityRepository<Question> {
public async createQuestion(question: { loId: LearningObjectIdentifier; author: Student; inGroup: Group, content: string }): Promise<Question> {
@ -64,4 +65,34 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
orderBy: { timestamp: 'DESC' }, // New to old
});
}
/**
* Looks up all questions for the given learning object which were asked as part of the given assignment.
* When forStudentUsername is set, only the questions within the given user's group are shown.
*/
public async findAllQuestionsAboutLearningObjectInAssignment(
loId: LearningObjectIdentifier,
assignment: Assignment,
forStudentUsername?: string
): Promise<Question[]> {
let inGroup = forStudentUsername ? {
assignment,
members: {
$some: {
username: forStudentUsername
}
}
} : {
assignment
};
return this.findAll({
where: {
learningObjectHruid: loId.hruid,
learningObjectLanguage: loId.language,
learningObjectVersion: loId.version,
inGroup
}
});
}
}