Lint and format
This commit is contained in:
@@ -1,19 +1,19 @@
|
||||
import { MongoClient } from 'mongodb';
|
||||
import {connectToDatabase, fetchLatestPatch} from '../../utils/mongo'
|
||||
import type { MongoClient } from 'mongodb'
|
||||
import { connectToDatabase, fetchLatestPatch } from '../../utils/mongo'
|
||||
|
||||
async function championInfos(client: MongoClient, patch: string, championAlias: string) {
|
||||
const database = client.db("champions");
|
||||
const collection = database.collection(patch);
|
||||
const query = { alias:championAlias };
|
||||
const championInfo = (await collection.findOne(query)) as unknown as ChampionData;
|
||||
return championInfo
|
||||
const database = client.db('champions')
|
||||
const collection = database.collection(patch)
|
||||
const query = { alias: championAlias }
|
||||
const championInfo = (await collection.findOne(query)) as unknown as ChampionData
|
||||
return championInfo
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const championAlias = (getRouterParam(event, "alias") as string).toLowerCase()
|
||||
const client = await connectToDatabase();
|
||||
const latestPatch = await fetchLatestPatch(client);
|
||||
const data = await championInfos(client, latestPatch, championAlias);
|
||||
await client.close()
|
||||
return data
|
||||
export default defineEventHandler(async event => {
|
||||
const championAlias = (getRouterParam(event, 'alias') as string).toLowerCase()
|
||||
const client = await connectToDatabase()
|
||||
const latestPatch = await fetchLatestPatch(client)
|
||||
const data = await championInfos(client, latestPatch, championAlias)
|
||||
await client.close()
|
||||
return data
|
||||
})
|
||||
|
||||
@@ -1,28 +1,30 @@
|
||||
import { MongoClient } from 'mongodb';
|
||||
import {connectToDatabase, fetchLatestPatch} from '../utils/mongo'
|
||||
import type { MongoClient } from 'mongodb'
|
||||
import { connectToDatabase, fetchLatestPatch } from '../utils/mongo'
|
||||
|
||||
async function champions(client: MongoClient, patch: string) {
|
||||
const database = client.db("champions");
|
||||
const collection = database.collection(patch);
|
||||
const data : Array<ChampionData> = (await collection.find().toArray()) as unknown as Array<ChampionData>
|
||||
data.map((x) => {
|
||||
if(x.lanes != undefined && x.lanes != null) {
|
||||
for(let lane of x.lanes) {
|
||||
delete lane.builds
|
||||
delete lane.runes
|
||||
}
|
||||
}
|
||||
})
|
||||
return data
|
||||
const database = client.db('champions')
|
||||
const collection = database.collection(patch)
|
||||
const data: Array<ChampionData> = (await collection
|
||||
.find()
|
||||
.toArray()) as unknown as Array<ChampionData>
|
||||
data.map(x => {
|
||||
if (x.lanes != undefined && x.lanes != null) {
|
||||
for (const lane of x.lanes) {
|
||||
delete lane.builds
|
||||
delete lane.runes
|
||||
}
|
||||
}
|
||||
})
|
||||
return data
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (_) => {
|
||||
const client = await connectToDatabase();
|
||||
const latestPatch = await fetchLatestPatch(client);
|
||||
export default defineEventHandler(async _ => {
|
||||
const client = await connectToDatabase()
|
||||
const latestPatch = await fetchLatestPatch(client)
|
||||
|
||||
const data = await champions(client, latestPatch);
|
||||
|
||||
await client.close()
|
||||
const data = await champions(client, latestPatch)
|
||||
|
||||
return data
|
||||
await client.close()
|
||||
|
||||
return data
|
||||
})
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
import { CDRAGON_BASE } from "~/utils/cdragon";
|
||||
import { CDRAGON_BASE } from '~/utils/cdragon'
|
||||
|
||||
async function championRoutes() {
|
||||
const championsData : Array<Champion> = await
|
||||
(await fetch(CDRAGON_BASE + "plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json")).json()
|
||||
|
||||
let routes : Array<string> = []
|
||||
for(let champion of championsData) {
|
||||
routes.push("/champion/" + champion.alias.toLowerCase())
|
||||
}
|
||||
return routes
|
||||
const championsData: Array<Champion> = await (
|
||||
await fetch(
|
||||
CDRAGON_BASE + 'plugins/rcp-be-lol-game-data/global/default/v1/champion-summary.json'
|
||||
)
|
||||
).json()
|
||||
|
||||
const routes: Array<string> = []
|
||||
for (const champion of championsData) {
|
||||
routes.push('/champion/' + champion.alias.toLowerCase())
|
||||
}
|
||||
return routes
|
||||
}
|
||||
|
||||
export default defineEventHandler(async (_) => {
|
||||
const data = await championRoutes();
|
||||
return data
|
||||
export default defineEventHandler(async _ => {
|
||||
const data = await championRoutes()
|
||||
return data
|
||||
})
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { MongoClient } from 'mongodb';
|
||||
import {connectToDatabase, fetchLatestPatch} from '../utils/mongo'
|
||||
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
|
||||
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()
|
||||
export default defineEventHandler(async _ => {
|
||||
const client = await connectToDatabase()
|
||||
const latestPatch = await fetchLatestPatch(client)
|
||||
const gameCount = await fetchGameCount(client, latestPatch)
|
||||
|
||||
return {patch: latestPatch, count: gameCount}
|
||||
await client.close()
|
||||
|
||||
return { patch: latestPatch, count: gameCount }
|
||||
})
|
||||
|
||||
@@ -1,21 +1,25 @@
|
||||
import { MongoClient } from 'mongodb'
|
||||
|
||||
async function connectToDatabase() {
|
||||
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
|
||||
let uri = `mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@${process.env.MONGO_HOST}`
|
||||
if(process.env.MONGO_URI != undefined && process.env.MONGO_URI != null && process.env.MONGO_URI != "") {
|
||||
uri = process.env.MONGO_URI
|
||||
}
|
||||
const client = new MongoClient(uri)
|
||||
await client.connect()
|
||||
return client
|
||||
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
|
||||
let uri = `mongodb://${process.env.MONGO_USER}:${process.env.MONGO_PASS}@${process.env.MONGO_HOST}`
|
||||
if (
|
||||
process.env.MONGO_URI != undefined &&
|
||||
process.env.MONGO_URI != null &&
|
||||
process.env.MONGO_URI != ''
|
||||
) {
|
||||
uri = process.env.MONGO_URI
|
||||
}
|
||||
const client = new MongoClient(uri)
|
||||
await client.connect()
|
||||
return client
|
||||
}
|
||||
|
||||
async function fetchLatestPatch(client : MongoClient) {
|
||||
const database = client.db("patches");
|
||||
const patches = database.collection("patches");
|
||||
const latestPatch = await patches.find().limit(1).sort({date:-1}).next()
|
||||
return latestPatch!!.patch as string
|
||||
async function fetchLatestPatch(client: MongoClient) {
|
||||
const database = client.db('patches')
|
||||
const patches = database.collection('patches')
|
||||
const latestPatch = await patches.find().limit(1).sort({ date: -1 }).next()
|
||||
return latestPatch!.patch as string
|
||||
}
|
||||
|
||||
export {connectToDatabase, fetchLatestPatch}
|
||||
export { connectToDatabase, fetchLatestPatch }
|
||||
|
||||
Reference in New Issue
Block a user