Merge remote-tracking branch 'origin/development' into development

This commit is contained in:
Tomas Bures 2019-04-03 12:14:09 +02:00
commit ec0f288d81
9 changed files with 171 additions and 6 deletions

View file

@ -16,6 +16,7 @@ const contextHelpers = require('../lib/context-helpers');
const shares = require('../models/shares');
const slugify = require('slugify');
const passport = require('../lib/passport');
const TemplateSender = require('../lib/template-sender');
const campaigns = require('../models/campaigns');
class APIError extends Error {
@ -285,5 +286,34 @@ router.getAsync('/rss/fetch/:campaignCid', passport.loggedIn, async (req, res) =
return res.json();
});
router.postAsync('/templates/:templateId/send', async (req, res) => {
const input = {};
Object.keys(req.body).forEach(key => {
input[
(key || '')
.toString()
.trim()
.toUpperCase()
] = req.body[key] || '';
});
try {
const templateSender = new TemplateSender({
context: req.context,
locale: req.locale,
templateId: req.params.templateId
});
const info = await templateSender.send({
data: input.DATA,
email: input.EMAIL,
sendConfigurationId: input.SEND_CONFIGURATION_ID,
subject: input.SUBJECT,
variables: input.VARIABLES
});
res.status(200).json({ data: info });
} catch (e) {
throw new APIError(e.message, 400);
}
});
module.exports = router;