* feat: add needed columns for throttling notifs * feat: update model * feat: deliver only one notif in a 12 hour window * fix: address review comments * prevent retry if notification update fails * fix type compatibility instead of circumventing it * add index for emailedAt * fix: add metadata attr to EmailProps * chore: decouple metadata from EmailProps * chore: add test * chore: revert sending metadata in props
22 lines
580 B
TypeScript
22 lines
580 B
TypeScript
import emails from "@server/emails/templates";
|
|
import BaseTask from "./BaseTask";
|
|
|
|
type Props = {
|
|
templateName: string;
|
|
props: Record<string, any>;
|
|
};
|
|
|
|
export default class EmailTask extends BaseTask<Props> {
|
|
public async perform({ templateName, props, ...metadata }: 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, metadata);
|
|
return email.send();
|
|
}
|
|
}
|