Files
hoerdle/app/api/specials/route.ts

52 lines
1.6 KiB
TypeScript

import { PrismaClient, Special } from '@prisma/client';
import { NextResponse } from 'next/server';
const prisma = new PrismaClient();
export async function GET() {
const specials = await prisma.special.findMany({
orderBy: { name: 'asc' },
});
return NextResponse.json(specials);
}
export async function POST(request: Request) {
const { name, maxAttempts = 7, unlockSteps = '[2,4,7,11,16,30,60]' } = await request.json();
if (!name) {
return NextResponse.json({ error: 'Name is required' }, { status: 400 });
}
const special = await prisma.special.create({
data: {
name,
maxAttempts: Number(maxAttempts),
unlockSteps,
},
});
return NextResponse.json(special);
}
export async function DELETE(request: Request) {
const { id } = await request.json();
if (!id) {
return NextResponse.json({ error: 'ID required' }, { status: 400 });
}
await prisma.special.delete({ where: { id: Number(id) } });
return NextResponse.json({ success: true });
}
export async function PUT(request: Request) {
const { id, name, maxAttempts, unlockSteps } = await request.json();
if (!id) {
return NextResponse.json({ error: 'ID required' }, { status: 400 });
}
const updated = await prisma.special.update({
where: { id: Number(id) },
data: {
...(name && { name }),
...(maxAttempts && { maxAttempts: Number(maxAttempts) }),
...(unlockSteps && { unlockSteps }),
},
});
return NextResponse.json(updated);
}