24 lines
657 B
TypeScript
24 lines
657 B
TypeScript
import { useApi } from '~/composables/useApi'
|
|
import type { BuildingData } from '~/services/dto/building-data'
|
|
|
|
export type BuildingListResponse =
|
|
| BuildingData[]
|
|
| { 'hydra:member'?: BuildingData[] }
|
|
|
|
export async function getBuildingList(): Promise<BuildingData[]> {
|
|
const api = useApi()
|
|
const response = await api.get<BuildingListResponse>('buildings', {}, {
|
|
toastErrorKey: 'errors.building.list'
|
|
})
|
|
|
|
if (Array.isArray(response)) {
|
|
return response
|
|
}
|
|
|
|
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
|
return response['hydra:member']
|
|
}
|
|
|
|
return []
|
|
}
|