refactor(FE-dashboard-modal): Refactor dashboard production data

fetching logic
This commit is contained in:
rstubryan
2026-04-08 09:54:40 +07:00
parent e251ab9eb4
commit 0b52fff5f5
2 changed files with 53 additions and 71 deletions
+20 -6
View File
@@ -1,7 +1,6 @@
import { BaseApiService } from '@/services/api/base';
import { BaseApiResponse } from '@/types/api/api-general';
import { Dashboard } from '@/types/api/dashboard/dashboard';
import { httpClientFetcher } from '@/services/http/client';
import { Dashboard, DashboardFilter } from '@/types/api/dashboard/dashboard';
class DashboardService extends BaseApiService<Dashboard, unknown, unknown> {
constructor(basePath: string) {
@@ -14,11 +13,26 @@ class DashboardService extends BaseApiService<Dashboard, unknown, unknown> {
* @returns Promise with BaseApiResponse containing DashboardProduction
*/
async getDashboardProductionFetcher(
endpoint: string
params: DashboardFilter
): Promise<BaseApiResponse<Dashboard> | undefined> {
return await httpClientFetcher<BaseApiResponse<Dashboard>>(
`${endpoint ? endpoint : this.basePath}`
);
return await this.customRequest<BaseApiResponse<Dashboard>>('', {
method: 'GET',
params: {
start_date: params.start_date || undefined,
end_date: params.end_date || undefined,
analysis_mode: params.analysis_mode || undefined,
location_ids: params.location_ids.length
? params.location_ids.toString()
: undefined,
flock_ids: params.flock_ids.length
? params.flock_ids.toString()
: undefined,
kandang_ids: params.kandang_ids.length
? params.kandang_ids.toString()
: undefined,
comparison_type: params.comparison_type || undefined,
},
});
}
}