SamuelSau / blitzboiggbackend

1 stars 0 forks source link

TODO: Extract match details in queryMatches.js #1

Closed SamuelSau closed 1 year ago

SamuelSau commented 1 year ago
//Query puuid from Summoners.js

const match = await Summoners.findOne({ puuid: puuid });

If puuid in matchList collection, return data from querySummoners and here to client immediately

Else make number of API calls dependent on count of matches in matchIdResponse

//Use matchId from matchIdResponse to retrieve details of each match

for (let i = 0; i < matchIdResponse.data.length; i++) {

    // Use the match ID to retrieve details of the match

    const matchStatsResponse = await axios.get(
        `https://americas.api.riotgames.com/lol/match/v5/matches/${matchIdResponse.data[i]}`
    );

    console.log(matchStatsResponse.data['info']['gameCreation']);
    }
SamuelSau commented 1 year ago

Implemented a matchDetailsArray that will return all the corresponding details of each matchId from matchList document. Also, I took into account that if a matchId doesn't exist in our matchList document, then we use the League of Legends API and save data into the matchDetails document.