mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-26 18:42:49 +00:00
@@ -1,5 +1,5 @@
|
||||
import type { Freight, PaginatedResponse } from "@edr/types";
|
||||
import { endpoint } from "@/utils/api";
|
||||
import { endpoint } from "@/utils/endpoint";
|
||||
import type {
|
||||
CreateFileUploadFieldDto,
|
||||
CreateFileUploadSettingDto,
|
||||
@@ -42,10 +42,8 @@ export const api = {
|
||||
Freight.IBooking
|
||||
>("bookings", "create", (input) => bookingsService.create(input)),
|
||||
|
||||
remove: endpoint<{ id: string }, void>(
|
||||
"bookings",
|
||||
"remove",
|
||||
({ id }) => bookingsService.remove(id),
|
||||
remove: endpoint<{ id: string }, void>("bookings", "remove", ({ id }) =>
|
||||
bookingsService.remove(id),
|
||||
),
|
||||
},
|
||||
|
||||
|
||||
@@ -15,13 +15,6 @@ import { ApiResponse } from "@/types/apiResponse";
|
||||
|
||||
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 &&
|
||||
@@ -37,44 +30,36 @@ type Envelope<T> = { data: T } | T;
|
||||
export const fileUploadSettingsService = {
|
||||
// GET /file-upload-settings
|
||||
list: async (): Promise<FileUploadSetting[]> => {
|
||||
const response =
|
||||
await client.get<ApiResponse<FileUploadSetting[]>>(BASE);
|
||||
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}`
|
||||
);
|
||||
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)}`
|
||||
);
|
||||
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
|
||||
payload: CreateFileUploadSettingDto,
|
||||
): Promise<FileUploadSetting> => {
|
||||
const response =
|
||||
await client.post<ApiResponse<FileUploadSetting>>(
|
||||
BASE,
|
||||
payload
|
||||
);
|
||||
const response = await client.post<ApiResponse<FileUploadSetting>>(
|
||||
BASE,
|
||||
payload,
|
||||
);
|
||||
|
||||
return unwrap(response.data);
|
||||
},
|
||||
@@ -82,13 +67,12 @@ export const fileUploadSettingsService = {
|
||||
// PATCH /file-upload-settings/:id
|
||||
update: async (
|
||||
id: string,
|
||||
payload: UpdateFileUploadSettingDto
|
||||
payload: UpdateFileUploadSettingDto,
|
||||
): Promise<FileUploadSetting> => {
|
||||
const response =
|
||||
await client.patch<ApiResponse<FileUploadSetting>>(
|
||||
`${BASE}/${id}`,
|
||||
payload
|
||||
);
|
||||
const response = await client.patch<ApiResponse<FileUploadSetting>>(
|
||||
`${BASE}/${id}`,
|
||||
payload,
|
||||
);
|
||||
|
||||
return unwrap(response.data);
|
||||
},
|
||||
@@ -101,26 +85,24 @@ export const fileUploadSettingsService = {
|
||||
// PUT /file-upload-settings/:id/fields
|
||||
replaceFields: async (
|
||||
id: string,
|
||||
fields: CreateFileUploadFieldDto[]
|
||||
fields: CreateFileUploadFieldDto[],
|
||||
): Promise<FileUploadField[]> => {
|
||||
const response =
|
||||
await client.put<ApiResponse<FileUploadField[]>>(
|
||||
`${BASE}/${id}/fields`,
|
||||
fields
|
||||
);
|
||||
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
|
||||
payload: CreateFileUploadFieldDto,
|
||||
): Promise<FileUploadField> => {
|
||||
const response =
|
||||
await client.post<ApiResponse<FileUploadField>>(
|
||||
`${BASE}/${id}/fields`,
|
||||
payload
|
||||
);
|
||||
const response = await client.post<ApiResponse<FileUploadField>>(
|
||||
`${BASE}/${id}/fields`,
|
||||
payload,
|
||||
);
|
||||
|
||||
return unwrap(response.data);
|
||||
},
|
||||
@@ -128,32 +110,28 @@ export const fileUploadSettingsService = {
|
||||
// PATCH /file-upload-settings/fields/:fieldId
|
||||
updateField: async (
|
||||
fieldId: string,
|
||||
payload: UpdateFileUploadFieldDto
|
||||
payload: UpdateFileUploadFieldDto,
|
||||
): Promise<FileUploadField> => {
|
||||
const response =
|
||||
await client.patch<ApiResponse<FileUploadField>>(
|
||||
`${BASE}/fields/${fieldId}`,
|
||||
payload
|
||||
);
|
||||
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}`
|
||||
);
|
||||
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) =>
|
||||
client
|
||||
.get<ApiResponse<FileUploadSetting>>(`${URL_CONSTANTS.FILES.FILE_UPLOAD_SETTINGS_BY_CODE}/${code}`)
|
||||
.then(res => res.data.data)
|
||||
);
|
||||
.get<
|
||||
ApiResponse<FileUploadSetting>
|
||||
>(`${URL_CONSTANTS.FILES.FILE_UPLOAD_SETTINGS_BY_CODE}/${code}`)
|
||||
.then((res) => res.data.data),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user