import type { APIRoute } from 'astro'; import { pb } from '../../lib/pb'; export const POST: APIRoute = async ({ request }) => { try { const data = await request.json(); const { name, phone, service } = data; if (!name || !phone) { return new Response(JSON.stringify({ success: false, error: 'Имя и телефон обязательны' }), { status: 400 }); } const record = await pb.collection('consultations').create({ name, phone, service: service || '', status: 'new', created_at: new Date().toISOString(), }); return new Response(JSON.stringify({ success: true, message: 'Заявка отправлена! Мы свяжемся с вами в течение 15 минут.', id: record.id }), { status: 201 }); } catch (error: any) { console.error('Consultation error:', error); return new Response(JSON.stringify({ success: false, error: error.message || 'Ошибка при отправке заявки' }), { status: 400 }); } };