diff --git a/cryptide_project/server/api/controllers/SessionController.js b/cryptide_project/server/api/controllers/SessionController.js index e0993b0..653389c 100644 --- a/cryptide_project/server/api/controllers/SessionController.js +++ b/cryptide_project/server/api/controllers/SessionController.js @@ -37,7 +37,10 @@ class SessionController { nbGamesEF = nbGamesEF.nbGames || 0; let nbWinsEF = await db.getNbWinsEnigmeByUserId(req.session.user.idUser, ENIGME_FACILE); nbWinsEF = nbWinsEF.nbWins || 0; - let ratioEF = (nbWinsEF.nbWins / nbGamesEF.nbGames) * 100 || 0; + let ratioEF = 0; + if (nbWinsEF.nbWins > 0){ + ratioEF = (nbWinsEF.nbWins / nbGamesEF.nbGames) * 100; + } let bestTimeEF = await db.getBestTimeEnigmeByUserId(req.session.user.idUser, ENIGME_FACILE); bestTimeEF = bestTimeEF.bestTime || 0; let avgTimeEF = await db.getAvgTimeEnigmeByUserId(req.session.user.idUser, ENIGME_FACILE); @@ -66,7 +69,10 @@ class SessionController { nbGamesED = nbGamesED.nbGames || 0; let nbWinsED = await db.getNbWinsEnigmeByUserId(req.session.user.idUser, ENIGME_DIFFICILE); nbWinsED = nbWinsED.nbWins || 0; - let ratioED = (nbWinsED.nbWins / nbGamesED.nbGames) * 100 || 0; + let ratioED = 0; + if (nbWinsED.nbWins > 0){ + ratioED = (nbWinsED.nbWins / nbGamesED.nbGames) * 100; + } let bestTimeED = await db.getBestTimeEnigmeByUserId(req.session.user.idUser, ENIGME_DIFFICILE); bestTimeED = bestTimeED.bestTime || 0; let avgTimeED = await db.getAvgTimeEnigmeByUserId(req.session.user.idUser, ENIGME_DIFFICILE); @@ -83,7 +89,10 @@ class SessionController { nbGamesOL = nbGamesOL.nbGames || 0; let nbWinsOL = await db.getNbWinsOnlineByUserId(req.session.user.idUser); nbWinsOL = nbWinsOL.nbWins || 0; - let ratioOL = (nbWinsOL.nbWins / nbGamesOL.nbGames) * 100 || 0; + let ratioOL = 0 + if (nbWinsOL.nbWins > 0){ + ratioOL = (nbWinsOL.nbWins / nbGamesOL.nbGames) * 100; + } req.session.user.onlineStats = {nbGames: nbGamesOL, nbWins: nbWinsOL, ratio: ratioOL};