diff --git a/dbTools/profile.js b/dbTools/profile.js index 4c51d72..c3ea60a 100644 --- a/dbTools/profile.js +++ b/dbTools/profile.js @@ -39,8 +39,23 @@ userDB = (DB) => { return DB.getProfile(profileId); } - DB.getProfiles = async (query) => { - let r = await DB.profileCols.find({isGroup: false}) + DB.searchProfile = async (queryStr) => { + let regEx = new RegExp(queryStr, 'i'); + let query = { + isGroup: false, + $or: [ + {"profile.firstName": { + $regex: regEx + }}, + {"profile.lastName": { + $regex: regEx + }}, + {"profile.description": { + $regex: regEx + }}, + ] + }; + let r = await DB.profileCols.find(queryStr ? query : {isGroup: false}) .sort({ lastUpdate: -1 }).limit(20) .toArray().catch((err) => { console.log(err); diff --git a/routes/profile.js b/routes/profile.js index 343d87d..668d9fb 100644 --- a/routes/profile.js +++ b/routes/profile.js @@ -156,7 +156,7 @@ DB.getDB.then((DB)=>{ router.get("/search", async (req, res) => { let query = req.query.query; - let profiles = await DB.getProfiles(query); + let profiles = await DB.searchProfile(query); return res.json({ status: "ok", profiles