Files
hossein-por-shop/frontend/composables/api/tickets/useGetTicket.ts
T
2025-02-27 20:49:09 +03:30

31 lines
688 B
TypeScript

// imports
import { useQuery } from "@tanstack/vue-query";
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
// types
export type GetTicketResponse = Ticket;
const useGetTicket = (id: ComputedRef<number | string>) => {
// state
const { $axios: axios } = useNuxtApp();
// methods
const handleGetTicket = async (id: string | number | undefined) => {
const { data } = await axios.get<GetTicketResponse>(
`${API_ENDPOINTS.tickets.get_one}/${id}`
);
return data;
};
return useQuery({
queryKey: [QUERY_KEYS.ticket, id],
queryFn: () => handleGetTicket(id.value),
});
};
export default useGetTicket;