Files
tripwithbonus/frontend/lib/search/fetchRoutes.ts
2025-05-23 14:49:12 +03:00

24 lines
679 B
TypeScript

import { SearchResponse } from '@/app/types'
// получаем все предложения по выбранному owner_type
export async function fetchRoutes(category: string, query: string = ''): Promise<SearchResponse> {
try {
const response = await fetch(
`${process.env.NEXT_PUBLIC_API_URL}/search/${category}/${query ? `?${query}` : ''}`,
{
cache: 'no-store',
}
)
if (!response.ok) {
throw new Error('Failed to fetch search results')
}
const data = await response.json()
return data
} catch (error) {
console.error('Error fetching search results:', error)
return { results: [], count: 0 }
}
}