// imports import { useQuery } from "@tanstack/vue-query"; import axios from "~/configs/axios.config"; import { API_ENDPOINTS, QUERY_KEYS } from "~/constants"; import type { ComputedRef } from "vue"; // types export type GetBranchResponse = Branch; // methods export const handleGetBranch = async ( branchId: string, page: string | undefined, folderId: string | undefined, sort: string | undefined, signal: AbortSignal ) => { const { data } = await axios.get(`${API_ENDPOINTS.branch.get}/${branchId}`, { signal, params: { sort_by: sort, folder_id: folderId, offset: ((!!page ? Number(page) : 1) * 20) - 20, limit: 20 } }); return data; }; // composable const useGetBranch = ( branchId: ComputedRef, page: ComputedRef, folderId: ComputedRef, sort: ComputedRef ) => { return useQuery({ queryKey: [QUERY_KEYS.branch, branchId, page, folderId, sort], queryFn: ({ signal }) => handleGetBranch( branchId.value, page.value, folderId.value, sort.value, signal ) }); }; export default useGetBranch;