Skip to content
Snippets Groups Projects
Commit 7d375309 authored by Matt Kirby's avatar Matt Kirby
Browse files

Seach returns no dupes now

parent b225cdb5
No related branches found
No related tags found
1 merge request!18Fe search and friends (sorry in advance)
......@@ -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;
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment