Aktueller Stand
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "../../../lib/prisma";
|
||||
import { isAdminSession, requireSession } from "../../../lib/auth-helpers";
|
||||
import { getAccessSettings } from "../../../lib/system-settings";
|
||||
|
||||
export async function GET() {
|
||||
const { session } = await requireSession();
|
||||
@@ -26,7 +27,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { name } = body || {};
|
||||
const { name, isPublic } = body || {};
|
||||
|
||||
if (!name) {
|
||||
return NextResponse.json({ error: "Name erforderlich." }, { status: 400 });
|
||||
@@ -37,8 +38,9 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ error: "Kategorie existiert bereits." }, { status: 409 });
|
||||
}
|
||||
|
||||
const { publicAccessEnabled } = await getAccessSettings();
|
||||
const category = await prisma.category.create({
|
||||
data: { name }
|
||||
data: { name, isPublic: publicAccessEnabled && isPublic === true }
|
||||
});
|
||||
|
||||
const views = await prisma.userView.findMany({
|
||||
@@ -68,25 +70,42 @@ export async function PATCH(request: Request) {
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { id, name } = body || {};
|
||||
const { id, name, isPublic } = body || {};
|
||||
|
||||
if (!id || !name) {
|
||||
return NextResponse.json({ error: "ID und Name erforderlich." }, { status: 400 });
|
||||
if (!id) {
|
||||
return NextResponse.json({ error: "ID erforderlich." }, { status: 400 });
|
||||
}
|
||||
|
||||
const trimmed = String(name).trim();
|
||||
if (!trimmed) {
|
||||
return NextResponse.json({ error: "Name erforderlich." }, { status: 400 });
|
||||
const data: { name?: string; isPublic?: boolean } = {};
|
||||
|
||||
if (name !== undefined) {
|
||||
const trimmed = String(name).trim();
|
||||
if (!trimmed) {
|
||||
return NextResponse.json({ error: "Name erforderlich." }, { status: 400 });
|
||||
}
|
||||
|
||||
const existing = await prisma.category.findUnique({ where: { name: trimmed } });
|
||||
if (existing && existing.id !== id) {
|
||||
return NextResponse.json({ error: "Kategorie existiert bereits." }, { status: 409 });
|
||||
}
|
||||
data.name = trimmed;
|
||||
}
|
||||
|
||||
const existing = await prisma.category.findUnique({ where: { name: trimmed } });
|
||||
if (existing && existing.id !== id) {
|
||||
return NextResponse.json({ error: "Kategorie existiert bereits." }, { status: 409 });
|
||||
const { publicAccessEnabled } = await getAccessSettings();
|
||||
if (publicAccessEnabled && typeof isPublic === "boolean") {
|
||||
data.isPublic = isPublic;
|
||||
}
|
||||
|
||||
if (Object.keys(data).length === 0) {
|
||||
return NextResponse.json(
|
||||
{ error: "Keine Änderungen angegeben." },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const category = await prisma.category.update({
|
||||
where: { id },
|
||||
data: { name: trimmed }
|
||||
data
|
||||
});
|
||||
|
||||
return NextResponse.json(category);
|
||||
|
||||
Reference in New Issue
Block a user