feat: get list of played seasons for a summoner from basic endpoint

This commit is contained in:
Valentin Kaelin 2020-02-01 17:14:33 +01:00
parent 1f7bd5a853
commit 7beb635c80
2 changed files with 38 additions and 6 deletions

View file

@ -9,6 +9,10 @@ const StatsService = use('App/Services/StatsService')
const Summoner = use('App/Models/Summoner') const Summoner = use('App/Models/Summoner')
class SummonerController { 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 * POST: get basic summoner data
*/ */
@ -44,6 +48,9 @@ class SummonerController {
const matchList = summonerDB.matchList const matchList = summonerDB.matchList
finalJSON.matchList = matchList finalJSON.matchList = matchList
// All seasons the summoner has played
finalJSON.seasons = await this._getSeasons(account.puuid)
// CURRENT GAME // CURRENT GAME
const currentGame = await Jax.Spectator.summonerID(account.id, region) const currentGame = await Jax.Spectator.summonerID(account.id, region)
finalJSON.playing = !!currentGame finalJSON.playing = !!currentGame
@ -70,6 +77,7 @@ class SummonerController {
async overview({ request, response }) { async overview({ request, response }) {
console.time('overview') console.time('overview')
const account = request.input('account') const account = request.input('account')
const season = request.input('season')
const finalJSON = {} const finalJSON = {}
// Summoner in DB // Summoner in DB

View file

@ -9,6 +9,18 @@ class MatchRepository {
this.Match = Match 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 * Build the aggregate mongo query
* @param {Number} puuid * @param {Number} puuid
@ -22,9 +34,7 @@ class MatchRepository {
return this.Match.query().aggregate([ return this.Match.query().aggregate([
{ {
$match: { $match: {
summoner_puuid: puuid, ...this._matchParams(puuid),
result: { $not: { $eq: 'Remake' } },
gamemode: { $nin: [800, 810, 820, 830, 840, 850] },
...matchParams ...matchParams
} }
}, },
@ -140,9 +150,7 @@ class MatchRepository {
return this.Match.query().aggregate([ return this.Match.query().aggregate([
{ {
$match: { $match: {
summoner_puuid: puuid, ...this._matchParams(puuid),
result: { $not: { $eq: 'Remake' } },
gamemode: { $nin: [800, 810, 820, 830, 840, 850] },
} }
}, },
{ {
@ -222,6 +230,22 @@ class MatchRepository {
] ]
return this._aggregate(puuid, matchParams, [], '$role', {}, finalSteps) 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 * Get Summoner's mates list