Skip to content

Commit 2320e1a

Browse files
authored
Merge pull request #181 from CodeForBaltimore/revjtanton/issue-132
Issue 180 Adding contact-direct check-in
2 parents 420c1c1 + 1ce9632 commit 2320e1a

22 files changed

+453
-240
lines changed

Bmore-Responsive.postman_collection.json

Lines changed: 151 additions & 64 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@ An API to drive disaster and emergency response systems.
66
<!-- TOC -->
77

88
- [Bmore Responsive](#bmore-responsive)
9-
- [Documentation](#documentation)
10-
- [API Spec](#api-spec)
11-
- [Database Documentation](#database-documentation)
12-
- [Infrastructure and Deployment](#infrastructure-and-deployment)
9+
- [Documentation](#documentation)
10+
- [API Spec](#api-spec)
11+
- [Database Documentation](#database-documentation)
12+
- [Infrastructure and Deployment](#infrastructure-and-deployment)
1313
- [Setup](#setup)
14-
- [Node and Express setup](#node-and-express-setup)
15-
- [Environment variables](#environment-variables)
16-
- [Example .env](#example-env)
17-
- [PostgreSQL](#postgresql)
18-
- [Sequelize](#sequelize)
19-
- [Docker](#docker)
20-
- [docker-compose](#docker-compose)
14+
- [Node and Express setup](#node-and-express-setup)
15+
- [Environment variables](#environment-variables)
16+
- [Example .env](#example-env)
17+
- [PostgreSQL](#postgresql)
18+
- [Sequelize](#sequelize)
19+
- [Docker](#docker)
20+
- [docker-compose](#docker-compose)
2121
- [Using this product](#using-this-product)
22-
- [Testing](#testing)
22+
- [Testing](#testing)
2323
- [Sources and Links](#sources-and-links)
24-
- [Contributors ✨](#contributors-)
24+
- [Contributors ✨](#contributors-)
2525

2626
<!-- /TOC -->
2727

@@ -86,6 +86,8 @@ The various variables are defined as follows:
8686
- `SMTP_PORT` = _optional_ port number for the SMTP server used to send notification emails
8787
- `SMTP_USER` = _optional_ username for the SMTP server used to send notification emails
8888
- `SMTP_PASSWORD` = _optional_ password for the SMTP server used to send notification emails
89+
- `URL` = _optional_ the URL for your front-end application
90+
- `TEST_EMAIL` = _optional_ the email you wish to send tests to
8991
- `BYPASS_LOGIN` = _optional_ Allows you to hit the endpoints locally without having to login. If you wish to bypass the login process during local dev, set this to `true`.
9092

9193
_We do not recommend using the default options for PostgreSQL. The above values are provided as examples. It is more secure to create your own credentials._
@@ -104,6 +106,8 @@ JWT_KEY=test123
104106
DATABASE_URL=postgres://postgres:postgres@localhost:5432/postgres
105107
DATABASE_SCHEMA=public
106108
BYPASS_LOGIN=true
109+
URL=http://localhost:8080
110+
107111
```
108112

109113
## PostgreSQL
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<h1>{{ emailTitle }}</h1>
2+
3+
<p>{{ emailContents }}</p>
4+
5+
<table width="100%" cellspacing="0" cellpadding="0">
6+
<tr>
7+
<td>
8+
<table cellspacing="0" cellpadding="0">
9+
<tr>
10+
<td style="border-radius: 2px;" bgcolor="#ED2939">
11+
<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;">
12+
Check In
13+
</a>
14+
</td>
15+
</tr>
16+
</table>
17+
</td>
18+
</tr>
19+
</table>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{{ emailTitle }}
2+
3+
{{ emailContents }}
4+
5+
{{ entityLink }}

mkdocs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
site_name: Project Template
2+
theme:
3+
name: readthedocs
4+
plugins:
5+
- swagger
6+
extra:
7+
swagger_url: 'https://raw.githubusercontent.com/CodeForBaltimore/Bmore-Responsive/master/swagger.json'

package-lock.json

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bmore-responsive",
3-
"version": "1.1.2",
3+
"version": "1.2.0",
44
"description": "An API-driven CRM (Civic Relationship Management) system.",
55
"main": "src/index.js",
66
"directories": {
@@ -40,6 +40,7 @@
4040
"casbin": "4.5.0",
4141
"casbin-sequelize-adapter": "2.1.0",
4242
"chai": "4.2.0",
43+
"complexity": "0.0.6",
4344
"cors": "2.8.5",
4445
"crypto": "1.0.1",
4546
"dotenv": "8.2.0",

publiccode.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ publiccodeYmlVersion: "0.2"
33
name: Bmore-Responsive
44
url: "https://github.com/CodeForBaltimore/Bmore-Responsive.git"
55
landingUrl: "https://github.com/CodeForBaltimore/Bmore-Responsive"
6-
softwareVersion: "1.1.2"
6+
softwareVersion: "1.2.0"
77
releaseDate: "2020-04-06"
88
platforms:
99
- web

src/email/index.js

Lines changed: 48 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,61 @@ const transporter = nodemailer.createTransport({
1919
* @param {string} text plain text of the email
2020
*/
2121
const sendMail = async (to, subject, html, text) => {
22-
let info = await transporter.sendMail({
23-
from: `"Healthcare Roll Call" <${process.env.SMTP_USER}>`, // sender address
24-
to, // list of receivers
25-
subject, // Subject line
26-
text, // plain text body
27-
html // html body
28-
});
29-
console.log("Email sent: %s", info.messageId);
22+
try {
23+
let info = await transporter.sendMail({
24+
from: `"Healthcare Roll Call" <${process.env.SMTP_USER}>`, // sender address
25+
to, // list of receivers
26+
subject, // Subject line
27+
text, // plain text body
28+
html // html body
29+
});
30+
console.log("Email sent: %s", info.messageId);
31+
} catch (e) {
32+
console.error(e);
33+
}
3034
};
3135

3236
/**
3337
* Send a forgot password email.
3438
* @param {string} userEmail email address of the user we're sending to
3539
* @param {string} resetPasswordToken temporary token for the reset password link
40+
*
41+
* @returns {Boolean}
3642
*/
3743
const sendForgotPassword = async (userEmail, resetPasswordToken) => {
38-
const emailResetLink = `https://healthcarerollcall.org/reset/${resetPasswordToken}`;
39-
await sendMail(
40-
userEmail,
41-
"Password Reset - Healthcare Roll Call",
42-
nunjucks.render("forgot_password_html.njk", { emailResetLink }),
43-
nunjucks.render("forgot_password_text.njk", { emailResetLink })
44-
);
45-
return true;
44+
try {
45+
const emailResetLink = `https://healthcarerollcall.org/reset/${resetPasswordToken}`;
46+
await sendMail(
47+
userEmail,
48+
"Password Reset - Healthcare Roll Call",
49+
nunjucks.render("forgot_password_html.njk", { emailResetLink }),
50+
nunjucks.render("forgot_password_text.njk", { emailResetLink })
51+
);
52+
return true;
53+
} catch (e) {
54+
console.error(e);
55+
return false;
56+
}
4657
};
4758

48-
export default { sendForgotPassword };
59+
const sendContactCheckInEmail = async (info) => {
60+
try {
61+
if (process.env.NODE_ENV === 'production' || process.env.TEST_EMAIL !== undefined && process.env.TEST_EMAIL === info.email) {
62+
const entityLink = `${process.env.URL}/checkin/${info.entityId}?token=${info.token}`;
63+
const emailTitle = `${info.entityName} Check In`;
64+
const emailContents = `Hello ${info.name}! It is time to update the status of ${info.entityName}. Please click the link below to check in.`
65+
await sendMail(
66+
info.email,
67+
emailTitle,
68+
nunjucks.render("contact_check_in_html.njk", { emailTitle, emailContents, entityLink }),
69+
nunjucks.render("contact_check_in_text.njk", { emailTitle, emailContents, entityLink })
70+
);
71+
console.log(info.email)
72+
return true;
73+
}
74+
} catch (e) {
75+
console.error(e);
76+
}
77+
}
78+
79+
export default { sendForgotPassword, sendContactCheckInEmail };

src/models/entity-contact.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ const entityContact = (sequelize, DataTypes) => {
4848
}
4949
}
5050

51+
EntityContact.findByEntityId = async (entityId) => {
52+
const entries = await EntityContact.findAll({
53+
where: {entityId}
54+
});
55+
56+
return entries;
57+
}
58+
5159
return EntityContact;
5260
};
5361

0 commit comments

Comments
 (0)