Root cause 1 — OpenAPI types: add @Schema(requiredMode=REQUIRED) to
non-nullable fields on Person, Tag, Document, AppUser, UserGroup;
regenerate api.ts so required fields are no longer optional.
Root cause 2 — Stale types: api.ts regenerated, picking up the Tag
endpoint fix from commit 62189d8 (List<Tag> instead of List<String>).
Root cause 3 — openapi-fetch error pattern: replace `if (apiError)`
(broken when error type is never/undefined) with `if (!result.response.ok)`
across all +page.server.ts files. Cast error via `unknown` to satisfy TS.
Root cause 4 — FormData casts: add `as string` / `as string[]` to
FormData.get() / FormData.getAll() calls in admin/+page.server.ts.
Standalone fixes:
- +page.server.ts: return error field so home page template compiles
- documents/[id]/+page.svelte: type loadFile param, remove invalid iframe `type`
- conversations: type documents as Document[] instead of unknown[]
- persons/[id]: non-null assert person data after ok-check
a11y: aria-label on all icon-only buttons in TagInput and admin page,
replace invalid <label> with <p> for compound controls, remove autofocus.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
61 lines
2.3 KiB
TypeScript
61 lines
2.3 KiB
TypeScript
import { redirect } from '@sveltejs/kit';
|
|
import { createApiClient } from '$lib/api.server';
|
|
|
|
export async function load({ url, fetch }) {
|
|
const q = url.searchParams.get('q') || '';
|
|
const from = url.searchParams.get('from') || '';
|
|
const to = url.searchParams.get('to') || '';
|
|
const senderId = url.searchParams.get('senderId') || '';
|
|
const receiverId = url.searchParams.get('receiverId') || '';
|
|
const tags = url.searchParams.getAll('tag');
|
|
|
|
const api = createApiClient(fetch);
|
|
|
|
try {
|
|
const [docsResult, personsResult] = await Promise.all([
|
|
api.GET('/api/documents/search', {
|
|
params: {
|
|
query: {
|
|
q: q || undefined,
|
|
from: from || undefined,
|
|
to: to || undefined,
|
|
senderId: senderId || undefined,
|
|
receiverId: receiverId || undefined,
|
|
tag: tags.length ? tags : undefined
|
|
}
|
|
}
|
|
}),
|
|
api.GET('/api/persons')
|
|
]);
|
|
|
|
if (docsResult.response.status === 401 || personsResult.response.status === 401) {
|
|
throw redirect(302, '/login');
|
|
}
|
|
|
|
const documents = docsResult.data ?? [];
|
|
const allPersons: { id: string; firstName: string; lastName: string }[] = personsResult.data ?? [];
|
|
|
|
const senderObj = allPersons.find(p => p.id === senderId);
|
|
const receiverObj = allPersons.find(p => p.id === receiverId);
|
|
|
|
return {
|
|
documents,
|
|
initialValues: {
|
|
senderName: senderObj ? `${senderObj.firstName} ${senderObj.lastName}` : '',
|
|
receiverName: receiverObj ? `${receiverObj.firstName} ${receiverObj.lastName}` : ''
|
|
},
|
|
filters: { q, from, to, senderId, receiverId, tags },
|
|
error: null as string | null
|
|
};
|
|
} catch (e) {
|
|
if ((e as { status?: number }).status) throw e;
|
|
console.error('Error loading data:', e);
|
|
return {
|
|
documents: [],
|
|
initialValues: { senderName: '', receiverName: '' },
|
|
filters: { q, from, to, senderId, receiverId, tags },
|
|
error: 'Daten konnten nicht geladen werden.' as string | null
|
|
};
|
|
}
|
|
}
|