Notifications Add & Delete Route

This commit is contained in:
headlesdev
2025-05-24 22:44:14 +02:00
parent d095524291
commit 913dd7dd63
2 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
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 });
}
}