34 lines
730 B
TypeScript
34 lines
730 B
TypeScript
// imports
|
|
|
|
import { useQuery } from "@tanstack/vue-query";
|
|
import axios from "~/configs/axios.config";
|
|
import { API_ENDPOINTS, QUERY_KEYS } from "~/constants";
|
|
|
|
// types
|
|
|
|
export type GetDocResponse = DocumentStructure;
|
|
|
|
// methods
|
|
|
|
export const handleGetDoc = async (id : string | undefined) => {
|
|
const { data } = await axios.get<GetDocResponse>(`${API_ENDPOINTS.branch.getDoc}/${id}`);
|
|
return data;
|
|
};
|
|
|
|
// composable
|
|
|
|
const useGetDoc = (id: ComputedRef<string | undefined>) => {
|
|
|
|
const enabled = computed(() => {
|
|
return !!id.value
|
|
});
|
|
|
|
return useQuery({
|
|
enabled,
|
|
queryKey: [QUERY_KEYS.document, id],
|
|
queryFn: () => handleGetDoc(id.value)
|
|
});
|
|
};
|
|
|
|
export default useGetDoc;
|