feat(mileage): add OneOS source priority controls
This commit is contained in:
@@ -1,4 +1,12 @@
|
||||
import type { MonitoringData, TargetSummary, TargetVehicle, TrendPoint } from './types';
|
||||
import type {
|
||||
MileageSourceCategory,
|
||||
MileageSourceGroup,
|
||||
MileageSourceProtocol,
|
||||
MonitoringData,
|
||||
TargetSummary,
|
||||
TargetVehicle,
|
||||
TrendPoint,
|
||||
} from './types';
|
||||
import { fetchJson } from '../../auth/api-client';
|
||||
|
||||
const BASE = '/api/mileage';
|
||||
@@ -25,6 +33,7 @@ export async function fetchMonitoring(params?: {
|
||||
startDate?: string;
|
||||
endDate?: string;
|
||||
brands?: string[];
|
||||
sourcePriority?: MileageSourceGroup[];
|
||||
}): Promise<MonitoringData> {
|
||||
const query = new URLSearchParams();
|
||||
if (params?.sortBy) query.set('sortBy', params.sortBy);
|
||||
@@ -56,6 +65,7 @@ export async function fetchMonitoring(params?: {
|
||||
if (params?.date) query.set('date', params.date);
|
||||
if (params?.startDate) query.set('startDate', params.startDate);
|
||||
if (params?.endDate) query.set('endDate', params.endDate);
|
||||
if (params?.sourcePriority?.length) query.set('sourcePriority', params.sourcePriority.join(','));
|
||||
const qs = query.toString();
|
||||
return fetchJson<MonitoringData>(`${BASE}/monitoring${qs ? `?${qs}` : ''}`);
|
||||
}
|
||||
@@ -82,6 +92,8 @@ export interface VehicleRecentDay {
|
||||
date: string;
|
||||
dailyKm: number;
|
||||
isDataSynced: boolean;
|
||||
sourceProtocol: MileageSourceProtocol | null;
|
||||
sourceCategory: Exclude<MileageSourceCategory, 'MIXED'> | null;
|
||||
}
|
||||
|
||||
export interface VehicleRecentResponse {
|
||||
@@ -89,16 +101,23 @@ export interface VehicleRecentResponse {
|
||||
start?: string;
|
||||
end?: string;
|
||||
days: VehicleRecentDay[];
|
||||
sourcePriority?: MileageSourceGroup[];
|
||||
}
|
||||
|
||||
export async function fetchVehicleRecent(
|
||||
plate: string,
|
||||
range: { days?: number; start?: string; end?: string } = { days: 15 },
|
||||
range: {
|
||||
days?: number;
|
||||
start?: string;
|
||||
end?: string;
|
||||
sourcePriority?: MileageSourceGroup[];
|
||||
} = { days: 15 },
|
||||
): Promise<VehicleRecentResponse> {
|
||||
const params = new URLSearchParams();
|
||||
if (range.start) params.set('start', range.start);
|
||||
if (range.end) params.set('end', range.end);
|
||||
if (range.days != null) params.set('days', String(range.days));
|
||||
if (range.sourcePriority?.length) params.set('sourcePriority', range.sourcePriority.join(','));
|
||||
return fetchJson<VehicleRecentResponse>(
|
||||
`${BASE}/vehicle/${encodeURIComponent(plate)}/recent?${params.toString()}`
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user