Files
hossein-por-shop/frontend/composables/api/branch/useGetBranch.ts
T
marzban-dev cdc0ebec26 Updated
2025-01-06 19:26:16 +03:30

55 lines
1.3 KiB
TypeScript

// 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<GetBranchResponse>(`${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<string>,
page: ComputedRef<string | undefined>,
folderId: ComputedRef<string | undefined>,
sort: ComputedRef<string | undefined>
) => {
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;