Skip to content

Commit

Permalink
#340 Send Email to invitees when an Event is updated (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
JacquelineTuyisenge authored Oct 7, 2024
1 parent 96e1ef6 commit 2fd15ac
Show file tree
Hide file tree
Showing 5 changed files with 524 additions and 317 deletions.
187 changes: 119 additions & 68 deletions src/helpers/sendEventEmails.ts
Original file line number Diff line number Diff line change
@@ -1,77 +1,128 @@
import jwt from "jsonwebtoken"
import { sendEmail } from "../utils/sendEmail"
import { eventCancellationTemplate, eventInvitationTemplate, invitationCancellationTemplate } from "../utils/templates/eventInvitationTemplates";
import jwt from 'jsonwebtoken'
import { sendEmail } from '../utils/sendEmail'
import {
eventCancellationTemplate,
eventUpdateTemplate,
eventInvitationTemplate,
invitationCancellationTemplate,
} from '../utils/templates/eventInvitationTemplates'

export async function sendEventInvitations(
email: string,
eventId: string,
eventTitle: string,
hostName: string,
eventStart: string,
eventEnd: string,
eventTimeToStart: string,
eventTimeToEnd: string,
){
try{
const secret = process.env.SECRET!
const acceptedEventToken = jwt.sign({
email,
eventId,
response: "accepted",
},secret)
const declinedEventToken = jwt.sign({
email,
eventId,
response: "declined",
},secret)
const content: string = eventInvitationTemplate(eventTitle,hostName,eventStart,eventEnd,eventTimeToStart,eventTimeToEnd, acceptedEventToken, declinedEventToken)
await sendEmail(
email,
'Event Invitation',
content,
null,
process.env.ADMIN_EMAIL,
process.env.ADMIN_PASS,
)
}catch(err){
return err
}
email: string,
eventId: string,
eventTitle: string,
hostName: string,
eventStart: string,
eventEnd: string,
eventTimeToStart: string,
eventTimeToEnd: string
) {
try {
const secret = process.env.SECRET!
const acceptedEventToken = jwt.sign(
{
email,
eventId,
response: 'accepted',
},
secret
)
const declinedEventToken = jwt.sign(
{
email,
eventId,
response: 'declined',
},
secret
)
const content: string = eventInvitationTemplate(
eventTitle,
hostName,
eventStart,
eventEnd,
eventTimeToStart,
eventTimeToEnd,
acceptedEventToken,
declinedEventToken
)
await sendEmail(
email,
'Event Invitation',
content,
null,
process.env.ADMIN_EMAIL,
process.env.ADMIN_PASS
)
} catch (err) {
return err
}
}

export async function sendEventUpdates(
email: string,
eventTitle: string,
hostName: string,
eventStart: string,
eventEnd: string,
eventTimeToStart: string,
eventTimeToEnd: string
) {
try {
const content: string = eventUpdateTemplate(
eventTitle,
hostName,
eventStart,
eventEnd,
eventTimeToStart,
eventTimeToEnd
)
await sendEmail(
email,
'Event Updated',
content,
null,
process.env.ADMIN_EMAIL,
process.env.ADMIN_PASS
)
} catch (err) {
return err
}
}

export async function sendEventCancellations(
email: string,
eventTitle: string,
){
try{
const content: string = eventCancellationTemplate(eventTitle)
await sendEmail(
email,
'Event Cancelled',
content,
null,
process.env.ADMIN_EMAIL,
process.env.ADMIN_PASS,
)
}catch(err){
return err
}
email: string,
eventTitle: string
) {
try {
const content: string = eventCancellationTemplate(eventTitle)
await sendEmail(
email,
'Event Cancelled',
content,
null,
process.env.ADMIN_EMAIL,
process.env.ADMIN_PASS
)
} catch (err) {
return err
}
}

export async function sendInvitationCancellations(
email: string,
eventTitle: string,
){
try{
const content: string = invitationCancellationTemplate(eventTitle)
await sendEmail(
email,
'Invitation Cancelled',
content,
null,
process.env.ADMIN_EMAIL,
process.env.ADMIN_PASS,
)
}catch(err){
return err
}
email: string,
eventTitle: string
) {
try {
const content: string = invitationCancellationTemplate(eventTitle)
await sendEmail(
email,
'Invitation Cancelled',
content,
null,
process.env.ADMIN_EMAIL,
process.env.ADMIN_PASS
)
} catch (err) {
return err
}
}
Loading

0 comments on commit 2fd15ac

Please sign in to comment.