import { Body, Controller, Delete, HttpCode, Param, Patch, Post, } from '@nestjs/common'; import { ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; import { User } from '@task-stream/api/identity/domain'; import { ApiPireonAuth, CurrentUser, } from '@task-stream/api/identity/presenters'; import { ApiCommandErrors } from '@task-stream/api/shared/presenters'; import { CommentsService } from '@task-stream/api/tracker/application'; import { REACTIONS } from '@task-stream/api/tracker/domain'; import { CommentBodyDto, ReactToCommentDto } from './dto/requests.dto'; import { CommandResultDto } from './dto/responses.dto'; /** REST adapter of the comment use cases (listing and adding live under /issues). */ @ApiTags('Comments') @ApiPireonAuth() @Controller('comments') export class CommentsController { constructor(private readonly comments: CommentsService) {} @Patch(':commentId') @ApiOperation({ summary: 'Edit a comment (author only)' }) @ApiOkResponse({ type: CommandResultDto }) @ApiCommandErrors() edit( @CurrentUser() me: User, @Param('commentId') commentId: string, @Body() body: CommentBodyDto, ) { return this.comments.edit(me.id, commentId, body.body); } @Post(':commentId/reactions') @HttpCode(200) @ApiOperation({ summary: 'React to a comment, or take the reaction back (members)', description: `One of ${REACTIONS.join(' ')}; repeating it changes nothing.`, }) @ApiOkResponse({ type: CommandResultDto }) @ApiCommandErrors() react( @CurrentUser() me: User, @Param('commentId') commentId: string, @Body() body: ReactToCommentDto, ) { return this.comments.react(me.id, commentId, body.emoji, body.on); } @Delete(':commentId') @ApiOperation({ summary: 'Delete a comment (author or project admin)' }) @ApiOkResponse({ type: CommandResultDto }) @ApiCommandErrors() delete(@CurrentUser() me: User, @Param('commentId') commentId: string) { return this.comments.delete(me.id, commentId); } }