From 28b58d9cac1597db21b0975c1e3d7fe24f2678d8 Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Fri, 23 Jan 2026 15:36:16 +0700 Subject: [PATCH] fix: fix exportProductionResultToExcel method --- src/services/api/report/production-result.ts | 36 +++++++++++--------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/services/api/report/production-result.ts b/src/services/api/report/production-result.ts index 251e3eb4..3a8d2fae 100644 --- a/src/services/api/report/production-result.ts +++ b/src/services/api/report/production-result.ts @@ -32,21 +32,21 @@ export class ProductionResultReportApiService extends BaseApiService< const mappedProductionResults: { projectFlockKandang: BaseProjectFlockKandang; productionResult: ProductionResult[] | null; - }[] = []; + }[] = await Promise.all( + (projectFlockKandangs || []).map(async (projectFlockKandang) => { + const getProductionResultPath = `${this.basePath}/${projectFlockKandang.id}?page=1&limit=99999999`; + const getProductionResultRes = await httpClient< + BaseApiResponse + >(getProductionResultPath); - projectFlockKandangs?.forEach(async (projectFlockKandang) => { - const getProductionResultPath = `${this.basePath}/${projectFlockKandang.id}?page=1&limit=99999999`; - const getProductionResultRes = await httpClient< - BaseApiResponse - >(getProductionResultPath); - - mappedProductionResults.push({ - projectFlockKandang, - productionResult: isResponseSuccess(getProductionResultRes) - ? getProductionResultRes.data - : null, - }); - }); + return { + projectFlockKandang, + productionResult: isResponseSuccess(getProductionResultRes) + ? getProductionResultRes.data + : null, + }; + }) + ); const rows = mappedProductionResults; if (!rows || rows.length === 0) { @@ -103,9 +103,11 @@ export class ProductionResultReportApiService extends BaseApiService< fcr_std: productionResult.fcr_std, hh: productionResult.hh, hh_std: productionResult.hh_std, - project_flock_name: productionResult.project_flock.name, - project_flock_category: productionResult.project_flock.category, - kandang_name: productionResult.project_flock.kandang.name, + project_flock_name: + row.projectFlockKandang.project_flock.flock_name, + project_flock_category: + row.projectFlockKandang.project_flock.category, + kandang_name: row.projectFlockKandang.kandang.name, created_at: formatDate(productionResult.created_at, 'YYYY-MM-DD'), updated_at: formatDate(productionResult.updated_at, 'YYYY-MM-DD'), });