mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Test Notifications client
This commit is contained in:
33
app/api/notifications/test/route.ts
Normal file
33
app/api/notifications/test/route.ts
Normal 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 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user