Gludek
Gludek
Explore posts from servers
ZZod
Created by Gludek on 5/13/2024 in #questions
Gludek - Hey,I have objects like this (there's...
It seems that it works if I do it like this
const baseData = z
.object({
adress: address,
email: z.literal('').nullish().or(z.string().email()),
name: z.string().min(3).trim(),
phoneNumber: z.string().min(9).trim(),
phonePrefix: z.string().min(1).trim(),
surname: z.string().min(3).trim(),
})
.and(
z
.object({
documentNumber: z.string().nullish(),
pesel: z.string().nullish(),
})
.superRefine((data, ctx) => {
if (!data.pesel && !data.documentNumber) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
params: {
Intl: 'peselOrDocumentNumberRequired',
},
path: ['pesel'],
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
params: {
Intl: 'peselOrDocumentNumberRequired',
},
path: ['documentNumber'],
});
}
if (data.pesel) {
if (data.pesel) {
if (data.pesel.length !== 11) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
params: {
Intl: 'invalid_pesel',
},
path: ['pesel'],
});
} else {
if (checkSum(data.pesel) !== parseInt(data.pesel[10])) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
params: {
Intl: 'invalid_pesel',
},
path: ['pesel'],
});
}
}
}
}
})
);
const baseData = z
.object({
adress: address,
email: z.literal('').nullish().or(z.string().email()),
name: z.string().min(3).trim(),
phoneNumber: z.string().min(9).trim(),
phonePrefix: z.string().min(1).trim(),
surname: z.string().min(3).trim(),
})
.and(
z
.object({
documentNumber: z.string().nullish(),
pesel: z.string().nullish(),
})
.superRefine((data, ctx) => {
if (!data.pesel && !data.documentNumber) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
params: {
Intl: 'peselOrDocumentNumberRequired',
},
path: ['pesel'],
});
ctx.addIssue({
code: z.ZodIssueCode.custom,
params: {
Intl: 'peselOrDocumentNumberRequired',
},
path: ['documentNumber'],
});
}
if (data.pesel) {
if (data.pesel) {
if (data.pesel.length !== 11) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
params: {
Intl: 'invalid_pesel',
},
path: ['pesel'],
});
} else {
if (checkSum(data.pesel) !== parseInt(data.pesel[10])) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
params: {
Intl: 'invalid_pesel',
},
path: ['pesel'],
});
}
}
}
}
})
);
13 replies
ZZod
Created by Gludek on 5/13/2024 in #questions
Gludek - Hey,I have objects like this (there's...
No description
13 replies
ZZod
Created by Gludek on 5/13/2024 in #questions
Gludek - Hey,I have objects like this (there's...
something like this
13 replies
ZZod
Created by Gludek on 5/13/2024 in #questions
Gludek - Hey,I have objects like this (there's...
patientData: [
{
baseData: {
adress: {
city: '',
country: '',
street: '',
zipCode: '',
flatNumber: '',
},
documentNumber: '',
email: '',
name: '',
pesel: '',
phoneNumber: '',
phonePrefix: '',
surname: '',
},
birthDate: undefined,
gender: false,
guardian: {
baseData: {
adress: {
city: '',
country: '',
street: '',
zipCode: '',
flatNumber: '',
},
documentNumber: '',
email: '',
name: '',
pesel: '',
phoneNumber: '',
phonePrefix: '',
surname: '',
},
ssnMode:"true",
differentAddress:false,
},
symptomes: [],
under18: undefined,
},
]
patientData: [
{
baseData: {
adress: {
city: '',
country: '',
street: '',
zipCode: '',
flatNumber: '',
},
documentNumber: '',
email: '',
name: '',
pesel: '',
phoneNumber: '',
phonePrefix: '',
surname: '',
},
birthDate: undefined,
gender: false,
guardian: {
baseData: {
adress: {
city: '',
country: '',
street: '',
zipCode: '',
flatNumber: '',
},
documentNumber: '',
email: '',
name: '',
pesel: '',
phoneNumber: '',
phonePrefix: '',
surname: '',
},
ssnMode:"true",
differentAddress:false,
},
symptomes: [],
under18: undefined,
},
]
13 replies
ZZod
Created by Gludek on 5/13/2024 in #questions
Gludek - Hey,I have objects like this (there's...
it's an empty form basically
13 replies
ZZod
Created by Gludek on 5/13/2024 in #questions
Gludek - Hey,I have objects like this (there's...
that's weird
13 replies
ZZod
Created by Gludek on 5/13/2024 in #questions
Gludek - Hey,I have objects like this (there's...
That seems to be correct but it works for the patients baseData if inner schema is not correct
13 replies
ZZod
Created by Gludek on 5/13/2024 in #questions
Gludek - Hey,I have objects like this (there's...
Even if I move superRefine onto baseData in guardian and remove nullish it's not running for some reason
13 replies
ZZod
Created by Gludek on 5/13/2024 in #questions
Gludek - Hey,I have objects like this (there's...
nope, never. Sorry for late response, totally forgot about this
13 replies
ZZod
Created by Gludek on 5/11/2024 in #questions
Gludek - Just to confirm z.string().email() can...
okay that works
8 replies
ZZod
Created by Gludek on 5/11/2024 in #questions
Gludek - Just to confirm z.string().email() can...
No description
8 replies
ZZod
Created by Gludek on 5/11/2024 in #questions
Gludek - Just to confirm z.string().email() can...
yeah, but regex validation of .email makes it so it needs to be defined, and null/undefined input is treated as invalid
8 replies
ZZod
Created by Gludek on 4/8/2024 in #questions
Gludek - Heey, can I somehow extend/merge discr...
oh well, then I'll probably nest the union then
5 replies
ZZod
Created by Gludek on 4/8/2024 in #questions
Gludek - Heey, can I somehow extend/merge discr...
I can't use .and becasue I need to extend it later to add fields based on this object
5 replies
ZZod
Created by Gludek on 7/24/2023 in #questions
Hey I have a schema where I need to
Does that sound plausible?
13 replies