reject and notification on request
This commit is contained in:
@@ -163,6 +163,31 @@ userDB = (DB) => {
|
||||
return r;
|
||||
}
|
||||
|
||||
DB.getFollowingGroups = async (profileid) => {
|
||||
const profile = await DB.getProfile(profileId);
|
||||
let ids = [];
|
||||
for(id in profile.following){
|
||||
let oId = DB.ObjectID(id);
|
||||
let checkProfile = await DB.getProfileCache(oId)
|
||||
if(checkProfile && checkProfile.isGroup){
|
||||
ids.push(oId)
|
||||
}
|
||||
}
|
||||
let query = {
|
||||
isGroup: true,
|
||||
isCourse: {$ne: true},
|
||||
_id: {
|
||||
$in: ids
|
||||
}
|
||||
};
|
||||
let r = await DB.profileCols.find(query).sort({ lastUpdate: -1 })
|
||||
.toArray().catch((err) => {
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
return r;
|
||||
}
|
||||
|
||||
DB.searchGroups = async (queryStr, coursesB = false) => {
|
||||
let regEx = new RegExp(queryStr, 'i');
|
||||
let query = queryStr ? {
|
||||
@@ -242,7 +267,21 @@ userDB = (DB) => {
|
||||
["pending." + profileid]: ""
|
||||
}
|
||||
}
|
||||
DB.followProfile(profileid, groupid)
|
||||
DB.followProfile(profileid, groupid);
|
||||
delete userProfileCache[groupid];
|
||||
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
||||
console.log(err);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
DB.rejectGroupJoinReq = async (profileid, groupid) => {
|
||||
const _id = DB.ObjectID(groupid);
|
||||
let update = {
|
||||
$unset:{
|
||||
["pending." + profileid]: ""
|
||||
}
|
||||
}
|
||||
delete userProfileCache[groupid];
|
||||
return DB.profileCols.updateOne({_id}, update).catch((err)=>{
|
||||
console.log(err);
|
||||
|
||||
@@ -123,7 +123,7 @@ const youHaveAnInvitation = (invitedName, invitedEmail, senderProfile) => {
|
||||
|
||||
<p>You have been invited to be part of the new efforts to be connected through our website.</p>
|
||||
|
||||
<p>The socila part of our site is a place to be in contact with the espiritual family, read what is new for all the members and have access to the most recent teachings, as well as our catalog of courses.</p>
|
||||
<p>The social part of our site is a place to be in contact with the espiritual family, read what is new for all the members and have access to the most recent teachings, as well as our catalog of courses.</p>
|
||||
|
||||
<p><a href="https://social.emmint.com/">Register to make an account at https://social.emmint.com/</a></p>
|
||||
|
||||
@@ -137,6 +137,21 @@ ${senderProfile.profile.firstName} ${senderProfile.profile.lastName}
|
||||
sendEmail(invitedEmail, subject, html)
|
||||
}
|
||||
|
||||
const yourGroupHasARequestTemplate = (groupProfile, ownerEmail, senderProfile) => {
|
||||
let subject = senderProfile.profile.firstName + " wants to join " + groupProfile.profile.firstName + groupProfile.profile.lastName;
|
||||
let html = `
|
||||
<p>Hello Admin of ${groupProfile.profile.firstName} ${groupProfile.profile.lastName},</p>
|
||||
|
||||
<p>Your group, has a new request from ${senderProfile.profile.firstName} ${senderProfile.profile.lastName}</p>
|
||||
|
||||
<p>To respond to this request <a href="https://social.emmint.com/">go to the group</a></p>
|
||||
|
||||
<p>Blessings</p>
|
||||
<p>Emmanuel International Ministries</p>
|
||||
`;
|
||||
sendEmail(ownerEmail, subject, html)
|
||||
}
|
||||
|
||||
const Notifications = {
|
||||
sendEmail,
|
||||
async yourBookmarkedPostGotAComment(post, postProfile, senderProfile, message) {
|
||||
@@ -204,7 +219,14 @@ const Notifications = {
|
||||
DB.addNotification(toProfileId, notifBody, post._id);
|
||||
return youGotANewPostTemplate(profile, user.username, senderProfile, message);
|
||||
},
|
||||
youHaveAnInvitation
|
||||
youHaveAnInvitation,
|
||||
async yourGroupHasARequest(requesterProfileId, groupId){
|
||||
const DB = await DBGetter.getDB;
|
||||
const requesterProfile = await DB.getProfileCache(requesterProfileId);
|
||||
const groupProfile = await DB.getProfileCache(groupId);
|
||||
const user = await DB.getUserById(groupProfile.userid);
|
||||
yourGroupHasARequestTemplate(groupProfile, user.username, requesterProfile)
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Notifications
|
||||
@@ -89,6 +89,14 @@ DB.getDB.then((DB)=>{
|
||||
});
|
||||
});
|
||||
|
||||
router.get("/groups/following", async (req, res) => {
|
||||
let groups = await DB.getFollowingGroups();
|
||||
return res.json({
|
||||
status: "ok",
|
||||
groups
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/groups", async (req, res) => {
|
||||
let profile = {
|
||||
userid: getUserId(req),
|
||||
@@ -124,6 +132,26 @@ DB.getDB.then((DB)=>{
|
||||
const profileAcepted = DB.ObjectID(req.body.profileid);
|
||||
DB.acceptGroupJoinReq(profileAcepted, groupidBody || groupid);
|
||||
//Add Notification to accepted user
|
||||
//Notifications.yourGroupHasARequest(profileAcepted, groupidBody || groupid)
|
||||
return res.json({
|
||||
status: "ok"
|
||||
});
|
||||
});
|
||||
|
||||
router.post("/groups/reject", async (req, res) => {
|
||||
//This function should be called to accept the join request
|
||||
//of an user that attempt to join a private group.
|
||||
const groupid = getProfileId(req); //It needs to have this profile context
|
||||
const groupidBody = req.body.groupid ? DB.ObjectID(req.body.groupid) : undefined;
|
||||
if(groupidBody && groupid != groupidBody && !DB.isOwnerOfGroup(groupid, groupidBody)){
|
||||
return res.json({
|
||||
status: "Only group owner can reject new subscribers"
|
||||
});
|
||||
}
|
||||
const profileAcepted = DB.ObjectID(req.body.profileid);
|
||||
DB.rejectGroupJoinReq(profileAcepted, groupidBody || groupid);
|
||||
//Add Notification to rejected user
|
||||
//Notifications.yourGroupHasARequest(profileAcepted, groupidBody || groupid)
|
||||
return res.json({
|
||||
status: "ok"
|
||||
});
|
||||
@@ -154,6 +182,7 @@ DB.getDB.then((DB)=>{
|
||||
const isPrivate = await DB.isGroupPrivate(groupid);
|
||||
DB.subscribeToGroup(profileid, groupid, isPrivate);
|
||||
//Add notification to group owner
|
||||
if(isPrivate) Notifications.yourGroupHasARequest(profileid, groupid)
|
||||
return res.json({
|
||||
status: "ok"
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user