feat: helper to get currentSeason

This commit is contained in:
Kalane 2021-09-11 14:09:10 +02:00
parent 5cd0837815
commit c24b4fd161
2 changed files with 10 additions and 1 deletions

View file

@ -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<number[]> {
const seasons = await MatchRepository.seasons(puuid)
return seasons.length ? seasons.map(s => s._id) : [10]
return seasons.length ? seasons.map(s => s._id) : [getCurrentSeason()]
}
/**

View file

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