Fetch adjacent games

This commit is contained in:
Peter 2024-11-10 20:05:13 -06:00
parent 308dc47000
commit e823ba8ff2

View File

@ -351,11 +351,18 @@ import type { Game, Team } from '@/services/apiResponseTypes'
import { isDiscordAuthenticated } from '@/services/authenticationService' import { isDiscordAuthenticated } from '@/services/authenticationService'
import { fetchBattingStatsBySeries, type BattingStat } from '@/services/battingStatsService' import { fetchBattingStatsBySeries, type BattingStat } from '@/services/battingStatsService'
import { fetchFieldingStatsBySeries, type FieldingStat } from '@/services/fieldingStatsService' import { fetchFieldingStatsBySeries, type FieldingStat } from '@/services/fieldingStatsService'
import { fetchSingleGame } from '@/services/gameService' import { fetchGamesBySeasonAndTeamId, fetchSingleGame } from '@/services/gameService'
import { fetchPitchingStatsBySeries, type PitchingStat } from '@/services/pitchingStatsService' import { fetchPitchingStatsBySeries, type PitchingStat } from '@/services/pitchingStatsService'
import { fetchTeam } from '@/services/teamsService' import { fetchTeam } from '@/services/teamsService'
import { outsToInnings } from '@/services/utilities' import { outsToInnings } from '@/services/utilities'
interface AdjacentGameHelper {
team1prevGame: Game
team1nextGame: Game
team2prevGame: Game
team2nextGame: Game
}
export default { export default {
name: 'GameView', name: 'GameView',
data() { data() {
@ -367,6 +374,7 @@ export default {
battingStats: [] as BattingStat[], battingStats: [] as BattingStat[],
pitchingStats: [] as PitchingStat[], pitchingStats: [] as PitchingStat[],
fieldingStats: [] as FieldingStat[], fieldingStats: [] as FieldingStat[],
adjacentGames: undefined as AdjacentGameHelper | undefined,
} }
}, },
props: { props: {
@ -457,7 +465,6 @@ export default {
decisionStrings.push(`Blown Save${blownSaves.length > 1 ? 's' : ''}: ${blownSaves.map(h => h.player.name).join(', ')}`) decisionStrings.push(`Blown Save${blownSaves.length > 1 ? 's' : ''}: ${blownSaves.map(h => h.player.name).join(', ')}`)
} }
return decisionStrings.join(' | ') return decisionStrings.join(' | ')
} }
}, },
@ -477,6 +484,25 @@ export default {
this.battingStats = await fetchBattingStatsBySeries(this.seasonNumber, this.weekNumber, this.team1.id, this.team2.id) this.battingStats = await fetchBattingStatsBySeries(this.seasonNumber, this.weekNumber, this.team1.id, this.team2.id)
this.pitchingStats = await fetchPitchingStatsBySeries(this.seasonNumber, this.weekNumber, this.team1.id, this.team2.id) this.pitchingStats = await fetchPitchingStatsBySeries(this.seasonNumber, this.weekNumber, this.team1.id, this.team2.id)
this.fieldingStats = await fetchFieldingStatsBySeries(this.seasonNumber, this.weekNumber, this.team1.id, this.team2.id) this.fieldingStats = await fetchFieldingStatsBySeries(this.seasonNumber, this.weekNumber, this.team1.id, this.team2.id)
await this.fetchAdjacentGames()
},
async fetchAdjacentGames(): Promise<void> {
const team1Games = await fetchGamesBySeasonAndTeamId(this.seasonNumber, this.team1!.id)
const team2Games = await fetchGamesBySeasonAndTeamId(this.seasonNumber, this.team2!.id)
const prevGameNumber = this.gameNumber === 1 ? 4 : this.gameNumber - 1
const nextGameNumber = this.gameNumber === 4 ? 1 : this.gameNumber + 1
const prevWeekNumber = this.gameNumber === 1 ? this.weekNumber - 1 : this.weekNumber
const nextWeekNumber = this.gameNumber === 4 ? this.weekNumber + 1 : this.weekNumber
this.adjacentGames = {
team1nextGame: team1Games.find(g => g.week === nextWeekNumber && g.game_num === nextGameNumber)!,
team1prevGame: team1Games.find(g => g.week === prevWeekNumber && g.game_num === prevGameNumber)!,
team2nextGame: team2Games.find(g => g.week === nextWeekNumber && g.game_num === nextGameNumber)!,
team2prevGame: team2Games.find(g => g.week === prevWeekNumber && g.game_num === prevGameNumber)!
}
}, },
outsToInnings(stat: PitchingStat): string { outsToInnings(stat: PitchingStat): string {
return outsToInnings(stat) return outsToInnings(stat)