Notifications refactor (#5151

* Ongoing

* refactor

* test

* Add cleanup task

* refactor
This commit is contained in:
Tom Moor
2023-04-08 09:22:49 -04:00
committed by GitHub
parent c97110e72b
commit 9c9ceef8ee
28 changed files with 1122 additions and 901 deletions

View File

@@ -0,0 +1,51 @@
import { NotificationEventType } from "@shared/types";
import CollectionCreatedEmail from "@server/emails/templates/CollectionCreatedEmail";
import CommentCreatedEmail from "@server/emails/templates/CommentCreatedEmail";
import CommentMentionedEmail from "@server/emails/templates/CommentMentionedEmail";
import DocumentMentionedEmail from "@server/emails/templates/DocumentMentionedEmail";
import DocumentPublishedOrUpdatedEmail from "@server/emails/templates/DocumentPublishedOrUpdatedEmail";
import { Notification } from "@server/models";
import { Event, NotificationEvent } from "@server/types";
import BaseProcessor from "./BaseProcessor";
export default class NotificationsProcessor extends BaseProcessor {
static applicableEvents: Event["name"][] = ["notifications.create"];
async perform(event: NotificationEvent) {
const notification = await Notification.scope([
"withTeam",
"withUser",
"withActor",
]).findByPk(event.modelId);
if (!notification) {
return;
}
switch (notification.event) {
case NotificationEventType.UpdateDocument:
case NotificationEventType.PublishDocument: {
await new DocumentPublishedOrUpdatedEmail(notification).schedule();
return;
}
case NotificationEventType.MentionedInDocument: {
await new DocumentMentionedEmail(notification).schedule();
return;
}
case NotificationEventType.MentionedInComment: {
await new CommentMentionedEmail(notification).schedule();
return;
}
case NotificationEventType.CreateCollection: {
await new CollectionCreatedEmail(notification).schedule();
return;
}
case NotificationEventType.CreateComment: {
await new CommentCreatedEmail(notification).schedule();
}
}
}
}