1import { Inject, Body, Controller, Delete, Get, Param, Patch, Post, Query, Req } from "@nestjs/common"; 2import type { Request } from "express"; 3import { CommentsService } from "./comments.service.js"; 4import { ZodValidate } from "../../common/pipes/zod-validation.pipe.js"; 5import { requireActor } from "../../common/types.js"; 6import { 7 CreateCommentDto, 8 type CreateCommentInput, 9 ListCommentsQuery, 10 type ListCommentsInput, 11 ReactionDto, 12 type ReactionInput, 13 UpdateCommentDto, 14 type UpdateCommentInput 15} from "./dto.js"; 16 17@Controller("comments") 18export class CommentsController { 19 constructor(@Inject(CommentsService) private readonly comments: CommentsService) {} 20 21 @Get() 22 list( 23 @Query(ZodValidate(ListCommentsQuery)) query: ListCommentsInput, 24 @Req() req: Request 25 ) { 26 return this.comments.list(requireActor(req), query); 27 } 28 29 @Post() 30 create( 31 @Body(ZodValidate(CreateCommentDto)) body: CreateCommentInput, 32 @Req() req: Request 33 ) { 34 return this.comments.create(requireActor(req), body, req); 35 } 36 37 @Patch(":id") 38 update( 39 @Param("id") id: string, 40 @Body(ZodValidate(UpdateCommentDto)) body: UpdateCommentInput, 41 @Req() req: Request 42 ) { 43 return this.comments.update(id, requireActor(req), body, req); 44 } 45 46 @Delete(":id") 47 remove(@Param("id") id: string, @Req() req: Request) { 48 return this.comments.remove(id, requireActor(req), req).then(() => ({ deleted: true })); 49 } 50 51 @Post(":id/reactions") 52 react( 53 @Param("id") id: string, 54 @Body(ZodValidate(ReactionDto)) body: ReactionInput, 55 @Req() req: Request 56 ) { 57 return this.comments.toggleReaction(id, requireActor(req), body, req); 58 } 59 60 @Post(":id/resolve") 61 resolve(@Param("id") id: string, @Req() req: Request) { 62 return this.comments.resolve(id, requireActor(req), req); 63 } 64 65 @Post(":id/reopen") 66 reopen(@Param("id") id: string, @Req() req: Request) { 67 return this.comments.reopen(id, requireActor(req), req); 68 } 69} 70