Some checks failed
Auto Tag Develop / tag (push) Has been cancelled
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | #326 | Admin modification creation client | ## 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: #25 Reviewed-by: Autin <tristan@yuno.malio.fr> Co-authored-by: Matteo <matteo@yuno.malio.fr> Co-committed-by: Matteo <matteo@yuno.malio.fr>
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { useApi } from "~/composables/useApi"
|
|
import type { CustomerData, CustomerPayload } from "~/services/dto/customer-data"
|
|
|
|
export type CustomerListResponse =
|
|
| CustomerData[]
|
|
| { "hydra:member"?: CustomerData[] }
|
|
|
|
export async function getCustomerList(): Promise<CustomerData[]> {
|
|
const api = useApi()
|
|
const response = await api.get<CustomerListResponse>("customers", {}, {
|
|
toastErrorKey: "errors.customer.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 getCustomer(id: number): Promise<CustomerData> {
|
|
const api = useApi()
|
|
return api.get<CustomerData>(`customers/${id}`, {}, {
|
|
toastErrorKey: "errors.customer.fetch",
|
|
})
|
|
}
|
|
|
|
export async function updateCustomer(id: number, payload: Partial<CustomerPayload>): Promise<CustomerData> {
|
|
const api = useApi()
|
|
return api.patch<CustomerData>(`customers/${id}`, payload, {
|
|
toastErrorKey: "errors.customer.update",
|
|
toastSuccessKey: "success.customer.update",
|
|
})
|
|
}
|
|
|
|
export async function createCustomer(payload: CustomerPayload): Promise<CustomerData> {
|
|
const api = useApi()
|
|
return api.post<CustomerData>("customers", payload, {
|
|
toastErrorKey: "errors.customer.create",
|
|
toastSuccessKey: "success.customer.create",
|
|
})
|
|
}
|
|
|