search profiles withot search
This commit is contained in:
@@ -13,7 +13,7 @@ userDB = (DB) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
DB.getProfile = async (profileId) => {
|
DB.getProfile = async (profileId) => {
|
||||||
//if (userProfileCache[profileId]) return userProfileCache[profileId];
|
//if (userProfileCache[profileId] && !userProfileCache[profileId].isGroup) return userProfileCache[profileId];
|
||||||
const _id = DB.ObjectID(profileId);
|
const _id = DB.ObjectID(profileId);
|
||||||
let r = await DB.profileCols.findOne({ _id }).catch((err) => {
|
let r = await DB.profileCols.findOne({ _id }).catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
@@ -23,6 +23,16 @@ userDB = (DB) => {
|
|||||||
return r;
|
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) => {
|
DB.getUserProfiles = async (userId) => {
|
||||||
const userid = DB.ObjectID(userId);
|
const userid = DB.ObjectID(userId);
|
||||||
return await DB.profileCols.find({ userid }).toArray().catch((err) => {
|
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
|
//Groups
|
||||||
DB.getGroups = async () => {
|
DB.getGroups = async () => {
|
||||||
let r = await DB.profileCols.find({isGroup: true})
|
let r = await DB.profileCols.find({isGroup: true})
|
||||||
@@ -84,7 +110,7 @@ userDB = (DB) => {
|
|||||||
|
|
||||||
DB.getGroup = async (groupid) => {
|
DB.getGroup = async (groupid) => {
|
||||||
const _id = DB.ObjectID(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})
|
let r = await DB.profileCols.findOne({_id, isGroup: true})
|
||||||
.toArray().catch((err) => {
|
.toArray().catch((err) => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ class User {
|
|||||||
this.isGroup = info.isGroup || false;
|
this.isGroup = info.isGroup || false;
|
||||||
this.isCourse = info.isCourse || false;
|
this.isCourse = info.isCourse || false;
|
||||||
this.subscribed = info.subscribed || {};
|
this.subscribed = info.subscribed || {};
|
||||||
|
this.notifications = info.notifications || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
toObj(){
|
toObj(){
|
||||||
@@ -34,6 +35,7 @@ class User {
|
|||||||
r.isGroup = this.isGroup;
|
r.isGroup = this.isGroup;
|
||||||
r.isCourse = this.isCourse;
|
r.isCourse = this.isCourse;
|
||||||
r.subscribed = this.subscribed;
|
r.subscribed = this.subscribed;
|
||||||
|
r.notifications = this.notifications;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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) => {
|
router.get("/:id", async (req, res) => {
|
||||||
let profileId = req.params.id;
|
let profileId = req.params.id;
|
||||||
let profile = await DB.getProfile(profileId);
|
let profile = await DB.getProfile(profileId);
|
||||||
|
|||||||
Reference in New Issue
Block a user