fix(schemas): use z.union + transform for teamId empty string handling
This commit is contained in:
@@ -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
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user