25 lines
699 B
TypeScript
25 lines
699 B
TypeScript
import { useApi } from '~/composables/useApi'
|
|
import type {ShipmentTypeData} from "~/services/dto/shipment-type-data";
|
|
|
|
export type ShipmentTypeListResponse =
|
|
| ShipmentTypeData[]
|
|
| { 'hydra:member'?: ShipmentTypeData[] }
|
|
|
|
|
|
export async function getShipmentTypeList(): Promise<ShipmentTypeData[]> {
|
|
const api = useApi()
|
|
const response = await api.get<ShipmentTypeListResponse>('shipment_types', {}, {
|
|
toastErrorKey: 'errors.shipmentType.list'
|
|
})
|
|
|
|
if (Array.isArray(response)) {
|
|
return response
|
|
}
|
|
|
|
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
|
return response['hydra:member']
|
|
}
|
|
|
|
return []
|
|
}
|