feat(FE-85-87-88): slicing ui and integrate api for search and edit

This commit is contained in:
randy-ar
2025-10-18 10:46:47 +07:00
parent da92874a40
commit a573551110
18 changed files with 281 additions and 112 deletions
+36
View File
@@ -79,4 +79,40 @@ export class BaseApiService<T, CreatePayloadGeneric, UpdatePayloadGeneric> {
return undefined;
}
}
async customRequest<ResponseType = T, PayloadType = unknown>(
endpoint: string,
options?: {
method?: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
payload?: PayloadType;
params?: Record<string, string | number | boolean | undefined>;
}
): Promise<ResponseType | undefined> {
try {
const urlBase = endpoint.startsWith('http')
? endpoint
: `${this.basePath.replace(/\/$/, '')}/${endpoint.replace(/^\//, '')}`;
const url = options?.params
? `${urlBase}?${new URLSearchParams(
Object.entries(options.params).reduce((acc, [key, value]) => {
if (value !== undefined) acc[key] = String(value);
return acc;
}, {} as Record<string, string>)
)}`
: urlBase;
const res = await httpClient<ResponseType>(url, {
method: options?.method || 'GET',
body: options?.payload,
});
return res;
} catch (error: unknown) {
if (axios.isAxiosError<ResponseType>(error)) {
return error.response?.data;
}
return undefined;
}
}
}