⚡ 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
import { and, eq } from "drizzle-orm";
import { HTTPException } from "hono/http-exception";
import db from "../../database";
import { activityTable, taskTable } from "../../database/schema";
import { publishEvent } from "../../events";
import { deleteOrphanedAssets } from "../../storage/cleanup-assets";
async function deleteComment(userId: string, id: string) {
const [existing] = await db
.select({
id: activityTable.id,
content: activityTable.content,
taskId: activityTable.taskId,
})
.from(activityTable)
.where(
and(
eq(activityTable.id, id),
eq(activityTable.userId, userId),
eq(activityTable.type, "comment"),
),
)
.limit(1);
if (!existing) {
throw new HTTPException(404, {
message: "Comment not found or you are not the author",
});
}
const [deletedComment] = await db
.delete(activityTable)
.where(
and(
eq(activityTable.id, id),
eq(activityTable.userId, userId),
eq(activityTable.type, "comment"),
),
)
.returning();
if (!deletedComment) {
throw new HTTPException(404, {
message: "Comment not found or you are not the author",
});
}
const [task] = await db
.select({ projectId: taskTable.projectId })
.from(taskTable)
.where(eq(taskTable.id, deletedComment.taskId))
.limit(1);
if (task) {
await publishEvent("comment.deleted", {
...deletedComment,
projectId: task.projectId,
userId,
});
}
deleteOrphanedAssets(existing.content, null, {
taskId: existing.taskId,
}).catch(() => {});
return deletedComment;
}
export default deleteComment;