Notification when accepted on private groups

This commit is contained in:
aeroreyna
2022-03-27 12:02:00 -07:00
parent f7f4592b36
commit 137d91bcc3
2 changed files with 25 additions and 3 deletions

View File

@@ -230,6 +230,21 @@ const yourGroupHasARequestTemplate = (groupProfile, ownerEmail, senderProfile) =
sendEmail(ownerEmail, subject, html) sendEmail(ownerEmail, subject, html)
} }
const yourGroupRequestAcceptedTemplate = (groupProfile, acceptedEmail, acceptedProfile) => {
let subject = "Welcome to the " + groupProfile.profile.firstName + " " + groupProfile.profile.lastName + " group";
let html = `
<p>Hello ${acceptedProfile.profile.firstName} ${acceptedProfile.profile.lastName},</p>
<p>Your request to the group ${groupProfile.profile.firstName + groupProfile.profile.lastName} has been accepted.</p>
<p>You can now <a href="https://social.emmint.com/feed/${groupProfile._id}">go to the group</a></p>
<p>Blessings</p>
<p>Emmanuel International Ministries</p>
`;
sendEmail(acceptedEmail, subject, html)
}
const convertLinks = (input) => { const convertLinks = (input) => {
let text = input; let text = input;
@@ -372,6 +387,13 @@ const Notifications = {
const groupProfile = await DB.getProfileCache(groupId); const groupProfile = await DB.getProfileCache(groupId);
const user = await DB.getUserById(groupProfile.userid); const user = await DB.getUserById(groupProfile.userid);
yourGroupHasARequestTemplate(groupProfile, user.username, requesterProfile) yourGroupHasARequestTemplate(groupProfile, user.username, requesterProfile)
},
async yourGroupRequestAccepted(requesterProfileId, groupId) {
const DB = await DBGetter.getDB;
const requesterProfile = await DB.getProfileCache(requesterProfileId);
const groupProfile = await DB.getProfileCache(groupId);
const user = await DB.getUserById(requesterProfile.userid);
yourGroupRequestAcceptedTemplate(groupProfile, user.username, requesterProfile)
} }
} }

View File

@@ -137,15 +137,15 @@ DB.getDB.then((DB)=>{
} }
const profileAcepted = DB.ObjectID(req.body.profileid); const profileAcepted = DB.ObjectID(req.body.profileid);
DB.acceptGroupJoinReq(profileAcepted, groupidBody || groupid); DB.acceptGroupJoinReq(profileAcepted, groupidBody || groupid);
//Add Notification to accepted user //Send Notification to accepted user
//Notifications.yourGroupHasARequest(profileAcepted, groupidBody || groupid) Notifications.yourGroupRequestAccepted(profileAcepted, groupidBody || groupid)
return res.json({ return res.json({
status: "ok" status: "ok"
}); });
}); });
router.post("/groups/reject", async (req, res) => { router.post("/groups/reject", async (req, res) => {
//This function should be called to accept the join request //This function should be called to reject the join request
//of an user that attempt to join a private group. //of an user that attempt to join a private group.
const groupid = getProfileId(req); //It needs to have this profile context const groupid = getProfileId(req); //It needs to have this profile context
const groupidBody = req.body.groupid ? DB.ObjectID(req.body.groupid) : undefined; const groupidBody = req.body.groupid ? DB.ObjectID(req.body.groupid) : undefined;