diff --git a/backend-services/user-service/controllers/appController.js b/backend-services/user-service/controllers/appController.js index 40e1ca87f5a69d7a72013d01ffa98ec8dc52ab45..b5038175cf872348bd4da7a34af69d0d6ebfd09f 100644 --- a/backend-services/user-service/controllers/appController.js +++ b/backend-services/user-service/controllers/appController.js @@ -245,9 +245,21 @@ export const GetUserList = async (req,res) => { const usersWithMatchingUsername = await UserModel.find({"username": {"$regex": `^${searchQuery}`}}, {password: 0, email: 0}) const usersWithMatchingName = await UserModel.find({$or: [{"firstName": {"$regex": `^${searchQuery}`,"$options": 'i'}}, {"lastName": {"$regex": `^${searchQuery}`,"$options": 'i'}}]}, {password: 0, email: 0}) - return res.status(201).send({ usersByUsername: usersWithMatchingUsername, usersByName: usersWithMatchingName}); + const result = getDistinctArray([...usersWithMatchingUsername, ...usersWithMatchingName]) + + return res.status(201).send({result: result}); } catch(error){ return res.status(401).send({ error: error.message }); } } +function getDistinctArray(arr) { + var dups = {}; + return arr.filter(function(el) { + var hash = el.valueOf(); + var isDup = dups[hash]; + dups[hash] = true; + return !isDup; + }); +} +