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 { 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';
|
||||
|
||||
@AuthGuards()
|
||||
@AdminRoute()
|
||||
@@ -18,6 +20,7 @@ export class TaskController {
|
||||
constructor(private readonly taskService: TaskService) {}
|
||||
|
||||
@Get()
|
||||
@PermissionsDec(PermissionEnum.TASK)
|
||||
@ApiOperation({ summary: 'Get all tasks, optionally filtered by phase' })
|
||||
@ApiQuery({ name: 'taskPhaseId', required: false, description: 'Filter tasks by task phase ID' })
|
||||
@ApiResponse({ status: 200, description: 'List of tasks', type: [TMTask] })
|
||||
@@ -27,6 +30,7 @@ export class TaskController {
|
||||
}
|
||||
|
||||
@Get(':id')
|
||||
@PermissionsDec(PermissionEnum.TASK)
|
||||
@ApiOperation({ summary: 'Get a task by ID' })
|
||||
@ApiParam({ name: 'id', description: 'Task ID' })
|
||||
@ApiResponse({ status: 200, description: 'Task found', type: TMTask })
|
||||
@@ -36,6 +40,7 @@ export class TaskController {
|
||||
}
|
||||
|
||||
@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' })
|
||||
@@ -44,6 +49,7 @@ export class TaskController {
|
||||
}
|
||||
|
||||
@Patch(':id')
|
||||
@PermissionsDec(PermissionEnum.TASK)
|
||||
@ApiOperation({ summary: 'Update a task' })
|
||||
@ApiParam({ name: 'id', description: 'Task ID' })
|
||||
@ApiResponse({ status: 200, description: 'Task updated', type: TMTask })
|
||||
@@ -53,6 +59,7 @@ export class TaskController {
|
||||
}
|
||||
|
||||
@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 })
|
||||
@@ -63,6 +70,7 @@ export class TaskController {
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@PermissionsDec(PermissionEnum.TASK)
|
||||
@ApiOperation({ summary: 'Delete a task' })
|
||||
@ApiParam({ name: 'id', description: 'Task ID' })
|
||||
@ApiResponse({ status: 200, description: 'Task deleted' })
|
||||
|
||||
@@ -5,18 +5,39 @@ import { TMTask } from "../entities/task.entity";
|
||||
|
||||
@Injectable()
|
||||
export class TaskRepository extends Repository<TMTask> {
|
||||
constructor(
|
||||
@InjectRepository(TMTask) taskRepository: Repository<TMTask>,
|
||||
) {
|
||||
super(taskRepository.target, taskRepository.manager, taskRepository.queryRunner)
|
||||
constructor(@InjectRepository(TMTask) taskRepository: Repository<TMTask>) {
|
||||
super(taskRepository.target, taskRepository.manager, taskRepository.queryRunner);
|
||||
}
|
||||
|
||||
async getTaskDetail(taskId: string): Promise<TMTask | null> {
|
||||
return this.createQueryBuilder('task')
|
||||
.leftJoinAndSelect('task.remarks', 'remark')
|
||||
.leftJoinAndSelect('task.attachments', 'attachment')
|
||||
.leftJoinAndSelect('task.checkListItems', 'checkListItem')
|
||||
.where('task.id = :taskId', {taskId})
|
||||
.getOne();
|
||||
return this.createQueryBuilder("task")
|
||||
.leftJoinAndSelect("task.remarks", "remark")
|
||||
.leftJoinAndSelect("task.attachments", "attachment")
|
||||
.leftJoinAndSelect("task.checkListItems", "checkListItem")
|
||||
.leftJoinAndSelect("task.users", "user")
|
||||
|
||||
.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",
|
||||
WORKSPACE="workspace",
|
||||
PROJECT="project",
|
||||
TASK_PHASE="task_phase"
|
||||
TASK_PHASE="task_phase",
|
||||
TASK="task"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user