Mention project members in comments with @, follow and unfollow tickets, and get told when something changes on the tickets you follow. Commenting on a ticket starts following it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
34 lines
1.3 KiB
TypeScript
34 lines
1.3 KiB
TypeScript
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs';
|
|
import { ForbiddenError } from '@task-stream/api/shared/domain';
|
|
import { CommandResult, ack } from './command-result';
|
|
import { WatchIssueCommand } from './watch-issue.command';
|
|
import { WriteAccess } from './write-access';
|
|
|
|
/**
|
|
* Following is for members, viewers included: reading a ticket is enough to
|
|
* want to hear about it. People only follow or unfollow for themselves.
|
|
*/
|
|
@CommandHandler(WatchIssueCommand)
|
|
export class WatchIssueCommandHandler
|
|
implements ICommandHandler<WatchIssueCommand>
|
|
{
|
|
constructor(private readonly access: WriteAccess) {}
|
|
|
|
async execute(command: WatchIssueCommand): Promise<CommandResult> {
|
|
const issue = await this.access.issue(command.issueId);
|
|
const project = await this.access.project(issue.projectId);
|
|
if (command.actorId !== command.userId) {
|
|
throw new ForbiddenError('You can only follow tickets yourself');
|
|
}
|
|
if (!project.isMember(command.userId)) {
|
|
throw new ForbiddenError(
|
|
`You are not a member of project ${project.key}`,
|
|
);
|
|
}
|
|
if (command.watching) issue.watch(command.actorId, command.userId);
|
|
else issue.unwatch(command.actorId, command.userId);
|
|
await issue.commitAndWait();
|
|
return ack(issue);
|
|
}
|
|
}
|