From ba6cd1ee7cff759ab78d201f26c7f7886fd9e8bc Mon Sep 17 00:00:00 2001 From: Lucas Patenaude Date: Thu, 4 Apr 2024 22:29:18 -0600 Subject: [PATCH] Links to other leagues added --- .../css/scoreboard-header/game-card.css | 4 +- .../scoreboard-header/current-match-routes.js | 88 ++++++++++--------- 2 files changed, 47 insertions(+), 45 deletions(-) diff --git a/ProjectSourceCode/src/resources/css/scoreboard-header/game-card.css b/ProjectSourceCode/src/resources/css/scoreboard-header/game-card.css index b3c29fa..972d147 100644 --- a/ProjectSourceCode/src/resources/css/scoreboard-header/game-card.css +++ b/ProjectSourceCode/src/resources/css/scoreboard-header/game-card.css @@ -58,7 +58,7 @@ } .team img { - width: 20px; /* Set the width of the image to 100% of its container */ - height: auto; /* Maintain the aspect ratio */ + max-width: 20px; /* Set the width of the image to 100% of its container */ + max-height: 20px; /* Maintain the aspect ratio */ margin-right: 10px; } diff --git a/ProjectSourceCode/src/resources/js/scoreboard-header/current-match-routes.js b/ProjectSourceCode/src/resources/js/scoreboard-header/current-match-routes.js index 3a09ecc..acafc17 100644 --- a/ProjectSourceCode/src/resources/js/scoreboard-header/current-match-routes.js +++ b/ProjectSourceCode/src/resources/js/scoreboard-header/current-match-routes.js @@ -3,59 +3,61 @@ const axios = require('axios'); // Middleware function to fetch matches data const fetchMatchesData = async (req, res, next) => { - try - { + try { const today = moment().format('YYYY-MM-DD'); // Get today's date in YYYY-MM-DD format // Subtract one day to get yesterday's date - var yesterdayUnformatted = moment().subtract(1, 'days'); + const yesterdayUnformatted = moment().subtract(1, 'days'); // Format yesterday's date as YYYY-MM-DD - var yesterday = yesterdayUnformatted.format('YYYY-MM-DD'); + const yesterday = yesterdayUnformatted.format('YYYY-MM-DD'); + // Array of years to fetch matches data + const years = [2002, 2003, 2021]; - const response = await axios({ - url: 'http://api.football-data.org/v4/competitions/2021/matches', - method: 'GET', - params: - { - dateFrom: yesterday, // Set dateFrom to today's date - dateTo: today, // Set dateTo to today's date - }, - headers: - { - 'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3', // Add your API key here - }, - }); + // Array to store all matches data + let allMatches = []; - // Extract relevant data from the API response - const matches = response.data.matches.map(match => ({ - homeTeam: - { - name: match.homeTeam.tla, - crest: match.homeTeam.crest, - }, - awayTeam: - { - name: match.awayTeam.tla, - crest: match.awayTeam.crest, - }, - score: - { - homeScore: match.score.fullTime.home, - awayScore: match.score.fullTime.away, - }, - minute: match.status, // Set the minute of the game - })); + // Loop through each year and fetch matches data + for (const year of years) { + const response = await axios({ + url: `http://api.football-data.org/v4/competitions/${year}/matches`, + method: 'GET', + params: { + dateFrom: yesterday, // Set dateFrom to yesterday's date + dateTo: today, // Set dateTo to today's date + }, + headers: { + 'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3', // Add your API key here + }, + }); - // Attach matches data to res.locals - res.locals.matches = matches; + // Extract relevant data from the API response + const matches = response.data.matches.map(match => ({ + homeTeam: { + name: match.homeTeam.tla, + crest: match.homeTeam.crest, + }, + awayTeam: { + name: match.awayTeam.tla, + crest: match.awayTeam.crest, + }, + score: { + homeScore: match.score.fullTime.home, + awayScore: match.score.fullTime.away, + }, + minute: match.status, // Set the minute of the game + })); + + // Concatenate matches data to allMatches array + allMatches = allMatches.concat(matches); + } + + // Attach all matches data to res.locals + res.locals.matches = allMatches; next(); - } - - catch (error) - { - console.error('Error fetching Premier League matches:', error); + } catch (error) { + console.error('Error fetching matches data:', error); res.locals.matches = []; // Set an empty array if there's an error next(); // Call next middleware or route handler }