Bovins Admin (!29)
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: https://gitea.malio.fr/MALIO-DEV/Ferme/pulls/29 Reviewed-by: Autin <tristan@yuno.malio.fr> Co-authored-by: Matteo <matteo@yuno.malio.fr> Co-committed-by: Matteo <matteo@yuno.malio.fr>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { useApi } from '~/composables/useApi'
|
||||
import type {BovineTypeData} from "~/services/dto/bovine-type-data";
|
||||
import type { BovineTypeData, BovinPayload } from "~/services/dto/bovine-type-data";
|
||||
|
||||
export type BovineTypeListResponse =
|
||||
| BovineTypeData[]
|
||||
@@ -12,12 +12,41 @@ export async function getBovineTypeList(): Promise<BovineTypeData[]> {
|
||||
})
|
||||
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
return response.map(mapToBovineTypeData)
|
||||
}
|
||||
|
||||
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||
return 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}`)
|
||||
return mapToBovineTypeData(response)
|
||||
}
|
||||
|
||||
export async function createBovin(payload: BovinPayload = {}): Promise<BovineTypeData> {
|
||||
const api = useApi()
|
||||
const response = await api.post<BovineTypeData>('bovine_types', toBovineTypePayload(payload))
|
||||
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))
|
||||
return mapToBovineTypeData(response)
|
||||
}
|
||||
|
||||
const mapToBovineTypeData = (item: BovineTypeData): BovineTypeData => ({
|
||||
id: item.id,
|
||||
label: item.label,
|
||||
code: item.code
|
||||
})
|
||||
|
||||
const toBovineTypePayload = (payload: BovinPayload): Partial<BovineTypeData> => ({
|
||||
label: payload.label ?? undefined,
|
||||
code: payload.code ?? undefined
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user