-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
96e1ef6
commit 2fd15ac
Showing
5 changed files
with
524 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} |
Oops, something went wrong.