From 363fca87217b5ab3935458888867470a5c13b475 Mon Sep 17 00:00:00 2001 From: Mamalizz Date: Sun, 23 Feb 2025 23:24:54 +0330 Subject: [PATCH] added use upload attachment --- .../api/tickets/useUploadAttachment.ts | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 frontend/composables/api/tickets/useUploadAttachment.ts 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;