added useGetTicket

This commit is contained in:
Mamalizz
2025-02-27 20:49:09 +03:30
parent 2b8cc91630
commit 866251125a
@@ -0,0 +1,30 @@
// 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;