UPDATE
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import { apiClient } from '../client'
|
||||
|
||||
const PREFIX = '/api/crop-health'
|
||||
|
||||
export interface CropHealthSummary {
|
||||
farm_health_score?: Record<string, unknown>
|
||||
ndviHealthCard?: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number
|
||||
msg: string
|
||||
data: T
|
||||
}
|
||||
|
||||
function extract<T>(res: ApiResponse<T> | T): T {
|
||||
return res && typeof res === 'object' && 'data' in res ? (res as ApiResponse<T>).data : (res as T)
|
||||
}
|
||||
|
||||
export const cropHealthService = {
|
||||
async getSummary(farmUuid: string): Promise<CropHealthSummary> {
|
||||
const res = await apiClient.get<ApiResponse<CropHealthSummary> | CropHealthSummary>(
|
||||
`${PREFIX}/summary/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { apiClient } from '../client'
|
||||
|
||||
const PREFIX = '/api/economic-overview'
|
||||
|
||||
export interface EconomicOverviewSummary {
|
||||
economicOverview?: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number
|
||||
msg: string
|
||||
data: T
|
||||
result?: T
|
||||
}
|
||||
|
||||
function extract<T>(res: ApiResponse<T> | T): T {
|
||||
if (res && typeof res === 'object') {
|
||||
if ('data' in res) return (res as ApiResponse<T>).data
|
||||
if ('result' in res) return (res as ApiResponse<T>).result as T
|
||||
}
|
||||
|
||||
return res as T
|
||||
}
|
||||
|
||||
export const economicOverviewService = {
|
||||
async getSummary(farmUuid: string): Promise<EconomicOverviewSummary> {
|
||||
const res = await apiClient.get<ApiResponse<EconomicOverviewSummary> | EconomicOverviewSummary>(
|
||||
`${PREFIX}/summary/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
const data = extract(res) as Record<string, unknown>
|
||||
|
||||
return 'economicOverview' in data ? (data as EconomicOverviewSummary) : { economicOverview: data }
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
import { apiClient } from '../client'
|
||||
|
||||
const PREFIX = '/api/farm-alerts'
|
||||
|
||||
export interface FarmAlertsSummary {
|
||||
tracker?: Record<string, unknown>
|
||||
timeline?: Record<string, unknown>
|
||||
recommendations?: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number
|
||||
msg: string
|
||||
data: T
|
||||
result?: T
|
||||
}
|
||||
|
||||
function extract<T>(res: ApiResponse<T> | T): T {
|
||||
if (res && typeof res === 'object') {
|
||||
if ('data' in res) return (res as ApiResponse<T>).data
|
||||
if ('result' in res) return (res as ApiResponse<T>).result as T
|
||||
}
|
||||
|
||||
return res as T
|
||||
}
|
||||
|
||||
export const farmAlertsService = {
|
||||
async getTracker(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/tracker/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getTimeline(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/timeline/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getRecommendations(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/recommendations/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import { apiClient } from '../client'
|
||||
|
||||
const PREFIX = '/api/pest-detection'
|
||||
|
||||
export interface PestRiskSummary {
|
||||
disease_risk?: Record<string, unknown>
|
||||
pest_risk?: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number
|
||||
msg: string
|
||||
data: T
|
||||
result?: T
|
||||
}
|
||||
|
||||
function extract<T>(res: ApiResponse<T> | T): T {
|
||||
if (res && typeof res === 'object') {
|
||||
if ('data' in res) return (res as ApiResponse<T>).data
|
||||
if ('result' in res) return (res as ApiResponse<T>).result as T
|
||||
}
|
||||
|
||||
return res as T
|
||||
}
|
||||
|
||||
function toKpiCard(card?: Record<string, unknown>): Record<string, unknown> {
|
||||
if (!card || typeof card !== 'object') return {}
|
||||
|
||||
return { kpis: [card] }
|
||||
}
|
||||
|
||||
export const pestDetectionDomainService = {
|
||||
async getRiskSummary(farmUuid: string): Promise<PestRiskSummary> {
|
||||
const res = await apiClient.get<ApiResponse<PestRiskSummary> | PestRiskSummary>(
|
||||
`${PREFIX}/risk-summary/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
const data = extract(res)
|
||||
|
||||
return {
|
||||
disease_risk: toKpiCard(data?.disease_risk),
|
||||
pest_risk: toKpiCard(data?.pest_risk)
|
||||
}
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
import { apiClient } from '../client'
|
||||
|
||||
const PREFIX = '/api/soil'
|
||||
|
||||
export interface SoilSummary {
|
||||
avg_soil_moisture?: Record<string, unknown>
|
||||
sensorRadarChart?: Record<string, unknown>
|
||||
sensorComparisonChart?: Record<string, unknown>
|
||||
anomalyDetectionCard?: Record<string, unknown>
|
||||
soilMoistureHeatmap?: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number
|
||||
msg: string
|
||||
data: T
|
||||
}
|
||||
|
||||
function extract<T>(res: ApiResponse<T> | T): T {
|
||||
return res && typeof res === 'object' && 'data' in res ? (res as ApiResponse<T>).data : (res as T)
|
||||
}
|
||||
|
||||
export const soilService = {
|
||||
async getSummary(farmUuid: string): Promise<SoilSummary> {
|
||||
const res = await apiClient.get<ApiResponse<SoilSummary> | SoilSummary>(
|
||||
`${PREFIX}/summary/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getAvgMoisture(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/avg-moisture/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getSensorRadarChart(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/sensor-radar-chart/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getSensorComparisonChart(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/sensor-comparison-chart/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getAnomalies(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/anomalies/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getMoistureHeatmap(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/moisture-heatmap/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { apiClient } from '../client'
|
||||
|
||||
const PREFIX = '/api/water'
|
||||
|
||||
export interface WaterSummary {
|
||||
farmWeatherCard?: Record<string, unknown>
|
||||
waterNeedPrediction?: Record<string, unknown>
|
||||
water_stress_index?: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number
|
||||
msg: string
|
||||
data: T
|
||||
}
|
||||
|
||||
function extract<T>(res: ApiResponse<T> | T): T {
|
||||
return res && typeof res === 'object' && 'data' in res ? (res as ApiResponse<T>).data : (res as T)
|
||||
}
|
||||
|
||||
export const waterService = {
|
||||
async getSummary(farmUuid: string): Promise<WaterSummary> {
|
||||
const res = await apiClient.get<ApiResponse<WaterSummary> | WaterSummary>(
|
||||
`${PREFIX}/summary/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getCard(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/card/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getNeedPrediction(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/need-prediction/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
|
||||
async getStressIndex(farmUuid: string): Promise<Record<string, unknown>> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/stress-index/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
return extract(res)
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import { apiClient } from '../client'
|
||||
|
||||
const PREFIX = '/api/yield-harvest'
|
||||
|
||||
export interface YieldHarvestSummary {
|
||||
yield_prediction?: Record<string, unknown>
|
||||
yieldPredictionChart?: Record<string, unknown>
|
||||
harvestPredictionCard?: Record<string, unknown>
|
||||
}
|
||||
|
||||
interface ApiResponse<T> {
|
||||
code: number
|
||||
msg: string
|
||||
data: T
|
||||
result?: T
|
||||
}
|
||||
|
||||
function extract<T>(res: ApiResponse<T> | T): T {
|
||||
if (res && typeof res === 'object') {
|
||||
if ('data' in res) return (res as ApiResponse<T>).data
|
||||
if ('result' in res) return (res as ApiResponse<T>).result as T
|
||||
}
|
||||
|
||||
return res as T
|
||||
}
|
||||
|
||||
function toKpiCard(card?: Record<string, unknown>): Record<string, unknown> {
|
||||
if (!card || typeof card !== 'object') return {}
|
||||
|
||||
return { kpis: [card] }
|
||||
}
|
||||
|
||||
export const yieldHarvestService = {
|
||||
async getSummary(farmUuid: string): Promise<YieldHarvestSummary> {
|
||||
const res = await apiClient.get<ApiResponse<Record<string, unknown>> | Record<string, unknown>>(
|
||||
`${PREFIX}/summary/?farm_uuid=${encodeURIComponent(farmUuid)}`
|
||||
)
|
||||
const data = extract(res)
|
||||
|
||||
return {
|
||||
yield_prediction: toKpiCard(data?.yield_prediction ?? data?.yield_prediction_card),
|
||||
yieldPredictionChart: (data?.yieldPredictionChart ?? data?.yield_prediction_chart ?? {}) as Record<string, unknown>,
|
||||
harvestPredictionCard: (data?.harvestPredictionCard ?? data?.harvest_prediction_card ?? {}) as Record<string, unknown>
|
||||
}
|
||||
},
|
||||
}
|
||||
Reference in New Issue
Block a user