mirror of
https://github.com/crocofied/CoreControl.git
synced 2025-12-29 16:14:43 +00:00
Notification Settings card
This commit is contained in:
@@ -3,6 +3,7 @@ import prisma from "@/app/prisma";
|
||||
import { z } from "zod/v4"
|
||||
|
||||
const schema = z.object({
|
||||
enabled: z.boolean(),
|
||||
statusChange: z.boolean(),
|
||||
latencyLimit: z.number().min(0).max(100),
|
||||
notificationTextStatus: z.string(),
|
||||
@@ -13,18 +14,18 @@ const schema = z.object({
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency } = schema.parse(body);
|
||||
const { enabled, statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency } = schema.parse(body);
|
||||
|
||||
const existingNotification = await prisma.applicationMonitoringNotification.findFirst();
|
||||
if(!existingNotification) {
|
||||
const notification = await prisma.applicationMonitoringNotification.create({
|
||||
data: { statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency },
|
||||
data: { enabled, statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency },
|
||||
});
|
||||
return NextResponse.json({ notification }, { status: 200 });
|
||||
} else {
|
||||
const notification = await prisma.applicationMonitoringNotification.update({
|
||||
where: { id: existingNotification.id },
|
||||
data: { statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency },
|
||||
data: { enabled, statusChange, latencyLimit, notificationTextStatus, notificationTextLatency, notificationLatency },
|
||||
});
|
||||
return NextResponse.json({ notification }, { status: 200 });
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import prisma from "@/app/prisma";
|
||||
import { z } from "zod/v4"
|
||||
|
||||
const schema = z.object({
|
||||
enabled: z.boolean(),
|
||||
statusChange: z.boolean(),
|
||||
cpuLimit: z.number().min(0).max(100),
|
||||
gpuLimit: z.number().min(0).max(100),
|
||||
@@ -25,18 +26,18 @@ const schema = z.object({
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature } = schema.parse(body);
|
||||
const { enabled, statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature } = schema.parse(body);
|
||||
|
||||
const existingNotification = await prisma.serverMonitoringNotification.findFirst();
|
||||
if(!existingNotification) {
|
||||
const notification = await prisma.serverMonitoringNotification.create({
|
||||
data: { statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature },
|
||||
data: { enabled, statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature },
|
||||
});
|
||||
return NextResponse.json({ notification }, { status: 200 });
|
||||
} else {
|
||||
const notification = await prisma.serverMonitoringNotification.update({
|
||||
where: { id: existingNotification.id },
|
||||
data: { statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature },
|
||||
data: { enabled, statusChange, cpuLimit, gpuLimit, memoryLimit, diskLimit, temperatureLimit, notificationTextStatus, notificationTextCpu, notificationTextGpu, notificationTextMemory, notificationTextDisk, notificationTextTemperature, notificationCpu, notificationGpu, notificationMemory, notificationDisk, notificationTemperature },
|
||||
});
|
||||
return NextResponse.json({ notification }, { status: 200 });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user