mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
feat: create getMaxTargetQty and getMappedFlockKandangsMaxTargetQty method
This commit is contained in:
@@ -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<ProjectFlockAvailableQuantity>
|
||||
@@ -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<ProjectFlockMaxQuantity>
|
||||
>(`${this.basePath}/project-flocks/${projectFlockId}/max-target-qty`);
|
||||
|
||||
return availableQtyRes;
|
||||
} catch (error) {
|
||||
if (axios.isAxiosError<BaseApiResponse<ProjectFlockMaxQuantity>>(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,
|
||||
|
||||
Reference in New Issue
Block a user