feat: added getTaskDetail API
This commit is contained in:
@@ -939,5 +939,6 @@ export const enum TaskPhaseMessage {
|
||||
|
||||
export const enum TaskMessage {
|
||||
TASK_NOT_FOUND = "تسک مورد نظر پیدا نشد!",
|
||||
USERS_ASSIGNED_TO_TASK_NOT_PROJECT_MEMBER = "حداقل یکی از کاربران تعیین شده عضو پروژه نیستند!"
|
||||
USERS_ASSIGNED_TO_TASK_NOT_PROJECT_MEMBER = "حداقل یکی از کاربران تعیین شده عضو پروژه نیستند!",
|
||||
USER_NOT_TASK_MEMBER = "شما عضو این تسک نیستید!"
|
||||
}
|
||||
@@ -5,7 +5,13 @@ 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';
|
||||
|
||||
@AuthGuards()
|
||||
@AdminRoute()
|
||||
@ApiTags('Task Manager - Tasks')
|
||||
@Controller('task-manager/tasks')
|
||||
export class TaskController {
|
||||
@@ -64,4 +70,16 @@ export class TaskController {
|
||||
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('id') userId: string,
|
||||
@Param() paramDto: ParamDto
|
||||
): Promise<TMTask | null> {
|
||||
return this.taskService.getTaskDetail(userId, paramDto.id);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { BadRequestException, ForbiddenException, Injectable, NotFoundException } from "@nestjs/common";
|
||||
import { InjectRepository } from "@nestjs/typeorm";
|
||||
import { In, Repository } from "typeorm";
|
||||
import { TaskRepository } from "../repositories/task.repository";
|
||||
@@ -35,6 +35,7 @@ export class TaskService {
|
||||
where: { id },
|
||||
relations: {
|
||||
taskPhase: true,
|
||||
users: true
|
||||
},
|
||||
});
|
||||
if (!task) throw new NotFoundException(TaskMessage.TASK_NOT_FOUND);
|
||||
@@ -123,4 +124,14 @@ export class TaskService {
|
||||
await this.findOneOrFail(id);
|
||||
await this.taskRepository.delete(id);
|
||||
}
|
||||
|
||||
async getTaskDetail(userId: string, taskId: string): Promise<TMTask | null> {
|
||||
const task = await this.findOneOrFail(taskId);
|
||||
|
||||
const isTaskMember = task.users.some((user) => user.id === userId);
|
||||
if(!isTaskMember) throw new ForbiddenException(TaskMessage.USER_NOT_TASK_MEMBER);
|
||||
|
||||
const taskDetail = await this.taskRepository.getTaskDetail(taskId);
|
||||
return taskDetail;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,4 +10,13 @@ export class TaskRepository extends 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();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user