-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chapter 01: creating confirmationMailMailer using a factory function …
…with too many responsibilities
- Loading branch information
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
chapter-01-the-single-responsibility-principle/ConfirmationMailMailer.js
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,30 @@ | ||
function confirmationMailMailer(templating, translator, mailer) { | ||
function sendTo(user) { | ||
const message = createMessageFor(user); | ||
|
||
sendMessage(message); | ||
} | ||
|
||
function createMessageFor(user) { | ||
const subject = translator.translate('Confirm your mail address'); | ||
|
||
const body = templating.render('confirmationMail.html.tpl', { | ||
confirmationCode: user.getConfirmationCode(), | ||
}); | ||
|
||
const message = new Message(subject, body); | ||
message.setTo(user.getEmailAddress()); | ||
|
||
return message; | ||
} | ||
|
||
function sendMessage(message) { | ||
mailer.send(message); | ||
} | ||
|
||
return { | ||
sendTo, | ||
}; | ||
} | ||
|
||
module.exports = confirmationMailMailer; |