import { NextRequest } from 'next/server' import { getServerSession } from 'next-auth' import { authOptions } from '@/app/api/auth/[...nextauth]/route' export async function POST(req: NextRequest) { try { const session = await getServerSession(authOptions) if (!session) { return new Response(JSON.stringify({ error: 'Unauthorized' }), { status: 401, }) } const data = await req.json() const { transport, country_from, city_from, country_to, city_to, cargo_type, departure, arrival, phone_number, comment, email_notification, } = data const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/account/create_route/`, { method: 'POST', headers: { 'Content-Type': 'application/json', Authorization: `Bearer ${session.accessToken}`, }, body: JSON.stringify({ owner_type: data.owner_type, transport: data.transport, country_from: data.country_from, city_from: data.city_from, country_to: data.country_to, city_to: data.city_to, cargo_type: data.cargo_type, departure: data.departure, arrival: data.arrival, phone_number: data.phone_number, comment: data.comment || '', email_notification: data.email_notification, }), }) if (!response.ok) { const error = await response.json() return new Response(JSON.stringify(error), { status: response.status }) } const result = await response.json() return new Response(JSON.stringify(result), { status: 200 }) } catch (error) { return new Response(JSON.stringify({ error: 'Internal Server Error' }), { status: 500, }) } }