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>
|
</p>
|
||||||
<ul>
|
<ul>
|
||||||
<li><strong>EMAIL</strong> – {t('emailAddress')} (<em>{t('required')}</em>)</li>
|
<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>SUBJECT</strong> – {t('subject')}</li>
|
||||||
<li><strong>VARIABLES</strong> – {t('templateVariables')}: <em>{"{"} FOO: bar {"}"}</em></li>
|
<li><strong>VARIABLES</strong> – {t('templateVariables')}: <em>{"{"} FOO: bar {"}"}</em></li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -967,5 +967,6 @@
|
||||||
"thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character",
|
"thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character",
|
||||||
"templateVariables": "Map of template variables to replace",
|
"templateVariables": "Map of template variables to replace",
|
||||||
"sendTransactionalEmail": "Send transactional email",
|
"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",
|
"thePasswordMustContainAtLeastOneSpecial": "The password must contain at least one special character",
|
||||||
"templateVariables": "Map of template variables to replace",
|
"templateVariables": "Map of template variables to replace",
|
||||||
"sendTransactionalEmail": "Send transactional email",
|
"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';
|
'use strict';
|
||||||
|
|
||||||
const contextHelpers = require('./context-helpers');
|
|
||||||
const mailers = require('./mailers');
|
const mailers = require('./mailers');
|
||||||
const templates = require('../models/templates');
|
const templates = require('../models/templates');
|
||||||
|
|
||||||
|
@ -18,9 +17,9 @@ class TemplateSender {
|
||||||
this._validateMailOptions(options);
|
this._validateMailOptions(options);
|
||||||
|
|
||||||
const [mailer, template] = await Promise.all([
|
const [mailer, template] = await Promise.all([
|
||||||
mailers.getOrCreateMailer(),
|
mailers.getOrCreateMailer(options.sendConfigurationId),
|
||||||
templates.getById(
|
templates.getById(
|
||||||
contextHelpers.getAdminContext(),
|
options.context,
|
||||||
this.templateId,
|
this.templateId,
|
||||||
false
|
false
|
||||||
)
|
)
|
||||||
|
@ -43,8 +42,11 @@ class TemplateSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
_validateMailOptions(options) {
|
_validateMailOptions(options) {
|
||||||
let { email, locale } = options;
|
let { context, email, locale } = options;
|
||||||
|
|
||||||
|
if (!context) {
|
||||||
|
throw new Error('Missing context');
|
||||||
|
}
|
||||||
if (!email || email.length === 0) {
|
if (!email || email.length === 0) {
|
||||||
throw new Error('Missing email');
|
throw new Error('Missing email');
|
||||||
}
|
}
|
||||||
|
|
|
@ -302,9 +302,11 @@ router.postAsync('/templates/:templateId/send', async (req, res) => {
|
||||||
templateId: req.params.templateId
|
templateId: req.params.templateId
|
||||||
});
|
});
|
||||||
const info = await templateSender.send({
|
const info = await templateSender.send({
|
||||||
|
context: req.context,
|
||||||
email: input.EMAIL,
|
email: input.EMAIL,
|
||||||
subject: input.SUBJECT,
|
|
||||||
locale: req.locale,
|
locale: req.locale,
|
||||||
|
sendConfigurationId: input.SEND_CONFIGURATION_ID,
|
||||||
|
subject: input.SUBJECT,
|
||||||
variables: input.VARIABLES
|
variables: input.VARIABLES
|
||||||
});
|
});
|
||||||
res.status(200).json({ data: info });
|
res.status(200).json({ data: info });
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue