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
This commit is contained in:
42
server/emails/index.ts
Normal file
42
server/emails/index.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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;
|
||||
Reference in New Issue
Block a user