Implement Specials feature, Admin UI enhancements, and Database Rebuild tool
This commit is contained in:
51
app/api/specials/route.ts
Normal file
51
app/api/specials/route.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user