feat: summoner/basic endpoint should be kinda good now

This commit is contained in:
Kalane 2021-09-12 19:13:48 +02:00
parent 9a3bb6311c
commit f04f9e95dd

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 Jax from 'App/Services/Jax'
import MatchService from 'App/Services/MatchService'
@ -7,6 +8,7 @@ import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator'
export default class SummonersController {
public async basic({ request, response }: HttpContextContract) {
console.time('BASIC_REQUEST')
const { summoner, region } = await request.validate(SummonerBasicValidator)
const finalJSON: any = {}
@ -28,6 +30,10 @@ export default class SummonersController {
// MATCH LIST
finalJSON.matchList = await MatchService.updateMatchList(account, summonerDB)
// All seasons the summoner has played
// TODO: check if there is a way to do that with V5...
finalJSON.seasons = [getCurrentSeason()]
// CURRENT GAME
const currentGame = await Jax.Spectator.summonerID(account.id, region)
finalJSON.playing = !!currentGame
@ -37,9 +43,11 @@ export default class SummonersController {
finalJSON.ranked = await SummonerService.getRanked(account, region)
} catch (e) {
console.log(e)
console.timeEnd('BASIC_REQUEST')
return response.json(null)
}
console.timeEnd('BASIC_REQUEST')
return response.json(finalJSON)
}