rule engine UI, services and API integration

This commit is contained in:
hagiye
2026-06-01 16:01:51 +03:00
45 changed files with 6785 additions and 78 deletions

View File

@@ -0,0 +1,97 @@
import { api as client } from "../auth/http";
import { unwrap } from "@/utils/endpoint";
import { URL_CONSTANTS } from "@/constants/URLS";
import type { ApiResponse } from "@/types/apiResponse";
import type {
CreateDropdownOptionDto,
CreateDropdownSettingDto,
DropdownOption,
DropdownSetting,
UpdateDropdownOptionDto,
UpdateDropdownSettingDto,
} from "@/types/dropdownSettings";
const BASE = URL_CONSTANTS.DROPDOWN_SETTINGS.BASE;
export const dropdownSettingsService = {
list: async (): Promise<DropdownSetting[]> => {
const response = await client.get<ApiResponse<DropdownSetting[]>>(BASE);
return unwrap(response.data);
},
getById: async (id: string): Promise<DropdownSetting> => {
const response = await client.get<ApiResponse<DropdownSetting>>(
URL_CONSTANTS.DROPDOWN_SETTINGS.BY_ID(id),
);
return unwrap(response.data);
},
getByCode: async (code: string): Promise<DropdownSetting> => {
const response = await client.get<ApiResponse<DropdownSetting>>(
URL_CONSTANTS.DROPDOWN_SETTINGS.BY_CODE(code),
);
return unwrap(response.data);
},
create: async (
payload: CreateDropdownSettingDto,
): Promise<DropdownSetting> => {
const response = await client.post<ApiResponse<DropdownSetting>>(
BASE,
payload,
);
return unwrap(response.data);
},
update: async (
id: string,
payload: UpdateDropdownSettingDto,
): Promise<DropdownSetting> => {
const response = await client.patch<ApiResponse<DropdownSetting>>(
URL_CONSTANTS.DROPDOWN_SETTINGS.BY_ID(id),
payload,
);
return unwrap(response.data);
},
remove: async (id: string): Promise<void> => {
await client.delete(URL_CONSTANTS.DROPDOWN_SETTINGS.BY_ID(id));
},
replaceOptions: async (
id: string,
options: CreateDropdownOptionDto[],
): Promise<DropdownOption[]> => {
const response = await client.put<ApiResponse<DropdownOption[]>>(
URL_CONSTANTS.DROPDOWN_SETTINGS.OPTIONS(id),
options,
);
return unwrap(response.data);
},
addOption: async (
id: string,
payload: CreateDropdownOptionDto,
): Promise<DropdownOption> => {
const response = await client.post<ApiResponse<DropdownOption>>(
URL_CONSTANTS.DROPDOWN_SETTINGS.OPTIONS(id),
payload,
);
return unwrap(response.data);
},
updateOption: async (
optionId: string,
payload: UpdateDropdownOptionDto,
): Promise<DropdownOption> => {
const response = await client.patch<ApiResponse<DropdownOption>>(
URL_CONSTANTS.DROPDOWN_SETTINGS.OPTION_BY_ID(optionId),
payload,
);
return unwrap(response.data);
},
removeOption: async (optionId: string): Promise<void> => {
await client.delete(URL_CONSTANTS.DROPDOWN_SETTINGS.OPTION_BY_ID(optionId));
},
};

View File

