Basic stats api
This commit is contained in:
19
frontend/server/api/stats.ts
Normal file
19
frontend/server/api/stats.ts
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
import { 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}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user