diff --git a/frontend/composables/api/product/useGetProduct.ts b/frontend/composables/api/product/useGetProduct.ts new file mode 100644 index 0000000..bed6794 --- /dev/null +++ b/frontend/composables/api/product/useGetProduct.ts @@ -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(`${API_ENDPOINTS.product.get}/${id}`); + return data; + }; + + return useQuery({ + queryKey: [QUERY_KEYS.product, id], + queryFn: () => handleGetProduct(id) + }); +}; + +export default useGetDoc;