mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-18 07:56:57 +00:00
28 lines
913 B
TypeScript
28 lines
913 B
TypeScript
|
|
import { NextRequest, NextResponse } from "next/server";
|
||
|
|
import prisma from "@/app/prisma";
|
||
|
|
import { z } from "zod/v4";
|
||
|
|
import { NotificationType } from "@/prisma/generated/prisma";
|
||
|
|
|
||
|
|
const schema = z.object({
|
||
|
|
name: z.string(),
|
||
|
|
type: z.string(),
|
||
|
|
config: z.string(),
|
||
|
|
})
|
||
|
|
|
||
|
|
export async function POST(request: NextRequest) {
|
||
|
|
try {
|
||
|
|
const body = await request.json();
|
||
|
|
const { name, type, config } = schema.parse(body);
|
||
|
|
|
||
|
|
const notification = await prisma.notificationProvider.create({
|
||
|
|
data: { name, type: type as NotificationType, config, tests: {} },
|
||
|
|
});
|
||
|
|
|
||
|
|
return NextResponse.json({ notification }, { status: 201 });
|
||
|
|
} catch (error) {
|
||
|
|
if(error instanceof z.ZodError) {
|
||
|
|
return NextResponse.json({ error: error.issues[0].message }, { status: 400 });
|
||
|
|
}
|
||
|
|
return NextResponse.json({ error: "Internal Server Error" }, { status: 500 });
|
||
|
|
}
|
||
|
|
}
|