fix: ensure we dont bloat notification table with any other notification than app
This commit is contained in:
@@ -117,21 +117,28 @@ function getIntegration(integrationId: string | null) {
|
||||
}
|
||||
|
||||
export async function createNotification(notification: ICreateNotification) {
|
||||
const res = await db.notification.create({
|
||||
data: {
|
||||
title: notification.title,
|
||||
message: notification.message,
|
||||
projectId: notification.projectId,
|
||||
payload: notification.payload || Prisma.DbNull,
|
||||
...getIntegration(notification.integrationId),
|
||||
notificationRuleId: notification.notificationRuleId,
|
||||
},
|
||||
});
|
||||
const data: Prisma.NotificationUncheckedCreateInput = {
|
||||
title: notification.title,
|
||||
message: notification.message,
|
||||
projectId: notification.projectId,
|
||||
payload: notification.payload || Prisma.DbNull,
|
||||
...getIntegration(notification.integrationId),
|
||||
notificationRuleId: notification.notificationRuleId,
|
||||
};
|
||||
|
||||
return triggerNotification(res);
|
||||
// Only create notifications for app
|
||||
if (data.sendToApp) {
|
||||
await db.notification.create({
|
||||
data,
|
||||
});
|
||||
}
|
||||
|
||||
return triggerNotification(data);
|
||||
}
|
||||
|
||||
export function triggerNotification(notification: Notification) {
|
||||
export function triggerNotification(
|
||||
notification: Prisma.NotificationUncheckedCreateInput,
|
||||
) {
|
||||
return notificationQueue.add('sendNotification', {
|
||||
type: 'sendNotification',
|
||||
payload: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { Queue, QueueEvents } from 'bullmq';
|
||||
|
||||
import type { IServiceEvent, Notification } from '@openpanel/db';
|
||||
import type { IServiceEvent, Notification, Prisma } from '@openpanel/db';
|
||||
import { getRedisQueue } from '@openpanel/redis';
|
||||
import type { TrackPayload } from '@openpanel/sdk';
|
||||
|
||||
@@ -130,7 +130,7 @@ export const miscQueue = new Queue<MiscQueuePayload>('misc', {
|
||||
export type NotificationQueuePayload = {
|
||||
type: 'sendNotification';
|
||||
payload: {
|
||||
notification: Notification;
|
||||
notification: Prisma.NotificationUncheckedCreateInput;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { type Redis, getRedisPub, getRedisSub } from './redis';
|
||||
|
||||
import type { IServiceEvent, Notification } from '@openpanel/db';
|
||||
import type { IServiceEvent, Notification, Prisma } from '@openpanel/db';
|
||||
import { getSuperJson, setSuperJson } from '@openpanel/json';
|
||||
|
||||
export type IPublishChannels = {
|
||||
@@ -14,7 +14,7 @@ export type IPublishChannels = {
|
||||
saved: IServiceEvent;
|
||||
};
|
||||
notification: {
|
||||
created: Notification;
|
||||
created: Prisma.NotificationUncheckedCreateInput;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user