Files
frontend/apps/as/src/entities/sewer-bsc-plan/api/queries.ts
T

147 lines
4.7 KiB
TypeScript

import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import type {
SewerBscPlanApplySaveRequestDto,
SewerBscPlanSaveRequestDto,
} from "../model/sewer-bsc-plan-apply-payload-schema";
import type {
SewerBscPlanSearchRequestDto,
SewerBscPlanUpdateRequestDto,
} from "../model/sewer-bsc-plan-interface";
import { sewerBscPlanService } from "./sewer-bsc-plan-service";
export const sewerBscPlanKeys = {
all: ["sewer-bsc-plan"] as const,
list: () => [...sewerBscPlanKeys.all, "list"] as const,
detail: (id: string) => [...sewerBscPlanKeys.all, "detail", id] as const,
details: (id: string, chgCycl?: number) =>
chgCycl == null
? ([...sewerBscPlanKeys.all, "details", id] as const)
: ([...sewerBscPlanKeys.all, "details", id, chgCycl] as const),
};
export function useSewerBscPlanPage(params: SewerBscPlanSearchRequestDto) {
return useQuery({
queryKey: [...sewerBscPlanKeys.list(), params],
queryFn: () => sewerBscPlanService.findPage(params),
});
}
export function useSewerBscPlan(sewerBscPlanDocNo: string | null | undefined) {
return useQuery({
queryKey: sewerBscPlanKeys.detail(sewerBscPlanDocNo!),
queryFn: () => sewerBscPlanService.findById(sewerBscPlanDocNo!),
enabled: Boolean(sewerBscPlanDocNo),
});
}
export function useSewerBscPlanDetails(
sewerBscPlanDocNo: string | null | undefined,
chgCycl: number | null | undefined,
) {
return useQuery({
queryKey: sewerBscPlanKeys.details(sewerBscPlanDocNo!, chgCycl ?? undefined),
queryFn: () => sewerBscPlanService.findDetails(sewerBscPlanDocNo!, chgCycl!),
enabled: Boolean(sewerBscPlanDocNo) && chgCycl != null,
});
}
export function useSaveSewerBscPlan() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (body: SewerBscPlanSaveRequestDto) => sewerBscPlanService.save(body),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
},
});
}
export function useUpdateSewerBscPlan() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({
sewerBscPlanDocNo,
body,
}: {
sewerBscPlanDocNo: string;
body: SewerBscPlanUpdateRequestDto;
}) => sewerBscPlanService.update(sewerBscPlanDocNo, body),
onSuccess: (_data, { sewerBscPlanDocNo }) => {
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
queryClient.invalidateQueries({
queryKey: sewerBscPlanKeys.detail(sewerBscPlanDocNo),
});
},
});
}
export function useDeleteSewerBscPlan() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (sewerBscPlanDocNo: string) => sewerBscPlanService.delete(sewerBscPlanDocNo),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
},
});
}
export function useSaveApplySewerBscPlan() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: (body: SewerBscPlanApplySaveRequestDto) => sewerBscPlanService.saveApply(body),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
},
});
}
export function useSubmitSupplementSewerBscPlan() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, body }: { id: string; body: SewerBscPlanApplySaveRequestDto }) =>
sewerBscPlanService.submitSupplement(id, body),
onSuccess: (_data, { id }) => {
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
queryClient.invalidateQueries({
queryKey: sewerBscPlanKeys.detail(id),
});
},
});
}
export function useSubmitReqSupplementSewerBscPlan() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({
id,
chgCycl,
body,
}: {
id: string;
chgCycl: number;
body: SewerBscPlanApplySaveRequestDto;
}) => sewerBscPlanService.submitReqSupplement(id, chgCycl, body),
onSuccess: (_data, { id }) => {
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
queryClient.invalidateQueries({
queryKey: sewerBscPlanKeys.detail(id),
});
},
});
}
export function useTechReviewSewerBscPlan() {
const queryClient = useQueryClient();
return useMutation({
mutationFn: ({ id, body }: { id: string; body: SewerBscPlanApplySaveRequestDto }) =>
sewerBscPlanService.techReview(id, body),
onSuccess: (_data, { id }) => {
queryClient.invalidateQueries({ queryKey: sewerBscPlanKeys.all });
queryClient.invalidateQueries({
queryKey: sewerBscPlanKeys.detail(id),
});
},
});
}