From 0d50eb30859ac1c6319bd9c215e9d4a23eef8846 Mon Sep 17 00:00:00 2001 From: vhaudiquet Date: Fri, 29 Nov 2024 18:34:55 +0100 Subject: [PATCH] Fix API response too large :) --- frontend/pages/champion/[alias].vue | 4 ++-- frontend/server/api/{champions.js => champions.ts} | 13 ++++++++----- frontend/types/api.ts | 4 ++-- 3 files changed, 12 insertions(+), 9 deletions(-) rename frontend/server/api/{champions.js => champions.ts} (53%) diff --git a/frontend/pages/champion/[alias].vue b/frontend/pages/champion/[alias].vue index 1532ee6..0dbeadb 100644 --- a/frontend/pages/champion/[alias].vue +++ b/frontend/pages/champion/[alias].vue @@ -27,8 +27,8 @@ function updateState(newState : string, newLane : number) {
- - + +

Sorry, there is no data for this champion :(

diff --git a/frontend/server/api/champions.js b/frontend/server/api/champions.ts similarity index 53% rename from frontend/server/api/champions.js rename to frontend/server/api/champions.ts index 6f54fa8..ad0645e 100644 --- a/frontend/server/api/champions.js +++ b/frontend/server/api/champions.ts @@ -1,17 +1,20 @@ +import { MongoClient } from 'mongodb'; import {connectToDatabase, fetchLatestPatch} from '../utils/mongo' -async function champions(client, patch) { +async function champions(client: MongoClient, patch: string) { const database = client.db("champions"); const collection = database.collection(patch); - const data = await collection.find().toArray() + const data : Array = (await collection.find().toArray()) as unknown as Array data.map((x) => { - delete x.runes - delete x.builds + for(let lane of x.lanes) { + delete lane.builds + delete lane.runes + } }) return data } -export default defineEventHandler(async (event) => { +export default defineEventHandler(async (_) => { const client = await connectToDatabase(); const latestPatch = await fetchLatestPatch(client); diff --git a/frontend/types/api.ts b/frontend/types/api.ts index e7b9401..38bb5fb 100644 --- a/frontend/types/api.ts +++ b/frontend/types/api.ts @@ -25,8 +25,8 @@ declare global { losingMatches: number winrate: number pickrate: number - runes: Array - builds: Builds + runes?: Array + builds?: Builds } type ChampionData = {