So, I'm making a football webapp in which currently few things are only one is you can see live score for which I have controller and another thing is You can see any team information teams in that league
And front end of it now I want you to modify my leaguecontroller such that it can also provide data of matches which it may take from scoreController and standings which it will take from API which I have provided and also top scorer in that league which has category like from which team is playing 
// controllers/leagueController.js

const axios = require("axios");

/**
 * Fetches detailed information about a specific league and its teams.
 * Route: GET /leagues/:code
 * Example: GET /leagues/PL
 */
async function leagueController(req, res) {
  try {
    const leagueCode = req.params.code.toUpperCase(); // Ensure the league code is uppercase (e.g., 'PL')

    // Define the API endpoints
    const leagueInfoUrl = `https://api.football-data.org/v4/competitions/${leagueCode}`;
    const leagueTeamsUrl = `https://api.football-data.org/v4/competitions/${leagueCode}/teams`;

    // Make parallel API requests for league info and teams
    const [leagueResponse, teamsResponse] = await Promise.all([
      axios.get(leagueInfoUrl, {
        headers: { "X-Auth-Token": process.env.API_FOOTBALL_KEY1 },
      }),
      axios.get(leagueTeamsUrl, {
        headers: { "X-Auth-Token": process.env.API_FOOTBALL_KEY1 },
      }),
    ]);
   
    const leagueData = leagueResponse.data;
    const teamsData = teamsResponse.data.teams;

    // Structure the response
    res.status(200).json({
      league: {
        id: leagueData.id,
        name: leagueData.name,
        code: leagueData.code,
        type: leagueData.type,
        emblem: leagueData.emblem,
        area: leagueData.area,
        currentSeason: leagueData.currentSeason,
      },
      teams: teamsData.map((team) => ({
        id: team.id,
        name: team.name,
        shortName: team.shortName,
        tla: team.tla,
        crest: team.crest,
        venue: team.venue,
        website: team.website,
        founded: team.founded,
        clubColors: team.clubColors,
      })),
    });
  } catch (error) {
    console.error("Error fetching league data:", error.message);

    // Handle specific API errors
    if (error.response) {
      const { status, data } = error.response;
      return res.status(status).json({
        message: data.message || "Error fetching league data from API.",
      });
    }

    // Generic server error
    res.status(500).json({
      message: "Unable to retrieve league data. Please try again later.",
    });
  }
}

module.exports = leagueController;


const axios = require("axios");

async function scoresController(req, res) {
  try {
    const apiUrl = "https://api.football-data.org/v4/matches";
    const response = await axios.get(apiUrl, {
      headers: {
        "X-Auth-Token": process.env.API_FOOTBALL_KEY,
      },
      params: {
        dateFrom: new Date().toISOString().split("T")[0],
        dateTo: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000)
          .toISOString()
          .split("T")[0],
      },
    });

    const leagueIds = {
      2014: "La Liga",
      2021: "Premier League",
      2002: "Bundesliga",
      2019: "Serie A",
      2015: "Ligue 1",
      2001: "UEFA Champions League",
      2146: "UEFA Europa League",
    };

    const filteredMatches = response.data.matches.map((match) => {
      const leagueName = leagueIds[match.competition.id] || "Other";
      return {
        id: match.id,
        utcDate: match.utcDate,
        status: match.status,
        league: leagueName,
        homeTeam: match.homeTeam,
        awayTeam: match.awayTeam,
        score: match.score,
        odds: Math.random().toFixed(2), // Mock data
        avgP: (Math.random() * 100).toFixed(2), // Mock data
        avgG: (Math.random() * 5).toFixed(2), // Mock data
        cG: Math.floor(Math.random() * 10), // Mock data
        BTS: Math.random() > 0.5 ? "Yes" : "No", // Mock data
        FTS: Math.random() > 0.5 ? "Yes" : "No", // Mock data
        "c>2,5": Math.random() > 0.5 ? "Yes" : "No", // Mock data
      };
    });

    const groupedMatches = filteredMatches.reduce((acc, match) => {
      if (!acc[match.league]) {
        acc[match.league] = [];
      }
      acc[match.league].push(match);
      return acc;
    }, {});

    res.status(200).json(groupedMatches);
  } catch (error) {
    console.error("Error fetching live scores:", error.message);
    res.status(500).json({
      message: "Unable to retrieve live scores. Please try again later.",
    });
  }
}

