Files
task-stream/libs/api/tracker/application/src/lib/comments.service.ts
Josep Piguillem 70e4fbd399 feat: comments marked as decisions, on top of the ticket and searchable
Whoever can change the ticket flags a comment as a decision (new event
CommentDecisionMarkedEvent on the comment). The ticket page lists its
decisions above the description, with a link to the comment in the
conversation (`?comment=<id>` scrolls to it and points at it), and the
search palette finds them by their text across my projects.

API: markDecision / PUT-DELETE /api/comments/{id}/decision; Issue.decisions
and GET /api/issues/{issue}/decisions; decisions(projectId?, search) and
GET /api/projects/{project}/decisions, GET /api/me/decisions. MCP:
mark_decision, search_decisions, and get_issue includes them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-17 11:32:07 +02:00

105 lines
3.0 KiB
TypeScript

import { CommandRunner } from '@task-stream/api/shared/application';
import { Injectable } from '@nestjs/common';
import { QueryBus } from '@nestjs/cqrs';
import {
CommentReadModel,
DecisionReadModel,
} from '@task-stream/api/tracker/domain';
import { AddCommentCommand } from './commands/add-comment.command';
import { CommandResult } from './commands/command-result';
import { DeleteCommentCommand } from './commands/delete-comment.command';
import { EditCommentCommand } from './commands/edit-comment.command';
import { ReactToCommentCommand } from './commands/react-to-comment.command';
import { MarkDecisionCommand } from './commands/mark-decision.command';
import { Page } from './ports/find-issues.repository';
import { GetCommentsQuery } from './queries/get-comments.query';
import {
GetIssueDecisionsQuery,
SearchDecisionsQuery,
} from './queries/decisions.query';
@Injectable()
export class CommentsService {
constructor(
private readonly commands: CommandRunner,
private readonly queryBus: QueryBus,
) {}
add(
actorId: string,
issueId: string,
body: string,
replyTo: string | null = null,
): Promise<CommandResult> {
return this.commands.execute(
new AddCommentCommand(actorId, issueId, body, replyTo),
);
}
edit(
actorId: string,
commentId: string,
body: string,
): Promise<CommandResult> {
return this.commands.execute(
new EditCommentCommand(actorId, commentId, body),
);
}
/** Adds (`on`) or takes back one's reaction (👍…). */
react(
actorId: string,
commentId: string,
emoji: string,
on: boolean,
): Promise<CommandResult> {
return this.commands.execute(
new ReactToCommentCommand(actorId, commentId, emoji, on),
);
}
/** Marks it as a decision of its ticket (`on`) or unmarks it: the team does. */
markDecision(
actorId: string,
commentId: string,
on: boolean,
): Promise<CommandResult> {
return this.commands.execute(
new MarkDecisionCommand(actorId, commentId, on),
);
}
/** A ticket's decisions, oldest first. */
decisions(
viewerId: string | null,
issueId: string,
): Promise<CommentReadModel[]> {
return this.queryBus.execute(new GetIssueDecisionsQuery(viewerId, issueId));
}
/** Decisions by their text: of a project, or of all mine without one. */
searchDecisions(
viewerId: string | null,
filter: { projectId?: string; search?: string; limit?: number },
): Promise<DecisionReadModel[]> {
return this.queryBus.execute(
new SearchDecisionsQuery(viewerId, { limit: 20, ...filter }),
);
}
delete(actorId: string, commentId: string): Promise<CommandResult> {
return this.commands.execute(new DeleteCommentCommand(actorId, commentId));
}
list(
viewerId: string | null,
issueId: string,
limit?: number,
offset?: number,
): Promise<Page<CommentReadModel>> {
return this.queryBus.execute(
new GetCommentsQuery(viewerId, issueId, limit, offset),
);
}
}