Skip to content

Commit

Permalink
fix: lastNamePrefix
Browse files Browse the repository at this point in the history
  • Loading branch information
DJ1TJOO committed Aug 14, 2024
1 parent aa5685e commit 7cd715f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,20 @@ export async function updatePerson(
) {
const expectedSchema = z.object({
firstName: z.string().trim().min(1),
lastNamePrefix: z
.string()
.trim()
.nullable()
.transform((tussenvoegsel) =>
tussenvoegsel === "" ? null : tussenvoegsel,
),
lastNamePrefix: z.string().trim().nullable().default(null),
lastName: z.string().min(1),
dateOfBirth: z.string().pipe(z.coerce.date()),
birthCity: z.string(),
birthCountry: z.string().length(2).toLowerCase(),
});

const data: Record<string, FormDataEntryValue | null> = Object.fromEntries(
formData.entries(),
);
const data: Record<string, FormDataEntryValue | undefined> =
Object.fromEntries(formData.entries());

// Set all empty strings to null
// Set all empty strings to undefined
for (const key in data) {
if (data[key] === "") {
data[key] = null;
data[key] = undefined;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,28 +18,20 @@ export async function createPerson(
const expectedSchema = z.object({
email: z.string().trim().toLowerCase().email().optional(),
firstName: z.string().trim().min(1),
lastNamePrefix: z
.string()
.trim()
.nullable()
.transform((tussenvoegsel) =>
tussenvoegsel === "" ? null : tussenvoegsel,
)
.optional(),
lastNamePrefix: z.string().trim().nullable().default(null),
lastName: z.string().min(1).optional(),
dateOfBirth: z.string().pipe(z.coerce.date()).optional(),
birthCity: z.string().optional(),
birthCountry: z.string().length(2).toLowerCase().optional(),
});

const data: Record<string, FormDataEntryValue | null> = Object.fromEntries(
formData.entries(),
);
const data: Record<string, FormDataEntryValue | undefined> =
Object.fromEntries(formData.entries());

// Set all empty strings to null
// Set all empty strings to undefined
for (const key in data) {
if (data[key] === "") {
data[key] = null;
data[key] = undefined;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function createPerson(
.object({
email: z.string().trim().toLowerCase().email().optional(),
firstName: z.string().trim().min(1),
lastNamePrefix: z.string().trim().nullable().optional(),
lastNamePrefix: z.string().trim().nullable().default(null),
lastName: z.string().min(1).optional(),
dateOfBirth: z.string().pipe(z.coerce.date()).optional(),
birthCity: z.string().optional(),
Expand Down Expand Up @@ -172,7 +172,7 @@ export async function updatePerson(
) {
const expectedSchema = z.object({
firstName: z.string().trim().min(1),
lastNamePrefix: z.string().trim().nullable().optional(),
lastNamePrefix: z.string().trim().nullable().default(null),
lastName: z.string().min(1).optional(),
dateOfBirth: z.string().pipe(z.coerce.date()).optional(),
birthCity: z.string().optional(),
Expand All @@ -187,10 +187,6 @@ export async function updatePerson(
if (data[key] === "") {
data[key] = undefined;
}

if (data[key] === null && key !== "lastNamePrefix") {
data[key] = undefined;
}
}

try {
Expand Down

0 comments on commit 7cd715f

Please sign in to comment.