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:
@@ -30,6 +30,12 @@ export async function load({ params, fetch, locals }) {
|
|||||||
export const actions = {
|
export const actions = {
|
||||||
update: async ({ request, params, fetch }) => {
|
update: async ({ request, params, fetch }) => {
|
||||||
const formData = await request.formData();
|
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 firstName = formData.get('firstName')?.toString().trim();
|
||||||
const lastName = formData.get('lastName')?.toString().trim();
|
const lastName = formData.get('lastName')?.toString().trim();
|
||||||
const alias = formData.get('alias')?.toString().trim() || undefined;
|
const alias = formData.get('alias')?.toString().trim() || undefined;
|
||||||
@@ -39,15 +45,20 @@ export const actions = {
|
|||||||
const birthYear = birthYearStr ? parseInt(birthYearStr, 10) : undefined;
|
const birthYear = birthYearStr ? parseInt(birthYearStr, 10) : undefined;
|
||||||
const deathYear = deathYearStr ? parseInt(deathYearStr, 10) : undefined;
|
const deathYear = deathYearStr ? parseInt(deathYearStr, 10) : undefined;
|
||||||
|
|
||||||
if (!firstName || !lastName) {
|
if (!lastName) {
|
||||||
return fail(400, { updateError: 'Vor- und Nachname sind Pflichtfelder.' });
|
return fail(400, { updateError: 'Nachname ist Pflichtfeld.' });
|
||||||
|
}
|
||||||
|
if (personType === 'PERSON' && !firstName) {
|
||||||
|
return fail(400, { updateError: 'Vorname ist Pflichtfeld.' });
|
||||||
}
|
}
|
||||||
|
|
||||||
const api = createApiClient(fetch);
|
const api = createApiClient(fetch);
|
||||||
const result = await api.PUT('/api/persons/{id}', {
|
const result = await api.PUT('/api/persons/{id}', {
|
||||||
params: { path: { id: params.id } },
|
params: { path: { id: params.id } },
|
||||||
body: {
|
body: {
|
||||||
firstName,
|
personType,
|
||||||
|
...(title ? { title } : {}),
|
||||||
|
...(firstName ? { firstName } : {}),
|
||||||
lastName,
|
lastName,
|
||||||
...(alias ? { alias } : {}),
|
...(alias ? { alias } : {}),
|
||||||
...(notes ? { notes } : {}),
|
...(notes ? { notes } : {}),
|
||||||
|
|||||||
Reference in New Issue
Block a user