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);