import { Inject, Body, Controller, Delete, Get, Param, Patch, Post, Query, Req } from "@nestjs/common"; import type { Request } from "express"; import { CommentsService } from "./comments.service.js"; import { ZodValidate } from "../../common/pipes/zod-validation.pipe.js"; import { requireActor } from "../../common/types.js"; import { CreateCommentDto, type CreateCommentInput, ListCommentsQuery, type ListCommentsInput, ReactionDto, type ReactionInput, UpdateCommentDto, type UpdateCommentInput } from "./dto.js"; @Controller("comments") export class CommentsController { constructor(@Inject(CommentsService) private readonly comments: CommentsService) {} @Get() list( @Query(ZodValidate(ListCommentsQuery)) query: ListCommentsInput, @Req() req: Request ) { return this.comments.list(requireActor(req), query); } @Post() create( @Body(ZodValidate(CreateCommentDto)) body: CreateCommentInput, @Req() req: Request ) { return this.comments.create(requireActor(req), body, req); } @Patch(":id") update( @Param("id") id: string, @Body(ZodValidate(UpdateCommentDto)) body: UpdateCommentInput, @Req() req: Request ) { return this.comments.update(id, requireActor(req), body, req); } @Delete(":id") remove(@Param("id") id: string, @Req() req: Request) { return this.comments.remove(id, requireActor(req), req).then(() => ({ deleted: true })); } @Post(":id/reactions") react( @Param("id") id: string, @Body(ZodValidate(ReactionDto)) body: ReactionInput, @Req() req: Request ) { return this.comments.toggleReaction(id, requireActor(req), body, req); } @Post(":id/resolve") resolve(@Param("id") id: string, @Req() req: Request) { return this.comments.resolve(id, requireActor(req), req); } @Post(":id/reopen") reopen(@Param("id") id: string, @Req() req: Request) { return this.comments.reopen(id, requireActor(req), req); } }