fix: merge + types frontend controller
This commit is contained in:
parent
4ca568e738
commit
8ceed7f779
20 changed files with 129 additions and 92 deletions
|
@ -18,14 +18,14 @@ const STUDENT_JOIN_REQUESTS_QUERY_KEY = (username: string) => ["student-join-req
|
|||
export function useStudentsQuery(full: MaybeRefOrGetter<boolean> = true) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => STUDENTS_QUERY_KEY(toValue(full))),
|
||||
queryFn: () => studentController.getAll(toValue(full)),
|
||||
queryFn: async () => studentController.getAll(toValue(full)),
|
||||
});
|
||||
}
|
||||
|
||||
export function useStudentQuery(username: MaybeRefOrGetter<string | undefined>) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => STUDENT_QUERY_KEY(toValue(username)!)),
|
||||
queryFn: () => studentController.getByUsername(toValue(username)!),
|
||||
queryFn: async () => studentController.getByUsername(toValue(username)!),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ export function useStudentClassesQuery(
|
|||
) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => STUDENT_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||
queryFn: () => studentController.getClasses(toValue(username)!, toValue(full)),
|
||||
queryFn: async () => studentController.getClasses(toValue(username)!, toValue(full)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ export function useStudentAssignmentsQuery(
|
|||
) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => STUDENT_ASSIGNMENTS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||
queryFn: () => studentController.getAssignments(toValue(username)!, toValue(full)),
|
||||
queryFn: async () => studentController.getAssignments(toValue(username)!, toValue(full)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -58,7 +58,7 @@ export function useStudentGroupsQuery(
|
|||
) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => STUDENT_GROUPS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||
queryFn: () => studentController.getGroups(toValue(username)!, toValue(full)),
|
||||
queryFn: async () => studentController.getGroups(toValue(username)!, toValue(full)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ export function useStudentGroupsQuery(
|
|||
export function useStudentSubmissionsQuery(username: MaybeRefOrGetter<string | undefined>) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => STUDENT_SUBMISSIONS_QUERY_KEY(toValue(username)!)),
|
||||
queryFn: () => studentController.getSubmissions(toValue(username)!),
|
||||
queryFn: async () => studentController.getSubmissions(toValue(username)!),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -77,7 +77,7 @@ export function useStudentQuestionsQuery(
|
|||
) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => STUDENT_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||
queryFn: () => studentController.getQuestions(toValue(username)!, toValue(full)),
|
||||
queryFn: async () => studentController.getQuestions(toValue(username)!, toValue(full)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -86,7 +86,7 @@ export function useCreateStudentMutation() {
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: any) => studentController.createStudent(data),
|
||||
mutationFn: async (data: any) => studentController.createStudent(data),
|
||||
onSuccess: () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ["students"] });
|
||||
},
|
||||
|
@ -103,7 +103,7 @@ export function useDeleteStudentMutation() {
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (username: string) => studentController.deleteStudent(username),
|
||||
mutationFn: async (username: string) => studentController.deleteStudent(username),
|
||||
onSuccess: () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ["students"] });
|
||||
},
|
||||
|
@ -116,7 +116,7 @@ export function useDeleteStudentMutation() {
|
|||
export function useStudentJoinRequestsQuery(username: MaybeRefOrGetter<string | undefined>) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => STUDENT_JOIN_REQUESTS_QUERY_KEY(toValue(username)!)),
|
||||
queryFn: () => studentController.getJoinRequests(toValue(username)!),
|
||||
queryFn: async () => studentController.getJoinRequests(toValue(username)!),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -127,7 +127,7 @@ export function useStudentJoinRequestQuery(
|
|||
) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => STUDENT_JOIN_REQUESTS_QUERY_KEY(toValue(username)!)),
|
||||
queryFn: () => studentController.getJoinRequest(toValue(username)!, toValue(classId)!),
|
||||
queryFn: async () => studentController.getJoinRequest(toValue(username)!, toValue(classId)!),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -139,7 +139,7 @@ export function useCreateJoinRequestMutation() {
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ username, classId }: { username: string; classId: string }) =>
|
||||
mutationFn: async ({ username, classId }: { username: string; classId: string }) =>
|
||||
studentController.createJoinRequest(username, classId),
|
||||
onSuccess: (_, { username }) => {
|
||||
await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUESTS_QUERY_KEY(username) });
|
||||
|
@ -157,7 +157,7 @@ export function useDeleteJoinRequestMutation() {
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({ username, classId }: { username: string; classId: string }) =>
|
||||
mutationFn: async ({ username, classId }: { username: string; classId: string }) =>
|
||||
studentController.deleteJoinRequest(username, classId),
|
||||
onSuccess: (_, { username }) => {
|
||||
await queryClient.invalidateQueries({ queryKey: STUDENT_JOIN_REQUESTS_QUERY_KEY(username) });
|
||||
|
|
|
@ -16,14 +16,14 @@ const JOIN_REQUESTS_QUERY_KEY = (username: string, classId: string) => ["join-re
|
|||
export function useTeachersQuery(full: MaybeRefOrGetter<boolean> = false) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => TEACHERS_QUERY_KEY(toValue(full))),
|
||||
queryFn: () => teacherController.getAll(toValue(full)),
|
||||
queryFn: async () => teacherController.getAll(toValue(full)),
|
||||
});
|
||||
}
|
||||
|
||||
export function useTeacherQuery(username: MaybeRefOrGetter<string | undefined>) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => TEACHER_QUERY_KEY(toValue(username)!)),
|
||||
queryFn: () => teacherController.getByUsername(toValue(username)!),
|
||||
queryFn: async () => teacherController.getByUsername(toValue(username)!),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ export function useTeacherClassesQuery(
|
|||
) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => TEACHER_CLASSES_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||
queryFn: () => teacherController.getClasses(toValue(username)!, toValue(full)),
|
||||
queryFn: async () => teacherController.getClasses(toValue(username)!, toValue(full)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ export function useTeacherStudentsQuery(
|
|||
) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => TEACHER_STUDENTS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||
queryFn: () => teacherController.getStudents(toValue(username)!, toValue(full)),
|
||||
queryFn: async () => teacherController.getStudents(toValue(username)!, toValue(full)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -56,7 +56,7 @@ export function useTeacherQuestionsQuery(
|
|||
) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => TEACHER_QUESTIONS_QUERY_KEY(toValue(username)!, toValue(full))),
|
||||
queryFn: () => teacherController.getQuestions(toValue(username)!, toValue(full)),
|
||||
queryFn: async () => teacherController.getQuestions(toValue(username)!, toValue(full)),
|
||||
enabled: () => Boolean(toValue(username)),
|
||||
});
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ export function useTeacherJoinRequestsQuery(
|
|||
) {
|
||||
return useQuery({
|
||||
queryKey: computed(() => JOIN_REQUESTS_QUERY_KEY(toValue(username)!, toValue(classId)!)),
|
||||
queryFn: () => teacherController.getStudentJoinRequests(toValue(username)!, toValue(classId)!),
|
||||
queryFn: async () => teacherController.getStudentJoinRequests(toValue(username)!, toValue(classId)!),
|
||||
enabled: () => Boolean(toValue(username)) && Boolean(toValue(classId)),
|
||||
});
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ export function useCreateTeacherMutation() {
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: any) => teacherController.createTeacher(data),
|
||||
mutationFn: async (data: any) => teacherController.createTeacher(data),
|
||||
onSuccess: () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ["teachers"] });
|
||||
},
|
||||
|
@ -90,7 +90,7 @@ export function useDeleteTeacherMutation() {
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (username: string) => teacherController.deleteTeacher(username),
|
||||
mutationFn: async (username: string) => teacherController.deleteTeacher(username),
|
||||
onSuccess: () => {
|
||||
await queryClient.invalidateQueries({ queryKey: ["teachers"] });
|
||||
},
|
||||
|
@ -104,7 +104,7 @@ export function useUpdateJoinRequestMutation() {
|
|||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({
|
||||
mutationFn: async ({
|
||||
teacherUsername,
|
||||
classId,
|
||||
studentUsername,
|
||||
|
|
|
@ -7,7 +7,7 @@ const themeController = new ThemeController();
|
|||
export function useThemeQuery(language: MaybeRefOrGetter<string | undefined>) {
|
||||
return useQuery({
|
||||
queryKey: ["themes", language],
|
||||
queryFn: () => {
|
||||
queryFn: async () => {
|
||||
const lang = toValue(language);
|
||||
return themeController.getAll(lang);
|
||||
},
|
||||
|
@ -18,7 +18,7 @@ export function useThemeQuery(language: MaybeRefOrGetter<string | undefined>) {
|
|||
export function useThemeHruidsQuery(themeKey: MaybeRefOrGetter<string | undefined>) {
|
||||
return useQuery({
|
||||
queryKey: ["theme-hruids", themeKey],
|
||||
queryFn: () => themeController.getHruidsByKey(toValue(themeKey)!),
|
||||
queryFn: async () => themeController.getHruidsByKey(toValue(themeKey)!),
|
||||
enabled: Boolean(themeKey),
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue