2024-04-15 11:04:16 -06:00
|
|
|
const axios = require('axios');
|
|
|
|
|
|
|
|
|
|
const fetchTeamNames = async (selectedLeague) => {
|
|
|
|
|
try {
|
|
|
|
|
const response = await axios({
|
|
|
|
|
url: `http://api.football-data.org/v4/competitions/${selectedLeague}/teams`,
|
|
|
|
|
method: 'GET',
|
|
|
|
|
headers: {
|
|
|
|
|
'X-Auth-Token': '0aa1ed31245d4a36b1ef5a79150324b3',
|
|
|
|
|
},
|
|
|
|
|
});
|
2024-04-17 18:06:45 -06:00
|
|
|
|
2024-04-15 11:04:16 -06:00
|
|
|
const teams = response.data.teams.map(team => team.name);
|
|
|
|
|
return teams;
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error fetching teams data:', error);
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
module.exports = fetchTeamNames;
|