file upload settings

This commit is contained in:
yaschalew
2026-05-20 08:15:29 +03:00
parent 6aa8265bf5
commit 51d6df42bb
28 changed files with 2483 additions and 4 deletions

View File

@@ -0,0 +1,60 @@
import { client } from "@/utils/api";
import { AxiosRequestConfig, AxiosResponse } from "axios";
class ApiService {
async get<T = any>(
url: string,
config?: AxiosRequestConfig
): Promise<T> {
const response: AxiosResponse<T> =
await client.get(url, config);
return response.data;
}
async post<T = any>(
url: string,
data?: any,
config?: AxiosRequestConfig
): Promise<T> {
const response: AxiosResponse<T> =
await client.post(url, data, config);
return response.data;
}
async put<T = any>(
url: string,
data?: any,
config?: AxiosRequestConfig
): Promise<T> {
const response: AxiosResponse<T> =
await client.put(url, data, config);
return response.data;
}
async patch<T = any>(
url: string,
data?: any,
config?: AxiosRequestConfig
): Promise<T> {
const response: AxiosResponse<T> =
await client.patch(url, data, config);
return response.data;
}
async delete<T = any>(
url: string,
config?: AxiosRequestConfig
): Promise<T> {
const response: AxiosResponse<T> =
await client.delete(url, config);
return response.data;
}
}
export const api = new ApiService();

View File

@@ -0,0 +1,148 @@
import { api } from "./crud";
import type {
CreateFileUploadFieldDto,
CreateFileUploadSettingDto,
FileUploadField,
FileUploadSetting,
UpdateFileUploadFieldDto,
UpdateFileUploadSettingDto,
} from "@/types/fileUploadSettings";
const BASE = "/api/file-upload-settings";
/**
* Handles both:
* 1. raw payload
* 2. { data: payload }
*/
type Envelope<T> = { data: T } | T;
function unwrap<T>(payload: Envelope<T>): T {
if (
payload &&
typeof payload === "object" &&
"data" in (payload as object)
) {
return (payload as { data: T }).data;
}
return payload as T;
}
export const fileUploadSettingsService = {
// GET /file-upload-settings
list: async (): Promise<FileUploadSetting[]> => {
const response =
await api.get<Envelope<FileUploadSetting[]>>(BASE);
return unwrap(response);
},
// GET /file-upload-settings/:id
getById: async (
id: string
): Promise<FileUploadSetting> => {
const response =
await api.get<Envelope<FileUploadSetting>>(
`${BASE}/${id}`
);
return unwrap(response);
},
// GET /file-upload-settings/by-code/:code
getByCode: async (
code: string
): Promise<FileUploadSetting> => {
const response =
await api.get<Envelope<FileUploadSetting>>(
`${BASE}/by-code/${encodeURIComponent(code)}`
);
return unwrap(response);
},
// POST /file-upload-settings
create: async (
payload: CreateFileUploadSettingDto
): Promise<FileUploadSetting> => {
const response =
await api.post<Envelope<FileUploadSetting>>(
BASE,
payload
);
return unwrap(response);
},
// PATCH /file-upload-settings/:id
update: async (
id: string,
payload: UpdateFileUploadSettingDto
): Promise<FileUploadSetting> => {
const response =
await api.patch<Envelope<FileUploadSetting>>(
`${BASE}/${id}`,
payload
);
return unwrap(response);
},
// DELETE /file-upload-settings/:id
remove: async (id: string): Promise<void> => {
await api.delete(`${BASE}/${id}`);
},
// PUT /file-upload-settings/:id/fields
replaceFields: async (
id: string,
fields: CreateFileUploadFieldDto[]
): Promise<FileUploadField[]> => {
const response =
await api.put<Envelope<FileUploadField[]>>(
`${BASE}/${id}/fields`,
fields
);
return unwrap(response);
},
// POST /file-upload-settings/:id/fields
addField: async (
id: string,
payload: CreateFileUploadFieldDto
): Promise<FileUploadField> => {
const response =
await api.post<Envelope<FileUploadField>>(
`${BASE}/${id}/fields`,
payload
);
return unwrap(response);
},
// PATCH /file-upload-settings/fields/:fieldId
updateField: async (
fieldId: string,
payload: UpdateFileUploadFieldDto
): Promise<FileUploadField> => {
const response =
await api.patch<Envelope<FileUploadField>>(
`${BASE}/fields/${fieldId}`,
payload
);
return unwrap(response);
},
// DELETE /file-upload-settings/fields/:fieldId
removeField: async (
fieldId: string
): Promise<void> => {
await api.delete(
`${BASE}/fields/${fieldId}`
);
},
};

View File

@@ -0,0 +1,3 @@
import { api } from "../crud";
import { URL_CONSTANTS } from "../../constants/URLS"