From 71f4bebe94ee352383d4595289b11c3759c29cb3 Mon Sep 17 00:00:00 2001 From: marzban-dev Date: Mon, 13 Jan 2025 21:13:40 +0330 Subject: [PATCH] Create get product composable --- .../composables/api/product/useGetProduct.ts | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 frontend/composables/api/product/useGetProduct.ts 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;