import { Injectable } from '@nestjs/common'; import { CommandBus, QueryBus } from '@nestjs/cqrs'; import { CommentReadModel } 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 { Page } from './ports/find-issues.repository'; import { GetCommentsQuery } from './queries/get-comments.query'; @Injectable() export class CommentsService { constructor( private readonly commandBus: CommandBus, private readonly queryBus: QueryBus, ) {} add(actorId: string, issueId: string, body: string): Promise { return this.commandBus.execute( new AddCommentCommand(actorId, issueId, body), ); } edit( actorId: string, commentId: string, body: string, ): Promise { return this.commandBus.execute( new EditCommentCommand(actorId, commentId, body), ); } delete(actorId: string, commentId: string): Promise { return this.commandBus.execute( new DeleteCommentCommand(actorId, commentId), ); } list( viewerId: string | null, issueId: string, limit?: number, offset?: number, ): Promise> { return this.queryBus.execute( new GetCommentsQuery(viewerId, issueId, limit, offset), ); } }