feat(persons): extract personType + title in edit action; relax firstName for non-PERSON

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-25 21:47:09 +02:00
parent 437144174c
commit e54240ea1b

View File

@@ -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 } : {}),