Create get product composable

This commit is contained in:
marzban-dev
2025-01-13 21:13:40 +03:30
parent 6f3fba9b8e
commit 71f4bebe94
@@ -0,0 +1,29 @@
// imports
import { useQuery } from "@tanstack/vue-query";
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
// types
export type GetProductResponse = Product;
const useGetDoc = (id: string | number | undefined) => {
// state
const { $axios: axios } = useNuxtApp();
// methods
const handleGetProduct = async (id: string | number | undefined) => {
const { data } = await axios.get<GetProductResponse>(`${API_ENDPOINTS.product.get}/${id}`);
return data;
};
return useQuery({
queryKey: [QUERY_KEYS.product, id],
queryFn: () => handleGetProduct(id)
});
};
export default useGetDoc;