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

+1 -1
View File
@@ -6,7 +6,7 @@ export async function GET(_req: NextRequest, { params }: { params: Promise<{ id:
const numId = Number(id);
if (!Number.isInteger(numId)) return NextResponse.json({ error: "not found" }, { status: 404 });
const db = getDb();
const v = await db.voucher.findUnique({ where: { id: numId } });
const v = await db.voucher.findUnique({ where: { id: numId }, include: { contacts: { include: { contact: true } } } });
if (!v) return NextResponse.json({ error: "not found" }, { status: 404 });
return NextResponse.json(v);
}
+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 });