Some checks failed
CI / Unit & Component Tests (push) Has been cancelled
CI / Backend Unit Tests (push) Has been cancelled
CI / E2E Tests (push) Has been cancelled
CI / Unit & Component Tests (pull_request) Successful in 2m30s
CI / Backend Unit Tests (pull_request) Failing after 2m37s
CI / E2E Tests (pull_request) Failing after 1h21m43s
- Cast PersonSummaryDTO array to concrete type in +page.server.ts (all fields are optional in the generated type but always populated at runtime) - Cast mockLocals/mockLocalsWriter to `any` in persons detail spec to match the pre-existing test pattern used throughout the codebase - Add .svelte-kit-backup/ to .gitignore and .prettierignore to prevent lint failures from Docker-owned leftover .svelte-kit directory Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
108 lines
3.4 KiB
TypeScript
108 lines
3.4 KiB
TypeScript
import { redirect } from '@sveltejs/kit';
|
|
import { createApiClient } from '$lib/api.server';
|
|
import type { components } from '$lib/generated/api';
|
|
|
|
type IncompleteDocumentDTO = components['schemas']['IncompleteDocumentDTO'];
|
|
type NotificationDTO = components['schemas']['NotificationDTO'];
|
|
type Document = components['schemas']['Document'];
|
|
|
|
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 isDashboard = !q && !from && !to && !senderId && !receiverId && !tags.length;
|
|
|
|
const api = createApiClient(fetch);
|
|
|
|
try {
|
|
const [docsResult, personsResult] = await Promise.all([
|
|
isDashboard
|
|
? Promise.resolve(null)
|
|
: 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 (personsResult.response.status === 401) {
|
|
throw redirect(302, '/login');
|
|
}
|
|
if (docsResult && docsResult.response.status === 401) {
|
|
throw redirect(302, '/login');
|
|
}
|
|
|
|
const documents: Document[] = docsResult?.data ?? [];
|
|
const allPersons = (personsResult.data ?? []) as {
|
|
id: string;
|
|
firstName: string;
|
|
lastName: string;
|
|
}[];
|
|
|
|
const senderObj = allPersons.find((p) => p.id === senderId);
|
|
const receiverObj = allPersons.find((p) => p.id === receiverId);
|
|
|
|
// Dashboard widgets — failures are isolated and don't crash the page
|
|
let mentions: NotificationDTO[] = [];
|
|
let incompleteDocs: IncompleteDocumentDTO[] = [];
|
|
let recentDocs: Document[] = [];
|
|
|
|
if (isDashboard) {
|
|
const [mentionsResult, incompleteResult, recentResult] = await Promise.allSettled([
|
|
api.GET('/api/notifications', { params: { query: { size: 5 } } }),
|
|
api.GET('/api/documents/incomplete', { params: { query: { size: 5 } } }),
|
|
api.GET('/api/documents/recent-activity', { params: { query: { size: 5 } } })
|
|
]);
|
|
|
|
if (mentionsResult.status === 'fulfilled' && mentionsResult.value.response.ok) {
|
|
mentions = mentionsResult.value.data?.content ?? [];
|
|
}
|
|
if (incompleteResult.status === 'fulfilled' && incompleteResult.value.response.ok) {
|
|
incompleteDocs = incompleteResult.value.data ?? [];
|
|
}
|
|
if (recentResult.status === 'fulfilled' && recentResult.value.response.ok) {
|
|
recentDocs = recentResult.value.data ?? [];
|
|
}
|
|
}
|
|
|
|
return {
|
|
isDashboard,
|
|
documents,
|
|
mentions,
|
|
incompleteDocs,
|
|
recentDocs,
|
|
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 {
|
|
isDashboard,
|
|
documents: [],
|
|
mentions: [],
|
|
incompleteDocs: [],
|
|
recentDocs: [],
|
|
initialValues: { senderName: '', receiverName: '' },
|
|
filters: { q, from, to, senderId, receiverId, tags },
|
|
error: 'Daten konnten nicht geladen werden.' as string | null
|
|
};
|
|
}
|
|
}
|