This repository has been archived by the owner on Oct 9, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API support for sending minor information email
- Loading branch information
1 parent
7cf4ed4
commit f844395
Showing
3 changed files
with
106 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -169,6 +169,71 @@ routes.get('/sendInfoEmail1', apiKeyValidator, eventDeadlineValidator, (request, | |
}); | ||
}); | ||
|
||
/** | ||
* This is used to send the infoEmailMinors email to all registrants that: | ||
* | ||
* - Are under 18 | ||
* - Have not received this email before | ||
* - Have confirmed their attendance for the event | ||
* | ||
* It is intended to be called manually, or from the dashboard if that | ||
* functionality gets implemented. | ||
* | ||
* usage: /sendInfoEmailMinors?key=<apikeyhere> | ||
* | ||
*/ | ||
routes.get('/sendInfoEmailMinors', apiKeyValidator, eventDeadlineValidator, (request, response) => { | ||
Registrant.find({attendanceConfirmed: "YES", receivedMinorInfoEmail: false}, (err, registrants) => { | ||
if (err) { | ||
console.error(err); | ||
return response.status(400).send('Sorry, something went wrong'); | ||
} | ||
|
||
// We'll do a little preprocessing here to filter out the non-minor registrants | ||
let eighteenYearsUnix = 567993600; | ||
registrants = registrants.filter(registrant => { | ||
let dob = Date.parse(registrant.dob) / 1000; | ||
let now = Date.now() / 1000; | ||
return now - dob < eighteenYearsUnix; | ||
}); | ||
|
||
for (registrant of registrants) { | ||
Registrant.update({email: registrant.email}, {receivedMinorInfoEmail: true}, (err, numberAffected, rawResponse) => {}); | ||
} | ||
|
||
sendInfoEmailMinors(request, registrants); | ||
response.json({"affected users": registrants.length}); | ||
}); // Registrant.find | ||
}); | ||
|
||
/** | ||
* This is used to send the infoEmail3 email to all registrants that: | ||
* | ||
* - Have not received this email before | ||
* - Have confirmed their attendance for the event | ||
* | ||
* It is intended to be called manually, or from the dashboard if that | ||
* functionality gets implemented. | ||
* | ||
* usage: /infoEmail3?key=<apikeyhere> | ||
* | ||
*/ | ||
routes.get('/sendInfoEmail3', apiKeyValidator, eventDeadlineValidator, (request, response) => { | ||
Registrant.find({attendanceConfirmed: "YES", receivedInfoEmail3: false}, (err, registrants) => { | ||
if (err) { | ||
console.error(err); | ||
return response.status(400).send('Sorry, something went wrong'); | ||
} | ||
|
||
for (registrant of registrants) { | ||
Registrant.update({email: registrant.email}, {receivedInfoEmail3: true}, (err, numberAffected, rawResponse) => {}); | ||
} | ||
|
||
sendInfoEmail3(request, registrants); | ||
response.json({"affected users": registrants.length}); | ||
}); // Registrant.find | ||
}); | ||
|
||
/* | ||
*********************************************************** | ||
* Below are helper functions that some of the above | ||
|
@@ -233,6 +298,38 @@ async function sendInfoEmail1(request, registrants) { | |
} | ||
} | ||
|
||
async function sendInfoEmailMinors(request, registrants) { | ||
for (let registrant of registrants) { | ||
// Build user emailData | ||
let emailData = { | ||
subject: "Minors at RevolutionUC - Important Information for the Event", | ||
shortDescription: "Because you're under 18, there is some extra information you need to know to get ready.", | ||
firstName: registrant.firstName | ||
}; | ||
|
||
// One async task | ||
// 1. Send infoEmailMinors | ||
const html = await build('infoEmailMinors', emailData); | ||
await send(mailgunApiKey, mailgunDomain, 'RevolutionUC <[email protected]>', registrant.email, emailData.subject, html); | ||
} | ||
} | ||
|
||
async function sendInfoEmail3(request, registrants) { | ||
for (let registrant of registrants) { | ||
// Build user emailData | ||
let emailData = { | ||
subject: "Important Information for RevolutionUC!", | ||
shortDescription: "Here's some important information you need to know to get ready for this weekend!", | ||
firstName: registrant.firstName | ||
}; | ||
|
||
// One async task | ||
// 1. Send infoEmail3 | ||
const html = await build('infoEmail3', emailData); | ||
await send(mailgunApiKey, mailgunDomain, 'RevolutionUC <[email protected]>', registrant.email, emailData.subject, html); | ||
} | ||
} | ||
|
||
async function sendEmailVerification(request, registrants) { | ||
for (let registrant of registrants) { | ||
// Build user emailData | ||
|
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
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