Files
Ferme/frontend/services/reception-type.ts

24 lines
709 B
TypeScript

import { useApi } from '~/composables/useApi'
import type { ReceptionTypeData } from '~/services/dto/reception-type-data'
export type ReceptionTypeListResponse =
| ReceptionTypeData[]
| { 'hydra:member'?: ReceptionTypeData[] }
export async function getReceptionTypeList(): Promise<ReceptionTypeData[]> {
const api = useApi()
const response = await api.get<ReceptionTypeListResponse>('reception_types', {}, {
toastErrorKey: 'errors.receptionType.list'
})
if (Array.isArray(response)) {
return response
}
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
return response['hydra:member']
}
return []
}