fix: final review wave (reminder-400, contact-400, soon-30, cron-claim, edge-session)
This commit is contained in:
1 parent
39f782057c
commit
98387bd2d2
10 files changed
+122
-29
No files matched your search
@@ -37,6 +37,23 @@ export async function POST(req: NextRequest) {
|
||||
const contactIds: number[] = Array.isArray(body.contactIds)
|
||||
? body.contactIds.map(Number).filter((n: number) => Number.isInteger(n))
|
||||
: [];
|
||||
if (contactIds.length) {
|
||||
const found = await db.contact.findMany({ where: { id: { in: contactIds } }, select: { id: true } });
|
||||
if (found.length !== new Set(contactIds).size) {
|
||||
return NextResponse.json({ errors: ["contactIds"] }, { status: 400 });
|
||||
}
|
||||
}
|
||||
const reminderRaw =
|
||||
typeof body.reminderDays === "string"
|
||||
? body.reminderDays
|
||||
: Array.isArray(body.reminderDays)
|
||||
? body.reminderDays.join(",")
|
||||
: undefined;
|
||||
const reminderProvided = reminderRaw !== undefined && reminderRaw.trim() !== "";
|
||||
const reminderDays = parseReminderDays(reminderRaw);
|
||||
if (reminderProvided && reminderDays.length === 0) {
|
||||
return NextResponse.json({ errors: ["reminderDays"] }, { status: 400 });
|
||||
}
|
||||
const created = await db.voucher.create({
|
||||
data: {
|
||||
name: input.name.trim(),
|
||||
@@ -49,9 +66,7 @@ export async function POST(req: NextRequest) {
|
||||
notiz: input.notiz,
|
||||
contacts: contactIds.length ? { create: contactIds.map((contactId) => ({ contactId })) } : undefined,
|
||||
rules: {
|
||||
create: parseReminderDays(
|
||||
typeof body.reminderDays === "string" ? body.reminderDays : Array.isArray(body.reminderDays) ? body.reminderDays.join(",") : undefined
|
||||
).map((tageVorher) => ({ tageVorher })),
|
||||
create: reminderDays.map((tageVorher) => ({ tageVorher })),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user