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); | ||||
| } | ||||
|  |  | |||
|  | @ -87,6 +87,18 @@ | |||
|         dialog.value = true; | ||||
|     } | ||||
| 
 | ||||
|     const snackbar = ref({ | ||||
|         visible: false, | ||||
|         message: "", | ||||
|         color: "success", | ||||
|     }); | ||||
| 
 | ||||
|     function showSnackbar(message: string, color: string): void { | ||||
|         snackbar.value.message = message; | ||||
|         snackbar.value.color = color; | ||||
|         snackbar.value.visible = true; | ||||
|     } | ||||
| 
 | ||||
|     const deleteAssignmentMutation = useDeleteAssignmentMutation(); | ||||
|     async function deleteAssignment(num: number, clsId: string): Promise<void> { | ||||
|         deleteAssignmentMutation.mutate( | ||||
|  | @ -95,6 +107,9 @@ | |||
|                 onSuccess: () => { | ||||
|                     window.location.href = "/user/assignment"; | ||||
|                 }, | ||||
|                 onError: (e) => { | ||||
|                     showSnackbar(t("failed") + ": " + e.response.data.error || e.message, "error"); | ||||
|                 } | ||||
|             }, | ||||
|         ); | ||||
|     } | ||||
|  | @ -458,6 +473,13 @@ | |||
|                     </v-card> | ||||
|                 </v-dialog> | ||||
|             </v-container> | ||||
|             <v-snackbar | ||||
|                 v-model="snackbar.visible" | ||||
|                 :color="snackbar.color" | ||||
|                 timeout="3000" | ||||
|             > | ||||
|                 {{ snackbar.message }} | ||||
|             </v-snackbar> | ||||
|         </using-query-result> | ||||
|     </div> | ||||
| </template> | ||||
|  |  | |||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl