25 lines
620 B
JavaScript
25 lines
620 B
JavaScript
const Email = require('../core/email');
|
|
|
|
module.exports = app => {
|
|
app.get(`/api/email/:name`, async(req, res, next) => {
|
|
try {
|
|
const reportName = req.params.name;
|
|
const email = new Email(reportName, req.args);
|
|
|
|
if (req.args.isPreview === 'true') {
|
|
const rendered = await email.render();
|
|
|
|
res.send(rendered);
|
|
} else {
|
|
await email.send();
|
|
|
|
res.status(200).json({
|
|
message: 'Sent'
|
|
});
|
|
}
|
|
} catch (e) {
|
|
next(e);
|
|
}
|
|
});
|
|
};
|