feat: Добавлен API для файлов приема

This commit is contained in:
Андрей Дувакин 2025-06-03 22:48:50 +05:00
parent eb4890e97b
commit 6cf3238ad4

View File

@ -0,0 +1,55 @@
import { createApi } from "@reduxjs/toolkit/query/react";
import { baseQueryWithAuth } from "./baseQuery.js";
export const appointmentFilesApi = createApi({
reducerPath: 'appointmentFilesApi',
baseQuery: baseQueryWithAuth,
tagTypes: ['AppointmentFile'],
endpoints: (builder) => ({
getAppointmentFiles: builder.query({
query: (appointmentId) => `/appointment-files/${appointmentId}/`,
providesTags: ['AppointmentFile'],
refetchOnMountOrArgChange: 5,
}),
downloadAppointmentFile: builder.query({
query: (fileId) => ({
url: `/appointment-files/${fileId}/file`,
responseHandler: async (response) => {
const blob = await response.blob();
const contentDisposition = response.headers.get('content-disposition');
const filename = contentDisposition
? contentDisposition.match(/filename="(.+)"/)?.[1] || `file_${fileId}`
: `file_${fileId}`;
return { blob, filename };
},
cache: 'no-cache',
}),
}),
uploadAppointmentFile: builder.mutation({
query: ({ appointmentId, file }) => {
const formData = new FormData();
formData.append('file', file);
return {
url: `/appointment-files/${appointmentId}/upload`,
method: 'POST',
body: formData,
};
},
invalidatesTags: ['AppointmentFile'],
}),
deleteAppointmentFile: builder.mutation({
query: (fileId) => ({
url: `/appointment-files/${fileId}/`,
method: 'DELETE',
}),
invalidatesTags: ['AppointmentFile'],
}),
}),
});
export const {
useGetAppointmentFilesQuery,
useDownloadAppointmentFileQuery,
useUploadAppointmentFileMutation,
useDeleteAppointmentFileMutation,
} = appointmentFilesApi;