Files
juanitosport/app/api/admin/classes/route.ts
T

26 lines
951 B
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, capacity, booked, isFull } = await req.json();
if (!id) return NextResponse.json({ error: "id requis" }, { status: 400 });
try {
const slot = await prisma.classSlot.update({
where: { id },
data: {
...(capacity !== undefined ? { capacity: Math.max(0, Number(capacity)) } : {}),
...(booked !== undefined ? { booked: Math.max(0, Number(booked)) } : {}),
...(isFull !== undefined ? { isFull: !!isFull } : {}),
},
});
return NextResponse.json(slot);
} catch (error) {
console.error(error);
return NextResponse.json({ error: "Erreur" }, { status: 500 });
}
}