Skip to content

Commit

Permalink
Merge pull request #170 from GTBitsOfGood/nathan/159-hours-email
Browse files Browse the repository at this point in the history
Add hours reminder email for training hours threshold
  • Loading branch information
SamratSahoo authored Nov 13, 2024
2 parents d3f53ea + 1bd3043 commit 667d544
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 2 deletions.
70 changes: 70 additions & 0 deletions backend/server/utils/emails/hours-notification/html.pug
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")
36 changes: 34 additions & 2 deletions backend/src/pages/api/user/training.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions backend/src/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,13 +186,15 @@ export enum EmailSubject {
PASSWORD_RESET = "Reset Your Password for Healing4Heroes",
ACCOUNT_CREATED = "Account Created on Healing4Heroes",
SHOT_REMINDER = "Rabies Shot Reminder for Your Service Animal",
HOURS_NOTIFICATION = "Training Hours Notification for Your Service Animal",
}

export enum EmailTemplate {
EMAIL_VERIFICATION = "verify",
PASSWORD_RESET = "reset",
ACCOUNT_CREATED = "create",
SHOT_REMINDER = "shot-reminder",
HOURS_NOTIFICATION = "hours-notification",
}

/* User Retrieval */
Expand Down

0 comments on commit 667d544

Please sign in to comment.