Merge remote-tracking branch 'origin/dev' into feat/endpoints-beschermen-met-authenticatie-#105

# Conflicts:
#	backend/src/services/questions.ts
This commit is contained in:
Gabriellvl 2025-05-01 22:40:24 +02:00
commit e799705a09
32 changed files with 579 additions and 8874 deletions

View file

@ -31,7 +31,7 @@ export function getQuestionId(learningObjectIdentifier: LearningObjectIdentifier
export async function getAllQuestionsHandler(req: Request, res: Response): Promise<void> {
const hruid = req.params.hruid;
const version = req.params.version;
const language = req.query.lang as string;
const language = (req.query.lang ? req.query.lang : FALLBACK_LANG) as string;
const full = req.query.full === 'true';
requireFields({ hruid });

View file

@ -73,7 +73,7 @@ export async function getStudentAssignmentsHandler(req: Request, res: Response):
const username = req.params.username;
requireFields({ username });
const assignments = getStudentAssignments(username, full);
const assignments = await getStudentAssignments(username, full);
res.json({ assignments });
}

View file

@ -12,7 +12,11 @@ export class AnswerRepository extends DwengoEntityRepository<Answer> {
content: answer.content,
timestamp: new Date(),
});
return this.insert(answerEntity);
await this.insert(answerEntity);
answerEntity.toQuestion = answer.toQuestion;
answerEntity.author = answer.author;
answerEntity.content = answer.content;
return answerEntity;
}
public async findAllAnswersToQuestion(question: Question): Promise<Answer[]> {
return this.findAll({

View file

@ -24,7 +24,7 @@ export class QuestionRepository extends DwengoEntityRepository<Question> {
questionEntity.author = question.author;
questionEntity.inGroup = question.inGroup;
questionEntity.content = question.content;
return this.insert(questionEntity);
return await this.insert(questionEntity);
}
public async findAllQuestionsAboutLearningObject(loId: LearningObjectIdentifier): Promise<Question[]> {
return this.findAll({

View file

@ -12,6 +12,7 @@ import { AssignmentDTO } from '@dwengo-1/common/interfaces/assignment';
import { fetchStudent } from './students.js';
import { NotFoundException } from '../exceptions/not-found-exception.js';
import { FALLBACK_VERSION_NUM } from '../config.js';
import { fetchAssignment } from './assignments.js';
import { ConflictException } from '../exceptions/conflict-exception.js';
export async function getQuestionsAboutLearningObjectInAssignment(
@ -87,22 +88,30 @@ export async function createQuestion(loId: LearningObjectIdentifier, questionDat
const author = await fetchStudent(questionData.author!);
const content = questionData.content;
const clazz = await getClassRepository().findById((questionData.inGroup.assignment as AssignmentDTO).within);
const assignment = mapToAssignment(questionData.inGroup.assignment as AssignmentDTO, clazz!);
const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionData.inGroup.groupNumber);
let assignment;
if (!group) {
if (typeof questionData.inGroup.assignment === 'number' && typeof questionData.inGroup.class === 'string') {
assignment = await fetchAssignment(questionData.inGroup.class, questionData.inGroup.assignment);
} else {
// TODO check if necessary and no conflicts to delete this if
const clazz = await getClassRepository().findById((questionData.inGroup.assignment as AssignmentDTO).within);
assignment = mapToAssignment(questionData.inGroup.assignment as AssignmentDTO, clazz!);
}
const inGroup = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, questionData.inGroup.groupNumber);
if (!inGroup) {
throw new NotFoundException('Group with id and assignment not found');
}
if (!group.members.contains(author)) {
if (!inGroup.members.contains(author)) {
throw new ConflictException('Author is not part of this group');
}
const question = await questionRepository.createQuestion({
loId,
author,
inGroup: group,
inGroup: inGroup!,
content,
});