31 lines
706 B
TypeScript
31 lines
706 B
TypeScript
// imports
|
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
|
import type { ComputedRef } from "vue";
|
|
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
|
|
|
|
// types
|
|
|
|
export type GetOrderResponse = OrderDetail;
|
|
|
|
const useGetOrder = (id: ComputedRef<string>) => {
|
|
// state
|
|
|
|
const { $axios: axios } = useNuxtApp();
|
|
|
|
// methods
|
|
|
|
const handleGetOrder = async () => {
|
|
const { data } = await axios.get<GetOrderResponse>(`${API_ENDPOINTS.orders.get_one}/${id.value}`);
|
|
return data;
|
|
};
|
|
|
|
return useQuery({
|
|
queryKey: [QUERY_KEYS.order, id],
|
|
queryFn: () => handleGetOrder(),
|
|
enabled: computed(() => !!id.value),
|
|
});
|
|
};
|
|
|
|
export default useGetOrder;
|