import { getSession } from '@/lib/session' import { isAdmin } from '@/lib/admin' import { createNews } from '@/lib/admin-news' export async function POST(request: Request) { const session = await getSession() if (!(await isAdmin(session))) return Response.json({ success: false, error: 'forbidden' }, { status: 403 }) let b: Record = {} try { b = await request.json() } catch { return Response.json({ success: false, error: 'invalidRequest' }, { status: 400 }) } const titulo = String(b.titulo ?? '').trim() const contenido = String(b.contenido ?? '').trim() const enlace = String(b.enlace ?? '').trim() || null const tituloEn = String(b.tituloEn ?? '').trim() || null const contenidoEn = String(b.contenidoEn ?? '').trim() || null if (!titulo || !contenido) return Response.json({ success: false, error: 'emptyError' }) const id = await createNews(titulo, contenido, enlace, tituloEn, contenidoEn) return Response.json({ success: true, id }) }