fix: align API response shapes (items instead of data), add fallbacks to prevent .length crash

This commit is contained in:
valitovgaziz
2026-06-12 02:30:57 +05:00
parent 86f37dde2d
commit 02c6cb680b
4 changed files with 7 additions and 7 deletions
@@ -71,8 +71,8 @@ onMounted(async () => {
if (user.value?.id) {
try {
const api = useApi()
const response = await api.get<{ data: typeof objects.value }>(`/objects/owner/${user.value.id}`)
objectsStore.objects = response.data
const response = await api.get<{ items: typeof objects.value }>(`/objects/owner/${user.value.id}`)
objectsStore.objects = response.items ?? []
} catch {
// ignore
}
@@ -39,7 +39,7 @@ export const useObjectsStore = defineStore('objects', {
const query = params.toString()
const response = await api.get<PaginatedResponse<TourObject>>(`/objects${query ? `?${query}` : ''}`)
this.objects = response.data
this.objects = response.items ?? []
this.total = response.total
this.page = response.page
this.totalPages = response.total_pages
@@ -82,13 +82,13 @@ export const useSearchStore = defineStore('search', {
: `/objects/search?${query}`
const response = await api.get<{
data: TourObject[]
items: TourObject[]
total: number
page: number
total_pages: number
}>(endpoint)
this.results = response.data
this.results = response.items ?? []
this.total = response.total
this.page = response.page
this.totalPages = response.total_pages
@@ -80,10 +80,10 @@ export interface SearchParams {
}
export interface PaginatedResponse<T> {
data: T[]
items: T[]
total: number
page: number
per_page: number
page_size: number
total_pages: number
}