mirror of
https://github.com/jcreek/LivingDexTracker.git
synced 2026-07-13 02:53:45 +00:00
feat(*): Add improvements to the UX and the data seeding
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { json } from '@sveltejs/kit';
|
||||
import type { RequestHandler } from './$types';
|
||||
|
||||
/**
|
||||
* GET /api/games
|
||||
* Returns all games from the games table, sorted by release year descending (newest first)
|
||||
*/
|
||||
export const GET: RequestHandler = async ({ locals }) => {
|
||||
const { supabase } = locals;
|
||||
|
||||
try {
|
||||
// Query games table for all games, sorted by release year descending
|
||||
const { data, error } = await supabase
|
||||
.from('games')
|
||||
.select('displayName, releaseYear')
|
||||
.order('releaseYear', { ascending: false })
|
||||
.order('displayName', { ascending: true }); // Secondary sort by name for same year
|
||||
|
||||
if (error) {
|
||||
console.error('Error fetching games:', error);
|
||||
return json({ error: 'Failed to fetch games' }, { status: 500 });
|
||||
}
|
||||
|
||||
// Extract just the display names
|
||||
const gameNames = data.map((row) => row.displayName);
|
||||
|
||||
return json({ games: gameNames });
|
||||
} catch (err) {
|
||||
console.error('Unexpected error fetching games:', err);
|
||||
return json({ error: 'Internal server error' }, { status: 500 });
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user