diff --git a/app/api/notifications/add/route.ts b/app/api/notifications/add/route.ts new file mode 100644 index 0000000..721bf5a --- /dev/null +++ b/app/api/notifications/add/route.ts @@ -0,0 +1,43 @@ +import { NextResponse, NextRequest } from "next/server"; +import { prisma } from "@/lib/prisma"; + +interface AddRequest { + type: string; + smtpHost?: string; + smtpPort?: number; + smtpSecure?: boolean; + smtpUsername?: string; + smtpPassword?: string; + smtpFrom?: string; + smtpTo?: string; + telegramToken?: string; + telegramChatId?: string; + discordWebhook?: string; +} + +export async function POST(request: NextRequest) { + try { + const body: AddRequest = await request.json(); + const { type, smtpHost, smtpPort, smtpSecure, smtpUsername, smtpPassword, smtpFrom, smtpTo, telegramToken, telegramChatId, discordWebhook } = body; + + const notification = await prisma.notification.create({ + data: { + type: type, + smtpHost: smtpHost, + smtpPort: smtpPort, + smtpFrom: smtpFrom, + smtpUser: smtpUsername, + smtpPass: smtpPassword, + smtpSecure: smtpSecure, + smtpTo: smtpTo, + telegramChatId: telegramChatId, + telegramToken: telegramToken, + discordWebhook: discordWebhook, + } + }); + + return NextResponse.json({ message: "Success", notification }); + } catch (error: any) { + return NextResponse.json({ error: error.message }, { status: 500 }); + } +} diff --git a/app/api/notifications/delete/route.ts b/app/api/notifications/delete/route.ts new file mode 100644 index 0000000..67966a6 --- /dev/null +++ b/app/api/notifications/delete/route.ts @@ -0,0 +1,21 @@ +import { NextResponse, NextRequest } from "next/server"; +import { prisma } from "@/lib/prisma"; + +export async function POST(request: NextRequest) { + try { + const body = await request.json(); + const id = Number(body.id); + + if (!id) { + return NextResponse.json({ error: "Missing ID" }, { status: 400 }); + } + + await prisma.notification.delete({ + where: { id: id } + }); + + return NextResponse.json({ success: true }); + } catch (error: any) { + return NextResponse.json({ error: error.message }, { status: 500 }); + } +} \ No newline at end of file