chore: Email + mailer refactor (#3342)

* Huge email refactor

* fix: One rename too many

* comments
This commit is contained in:
Tom Moor
2022-04-07 16:50:04 -07:00
committed by GitHub
parent 15375bf199
commit 5c24f9e1d5
39 changed files with 879 additions and 870 deletions

View File

@@ -1,15 +1,23 @@
import emails from "@server/emails/templates";
import { APM } from "@server/logging/tracing";
import mailer, { EmailSendOptions, EmailTypes } from "../../mailer";
import BaseTask from "./BaseTask";
type Props = {
type: EmailTypes;
options: EmailSendOptions;
templateName: string;
props: Record<string, any>;
};
@APM.trace()
export default class EmailTask extends BaseTask<Props> {
public async perform(props: Props) {
await mailer[props.type](props.options);
public async perform({ templateName, props }: Props) {
const EmailClass = emails[templateName];
if (!EmailClass) {
throw new Error(
`Email task "${templateName}" template does not exist. Check the file name matches the class name.`
);
}
const email = new EmailClass(props);
return email.send();
}
}