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