refactor: refactored taskDetailAPI by adding some values
This commit is contained in:
@@ -9,6 +9,8 @@ import { AuthGuards } from '../../../common/decorators/auth-guard.decorator';
|
|||||||
import { AdminRoute } from '../../../common/decorators/admin.decorator';
|
import { AdminRoute } from '../../../common/decorators/admin.decorator';
|
||||||
import { UserDec } from '../../../common/decorators/user.decorator';
|
import { UserDec } from '../../../common/decorators/user.decorator';
|
||||||
import { ParamDto } from '../../../common/DTO/param.dto';
|
import { ParamDto } from '../../../common/DTO/param.dto';
|
||||||
|
import { PermissionsDec } from '../../../common/decorators/permission.decorator';
|
||||||
|
import { PermissionEnum } from '../../users/enums/permission.enum';
|
||||||
|
|
||||||
@AuthGuards()
|
@AuthGuards()
|
||||||
@AdminRoute()
|
@AdminRoute()
|
||||||
@@ -18,6 +20,7 @@ export class TaskController {
|
|||||||
constructor(private readonly taskService: TaskService) {}
|
constructor(private readonly taskService: TaskService) {}
|
||||||
|
|
||||||
@Get()
|
@Get()
|
||||||
|
@PermissionsDec(PermissionEnum.TASK)
|
||||||
@ApiOperation({ summary: 'Get all tasks, optionally filtered by phase' })
|
@ApiOperation({ summary: 'Get all tasks, optionally filtered by phase' })
|
||||||
@ApiQuery({ name: 'taskPhaseId', required: false, description: 'Filter tasks by task phase ID' })
|
@ApiQuery({ name: 'taskPhaseId', required: false, description: 'Filter tasks by task phase ID' })
|
||||||
@ApiResponse({ status: 200, description: 'List of tasks', type: [TMTask] })
|
@ApiResponse({ status: 200, description: 'List of tasks', type: [TMTask] })
|
||||||
@@ -27,6 +30,7 @@ export class TaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
|
@PermissionsDec(PermissionEnum.TASK)
|
||||||
@ApiOperation({ summary: 'Get a task by ID' })
|
@ApiOperation({ summary: 'Get a task by ID' })
|
||||||
@ApiParam({ name: 'id', description: 'Task ID' })
|
@ApiParam({ name: 'id', description: 'Task ID' })
|
||||||
@ApiResponse({ status: 200, description: 'Task found', type: TMTask })
|
@ApiResponse({ status: 200, description: 'Task found', type: TMTask })
|
||||||
@@ -36,6 +40,7 @@ export class TaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Post()
|
@Post()
|
||||||
|
@PermissionsDec(PermissionEnum.TASK)
|
||||||
@ApiOperation({ summary: 'Create a new task' })
|
@ApiOperation({ summary: 'Create a new task' })
|
||||||
@ApiResponse({ status: 201, description: 'Task created', type: TMTask })
|
@ApiResponse({ status: 201, description: 'Task created', type: TMTask })
|
||||||
@ApiResponse({ status: 404, description: 'TaskPhase not found' })
|
@ApiResponse({ status: 404, description: 'TaskPhase not found' })
|
||||||
@@ -44,6 +49,7 @@ export class TaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id')
|
@Patch(':id')
|
||||||
|
@PermissionsDec(PermissionEnum.TASK)
|
||||||
@ApiOperation({ summary: 'Update a task' })
|
@ApiOperation({ summary: 'Update a task' })
|
||||||
@ApiParam({ name: 'id', description: 'Task ID' })
|
@ApiParam({ name: 'id', description: 'Task ID' })
|
||||||
@ApiResponse({ status: 200, description: 'Task updated', type: TMTask })
|
@ApiResponse({ status: 200, description: 'Task updated', type: TMTask })
|
||||||
@@ -53,6 +59,7 @@ export class TaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Patch(':id/change-phase')
|
@Patch(':id/change-phase')
|
||||||
|
@PermissionsDec(PermissionEnum.TASK)
|
||||||
@ApiOperation({ summary: 'Move a task to a different phase within the same project' })
|
@ApiOperation({ summary: 'Move a task to a different phase within the same project' })
|
||||||
@ApiParam({ name: 'id', description: 'Task ID' })
|
@ApiParam({ name: 'id', description: 'Task ID' })
|
||||||
@ApiResponse({ status: 200, description: 'Task phase changed', type: TMTask })
|
@ApiResponse({ status: 200, description: 'Task phase changed', type: TMTask })
|
||||||
@@ -63,6 +70,7 @@ export class TaskController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':id')
|
@Delete(':id')
|
||||||
|
@PermissionsDec(PermissionEnum.TASK)
|
||||||
@ApiOperation({ summary: 'Delete a task' })
|
@ApiOperation({ summary: 'Delete a task' })
|
||||||
@ApiParam({ name: 'id', description: 'Task ID' })
|
@ApiParam({ name: 'id', description: 'Task ID' })
|
||||||
@ApiResponse({ status: 200, description: 'Task deleted' })
|
@ApiResponse({ status: 200, description: 'Task deleted' })
|
||||||
|
|||||||
@@ -5,18 +5,39 @@ import { TMTask } from "../entities/task.entity";
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TaskRepository extends Repository<TMTask> {
|
export class TaskRepository extends Repository<TMTask> {
|
||||||
constructor(
|
constructor(@InjectRepository(TMTask) taskRepository: Repository<TMTask>) {
|
||||||
@InjectRepository(TMTask) taskRepository: Repository<TMTask>,
|
super(taskRepository.target, taskRepository.manager, taskRepository.queryRunner);
|
||||||
) {
|
|
||||||
super(taskRepository.target, taskRepository.manager, taskRepository.queryRunner)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async getTaskDetail(taskId: string): Promise<TMTask | null> {
|
async getTaskDetail(taskId: string): Promise<TMTask | null> {
|
||||||
return this.createQueryBuilder('task')
|
return this.createQueryBuilder("task")
|
||||||
.leftJoinAndSelect('task.remarks', 'remark')
|
.leftJoinAndSelect("task.remarks", "remark")
|
||||||
.leftJoinAndSelect('task.attachments', 'attachment')
|
.leftJoinAndSelect("task.attachments", "attachment")
|
||||||
.leftJoinAndSelect('task.checkListItems', 'checkListItem')
|
.leftJoinAndSelect("task.checkListItems", "checkListItem")
|
||||||
.where('task.id = :taskId', {taskId})
|
.leftJoinAndSelect("task.users", "user")
|
||||||
.getOne();
|
|
||||||
|
.loadRelationCountAndMap("task.checkListItemCount", "task.checkListItems")
|
||||||
|
|
||||||
|
.loadRelationCountAndMap("task.completedCheckListItemCount", "task.checkListItems", "completedCheckListItems", (qb) =>
|
||||||
|
qb.where("completedCheckListItems.isDone = :isDone", { isDone: true }),
|
||||||
|
)
|
||||||
|
|
||||||
|
.select(["remark.id",
|
||||||
|
"remark.title",
|
||||||
|
"remark.color",
|
||||||
|
"checkListItem.id",
|
||||||
|
"checkListItem.title",
|
||||||
|
"checkListItem.isDone",
|
||||||
|
"attachment.id",
|
||||||
|
"attachment.title",
|
||||||
|
"attachment.type",
|
||||||
|
"attachment.file",
|
||||||
|
|
||||||
|
"user.id",
|
||||||
|
"user.firstName",
|
||||||
|
"user.lastName"
|
||||||
|
])
|
||||||
|
.where("task.id = :taskId", { taskId })
|
||||||
|
.getOne();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,5 +27,6 @@ export enum PermissionEnum {
|
|||||||
RESELLER="reseller",
|
RESELLER="reseller",
|
||||||
WORKSPACE="workspace",
|
WORKSPACE="workspace",
|
||||||
PROJECT="project",
|
PROJECT="project",
|
||||||
TASK_PHASE="task_phase"
|
TASK_PHASE="task_phase",
|
||||||
|
TASK="task"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user