30 lines
961 B
TypeScript
Raw Normal View History

2025-05-24 22:44:14 +02:00
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);
2025-05-25 00:32:16 +02:00
const parsedConfig = JSON.parse(config);
2025-05-24 22:44:14 +02:00
const notification = await prisma.notificationProvider.create({
2025-05-25 00:32:16 +02:00
data: { name, type: type as NotificationType, config: parsedConfig},
2025-05-24 22:44:14 +02:00
});
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 });
}
}