42 lines
1.4 KiB
TypeScript
42 lines
1.4 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { prisma } from "@/lib/prisma";
|
|
import { requireAdmin } from "@/lib/session";
|
|
|
|
export async function PATCH(req: NextRequest) {
|
|
const admin = await requireAdmin();
|
|
if (!admin) return NextResponse.json({ error: "Admin requis" }, { status: 403 });
|
|
|
|
const { id, name, numberOfSessions, priceTotal, isActive } = await req.json();
|
|
if (!id) return NextResponse.json({ error: "id requis" }, { status: 400 });
|
|
|
|
try {
|
|
const tier = await prisma.yogaTier.update({
|
|
where: { id },
|
|
data: {
|
|
...(name !== undefined ? { name } : {}),
|
|
...(numberOfSessions !== undefined ? { numberOfSessions: Number(numberOfSessions) } : {}),
|
|
...(priceTotal !== undefined ? { priceTotal: Number(priceTotal) } : {}),
|
|
...(isActive !== undefined ? { isActive } : {}),
|
|
},
|
|
});
|
|
return NextResponse.json(tier);
|
|
} catch {
|
|
return NextResponse.json({ error: "Erreur" }, { status: 500 });
|
|
}
|
|
}
|
|
|
|
export async function DELETE(req: NextRequest) {
|
|
const admin = await requireAdmin();
|
|
if (!admin) return NextResponse.json({ error: "Admin requis" }, { status: 403 });
|
|
|
|
const { id } = await req.json();
|
|
if (!id) return NextResponse.json({ error: "id requis" }, { status: 400 });
|
|
|
|
try {
|
|
await prisma.yogaTier.delete({ where: { id } });
|
|
return NextResponse.json({ ok: true });
|
|
} catch {
|
|
return NextResponse.json({ error: "Erreur" }, { status: 500 });
|
|
}
|
|
}
|