fix: verbod op toevoegen van student aan groep wanneer die student niet in de klas zit
This commit is contained in:
parent
37c9e622e6
commit
f1e9e3a8d6
1 changed files with 8 additions and 0 deletions
|
@ -9,6 +9,8 @@ import { fetchAssignment } from './assignments.js';
|
||||||
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
import { NotFoundException } from '../exceptions/not-found-exception.js';
|
||||||
import { putObject } from './service-helper.js';
|
import { putObject } from './service-helper.js';
|
||||||
import { fetchStudents } from './students.js';
|
import { fetchStudents } from './students.js';
|
||||||
|
import { fetchClass } from './classes.js';
|
||||||
|
import { BadRequestException } from '../exceptions/bad-request-exception.js';
|
||||||
|
|
||||||
export async function fetchGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<Group> {
|
export async function fetchGroup(classId: string, assignmentNumber: number, groupNumber: number): Promise<Group> {
|
||||||
const assignment = await fetchAssignment(classId, assignmentNumber);
|
const assignment = await fetchAssignment(classId, assignmentNumber);
|
||||||
|
@ -60,9 +62,15 @@ export async function getExistingGroupFromGroupDTO(groupData: GroupDTO): Promise
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function createGroup(groupData: GroupDTO, classid: string, assignmentNumber: number): Promise<GroupDTO> {
|
export async function createGroup(groupData: GroupDTO, classid: string, assignmentNumber: number): Promise<GroupDTO> {
|
||||||
|
const cls = await fetchClass(classid);
|
||||||
|
|
||||||
const memberUsernames = (groupData.members as string[]) || [];
|
const memberUsernames = (groupData.members as string[]) || [];
|
||||||
const members = await fetchStudents(memberUsernames);
|
const members = await fetchStudents(memberUsernames);
|
||||||
|
|
||||||
|
if (!members.every(student => cls.students.contains(student))) {
|
||||||
|
throw new BadRequestException("It is not allowed to add a student to a group when the student is not part of the class");
|
||||||
|
}
|
||||||
|
|
||||||
const assignment = await fetchAssignment(classid, assignmentNumber);
|
const assignment = await fetchAssignment(classid, assignmentNumber);
|
||||||
|
|
||||||
const groupRepository = getGroupRepository();
|
const groupRepository = getGroupRepository();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue