query profiles
This commit is contained in:
+17
-2
@@ -39,8 +39,23 @@ userDB = (DB) => {
|
|||||||
return DB.getProfile(profileId);
|
return DB.getProfile(profileId);
|
||||||
}
|
}
|
||||||
|
|
||||||
DB.getProfiles = async (query) => {
|
DB.searchProfile = async (queryStr) => {
|
||||||
let r = await DB.profileCols.find({isGroup: false})
|
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)
|
.sort({ lastUpdate: -1 }).limit(20)
|
||||||
.toArray().catch((err) => {
|
.toArray().catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|||||||
+1
-1
@@ -156,7 +156,7 @@ DB.getDB.then((DB)=>{
|
|||||||
|
|
||||||
router.get("/search", async (req, res) => {
|
router.get("/search", async (req, res) => {
|
||||||
let query = req.query.query;
|
let query = req.query.query;
|
||||||
let profiles = await DB.getProfiles(query);
|
let profiles = await DB.searchProfile(query);
|
||||||
return res.json({
|
return res.json({
|
||||||
status: "ok",
|
status: "ok",
|
||||||
profiles
|
profiles
|
||||||
|
|||||||
Reference in New Issue
Block a user