feat: add api implementation
This commit is contained in:
46
frontend/src/services/tracking.service.ts
Normal file
46
frontend/src/services/tracking.service.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { apiFetch } from "../lib/api";
|
||||
|
||||
export type NotificationType =
|
||||
| "ROUTE_START"
|
||||
| "TRUCK_PROXIMITY"
|
||||
| "TRUCK_ARRIVED"
|
||||
| "ROUTE_COMPLETED"
|
||||
| "DELAY"
|
||||
| "MECHANICAL_FAILURE";
|
||||
|
||||
export interface GpsUpdatePayload {
|
||||
truckId: string;
|
||||
routeId: string;
|
||||
lat: number;
|
||||
lng: number;
|
||||
speed: number;
|
||||
status: "EN_RUTA" | "DETENIDO" | "FINALIZADO" | "FALLA";
|
||||
positionId?: number;
|
||||
timestamp?: string;
|
||||
}
|
||||
|
||||
export interface EtaResult {
|
||||
etaMinutes: number;
|
||||
arrivalWindow: { from: string; to: string };
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface BackendNotification {
|
||||
userId: number;
|
||||
type: NotificationType;
|
||||
title: string;
|
||||
body: string;
|
||||
}
|
||||
|
||||
export interface GpsUpdateResponse {
|
||||
message: string;
|
||||
truck: { truckId: number; routeId: string; status: string };
|
||||
eta: EtaResult;
|
||||
notifications: BackendNotification[];
|
||||
}
|
||||
|
||||
export const sendGpsUpdate = (payload: GpsUpdatePayload) =>
|
||||
apiFetch<GpsUpdateResponse>("/api/tracking/gps-update", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
});
|
||||
Reference in New Issue
Block a user