UPDATE
This commit is contained in:
@@ -41,16 +41,19 @@ export interface IrrigationConfigResponse {
|
||||
}
|
||||
|
||||
export interface IrrigationPlan {
|
||||
frequencyPerWeek: number | string;
|
||||
durationMinutes: number | string;
|
||||
bestTimeOfDay: string;
|
||||
moistureLevel: number | string;
|
||||
frequencyPerWeek?: number | string;
|
||||
durationMinutes?: number | string;
|
||||
bestTimeOfDay?: string;
|
||||
moistureLevel?: number | string;
|
||||
warning?: string;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface IrrigationRecommendPayload {
|
||||
farm_uuid: string;
|
||||
farm_uuid?: string;
|
||||
sensor_uuid?: string;
|
||||
crop_id?: string;
|
||||
plant_name?: string;
|
||||
growth_stage?: string;
|
||||
irrigation_method_id?: string;
|
||||
farm_data?: Partial<FarmInfo>;
|
||||
@@ -78,13 +81,57 @@ export interface WaterBalance {
|
||||
daily: WaterBalanceDailyEntry[];
|
||||
crop_profile?: WaterBalanceCropProfile;
|
||||
active_kc?: number;
|
||||
[key: string]: unknown;
|
||||
}
|
||||
|
||||
export interface IrrigationRecommendationTimelineItem {
|
||||
step_number: number;
|
||||
title: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export interface IrrigationRecommendationSection {
|
||||
title: string;
|
||||
icon?: string;
|
||||
type: "schedule" | "warning" | "tip" | "method" | string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface IrrigationRecommendationResult {
|
||||
recommendation_uuid?: string;
|
||||
crop_id?: string;
|
||||
plant_name?: string;
|
||||
growth_stage?: string;
|
||||
irrigation_method_name?: string;
|
||||
status?: string;
|
||||
status_label?: string;
|
||||
plan: IrrigationPlan;
|
||||
raw_response?: string;
|
||||
water_balance?: WaterBalance;
|
||||
status?: string;
|
||||
timeline?: IrrigationRecommendationTimelineItem[];
|
||||
sections?: IrrigationRecommendationSection[];
|
||||
}
|
||||
|
||||
export interface IrrigationRecommendationHistoryItem {
|
||||
recommendation_uuid: string;
|
||||
crop_id?: string;
|
||||
plant_name?: string;
|
||||
growth_stage?: string;
|
||||
irrigation_method_name?: string;
|
||||
status: "pending_confirmation" | "in_progress" | "completed" | "error" | string;
|
||||
status_label: string;
|
||||
requested_at: string;
|
||||
}
|
||||
|
||||
export interface IrrigationRecommendationHistoryPagination {
|
||||
page: number;
|
||||
page_size: number;
|
||||
total_pages: number;
|
||||
total_items: number;
|
||||
has_next: boolean;
|
||||
has_previous: boolean;
|
||||
next: string | null;
|
||||
previous: string | null;
|
||||
}
|
||||
|
||||
export interface WaterStressPayload {
|
||||
@@ -120,10 +167,16 @@ export type IrrigationRecommendResponse =
|
||||
| RecommendationTaskInitResponse;
|
||||
|
||||
interface ApiResponse<T> {
|
||||
status: string;
|
||||
code?: number;
|
||||
msg?: string;
|
||||
status?: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
interface PaginatedApiResponse<T> extends ApiResponse<T> {
|
||||
pagination: IrrigationRecommendationHistoryPagination;
|
||||
}
|
||||
|
||||
async function unwrap<T>(promise: Promise<ApiResponse<T>>): Promise<T> {
|
||||
const res = await promise;
|
||||
return res.data;
|
||||
@@ -142,9 +195,7 @@ function normalizeRecommendationResult(
|
||||
|
||||
export const irrigationRecommendationService = {
|
||||
listMethods(): Promise<IrrigationMethod[]> {
|
||||
return unwrap(
|
||||
apiClient.get<ApiResponse<IrrigationMethod[]>>(`${PREFIX}/`),
|
||||
);
|
||||
return unwrap(apiClient.get<ApiResponse<IrrigationMethod[]>>(`${PREFIX}/`));
|
||||
},
|
||||
|
||||
getConfig(farmUuid: string): Promise<IrrigationConfigResponse> {
|
||||
@@ -173,6 +224,36 @@ export const irrigationRecommendationService = {
|
||||
);
|
||||
},
|
||||
|
||||
async getRecommendationsHistory(
|
||||
farmUuid: string,
|
||||
page = 1,
|
||||
pageSize = 10,
|
||||
): Promise<{
|
||||
data: IrrigationRecommendationHistoryItem[];
|
||||
pagination: IrrigationRecommendationHistoryPagination;
|
||||
}> {
|
||||
const response = await apiClient.get<
|
||||
PaginatedApiResponse<IrrigationRecommendationHistoryItem[]>
|
||||
>(
|
||||
`${RECOMMEND_PREFIX}/recommendations/?farm_uuid=${encodeURIComponent(farmUuid)}&page=${page}&page_size=${pageSize}`,
|
||||
);
|
||||
|
||||
return {
|
||||
data: response.data,
|
||||
pagination: response.pagination,
|
||||
};
|
||||
},
|
||||
|
||||
getRecommendationDetail(
|
||||
recommendationUuid: string,
|
||||
): Promise<IrrigationRecommendationResult> {
|
||||
return unwrap(
|
||||
apiClient.get<ApiResponse<IrrigationRecommendationResult>>(
|
||||
`${RECOMMEND_PREFIX}/recommendations/${encodeURIComponent(recommendationUuid)}/`,
|
||||
),
|
||||
).then(normalizeRecommendationResult);
|
||||
},
|
||||
|
||||
getWaterStress(payload?: WaterStressPayload): Promise<WaterStressResponse> {
|
||||
return unwrap(
|
||||
apiClient.post<ApiResponse<WaterStressResponse>>(
|
||||
|
||||
Reference in New Issue
Block a user