- 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
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
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 ({ params }) => {
|
|
try {
|
|
await dbConnect();
|
|
|
|
// Use lean with flattenMaps option to convert Map objects to plain objects
|
|
const tournament = await MarioKartTournament.findById(params.id).lean({ flattenMaps: true });
|
|
|
|
if (!tournament) {
|
|
throw error(404, 'Tournament not found');
|
|
}
|
|
|
|
console.log('=== SERVER LOAD DEBUG ===');
|
|
console.log('Raw tournament bracket:', tournament.bracket);
|
|
if (tournament.bracket?.rounds) {
|
|
console.log('First bracket round matches:', tournament.bracket.rounds[0]?.matches);
|
|
}
|
|
console.log('=== END SERVER LOAD DEBUG ===');
|
|
|
|
// Convert _id and other MongoDB ObjectIds to strings for serialization
|
|
const serializedTournament = JSON.parse(JSON.stringify(tournament));
|
|
|
|
console.log('=== SERIALIZED DEBUG ===');
|
|
if (serializedTournament.bracket?.rounds) {
|
|
console.log('Serialized first bracket round matches:', serializedTournament.bracket.rounds[0]?.matches);
|
|
}
|
|
console.log('=== END SERIALIZED DEBUG ===');
|
|
|
|
return {
|
|
tournament: serializedTournament
|
|
};
|
|
} catch (err: any) {
|
|
if (err.status === 404) {
|
|
throw err;
|
|
}
|
|
console.error('Error loading tournament:', err);
|
|
throw error(500, 'Failed to load tournament');
|
|
}
|
|
};
|