diff --git a/match_collector/index.ts b/match_collector/index.ts index 48285f8..c3839ff 100644 --- a/match_collector/index.ts +++ b/match_collector/index.ts @@ -5,6 +5,7 @@ const sleep_minutes = 12 import { MongoClient } from 'mongodb' import champion_stat from './champion_stat' +import { Match } from './api' main() @@ -32,7 +33,7 @@ async function main() { const challengerLeague = await fetchChallengerLeague() console.log('ChallengerLeague: got ' + challengerLeague.entries.length + ' entries') - const gameList = [] + const gameList : string[] = [] let i = 0 for (const challenger of challengerLeague.entries) { console.log('Entry ' + i + '/' + challengerLeague.entries.length + ' ...') @@ -105,11 +106,11 @@ async function connectToDatabase() { return client } -async function fetchLatestPatchDate(client) { +async function fetchLatestPatchDate(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, Math.floor(latestPatch.date.valueOf() / 1000)] + return [latestPatch!.patch, Math.floor(latestPatch!.date.valueOf() / 1000)] } async function fetchChallengerLeague() { @@ -125,7 +126,7 @@ async function fetchChallengerLeague() { return challengerLeague } -async function summonerGameList(puuid, startTime) { +async function summonerGameList(puuid: string, startTime: string) { const base = 'https://europe.api.riotgames.com' const endpoint = `/lol/match/v5/matches/by-puuid/${puuid}/ids` const url = `${base}${endpoint}?queue=420&type=ranked&startTime=${startTime}&api_key=${api_key}` @@ -137,7 +138,7 @@ async function summonerGameList(puuid, startTime) { return gameList } -async function match(matchId) { +async function match(matchId: string) { const base = 'https://europe.api.riotgames.com' const endpoint = `/lol/match/v5/matches/${matchId}` const url = `${base}${endpoint}?api_key=${api_key}` @@ -149,7 +150,7 @@ async function match(matchId) { return match } -async function matchTimeline(matchId) { +async function matchTimeline(matchId: string) { const base = 'https://europe.api.riotgames.com' const endpoint = `/lol/match/v5/matches/${matchId}/timeline` const url = `${base}${endpoint}?api_key=${api_key}` @@ -161,7 +162,7 @@ async function matchTimeline(matchId) { return timeline } -async function alreadySeenGames(client, latestPatch) { +async function alreadySeenGames(client: MongoClient, latestPatch: string) { const database = client.db('matches') const matches = database.collection(latestPatch) @@ -169,7 +170,7 @@ async function alreadySeenGames(client, latestPatch) { return alreadySeen } -async function saveMatch(client, match, latestPatch) { +async function saveMatch(client: MongoClient, match: Match, latestPatch: string) { const database = client.db('matches') const matches = database.collection(latestPatch) await matches.insertOne(match)