fix&feature: fixxing some logical bogs and adding cursor pagination
This commit is contained in:
@@ -1,74 +1,104 @@
|
||||
import { Controller, Get, Post, Patch, Delete, Param, Body } 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 { 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')
|
||||
@ApiTags("Task Manager - Tasks")
|
||||
@Controller("task-manager/tasks")
|
||||
export class TaskController {
|
||||
constructor(private readonly taskService: TaskService) {}
|
||||
|
||||
@Post()
|
||||
@PermissionsDec(PermissionEnum.TASK)
|
||||
@ApiOperation({ summary: 'Create a new task' })
|
||||
@ApiResponse({ status: 201, description: 'Task created', type: TMTask })
|
||||
@ApiResponse({ status: 404, description: 'TaskPhase not found' })
|
||||
@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')
|
||||
@Patch(":id")
|
||||
@PermissionsDec(PermissionEnum.TASK)
|
||||
@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> {
|
||||
@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')
|
||||
@Patch(":id/change-phase")
|
||||
@PermissionsDec(PermissionEnum.TASK)
|
||||
@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, @Body() body: ChangeTaskPhaseDto): Promise<TMTask> {
|
||||
@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, @Body() body: ChangeTaskPhaseDto): Promise<TMTask> {
|
||||
return this.taskService.changePhase(id, body);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@Delete(":id")
|
||||
@PermissionsDec(PermissionEnum.TASK)
|
||||
@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> {
|
||||
@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> {
|
||||
@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): Promise<TMTask> {
|
||||
return this.taskService.changePriority(srcId, desId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user