salix/print/methods/email.js

34 lines
829 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);
await email.send();
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();
res.send(rendered);
} catch (e) {
next(e);
}
});
};