Skip to content

Commit

Permalink
fix getUsersByIds to pass sonarcloud
Browse files Browse the repository at this point in the history
  • Loading branch information
pelazas committed Apr 29, 2024
1 parent e6a9563 commit 8a40efb
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions users/userservice/UserController.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,20 +126,15 @@ let UserController = {
res.json(response);
},
getUsersByIds: async (req, res) => {
try{
try {
const userIds = req.body.userIds;
const users = [];
for(const id of userIds){
if(!isValidUuidV4(id)){
throw new Error(`Invalid UUID provided`);
} else {
const user = await User.findOne({ uuid: id });
users.push(user);
}
}
// Fetch all users from the database
const allUsers = await User.find();
// Filter users based on provided UUIDs
const users = allUsers.filter(user => userIds.includes(user.uuid));
res.json(users);
} catch(error){
console.log(error)
} catch(error) {
console.log(error);
res.status(500).json({ error: error.message });
}
},
Expand Down

0 comments on commit 8a40efb

Please sign in to comment.