Files
2025-02-23 23:24:54 +03:30

53 lines
1008 B
TypeScript

// imports
import { useMutation } from "@tanstack/vue-query";
import { API_ENDPOINTS } from "~/constants";
// types
export type UploadAttachmentRequest = {
file: File;
};
export type UploadAttachmentResponse = {
id: number;
file_link: string;
date: string;
size: number;
name: string;
};
// methods
export const handleUploadAttachment = async ({
file,
}: UploadAttachmentRequest) => {
// state
const { $axios: axios } = useNuxtApp();
const { data } = await axios.post<UploadAttachmentResponse>(
API_ENDPOINTS.tickets.upload_attachment,
{
file,
},
{
headers: {
"Content-Type": "multipart/form-data",
},
}
);
return data;
};
// composable
const useUploadAttachment = () => {
return useMutation({
mutationFn: (data: UploadAttachmentRequest) =>
handleUploadAttachment({ file: data.file }),
});
};
export default useUploadAttachment;