fix: voeg student toe aan klas indien leeraar accept
This commit is contained in:
		
							parent
							
								
									12d21f3c49
								
							
						
					
					
						commit
						7887a5aec4
					
				
					 1 changed files with 13 additions and 6 deletions
				
			
		|  | @ -22,13 +22,15 @@ import { Question } from '../entities/questions/question.entity.js'; | ||||||
| import { ClassJoinRequestRepository } from '../data/classes/class-join-request-repository.js'; | import { ClassJoinRequestRepository } from '../data/classes/class-join-request-repository.js'; | ||||||
| import { Student } from '../entities/users/student.entity.js'; | import { Student } from '../entities/users/student.entity.js'; | ||||||
| import { NotFoundException } from '../exceptions/not-found-exception.js'; | import { NotFoundException } from '../exceptions/not-found-exception.js'; | ||||||
| import { getClassStudents, getClassStudentsDTO } from './classes.js'; | import {addClassStudent, fetchClass, getClassStudents, getClassStudentsDTO} from './classes.js'; | ||||||
| import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher'; | import { TeacherDTO } from '@dwengo-1/common/interfaces/teacher'; | ||||||
| import { ClassDTO } from '@dwengo-1/common/interfaces/class'; | import { ClassDTO } from '@dwengo-1/common/interfaces/class'; | ||||||
| import { StudentDTO } from '@dwengo-1/common/interfaces/student'; | import { StudentDTO } from '@dwengo-1/common/interfaces/student'; | ||||||
| import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | import { QuestionDTO, QuestionId } from '@dwengo-1/common/interfaces/question'; | ||||||
| import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | import { ClassJoinRequestDTO } from '@dwengo-1/common/interfaces/class-join-request'; | ||||||
| import { ClassJoinRequestStatus } from '@dwengo-1/common/util/class-join-request'; | import { ClassJoinRequestStatus } from '@dwengo-1/common/util/class-join-request'; | ||||||
|  | import {BadRequestException} from "../exceptions/bad-request-exception"; | ||||||
|  | import {ConflictException} from "../exceptions/conflict-exception"; | ||||||
| 
 | 
 | ||||||
| export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> { | export async function getAllTeachers(full: boolean): Promise<TeacherDTO[] | string[]> { | ||||||
|     const teacherRepository: TeacherRepository = getTeacherRepository(); |     const teacherRepository: TeacherRepository = getTeacherRepository(); | ||||||
|  | @ -145,13 +147,12 @@ export async function getJoinRequestsByClass(classId: string): Promise<ClassJoin | ||||||
| 
 | 
 | ||||||
| export async function updateClassJoinRequestStatus(studentUsername: string, classId: string, accepted = true): Promise<ClassJoinRequestDTO> { | export async function updateClassJoinRequestStatus(studentUsername: string, classId: string, accepted = true): Promise<ClassJoinRequestDTO> { | ||||||
|     const requestRepo: ClassJoinRequestRepository = getClassJoinRequestRepository(); |     const requestRepo: ClassJoinRequestRepository = getClassJoinRequestRepository(); | ||||||
|     const classRepo: ClassRepository = getClassRepository(); |  | ||||||
| 
 | 
 | ||||||
|     const student: Student = await fetchStudent(studentUsername); |     const student: Student = await fetchStudent(studentUsername); | ||||||
|     const cls: Class | null = await classRepo.findById(classId); |     const cls = await fetchClass(classId); | ||||||
| 
 | 
 | ||||||
|     if (!cls) { |     if (cls.students.contains(student)) { | ||||||
|         throw new NotFoundException('Class not found'); |         throw new ConflictException("Student already in this class"); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     const request: ClassJoinRequest | null = await requestRepo.findByStudentAndClass(student, cls); |     const request: ClassJoinRequest | null = await requestRepo.findByStudentAndClass(student, cls); | ||||||
|  | @ -160,8 +161,14 @@ export async function updateClassJoinRequestStatus(studentUsername: string, clas | ||||||
|         throw new NotFoundException('Join request not found'); |         throw new NotFoundException('Join request not found'); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     request.status = accepted ? ClassJoinRequestStatus.Accepted : ClassJoinRequestStatus.Declined; |     request.status = ClassJoinRequestStatus.Declined; | ||||||
|  | 
 | ||||||
|  |     if (accepted){ | ||||||
|  |         request.status = ClassJoinRequestStatus.Accepted; | ||||||
|  |         await addClassStudent(classId, studentUsername); | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|     await requestRepo.save(request); |     await requestRepo.save(request); | ||||||
|  | 
 | ||||||
|     return mapToStudentRequestDTO(request); |     return mapToStudentRequestDTO(request); | ||||||
| } | } | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl