mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 07:45:47 +00:00
feat: create getMaxTargetQty and getMappedFlockKandangsMaxTargetQty method
This commit is contained in:
@@ -12,7 +12,10 @@ import {
|
|||||||
UpdateTransferToLayingPayload,
|
UpdateTransferToLayingPayload,
|
||||||
} from '@/types/api/production/transfer-to-laying';
|
} from '@/types/api/production/transfer-to-laying';
|
||||||
import { httpClient } from '@/services/http/client';
|
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';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
|
|
||||||
export class TransferToLayingService extends BaseApiService<
|
export class TransferToLayingService extends BaseApiService<
|
||||||
@@ -132,7 +135,7 @@ export class TransferToLayingService extends BaseApiService<
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async getAvailabelQty(projectFlockId: number) {
|
async getAvailableQty(projectFlockId: number) {
|
||||||
try {
|
try {
|
||||||
const availableQtyRes = await httpClient<
|
const availableQtyRes = await httpClient<
|
||||||
BaseApiResponse<ProjectFlockAvailableQuantity>
|
BaseApiResponse<ProjectFlockAvailableQuantity>
|
||||||
@@ -154,7 +157,7 @@ export class TransferToLayingService extends BaseApiService<
|
|||||||
|
|
||||||
async getMappedFlockKandangsAvailability(projectFlockId: number) {
|
async getMappedFlockKandangsAvailability(projectFlockId: number) {
|
||||||
try {
|
try {
|
||||||
const flockAvailableQty = await this.getAvailabelQty(projectFlockId);
|
const flockAvailableQty = await this.getAvailableQty(projectFlockId);
|
||||||
|
|
||||||
const flockKandangsAvailableQty = isResponseSuccess(flockAvailableQty)
|
const flockKandangsAvailableQty = isResponseSuccess(flockAvailableQty)
|
||||||
? flockAvailableQty.data.kandangs
|
? 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(
|
async getApprovalHistory(
|
||||||
transferToLayingId: number,
|
transferToLayingId: number,
|
||||||
group: boolean = true,
|
group: boolean = true,
|
||||||
|
|||||||
Reference in New Issue
Block a user