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 { const api = useApi() const response = await api.get("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 { const api = useApi() return api.get(`customers/${id}`, {}, { toastErrorKey: "errors.customer.fetch", }) } export async function updateCustomer(id: number, payload: Partial): Promise { const api = useApi() return api.patch(`customers/${id}`, payload, { toastErrorKey: "errors.customer.update", toastSuccessKey: "success.customer.update", }) } export async function createCustomer(payload: CustomerPayload): Promise { const api = useApi() return api.post("customers", payload, { toastErrorKey: "errors.customer.create", toastSuccessKey: "success.customer.create", }) }