260617_01_ENH: 배정 테스트를 위해 개발 중도 커밋
This commit is contained in:
56
src/query/monitoring.ts
Normal file
56
src/query/monitoring.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
"use client";
|
||||
|
||||
import {useMutation, useQuery, useQueryClient} from "@tanstack/react-query";
|
||||
import {nextApi} from "@/lib/http-client";
|
||||
import {qk} from "@/query/key/keys";
|
||||
import {MonitoringGpsRequest, PerformanceMonitoringVisit} from "@/types/gwcf";
|
||||
|
||||
export function useSaveDepartureMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, gps}: {performanceId: number; gps: MonitoringGpsRequest}) =>
|
||||
nextApi.post<PerformanceMonitoringVisit>(`/monitoring/visit/departure/${performanceId}`, gps),
|
||||
onSuccess: (_res, {performanceId}) => {
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useSaveArrivalMutation() {
|
||||
const qc = useQueryClient();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, gps, files}: {performanceId: number; gps: MonitoringGpsRequest; files?: File[]}) => {
|
||||
const formData = new FormData();
|
||||
formData.append("gps", new Blob([JSON.stringify(gps)], {type: "application/json"}));
|
||||
files?.forEach((file) => formData.append("files", file, file.name));
|
||||
return nextApi.postForm<PerformanceMonitoringVisit>(`/monitoring/visit/arrival/${performanceId}`, formData);
|
||||
},
|
||||
onSuccess: (_res, {performanceId}) => {
|
||||
qc.invalidateQueries({ queryKey: qk.performance(performanceId) });
|
||||
qc.invalidateQueries({ queryKey: ["performance", "list"] });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useMonitoringEvidenceQuery(performanceId: number, userId: string, enabled: boolean = true) {
|
||||
return useQuery({
|
||||
queryKey: qk.monitoringEvidence(performanceId, userId),
|
||||
queryFn: () => nextApi.get<PerformanceMonitoringVisit[]>(`/monitoring/visit/evidence/${performanceId}/${encodeURIComponent(userId)}`),
|
||||
enabled: enabled && performanceId > 0 && Boolean(userId),
|
||||
staleTime: 0,
|
||||
refetchOnMount: "always",
|
||||
});
|
||||
}
|
||||
|
||||
export function useDownloadEvidenceZipMutation() {
|
||||
return useMutation({
|
||||
mutationFn: ({performanceId, userId}: {performanceId: number; userId: string}) =>
|
||||
nextApi.get<ArrayBuffer>(
|
||||
`/monitoring/visit/evidence/zip/${performanceId}/${encodeURIComponent(userId)}`,
|
||||
{expectBinary: true}
|
||||
),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user