diff --git a/frontend/composables/api/tickets/useUploadAttachment.ts b/frontend/composables/api/tickets/useUploadAttachment.ts new file mode 100644 index 0000000..46ad07d --- /dev/null +++ b/frontend/composables/api/tickets/useUploadAttachment.ts @@ -0,0 +1,52 @@ +// 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( + 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;