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')
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

View file

@ -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