mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-19 16:36:46 +00:00
34 lines
924 B
TypeScript
34 lines
924 B
TypeScript
|
|
import { NextRequest, NextResponse } from "next/server";
|
||
|
|
import prisma from "@/app/prisma";
|
||
|
|
|
||
|
|
interface Body {
|
||
|
|
username: string;
|
||
|
|
name: string;
|
||
|
|
email: string;
|
||
|
|
password: string;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function POST(request: NextRequest) {
|
||
|
|
try {
|
||
|
|
const body: Body = await request.json();
|
||
|
|
|
||
|
|
if (!body.username || !body.name || !body.email || !body.password) {
|
||
|
|
return NextResponse.json({ error: "Missing required fields" }, { status: 400 });
|
||
|
|
}
|
||
|
|
|
||
|
|
const user = await prisma.user.create({
|
||
|
|
data: {
|
||
|
|
username: body.username,
|
||
|
|
name: body.name,
|
||
|
|
email: body.email,
|
||
|
|
password: body.password,
|
||
|
|
},
|
||
|
|
});
|
||
|
|
|
||
|
|
return NextResponse.json({ user }, { status: 201 });
|
||
|
|
|
||
|
|
} catch (error: any) {
|
||
|
|
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|