Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | 59x 59x 59x 59x 141x 141x 141x 141x 141x 1x 1x 1x 1x 1x 1x 1x 2x 2x 2x 1x 1x 1x 1x 59x | import { ADMIN } from '../../types/permissions';
import { TemplateFormat } from '../../services/email-service';
import { IUnleashConfig } from '../../types/option';
import { IUnleashServices } from '../../types/services';
import { Request, Response } from 'express';
const Controller = require('../controller');
export default class EmailController extends Controller {
constructor(
config: IUnleashConfig,
{ emailService }: Pick<IUnleashServices, 'emailService'>,
) {
super(config);
this.emailService = emailService;
this.logger = config.getLogger('routes/admin-api/email');
this.get('/preview/html/:template', this.getHtmlPreview, ADMIN);
this.get('/preview/text/:template', this.getTextPreview, ADMIN);
}
async getHtmlPreview(req: Request, res: Response): Promise<void> {
const { template } = req.params;
const ctx = req.query;
const data = await this.emailService.compileTemplate(
template,
TemplateFormat.HTML,
ctx,
);
res.setHeader('Content-Type', 'text/html');
res.status(200);
res.send(data);
res.end();
}
async getTextPreview(req: Request, res: Response): Promise<void> {
const { template } = req.params;
const ctx = req.query;
const data = await this.emailService.compileTemplate(
template,
TemplateFormat.PLAIN,
ctx,
);
res.setHeader('Content-Type', 'text/plain');
res.status(200);
res.send(data);
res.end();
}
}
module.exports = EmailController;
|