chore: create getAll method in BaseApiService

This commit is contained in:
ValdiANS
2025-12-30 22:26:43 +07:00
parent 5326eff293
commit f985c041e4
+16
View File
@@ -15,6 +15,22 @@ export class BaseApiService<T, CreatePayloadGeneric, UpdatePayloadGeneric> {
return await httpClientFetcher<BaseApiResponse<T[]>>(endpoint); return await httpClientFetcher<BaseApiResponse<T[]>>(endpoint);
} }
async getAll(query?: Record<string, unknown>) {
try {
const getAllPath = this.basePath;
const getAllRes = await httpClient<BaseApiResponse<T[]>>(getAllPath, {
query,
});
return getAllRes;
} catch (error) {
if (axios.isAxiosError<BaseApiResponse<T[]>>(error)) {
return error.response?.data;
}
return undefined;
}
}
async getSingle(id: number) { async getSingle(id: number) {
try { try {
const getSinglePath = `${this.basePath}/${id}`; const getSinglePath = `${this.basePath}/${id}`;