fix: extra invalidate queries bij delete en put
This commit is contained in:
		
							parent
							
								
									075616b67b
								
							
						
					
					
						commit
						dadde1651b
					
				
					 4 changed files with 21 additions and 28 deletions
				
			
		
							
								
								
									
										6
									
								
								common/src/interfaces/teacher.d.ts
									
										
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								common/src/interfaces/teacher.d.ts
									
										
									
									
										vendored
									
									
								
							|  | @ -3,10 +3,4 @@ export interface TeacherDTO { | |||
|     username: string; | ||||
|     firstName: string; | ||||
|     lastName: string; | ||||
|     endpoints?: { | ||||
|         classes: string; | ||||
|         questions: string; | ||||
|         invitations: string; | ||||
|         groups: string; | ||||
|     }; | ||||
| } | ||||
|  |  | |||
|  | @ -5,7 +5,7 @@ import type {ClassesResponse} from "@/controllers/classes.ts"; | |||
| import type {TeacherDTO} from "dwengo-1-common/src/interfaces/teacher"; | ||||
| 
 | ||||
| export interface TeachersResponse { teachers: TeacherDTO[] | string[] } | ||||
| export interface TeacherResponse { teacher: TeacherDTO | string } | ||||
| export interface TeacherResponse { teacher: TeacherDTO } | ||||
| 
 | ||||
| 
 | ||||
| export class TeacherController extends BaseController { | ||||
|  |  | |||
|  | @ -45,10 +45,10 @@ function STUDENT_SUBMISSIONS_QUERY_KEY(username: string): [string, string] { | |||
| function STUDENT_QUESTIONS_QUERY_KEY(username: string, full: boolean): [string, string, boolean] { | ||||
|     return ["student-questions", username, full]; | ||||
| } | ||||
| function STUDENT_JOIN_REQUESTS_QUERY_KEY(username: string): [string, string] { | ||||
| export function STUDENT_JOIN_REQUESTS_QUERY_KEY(username: string): [string, string] { | ||||
|     return ["student-join-requests", username]; | ||||
| } | ||||
| function STUDENT_JOIN_REQUEST_QUERY_KEY(username: string, classId: string): [string, string, string] { | ||||
| export function STUDENT_JOIN_REQUEST_QUERY_KEY(username: string, classId: string): [string, string, string] { | ||||
|     return ["student-join-request", username, classId]; | ||||
| } | ||||
| 
 | ||||
|  | @ -172,8 +172,9 @@ export function useDeleteStudentMutation(): UseMutationReturnType< | |||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async (username) => studentController.deleteStudent(username), | ||||
|         onSuccess: async () => { | ||||
|         onSuccess: async (deletedUser) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: ["students"] }); | ||||
|             await queryClient.invalidateQueries({ queryKey: STUDENT_QUERY_KEY(deletedUser.student.username) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
|  | @ -188,8 +189,8 @@ export function useCreateJoinRequestMutation(): UseMutationReturnType< | |||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ username, classId }) => studentController.createJoinRequest(username, classId), | ||||
|         onSuccess: async ({ username }) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUESTS_QUERY_KEY(username) }); | ||||
|         onSuccess: async (newJoinRequest) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUESTS_QUERY_KEY(newJoinRequest.request.requester) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
|  | @ -204,8 +205,11 @@ export function useDeleteJoinRequestMutation(): UseMutationReturnType< | |||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: async ({ username, classId }) => studentController.deleteJoinRequest(username, classId), | ||||
|         onSuccess: async ({ username }) => { | ||||
|         onSuccess: async (deletedJoinRequest) => { | ||||
|             const username = deletedJoinRequest.request.requester; | ||||
|             const classId = deletedJoinRequest.request.class; | ||||
|             await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUESTS_QUERY_KEY(username) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUEST_QUERY_KEY(username, classId) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
|  |  | |||
|  | @ -8,17 +8,11 @@ import { | |||
|     UseQueryReturnType, | ||||
| } from "@tanstack/vue-query"; | ||||
| import {TeacherController, type TeacherResponse, type TeachersResponse} from "@/controllers/teachers.ts"; | ||||
| import type { | ||||
|     TeacherDTO, | ||||
|     ClassDTO, | ||||
|     StudentDTO, | ||||
|     QuestionDTO, | ||||
|     QuestionId, | ||||
|     JoinRequestDTO, | ||||
| } from "dwengo-1-common/src/interfaces"; | ||||
| import type {ClassesResponse} from "@/controllers/classes.ts"; | ||||
| import type {JoinRequestResponse, JoinRequestsResponse, StudentsResponse} from "@/controllers/students.ts"; | ||||
| import type {QuestionsResponse} from "@/controllers/questions.ts"; // pas dit aan naar jouw pad indien nodig
 | ||||
| import type {QuestionsResponse} from "@/controllers/questions.ts"; | ||||
| import type {TeacherDTO} from "dwengo-1-common/src/interfaces/teacher"; | ||||
| import {STUDENT_JOIN_REQUEST_QUERY_KEY, STUDENT_JOIN_REQUESTS_QUERY_KEY} from "@/queries/students.ts"; | ||||
| 
 | ||||
| const teacherController = new TeacherController(); | ||||
| 
 | ||||
|  | @ -133,8 +127,9 @@ export function useDeleteTeacherMutation(): UseMutationReturnType< | |||
| 
 | ||||
|     return useMutation({ | ||||
|         mutationFn: (username: string) => teacherController.deleteTeacher(username), | ||||
|         onSuccess: async () => { | ||||
|         onSuccess: async (deletedTeacher) => { | ||||
|             await queryClient.invalidateQueries({ queryKey: ["teachers"] }); | ||||
|             await queryClient.invalidateQueries({ queryKey: TEACHER_QUERY_KEY(deletedTeacher.teacher.username) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
|  | @ -150,11 +145,11 @@ export function useUpdateJoinRequestMutation(): UseMutationReturnType< | |||
|     return useMutation({ | ||||
|         mutationFn: ({ teacherUsername, classId, studentUsername, accepted }) => | ||||
|             teacherController.updateStudentJoinRequest(teacherUsername, classId, studentUsername, accepted), | ||||
|         onSuccess: async (_, { teacherUsername, classId }) => { | ||||
|             await queryClient.invalidateQueries({ | ||||
|                 queryKey: JOIN_REQUESTS_QUERY_KEY(teacherUsername, classId), | ||||
|                 // TODO
 | ||||
|             }); | ||||
|         onSuccess: async (deletedJoinRequest) => { | ||||
|             const username = deletedJoinRequest.request.requester; | ||||
|             const classId = deletedJoinRequest.request.class; | ||||
|             await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUESTS_QUERY_KEY(username) }); | ||||
|             await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUEST_QUERY_KEY(username, classId) }); | ||||
|         }, | ||||
|     }); | ||||
| } | ||||
|  |  | |||
		Reference in a new issue
	
	 Gabriellvl
						Gabriellvl