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

+4
View File
@@ -33,6 +33,9 @@ export async function POST(req: NextRequest) {
const errs = validateVoucher(input);
if (errs.length) return NextResponse.json({ errors: errs }, { status: 400 });
const db = getDb();
const contactIds: number[] = Array.isArray(body.contactIds)
? body.contactIds.map(Number).filter((n: number) => Number.isInteger(n))
: [];
const created = await db.voucher.create({
data: {
name: input.name.trim(),
@@ -43,6 +46,7 @@ export async function POST(req: NextRequest) {
codeText: input.codeText,
kategorie: input.kategorie,
notiz: input.notiz,
contacts: contactIds.length ? { create: contactIds.map((contactId) => ({ contactId })) } : undefined,
},
});
return NextResponse.json(created, { status: 201 });