fix(schemas): use z.union + transform for teamId empty string handling

This commit is contained in:
2026-06-26 02:21:25 +02:00
parent 58b821b198
commit 290b66fec1
2 changed files with 21 additions and 24 deletions
+5 -8
View File
@@ -22,14 +22,11 @@ function buildPersonBaseSchema(copy: PersonSchemaCopy) {
lastName: z.string().min(1, {
error: copy.lastNameRequired,
}),
teamId: z.preprocess(
(val) => (val === "" ? null : val),
z
.string()
.uuid({ error: copy.teamIdInvalid })
.optional()
.nullable(),
),
teamId: z
.union([z.string().uuid({ error: copy.teamIdInvalid }), z.literal("")])
.transform((val) => (val === "" ? null : val))
.nullable()
.optional(),
email: z.string().optional().nullable(),
phone: z.string().optional().nullable(),
userId: z
+16 -16
View File
@@ -92,14 +92,14 @@ export function buildUnifiedUpdateSchema(copy: UnifiedSchemaCopy) {
id: z.string().nonempty(copy.idRequired),
firstName: z.string().trim().min(1, { error: copy.firstNameRequired }),
lastName: z.string().trim().min(1, { error: copy.lastNameRequired }),
teamId: z.preprocess(
(val) => (val === "" ? null : val),
z
.string()
.uuid({ error: copy.teamIdInvalid })
.optional()
.nullable(),
),
teamId: z
.union([
z.string().uuid({ error: copy.teamIdInvalid }),
z.literal(""),
])
.transform((val) => (val === "" ? null : val))
.nullable()
.optional(),
email: z
.union([z.email({ error: copy.emailInvalid }), z.literal(""), z.null()])
.optional(),
@@ -133,14 +133,14 @@ export function buildUnifiedCreateSchema(copy: UnifiedSchemaCopy) {
.object({
firstName: z.string().trim().min(1, { error: copy.firstNameRequired }),
lastName: z.string().trim().min(1, { error: copy.lastNameRequired }),
teamId: z.preprocess(
(val) => (val === "" ? null : val),
z
.string()
.uuid({ error: copy.teamIdInvalid })
.optional()
.nullable(),
),
teamId: z
.union([
z.string().uuid({ error: copy.teamIdInvalid }),
z.literal(""),
])
.transform((val) => (val === "" ? null : val))
.nullable()
.optional(),
email: z.email({ error: copy.emailInvalid }),
phone: z.string().optional().nullable(),
role: unifiedFormRoleSchema,