Skip to content

armgit / kaneo

Public Imported from GitHub
0

⚡ Project management that doesn't become the project. Boards, Gantt charts, and GitHub integration. Self-host it or use Kaneo Cloud.

feat(api): add event subscriptions for task activity tracking

Andrej Acevskif921402f21e4
diff --git a/apps/api/src/activity/index.ts b/apps/api/src/activity/index.ts
index 25ae93e8a..0c44528d5 100644
--- a/apps/api/src/activity/index.ts
+++ b/apps/api/src/activity/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 { activitySchema } from "../schemas";
import createActivity from "./controllers/create-activity";
import createComment from "./controllers/create-comment";
@@ -152,4 +153,125 @@ const activity = new Hono<{
},
);
+subscribeToEvent<{
+ taskId: string;
+ userId: string;
+ type: string;
+ content: string;
+}>("task.created", async (data) => {
+ await createActivity(data.taskId, data.type, data.userId, data.content);
+});
+
+subscribeToEvent<{
+ taskId: string;
+ userId: string;
+ oldStatus: string;
+ newStatus: string;
+ title: string;
+ type: string;
+}>("task.status_changed", async (data) => {
+ await createActivity(
+ data.taskId,
+ data.type,
+ data.userId,
+ `changed status from "${data.oldStatus}" to "${data.newStatus}"`,
+ );
+});
+
+subscribeToEvent<{
+ taskId: string;
+ userId: string;
+ oldPriority: string;
+ newPriority: string;
+ title: string;
+ type: string;
+}>("task.priority_changed", async (data) => {
+ await createActivity(
+ data.taskId,
+ data.type,
+ data.userId,
+ `changed priority from "${data.oldPriority}" to "${data.newPriority}"`,
+ );
+});
+
+subscribeToEvent<{
+ taskId: string;
+ userId: string;
+ title: string;
+ type: string;
+}>("task.unassigned", async (data) => {
+ await createActivity(
+ data.taskId,
+ data.type,
+ data.userId,
+ "unassigned the task",
+ );
+});
+
+subscribeToEvent<{
+ taskId: string;
+ userId: string;
+ oldAssignee: string | null;
+ newAssignee: string;
+ title: string;
+ type: string;
+}>("task.assignee_changed", async (data) => {
+ await createActivity(
+ data.taskId,
+ data.type,
+ data.userId,
+ `assigned the task to ${data.newAssignee}`,
+ );
+});
+
+subscribeToEvent<{
+ taskId: string;
+ userId: string;
+ oldDueDate: Date | null;
+ newDueDate: Date;
+ title: string;
+ type: string;
+}>("task.due_date_changed", async (data) => {
+ const oldDate = data.oldDueDate
+ ? new Date(data.oldDueDate).toLocaleDateString()
+ : "none";
+ const newDate = new Date(data.newDueDate).toLocaleDateString();
+ await createActivity(
+ data.taskId,
+ data.type,
+ data.userId,
+ `changed due date from ${oldDate} to ${newDate}`,
+ );
+});
+
+subscribeToEvent<{
+ taskId: string;
+ userId: string;
+ oldTitle: string;
+ newTitle: string;
+ title: string;
+ type: string;
+}>("task.title_changed", async (data) => {
+ await createActivity(
+ data.taskId,
+ data.type,
+ data.userId,
+ `changed title from "${data.oldTitle}" to "${data.newTitle}"`,
+ );
+});
+
+subscribeToEvent<{
+ taskId: string;
+ userId: string;
+ title: string;
+ type: string;
+}>("task.description_changed", async (data) => {
+ await createActivity(
+ data.taskId,
+ data.type,
+ data.userId,
+ "updated the description",
+ );
+});
+
export default activity;