refactor(persons): centralise PersonType, PERSON_TYPES and normalizePersonType in person-validation

Removes four independent PersonType type declarations and the duplicated
TYPES/PERSON_TYPES arrays. normalizePersonType moves from the edit route
module into the shared lib so page.server.test.ts no longer imports from a
route. Both server actions now use normalizePersonType for personType
extraction instead of an inline type cast.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-26 10:22:52 +02:00
parent 842ab28f59
commit 8e1733abbf
7 changed files with 15 additions and 28 deletions

View File

@@ -1,7 +1,7 @@
import { error, fail, redirect } from '@sveltejs/kit';
import { createApiClient } from '$lib/api.server';
import { getErrorMessage } from '$lib/errors';
import { validatePersonFields } from '$lib/person-validation';
import { normalizePersonType, validatePersonFields } from '$lib/person-validation';
export async function load({ locals }: { locals: App.Locals }) {
const canWrite =
@@ -14,11 +14,7 @@ export async function load({ locals }: { locals: App.Locals }) {
export const actions = {
default: async ({ request, fetch }) => {
const formData = await request.formData();
const personType = (formData.get('personType')?.toString() ?? 'PERSON') as
| 'PERSON'
| 'INSTITUTION'
| 'GROUP'
| 'UNKNOWN';
const personType = normalizePersonType(formData.get('personType')?.toString());
const title = formData.get('title')?.toString().trim() || undefined;
const firstName = formData.get('firstName')?.toString().trim();
const lastName = formData.get('lastName')?.toString().trim();