module.exports = scoresController;

// controllers/leaguesController.js

const axios = require("axios");

/**
 * Fetches a list of all available leagues (competitions).
 * Route: GET /leagues
 */
async function leaguesController(req, res) {
  try {
    const apiUrl = "https://api.football-data.org/v4/competitions";

    const response = await axios.get(apiUrl, {
      headers: { "X-Auth-Token": process.env.API_FOOTBALL_KEY1 },
      params: {
        plan: "TIER_ONE", // Optional: Filter competitions by plan if needed
      },
    });

    const competitions = response.data.competitions;

    // Map and structure the competitions data
    const leagues = competitions.map((competition) => ({
      id: competition.id,
      name: competition.name,
      code: competition.code,
      type: competition.type,
      emblem: competition.emblem,
      area: competition.area,
    }));

    res.status(200).json({
      count: leagues.length,
      leagues,
    });
  } catch (error) {
    console.error("Error fetching leagues data:", error.message);

    // Handle specific API errors
    if (error.response) {
      const { status, data } = error.response;
      return res.status(status).json({
        message: data.message || "Error fetching leagues data from API.",
      });
    }

    // Generic server error
    res.status(500).json({
      message: "Unable to retrieve leagues data. Please try again later.",
    });
  }
}

module.exports = leaguesController;



