51 lines
2.3 KiB
TypeScript
51 lines
2.3 KiB
TypeScript
import { Controller, Post, Patch, Delete, Param, Body, Get } from "@nestjs/common";
|
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam } from "@nestjs/swagger";
|
|
import { TaskCommentService } from "../providers/task-comment.service";
|
|
import { CreateTaskCommentDto } from "../dto/task-comment/create-task-comment.dto";
|
|
import { UpdateTaskCommentDto } from "../dto/task-comment/update-task-comment.dto";
|
|
import { TMTaskComment } from "../entities/task-comment.entity";
|
|
import { AuthGuards } from "../../../common/decorators/auth-guard.decorator";
|
|
import { AdminRoute } from "../../../common/decorators/admin.decorator";
|
|
import { UserDec } from "../../../common/decorators/user.decorator";
|
|
|
|
@AuthGuards()
|
|
@AdminRoute()
|
|
@ApiTags("Task Manager - Comments")
|
|
@Controller("task-manager/comments")
|
|
export class TaskCommentController {
|
|
constructor(private readonly taskCommentService: TaskCommentService) {}
|
|
|
|
@Get("task/:taskId")
|
|
@ApiOperation({ summary: "Get all comments for a task" })
|
|
@ApiParam({ name: "taskId", description: "Task ID" })
|
|
getTaskComments(@Param("taskId") taskId: string): Promise<TMTaskComment[]> {
|
|
return this.taskCommentService.getTaskComments(taskId);
|
|
}
|
|
|
|
@Post()
|
|
@ApiOperation({ summary: "Create a new comment" })
|
|
@ApiResponse({ status: 201, description: "Comment created", type: TMTaskComment })
|
|
@ApiResponse({ status: 404, description: "Task not found" })
|
|
create(@UserDec("id") userId: string, @Body() body: CreateTaskCommentDto): Promise<TMTaskComment> {
|
|
return this.taskCommentService.create(userId, body);
|
|
}
|
|
|
|
@Patch(":id")
|
|
@ApiOperation({ summary: "Update a comment" })
|
|
@ApiParam({ name: "id", description: "Comment ID" })
|
|
@ApiResponse({ status: 200, description: "Comment updated", type: TMTaskComment })
|
|
@ApiResponse({ status: 404, description: "Comment or Task not found" })
|
|
update(@Param("id") id: string, @Body() body: UpdateTaskCommentDto): Promise<TMTaskComment> {
|
|
return this.taskCommentService.update(id, body);
|
|
}
|
|
|
|
@Delete(":id")
|
|
@ApiOperation({ summary: "Delete a comment" })
|
|
@ApiParam({ name: "id", description: "Comment ID" })
|
|
@ApiResponse({ status: 200, description: "Comment deleted" })
|
|
@ApiResponse({ status: 404, description: "Comment not found" })
|
|
remove(@Param("id") id: string): Promise<void> {
|
|
return this.taskCommentService.remove(id);
|
|
}
|
|
}
|