fix: error message delete assignment knop met vragen of submissions
This commit is contained in:
parent
29f6bd9cad
commit
8cf2f16ff7
2 changed files with 33 additions and 2 deletions
|
@ -14,11 +14,14 @@ import { mapToSubmissionDTO, mapToSubmissionDTOId } from '../interfaces/submissi
|
|||
import { fetchClass } from './classes.js';
|
||||
import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question';
|
||||
import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission';
|
||||
import { EntityDTO } from '@mikro-orm/core';
|
||||
import {EntityDTO, ForeignKeyConstraintViolationException} from '@mikro-orm/core';
|
||||
import { putObject } from './service-helper.js';
|
||||
import { fetchStudents } from './students.js';
|
||||
import { ServerErrorException } from '../exceptions/server-error-exception.js';
|
||||
import { BadRequestException } from '../exceptions/bad-request-exception.js';
|
||||
import {getQuestionsAboutLearningObjectInAssignment} from "./questions";
|
||||
import {LearningObjectIdentifier} from "../entities/content/learning-object-identifier";
|
||||
import {ConflictException} from "../exceptions/conflict-exception";
|
||||
|
||||
export async function fetchAssignment(classid: string, assignmentNumber: number): Promise<Assignment> {
|
||||
const classRepository = getClassRepository();
|
||||
|
@ -133,7 +136,13 @@ export async function deleteAssignment(classid: string, id: number): Promise<Ass
|
|||
const cls = await fetchClass(classid);
|
||||
|
||||
const assignmentRepository = getAssignmentRepository();
|
||||
await assignmentRepository.deleteByClassAndId(cls, id);
|
||||
|
||||
try {
|
||||
await assignmentRepository.deleteByClassAndId(cls, id);
|
||||
} catch (e: ForeignKeyConstraintViolationException) {
|
||||
throw new ConflictException("Cannot delete assigment with questions or submissions")
|
||||
}
|
||||
|
||||
|
||||
return mapToAssignmentDTO(assignment);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue