From 0cec2c1b9e88862fe7934b57a41c4c17bcca370c Mon Sep 17 00:00:00 2001 From: uo289689 Date: Fri, 26 Apr 2024 20:49:39 +0200 Subject: [PATCH] Fixed error on get the statistics of an user --- users/routes/user-routes.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/users/routes/user-routes.js b/users/routes/user-routes.js index 663759c5..ab6ed088 100644 --- a/users/routes/user-routes.js +++ b/users/routes/user-routes.js @@ -588,12 +588,14 @@ router.get('/statistics/:username', async (req,res) => { } }); - const hasCommonGroup = userGroups.some(userGroup => { - return loggedUserGroups.some(loggedUserGroup => loggedUserGroup.groupName === userGroup.groupName); - }); - - if(!hasCommonGroup){ - return res.status(403).json({ error: 'You are not allowed to see this user statistics' }); + if (loggedUserGroups.length != 0 && userGroups != 0){ + const hasCommonGroup = userGroups.some(userGroup => { + return loggedUserGroups.some(loggedUserGroup => loggedUserGroup.groupName === userGroup.groupName); + }); + + if(!hasCommonGroup){ + return res.status(403).json({ error: 'You are not allowed to see this user statistics' }); + } } }