From 80279346f346dea3a1490804c80f151b2b478967 Mon Sep 17 00:00:00 2001 From: Alexey Zinkevych Date: Sun, 31 Mar 2019 15:50:40 +0300 Subject: [PATCH] Transactional mail: code review fixes --- client/src/account/API.js | 1 + locales/en-US/common.json | 3 ++- locales/es-ES/common.json | 3 ++- server/lib/template-sender.js | 10 ++++++---- server/routes/api.js | 4 +++- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/client/src/account/API.js b/client/src/account/API.js index b57c04d4..56af2106 100644 --- a/client/src/account/API.js +++ b/client/src/account/API.js @@ -387,6 +387,7 @@ export default class API extends Component {

diff --git a/locales/en-US/common.json b/locales/en-US/common.json index a5a10b28..20d5b6d9 100644 --- a/locales/en-US/common.json +++ b/locales/en-US/common.json @@ -967,5 +967,6 @@ "thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character", "templateVariables": "Map of template variables to replace", "sendTransactionalEmail": "Send transactional email", - "sendSingleEmailByTemplateId": "Send single template by :templateId" + "sendSingleEmailByTemplateId": "Send single template by :templateId", + "sendConfigurationId": "ID of configuration used to create mailer instance" } \ No newline at end of file diff --git a/locales/es-ES/common.json b/locales/es-ES/common.json index 4a83ea90..247b23b5 100644 --- a/locales/es-ES/common.json +++ b/locales/es-ES/common.json @@ -967,6 +967,7 @@ "thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character", "templateVariables": "Map of template variables to replace", "sendTransactionalEmail": "Send transactional email", - "sendSingleEmailByTemplateId": "Send single template by :templateId" + "sendSingleEmailByTemplateId": "Send single template by :templateId", + "sendConfigurationId": "ID of configuration used to create mailer instance" } \ No newline at end of file diff --git a/server/lib/template-sender.js b/server/lib/template-sender.js index 40ccd0b8..5ea4db67 100644 --- a/server/lib/template-sender.js +++ b/server/lib/template-sender.js @@ -1,6 +1,5 @@ 'use strict'; -const contextHelpers = require('./context-helpers'); const mailers = require('./mailers'); const templates = require('../models/templates'); @@ -18,9 +17,9 @@ class TemplateSender { this._validateMailOptions(options); const [mailer, template] = await Promise.all([ - mailers.getOrCreateMailer(), + mailers.getOrCreateMailer(options.sendConfigurationId), templates.getById( - contextHelpers.getAdminContext(), + options.context, this.templateId, false ) @@ -43,8 +42,11 @@ class TemplateSender { } _validateMailOptions(options) { - let { email, locale } = options; + let { context, email, locale } = options; + if (!context) { + throw new Error('Missing context'); + } if (!email || email.length === 0) { throw new Error('Missing email'); } diff --git a/server/routes/api.js b/server/routes/api.js index 9fcc2863..60fa8a62 100644 --- a/server/routes/api.js +++ b/server/routes/api.js @@ -302,9 +302,11 @@ router.postAsync('/templates/:templateId/send', async (req, res) => { templateId: req.params.templateId }); const info = await templateSender.send({ + context: req.context, email: input.EMAIL, - subject: input.SUBJECT, locale: req.locale, + sendConfigurationId: input.SEND_CONFIGURATION_ID, + subject: input.SUBJECT, variables: input.VARIABLES }); res.status(200).json({ data: info });