@@ -0,0 +1,137 @@
import { api as client } from "../auth/http";
import type {
CreateFileUploadFieldDto,
CreateFileUploadSettingDto,
FileUploadField,
FileUploadSetting,
UpdateFileUploadFieldDto,
UpdateFileUploadSettingDto,
} from "@/types/fileUploadSettings";
import { URL_CONSTANTS } from "@/constants/URLS";
import { QUERY_KEYS } from "@/constants/TANSTACK_QUEY_KEY";
import { ApiResponse } from "@/types/apiResponse";
import { endpoint, unwrap } from "@/utils/endpoint";
const BASE = "/file-upload-settings";
// 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 client.get<ApiResponse<FileUploadSetting[]>>(BASE);
return unwrap(response.data);
},
// GET /file-upload-settings/:id
getById: async (id: string): Promise<FileUploadSetting> => {
const response = await client.get<ApiResponse<FileUploadSetting>>(
`${BASE}/${id}`,
);
return unwrap(response.data);
},
// GET /file-upload-settings/by-code/:code
getByCode: async (code: string): Promise<FileUploadSetting> => {
const response = await client.get<ApiResponse<FileUploadSetting>>(
`${BASE}/by-code/${encodeURIComponent(code)}`,
);
return unwrap(response.data);
},
// POST /file-upload-settings
create: async (
payload: CreateFileUploadSettingDto,
): Promise<FileUploadSetting> => {
const response = await client.post<ApiResponse<FileUploadSetting>>(
BASE,
payload,
);
return unwrap(response.data);
},
// PATCH /file-upload-settings/:id
update: async (
id: string,
payload: UpdateFileUploadSettingDto,
): Promise<FileUploadSetting> => {
const response = await client.patch<ApiResponse<FileUploadSetting>>(
`${BASE}/${id}`,
payload,
);
return unwrap(response.data);
},
// DELETE /file-upload-settings/:id
remove: async (id: string): Promise<void> => {
await client.delete(`${BASE}/${id}`);
},
// PUT /file-upload-settings/:id/fields
replaceFields: async (
id: string,
fields: CreateFileUploadFieldDto[],
): Promise<FileUploadField[]> => {
const response = await client.put<ApiResponse<FileUploadField[]>>(
`${BASE}/${id}/fields`,
fields,
);
return unwrap(response.data);
},
// POST /file-upload-settings/:id/fields
addField: async (
id: string,
payload: CreateFileUploadFieldDto,
): Promise<FileUploadField> => {
const response = await client.post<ApiResponse<FileUploadField>>(
`${BASE}/${id}/fields`,
payload,
);
return unwrap(response.data);
},
// PATCH /file-upload-settings/fields/:fieldId
updateField: async (
fieldId: string,
payload: UpdateFileUploadFieldDto,
): Promise<FileUploadField> => {
const response = await client.patch<ApiResponse<FileUploadField>>(
`${BASE}/fields/${fieldId}`,
payload,
);
return unwrap(response.data);
},
// DELETE /file-upload-settings/fields/:fieldId
removeField: async (fieldId: string): Promise<void> => {
await client.delete(`${BASE}/fields/${fieldId}`);
},
};
export const getFileUploadSettingByCode = endpoint<string, FileUploadSetting>(
QUERY_KEYS.FILES.FILE_UPLOAD_SETTINGS,
QUERY_KEYS.FILES.BY_CODE,
(code: any) =>
client
.get<
ApiResponse<FileUploadSetting>
>(`${URL_CONSTANTS.FILES.FILE_UPLOAD_SETTINGS_BY_CODE}/${code}`)
.then((res: any) => res.data.data),
);

View File

@@ -1,5 +1,25 @@
// import { CargoType } from "@edr-freight-web/types";
// import { api as client } from "@edr-freight-web/utils/api/";
import { api as client } from "../../auth/http";
import { URL_CONSTANTS } from "../../constants/URLS";
export const createCargoType = (data: any) => {
return client.post(URL_CONSTANTS.RULE_ENGINE.CARGO_TYPES, { data });
};
export const getCargoType = () => {
return client.get(URL_CONSTANTS.RULE_ENGINE.CARGO_TYPES);
};
export const getCargoTypeById = (id: string) => {
return client.get(`${URL_CONSTANTS.RULE_ENGINE.CARGO_TYPES}/${id}`);
};
export const updateCargoType = (id: string, data: any) => {
return client.put(`${URL_CONSTANTS.RULE_ENGINE.CARGO_TYPES}/${id}`, { data });
};
export const deleteCargoType = (id: string) => {
return client.delete(`${URL_CONSTANTS.RULE_ENGINE.CARGO_TYPES}/${id}`);
};

View File

@@ -0,0 +1,19 @@
import { api as client } from "../../auth/http";
import { URL_CONSTANTS } from "../../constants/URLS";
export const createContainerType = (data: any) =>
client.post(URL_CONSTANTS.RULE_ENGINE.CONTAINER_TYPES, { data });
export const getContainerTypes = () =>
client.get(URL_CONSTANTS.RULE_ENGINE.CONTAINER_TYPES);
export const getContainerTypeById = (id: string) =>
client.get(URL_CONSTANTS.RULE_ENGINE.CONTAINER_TYPE_BY_ID(id));
export const updateContainerType = (id: string, data: any) =>
client.put(URL_CONSTANTS.RULE_ENGINE.CONTAINER_TYPE_BY_ID(id), { data });
export const deleteContainerType = (id: string) =>
client.delete(URL_CONSTANTS.RULE_ENGINE.CONTAINER_TYPE_BY_ID(id));