30 lines
711 B
TypeScript
30 lines
711 B
TypeScript
// imports
|
|
|
|
import { useMutation } from "@tanstack/vue-query";
|
|
import axios from "~/configs/axios.config";
|
|
import { API_ENDPOINTS } from "~/constants";
|
|
|
|
// types
|
|
|
|
export type EditDocRequest = {
|
|
id: number
|
|
};
|
|
|
|
// methods
|
|
|
|
export const handleEditDoc = async ({ id, name }: { id: string | undefined, name: string | undefined }) => {
|
|
await axios.patch<EditDocRequest>(`${API_ENDPOINTS.branch.getDoc}/${id}`, { name });
|
|
};
|
|
|
|
// composable
|
|
|
|
const useEditDoc = (id: Ref<string | undefined>) => {
|
|
return useMutation({
|
|
mutationFn: ({ name }: { name: Ref<string | undefined> }) => {
|
|
return handleEditDoc({ id: id.value, name: name.value });
|
|
}
|
|
});
|
|
};
|
|
|
|
export default useEditDoc;
|