- Implémentation complète du système d'administration (/admin) - Gestion des clients avec base de données JSON - Génération de token unique et QR code pour chaque client - Intégration des données client dans l'application (bungalow, WiFi, message) - Amélioration du composant WifiCard avec fallback de copie - Optimisation du hook useClientData pour chargement immédiat - Ajout de la variable d'environnement ADMIN_PASSWORD
61 lines
1.5 KiB
TypeScript
61 lines
1.5 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import {
|
|
createClient,
|
|
loadClients,
|
|
updateClient,
|
|
deleteClient,
|
|
validateEmail,
|
|
} from "@/lib/admin/client-utils";
|
|
import { requireAdminAuth } from "@/lib/admin/auth";
|
|
import { ClientInput } from "@/lib/types/client";
|
|
|
|
export async function GET(request: Request) {
|
|
if (!requireAdminAuth(request)) {
|
|
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
|
|
}
|
|
|
|
const clients = loadClients();
|
|
return NextResponse.json(clients);
|
|
}
|
|
|
|
export async function POST(request: Request) {
|
|
if (!requireAdminAuth(request)) {
|
|
return NextResponse.json({ error: "Non autorisé" }, { status: 401 });
|
|
}
|
|
|
|
try {
|
|
const body: ClientInput = await request.json();
|
|
|
|
// Validation
|
|
if (!body.email || !validateEmail(body.email)) {
|
|
return NextResponse.json(
|
|
{ error: "Email invalide" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
if (!body.bungalowNumber) {
|
|
return NextResponse.json(
|
|
{ error: "Numéro de bungalow requis" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const client = createClient({
|
|
email: body.email,
|
|
bungalowNumber: body.bungalowNumber,
|
|
wifiName: body.wifiName || "Lagon-WiFi",
|
|
wifiPassword: body.wifiPassword || "",
|
|
gerantMessage: body.gerantMessage || "Bienvenue dans notre pension de famille !",
|
|
});
|
|
|
|
return NextResponse.json(client, { status: 201 });
|
|
} catch (error: any) {
|
|
return NextResponse.json(
|
|
{ error: error.message || "Erreur lors de la création du client" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
}
|
|
|