import type { Task, GraphData, CreateTaskInput, UpdateTaskInput } from './types'; const BASE = '/api'; async function request(path: string, init?: RequestInit): Promise { const res = await fetch(`${BASE}${path}`, { headers: { 'Content-Type': 'application/json', ...init?.headers }, ...init, }); if (!res.ok) { const text = await res.text().catch(() => res.statusText); throw new Error(`API error ${res.status}: ${text}`); } return res.json() as Promise; } export async function getTasks(): Promise { return request('/tasks'); } export async function createTask(input: CreateTaskInput): Promise { return request('/tasks', { method: 'POST', body: JSON.stringify(input), }); } export async function updateTask(id: number, input: UpdateTaskInput): Promise { return request(`/tasks/${id}`, { method: 'PATCH', body: JSON.stringify(input), }); } export async function deleteTask(id: number): Promise { await fetch(`${BASE}/tasks/${id}`, { method: 'DELETE' }); } export async function getGraph(): Promise { return request('/graph'); }