Request:
curl -X GET http://api.football-data.org/v4/competitions/PL/standings
(Abbreviated) Response:
{
    "filters": {
        "season": "2021"
    },
    "area": {
        "id": 2072,
        "name": "England",
        "code": "ENG",
        "flag": "https://crests.football-data.org/770.svg"
    },
    "competition": {
        "id": 2021,
        "name": "Premier League",
        "code": "PL",
        "type": "LEAGUE",
        "emblem": "https://crests.football-data.org/PL.png"
    },
    "season": {
        "id": 733,
        "startDate": "2021-08-13",
        "endDate": "2022-05-22",
        "currentMatchday": 37,
        "winner": null,
        "stages": [
            "REGULAR_SEASON"
        ]
    },
    "standings": [
        {
            "stage": "REGULAR_SEASON",
            "type": "TOTAL",
            "group": null,
            "table": [
                {
                    "position": 1,
                    "team": {
                        "id": 65,
                        "name": "Manchester City FC",
                        "shortName": "Man City",
                        "tla": "MCI",
                        "crest": "https://crests.football-data.org/65.png"
                    },
                    "playedGames": 37,
                    "form": "D,W,W,W,W",
                    "won": 28,
                    "draw": 6,
                    "lost": 3,
                    "points": 90,
                    "goalsFor": 96,
                    "goalsAgainst": 24,
                    "goalDifference": 72
                },
                {
                    "position": 2,
                    "team": {
                        "id": 64,
                        "name": "Liverpool FC",
                        "shortName": "Liverpool",
                        "tla": "LIV",
                        "crest": "https://crests.football-data.org/64.png"
                    },
                    "playedGames": 36,
                    "form": "W,D,W,W,W",
                    "won": 26,
                    "draw": 8,
                    "lost": 2,
                    "points": 86,
                    "goalsFor": 89,
                    "goalsAgainst": 24,
                    "goalDifference": 65
                },
                {
                    "position": 3,
                    "team": {
                        "id": 61,
                        "name": "Chelsea FC",
                        "shortName": "Chelsea",
                        "tla": "CHE",
                        "crest": "https://crests.football-data.org/61.png"
                    },
                    "playedGames": 36,
                    "form": "W,D,L,D,W",
                    "won": 20,
                    "draw": 10,
                    "lost": 6,
                    "points": 70,
                    "goalsFor": 73,
                    "goalsAgainst": 31,
                    "goalDifference": 42
                },
This sample API request and response for standings for you as an example 
And matches are fetched in scoreController.js which you can use
curl -X GET http://api.football-data.org/v4/competitions/SA/scorers
(Abbreviated) Response:
{
    "count": 10,
    "filters": {
        "season": "2021",
        "limit": 10
    },
    "competition": {
        "id": 2019,
        "name": "Serie A",
        "code": "SA",
        "type": "LEAGUE",
        "emblem": "https://crests.football-data.org/SA.png"
    },
    "season": {
        "id": 757,
        "startDate": "2021-08-21",
        "endDate": "2022-05-22",
        "currentMatchday": 37,
        "winner": null,
        "stages": [
            "REGULAR_SEASON"
        ]
    },
    "scorers": [
        {
            "player": {
                "id": 2076,
                "name": "Ciro Immobile",
                "firstName": "Ciro",
                "lastName": "Immobile",
                "dateOfBirth": "1990-02-20",
                "nationality": "Italy",
                "position": "Offence",
                "shirtNumber": null,
                "lastUpdated": "2021-10-13T08:03:51Z"
            },
            "team": {
                "id": 110,
                "name": "SS Lazio",
                "shortName": "Lazio",
                "tla": "LAZ",
                "crest": "https://crests.football-data.org/110.svg",
                "address": "Via di Santa Cornelia, 1000 Formello 00060",
                "website": "http://www.sslazio.it",
                "founded": 1900,
                "clubColors": "White / Sky Blue",
                "venue": "Stadio Olimpico",
                "lastUpdated": "2020-11-26T02:19:41Z"
            },
            "goals": 27,
            "assists": 2,
            "penalties": 7
        },
        {
            "player": {
                "id": 82002,
                "name": "Dušan Vlahović",
                "firstName": "Dušan",
                "lastName": null,
                "dateOfBirth": "2000-01-28",
                "nationality": "Serbia",
                "position": "Offence",
                "shirtNumber": null,
                "lastUpdated": "2020-09-07T21:10:05Z"
            },
            "team": {
                "id": 109,
                "name": "Juventus FC",
                "shortName": "Juventus",
                "tla": "JUV",
                "crest": "https://crests.football-data.org/109.svg",
                "address": "Corso Galileo Ferraris, 32 Torino 10128",
                "website": "http://www.juventus.com",
                "founded": 1897,
                "clubColors": "White / Black",
                "venue": "Allianz Stadium",
                "lastUpdated": "2020-11-26T02:19:40Z"
            },
            "goals": 24,
            "assists": 3,
            "penalties": 5
        },
        {
            "player": {
                "id": 3220,
                "name": "Lautaro Martínez",
                "firstName": "Lautaro Javier",
                "lastName": null,
                "dateOfBirth": "1997-08-22",
                "nationality": "Argentina",
                "position": "Offence",
                "shirtNumber": null,
                "lastUpdated": "2020-09-07T21:10:27Z"
            },
            "team": {
                "id": 108,
                "name": "FC Internazionale Milano",
                "shortName": "Inter",
                "tla": "INT",
                "crest": "https://crests.football-data.org/108.png",
                "address": "Corso Vittorio Emanuele II 9 Milano 20122",
                "website": "http://www.inter.it",
                "founded": 1908,
                "clubColors": "Blue / Black",
                "venue": "Stadio Giuseppe Meazza",
                "lastUpdated": "2021-11-24T14:55:58Z"
            },
            "goals": 21,
            "assists": 3,
            "penalties": 3
        },
This is sample API request response for scorers 
Now make me do this I have used two api keys as it is free and limited I got so make sure that