diff --git a/server/app/Controllers/Http/SummonerController.js b/server/app/Controllers/Http/SummonerController.js index 0484112..61d6336 100644 --- a/server/app/Controllers/Http/SummonerController.js +++ b/server/app/Controllers/Http/SummonerController.js @@ -9,6 +9,10 @@ const StatsService = use('App/Services/StatsService') const Summoner = use('App/Models/Summoner') class SummonerController { + async _getSeasons(puuid) { + let seasons = await MatchRepository.seasons(puuid) + return seasons.length ? seasons.map(s => s._id) : [10] + } /** * POST: get basic summoner data */ @@ -44,6 +48,9 @@ class SummonerController { const matchList = summonerDB.matchList finalJSON.matchList = matchList + // All seasons the summoner has played + finalJSON.seasons = await this._getSeasons(account.puuid) + // CURRENT GAME const currentGame = await Jax.Spectator.summonerID(account.id, region) finalJSON.playing = !!currentGame @@ -70,6 +77,7 @@ class SummonerController { async overview({ request, response }) { console.time('overview') const account = request.input('account') + const season = request.input('season') const finalJSON = {} // Summoner in DB diff --git a/server/app/Repositories/MatchRepository.js b/server/app/Repositories/MatchRepository.js index 5710497..d6bc0f1 100644 --- a/server/app/Repositories/MatchRepository.js +++ b/server/app/Repositories/MatchRepository.js @@ -9,6 +9,18 @@ class MatchRepository { this.Match = Match } + /** + * Basic matchParams used in a lot of requests + * @param puuid of the summoner + */ + _matchParams(puuid) { + return { + summoner_puuid: puuid, + result: { $not: { $eq: 'Remake' } }, + gamemode: { $nin: [800, 810, 820, 830, 840, 850] }, + } + } + /** * Build the aggregate mongo query * @param {Number} puuid @@ -22,9 +34,7 @@ class MatchRepository { return this.Match.query().aggregate([ { $match: { - summoner_puuid: puuid, - result: { $not: { $eq: 'Remake' } }, - gamemode: { $nin: [800, 810, 820, 830, 840, 850] }, + ...this._matchParams(puuid), ...matchParams } }, @@ -140,9 +150,7 @@ class MatchRepository { return this.Match.query().aggregate([ { $match: { - summoner_puuid: puuid, - result: { $not: { $eq: 'Remake' } }, - gamemode: { $nin: [800, 810, 820, 830, 840, 850] }, + ...this._matchParams(puuid), } }, { @@ -222,6 +230,22 @@ class MatchRepository { ] return this._aggregate(puuid, matchParams, [], '$role', {}, finalSteps) } + /** + * Get Summoner's played seasons + * @param puuid of the summoner + */ + seasons(puuid) { + return this.Match.query().aggregate([ + { + $match: { + ...this._matchParams(puuid), + } + }, + { + $group: { _id: '$season' } + }, + ]) + } /** * Get Summoner's mates list