Test Notifications client

This commit is contained in:
headlesdev
2025-05-25 21:03:37 +02:00
parent 67909493a2
commit 3d982bf1ac
4 changed files with 79 additions and 3 deletions

View File

@@ -0,0 +1,33 @@
import { NextRequest, NextResponse } from "next/server";
import prisma from "@/app/prisma";
import { z } from "zod/v4";
const schema = z.object({
notificationProviderId: z.number()
})
export async function POST(request: NextRequest) {
try {
const body = await request.json();
const { notificationProviderId } = schema.parse(body);
const notificationProvider = await prisma.notificationProvider.findUnique({
where: { id: notificationProviderId }
})
if(!notificationProvider) {
return NextResponse.json({ error: "Notification provider not found" }, { status: 404 });
}
const notificationTest = await prisma.notificationTest.create({
data: { notificationProviderId: notificationProviderId }
})
return NextResponse.json({ notificationTest }, { 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 });
}
}