diff --git a/notifications.js b/notifications.js index 1b433e1..bc29a74 100644 --- a/notifications.js +++ b/notifications.js @@ -230,6 +230,21 @@ const yourGroupHasARequestTemplate = (groupProfile, ownerEmail, senderProfile) = sendEmail(ownerEmail, subject, html) } +const yourGroupRequestAcceptedTemplate = (groupProfile, acceptedEmail, acceptedProfile) => { + let subject = "Welcome to the " + groupProfile.profile.firstName + " " + groupProfile.profile.lastName + " group"; + let html = ` +
Hello ${acceptedProfile.profile.firstName} ${acceptedProfile.profile.lastName},
+ +Your request to the group ${groupProfile.profile.firstName + groupProfile.profile.lastName} has been accepted.
+ +You can now go to the group
+ +Blessings
+Emmanuel International Ministries
+`; + sendEmail(acceptedEmail, subject, html) +} + const convertLinks = (input) => { let text = input; @@ -372,6 +387,13 @@ const Notifications = { const groupProfile = await DB.getProfileCache(groupId); const user = await DB.getUserById(groupProfile.userid); 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) } } diff --git a/routes/profile.js b/routes/profile.js index 9d5e486..322abbd 100644 --- a/routes/profile.js +++ b/routes/profile.js @@ -137,15 +137,15 @@ 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) + //Send Notification to accepted user + Notifications.yourGroupRequestAccepted(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 + //This function should be called to reject 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;