diff --git a/statsservice/stats-service.js b/statsservice/stats-service.js index d6c177de..ac33eca3 100644 --- a/statsservice/stats-service.js +++ b/statsservice/stats-service.js @@ -98,12 +98,12 @@ app.post("/saveGame", async (req, res) => { ); } - res.status(200).json({ message: "Partida guardada exitosamente" }); + res.status(200).json({ message: "Game saved successfully" }); } else { throw new Error("Invalid game mode"); } } catch (error) { - res.status(400).json({ error: "Error al guardar juego: " + error.message }); + res.status(400).json({ error: "Error while saving game: " + error.message }); } }); @@ -121,7 +121,7 @@ app.get("/stats", async (req, res) => { } catch (error) { res .status(400) - .json({ error: "Error al obtener las estadísticas:" + error.message }); + .json({ error: "Error getting stats:" + error.message }); } }); @@ -131,8 +131,8 @@ app.get("/ranking", async (req, res) => { let gamemode = req.query.gamemode; let data = await Stats.find({ gamemode: gamemode }) - .sort(sortBy) - .limit(10); + .sort(sortBy === 'avgTime' ? { [sortBy]: 1 } : { [sortBy]: -1 }) + .limit(10); if (data && data.length > 0) { data = data.map((stat) => ({ @@ -140,14 +140,14 @@ app.get("/ranking", async (req, res) => { [sortBy]: stat[sortBy], })); } else { - throw new Error("No se encontraron estadísticas"); + throw new Error("No stats found"); } res.status(200).json(data); } catch (error) { res .status(400) - .json({ error: "Error al obtener el ranking: " + error.message }); + .json({ error: "Error getting ranking: " + error.message }); } }); diff --git a/webapp/src/locales/en.json b/webapp/src/locales/en.json index 0879d619..8c85712e 100644 --- a/webapp/src/locales/en.json +++ b/webapp/src/locales/en.json @@ -160,7 +160,8 @@ "ratioCorrect": "Correct Ratio (%)", "avgTime": "Time per Question (s):", "reboot": "Reset to Default", - "errorText": "An error occurred while retrieving the ranking" + "errorText": "An error occurred while retrieving the ranking", + "noStats":"No stats found for this gamemode" }, "about": { "title": "WIQ_es1a Team", diff --git a/webapp/src/locales/es.json b/webapp/src/locales/es.json index d8a072d4..005c8f87 100644 --- a/webapp/src/locales/es.json +++ b/webapp/src/locales/es.json @@ -160,7 +160,8 @@ "ratioCorrect": "Ratio de aciertos (%)", "avgTime": "Tiempo por pregunta (s):", "reboot": "Restablecer por defecto", - "errorText": "Ha ocurrido un error al obtener el ranking" + "errorText": "Ha ocurrido un error al obtener el ranking", + "noStats":"No hay estadísticas para este modo de juego" }, "about": { "title": "Equipo WIQ_es1a", diff --git a/webapp/src/pages/Ranking/Ranking.js b/webapp/src/pages/Ranking/Ranking.js index 9605193e..d8efc643 100644 --- a/webapp/src/pages/Ranking/Ranking.js +++ b/webapp/src/pages/Ranking/Ranking.js @@ -27,7 +27,6 @@ const Ranking = () => { fetch(gatewayUrl + `/ranking?gamemode=${gamemode}&filterBy=${filterBy}`) .then((response) => response.json()) .then((data) => { - setRanking(data); setIsLoading(false); }) @@ -110,13 +109,13 @@ const Ranking = () => { if (error) { return ( <> - -
{t('pages.ranking.errorLabel')}
-{error}
+{t('pages.ranking.user')} | @@ -170,6 +171,15 @@ const Ranking = () => { ))}
---|
{t('pages.ranking.noStats')}
+