Files
sexy/app/api/devices/[id]/route.ts
T

17 lines
724 B
TypeScript
Raw Normal View History

import { NextResponse } from "next/server";
import { z } from "zod";
import { renameDevice } from "@/lib/db/queries/devices";
const bodySchema = z.object({ displayName: z.string().min(1).max(120) });
export async function PATCH(req: Request, { params }: { params: Promise<{ id: string }> }) {
const { id } = await params;
const parsed = bodySchema.safeParse(await req.json().catch(() => null));
if (!parsed.success) {
return NextResponse.json({ error: "displayName is required" }, { status: 400 });
}
const updated = await renameDevice(Number(id), parsed.data.displayName);
if (!updated) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json({ device: updated });
}