Skip to content

Commit

Permalink
update the email template and add pug for templating (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
choden-dev authored Jul 26, 2024
1 parent 4d2a901 commit bd3bf70
Show file tree
Hide file tree
Showing 5 changed files with 311 additions and 11 deletions.
2 changes: 2 additions & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"firebase-admin": "^12.0.0",
"helmet": "^7.1.0",
"nodemailer": "^6.9.14",
"pug": "^3.0.3",
"stripe": "^14.22.0",
"supertest": "^6.3.4",
"swagger-jsdoc": "^6.2.8",
Expand All @@ -24,6 +25,7 @@
"@types/helmet": "^4.0.0",
"@types/node": "^20.11.22",
"@types/nodemailer": "^6",
"@types/pug": "^2.0.10",
"@types/supertest": "^6.0.2",
"@types/swagger-jsdoc": "^6.0.4",
"@types/swagger-ui-express": "^4.1.6",
Expand Down
21 changes: 17 additions & 4 deletions server/src/business-layer/services/MailService.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import * as NodeMailer from "nodemailer"
import path from "path"
import { compileFile } from "pug"

const TEMPLATE_BASE_PATH = path.join(__dirname, "..", "templates")

const transporter = NodeMailer.createTransport({
service: "Gmail",
Expand All @@ -16,20 +20,29 @@ export default class MailService {
* Sends an email to the user confirming their booking was made and specifying the dates
*
* @param recipientEmail the email for which the confirmation should be sent
* @param recipientName the **full** name of the intended recipient
* @param startDateString the pre-formatted date **string** of the *first* **night** in the user's booking
* @param endDateString the pre-formatted date **string** of the *last* **night** in the user's booking
*/
public async sendBookingConfirmationEmail(
recipientEmail: string,
recipientName: string,
startDateString: string,
endDateString: string
) {
const compiledFunction = compileFile(
`${TEMPLATE_BASE_PATH}/BookingConfirmation.pug`
)

const info = await transporter.sendMail({
from: '"UASC Bookings"',
to: recipientEmail,
subject: `Your booking from ${startDateString} to ${endDateString}`,
html: `<p>
Your booking from <strong>${startDateString}</strong> to <strong>${endDateString}</strong> has been confirmed.
Please email <a href="mailto:[email protected]">[email protected]</a> for any queries
</p>`
html: compiledFunction({
name: recipientName,
startDate: startDateString,
endDate: endDateString
})
})

console.log("Booking confirmation email sent: %s", info.messageId)
Expand Down
4 changes: 4 additions & 0 deletions server/src/business-layer/services/StripeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,9 +431,13 @@ export default class StripeService {
const [userAuthData] = await new AuthService().bulkRetrieveUsersByUids([
{ uid }
])
const { first_name, last_name } = await new UserDataService().getUserData(
uid
)

await new MailService().sendBookingConfirmationEmail(
userAuthData.email,
`${first_name} ${last_name}`,
session.metadata[START_DATE],
session.metadata[END_DATE]
)
Expand Down
30 changes: 30 additions & 0 deletions server/src/business-layer/templates/BookingConfirmation.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
p Kia ora #{name}

p UASC is stoked to confirm your booking for an unforgettable stay at your lodge between the nights of:

p <strong>#{startDate} to #{endDate}</strong>

p Here's some info for both new and old members:

p <strong>Getting to our lodge</strong> - Our lodge is nestled on the whakapapa side of Ruapehu, it is a 4 hour drive from Auckland. The drive up Bruce road to the lodge can be snow joke, please drive to the conditions and check Bruce roads status on the whakapapa website before departing.

p <strong>Parking</strong> - Parking is available on the same road as the lodge. Parking can be hard to find from mid morning to afternoon. You can repark closer to the lodge later in the evening.

p <strong>Getting into our lodge</strong> - The door code is <strong>1627Y</strong> then turn the handle anticlockwise.

p <strong>The Lodge</strong> - If this is your first time, welcome to your new home. The bottom floor houses the kitchen, lounge, conversation pit, drying and tuning room. Upstairs you’ll find two bunk rooms and bathrooms, feel free to find a spare bunk and set yourself up. Our lodge custodian, Issac, will be on hand to look after the lodge and answer any questions you might have.

p <strong>Food</strong> - Dinner is provided

p <strong>Expectations</strong> - To keep our lodge in top shape, we ask all guests to pitch in with chores. When you see Issac, be proactive and ask what needs doing. Please make sure to leave the lodge as clean (or cleaner!) than you found it.

p By staying at our lodge you are agreeing to our policy and behavior rules, which you can find in detail on our website.

p If at any point during your stay you feel unsafe, uncomfortable or want to report something please use our form below which is monitored by our wellbeing officer.
<a href="https://forms.gle/UTBB4TsMCTgyaatYA">https://forms.gle/UTBB4TsMCTgyaatYA</a>

p Cheers,
p Dominic Chanwai
p University of Auckland Snowsports Club
p Instagram: uasc_nz | Email: <a href="mailto:[email protected]">[email protected]</a> | Website: <a href="https://uasc.co.nz">uasc.co.nz</a>

Loading

0 comments on commit bd3bf70

Please sign in to comment.