29 lines
1.9 KiB
TypeScript
29 lines
1.9 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { ListArguments } from '@/types/listRequest'
|
|
|
|
const fetchGraphQlLivingSpaceList = async (buildID: string, params: ListArguments): Promise<any> => {
|
|
console.log('Fetching test data from local API');
|
|
const { limit, skip, sort, filters } = params;
|
|
try {
|
|
const res = await fetch('/api/living-space/list', { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify({ buildID, limit, skip, sort, filters }) });
|
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }; const data = await res.json();
|
|
return { data: data.data, totalCount: data.totalCount }
|
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
|
};
|
|
|
|
const fetchGraphQlLivingSpaceDetail = async (uuid: string, buildID: string): Promise<any> => {
|
|
console.log('Fetching test data from local API');
|
|
try {
|
|
const res = await fetch(`/api/living-space/detail`, { method: 'POST', cache: 'no-store', credentials: "include", body: JSON.stringify({ uuid, buildID }) });
|
|
if (!res.ok) { const errorText = await res.text(); console.error('Test data API error:', errorText); throw new Error(`API error: ${res.status} ${res.statusText}`) }; const data = await res.json();
|
|
return { data: data.data }
|
|
} catch (error) { console.error('Error fetching test data:', error); throw error }
|
|
};
|
|
|
|
export function useGraphQlLivingSpaceList(buildID: string, params: ListArguments) {
|
|
return useQuery({ queryKey: ['graphql-living-space-list', buildID, params], queryFn: () => fetchGraphQlLivingSpaceList(buildID, params) })
|
|
}
|
|
|
|
export function useGraphQlLivingSpaceDetail(uuid: string, buildID: string) {
|
|
return useQuery({ queryKey: ['graphql-living-space-detail', uuid, buildID], queryFn: () => fetchGraphQlLivingSpaceDetail(uuid, buildID) })
|
|
} |