Merge remote-tracking branch 'origin/dev' into feat/indieningen-kunnen-posten-en-bekijken-#194

# Conflicts:
#	backend/tests/setup-tests.ts
This commit is contained in:
Gerald Schmittinger 2025-04-16 16:31:18 +02:00
commit dd2cdf3fe9
46 changed files with 1670 additions and 123 deletions

View file

@ -111,6 +111,7 @@ async function convertNode(
updatedAt: node.updatedAt.toISOString(),
learningobject_hruid: node.learningObjectHruid,
version: learningObject.version,
done: personalizedFor ? lastSubmission !== null : undefined,
transitions,
};
}

View file

@ -1,4 +1,4 @@
import { getAssignmentRepository, getSubmissionRepository } from '../data/repositories.js';
import {getAssignmentRepository, getGroupRepository, getSubmissionRepository} from '../data/repositories.js';
import { LearningObjectIdentifier } from '../entities/content/learning-object-identifier.js';
import { NotFoundException } from '../exceptions/not-found-exception.js';
import { mapToSubmission, mapToSubmissionDTO } from '../interfaces/submission.js';
@ -69,3 +69,24 @@ export async function getSubmissionsForLearningObjectAndAssignment(
return submissions.map((s) => mapToSubmissionDTO(s));
}
export async function getSubmissionsForLearningObjectAndGroup(
learningObjectHruid: string,
language: Language,
version: number,
classId: string,
assignmentNo: number,
groupNumber: number
): Promise<SubmissionDTO[]> {
const loId = new LearningObjectIdentifier(learningObjectHruid, language, version);
const assignment = await getAssignmentRepository().findByClassIdAndAssignmentId(classId, assignmentNo);
if (!assignment) {
throw new NotFoundException("Assignment not found!");
}
const group = await getGroupRepository().findByAssignmentAndGroupNumber(assignment, groupNumber);
if (!group) {
throw new NotFoundException("Group not found!");
}
const submissions = await getSubmissionRepository().findAllSubmissionsForGroup(group);
return submissions.map((s) => mapToSubmissionDTO(s));
}

View file

@ -0,0 +1,87 @@
import { fetchTeacher } from './teachers';
import { getTeacherInvitationRepository } from '../data/repositories';
import { mapToInvitation, mapToTeacherInvitationDTO } from '../interfaces/teacher-invitation';
import { addClassTeacher, fetchClass } from './classes';
import { TeacherInvitationData, TeacherInvitationDTO } from '@dwengo-1/common/interfaces/teacher-invitation';
import { ConflictException } from '../exceptions/conflict-exception';
import { NotFoundException } from '../exceptions/not-found-exception';
import { TeacherInvitation } from '../entities/classes/teacher-invitation.entity';
import { ClassStatus } from '@dwengo-1/common/util/class-join-request';
export async function getAllInvitations(username: string, sent: boolean): Promise<TeacherInvitationDTO[]> {
const teacher = await fetchTeacher(username);
const teacherInvitationRepository = getTeacherInvitationRepository();
let invitations;
if (sent) {
invitations = await teacherInvitationRepository.findAllInvitationsBy(teacher);
} else {
invitations = await teacherInvitationRepository.findAllInvitationsFor(teacher);
}
return invitations.map(mapToTeacherInvitationDTO);
}
export async function createInvitation(data: TeacherInvitationData): Promise<TeacherInvitationDTO> {
const teacherInvitationRepository = getTeacherInvitationRepository();
const sender = await fetchTeacher(data.sender);
const receiver = await fetchTeacher(data.receiver);
const cls = await fetchClass(data.class);
if (!cls.teachers.contains(sender)) {
throw new ConflictException('The teacher sending the invite is not part of the class');
}
const newInvitation = mapToInvitation(sender, receiver, cls);
await teacherInvitationRepository.save(newInvitation, { preventOverwrite: true });
return mapToTeacherInvitationDTO(newInvitation);
}
async function fetchInvitation(usernameSender: string, usernameReceiver: string, classId: string): Promise<TeacherInvitation> {
const sender = await fetchTeacher(usernameSender);
const receiver = await fetchTeacher(usernameReceiver);
const cls = await fetchClass(classId);
const teacherInvitationRepository = getTeacherInvitationRepository();
const invite = await teacherInvitationRepository.findBy(cls, sender, receiver);
if (!invite) {
throw new NotFoundException('Teacher invite not found');
}
return invite;
}
export async function getInvitation(sender: string, receiver: string, classId: string): Promise<TeacherInvitationDTO> {
const invitation = await fetchInvitation(sender, receiver, classId);
return mapToTeacherInvitationDTO(invitation);
}
export async function updateInvitation(data: TeacherInvitationData): Promise<TeacherInvitationDTO> {
const invitation = await fetchInvitation(data.sender, data.receiver, data.class);
invitation.status = ClassStatus.Declined;
if (data.accepted) {
invitation.status = ClassStatus.Accepted;
await addClassTeacher(data.class, data.receiver);
}
const teacherInvitationRepository = getTeacherInvitationRepository();
await teacherInvitationRepository.save(invitation);
return mapToTeacherInvitationDTO(invitation);
}
export async function deleteInvitation(data: TeacherInvitationData): Promise<TeacherInvitationDTO> {
const invitation = await fetchInvitation(data.sender, data.receiver, data.class);
const sender = await fetchTeacher(data.sender);
const receiver = await fetchTeacher(data.receiver);
const cls = await fetchClass(data.class);
const teacherInvitationRepository = getTeacherInvitationRepository();
await teacherInvitationRepository.deleteBy(cls, sender, receiver);
return mapToTeacherInvitationDTO(invitation);
}

View file

@ -28,7 +28,7 @@ import { ClassDTO } from '@dwengo-1/common/interfaces/class';
import { StudentDTO } from '@dwengo-1/common/interfaces/student';
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request';
import { ClassJoinRequestStatus } from '@dwengo-1/common/util/class-join-request';
import { ClassStatus } from '@dwengo-1/common/util/class-join-request';
import { ConflictException } from '../exceptions/conflict-exception.js';
export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> {
@ -160,10 +160,10 @@ export async function updateClassJoinRequestStatus(studentUsername: string, clas
throw new NotFoundException('Join request not found');
}
request.status = ClassJoinRequestStatus.Declined;
request.status = ClassStatus.Declined;
if (accepted) {
request.status = ClassJoinRequestStatus.Accepted;
request.status = ClassStatus.Accepted;
await addClassStudent(classId, studentUsername);
}