mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-21 05:45:46 +00:00
Merge branch 'development' into feat/FE/US-77/TASK-113-slicing-transfer-to-laying-create-form
This commit is contained in:
@@ -89,4 +89,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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +59,11 @@ import {
|
||||
Fcr,
|
||||
UpdateFcrPayload,
|
||||
} from '@/types/api/master-data/fcr';
|
||||
import {
|
||||
CreateFlockPayload,
|
||||
Flock,
|
||||
UpdateFlockPayload,
|
||||
} from '@/types/api/master-data/flock';
|
||||
|
||||
export const UomApi = new BaseApiService<
|
||||
Uom,
|
||||
@@ -130,3 +135,9 @@ export const FcrApi = new BaseApiService<
|
||||
CreateFcrPayload,
|
||||
UpdateFcrPayload
|
||||
>('/master-data/fcrs');
|
||||
|
||||
export const FlockApi = new BaseApiService<
|
||||
Flock,
|
||||
CreateFlockPayload,
|
||||
UpdateFlockPayload
|
||||
>('/master-data/flocks');
|
||||
@@ -0,0 +1,11 @@
|
||||
import {
|
||||
ProjectFlock,
|
||||
CreateProjectFlockPayload,
|
||||
} from '@/types/api/production/project-flock';
|
||||
import { BaseApiService } from '@/services/api/base';
|
||||
|
||||
export const ProjectFlockApi = new BaseApiService<
|
||||
ProjectFlock,
|
||||
CreateProjectFlockPayload,
|
||||
unknown
|
||||
>('/production/project_flocks');
|
||||
Reference in New Issue
Block a user