mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: add "new" badge on matches + fix wrong match results
This commit is contained in:
parent
d6c4fe3e11
commit
00518e5143
5 changed files with 13 additions and 19 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import { BaseModel, column, HasMany, hasMany, HasOne, hasOne } from '@ioc:Adonis/Lucid/Orm'
|
import { BaseModel, column, HasMany, hasMany } from '@ioc:Adonis/Lucid/Orm'
|
||||||
import MatchPlayer from './MatchPlayer'
|
import MatchPlayer from './MatchPlayer'
|
||||||
import MatchTeam from './MatchTeam'
|
import MatchTeam from './MatchTeam'
|
||||||
|
|
||||||
|
|
@ -32,11 +32,8 @@ export default class Match extends BaseModel {
|
||||||
@column()
|
@column()
|
||||||
public gameDuration: number
|
public gameDuration: number
|
||||||
|
|
||||||
@hasOne(() => MatchTeam)
|
@hasMany(() => MatchTeam)
|
||||||
public blueTeam: HasOne<typeof MatchTeam>
|
public teams: HasMany<typeof MatchTeam>
|
||||||
|
|
||||||
@hasOne(() => MatchTeam)
|
|
||||||
public redTeam: HasOne<typeof MatchTeam>
|
|
||||||
|
|
||||||
@hasMany(() => MatchPlayer)
|
@hasMany(() => MatchPlayer)
|
||||||
public players: HasMany<typeof MatchPlayer>
|
public players: HasMany<typeof MatchPlayer>
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@ class MatchParser {
|
||||||
if (match.info.gameDuration < 300) {
|
if (match.info.gameDuration < 300) {
|
||||||
result = 'Remake'
|
result = 'Remake'
|
||||||
}
|
}
|
||||||
const teamColor = team.teamId === 100 ? 'blueTeam' : 'redTeam'
|
await parsedMatch.related('teams').create({
|
||||||
await parsedMatch.related(teamColor).create({
|
|
||||||
matchId: match.metadata.matchId,
|
matchId: match.metadata.matchId,
|
||||||
color: team.teamId,
|
color: team.teamId,
|
||||||
result: result,
|
result: result,
|
||||||
|
|
@ -121,7 +120,7 @@ class MatchParser {
|
||||||
|
|
||||||
// Load Match relations
|
// Load Match relations
|
||||||
await parsedMatch.load((loader) => {
|
await parsedMatch.load((loader) => {
|
||||||
loader.load('blueTeam').load('redTeam').load('players')
|
loader.load('teams').load('players')
|
||||||
})
|
})
|
||||||
return parsedMatch
|
return parsedMatch
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -123,11 +123,9 @@ class BasicMatchSerializer extends MatchSerializer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public serializeOneMatch(match: Match, puuid: string): SerializedMatch {
|
public serializeOneMatch(match: Match, puuid: string, newMatch = false): SerializedMatch {
|
||||||
const identity = match.players.find((p) => p.summonerPuuid === puuid)!
|
const identity = match.players.find((p) => p.summonerPuuid === puuid)!
|
||||||
|
const allyTeam = match.teams.find((t) => t.color === identity.team)!
|
||||||
const allyTeamColor = identity.team === 100 ? 'blueTeam' : 'redTeam'
|
|
||||||
const allyTeam = match[allyTeamColor]
|
|
||||||
|
|
||||||
const allyPlayers: MatchPlayer[] = []
|
const allyPlayers: MatchPlayer[] = []
|
||||||
const enemyPlayers: MatchPlayer[] = []
|
const enemyPlayers: MatchPlayer[] = []
|
||||||
|
|
@ -147,6 +145,7 @@ class BasicMatchSerializer extends MatchSerializer {
|
||||||
level: identity.champLevel,
|
level: identity.champLevel,
|
||||||
map: match.map,
|
map: match.map,
|
||||||
name: identity.summonerName,
|
name: identity.summonerName,
|
||||||
|
newMatch,
|
||||||
perks: this.getPerks(identity),
|
perks: this.getPerks(identity),
|
||||||
region: match.region,
|
region: match.region,
|
||||||
result: allyTeam.result,
|
result: allyTeam.result,
|
||||||
|
|
@ -160,8 +159,8 @@ class BasicMatchSerializer extends MatchSerializer {
|
||||||
time: match.gameDuration,
|
time: match.gameDuration,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public serialize(matches: Match[], puuid: string): SerializedMatch[] {
|
public serialize(matches: Match[], puuid: string, newMatches = false): SerializedMatch[] {
|
||||||
return matches.map((match) => this.serializeOneMatch(match, puuid))
|
return matches.map((match) => this.serializeOneMatch(match, puuid, newMatches))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ export interface SerializedMatch {
|
||||||
level: number
|
level: number
|
||||||
map: number
|
map: number
|
||||||
name: string
|
name: string
|
||||||
|
newMatch: boolean
|
||||||
perks: SerializedMatchPerks
|
perks: SerializedMatchPerks
|
||||||
region: string
|
region: string
|
||||||
result: string
|
result: string
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,6 @@ import { MatchlistDto } from './Jax/src/Endpoints/MatchlistEndpoint'
|
||||||
import { SummonerDTO } from './Jax/src/Endpoints/SummonerEndpoint'
|
import { SummonerDTO } from './Jax/src/Endpoints/SummonerEndpoint'
|
||||||
import Summoner from 'App/Models/Summoner'
|
import Summoner from 'App/Models/Summoner'
|
||||||
import Database from '@ioc:Adonis/Lucid/Database'
|
import Database from '@ioc:Adonis/Lucid/Database'
|
||||||
import SummonerMatchlist from 'App/Models/SummonerMatchlist'
|
|
||||||
import MatchParser from 'App/Parsers/MatchParser'
|
import MatchParser from 'App/Parsers/MatchParser'
|
||||||
import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
|
import BasicMatchSerializer from 'App/Serializers/BasicMatchSerializer'
|
||||||
import { SerializedMatch } from 'App/Serializers/SerializedTypes'
|
import { SerializedMatch } from 'App/Serializers/SerializedTypes'
|
||||||
|
|
@ -91,8 +90,7 @@ class MatchService {
|
||||||
for (let i = 0; i < matchIds.length; ++i) {
|
for (let i = 0; i < matchIds.length; ++i) {
|
||||||
const matchSaved = await Match.query()
|
const matchSaved = await Match.query()
|
||||||
.where('id', matchIds[i])
|
.where('id', matchIds[i])
|
||||||
.preload('blueTeam')
|
.preload('teams')
|
||||||
.preload('redTeam')
|
|
||||||
.preload('players')
|
.preload('players')
|
||||||
.first()
|
.first()
|
||||||
|
|
||||||
|
|
@ -113,7 +111,7 @@ class MatchService {
|
||||||
const parsedMatches: any = await MatchParser.parse(matchesFromApi)
|
const parsedMatches: any = await MatchParser.parse(matchesFromApi)
|
||||||
|
|
||||||
// TODO: Serialize match from DB + put it in Redis + push it in "matches"
|
// TODO: Serialize match from DB + put it in Redis + push it in "matches"
|
||||||
const serializedMatches = BasicMatchSerializer.serialize(parsedMatches, puuid)
|
const serializedMatches = BasicMatchSerializer.serialize(parsedMatches, puuid, true)
|
||||||
matches = [...matches, ...serializedMatches]
|
matches = [...matches, ...serializedMatches]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue