mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Check Notification Test Status
This commit is contained in:
33
app/api/notifications/test/get/route.ts
Normal file
33
app/api/notifications/test/get/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({
|
||||
notificationTestId: z.string()
|
||||
})
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const searchParams = request.nextUrl.searchParams;
|
||||
const notificationTestId = schema.parse({ notificationTestId: searchParams.get('notificationTestId') });
|
||||
|
||||
if(!notificationTestId) {
|
||||
return NextResponse.json({ error: "Notification test ID is required" }, { status: 400 });
|
||||
}
|
||||
|
||||
const notificationTest = await prisma.notificationTest.findUnique({
|
||||
where: { id: parseInt(notificationTestId.notificationTestId) }
|
||||
})
|
||||
|
||||
if(!notificationTest) {
|
||||
return NextResponse.json({ error: "Notification test not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ notificationTest }, { status: 200 });
|
||||
} 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