Entonces, estoy tratando de arreglar mi página de inicio en mi sitio web, pero solo imprime mi error No se pueden leer las propiedades de undefined (leyendo 'nombre de usuario') este es mi error
Traté de corregir mi error eliminándolo, pero siguió imprimiendo el error pero con una propiedad diferente, así que creo que el problema no es esa propiedad sino singleHighscore
const express = require("express"); const router = express.Router(); const db = require("../queries"); /* GET home page. */ router.get("/", async function (req, res, next) { const highscore = await db.getHighscore(1); const game = await db.getGame(1); const games = await db.getGames(10); const highscores = await db.getHighscores(10); const searchGames = await db.getSearch("C"); res.render("index", { title: "Express", games: games, highscores: highscores, singleHighscore: highscore, singleGame: game, searchGames: searchGames, }); }); module.exports = router;Este código superior es el que afecta al código inferior.
<div> <p><%=singleHighscore.username%></p> <p><%=singleHighscore.game.name%></p> <p><%=singleHighscore.score%></p> <p><%=singleHighscore.active%></p> </div>Este es el código inferior que afecta a getHighscores
const getHighscore = async (id) => { let highscore; const pool = new Pool(credentials); await pool .query(`SELECT * FROM public.highscores WHERE id= ${id}`) .then((res) => { highscore = res.rows[0]; }); if (highscore && highscore.hasOwnProperty("gameid")) await pool .query(`SELECT * FROM public.games WHERE id= ${highscore.gameid}`) .then((res) => (highscore.game = res.rows[0])); return highscore; };