diff --git a/frontend/src/queries/students.ts b/frontend/src/queries/students.ts index 6dcdc5b1..918bfc7c 100644 --- a/frontend/src/queries/students.ts +++ b/frontend/src/queries/students.ts @@ -24,31 +24,31 @@ import type {StudentDTO} from "dwengo-1-common/src/interfaces/student"; const studentController = new StudentController(); /** 🔑 Query keys */ -function STUDENTS_QUERY_KEY(full: boolean): [string, boolean] { +function studentsQueryKey(full: boolean): [string, boolean] { return ["students", full]; } -function STUDENT_QUERY_KEY(username: string): [string, string] { +function studentQueryKey(username: string): [string, string] { return ["student", username]; } -function STUDENT_CLASSES_QUERY_KEY(username: string, full: boolean): [string, string, boolean] { +function studentClassesQueryKey(username: string, full: boolean): [string, string, boolean] { return ["student-classes", username, full]; } -function STUDENT_ASSIGNMENTS_QUERY_KEY(username: string, full: boolean): [string, string, boolean] { +function studentAssignmentsQueryKey(username: string, full: boolean): [string, string, boolean] { return ["student-assignments", username, full]; } -function STUDENT_GROUPS_QUERY_KEY(username: string, full: boolean): [string, string, boolean] { +function studentGroupsQueryKeys(username: string, full: boolean): [string, string, boolean] { return ["student-groups", username, full]; } -function STUDENT_SUBMISSIONS_QUERY_KEY(username: string): [string, string] { +function studentSubmissionsQueryKey(username: string): [string, string] { return ["student-submissions", username]; } -function STUDENT_QUESTIONS_QUERY_KEY(username: string, full: boolean): [string, string, boolean] { +function studentQuestionsQueryKey(username: string, full: boolean): [string, string, boolean] { return ["student-questions", username, full]; } -export function STUDENT_JOIN_REQUESTS_QUERY_KEY(username: string): [string, string] { +export function studentJoinRequestsQueryKey(username: string): [string, string] { return ["student-join-requests", username]; } -export function STUDENT_JOIN_REQUEST_QUERY_KEY(username: string, classId: string): [string, string, string] { +export function studentJoinRequestQueryKey(username: string, classId: string): [string, string, string] { return ["student-join-request", username, classId]; } @@ -56,7 +56,7 @@ export function useStudentsQuery( full: MaybeRefOrGetter = true ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => STUDENTS_QUERY_KEY(toValue(full))), + queryKey: computed(() => studentsQueryKey(toValue(full))), queryFn: async () => studentController.getAll(toValue(full)), }); } @@ -65,7 +65,7 @@ export function useStudentQuery( username: MaybeRefOrGetter ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => STUDENT_QUERY_KEY(toValue(username)!)), + queryKey: computed(() => studentQueryKey(toValue(username)!)), queryFn: async () => studentController.getByUsername(toValue(username)!), enabled: () => Boolean(toValue(username)), }); @@ -76,7 +76,7 @@ export function useStudentClassesQuery( full: MaybeRefOrGetter = true ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => STUDENT_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))), + queryKey: computed(() => studentClassesQueryKey(toValue(username)!, toValue(full))), queryFn: async () => studentController.getClasses(toValue(username)!, toValue(full)), enabled: () => Boolean(toValue(username)), }); @@ -87,7 +87,7 @@ export function useStudentAssignmentsQuery( full: MaybeRefOrGetter = true ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => STUDENT_ASSIGNMENTS_QUERY_KEY(toValue(username)!, toValue(full))), + queryKey: computed(() => studentAssignmentsQueryKey(toValue(username)!, toValue(full))), queryFn: async () => studentController.getAssignments(toValue(username)!, toValue(full)), enabled: () => Boolean(toValue(username)), }); @@ -98,7 +98,7 @@ export function useStudentGroupsQuery( full: MaybeRefOrGetter = true ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => STUDENT_GROUPS_QUERY_KEY(toValue(username)!, toValue(full))), + queryKey: computed(() => studentGroupsQueryKeys(toValue(username)!, toValue(full))), queryFn: async () => studentController.getGroups(toValue(username)!, toValue(full)), enabled: () => Boolean(toValue(username)), }); @@ -108,7 +108,7 @@ export function useStudentSubmissionsQuery( username: MaybeRefOrGetter ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => STUDENT_SUBMISSIONS_QUERY_KEY(toValue(username)!)), + queryKey: computed(() => studentSubmissionsQueryKey(toValue(username)!)), queryFn: async () => studentController.getSubmissions(toValue(username)!), enabled: () => Boolean(toValue(username)), }); @@ -119,7 +119,7 @@ export function useStudentQuestionsQuery( full: MaybeRefOrGetter = true ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => STUDENT_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))), + queryKey: computed(() => studentQuestionsQueryKey(toValue(username)!, toValue(full))), queryFn: async () => studentController.getQuestions(toValue(username)!, toValue(full)), enabled: () => Boolean(toValue(username)), }); @@ -129,7 +129,7 @@ export function useStudentJoinRequestsQuery( username: MaybeRefOrGetter ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => STUDENT_JOIN_REQUESTS_QUERY_KEY(toValue(username)!)), + queryKey: computed(() => studentJoinRequestsQueryKey(toValue(username)!)), queryFn: async () => studentController.getJoinRequests(toValue(username)!), enabled: () => Boolean(toValue(username)), }); @@ -140,7 +140,7 @@ export function useStudentJoinRequestQuery( classId: MaybeRefOrGetter ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => STUDENT_JOIN_REQUEST_QUERY_KEY(toValue(username)!, toValue(classId)!)), + queryKey: computed(() => studentJoinRequestQueryKey(toValue(username)!, toValue(classId)!)), queryFn: async () => studentController.getJoinRequest(toValue(username)!, toValue(classId)!), enabled: () => Boolean(toValue(username)) && Boolean(toValue(classId)), }); @@ -174,7 +174,7 @@ export function useDeleteStudentMutation(): UseMutationReturnType< mutationFn: async (username) => studentController.deleteStudent(username), onSuccess: async (deletedUser) => { await queryClient.invalidateQueries({ queryKey: ["students"] }); - await queryClient.invalidateQueries({ queryKey: STUDENT_QUERY_KEY(deletedUser.student.username) }); + await queryClient.invalidateQueries({ queryKey: studentQueryKey(deletedUser.student.username) }); }, }); } @@ -190,7 +190,7 @@ export function useCreateJoinRequestMutation(): UseMutationReturnType< return useMutation({ mutationFn: async ({ username, classId }) => studentController.createJoinRequest(username, classId), onSuccess: async (newJoinRequest) => { - await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUESTS_QUERY_KEY(newJoinRequest.request.requester) }); + await queryClient.invalidateQueries({ queryKey: studentJoinRequestsQueryKey(newJoinRequest.request.requester) }); }, }); } @@ -208,8 +208,8 @@ export function useDeleteJoinRequestMutation(): UseMutationReturnType< 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) }); + await queryClient.invalidateQueries({ queryKey: studentJoinRequestsQueryKey(username) }); + await queryClient.invalidateQueries({ queryKey: studentJoinRequestQueryKey(username, classId) }); }, }); } diff --git a/frontend/src/queries/teachers.ts b/frontend/src/queries/teachers.ts index 3bd625b1..b708b18b 100644 --- a/frontend/src/queries/teachers.ts +++ b/frontend/src/queries/teachers.ts @@ -12,28 +12,28 @@ import type {ClassesResponse} from "@/controllers/classes.ts"; import type {JoinRequestResponse, JoinRequestsResponse, StudentsResponse} from "@/controllers/students.ts"; 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"; +import {studentJoinRequestQueryKey, studentJoinRequestsQueryKey} from "@/queries/students.ts"; const teacherController = new TeacherController(); /** 🔑 Query keys */ -function TEACHERS_QUERY_KEY(full: boolean): [string, boolean] { +function teachersQueryKey(full: boolean): [string, boolean] { return ["teachers", full]; } -function TEACHER_QUERY_KEY(username: string): [string, string] { +function teacherQueryKey(username: string): [string, string] { return ["teacher", username]; } -function TEACHER_CLASSES_QUERY_KEY(username: string, full: boolean): [string, string, boolean] { +function teacherClassesQueryKey(username: string, full: boolean): [string, string, boolean] { return ["teacher-classes", username, full]; } -function TEACHER_STUDENTS_QUERY_KEY(username: string, full: boolean): [string, string, boolean] { +function teacherStudentsQueryKey(username: string, full: boolean): [string, string, boolean] { return ["teacher-students", username, full]; } -function TEACHER_QUESTIONS_QUERY_KEY(username: string, full: boolean): [string, string, boolean] { +function teacherQuestionsQueryKey(username: string, full: boolean): [string, string, boolean] { return ["teacher-questions", username, full]; } @@ -42,7 +42,7 @@ export function useTeachersQuery( full: MaybeRefOrGetter = false ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => TEACHERS_QUERY_KEY(toValue(full))), + queryKey: computed(() => teachersQueryKey(toValue(full))), queryFn: async () => teacherController.getAll(toValue(full)), }); } @@ -51,7 +51,7 @@ export function useTeacherQuery( username: MaybeRefOrGetter ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => TEACHER_QUERY_KEY(toValue(username)!)), + queryKey: computed(() => teacherQueryKey(toValue(username)!)), queryFn: async () => teacherController.getByUsername(toValue(username)!), enabled: () => Boolean(toValue(username)), }); @@ -62,7 +62,7 @@ export function useTeacherClassesQuery( full: MaybeRefOrGetter = false ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => TEACHER_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))), + queryKey: computed(() => teacherClassesQueryKey(toValue(username)!, toValue(full))), queryFn: async () => teacherController.getClasses(toValue(username)!, toValue(full)), enabled: () => Boolean(toValue(username)), }); @@ -73,7 +73,7 @@ export function useTeacherStudentsQuery( full: MaybeRefOrGetter = false ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => TEACHER_STUDENTS_QUERY_KEY(toValue(username)!, toValue(full))), + queryKey: computed(() => teacherStudentsQueryKey(toValue(username)!, toValue(full))), queryFn: async () => teacherController.getStudents(toValue(username)!, toValue(full)), enabled: () => Boolean(toValue(username)), }); @@ -84,7 +84,7 @@ export function useTeacherQuestionsQuery( full: MaybeRefOrGetter = false ): UseQueryReturnType { return useQuery({ - queryKey: computed(() => TEACHER_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))), + queryKey: computed(() => teacherQuestionsQueryKey(toValue(username)!, toValue(full))), queryFn: async () => teacherController.getQuestions(toValue(username)!, toValue(full)), enabled: () => Boolean(toValue(username)), }); @@ -129,7 +129,7 @@ export function useDeleteTeacherMutation(): UseMutationReturnType< mutationFn: async (username: string) => teacherController.deleteTeacher(username), onSuccess: async (deletedTeacher) => { await queryClient.invalidateQueries({ queryKey: ["teachers"] }); - await queryClient.invalidateQueries({ queryKey: TEACHER_QUERY_KEY(deletedTeacher.teacher.username) }); + await queryClient.invalidateQueries({ queryKey: teacherQueryKey(deletedTeacher.teacher.username) }); }, }); } @@ -148,8 +148,8 @@ export function useUpdateJoinRequestMutation(): UseMutationReturnType< 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) }); + await queryClient.invalidateQueries({ queryKey: studentJoinRequestsQueryKey(username) }); + await queryClient.invalidateQueries({ queryKey: studentJoinRequestQueryKey(username, classId) }); }, }); }