⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.
TypeScript honoissue-managementissue-trackerjira-alternativekanbanlinear-alternativemcpproject-managementreactself-hostedtypescript
feat(api): enhance event subscriptions for task and workspace notifications
Andrej Acevski04429bbeb812
diff --git a/apps/api/src/activity/index.ts b/apps/api/src/activity/index.tsindex 0c44528d5..e560e36b9 100644--- a/apps/api/src/activity/index.ts+++ b/apps/api/src/activity/index.ts@@ -168,6 +168,7 @@ subscribeToEvent<{oldStatus: string;newStatus: string;title: string;+ assigneeId?: string;type: string;}>("task.status_changed", async (data) => {await createActivity(@@ -213,6 +214,7 @@ subscribeToEvent<{userId: string;oldAssignee: string | null;newAssignee: string;+ newAssigneeId: string;title: string;type: string;}>("task.assignee_changed", async (data) => {diff --git a/apps/api/src/auth.ts b/apps/api/src/auth.tsindex adcb0523a..759f44ad5 100644--- a/apps/api/src/auth.ts+++ b/apps/api/src/auth.ts@@ -170,6 +170,7 @@ export const auth = betterAuth({workspaceId: organization.id,workspaceName: organization.name,ownerEmail: user.name,+ ownerId: user.id,});},},diff --git a/apps/api/src/notification/index.ts b/apps/api/src/notification/index.tsindex 4d1c59748..5157afa14 100644--- a/apps/api/src/notification/index.ts+++ b/apps/api/src/notification/index.ts@@ -1,6 +1,7 @@import { Hono } from "hono";import { describeRoute, resolver, validator } from "hono-openapi";import * as v from "valibot";+import { subscribeToEvent } from "../events";import { notificationSchema } from "../schemas";import clearNotifications from "./controllers/clear-notifications";import createNotification from "./controllers/create-notification";@@ -152,4 +153,99 @@ const notification = new Hono<{},);+subscribeToEvent<{+ taskId: string;+ userId: string;+ title: string;+ projectId: string;+}>("task.created", async (data) => {+ if (data.userId) {+ await createNotification({+ userId: data.userId,+ title: "New task assigned",+ content: `You have been assigned to task: ${data.title}`,+ type: "task_created",+ resourceId: data.taskId,+ resourceType: "task",+ });+ }+});++subscribeToEvent<{+ workspaceId: string;+ workspaceName: string;+ ownerEmail: string;+ ownerId?: string;+}>("workspace.created", async (data) => {+ if (data.ownerId) {+ await createNotification({+ userId: data.ownerId,+ title: "Workspace created",+ content: `Your workspace "${data.workspaceName}" has been created successfully`,+ type: "workspace_created",+ resourceId: data.workspaceId,+ resourceType: "workspace",+ });+ }+});++subscribeToEvent<{+ taskId: string;+ userId: string;+ oldStatus: string;+ newStatus: string;+ title: string;+ assigneeId?: string;+}>("task.status_changed", async (data) => {+ if (data.assigneeId && data.assigneeId !== data.userId) {+ await createNotification({+ userId: data.assigneeId,+ title: "Task status changed",+ content: `Task "${data.title}" status changed from "${data.oldStatus}" to "${data.newStatus}"`,+ type: "task_status_changed",+ resourceId: data.taskId,+ resourceType: "task",+ });+ }+});++subscribeToEvent<{+ taskId: string;+ userId: string;+ oldAssignee: string | null;+ newAssignee: string;+ newAssigneeId: string;+ title: string;+}>("task.assignee_changed", async (data) => {+ if (data.newAssigneeId) {+ await createNotification({+ userId: data.newAssigneeId,+ title: "Task assigned to you",+ content: `You have been assigned to task: ${data.title}`,+ type: "task_assignee_changed",+ resourceId: data.taskId,+ resourceType: "task",+ });+ }+});++subscribeToEvent<{+ timeEntryId: string;+ taskId: string;+ userId: string;+ taskOwnerId?: string;+ taskTitle?: string;+}>("time-entry.created", async (data) => {+ if (data.taskOwnerId && data.taskOwnerId !== data.userId) {+ await createNotification({+ userId: data.taskOwnerId,+ title: "Time tracking started",+ content: `Time tracking started on task${data.taskTitle ? `: ${data.taskTitle}` : ""}`,+ type: "time_entry_created",+ resourceId: data.taskId,+ resourceType: "task",+ });+ }+});+export default notification;diff --git a/apps/api/src/task/index.ts b/apps/api/src/task/index.tsindex cdbb7855f..3790304f1 100644--- a/apps/api/src/task/index.ts+++ b/apps/api/src/task/index.ts@@ -177,6 +177,7 @@ const task = new Hono<{oldStatus: task.status,newStatus: status,title: task.title,+ assigneeId: task.userId,type: "status_changed",});}@@ -302,6 +303,7 @@ const task = new Hono<{oldStatus: task.status,newStatus: status,title: task.title,+ assigneeId: task.userId,type: "status_changed",});@@ -391,6 +393,7 @@ const task = new Hono<{userId: user,oldAssignee: task.userId,newAssignee: newAssigneeName,+ newAssigneeId: userId,title: task.title,type: "assignee_changed",});diff --git a/apps/api/src/time-entry/controllers/create-time-entry.ts b/apps/api/src/time-entry/controllers/create-time-entry.tsindex 1fda88ea9..ed56398a8 100644--- a/apps/api/src/time-entry/controllers/create-time-entry.ts+++ b/apps/api/src/time-entry/controllers/create-time-entry.ts@@ -1,7 +1,8 @@import { createId } from "@paralleldrive/cuid2";+import { eq } from "drizzle-orm";import { HTTPException } from "hono/http-exception";import db from "../../database";-import { timeEntryTable } from "../../database/schema";+import { taskTable, timeEntryTable } from "../../database/schema";import { publishEvent } from "../../events";async function createTimeEntry({@@ -38,12 +39,19 @@ async function createTimeEntry({});}+ const [task] = await db+ .select({ userId: taskTable.userId, title: taskTable.title })+ .from(taskTable)+ .where(eq(taskTable.id, taskId));+await publishEvent("time-entry.created", {timeEntryId: createdTimeEntry.id,taskId: createdTimeEntry.taskId,userId,type: "create",content: "started time tracking",+ taskOwnerId: task?.userId,+ taskTitle: task?.title,});return createdTimeEntry;