26 lines
749 B
TypeScript
26 lines
749 B
TypeScript
import { useApi } from '~/composables/useApi'
|
|
|
|
export type BovinDataResponse =
|
|
| IdentificationBovinData
|
|
| { 'hydra:member'?: IdentificationBovinData }
|
|
|
|
export async function getBovinData(
|
|
nationalNumber: string
|
|
): Promise<IdentificationBovinData | null> {
|
|
const api = useApi()
|
|
const response = await api.get<BovinDataResponse>(
|
|
`bovins/${nationalNumber}/identification`,
|
|
{},
|
|
{ toastErrorKey: 'errors.building.list' }
|
|
)
|
|
|
|
if (response && typeof response === 'object') {
|
|
// direct item
|
|
if (!('hydra:member' in response)) return response as IdentificationBovinData
|
|
// hydra format
|
|
if (response['hydra:member']) return response['hydra:member']
|
|
}
|
|
|
|
return null
|
|
}
|