swaf/src/mail/MailController.ts

17 lines
624 B
TypeScript
Raw Normal View History

2020-06-03 14:14:42 +02:00
import {Request, Response} from "express";
import Controller from "../Controller";
import Mail from "./Mail";
import NunjucksComponent from "../components/NunjucksComponent";
2020-06-03 14:14:42 +02:00
export default class MailController extends Controller {
public routes(): void {
2020-07-15 11:42:49 +02:00
this.get("/mail/:template", this.getMail, 'mail');
2020-06-03 14:14:42 +02:00
}
protected async getMail(request: Request, response: Response): Promise<void> {
2020-06-03 14:14:42 +02:00
const template = request.params['template'];
response.send(Mail.parse(this.getApp().as(NunjucksComponent).getEnvironment(),
`mails/${template}.mjml.njk`, request.query, false));
2020-06-03 14:14:42 +02:00
}
}