mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-24 10:56:54 +00:00
Add Site API Route
This commit is contained in:
parent
ad24a6e8e2
commit
460192e0ce
30
app/api/sites/add/route.ts
Normal file
30
app/api/sites/add/route.ts
Normal file
@ -0,0 +1,30 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import prisma from "@/app/prisma";
|
||||
|
||||
interface Body {
|
||||
name: string;
|
||||
description: string;
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body: Body = await request.json();
|
||||
|
||||
if (!body.name) {
|
||||
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
|
||||
}
|
||||
|
||||
const site = await prisma.site.create({
|
||||
data: {
|
||||
name: body.name,
|
||||
description: body.description,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({ site }, { status: 201 });
|
||||
|
||||
} catch (error: any) {
|
||||
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user