salix/print/methods/email.js

25 lines
620 B
JavaScript
Raw Normal View History

const Email = require('../core/email');
module.exports = app => {
2019-11-19 09:32:09 +00:00
app.get(`/api/email/:name`, async(req, res, next) => {
try {
2020-05-20 14:23:53 +00:00
const reportName = req.params.name;
const email = new Email(reportName, req.args);
2019-11-19 09:32:09 +00:00
2020-05-20 14:23:53 +00:00
if (req.args.isPreview === 'true') {
const rendered = await email.render();
res.send(rendered);
2019-11-19 09:32:09 +00:00
} else {
await email.send();
2019-11-19 09:32:09 +00:00
res.status(200).json({
message: 'Sent'
});
}
} catch (e) {
next(e);
}
});
};