This commit is contained in:
@@ -1,15 +0,0 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
|
||||
export async function DELETE(_: Request, context: { params: Promise<{ id: string }> }) {
|
||||
const { id } = await context.params;
|
||||
// 파트너가 참조 중이면 삭제 실패(외래키 제약), 클라이언트에서 안내 필요
|
||||
try {
|
||||
await prisma.partnerType.delete({ where: { typeId: id } });
|
||||
return NextResponse.json({ ok: true });
|
||||
} catch (e) {
|
||||
return NextResponse.json({ error: "type_in_use" }, { status: 409 });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { z } from "zod";
|
||||
|
||||
export async function GET() {
|
||||
const types = await prisma.partnerType.findMany({ orderBy: { createdAt: "desc" } });
|
||||
return NextResponse.json({ types });
|
||||
}
|
||||
|
||||
const createSchema = z.object({ name: z.string().min(1).max(50) });
|
||||
|
||||
export async function POST(req: Request) {
|
||||
const body = await req.json().catch(() => ({}));
|
||||
const parsed = createSchema.safeParse(body);
|
||||
if (!parsed.success) return NextResponse.json({ error: parsed.error.flatten() }, { status: 400 });
|
||||
const type = await prisma.partnerType.create({ data: { name: parsed.data.name } });
|
||||
return NextResponse.json({ type }, { status: 201 });
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user