feat: add api implementation

This commit is contained in:
Diego Mireles
2026-05-23 00:07:00 -06:00
parent 3297f3d9fa
commit 39bd572955
12 changed files with 799 additions and 45 deletions

View 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),
});