mirror of
https://github.com/arkorty/B.Tech-Project-III.git
synced 2026-04-19 12:41:48 +00:00
20 lines
739 B
TypeScript
20 lines
739 B
TypeScript
// Thin API client for the negoT8 FastAPI backend
|
|
import type { Negotiation, Stats } from "./types";
|
|
|
|
const BASE = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:8000";
|
|
|
|
async function get<T>(path: string): Promise<T> {
|
|
const res = await fetch(`${BASE}${path}`, { cache: "no-store" });
|
|
if (!res.ok) throw new Error(`GET ${path} → ${res.status}`);
|
|
return res.json() as Promise<T>;
|
|
}
|
|
|
|
export const api = {
|
|
stats: () => get<Stats>("/api/stats"),
|
|
negotiations: () =>
|
|
get<{ negotiations: Negotiation[]; total: number }>("/api/negotiations"),
|
|
negotiation: (id: string) => get<Negotiation>(`/api/negotiations/${id}`),
|
|
analytics: (id: string) =>
|
|
get<Negotiation["analytics"]>(`/api/negotiations/${id}/analytics`),
|
|
};
|