mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat(FE-85-87-88): slicing ui and integrate api for search and edit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user