More TypeScript :)
This commit is contained in:
@@ -1,15 +1,16 @@
|
|||||||
|
import { MongoClient } from 'mongodb';
|
||||||
import {connectToDatabase, fetchLatestPatch} from '../../utils/mongo'
|
import {connectToDatabase, fetchLatestPatch} from '../../utils/mongo'
|
||||||
|
|
||||||
async function championInfos(client, patch, championAlias) {
|
async function championInfos(client: MongoClient, patch: string, championAlias: string) {
|
||||||
const database = client.db("champions");
|
const database = client.db("champions");
|
||||||
const collection = database.collection(patch);
|
const collection = database.collection(patch);
|
||||||
const query = { alias:championAlias };
|
const query = { alias:championAlias };
|
||||||
const championInfo = await collection.findOne(query);
|
const championInfo = (await collection.findOne(query)) as unknown as ChampionData;
|
||||||
return championInfo
|
return championInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const championAlias = getRouterParam(event, "alias").toLowerCase()
|
const championAlias = (getRouterParam(event, "alias") as string).toLowerCase()
|
||||||
const client = await connectToDatabase();
|
const client = await connectToDatabase();
|
||||||
const latestPatch = await fetchLatestPatch(client);
|
const latestPatch = await fetchLatestPatch(client);
|
||||||
const data = await championInfos(client, latestPatch, championAlias);
|
const data = await championInfos(client, latestPatch, championAlias);
|
||||||
@@ -7,11 +7,11 @@ async function connectToDatabase() {
|
|||||||
return client
|
return client
|
||||||
}
|
}
|
||||||
|
|
||||||
async function fetchLatestPatch(client) {
|
async function fetchLatestPatch(client : MongoClient) {
|
||||||
const database = client.db("patches");
|
const database = client.db("patches");
|
||||||
const patches = database.collection("patches");
|
const patches = database.collection("patches");
|
||||||
const latestPatch = await patches.find().limit(1).sort({date:-1}).next()
|
const latestPatch = await patches.find().limit(1).sort({date:-1}).next()
|
||||||
return latestPatch.patch
|
return latestPatch!!.patch as string
|
||||||
}
|
}
|
||||||
|
|
||||||
export {connectToDatabase, fetchLatestPatch}
|
export {connectToDatabase, fetchLatestPatch}
|
||||||
Reference in New Issue
Block a user