104 lines
4.8 KiB
TypeScript
104 lines
4.8 KiB
TypeScript
import { Controller, Get, Post, Patch, Delete, Param, Body, Query } from "@nestjs/common";
|
|
import { ApiTags, ApiOperation, ApiResponse, ApiParam } from "@nestjs/swagger";
|
|
import { TaskService } from "../providers/task.service";
|
|
import { CreateTaskDto } from "../dto/task/create-task.dto";
|
|
import { UpdateTaskDto } from "../dto/task/update-task.dto";
|
|
import { ChangeTaskPhaseDto } from "../dto/task/change-task-phase.dto";
|
|
import { TMTask } from "../entities/task.entity";
|
|
import { AuthGuards } from "../../../common/decorators/auth-guard.decorator";
|
|
import { AdminRoute } from "../../../common/decorators/admin.decorator";
|
|
import { UserDec } from "../../../common/decorators/user.decorator";
|
|
import { ParamDto } from "../../../common/DTO/param.dto";
|
|
import { PermissionsDec } from "../../../common/decorators/permission.decorator";
|
|
import { PermissionEnum } from "../../users/enums/permission.enum";
|
|
import { ITokenPayload } from "../../auth/interfaces/IToken-payload";
|
|
import { CursorPagination } from "../../../common/decorators/cursor-pagination.decorator";
|
|
import { CursorPaginationDto } from "../../../common/DTO/cursor-pagination.dto";
|
|
|
|
@AuthGuards()
|
|
@AdminRoute()
|
|
@ApiTags("Task Manager - Tasks")
|
|
@Controller("task-manager/tasks")
|
|
export class TaskController {
|
|
constructor(private readonly taskService: TaskService) {}
|
|
|
|
@Post()
|
|
@PermissionsDec(PermissionEnum.TASK_CREATE)
|
|
@ApiOperation({ summary: "Create a new task" })
|
|
@ApiResponse({ status: 201, description: "Task created", type: TMTask })
|
|
@ApiResponse({ status: 404, description: "TaskPhase not found" })
|
|
create(@Body() body: CreateTaskDto): Promise<TMTask> {
|
|
return this.taskService.create(body);
|
|
}
|
|
|
|
@Patch(":id")
|
|
@PermissionsDec(PermissionEnum.TASK_UPDATE)
|
|
@ApiOperation({ summary: "Update a task" })
|
|
@ApiParam({ name: "id", description: "Task ID" })
|
|
@ApiResponse({ status: 200, description: "Task updated", type: TMTask })
|
|
@ApiResponse({ status: 404, description: "Task or TaskPhase not found" })
|
|
update(@Param("id") id: string, @Body() body: UpdateTaskDto): Promise<TMTask> {
|
|
return this.taskService.update(id, body);
|
|
}
|
|
|
|
@Patch(":id/change-phase")
|
|
@ApiOperation({ summary: "Move a task to a different phase within the same project" })
|
|
@ApiParam({ name: "id", description: "Task ID" })
|
|
@ApiResponse({ status: 200, description: "Task phase changed", type: TMTask })
|
|
@ApiResponse({ status: 400, description: "Target phase belongs to a different project" })
|
|
@ApiResponse({ status: 404, description: "Task or TaskPhase not found" })
|
|
changePhase(@Param("id") id: string,@UserDec() user: ITokenPayload, @Body() body: ChangeTaskPhaseDto): Promise<TMTask> {
|
|
return this.taskService.changePhase(id, user.permissions, user.id, body);
|
|
}
|
|
|
|
@Delete(":id")
|
|
@PermissionsDec(PermissionEnum.TASK_DELETE)
|
|
@ApiOperation({ summary: "Delete a task" })
|
|
@ApiParam({ name: "id", description: "Task ID" })
|
|
@ApiResponse({ status: 200, description: "Task deleted" })
|
|
@ApiResponse({ status: 404, description: "Task not found" })
|
|
remove(@Param("id") id: string): Promise<void> {
|
|
return this.taskService.remove(id);
|
|
}
|
|
|
|
@Get("detail/:id")
|
|
@ApiOperation({ summary: "Get Task Detail" })
|
|
@ApiParam({ name: "id", description: "Task ID" })
|
|
@ApiResponse({ status: 200, description: "Task detail received!" })
|
|
@ApiResponse({ status: 404, description: "Task not found" })
|
|
getTaskDetail(@UserDec() user: ITokenPayload, @Param() paramDto: ParamDto): Promise<TMTask | null> {
|
|
return this.taskService.getTaskDetail(user.id, user.permissions, paramDto.id);
|
|
}
|
|
|
|
@Get("task-phase/:id")
|
|
@ApiOperation({ summary: "Get Tasks by task phase" })
|
|
@ApiParam({ name: "id", description: "Task phase id" })
|
|
@ApiResponse({ status: 200, description: "Got Tasks by task phase successfully!" })
|
|
@ApiResponse({ status: 400, description: "Bad request from user." })
|
|
@CursorPagination()
|
|
findByTaskPhase(
|
|
@Param("id") taskPhaseId: string,
|
|
@Query() pagination: CursorPaginationDto,
|
|
): Promise<{
|
|
data: TMTask[];
|
|
nextCursor: string | null;
|
|
previousCursor: string | null;
|
|
hasNextPage: boolean;
|
|
hasPreviousPage: boolean;
|
|
cursorPaginate: true;
|
|
}> {
|
|
return this.taskService.findTasksByTaskPhase(taskPhaseId, pagination);
|
|
}
|
|
|
|
@Patch("change-priority/:srcid/:desid")
|
|
@ApiOperation({ summary: "changing the task priority" })
|
|
@ApiParam({ name: "srcid", description: "ID of the source task" })
|
|
@ApiParam({ name: "desid", description: "ID of the destination task" })
|
|
@ApiResponse({ status: 200, description: "Changed the task priority successfully!" })
|
|
@ApiResponse({ status: 400, description: "Bad Request from user." })
|
|
@ApiResponse({ status: 404, description: "Task not found!" })
|
|
changePriority(@Param("srcid") srcId: string, @Param("desid") desId: string,@UserDec() user: ITokenPayload): Promise<TMTask> {
|
|
return this.taskService.changePriority(srcId, user.permissions, user.id, desId);
|
|
}
|
|
}
|