feat: contacts and voucher assignment

This commit is contained in:
opencode committed 2026-10-18 10:33:05 +02:00
1 parent c86ec8bd36
commit f2b1d0293a
8 files changed
+154 -4

No files matched your search

+25
View File
@@ -0,0 +1,25 @@
import { NextRequest, NextResponse } from "next/server";
import { getDb } from "@/lib/db";
import { validateContact } from "@/lib/contacts";
export async function GET() {
const db = getDb();
const all = await db.contact.findMany({ orderBy: { name: "asc" } });
return NextResponse.json(all);
}
export async function POST(req: NextRequest) {
const body = await req.json().catch(() => ({}));
const input = {
name: String(body.name ?? ""),
email: body.email ? String(body.email) : null,
telegramChatId: body.telegramChatId ? String(body.telegramChatId) : null,
};
const errs = validateContact(input);
if (errs.length) return NextResponse.json({ errors: errs }, { status: 400 });
const db = getDb();
const created = await db.contact.create({
data: { name: input.name.trim(), email: input.email?.trim() || null, telegramChatId: input.telegramChatId?.trim() || null },
});
return NextResponse.json(created, { status: 201 });
}