mirror of
https://github.com/arthur-pbty/contact.git
synced 2026-06-03 15:07:21 +02:00
f63eeb2e84
- Implemented a contact page with a form for user inquiries. - Added validation for form fields using Zod schema. - Integrated PostgreSQL database for storing contact messages. - Created necessary API endpoints for form submission. - Added admin authentication and session management. - Developed CGU, cookies policy, privacy policy, and legal mentions pages. - Set up Docker configuration for PostgreSQL and application services. - Enhanced UI with responsive design and accessibility features.
34 lines
1.1 KiB
TypeScript
34 lines
1.1 KiB
TypeScript
import { NextResponse } from "next/server";
|
|
import { isAdminAuthenticated } from "@/lib/admin-auth";
|
|
import { setMessageStatus } from "@/lib/db";
|
|
|
|
export async function POST(
|
|
request: Request,
|
|
context: { params: Promise<{ id: string }> },
|
|
) {
|
|
const authenticated = await isAdminAuthenticated();
|
|
if (!authenticated) {
|
|
return NextResponse.json({ message: "Unauthorized" }, { status: 401 });
|
|
}
|
|
|
|
const { id } = await context.params;
|
|
const messageId = Number(id);
|
|
if (!Number.isInteger(messageId) || messageId <= 0) {
|
|
return NextResponse.json({ message: "ID invalide." }, { status: 400 });
|
|
}
|
|
|
|
const body = (await request.json().catch(() => null)) as { status?: string } | null;
|
|
const status = body?.status;
|
|
|
|
if (status !== "pending" && status !== "replied") {
|
|
return NextResponse.json({ message: "Statut invalide." }, { status: 400 });
|
|
}
|
|
|
|
const updated = await setMessageStatus(messageId, status);
|
|
if (!updated) {
|
|
return NextResponse.json({ message: "Message introuvable." }, { status: 404 });
|
|
}
|
|
|
|
return NextResponse.json({ ok: true });
|
|
}
|