import type { NextRequest } from "next/server"; import { getSession } from "@/lib/session"; import { profilAlanYaz, profilGetir } from "@/lib/danisman-profil-db"; import { PROFIL_ALANLARI, profilSatirlari, type ProfilAlani } from "@/lib/danisman-profil"; /** * Danışman profili — sohbetten `profil_guncelle` aracıyla yazılan alanlar. * GET: alanlar + öğrenciye okunan satırlar. DELETE {alan}: tek alanı siler * (KVKK: öğrenci her alanı görür ve tek tıkla siler). Yazma yalnız araç * üzerinden; elle düzenleme sohbette "şunu değiştir" diyerek yapılır. */ export async function GET() { const session = await getSession(); if (!session) return Response.json({ error: "Oturum gerekli." }, { status: 401 }); const profil = await profilGetir(session.user.id); return Response.json({ profil, satirlar: profilSatirlari(profil) }); } export async function DELETE(request: NextRequest) { const session = await getSession(); if (!session) return Response.json({ error: "Oturum gerekli." }, { status: 401 }); const body = (await request.json().catch(() => null)) as { alan?: unknown } | null; const alan = typeof body?.alan === "string" ? (body.alan as ProfilAlani) : null; if (!alan || !PROFIL_ALANLARI.includes(alan)) { return Response.json({ error: "Geçersiz alan." }, { status: 400 }); } const profil = await profilAlanYaz(session.user.id, alan, null); return Response.json({ profil, satirlar: profilSatirlari(profil) }); }