Add custom commission types

This commit is contained in:
2026-02-01 16:21:20 +01:00
parent e869f19142
commit 2015ea6f2e
19 changed files with 1180 additions and 1 deletions

View File

@ -7,6 +7,7 @@ import { z } from "zod/v4";
const payloadSchema = z.object({
typeId: z.string().min(1).optional().nullable(),
customCardId: z.string().min(1).optional().nullable(),
optionId: z.string().min(1).optional().nullable(),
extraIds: z.array(z.string().min(1)).default([]),
@ -14,6 +15,23 @@ const payloadSchema = z.object({
customerEmail: z.string().email().max(320),
customerSocials: z.string().max(2000).optional().nullable(),
message: z.string().min(1).max(20_000),
}).superRefine((data, ctx) => {
const hasType = Boolean(data.typeId);
const hasCustom = Boolean(data.customCardId);
if (!hasType && !hasCustom) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["typeId"],
message: "Missing commission type or custom card",
});
}
if (hasType && hasCustom) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
path: ["typeId"],
message: "Only one of typeId or customCardId is allowed",
});
}
});
function safeJsonParse(input: string) {
@ -83,6 +101,7 @@ export async function POST(request: Request) {
message: payload.data.message,
typeId: payload.data.typeId ?? null,
customCardId: payload.data.customCardId ?? null,
optionId: payload.data.optionId ?? null,
ipAddress,