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