Files
buildpath/frontend/server/api/stats.ts
Valentin Haudiquet 3fc52205f6
Some checks failed
pipeline / lint-and-format (push) Failing after 56s
pipeline / build-and-push-images (push) Has been skipped
Lint and format
2026-01-21 00:59:23 +01:00

20 lines
614 B
TypeScript

import type { MongoClient } from 'mongodb'
import { connectToDatabase, fetchLatestPatch } from '../utils/mongo'
async function fetchGameCount(client: MongoClient, patch: string) {
const database = client.db('matches')
const matches = database.collection(patch)
const count = await matches.countDocuments()
return count
}
export default defineEventHandler(async _ => {
const client = await connectToDatabase()
const latestPatch = await fetchLatestPatch(client)
const gameCount = await fetchGameCount(client, latestPatch)
await client.close()
return { patch: latestPatch, count: gameCount }
})