Files
outline/server/emails/index.ts
Tom Moor 15b1069bcc chore: Move to Typescript (#2783)
This PR moves the entire project to Typescript. Due to the ~1000 ignores this will lead to a messy codebase for a while, but the churn is worth it – all of those ignore comments are places that were never type-safe previously.

closes #1282
2021-11-29 06:40:55 -08:00

43 lines
1.2 KiB
TypeScript

import Koa from "koa";
import Router from "koa-router";
import { NotFoundError } from "../errors";
import { Mailer } from "../mailer";
const emailPreviews = new Koa();
const router = new Router();
router.get("/:type/:format", async (ctx) => {
let mailerOutput;
const mailer = new Mailer();
mailer.transporter = {
// @ts-expect-error ts-migrate(7006) FIXME: Parameter 'data' implicitly has an 'any' type.
sendMail: (data) => (mailerOutput = data),
};
switch (ctx.params.type) {
// case 'emailWithProperties':
// mailer.emailWithProperties('user@example.com', {...properties});
// break;
default:
if (Object.getOwnPropertyNames(mailer).includes(ctx.params.type)) {
mailer[ctx.params.type]("user@example.com");
} else {
throw NotFoundError("Email template could not be found");
}
}
if (!mailerOutput) return;
if (ctx.params.format === "text") {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'text' does not exist on type 'never'.
ctx.body = mailerOutput.text;
} else {
// @ts-expect-error ts-migrate(2339) FIXME: Property 'html' does not exist on type 'never'.
ctx.body = mailerOutput.html;
}
});
emailPreviews.use(router.routes());
export default emailPreviews;