import type { MongoClient } from 'mongodb' import { connectToDatabase, fetchLatestPatch, getAvailablePlatforms } from '../utils/mongo' async function fetchGameCount(client: MongoClient, patch: string) { const database = client.db('matches') // Check for platform-specific collections const platforms = await getAvailablePlatforms(client, patch) if (platforms.length > 0) { // Sum counts from all platform-specific collections let totalCount = 0 const platformCounts: Record = {} for (const platform of platforms) { const collection = database.collection(`${patch}_${platform}`) const count = await collection.countDocuments() platformCounts[platform] = count totalCount += count } return { total: totalCount, platforms: platformCounts } } // Fall back to old format (single collection) const matches = database.collection(patch) const count = await matches.countDocuments() return { total: count, platforms: {} } } export default defineEventHandler(async _ => { const client = await connectToDatabase() const latestPatch = await fetchLatestPatch(client) const gameCountData = await fetchGameCount(client, latestPatch) await client.close() return { patch: latestPatch, count: gameCountData.total, platformCounts: gameCountData.platforms } })