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";
5
6async function createNotification({
7 userId,
8 title,
9 content,
10 type,
11 resourceId,
12 resourceType,
13}: {
14 userId: string;
15 title: string;
16 content?: string;
17 type?: string;
18 resourceId?: string;
19 resourceType?: string;
20}) {
21 const [notification] = await db
22 .insert(notificationTable)
23 .values({
24 id: createId(),
25 userId,
26 title,
27 content: content || "",
28 type: type || "info",
29 resourceId: resourceId || null,
30 resourceType: resourceType || null,
31 })
32 .returning();
33
34 if (notification) {
35 await publishEvent("notification.created", {
36 notificationId: notification.id,
37 userId,
38 });
39 }
40
41 return notification;
42}
43
44export default createNotification;