30 lines
829 B
TypeScript
Raw Normal View History

2025-05-18 11:56:07 +02:00
import { NextRequest, NextResponse } from "next/server";
import prisma from "@/app/prisma";
2025-05-21 23:32:21 +02:00
import { z } from "zod/v4";
2025-05-18 11:56:07 +02:00
2025-05-21 23:32:21 +02:00
const schema = z.object({
name: z.string(),
description: z.string(),
});
2025-05-18 11:56:07 +02:00
export async function POST(request: NextRequest) {
try {
2025-05-21 23:32:21 +02:00
const body = schema.parse(await request.json());
2025-05-18 11:56:07 +02:00
const site = await prisma.site.create({
data: {
name: body.name,
description: body.description,
},
});
return NextResponse.json({ site }, { status: 201 });
} catch (error: any) {
2025-05-21 23:32:21 +02:00
if(error instanceof z.ZodError) {
return NextResponse.json({ error: error.issues[0].message }, { status: 400 });
}
2025-05-18 11:56:07 +02:00
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
}
}