Skip to content

Commit

Permalink
chapter 01: creating confirmationMailMailer using a factory function …
Browse files Browse the repository at this point in the history
…with too many responsibilities
  • Loading branch information
devcorpio committed Mar 30, 2019
1 parent 26fa2cc commit 395c7e0
Showing 1 changed file with 30 additions and 0 deletions.
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;

0 comments on commit 395c7e0

Please sign in to comment.