Transactional mail: code review fixes
This commit is contained in:
parent
ed4a13fef7
commit
80279346f3
5 changed files with 14 additions and 7 deletions
|
@ -387,6 +387,7 @@ export default class API extends Component {
|
|||
</p>
|
||||
<ul>
|
||||
<li><strong>EMAIL</strong> – {t('emailAddress')} (<em>{t('required')}</em>)</li>
|
||||
<li><strong>SEND_CONFIGURATION_ID</strong> – {t('sendConfigurationId')}</li>
|
||||
<li><strong>SUBJECT</strong> – {t('subject')}</li>
|
||||
<li><strong>VARIABLES</strong> – {t('templateVariables')}: <em>{"{"} FOO: bar {"}"}</em></li>
|
||||
</ul>
|
||||
|
|
|
@ -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"
|
||||
}
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -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');
|
||||
}
|
||||
|
|
|
@ -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 });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue