mirror of
https://github.com/Portabase/portabase.git
synced 2026-07-14 11:16:13 +02:00
Working on implementation of alert policies.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
"use server"
|
||||
// src/notifications/dispatch.ts
|
||||
import { eq } from 'drizzle-orm';
|
||||
import { dispatchViaProvider } from './providers';
|
||||
import type { EventPayload, DispatchResult } from './types';
|
||||
import {eq} from 'drizzle-orm';
|
||||
import {dispatchViaProvider} from './providers';
|
||||
import type {EventPayload, DispatchResult} from './types';
|
||||
import * as drizzleDb from "@/db";
|
||||
import {db} from "@/db";
|
||||
import {notificationLog} from "@/db/schema/11_notification-log";
|
||||
|
||||
export async function dispatchNotification(
|
||||
payload: EventPayload,
|
||||
@@ -44,30 +45,47 @@ export async function dispatchNotification(
|
||||
// };
|
||||
// }
|
||||
|
||||
if (channelId){
|
||||
if (channelId) {
|
||||
const channel = await db.query.notificationChannel.findFirst({
|
||||
where: eq(drizzleDb.schemas.notificationChannel.id, channelId),
|
||||
})
|
||||
|
||||
if (channel){
|
||||
if (channel) {
|
||||
const config = channel.config;
|
||||
|
||||
const result = await dispatchViaProvider(
|
||||
channel.provider as any,
|
||||
config,
|
||||
{ ...payload, timestamp: payload.timestamp || new Date() },
|
||||
{...payload, timestamp: payload.timestamp || new Date()},
|
||||
channel.id
|
||||
);
|
||||
|
||||
|
||||
const [log] = await db
|
||||
.insert(notificationLog)
|
||||
.values({
|
||||
channelId: channel.id,
|
||||
// policyId: policy.id,
|
||||
// organizationId: organizationId || null,
|
||||
title: payload.title,
|
||||
message: payload.message,
|
||||
level: payload.level,
|
||||
payload: payload.data || null,
|
||||
success: result.success,
|
||||
error: result.success ? null : result.error,
|
||||
providerResponse: result.response || null,
|
||||
})
|
||||
.returning({id: notificationLog.id});
|
||||
|
||||
|
||||
return {
|
||||
...result,
|
||||
channelId: channel.id,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
success: false,
|
||||
channelId,
|
||||
@@ -76,5 +94,4 @@ export async function dispatchNotification(
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user