feat: submissions van een assignment geimplementeerd

This commit is contained in:
Adriaan Jacquet 2025-03-12 15:23:33 +01:00
parent 7c453467df
commit fd693dc55f
5 changed files with 58 additions and 4 deletions

View file

@ -1,12 +1,15 @@
import {
getAssignmentRepository,
getClassRepository,
getGroupRepository,
getSubmissionRepository,
} from '../data/repositories.js';
import {
AssignmentDTO,
mapToAssignmentDTO,
mapToAssignmentDTOId,
} from '../interfaces/assignment.js';
import { mapToSubmissionDTO, SubmissionDTO } from '../interfaces/submission.js';
export async function getAllAssignments(
classid: string,
@ -50,3 +53,31 @@ export async function getAssignment(
return mapToAssignmentDTO(assignment);
}
export async function getAssignmentsSubmissions(
classid: string,
assignmentNumber: number,
): Promise<SubmissionDTO[]> {
const classRepository = getClassRepository();
const cls = await classRepository.findById(classid);
if (!cls) {
return [];
}
const assignmentRepository = getAssignmentRepository();
const assignment = await assignmentRepository.findByClassAndId(cls, assignmentNumber);
if (!assignment) {
return [];
}
const groupRepository = getGroupRepository();
const groups = await groupRepository.findAllGroupsForAssignment(assignment);
const submissionRepository = getSubmissionRepository();
const submissions =
(await Promise.all(groups.map(group => submissionRepository.findAllSubmissionsForGroup(group)))).flat();
return submissions.map(mapToSubmissionDTO);
}