From 0ca9a9e8b3349927d75af6b3897aa017824a8adc Mon Sep 17 00:00:00 2001 From: Peter Date: Tue, 19 Sep 2023 10:25:06 -0400 Subject: [PATCH] Add Schedule to TeamView --- components.d.ts | 1 + src/components/TeamScheduleTable.vue | 175 +++++++++++++++++++++++++++ src/services/gameService.ts | 18 +++ src/services/utilities.ts | 2 + src/views/TeamView.vue | 7 ++ 5 files changed, 203 insertions(+) create mode 100644 src/components/TeamScheduleTable.vue create mode 100644 src/services/gameService.ts diff --git a/components.d.ts b/components.d.ts index 1766ef5..e466e0b 100644 --- a/components.d.ts +++ b/components.d.ts @@ -26,5 +26,6 @@ declare module '@vue/runtime-core' { RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] StandingsTable: typeof import('./src/components/StandingsTable.vue')['default'] + TeamScheduleTable: typeof import('./src/components/TeamScheduleTable.vue')['default'] } } diff --git a/src/components/TeamScheduleTable.vue b/src/components/TeamScheduleTable.vue new file mode 100644 index 0000000..85a81b1 --- /dev/null +++ b/src/components/TeamScheduleTable.vue @@ -0,0 +1,175 @@ + + + \ No newline at end of file diff --git a/src/services/gameService.ts b/src/services/gameService.ts new file mode 100644 index 0000000..6a710a2 --- /dev/null +++ b/src/services/gameService.ts @@ -0,0 +1,18 @@ +import type { Game } from './apiResponseTypes' +import { MODERN_STAT_ERA_START, SITE_URL } from './utilities' + +export async function fetchGamesBySeasonAndTeamId(seasonNumber: number, teamId: number): Promise { + if (seasonNumber < MODERN_STAT_ERA_START) { + console.warn(`Cannot use games endpoint to fetch stats before season 8`) + return [] + } + + const response = await fetch(`${SITE_URL}/api/v3/games?season=${seasonNumber}&team1_id=${teamId}&team2_id=${teamId}`) + + const gamesResponse: { + count: number + games: Game[] + } = await response.json() + + return gamesResponse.games +} diff --git a/src/services/utilities.ts b/src/services/utilities.ts index 605db3c..9d55054 100644 --- a/src/services/utilities.ts +++ b/src/services/utilities.ts @@ -4,6 +4,8 @@ export const CURRENT_SEASON = 8 export const MODERN_STAT_ERA_START = 8 +export const GAMES_PER_SEASON = 72 + // a type guard to tell typescript that undefined has been filtered and to only consider an array // of the expected types (no undefineds) after filtering export const isNotUndefined = (value: S | undefined): value is S => value != undefined diff --git a/src/views/TeamView.vue b/src/views/TeamView.vue index e94768e..ef0011f 100644 --- a/src/views/TeamView.vue +++ b/src/views/TeamView.vue @@ -154,6 +154,9 @@ + + + @@ -164,9 +167,13 @@ import { fetchPlayersByTeam, type Player } from '@/services/playersService' import { fetchStandings, type TeamStanding } from '@/services/standingsService' import { fetchTeam } from '@/services/teamsService' import { fetchTransactionsByTeamAndWeek, type Transaction } from '@/services/transactionsService' +import TeamScheduleTable from '@/components/TeamScheduleTable.vue' export default { name: "TeamView", + components: { + TeamScheduleTable + }, data() { return { team: undefined as Team | undefined,