fix: check student in klas, conflict error
This commit is contained in:
		
							parent
							
								
									3f74c3491f
								
							
						
					
					
						commit
						12d21f3c49
					
				
					 1 changed files with 6 additions and 0 deletions
				
			
		|  | @ -23,6 +23,8 @@ import { GroupDTO } from '@dwengo-1/common/interfaces/group'; | |||
| import { SubmissionDTO, SubmissionDTOId } from '@dwengo-1/common/interfaces/submission'; | ||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||
| import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | ||||
| import {BadRequestException} from "../exceptions/bad-request-exception"; | ||||
| import {ConflictException} from "../exceptions/conflict-exception"; | ||||
| 
 | ||||
| export async function getAllStudents(full: boolean): Promise<StudentDTO[] | string[]> { | ||||
|     const studentRepository = getStudentRepository(); | ||||
|  | @ -135,6 +137,10 @@ export async function createClassJoinRequest(username: string, classId: string): | |||
|     const student = await fetchStudent(username); // Throws error if student not found
 | ||||
|     const cls = await fetchClass(classId); | ||||
| 
 | ||||
|     if (cls.students.contains(student)) { | ||||
|         throw new ConflictException("Student already in this class"); | ||||
|     } | ||||
| 
 | ||||
|     const request = mapToStudentRequest(student, cls); | ||||
|     await requestRepo.save(request, { preventOverwrite: true }); | ||||
|     return mapToStudentRequestDTO(request); | ||||
|  |  | |||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl