Files
tripwithbonus/frontend/app/api/account/highlight/route.ts
2025-05-29 12:08:38 +03:00

40 lines
1.2 KiB
TypeScript

import { NextRequest } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/app/api/auth/[...nextauth]/route'
export async function PATCH(req: NextRequest) {
try {
const session = await getServerSession(authOptions)
if (!session) {
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
status: 401,
})
}
const { route_id } = await req.json()
const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/account/route_highlight/`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${session.accessToken}`,
},
body: JSON.stringify({ route_id }),
})
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) {
console.error('PATCH /api/account/highlight error:', error)
return new Response(JSON.stringify({ error: 'Internal Server Error' }), {
status: 500,
})
}
}