import { NextResponse } from "next/server";
import { db, notifications, eq, and } from "@epicure/db";
import { requireSession } from "@/lib/api-auth";

export async function POST(_req: Request, { params }: { params: Promise<{ id: string }> }) {
  const { session, response } = await requireSession();
  if (response) return response;

  const { id } = await params;

  await db
    .update(notifications)
    .set({ read: true })
    .where(and(eq(notifications.id, id), eq(notifications.userId, session!.user.id)));

  return NextResponse.json({ ok: true });
}
