33 lines
811 B
TypeScript
33 lines
811 B
TypeScript
// imports
|
|
|
|
import { useMutation } from "@tanstack/vue-query";
|
|
import axios from "~/configs/axios.config";
|
|
import { API_ENDPOINTS } from "~/constants";
|
|
|
|
// types
|
|
|
|
export type MoveDocRequest = {
|
|
itemsToMove: number[] | string[],
|
|
parent: number | string
|
|
};
|
|
|
|
// methods
|
|
|
|
export const handleMoveDoc = async ({ itemsToMove, parent }: MoveDocRequest) => {
|
|
const apiUrl = `${API_ENDPOINTS.branch.moveDoc}?new_parent_id=${parent}&${itemsToMove.map(i => `patch_list=${i}&`)}`
|
|
const splittedUrl = apiUrl.split("");
|
|
splittedUrl.pop()
|
|
|
|
await axios.patch<MoveDocRequest>(splittedUrl.join("").replaceAll(",", ""));
|
|
};
|
|
|
|
// composable
|
|
|
|
const useMoveDoc = () => {
|
|
return useMutation({
|
|
mutationFn: (variables: MoveDocRequest) => handleMoveDoc(variables)
|
|
});
|
|
};
|
|
|
|
export default useMoveDoc;
|