Files
outline/server/queues/tasks/CollectionCreatedNotificationsTask.ts
dependabot[bot] fbd16d4b9a chore(deps-dev): bump prettier from 2.1.2 to 2.8.8 (#5372)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Tom Moor <tom.moor@gmail.com>
2023-05-22 19:14:56 -07:00

44 lines
1.3 KiB
TypeScript

import { NotificationEventType } from "@shared/types";
import { Collection, Notification } from "@server/models";
import NotificationHelper from "@server/models/helpers/NotificationHelper";
import { CollectionEvent } from "@server/types";
import BaseTask, { TaskPriority } from "./BaseTask";
export default class CollectionCreatedNotificationsTask extends BaseTask<CollectionEvent> {
public async perform(event: CollectionEvent) {
const collection = await Collection.findByPk(event.collectionId);
// We only send notifications for collections visible to the entire team
if (!collection || collection.isPrivate) {
return;
}
const recipients =
await NotificationHelper.getCollectionNotificationRecipients(
collection,
NotificationEventType.CreateCollection
);
for (const recipient of recipients) {
// Suppress notifications for suspended users
if (recipient.isSuspended || !recipient.email) {
continue;
}
await Notification.create({
event: NotificationEventType.CreateCollection,
userId: recipient.id,
collectionId: collection.id,
actorId: collection.createdById,
teamId: collection.teamId,
});
}
}
public get options() {
return {
priority: TaskPriority.Background,
};
}
}