diff --git a/public/views/pages/leagues-page.hbs b/public/views/pages/leagues-page.hbs index 15e142e..1c92f1b 100644 --- a/public/views/pages/leagues-page.hbs +++ b/public/views/pages/leagues-page.hbs @@ -75,9 +75,9 @@ {{#each topScorers.scorers}} {{goals}} - + {{player.player_name}} - {{team.team_name}} + {{team.team_name}} {{games_played}} {{/each}} diff --git a/src/app.js b/src/app.js index fa75c67..23b9031 100644 --- a/src/app.js +++ b/src/app.js @@ -58,23 +58,9 @@ app.use(fetchMatchesData); const convert_time = require("./middleware/navigation-bar/convert-time"); app.use(convert_time); -// Leagues Page Middleware - -const fetchLeaguesData = require("./middleware/leagues-page/get-current-league-information"); -const fetchLeagueScorerData = require("./middleware/leagues-page/get-current-league-top-scorers"); - -app.get( - "/league/:leagueID", - [fetchLeaguesData, fetchLeagueScorerData], - (req, res) => { - // Render the Handlebars view with league data - res.render("pages/leagues-page", { - leagueID: req.params.leagueID, - leagues: res.locals.leagues, - scorers: res.locals.topScorers, // Assuming fetchLeagueScorerData sets the data in res.locals.scorers - }); - } -); +// Other middleware and route imports +const leagueRoutes = require("./routes/league-pages/league-routes"); +leagueRoutes(app); // Clubs Page Middleware diff --git a/src/routes/account/login.js b/src/routes/account/login.js index 52ea3b4..1a69e64 100644 --- a/src/routes/account/login.js +++ b/src/routes/account/login.js @@ -19,7 +19,7 @@ router.post("/login", async (req, res) => { if (!user) { // Redirect user to login screen if no user is found with the provided username - return res.redirect("/register"); + return res.render("pages/home", { message: "User Not Found!" }); } // Check if password from request matches with password in DB @@ -28,7 +28,7 @@ router.post("/login", async (req, res) => { // Check if match returns no data if (!match) { // Render the login page with the message parameter - return res.render("/", { message: "Password does not match" }); + return res.render("pages/home", { message: "Password does not match" }); } else { // Save user information in the session variable req.session.user = user; diff --git a/src/routes/league-pages/league-routes.js b/src/routes/league-pages/league-routes.js new file mode 100644 index 0000000..18e45a7 --- /dev/null +++ b/src/routes/league-pages/league-routes.js @@ -0,0 +1,25 @@ +// src/routes/leagueRoutes.js +const express = require("express"); +const app = express(); + +// Import the middleware functions +const fetchLeaguesData = require("../../middleware/leagues-page/get-current-league-information"); +const fetchLeagueScorerData = require("../../middleware/leagues-page/get-current-league-top-scorers"); + +// Define the route handling function +const leagueRoutes = (app) => { + app.get( + "/league/:leagueID", + [fetchLeaguesData, fetchLeagueScorerData], + (req, res) => { + // Render the Handlebars view with league data + res.render("pages/leagues-page", { + leagueID: req.params.leagueID, + leagues: res.locals.leagues, + scorers: res.locals.topScorers, // Assuming fetchLeagueScorerData sets the data in res.locals.scorers + }); + } + ); +}; + +module.exports = leagueRoutes;