search profiles withot search

This commit is contained in:
Adolfo Reyna
2021-09-06 13:22:35 -07:00
parent 8490359ea7
commit 66748cec8b
3 changed files with 39 additions and 2 deletions

View File

@@ -13,7 +13,7 @@ userDB = (DB) => {
}
DB.getProfile = async (profileId) => {
//if (userProfileCache[profileId]) return userProfileCache[profileId];
//if (userProfileCache[profileId] && !userProfileCache[profileId].isGroup) return userProfileCache[profileId];
const _id = DB.ObjectID(profileId);
let r = await DB.profileCols.findOne({ _id }).catch((err) => {
console.log(err);
@@ -23,6 +23,16 @@ userDB = (DB) => {
return r;
}
DB.getProfiles = async (query) => {
let r = await DB.profileCols.find({isGroup: false})
.sort({ lastUpdate: -1 }).limit(20)
.toArray().catch((err) => {
console.log(err);
return false;
});
return r;
}
DB.getUserProfiles = async (userId) => {
const userid = DB.ObjectID(userId);
return await DB.profileCols.find({ userid }).toArray().catch((err) => {
@@ -71,6 +81,22 @@ userDB = (DB) => {
});
}
DB.addNotification = async (profileid, message) => {
const _id = DB.ObjectID(profileid);
let update = {
$push:{
notifications: {
ts: new Date(),
body: message
}
}
}
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
console.log(err);
return false;
});
}
//Groups
DB.getGroups = async () => {
let r = await DB.profileCols.find({isGroup: true})
@@ -84,7 +110,7 @@ userDB = (DB) => {
DB.getGroup = async (groupid) => {
const _id = DB.ObjectID(groupid);
if(userProfileCache[groupid]) return userProfileCache[groupid];
//if(userProfileCache[groupid]) return userProfileCache[groupid];
let r = await DB.profileCols.findOne({_id, isGroup: true})
.toArray().catch((err) => {
console.log(err);

View File

@@ -19,6 +19,7 @@ class User {
this.isGroup = info.isGroup || false;
this.isCourse = info.isCourse || false;
this.subscribed = info.subscribed || {};
this.notifications = info.notifications || [];
}
toObj(){
@@ -34,6 +35,7 @@ class User {
r.isGroup = this.isGroup;
r.isCourse = this.isCourse;
r.subscribed = this.subscribed;
r.notifications = this.notifications;
return r;
}

View File

@@ -87,6 +87,15 @@ DB.getDB.then((DB)=>{
});
});
router.get("/search", async (req, res) => {
let query = req.query.query;
let profiles = await DB.getProfiles(query);
return res.json({
status: "ok",
profiles
});
});
router.get("/:id", async (req, res) => {
let profileId = req.params.id;
let profile = await DB.getProfile(profileId);