Files
homepage/src/routes/mario-kart/+page.server.ts
Alexander Bocken 8dd1e3852e refactor: consolidate formatting utilities and add testing infrastructure
- Replace 8 duplicate formatCurrency functions with shared utility
- Add comprehensive formatter utilities (currency, date, number, etc.)
- Set up Vitest for unit testing with 38 passing tests
- Set up Playwright for E2E testing
- Consolidate database connection to single source (src/utils/db.ts)
- Add auth middleware helpers to reduce code duplication
- Fix display bug: remove spurious minus sign in recent activity amounts
- Add path aliases for cleaner imports ($utils, $models)
- Add project documentation (CODEMAP.md, REFACTORING_PLAN.md)

Test coverage: 38 unit tests passing
Build: successful with no breaking changes
2025-11-18 15:24:22 +01:00

25 lines
709 B
TypeScript

import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
import { dbConnect } from '$utils/db';
import { MarioKartTournament } from '$models/MarioKartTournament';
export const load: PageServerLoad = async () => {
try {
await dbConnect();
const tournaments = await MarioKartTournament.find()
.sort({ createdAt: -1 })
.lean({ flattenMaps: true });
// Convert MongoDB documents to plain objects for serialization
const serializedTournaments = JSON.parse(JSON.stringify(tournaments));
return {
tournaments: serializedTournaments
};
} catch (err) {
console.error('Error loading tournaments:', err);
throw error(500, 'Failed to load tournaments');
}
};