diff --git a/statsservice/stats-service.js b/statsservice/stats-service.js index a5756df9..0050281e 100644 --- a/statsservice/stats-service.js +++ b/statsservice/stats-service.js @@ -83,7 +83,7 @@ app.post("/saveGame", async (req, res) => { ); } - res.json({ message: "Partida guardada exitosamente" }); + res.status(200).json({ message: "Partida guardada exitosamente" }); } } catch (error) { res.status(400).json({ error: "Error al guardar juego" + error.message }); @@ -99,7 +99,7 @@ app.get("/stats", async (req, res) => { if (!data) { res.status(400).json({ error: "User not found" }); } else { - res.json(data); + res.status(200).json(data); } } catch (error) { res @@ -126,7 +126,7 @@ app.get("/ranking", async (req, res) => { throw new Error("No se encontraron estadísticas"); } - res.json(data); + res.status(200).json(data); } catch (error) { res .status(400) diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js index d5d6a973..7774f015 100644 --- a/users/userservice/user-service.js +++ b/users/userservice/user-service.js @@ -79,7 +79,7 @@ app.post("/adduser", async (req, res) => { expiresIn: "1h", }); - res.json({ + res.status(200).json({ username: newUser.username, createdAt: newUser.createdAt, token: token, @@ -93,7 +93,7 @@ app.post("/adduser", async (req, res) => { app.get("/users", async (req, res) => { try { const users = await User.find(); - res.json(users); + res.status(200).json(users); } catch (error) { res.status(500).json({ error: "Internal Server Error" }); } @@ -117,7 +117,7 @@ app.get("/users/search", async (req, res) => { username: { $ne: un, $nin: currentUserFriends }, }); - res.json(users); + res.status(200).json(users); } catch (error) { res.status(500).json({ error: "Internal Server Error" }); } @@ -143,7 +143,7 @@ app.post("/users/add-friend", async (req, res) => { user.friends.push(friendUsername); await user.save(); - res.json({ message: "Friend added successfully" }); + res.status(200).json({ message: "Friend added successfully" }); } catch (error) { res.status(500).json({ error: "Internal Server Error" }); } @@ -171,7 +171,7 @@ app.post("/users/remove-friend", async (req, res) => { user.friends = user.friends.filter((friend) => friend !== friendUsername); await user.save(); - res.json({ message: "Friend removed successfully" }); + res.status(200).json({ message: "Friend removed successfully" }); } catch (error) { console.error("Error removing friend:", error); res.status(500).json({ error: "Internal Server Error" }); @@ -189,7 +189,7 @@ app.get("/friends", async (req, res) => { return res.status(404).json({ error: "User not found" }); } // Devuelve la lista de amigos - res.json({ friends: user.friends }); + res.status(200).json({ friends: user.friends }); } catch (error) { res.status(500).json({ error: "Internal Server Error" }); } @@ -202,7 +202,7 @@ app.get("/userInfo", async (req, res) => { { username: username }, { username: 1, createdAt: 1, games: 1 } ); - res.json(user); + res.status(200).json(user); } catch (error) { res.status(400).json({ error: error.message }); } @@ -220,7 +220,7 @@ app.get("/userGames", async (req, res) => { if (!user) { return res.status(404).json({ error: "Usuario no encontrado" }); } - res.json(user.games); + res.status(200).json(user.games); } catch (error) { res.status(400).json({ error: error.message }); } @@ -244,7 +244,7 @@ app.post("/saveGameList", async (req, res) => { await user.save(); - res.json({ message: "Partida guardada exitosamente" }); + res.status(200).json({ message: "Partida guardada exitosamente" }); } catch (error) { res.status(400).json({ error: "Error al guardar partida en la lista: " + error.message }); } @@ -253,7 +253,7 @@ app.post("/saveGameList", async (req, res) => { app.get('/group/list', async (req, res) => { try { const allGroups = await Group.find(); - res.json({ groups: allGroups }); + res.status(200).json({ groups: allGroups }); } catch (error) { res.status(500).json({ error: 'Internal Server Error' }); } @@ -269,7 +269,7 @@ app.get('/group/:groupName', async (req, res) => { return res.status(404).json({ error: 'Group not found' }); } - res.json({ group }); + res.status(200).json({ group }); } catch (error) { res.status(400).json({ error: error.message }); } @@ -301,7 +301,7 @@ app.post('/group/add', async (req, res) => { createdAt:Date.now() }); await newGroup.save(); - res.json({ message: 'Group created successfully' }); + res.status(200).json({ message: 'Group created successfully' }); } catch (error) { res.status(400).json({ error: error.message }); } @@ -330,7 +330,7 @@ app.post('/group/join', async (req, res) => { group.members.push(username); await group.save(); - res.json({ message: 'User joined the group successfully' }); + res.status(200).json({ message: 'User joined the group successfully' }); } catch (error) { res.status(400).json({ error: error.message }); } diff --git a/webapp/src/pages/Ranking/Ranking.js b/webapp/src/pages/Ranking/Ranking.js index b3ecc1a1..750fde6f 100644 --- a/webapp/src/pages/Ranking/Ranking.js +++ b/webapp/src/pages/Ranking/Ranking.js @@ -27,9 +27,7 @@ const Ranking = () => { fetch(gatewayUrl + `/ranking?gamemode=${gamemode}&filterBy=${filterBy}`) .then((response) => response.json()) .then((data) => { - if (!data.ok) { - throw new Error(data.message || "Ha ocurrido un error"); - } + setRanking(data); setIsLoading(false); }) diff --git a/webapp/src/pages/Social/GroupDetails.js b/webapp/src/pages/Social/GroupDetails.js index 80139d2b..f63c2d80 100644 --- a/webapp/src/pages/Social/GroupDetails.js +++ b/webapp/src/pages/Social/GroupDetails.js @@ -1,5 +1,5 @@ import React, { useState, useEffect } from "react"; -import { useParams, useNavigate } from "react-router-dom"; +import { useParams } from "react-router-dom"; import { Container, Box, @@ -19,7 +19,6 @@ import Nav from "../../components/Nav/Nav.js"; import Footer from "../../components/Footer/Footer.js"; import { useTranslation } from "react-i18next"; import Perfil from "../../components/Profile/Profile.js"; -import { set } from "date-fns"; const GroupDetails = () => { const { t } = useTranslation(); @@ -29,7 +28,6 @@ const GroupDetails = () => { const { groupName } = useParams(); const apiEndpoint = process.env.REACT_APP_API_ENDPOINT || "http://localhost:8000"; - const navigate = useNavigate(); useEffect(() => { fetchGroupDetails(); @@ -41,9 +39,9 @@ const GroupDetails = () => { const response = await fetch( `${apiEndpoint}/group/${encodeURIComponent(groupName)}` ); - if (!response.ok) { - throw new Error("Network response was not ok"); - } + // if (!response.status === 200) { + // throw new Error("Network response was not ok"); + // } const data = await response.json(); setGroup(data.group); setError(null); diff --git a/webapp/src/pages/Stats/Stats.js b/webapp/src/pages/Stats/Stats.js index 4b3d68c2..a52eef8b 100644 --- a/webapp/src/pages/Stats/Stats.js +++ b/webapp/src/pages/Stats/Stats.js @@ -28,10 +28,11 @@ const Stats = () => { const fetchStats = (mode) => { setIsLoading(true); - fetch(gatewayUrl + `/stats?user=${username}&gamemode=${mode}`) + fetch(gatewayUrl + `/stats?username=${username}&gamemode=${mode}`) .then((response) => response.json()) .then((data) => { - if (!data.ok) { + console.log(data); + if (!data._id) { throw new Error(data.message || "Ha ocurrido un error"); } setStats(data); @@ -152,6 +153,7 @@ const Stats = () => { {t("pages.stats.wisebattery")}