-
Notifications
You must be signed in to change notification settings - Fork 21
Issue 180 Adding contact-direct check-in #181
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
ba3decd
05ae1b6
b1a4958
2f98df0
5a5ef25
fc17e5f
1ce9632
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <h1>{{ emailTitle }}</h1> | ||
|
|
||
| <p>{{ emailContents }}</p> | ||
|
|
||
| <table width="100%" cellspacing="0" cellpadding="0"> | ||
| <tr> | ||
| <td> | ||
| <table cellspacing="0" cellpadding="0"> | ||
| <tr> | ||
| <td style="border-radius: 2px;" bgcolor="#ED2939"> | ||
| <a href="{{ entityLink }}" target="_blank" style="padding: 8px 12px; border: 1px solid #ED2939;border-radius: 2px;font-family: Helvetica, Arial, sans-serif;font-size: 14px; color: #ffffff;text-decoration: none;font-weight:bold;display: inline-block;"> | ||
| Check In | ||
| </a> | ||
| </td> | ||
| </tr> | ||
| </table> | ||
| </td> | ||
| </tr> | ||
| </table> |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| {{ emailTitle }} | ||
|
|
||
| {{ emailContents }} | ||
|
|
||
| {{ entityLink }} |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| site_name: Project Template | ||
| theme: | ||
| name: readthedocs | ||
| plugins: | ||
| - swagger | ||
| extra: | ||
| swagger_url: 'https://raw.githubusercontent.com/CodeForBaltimore/Bmore-Responsive/master/swagger.json' |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| import { Router } from 'express'; | ||
| import validator from 'validator'; | ||
| import email from '../email'; | ||
| import utils from '../utils'; | ||
|
|
||
| const router = new Router(); | ||
|
|
@@ -92,6 +93,54 @@ router.post('/', async (req, res) => { | |
| return utils.response(res, code, message); | ||
| }); | ||
|
|
||
| // Sends emails to contacts based on body | ||
| router.post('/send', async (req, res) => { | ||
| let code; | ||
| let message; | ||
| const emails = []; | ||
|
|
||
| try { | ||
| /** @todo allow for passing entity and contact arrays */ | ||
| const { entityIds, contactIds, relationshipTitle } = req.body; | ||
|
|
||
| if (entityIds === undefined && contactIds === undefined) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is only running if
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's for future planning. Eventually, we're going to allow for passing an array of either or both types of ID's to only send emails to those associations. For now, though, that functionality isn't in there. |
||
| const whereClause = (relationshipTitle !== undefined) ? {where: {relationshipTitle}} : {}; | ||
| const associations = await req.context.models.EntityContact.findAll(whereClause); | ||
|
|
||
| for (const association of associations) { | ||
| const contact = await req.context.models.Contact.findById(association.contactId); | ||
|
|
||
| if (contact.email !== null) { | ||
| const entity = await req.context.models.Entity.findById(association.entityId); | ||
| // short-lived temporary token that only lasts one hour | ||
| const temporaryToken = await utils.getToken(contact.id, contact.email[0].address, 'contact'); | ||
|
|
||
| emails.push({ | ||
| email: contact.email[0].address, | ||
| name: contact.name, | ||
| entityName: entity.name, | ||
| entityId: association.entityId, | ||
| relationshipTitle: association.relationshipTitle, | ||
| token: temporaryToken | ||
| }); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| emails.forEach(async (e) => { | ||
| email.sendContactCheckInEmail(e); | ||
| }) | ||
|
|
||
| code = 200; | ||
| message = 'contacts emailed'; | ||
| } catch (e) { | ||
| console.error(e); | ||
| code = 500; | ||
| } | ||
|
|
||
| return utils.response(res, code, message); | ||
| }); | ||
|
|
||
| // Updates any contact. | ||
| router.put('/', async (req, res) => { | ||
| let code; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this automatically find it by pk?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not for some reason. Not sure what was off about that but it wasn't really worth debugging. When I used
findByPknothing came back.