refactor(persons): export normalizePersonType from edit server module

Tests now import from production code instead of a local copy, giving real
regression protection if the inline logic is changed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-04-26 00:39:21 +02:00
committed by marcel
parent 7ef1ab3b01
commit 1f19fa3462
2 changed files with 8 additions and 7 deletions

View File

@@ -2,6 +2,12 @@ import { error, fail, redirect } from '@sveltejs/kit';
import { createApiClient } from '$lib/api.server';
import { getErrorMessage } from '$lib/errors';
type PersonType = 'PERSON' | 'INSTITUTION' | 'GROUP' | 'UNKNOWN' | 'SKIP';
export function normalizePersonType(raw: string | undefined | null): Exclude<PersonType, 'SKIP'> {
return raw === 'SKIP' ? 'UNKNOWN' : ((raw ?? 'PERSON') as Exclude<PersonType, 'SKIP'>);
}
export async function load({ params, fetch, locals }) {
const canWrite =
(locals.user as { groups?: { permissions: string[] }[] } | undefined)?.groups?.some((g) =>
@@ -23,7 +29,7 @@ export async function load({ params, fetch, locals }) {
}
const person = result.data!;
const personType = person.personType === 'SKIP' ? 'UNKNOWN' : person.personType;
const personType = normalizePersonType(person.personType);
return { person: { ...person, personType }, aliases: aliasesResult.data ?? [] };
}