mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Notifications Add & Delete Route
This commit is contained in:
28
app/api/notifications/add/route.ts
Normal file
28
app/api/notifications/add/route.ts
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
const notification = await prisma.notificationProvider.create({
|
||||||
|
data: { name, type: type as NotificationType, config, tests: {} },
|
||||||
|
});
|
||||||
|
|
||||||
|
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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
25
app/api/notifications/delete/route.ts
Normal file
25
app/api/notifications/delete/route.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
import prisma from "@/app/prisma";
|
||||||
|
import { z } from "zod/v4";
|
||||||
|
|
||||||
|
const schema = z.object({
|
||||||
|
notificationId: z.number(),
|
||||||
|
});
|
||||||
|
|
||||||
|
export async function DELETE(request: NextRequest) {
|
||||||
|
const searchParams = request.nextUrl.searchParams;
|
||||||
|
const notificationId = schema.parse({ notificationId: searchParams.get("notificationId") });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const notification = await prisma.notificationProvider.delete({
|
||||||
|
where: { id: notificationId.notificationId },
|
||||||
|
});
|
||||||
|
|
||||||
|
return NextResponse.json(notification);
|
||||||
|
} catch (error: any) {
|
||||||
|
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