Initial commit

This commit is contained in:
2024-11-21 19:39:22 +01:00
commit 56d1075459
32 changed files with 10966 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
import { MongoClient } from 'mongodb'
async function connectToDatabase() {
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
const client = new MongoClient(`mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@mongo:27017`)
await client.connect()
return client
}
async function fetchLatestPatch(client) {
const database = client.db("patches");
const patches = database.collection("patches");
const latestPatch = await patches.find().limit(1).sort({date:-1}).next()
return latestPatch.patch
}
async function championInfos(client, patch, championId) {
const database = client.db("champions");
const collection = database.collection(patch);
const query = { id:Number(championId) };
const championInfo = await collection.findOne(query);
return championInfo
}
export default defineEventHandler(async (event) => {
const championId = getRouterParam(event, "id")
const client = await connectToDatabase();
const latestPatch = await fetchLatestPatch(client);
const data = await championInfos(client, latestPatch, championId);
await client.close()
return data
})