UX-3 附件上传删除功能
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
import { apiGet, apiPost } from "./axios";
|
||||
import { apiGet, apiPost, apiDelete } from "./axios";
|
||||
|
||||
export const fetchAttachments = (studyId: string, entityType: string, entityId: string) =>
|
||||
apiGet(`/api/v1/studies/${studyId}/${entityType}/${entityId}/attachments`);
|
||||
|
||||
export const uploadAttachment = (studyId: string, entityType: string, entityId: string, file: File) => {
|
||||
export const uploadAttachment = (
|
||||
studyId: string,
|
||||
entityType: string,
|
||||
entityId: string,
|
||||
file: File,
|
||||
options?: Record<string, any>
|
||||
) => {
|
||||
const formData = new FormData();
|
||||
formData.append("file", file);
|
||||
return apiPost(`/api/v1/studies/${studyId}/${entityType}/${entityId}/attachments`, formData, {
|
||||
headers: { "Content-Type": "multipart/form-data" },
|
||||
...options,
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteAttachment = (attachmentId: string) => apiDelete(`/api/v1/attachments/${attachmentId}`);
|
||||
|
||||
@@ -52,5 +52,7 @@ export const apiPost = <T = unknown>(url: string, data?: unknown, config?: Axios
|
||||
instance.post<T>(url, data, config);
|
||||
export const apiPatch = <T = unknown>(url: string, data?: unknown, config?: AxiosRequestConfig) =>
|
||||
instance.patch<T>(url, data, config);
|
||||
export const apiDelete = <T = unknown>(url: string, config?: AxiosRequestConfig) =>
|
||||
instance.delete<T>(url, config);
|
||||
|
||||
export default instance;
|
||||
|
||||
Reference in New Issue
Block a user