import { FastifyInstance } from 'fastify'; import { getLeaderboard, getUserRank } from '../services/gamification/leaderboard-service.js'; import { getAchievements, checkAchievements } from '../services/gamification/achievement-service.js'; export async function gamificationRoutes(app: FastifyInstance): Promise { app.get('/leaderboard', async (request) => { const { tier, page = '1', limit = '20' } = request.query as Record; const data = await getLeaderboard(tier, Number(page), Number(limit)); return { success: true, data: data.items, pagination: data.pagination, error: null }; }); app.get('/leaderboard/me', async (request) => { const userId = (request.user as { userId: string }).userId; const data = await getUserRank(userId); return { success: true, data, error: null }; }); app.get('/achievements', async (request) => { const userId = (request.user as { userId: string }).userId; const data = await getAchievements(userId); return { success: true, data, error: null }; }); app.post('/achievements/check', async (request) => { const userId = (request.user as { userId: string }).userId; const newlyUnlocked = await checkAchievements(userId); return { success: true, data: { newlyUnlocked }, error: null }; }); }