diff --git a/frontend/composables/api/tickets/useGetTicket.ts b/frontend/composables/api/tickets/useGetTicket.ts new file mode 100644 index 0000000..586af6b --- /dev/null +++ b/frontend/composables/api/tickets/useGetTicket.ts @@ -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) => { + // state + + const { $axios: axios } = useNuxtApp(); + + // methods + + const handleGetTicket = async (id: string | number | undefined) => { + const { data } = await axios.get( + `${API_ENDPOINTS.tickets.get_one}/${id}` + ); + return data; + }; + + return useQuery({ + queryKey: [QUERY_KEYS.ticket, id], + queryFn: () => handleGetTicket(id.value), + }); +}; + +export default useGetTicket;