Ajoute un champ display (défaut false) sur BovineType : seuls les types activés par un admin apparaissent à la sélection des races en réception. Les types créés par la synchro inventaire restent masqués par défaut. - Affichage des races en grille 4 colonnes (création réception) - Édition réception : conserve les types déjà saisis même masqués - Admin : badge "Affiché en réception" + checkbox dans le formulaire Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
67 lines
2.3 KiB
TypeScript
67 lines
2.3 KiB
TypeScript
import { useApi } from '~/composables/useApi'
|
|
import type { BovineTypeData, BovinPayload } from "~/services/dto/bovine-type-data";
|
|
|
|
export type BovineTypeListResponse =
|
|
| BovineTypeData[]
|
|
| { 'hydra:member'?: BovineTypeData[] }
|
|
|
|
export async function getBovineTypeList(filters: { display?: boolean } = {}): Promise<BovineTypeData[]> {
|
|
const api = useApi()
|
|
const query: Record<string, string> = {}
|
|
if (filters.display !== undefined) {
|
|
query.display = filters.display ? 'true' : 'false'
|
|
}
|
|
const response = await api.get<BovineTypeListResponse>('bovine_types', query, {
|
|
toastErrorKey: 'errors.bovin.list'
|
|
})
|
|
|
|
if (Array.isArray(response)) {
|
|
return response.map(mapToBovineTypeData)
|
|
}
|
|
|
|
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
|
return response['hydra:member'].map(mapToBovineTypeData)
|
|
}
|
|
|
|
return []
|
|
}
|
|
|
|
export async function getBovin(id: number): Promise<BovineTypeData> {
|
|
const api = useApi()
|
|
const response = await api.get<BovineTypeData>(`bovine_types/${id}`, {}, {
|
|
toastErrorKey: 'errors.bovin.fetch'
|
|
})
|
|
return mapToBovineTypeData(response)
|
|
}
|
|
|
|
export async function createBovin(payload: BovinPayload = {}): Promise<BovineTypeData> {
|
|
const api = useApi()
|
|
const response = await api.post<BovineTypeData>('bovine_types', toBovineTypePayload(payload), {
|
|
toastErrorKey: 'errors.bovin.create',
|
|
toastSuccessKey: 'success.bovin.create'
|
|
})
|
|
return mapToBovineTypeData(response)
|
|
}
|
|
|
|
export async function updateBovin(id: number, payload: BovinPayload = {}): Promise<BovineTypeData> {
|
|
const api = useApi()
|
|
const response = await api.patch<BovineTypeData>(`bovine_types/${id}`, toBovineTypePayload(payload), {
|
|
toastErrorKey: 'errors.bovin.update',
|
|
toastSuccessKey: 'success.bovin.update'
|
|
})
|
|
return mapToBovineTypeData(response)
|
|
}
|
|
|
|
const mapToBovineTypeData = (item: BovineTypeData): BovineTypeData => ({
|
|
id: item.id,
|
|
label: item.label,
|
|
code: item.code,
|
|
display: item.display ?? false
|
|
})
|
|
|
|
const toBovineTypePayload = (payload: BovinPayload): Partial<BovineTypeData> => ({
|
|
label: payload.label ?? undefined,
|
|
code: payload.code ?? undefined,
|
|
display: payload.display ?? undefined
|
|
})
|