UPDATE
This commit is contained in:
@@ -142,6 +142,31 @@ interface ApiResponse<T> {
|
||||
data: T;
|
||||
}
|
||||
|
||||
export interface FertilizationRecommendationHistoryItem {
|
||||
recommendation_uuid: string;
|
||||
plant_name: string;
|
||||
growth_stage: string;
|
||||
fertilizer_type: string;
|
||||
status: "pending_confirmation" | "in_progress" | "completed" | string;
|
||||
status_label: string;
|
||||
requested_at: string;
|
||||
}
|
||||
|
||||
export interface FertilizationRecommendationHistoryPagination {
|
||||
page: number;
|
||||
page_size: number;
|
||||
total_pages: number;
|
||||
total_items: number;
|
||||
has_next: boolean;
|
||||
has_previous: boolean;
|
||||
next: string | null;
|
||||
previous: string | null;
|
||||
}
|
||||
|
||||
interface PaginatedApiResponse<T> extends ApiResponse<T> {
|
||||
pagination: FertilizationRecommendationHistoryPagination;
|
||||
}
|
||||
|
||||
async function unwrap<T>(promise: Promise<ApiResponse<T>>): Promise<T> {
|
||||
const res = await promise;
|
||||
return res.data;
|
||||
@@ -166,4 +191,34 @@ export const fertilizationRecommendationService = {
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
async getRecommendationsHistory(
|
||||
farmUuid: string,
|
||||
page = 1,
|
||||
pageSize = 10,
|
||||
): Promise<{
|
||||
data: FertilizationRecommendationHistoryItem[];
|
||||
pagination: FertilizationRecommendationHistoryPagination;
|
||||
}> {
|
||||
const response = await apiClient.get<
|
||||
PaginatedApiResponse<FertilizationRecommendationHistoryItem[]>
|
||||
>(
|
||||
`${RECOMMEND_PREFIX}/recommendations/?farm_uuid=${encodeURIComponent(farmUuid)}&page=${page}&page_size=${pageSize}`,
|
||||
);
|
||||
|
||||
return {
|
||||
data: response.data,
|
||||
pagination: response.pagination,
|
||||
};
|
||||
},
|
||||
|
||||
getRecommendationDetail(
|
||||
recommendationUuid: string,
|
||||
): Promise<FertilizationRecommendationResult> {
|
||||
return unwrap(
|
||||
apiClient.get<ApiResponse<FertilizationRecommendationResult>>(
|
||||
`${RECOMMEND_PREFIX}/recommendations/${encodeURIComponent(recommendationUuid)}/`,
|
||||
),
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user