fix: snackbar message bij groep aanpassen
This commit is contained in:
parent
3dae015e3e
commit
1c118a42f3
2 changed files with 44 additions and 27 deletions
|
@ -103,6 +103,7 @@ function hasDuplicates(arr: string[]): boolean {
|
|||
export async function putAssignment(classid: string, id: number, assignmentData: Partial<AssignmentDTO>): Promise<AssignmentDTO> {
|
||||
const assignment = await fetchAssignment(classid, id);
|
||||
|
||||
|
||||
if (assignmentData.groups) {
|
||||
if (hasDuplicates(assignmentData.groups.flat() as string[])) {
|
||||
throw new BadRequestException('Student can only be in one group');
|
||||
|
@ -110,17 +111,26 @@ export async function putAssignment(classid: string, id: number, assignmentData:
|
|||
|
||||
const studentLists = await Promise.all((assignmentData.groups as string[][]).map(async (group) => await fetchStudents(group)));
|
||||
|
||||
const groupRepository = getGroupRepository();
|
||||
await groupRepository.deleteAllByAssignment(assignment);
|
||||
await Promise.all(
|
||||
studentLists.map(async (students) => {
|
||||
const newGroup = groupRepository.create({
|
||||
assignment: assignment,
|
||||
members: students,
|
||||
});
|
||||
await groupRepository.save(newGroup);
|
||||
})
|
||||
);
|
||||
try {
|
||||
const groupRepository = getGroupRepository();
|
||||
await groupRepository.deleteAllByAssignment(assignment);
|
||||
|
||||
await Promise.all(
|
||||
studentLists.map(async (students) => {
|
||||
const newGroup = groupRepository.create({
|
||||
assignment: assignment,
|
||||
members: students,
|
||||
});
|
||||
await groupRepository.save(newGroup);
|
||||
})
|
||||
);
|
||||
} catch(e: unknown) {
|
||||
if (e instanceof ForeignKeyConstraintViolationException || e instanceof PostgreSqlExceptionConverter) {
|
||||
throw new ConflictException('Cannot update assigment with questions or submissions');
|
||||
} else {
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
delete assignmentData.groups;
|
||||
}
|
||||
|
|
|
@ -130,13 +130,28 @@
|
|||
return `/learningPath/${lp.hruid}/${lp.language}/${lp.startNode.learningobjectHruid}?forGroup=${groupNo}&assignmentNo=${props.assignmentId}&classId=${props.classId}`;
|
||||
}
|
||||
|
||||
const { mutate, data, isSuccess } = useUpdateAssignmentMutation();
|
||||
const updateAssignmentMutate = useUpdateAssignmentMutation();
|
||||
|
||||
watch([isSuccess, data], async ([success, newData]) => {
|
||||
if (success && newData?.assignment) {
|
||||
await assignmentQueryResult.refetch();
|
||||
}
|
||||
});
|
||||
function updateAssignment(assignmentDTO) {
|
||||
updateAssignmentMutate.mutate(
|
||||
{
|
||||
cid: assignmentQueryResult.data.value?.assignment.within,
|
||||
an: assignmentQueryResult.data.value?.assignment.id,
|
||||
data: assignmentDTO,
|
||||
},
|
||||
{
|
||||
onSuccess: async (newData) => {
|
||||
if (newData?.assignment) {
|
||||
await assignmentQueryResult.refetch();
|
||||
}
|
||||
},
|
||||
onError: (err: any) => {
|
||||
const message = err.response?.data?.error || err.message || t("unknownError");
|
||||
showSnackbar(t("failed") + ": " + message, "error");
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
async function saveChanges(): Promise<void> {
|
||||
const { valid } = await form.value.validate();
|
||||
|
@ -149,22 +164,14 @@
|
|||
deadline: deadline.value ?? null,
|
||||
};
|
||||
|
||||
mutate({
|
||||
cid: assignmentQueryResult.data.value?.assignment.within,
|
||||
an: assignmentQueryResult.data.value?.assignment.id,
|
||||
data: assignmentDTO,
|
||||
});
|
||||
updateAssignment(assignmentDTO);
|
||||
}
|
||||
|
||||
async function handleGroupsUpdated(updatedGroups: string[][]): Promise<void> {
|
||||
const assignmentDTO: AssignmentDTO = {
|
||||
groups: updatedGroups,
|
||||
};
|
||||
mutate({
|
||||
cid: assignmentQueryResult.data.value?.assignment.within,
|
||||
an: assignmentQueryResult.data.value?.assignment.id,
|
||||
data: assignmentDTO,
|
||||
});
|
||||
updateAssignment(assignmentDTO);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue