mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-17 15:36:50 +00:00
30 lines
829 B
TypeScript
30 lines
829 B
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import prisma from "@/app/prisma";
|
|
import { z } from "zod/v4";
|
|
|
|
const schema = z.object({
|
|
name: z.string(),
|
|
description: z.string(),
|
|
});
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const body = schema.parse(await request.json());
|
|
|
|
const site = await prisma.site.create({
|
|
data: {
|
|
name: body.name,
|
|
description: body.description,
|
|
},
|
|
});
|
|
|
|
return NextResponse.json({ site }, { status: 201 });
|
|
|
|
} catch (error: any) {
|
|
if(error instanceof z.ZodError) {
|
|
return NextResponse.json({ error: error.issues[0].message }, { status: 400 });
|
|
}
|
|
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
|
}
|
|
}
|
|
|