diff --git a/server/app/Controllers/Http/SummonersController.ts b/server/app/Controllers/Http/SummonersController.ts index 46e3ce8..e692126 100644 --- a/server/app/Controllers/Http/SummonersController.ts +++ b/server/app/Controllers/Http/SummonersController.ts @@ -1,4 +1,5 @@ import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' +import { getCurrentSeason } from 'App/helpers' import Summoner from 'App/Models/Summoner' import MatchRepository from 'App/Repositories/MatchRepository' import Jax from 'App/Services/Jax' @@ -19,7 +20,7 @@ export default class SummonersController { */ private async getSeasons (puuid: string): Promise { const seasons = await MatchRepository.seasons(puuid) - return seasons.length ? seasons.map(s => s._id) : [10] + return seasons.length ? seasons.map(s => s._id) : [getCurrentSeason()] } /** diff --git a/server/app/helpers.ts b/server/app/helpers.ts index db8adef..a8b3f11 100644 --- a/server/app/helpers.ts +++ b/server/app/helpers.ts @@ -89,6 +89,14 @@ export function getSeasonNumber (timestamp: number): number { return seasons[arrSeasons[indexSeason]] } +/** + * Return current League of Legends season number + */ +export function getCurrentSeason () : number { + const lastTimestamp = Object.keys(seasons).pop()! + return seasons[lastTimestamp] +} + /** * Sort array of Players by roles according to a specific order * @param a first player