From e54240ea1bd3cdefed4bf9b6e76fb7156eb00194 Mon Sep 17 00:00:00 2001 From: Marcel Date: Sat, 25 Apr 2026 21:47:09 +0200 Subject: [PATCH] feat(persons): extract personType + title in edit action; relax firstName for non-PERSON Co-Authored-By: Claude Sonnet 4.6 --- .../routes/persons/[id]/edit/+page.server.ts | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/frontend/src/routes/persons/[id]/edit/+page.server.ts b/frontend/src/routes/persons/[id]/edit/+page.server.ts index dd9fd1af..2d01ce1f 100644 --- a/frontend/src/routes/persons/[id]/edit/+page.server.ts +++ b/frontend/src/routes/persons/[id]/edit/+page.server.ts @@ -30,6 +30,12 @@ export async function load({ params, fetch, locals }) { export const actions = { update: async ({ request, params, fetch }) => { const formData = await request.formData(); + const personType = (formData.get('personType')?.toString() ?? 'PERSON') as + | 'PERSON' + | 'INSTITUTION' + | 'GROUP' + | 'UNKNOWN'; + const title = formData.get('title')?.toString().trim() || undefined; const firstName = formData.get('firstName')?.toString().trim(); const lastName = formData.get('lastName')?.toString().trim(); const alias = formData.get('alias')?.toString().trim() || undefined; @@ -39,15 +45,20 @@ export const actions = { const birthYear = birthYearStr ? parseInt(birthYearStr, 10) : undefined; const deathYear = deathYearStr ? parseInt(deathYearStr, 10) : undefined; - if (!firstName || !lastName) { - return fail(400, { updateError: 'Vor- und Nachname sind Pflichtfelder.' }); + if (!lastName) { + return fail(400, { updateError: 'Nachname ist Pflichtfeld.' }); + } + if (personType === 'PERSON' && !firstName) { + return fail(400, { updateError: 'Vorname ist Pflichtfeld.' }); } const api = createApiClient(fetch); const result = await api.PUT('/api/persons/{id}', { params: { path: { id: params.id } }, body: { - firstName, + personType, + ...(title ? { title } : {}), + ...(firstName ? { firstName } : {}), lastName, ...(alias ? { alias } : {}), ...(notes ? { notes } : {}),