From 745a5c90c30829f5b2d27575d56021afab92cf72 Mon Sep 17 00:00:00 2001 From: uo288245 Date: Mon, 8 Apr 2024 18:45:43 +0200 Subject: [PATCH] Introduced logs to test groups deployed fail. --- gatewayservice/gateway-service.js | 2 ++ users/routes/user-routes.js | 25 ++++++++----------------- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/gatewayservice/gateway-service.js b/gatewayservice/gateway-service.js index 9b57cbd8..f509904e 100644 --- a/gatewayservice/gateway-service.js +++ b/gatewayservice/gateway-service.js @@ -149,7 +149,9 @@ app.get('/user/statistics/:username', async (req, res) => { app.get('/user/group/list', async (req, res) => { try { const username = req.query.username; + console.log("username: ", username); const userResponse = await axios.get(userServiceUrl + '/user/group/list',{params: {username: username }}); + console.log("userResponse: ", userResponse); res.json(userResponse.data); } catch (error) { handleErrors(res, error); diff --git a/users/routes/user-routes.js b/users/routes/user-routes.js index e328f57a..f528b88a 100644 --- a/users/routes/user-routes.js +++ b/users/routes/user-routes.js @@ -103,30 +103,19 @@ router.post('/add', async (req, res) => { } }); - -// router.post('/logout', async (req, res) => { -// try { - -// req.session.username = null; -// } catch (error) { -// return res.status(500).json({ error: 'Internal Server Error' }); -// } -// }); - - -// router.get('/session', async (req, res) => { -// res.json({ session: req.session }); -// }); - - // Getting the list of groups in the database router.get('/group/list', async (req, res) => { try { const username = req.query.username; + console.log("usernameUsers: "+username); + // If the user is null or undefined (no one is logged, return all groups) if (username === null || username === undefined) { + + console.log("username is null or undefined"); + const allGroups = await Group.findAll({ order: [['name', 'ASC']] }); const groupsJSON = await Promise.all(allGroups.map(async (group) => { const userCount = await UserGroup.count({ @@ -152,6 +141,7 @@ router.get('/group/list', async (req, res) => { const userGroupNames = userGroups.map(userGroup => userGroup.groupName); const allGroups = await Group.findAll({ order: [['name', 'ASC']] }); + console.log("username is not null or undefined"); const groupsJSON = await Promise.all(allGroups.map(async (group) => { const userCount = await UserGroup.count({ where: { @@ -164,10 +154,11 @@ router.get('/group/list', async (req, res) => { isFull: userCount === 20 }; })); - + console.log("groups json"+groupsJSON); res.json({ groups: groupsJSON }); } catch (error) { + console.log(error); return res.status(500).json({ error: 'Internal Server Error' }); } });