Add slots based per class, admin courses mgmt, admin roles, horizontal nav/landing, glove favicon
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
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 });
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { requireAdmin } from "@/lib/session";
|
||||
import bcrypt from "bcryptjs";
|
||||
|
||||
export async function PATCH(req: NextRequest) {
|
||||
const admin = await requireAdmin();
|
||||
@@ -10,7 +11,7 @@ export async function PATCH(req: NextRequest) {
|
||||
if (!id) return NextResponse.json({ error: "id requis" }, { status: 400 });
|
||||
|
||||
const allowed = [
|
||||
"name", "email", "isMuayThai", "isYoga", "role", "phone", "avatar"
|
||||
"name", "email", "isMuayThai", "isYoga", "role", "phone", "avatar", "password"
|
||||
];
|
||||
|
||||
const updateData: any = {};
|
||||
@@ -20,6 +21,16 @@ export async function PATCH(req: NextRequest) {
|
||||
|
||||
if (updateData.email) updateData.email = updateData.email.toLowerCase();
|
||||
|
||||
if (updateData.password) {
|
||||
if (updateData.password.length < 6) {
|
||||
return NextResponse.json(
|
||||
{ error: "Le mot de passe doit contenir au moins 6 caractères" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
updateData.password = await bcrypt.hash(updateData.password, 10);
|
||||
}
|
||||
|
||||
try {
|
||||
if (updateData.isMuayThai === true) {
|
||||
await prisma.muayThaiProfile.upsert({
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
|
||||
export async function GET() {
|
||||
try {
|
||||
const slots = await prisma.classSlot.findMany({
|
||||
orderBy: { label: "asc" },
|
||||
});
|
||||
return NextResponse.json(slots);
|
||||
} catch {
|
||||
return NextResponse.json({ error: "Erreur" }, { status: 500 });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user