kaneo (minimalist kanban) fork to experiment adding a tangled integration
github.com/usekaneo/kaneo
1import { createId } from "@paralleldrive/cuid2";
2import db from "../../database";
3import { notificationTable } from "../../database/schema";
4import { publishEvent } from "../../events";
5import { deliverNotification } from "../../notification-preferences/delivery";
6
7async function createNotification({
8 userId,
9 title,
10 content,
11 type,
12 eventData,
13 resourceId,
14 resourceType,
15}: {
16 userId: string;
17 title?: string | null;
18 content?: string | null;
19 type?: string;
20 eventData?: Record<string, unknown> | null;
21 resourceId?: string;
22 resourceType?: string;
23}) {
24 const [notification] = await db
25 .insert(notificationTable)
26 .values({
27 id: createId(),
28 userId,
29 title: title ?? null,
30 content: content ?? null,
31 type: type || "info",
32 eventData: eventData ?? null,
33 resourceId: resourceId || null,
34 resourceType: resourceType || null,
35 })
36 .returning();
37
38 if (notification) {
39 await publishEvent("notification.created", {
40 notificationId: notification.id,
41 userId,
42 });
43 void deliverNotification(notification.id).catch((error) => {
44 console.error("Failed to deliver notification", {
45 notificationId: notification.id,
46 error,
47 });
48 });
49 }
50
51 return notification;
52}
53
54export default createNotification;