feat(frontend): Heel ruwe eerste versie van leerpadbeheerpagina toegevoegd
This commit is contained in:
parent
1a768fedcc
commit
2db5d77296
15 changed files with 732 additions and 5820 deletions
|
@ -1,8 +1,10 @@
|
|||
import { type MaybeRefOrGetter, toValue } from "vue";
|
||||
import type { Language } from "@/data-objects/language.ts";
|
||||
import { useQuery, type UseQueryReturnType } from "@tanstack/vue-query";
|
||||
import { useMutation, useQuery, useQueryClient, type UseMutationReturnType, type UseQueryReturnType } from "@tanstack/vue-query";
|
||||
import { getLearningPathController } from "@/controllers/controllers";
|
||||
import type { LearningPath } from "@/data-objects/learning-paths/learning-path.ts";
|
||||
import type { AxiosError } from "axios";
|
||||
import type { LearningPathDTO } from "@/data-objects/learning-paths/learning-path-dto";
|
||||
|
||||
export const LEARNING_PATH_KEY = "learningPath";
|
||||
const learningPathController = getLearningPathController();
|
||||
|
@ -32,6 +34,46 @@ export function useGetAllLearningPathsByThemeQuery(
|
|||
});
|
||||
}
|
||||
|
||||
export function useGetAllLearningPathsByAdminQuery(
|
||||
admin: MaybeRefOrGetter<string | undefined>
|
||||
): UseQueryReturnType<LearningPathDTO[], AxiosError> {
|
||||
return useQuery({
|
||||
queryKey: [LEARNING_PATH_KEY, "getAllByAdmin", admin],
|
||||
queryFn: async () => learningPathController.getAllByAdminRaw(toValue(admin)!),
|
||||
enabled: () => Boolean(toValue(admin))
|
||||
});
|
||||
}
|
||||
|
||||
export function usePostLearningPathMutation():
|
||||
UseMutationReturnType<LearningPathDTO, AxiosError, { learningPath: LearningPathDTO }, unknown> {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ learningPath }) => learningPathController.postLearningPath(learningPath),
|
||||
onSuccess: async () => queryClient.invalidateQueries({ queryKey: [LEARNING_PATH_KEY] })
|
||||
});
|
||||
}
|
||||
|
||||
export function usePutLearningPathMutation():
|
||||
UseMutationReturnType<LearningPathDTO, AxiosError, { learningPath: LearningPathDTO }, unknown> {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ learningPath }) => learningPathController.putLearningPath(learningPath),
|
||||
onSuccess: async () => queryClient.invalidateQueries({ queryKey: [LEARNING_PATH_KEY] })
|
||||
});
|
||||
}
|
||||
|
||||
export function useDeleteLearningPathMutation():
|
||||
UseMutationReturnType<LearningPathDTO, AxiosError, { hruid: string, language: Language }, unknown> {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: async ({ hruid, language }) => learningPathController.deleteLearningPath(hruid, language),
|
||||
onSuccess: async () => queryClient.invalidateQueries({ queryKey: [LEARNING_PATH_KEY] })
|
||||
});
|
||||
}
|
||||
|
||||
export function useSearchLearningPathQuery(
|
||||
query: MaybeRefOrGetter<string | undefined>,
|
||||
language: MaybeRefOrGetter<string | undefined>,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue