salix/print/methods/email.js

34 lines
829 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
2021-04-06 11:46:38 +00:00
await email.send();
2021-04-06 11:46:38 +00:00
res.status(200).json({
message: 'Sent'
});
} catch (e) {
next(e);
}
});
app.get(`/api/email/:name/preview`, async(req, res, next) => {
try {
const reportName = req.params.name;
const args = req.args;
args.isPreview = true;
const email = new Email(reportName, args);
const rendered = await email.render();
2021-04-06 11:46:38 +00:00
res.send(rendered);
2019-11-19 09:32:09 +00:00
} catch (e) {
next(e);
}
});
};