klg-asutk-app/lib/api.ts
Yuriy b147d16798 MVP: заглушки, auth, .env.example, связь с бэкендом, главная КЛГ
- Заполнены заглушки: user-friendly-messages, health, aria, keyboard
- backend: core/auth.py, /api/v1/stats; cached-api → backend-client при USE_MOCK_DATA=false
- .env.example, middleware auth (skip при USE_MOCK_DATA), убраны неиспользуемые deps
- Страницы: airworthiness, maintenance, defects, modifications; AircraftAddModal, Sidebar
- Главная страница: REFLY — Контроль лётной годности (вместо Numerology App)
- Линт/скрипты: eslintrc, security, cleanup, logs, api inbox/knowledge

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-13 16:43:53 +03:00

42 lines
1.3 KiB
TypeScript

export interface Aircraft {
id: string;
registrationNumber: string;
serialNumber: string;
aircraftType: string;
model: string;
operator: string;
status: string;
flightHours?: number;
manufacturer?: string;
yearOfManufacture?: number;
maxTakeoffWeight?: number;
engineType?: string;
lastInspectionDate?: string;
nextInspectionDate?: string;
certificateExpiry?: string;
date?: string;
rating?: number;
notes?: string;
[key: string]: any;
}
const API_BASE = process.env.NEXT_PUBLIC_API_URL || "/api";
export async function apiFetch(path: string, opts: RequestInit = {}) {
const res = await fetch(API_BASE + path, { ...opts, headers: { "Content-Type": "application/json", ...opts.headers } });
if (!res.ok) throw new Error("API error: " + res.status);
const json = await res.json();
return json.data !== undefined ? json.data : json;
}
export const aircraftApi = {
getAircraft: () => apiFetch("/aircraft"),
getAll: () => apiFetch("/aircraft"),
getById: (id: string) => apiFetch("/aircraft/" + id),
create: (data: any) => apiFetch("/aircraft", { method: "POST", body: JSON.stringify(data) }),
update: (id: string, data: any) => apiFetch("/aircraft/" + id, { method: "PUT", body: JSON.stringify(data) }),
delete: (id: string) => apiFetch("/aircraft/" + id, { method: "DELETE" }),
};
export default { fetch: apiFetch };