Skip to content

Commit

Permalink
Merge branch 'develop-deploy' of https://github.com/Arquisoft/wiq_es04a
Browse files Browse the repository at this point in the history
… into develop-deploy
  • Loading branch information
uo288543 committed Apr 8, 2024
2 parents c87fb2d + 745a5c9 commit fd66ef1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 17 deletions.
2 changes: 2 additions & 0 deletions gatewayservice/gateway-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
25 changes: 8 additions & 17 deletions users/routes/user-routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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: {
Expand All @@ -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' });
}
});
Expand Down

0 comments on commit fd66ef1

Please sign in to comment.