mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
fix: remove crash on overview endpoint
This commit is contained in:
parent
adf08ac779
commit
8bb7779edb
5 changed files with 34 additions and 20 deletions
|
|
@ -76,6 +76,6 @@ export default class SummonersController {
|
|||
// console.timeEnd('STATS')
|
||||
|
||||
console.timeEnd('OVERVIEW_REQUEST')
|
||||
return response.json('OVERVIEW REQUEST')
|
||||
return response.json(finalJSON)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@ class MatchParser {
|
|||
})
|
||||
|
||||
// - 2x MatchTeam : Red and Blue
|
||||
let result = 'Remake'
|
||||
for (const team of match.info.teams) {
|
||||
if (match.info.gameDuration >= 300) {
|
||||
result = team.win ? 'Win' : 'Fail'
|
||||
let result = team.win ? 'Win' : 'Fail'
|
||||
if (match.info.gameDuration < 300) {
|
||||
result = 'Remake'
|
||||
}
|
||||
const teamColor = team.teamId === 100 ? 'blueTeam' : 'redTeam'
|
||||
parsedMatch.related(teamColor).create({
|
||||
|
|
@ -41,9 +41,9 @@ class MatchParser {
|
|||
// - 10x MatchPlayer
|
||||
const matchPlayers: any[] = []
|
||||
for (const player of match.info.participants) {
|
||||
const kda: number =
|
||||
const kda =
|
||||
player.kills + player.assists !== 0 && player.deaths === 0
|
||||
? Infinity
|
||||
? player.kills + player.assists
|
||||
: +(player.deaths === 0 ? 0 : (player.kills + player.assists) / player.deaths).toFixed(2)
|
||||
|
||||
const teamKills =
|
||||
|
|
@ -51,7 +51,7 @@ class MatchParser {
|
|||
? match.info.teams[0].objectives.champion.kills
|
||||
: match.info.teams[1].objectives.champion.kills
|
||||
|
||||
const kp: number =
|
||||
const kp =
|
||||
teamKills === 0 ? 0 : +(((player.kills + player.assists) * 100) / teamKills).toFixed(1)
|
||||
|
||||
const primaryStyle = player.perks.styles.find((s) => s.description === 'primaryStyle')
|
||||
|
|
|
|||
|
|
@ -104,7 +104,19 @@ class BasicMatchSerializer extends MatchSerializer {
|
|||
}
|
||||
}
|
||||
|
||||
public serializeOneMatch(match: Match, puuid: string): SerializedMatch {
|
||||
public async serializeOneMatch(match: Match, puuid: string): Promise<SerializedMatch> {
|
||||
// TODO: use a CDragon Service
|
||||
await super.getContext()
|
||||
|
||||
// TODO: do we really need to...
|
||||
if (!match.players) {
|
||||
console.log('NEED TO LOAD')
|
||||
|
||||
await match.load('players')
|
||||
await match.load('blueTeam')
|
||||
await match.load('redTeam')
|
||||
}
|
||||
|
||||
const identity = match.players.find((p) => p.summonerPuuid === puuid)!
|
||||
|
||||
const allyTeamColor = identity.team === 100 ? 'blueTeam' : 'redTeam'
|
||||
|
|
@ -114,8 +126,7 @@ class BasicMatchSerializer extends MatchSerializer {
|
|||
const enemyPlayers: MatchPlayer[] = []
|
||||
|
||||
for (const p of match.players) {
|
||||
// TODO: remove Number() when Lazar push the updated migration
|
||||
p.team === Number(allyTeam.color) ? allyPlayers.push(p) : enemyPlayers.push(p)
|
||||
p.team === allyTeam.color ? allyPlayers.push(p) : enemyPlayers.push(p)
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
@ -132,7 +143,7 @@ class BasicMatchSerializer extends MatchSerializer {
|
|||
name: identity.summonerName,
|
||||
perks: this.getPerks(identity),
|
||||
region: match.region,
|
||||
result: allyTeam.result.toString(), // TODO: remove toString() when Lazar push the updated migration
|
||||
result: allyTeam.result,
|
||||
role: identity.teamPosition,
|
||||
season: getSeasonNumber(match.date),
|
||||
secondSum: identity.summoner2Id,
|
||||
|
|
@ -145,7 +156,7 @@ class BasicMatchSerializer extends MatchSerializer {
|
|||
public async serialize(matches: Match[], puuid: string): Promise<SerializedMatch[]> {
|
||||
await super.getContext()
|
||||
|
||||
return matches.map((match) => this.serializeOneMatch(match, puuid))
|
||||
return await Promise.all(matches.map((match) => this.serializeOneMatch(match, puuid)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,10 @@ export default abstract class MatchSerializer {
|
|||
* Get global Context with CDragon Data
|
||||
*/
|
||||
public async getContext() {
|
||||
if (this.champions) {
|
||||
return
|
||||
}
|
||||
|
||||
const items = await Jax.CDragon.items()
|
||||
const champions = await Jax.CDragon.champions()
|
||||
const perks = await Jax.CDragon.perks()
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import SummonerMatchlist from 'App/Models/SummonerMatchlist'
|
|||
import MatchParser from 'App/Parsers/MatchParser'
|
||||
import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
|
||||
import { SerializedMatch } from 'App/Serializers/SerializedTypes'
|
||||
import Match from 'App/Models/Match'
|
||||
|
||||
class MatchService {
|
||||
/**
|
||||
|
|
@ -88,18 +89,16 @@ class MatchService {
|
|||
let matches: SerializedMatch[] = []
|
||||
const matchesToGetFromRiot: MatchlistDto = []
|
||||
for (let i = 0; i < matchList.length; ++i) {
|
||||
const matchSaved = await summonerDB
|
||||
.related('matches')
|
||||
.query()
|
||||
.where('matchId', matchList[i].matchId)
|
||||
.preload('match', (preloader) => {
|
||||
preloader.preload('blueTeam').preload('redTeam').preload('players')
|
||||
})
|
||||
const matchSaved = await Match.query()
|
||||
.where('id', matchList[i].matchId)
|
||||
.preload('blueTeam')
|
||||
.preload('redTeam')
|
||||
.preload('players')
|
||||
.first()
|
||||
|
||||
if (matchSaved) {
|
||||
// TODO: Serialize match from DB + put it in Redis + push it in "matches"
|
||||
matches.push(BasicMatchSerializer.serializeOneMatch(matchSaved.match, summonerDB.puuid))
|
||||
matches.push(await BasicMatchSerializer.serializeOneMatch(matchSaved, summonerDB.puuid))
|
||||
} else {
|
||||
matchesToGetFromRiot.push(matchList[i].matchId)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue