// frontend/js/api.js import { apiFetch } from "./auth.js"; import { API_BASE } from "./config.js"; // <-- Добавили импорт // УДАЛИТЬ эти строки из начала api.js: // export const API_BASE = ... export async function fetchWorkoutTypes() { const res = await apiFetch("/workout-types/"); if (!res.ok) throw new Error('Failed to fetch workout types'); return await res.json(); } export async function fetchMetricTypes() { const res = await fetch(`${API_BASE}/metric-types/`); if (!res.ok) throw new Error('Failed to fetch metric types'); return await res.json(); } export async function fetchClients() { const res = await fetch(`${API_BASE}/clients/`); if (!res.ok) throw new Error('Failed to fetch clients'); return await res.json(); } export async function fetchExerciseHistory(exerciseName, clientId = null) { let url = `${API_BASE}/exercises/history/${encodeURIComponent(exerciseName)}?limit=10`; if (clientId) url += `&client_id=${clientId}`; const res = await fetch(url); if (!res.ok) throw new Error('Failed to fetch history'); return await res.json(); } export async function syncData(payload) { const res = await fetch(`${API_BASE}/sync/`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(payload) }); if (!res.ok) { const err = await res.json(); console.error('❌ Sync API Error Detail:', err); // <-- Покажет, какое именно поле не прошло валидацию throw new Error(err.detail ? JSON.stringify(err.detail) : 'Sync failed'); } return await res.json(); }