mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-18 07:56:57 +00:00
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
|
|
import { NextRequest, NextResponse } from "next/server";
|
||
|
|
import prisma from "@/app/prisma";
|
||
|
|
import { z } from "zod/v4";
|
||
|
|
|
||
|
|
const schema = z.object({
|
||
|
|
networkId: z.number(),
|
||
|
|
name: z.string().min(3, "Server name must be at least 3 characters long").max(30, "Server name must be less than 30 characters long"),
|
||
|
|
description: z.string().optional(),
|
||
|
|
icon: z.string().optional(),
|
||
|
|
});
|
||
|
|
|
||
|
|
export async function POST(request: NextRequest) {
|
||
|
|
try {
|
||
|
|
const body = schema.parse(await request.json());
|
||
|
|
|
||
|
|
const server = await prisma.server.create({
|
||
|
|
data: {
|
||
|
|
networkId: body.networkId,
|
||
|
|
name: body.name,
|
||
|
|
description: body.description,
|
||
|
|
icon: body.icon,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
return NextResponse.json({ server }, { 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 });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|