feat: teacher's assignments full stack geimplementeerd
This commit is contained in:
		
							parent
							
								
									509dd6bfab
								
							
						
					
					
						commit
						c03669eda7
					
				
					 5 changed files with 49 additions and 0 deletions
				
			
		|  | @ -7,6 +7,7 @@ import { | ||||||
|     getJoinRequestsByClass, |     getJoinRequestsByClass, | ||||||
|     getStudentsByTeacher, |     getStudentsByTeacher, | ||||||
|     getTeacher, |     getTeacher, | ||||||
|  |     getTeacherAssignments, | ||||||
|     getTeacherQuestions, |     getTeacherQuestions, | ||||||
|     updateClassJoinRequestStatus, |     updateClassJoinRequestStatus, | ||||||
| } from '../services/teachers.js'; | } from '../services/teachers.js'; | ||||||
|  | @ -60,6 +61,16 @@ export async function getTeacherClassHandler(req: Request, res: Response): Promi | ||||||
|     res.json({ classes }); |     res.json({ classes }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export async function getTeacherAssignmentsHandler(req: Request, res: Response): Promise<void> { | ||||||
|  |     const username = req.params.username; | ||||||
|  |     const full = req.query.full === 'true'; | ||||||
|  |     requireFields({ username }); | ||||||
|  | 
 | ||||||
|  |     const assignments = await getTeacherAssignments(username, full); | ||||||
|  | 
 | ||||||
|  |     res.json({ assignments }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export async function getTeacherStudentHandler(req: Request, res: Response): Promise<void> { | export async function getTeacherStudentHandler(req: Request, res: Response): Promise<void> { | ||||||
|     const username = req.params.username; |     const username = req.params.username; | ||||||
|     const full = req.query.full === 'true'; |     const full = req.query.full === 'true'; | ||||||
|  |  | ||||||
|  | @ -4,6 +4,7 @@ import { | ||||||
|     deleteTeacherHandler, |     deleteTeacherHandler, | ||||||
|     getAllTeachersHandler, |     getAllTeachersHandler, | ||||||
|     getStudentJoinRequestHandler, |     getStudentJoinRequestHandler, | ||||||
|  |     getTeacherAssignmentsHandler, | ||||||
|     getTeacherClassHandler, |     getTeacherClassHandler, | ||||||
|     getTeacherHandler, |     getTeacherHandler, | ||||||
|     getTeacherQuestionHandler, |     getTeacherQuestionHandler, | ||||||
|  | @ -25,6 +26,8 @@ router.delete('/:username', deleteTeacherHandler); | ||||||
| 
 | 
 | ||||||
| router.get('/:username/classes', getTeacherClassHandler); | router.get('/:username/classes', getTeacherClassHandler); | ||||||
| 
 | 
 | ||||||
|  | router.get(`/:username/assignments`, getTeacherAssignmentsHandler); | ||||||
|  | 
 | ||||||
| router.get('/:username/students', getTeacherStudentHandler); | router.get('/:username/students', getTeacherStudentHandler); | ||||||
| 
 | 
 | ||||||
| router.get('/:username/questions', getTeacherQuestionHandler); | router.get('/:username/questions', getTeacherQuestionHandler); | ||||||
|  |  | ||||||
|  | @ -1,4 +1,5 @@ | ||||||
| import { | import { | ||||||
|  |     getAssignmentRepository, | ||||||
|     getClassJoinRequestRepository, |     getClassJoinRequestRepository, | ||||||
|     getClassRepository, |     getClassRepository, | ||||||
|     getLearningObjectRepository, |     getLearningObjectRepository, | ||||||
|  | @ -30,6 +31,8 @@ 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 { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | import { ClassStatus } from '@dwengo-1/common/util/class-join-request'; | ||||||
| import { ConflictException } from '../exceptions/conflict-exception.js'; | import { ConflictException } from '../exceptions/conflict-exception.js'; | ||||||
|  | import { AssignmentDTO, AssignmentDTOId } from '@dwengo-1/common/interfaces/assignment'; | ||||||
|  | import { mapToAssignmentDTO, mapToAssignmentDTOId } from '../interfaces/assignment.js'; | ||||||
| 
 | 
 | ||||||
| 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(); | ||||||
|  | @ -101,6 +104,17 @@ export async function getClassesByTeacher(username: string, full: boolean): Prom | ||||||
|     return classes.map((cls) => cls.id); |     return classes.map((cls) => cls.id); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export async function getTeacherAssignments(username: string, full: boolean): Promise<AssignmentDTO[] | AssignmentDTOId[]> { | ||||||
|  |     const assignmentRepository = getAssignmentRepository(); | ||||||
|  |     const assignments = await assignmentRepository.findAllByResponsibleTeacher(username); | ||||||
|  | 
 | ||||||
|  |     if (full) { | ||||||
|  |         return assignments.map(mapToAssignmentDTO); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     return assignments.map(mapToAssignmentDTOId); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export async function getStudentsByTeacher(username: string, full: boolean): Promise<StudentDTO[] | string[]> { | export async function getStudentsByTeacher(username: string, full: boolean): Promise<StudentDTO[] | string[]> { | ||||||
|     const classes: ClassDTO[] = await fetchClassesByTeacher(username); |     const classes: ClassDTO[] = await fetchClassesByTeacher(username); | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -3,6 +3,7 @@ import type { JoinRequestResponse, JoinRequestsResponse, StudentsResponse } from | ||||||
| import type { QuestionsResponse } from "@/controllers/questions.ts"; | import type { QuestionsResponse } from "@/controllers/questions.ts"; | ||||||
| import type { ClassesResponse } from "@/controllers/classes.ts"; | import type { ClassesResponse } from "@/controllers/classes.ts"; | ||||||
| import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | ||||||
|  | import type { AssignmentsResponse } from "./assignments"; | ||||||
| 
 | 
 | ||||||
| export interface TeachersResponse { | export interface TeachersResponse { | ||||||
|     teachers: TeacherDTO[] | string[]; |     teachers: TeacherDTO[] | string[]; | ||||||
|  | @ -36,6 +37,10 @@ export class TeacherController extends BaseController { | ||||||
|         return this.get<ClassesResponse>(`/${username}/classes`, { full }); |         return this.get<ClassesResponse>(`/${username}/classes`, { full }); | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|  |     async getAssignments(username: string, full = true): Promise<AssignmentsResponse> { | ||||||
|  |         return this.get<AssignmentsResponse>(`/${username}/assignments`, { full }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     async getStudents(username: string, full = false): Promise<StudentsResponse> { |     async getStudents(username: string, full = false): Promise<StudentsResponse> { | ||||||
|         return this.get<StudentsResponse>(`/${username}/students`, { full }); |         return this.get<StudentsResponse>(`/${username}/students`, { full }); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  | @ -13,6 +13,7 @@ import type { JoinRequestResponse, JoinRequestsResponse, StudentsResponse } from | ||||||
| import type { QuestionsResponse } from "@/controllers/questions.ts"; | import type { QuestionsResponse } from "@/controllers/questions.ts"; | ||||||
| import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | import type { TeacherDTO } from "@dwengo-1/common/interfaces/teacher"; | ||||||
| import { studentJoinRequestQueryKey, studentJoinRequestsQueryKey } from "@/queries/students.ts"; | import { studentJoinRequestQueryKey, studentJoinRequestsQueryKey } from "@/queries/students.ts"; | ||||||
|  | import type { AssignmentResponse, AssignmentsResponse } from "@/controllers/assignments"; | ||||||
| 
 | 
 | ||||||
| const teacherController = new TeacherController(); | const teacherController = new TeacherController(); | ||||||
| 
 | 
 | ||||||
|  | @ -29,6 +30,10 @@ function teacherClassesQueryKey(username: string, full: boolean): [string, strin | ||||||
|     return ["teacher-classes", username, full]; |     return ["teacher-classes", username, full]; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | function teacherAssignmentsQueryKey(username: string, full: boolean): [string, string, boolean] { | ||||||
|  |     return ["teacher-assignments", username, full]; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| function teacherStudentsQueryKey(username: string, full: boolean): [string, string, boolean] { | function teacherStudentsQueryKey(username: string, full: boolean): [string, string, boolean] { | ||||||
|     return ["teacher-students", username, full]; |     return ["teacher-students", username, full]; | ||||||
| } | } | ||||||
|  | @ -69,6 +74,17 @@ export function useTeacherClassesQuery( | ||||||
|     }); |     }); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | export function useTeacherAssignmentsQuery( | ||||||
|  |     username: MaybeRefOrGetter<string | undefined>, | ||||||
|  |     full: MaybeRefOrGetter<boolean> = false, | ||||||
|  | ): UseQueryReturnType<AssignmentsResponse, Error> { | ||||||
|  |     return useQuery({ | ||||||
|  |         queryKey: computed(() => teacherAssignmentsQueryKey(toValue(username)!, toValue(full))), | ||||||
|  |         queryFn: async () => teacherController.getAssignments(toValue(username)!, toValue(full)), | ||||||
|  |         enabled: () => Boolean(toValue(username)), | ||||||
|  |     }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| export function useTeacherStudentsQuery( | export function useTeacherStudentsQuery( | ||||||
|     username: MaybeRefOrGetter<string | undefined>, |     username: MaybeRefOrGetter<string | undefined>, | ||||||
|     full: MaybeRefOrGetter<boolean> = false, |     full: MaybeRefOrGetter<boolean> = false, | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 Adriaan Jacquet
						Adriaan Jacquet