90c2cfc665
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #317 | Création d'une page d'administration : modification/création d'un transporteur | ## 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/18 Reviewed-by: Autin <tristan@yuno.malio.fr> Co-authored-by: sroy <sebastien@yuno.malio.fr> Co-committed-by: sroy <sebastien@yuno.malio.fr>
47 lines
1.3 KiB
TypeScript
47 lines
1.3 KiB
TypeScript
import { useApi } from '~/composables/useApi'
|
|
import type {CarrierData, CarrierPayload} from "~/services/dto/carrier-data";
|
|
|
|
export type CarrierListResponse =
|
|
| CarrierData[]
|
|
| { 'hydra:member'?: CarrierData[] }
|
|
|
|
export async function getCarrierList(): Promise<CarrierData[]> {
|
|
const api = useApi()
|
|
const response = await api.get<CarrierListResponse>('carriers', {}, {
|
|
toastErrorKey: 'errors.carrier.list'
|
|
})
|
|
|
|
if (Array.isArray(response)) {
|
|
return response
|
|
}
|
|
|
|
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
|
return response['hydra:member']
|
|
}
|
|
|
|
return []
|
|
}
|
|
|
|
export async function getCarrier(id: number) {
|
|
const api = useApi()
|
|
return api.get<CarrierData>(`carriers/${id}`, {}, {
|
|
toastErrorKey: 'errors.carrier.fetch'
|
|
})
|
|
}
|
|
|
|
export async function updateCarrier(id: number, payload: CarrierPayload) {
|
|
const api = useApi()
|
|
return api.patch<CarrierData>(`carriers/${id}`, payload, {
|
|
toastErrorKey: 'errors.carrier.update',
|
|
toastSuccessKey: 'success.carrier.update'
|
|
})
|
|
}
|
|
|
|
export async function createCarrier(payload: CarrierPayload = {}) {
|
|
const api = useApi()
|
|
return api.post<CarrierData>('carriers', payload, {
|
|
toastErrorKey: 'errors.carrier.create',
|
|
toastSuccessKey: 'success.carrier.update'
|
|
})
|
|
}
|