Files
hossein-por-shop/frontend/composables/api/orders/useGetCartOrders.ts
T
2025-06-04 19:12:54 +03:30

33 lines
713 B
TypeScript

// imports
import { useQuery } from "@tanstack/vue-query";
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
import { useAuth } from "../auth/useAuth";
// types
export type GetCartOrdersResponse = Cart;
const useGetCartOrders = () => {
// state
const { $axios: axios } = useNuxtApp();
const { token } = useAuth();
// methods
const handleGetCartOrders = async () => {
const { data } = await axios.get<GetCartOrdersResponse>(API_ENDPOINTS.orders.cart.get_all);
return data;
};
return useQuery({
queryKey: [QUERY_KEYS.cart],
enabled: !!token.value,
queryFn: () => handleGetCartOrders(),
});
};
export default useGetCartOrders;