-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from GTBitsOfGood/nathan/159-hours-email
Add hours reminder email for training hours threshold
- Loading branch information
Showing
3 changed files
with
106 additions
and
2 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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
doctype html | ||
html(lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml" xmlns:o="urn:schemas-microsoft-com:office:office") | ||
head | ||
meta(charset="UTF-8") | ||
meta(name="viewport" content="width=device-width, initial-scale=1") | ||
meta(name="x-apple-disable-message-reformatting") | ||
meta(http-equiv="X-UA-Compatible" content="IE=edge") | ||
meta(name="format-detection" content="telephone=no") | ||
title Copy of (2) New Message | ||
style. | ||
.rollover:hover .rollover-first { max-height:0px!important; display:none!important; } | ||
.rollover:hover .rollover-second { max-height:none!important; display:block!important; } | ||
.rollover span { font-size:0px; } | ||
u + .body img ~ div div { display:none; } | ||
#outlook a { padding:0; } | ||
span.MsoHyperlink, span.MsoHyperlinkFollowed { color:inherit; mso-style-priority:99; } | ||
a.es-button { mso-style-priority:100!important; text-decoration:none!important; } | ||
a[x-apple-data-detectors], #MessageViewBody a { color:inherit!important; text-decoration:none!important; font-size:inherit!important; font-family:inherit!important; font-weight:inherit!important; line-height:inherit!important; } | ||
.es-desk-hidden { display:none; float:left; overflow:hidden; width:0; max-height:0; line-height:0; mso-hide:all; } | ||
body(style="width:100%;height:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;padding:0;margin:0") | ||
.es-wrapper-color(style="background-color:#F6F6F6") | ||
table.es-wrapper(role="none" cellspacing="0" cellpadding="0" width="100%" style="border-collapse:collapse;width:100%;height:100%;background-repeat:repeat;background-position:center top;background-color:#F6F6F6") | ||
tr | ||
td(valign="top") | ||
table.es-header(role="none" cellspacing="0" cellpadding="0" align="center" style="width:100%;background-color:transparent") | ||
tr | ||
td(align="center") | ||
table.es-header-body(role="none" cellspacing="0" cellpadding="0" align="center" bgcolor="#ffffff" style="background-color:#FFFFFF;width:600px") | ||
tr | ||
td(align="left" style="padding:20px 150px") | ||
table.es-right(role="none" cellspacing="0" cellpadding="0" align="right" style="float:right") | ||
tr | ||
td(align="left" style="width:300px") | ||
table(role="presentation" width="100%" cellspacing="0" cellpadding="0") | ||
tr | ||
td(align="center" style="font-size:0") | ||
img.adapt-img(src="https://epiujlr.stripocdn.email/content/guids/CABINET_b671897a35158e25b88e73b31b95f12e48ace5edc8e5b734899d083c66476053/images/h4hlogo_zhD.png" alt="" width="150" height="161" style="display:block;border:0") | ||
|
||
table.es-content(role="none" cellspacing="0" cellpadding="0" align="center" style="width:100%") | ||
tr | ||
td(align="center") | ||
table.es-content-body(role="none" cellspacing="0" cellpadding="0" align="center" bgcolor="#ffffff" style="background-color:#FFFFFF;width:600px") | ||
tr | ||
td(align="left" style="padding:20px") | ||
table(role="none" width="100%" cellspacing="0" cellpadding="0") | ||
tr | ||
td(align="center" style="width:560px") | ||
table(role="presentation" width="100%" cellspacing="0" cellpadding="0") | ||
tr | ||
td(align="left") | ||
p Congratulations #{handlerName}! You and #{animalName} have trained for #{thresholdAchieved} hours! | ||
|
||
table.es-footer(role="none" cellspacing="0" cellpadding="0" align="center" style="width:100%;background-color:transparent") | ||
tr | ||
td(align="center") | ||
table.es-footer-body(role="none" cellspacing="0" cellpadding="0" align="center" bgcolor="#ffffff" style="background-color:#FFFFFF;width:600px") | ||
tr | ||
td(align="left" style="padding:20px") | ||
table.es-left(role="none" cellspacing="0" cellpadding="0" align="left" style="float:left") | ||
tr | ||
td(align="left" class="es-m-p20b" style="width:270px") | ||
table(role="none" width="100%" cellspacing="0" cellpadding="0") | ||
tr | ||
td(align="center" style="display:none") | ||
table.es-right(role="none" cellspacing="0" cellpadding="0" align="right" style="float:right") | ||
tr | ||
td(align="left" style="width:270px") | ||
table(role="none" width="100%" cellspacing="0" cellpadding="0") | ||
tr | ||
td(align="center" style="display:none") |
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 |
---|---|---|
|
@@ -5,8 +5,10 @@ import { | |
getTrainingLogs, | ||
} from "server/mongodb/actions/TrainingLog"; | ||
import APIWrapper from "server/utils/APIWrapper"; | ||
import { getUser } from "server/utils/Authentication"; | ||
import { BehaviorTypes, Role, User } from "src/utils/types"; | ||
import { getUser, sendEmail } from "server/utils/Authentication"; | ||
import { BehaviorTypes, Role, User, ServiceAnimal } from "src/utils/types"; | ||
import { findAnimalByUserId } from "server/mongodb/actions/Animal"; | ||
import { EmailSubject, EmailTemplate } from "src/utils/types"; | ||
|
||
export default APIWrapper({ | ||
POST: { | ||
|
@@ -43,6 +45,36 @@ export default APIWrapper({ | |
throw new Error("Failed to create training log"); | ||
} | ||
|
||
const handlerAnimal: ServiceAnimal | null = await findAnimalByUserId( | ||
handler._id | ||
); | ||
|
||
if ( | ||
handlerAnimal && | ||
((handlerAnimal.totalHours < 800 && | ||
handlerAnimal.totalHours + trainingHours >= 800) || | ||
(handlerAnimal.totalHours < 1600 && | ||
handlerAnimal.totalHours + trainingHours >= 1600) || | ||
(handlerAnimal.totalHours < 3200 && | ||
handlerAnimal.totalHours + trainingHours >= 3200)) | ||
) { | ||
await sendEmail( | ||
"[email protected]", | ||
EmailSubject.HOURS_NOTIFICATION, | ||
EmailTemplate.HOURS_NOTIFICATION, | ||
{ | ||
handlerName: handler.firstName + " " + handler.lastName, | ||
animalName: handlerAnimal.name, | ||
thresholdAchieved: | ||
handlerAnimal.totalHours < 800 | ||
? "800" | ||
: handlerAnimal.totalHours < 1600 | ||
? "1600" | ||
: "3200", | ||
} | ||
); | ||
} | ||
|
||
await updateCumulativeTrainingHours(trainingHours); | ||
|
||
return trainingLog; | ||
|
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