Add endpoint to retrieve posts by tag with validation
This commit is contained in:
@@ -233,7 +233,7 @@ postDB = (DB)=>{
|
||||
if(!DB.ObjectID.isValid(profileId)) return [];
|
||||
const profile = await DB.getProfile(profileId);
|
||||
if(!profile) return [];
|
||||
query = {
|
||||
const query = {
|
||||
nonOrganicType: null // Exlcude news
|
||||
};
|
||||
return DB.postCols.find(query).sort({lastUpdated: -1}).limit(50).toArray().then(async (posts)=>{
|
||||
@@ -244,6 +244,25 @@ postDB = (DB)=>{
|
||||
});
|
||||
}
|
||||
|
||||
// For all post with tags const query = { content: { $regex: '#\\w+', $options: 'i' } };
|
||||
DB.getPostsByTag = async (tag, profileId, limit = 50) => {
|
||||
if(!DB.ObjectID.isValid(profileId)) return [];
|
||||
const profile = await DB.getProfile(profileId);
|
||||
if(!profile) return [];
|
||||
let query = {
|
||||
content: {
|
||||
"$regex": tag
|
||||
},
|
||||
nonOrganicType: null // Exlcude news
|
||||
};
|
||||
return DB.postCols.find(query).sort({lastUpdated: -1}).limit(limit).toArray().then(async (posts)=>{
|
||||
return await filterPrivateGroups(posts, profile);
|
||||
}).catch((err)=>{
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.getNews = async () => {
|
||||
let query = {
|
||||
nonOrganicType: 'News'
|
||||
|
||||
Reference in New Issue
Block a user