Initial commit: JuanitoSport - Muay Thai & Yog4Fight PWA
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { requireAdmin } from "@/lib/session";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const admin = await requireAdmin();
|
||||
if (!admin) return NextResponse.json({ error: "Admin requis" }, { status: 403 });
|
||||
|
||||
try {
|
||||
const tiers = await prisma.yogaTier.findMany({ orderBy: { numberOfSessions: "asc" } });
|
||||
return NextResponse.json(tiers);
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Erreur" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const admin = await requireAdmin();
|
||||
if (!admin) return NextResponse.json({ error: "Admin requis" }, { status: 403 });
|
||||
|
||||
const { name, numberOfSessions, priceTotal } = await req.json();
|
||||
if (!name || !numberOfSessions || !priceTotal) {
|
||||
return NextResponse.json({ error: "Champs requis" }, { status: 400 });
|
||||
}
|
||||
|
||||
try {
|
||||
const tier = await prisma.yogaTier.create({
|
||||
data: { name, numberOfSessions: Number(numberOfSessions), priceTotal: Number(priceTotal) },
|
||||
});
|
||||
return NextResponse.json(tier, { status: 201 });
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Erreur" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user