import { NextRequest, NextResponse } from "next/server"; import { eq } from "drizzle-orm"; import { db } from "@/lib/db"; import { claws } from "@/lib/db/schema"; import { authenticateRequest } from "@/lib/auth/request"; import { updateNameSchema } from "@/lib/validators/schemas"; export async function PUT(req: NextRequest) { try { const auth = await authenticateRequest(req); if (auth instanceof NextResponse) { return auth; } const { claw } = auth; const body = await req.json(); const parsed = updateNameSchema.safeParse(body); if (!parsed.success) { return NextResponse.json( { error: "Validation failed", details: parsed.error.flatten() }, { status: 400 } ); } const { name } = parsed.data; await db .update(claws) .set({ name, updatedAt: new Date() }) .where(eq(claws.id, claw.id)); return NextResponse.json({ ok: true, name }); } catch (error) { console.error("Update name error:", error); return NextResponse.json( { error: "Internal server error" }, { status: 500 } ); } }