Delete & View Notification Providers

This commit is contained in:
headlesdev
2025-05-25 00:56:54 +02:00
parent 6ba144b7bd
commit 1e93f84b24
5 changed files with 118 additions and 6 deletions

View File

@@ -14,7 +14,14 @@ export async function POST(request: NextRequest) {
const body = await request.json();
const { name, type, config } = schema.parse(body);
if(type !== "TELEGRAM") {
return NextResponse.json({ error: "Invalid notification type" }, { status: 400 });
}
const parsedConfig = JSON.parse(config);
if(parsedConfig.token === "" || parsedConfig.chat_id === "") {
return NextResponse.json({ error: "Invalid config" }, { status: 400 });
}
const notification = await prisma.notificationProvider.create({
data: { name, type: type as NotificationType, config: parsedConfig},

View File

@@ -3,7 +3,7 @@ import prisma from "@/app/prisma";
import { z } from "zod/v4";
const schema = z.object({
notificationId: z.number(),
notificationId: z.string(),
});
export async function DELETE(request: NextRequest) {
@@ -12,7 +12,7 @@ export async function DELETE(request: NextRequest) {
try {
const notification = await prisma.notificationProvider.delete({
where: { id: notificationId.notificationId },
where: { id: parseInt(notificationId.notificationId) },
});
return NextResponse.json(notification);