From 1d65cf0d08365c8cab677ed83642c09a9a12100a Mon Sep 17 00:00:00 2001 From: ValdiANS Date: Tue, 27 Jan 2026 18:18:06 +0700 Subject: [PATCH] feat: create getMaxTargetQty and getMappedFlockKandangsMaxTargetQty method --- .../api/production/transfer-to-laying.ts | 50 +++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/src/services/api/production/transfer-to-laying.ts b/src/services/api/production/transfer-to-laying.ts index 22216e38..db3d815c 100644 --- a/src/services/api/production/transfer-to-laying.ts +++ b/src/services/api/production/transfer-to-laying.ts @@ -12,7 +12,10 @@ import { UpdateTransferToLayingPayload, } from '@/types/api/production/transfer-to-laying'; import { httpClient } from '@/services/http/client'; -import { ProjectFlockAvailableQuantity } from '@/types/api/production/project-flock'; +import { + ProjectFlockAvailableQuantity, + ProjectFlockMaxQuantity, +} from '@/types/api/production/project-flock'; import { isResponseSuccess } from '@/lib/api-helper'; export class TransferToLayingService extends BaseApiService< @@ -132,7 +135,7 @@ export class TransferToLayingService extends BaseApiService< } } - async getAvailabelQty(projectFlockId: number) { + async getAvailableQty(projectFlockId: number) { try { const availableQtyRes = await httpClient< BaseApiResponse @@ -154,7 +157,7 @@ export class TransferToLayingService extends BaseApiService< async getMappedFlockKandangsAvailability(projectFlockId: number) { try { - const flockAvailableQty = await this.getAvailabelQty(projectFlockId); + const flockAvailableQty = await this.getAvailableQty(projectFlockId); const flockKandangsAvailableQty = isResponseSuccess(flockAvailableQty) ? flockAvailableQty.data.kandangs @@ -177,6 +180,47 @@ export class TransferToLayingService extends BaseApiService< } } + async getMaxTargetQty(projectFlockId: number) { + try { + const availableQtyRes = await httpClient< + BaseApiResponse + >(`${this.basePath}/project-flocks/${projectFlockId}/max-target-qty`); + + return availableQtyRes; + } catch (error) { + if (axios.isAxiosError>(error)) { + return error.response?.data; + } + + return undefined; + } + } + + async getMappedFlockKandangsMaxTargetQty(projectFlockId: number) { + try { + const flockMaxTargetQty = await this.getMaxTargetQty(projectFlockId); + + const flockKandangsMaxTargetQty = isResponseSuccess(flockMaxTargetQty) + ? flockMaxTargetQty.data.project_flock_kandangs + : []; + + const mappedFlockKandangsMaxTargetQty: Record< + number, + (typeof flockKandangsMaxTargetQty)[0] + > = {}; + + flockKandangsMaxTargetQty.forEach((item) => { + if (!mappedFlockKandangsMaxTargetQty[item.project_flock_kandang_id]) { + mappedFlockKandangsMaxTargetQty[item.project_flock_kandang_id] = item; + } + }); + + return mappedFlockKandangsMaxTargetQty; + } catch (error) { + return undefined; + } + } + async getApprovalHistory( transferToLayingId: number, group: boolean = true,