74 lines
2.1 KiB
TypeScript
74 lines
2.1 KiB
TypeScript
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
|
|
|
|
import { ENDPOINT } from "@/shared/config";
|
|
|
|
import type {
|
|
CnstpSeMngPutRequestDto,
|
|
CnstpSeMngSaveRequestDto,
|
|
CnstpSeMngSearchDto,
|
|
} from "../model/cnstp-interface";
|
|
|
|
import { cnstpSeMngService } from "./cnstp-service";
|
|
|
|
const cnstpSeMngBaseKey = [ENDPOINT.AS_COMMON_SERVICE.CNSTP_SE] as const;
|
|
|
|
export function useCnstpSeMngPage(params: CnstpSeMngSearchDto) {
|
|
return useQuery({
|
|
queryKey: [...cnstpSeMngBaseKey, "findAll", params],
|
|
queryFn: () => cnstpSeMngService.findAll(params),
|
|
});
|
|
}
|
|
|
|
export function useCnstpSeMngTree() {
|
|
return useQuery({
|
|
queryKey: [...cnstpSeMngBaseKey, "findTree"],
|
|
queryFn: () => cnstpSeMngService.findTree(),
|
|
staleTime: Infinity,
|
|
});
|
|
}
|
|
|
|
export function useCnstpSeMng(cnstpSeCd: string | null | undefined) {
|
|
return useQuery({
|
|
queryKey: [...cnstpSeMngBaseKey, "findById", cnstpSeCd],
|
|
queryFn: () => cnstpSeMngService.findById(cnstpSeCd!),
|
|
enabled: Boolean(cnstpSeCd),
|
|
});
|
|
}
|
|
|
|
export function useSaveMultiCnstpSeMng() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (body: CnstpSeMngSaveRequestDto[]) => cnstpSeMngService.saveMulti(body),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: cnstpSeMngBaseKey });
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useUpdateCnstpSeMng() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: ({ cnstpSeCd, body }: { cnstpSeCd: string; body: CnstpSeMngPutRequestDto }) =>
|
|
cnstpSeMngService.update(cnstpSeCd, body),
|
|
onSuccess: (_data, { cnstpSeCd }) => {
|
|
queryClient.invalidateQueries({ queryKey: cnstpSeMngBaseKey });
|
|
queryClient.invalidateQueries({
|
|
queryKey: [...cnstpSeMngBaseKey, "findById", cnstpSeCd],
|
|
});
|
|
},
|
|
});
|
|
}
|
|
|
|
export function useDeleteCnstpSeMng() {
|
|
const queryClient = useQueryClient();
|
|
|
|
return useMutation({
|
|
mutationFn: (cnstpSeCd: string) => cnstpSeMngService.delete(cnstpSeCd),
|
|
onSuccess: () => {
|
|
queryClient.invalidateQueries({ queryKey: cnstpSeMngBaseKey });
|
|
},
|
|
});
|
|
}
|