refactor: changed the getUserProjects to get projects in a specific workspace
This commit is contained in:
@@ -920,11 +920,13 @@ export const enum WorkSpaceMessage {
|
|||||||
WORKSPACE_EXISTS = "فضای کار با این اسم وجود دارد!",
|
WORKSPACE_EXISTS = "فضای کار با این اسم وجود دارد!",
|
||||||
WORKSPACE_NOT_FOUND = "فضای کار مورد نظر شما وجود ندارد!",
|
WORKSPACE_NOT_FOUND = "فضای کار مورد نظر شما وجود ندارد!",
|
||||||
USERS_DONT_BELONG_TO_THIS_WORKSPACE = "کاربران تعیین شده برای این فضای کاری نیستند!",
|
USERS_DONT_BELONG_TO_THIS_WORKSPACE = "کاربران تعیین شده برای این فضای کاری نیستند!",
|
||||||
WORKSPACE_SAME_NAME_EXISTS = "فضای کاری با این اسم از قبل وجود دارد!"
|
WORKSPACE_SAME_NAME_EXISTS = "فضای کاری با این اسم از قبل وجود دارد!",
|
||||||
|
WORKSPACE_ID_PARAM_NOT_EMPTY = "پارامتر شناسه فضای کار نباید خالی باشد!",
|
||||||
|
WORKSPACE_ID_UUID = "شناسه فضای کار باید uuid باشد"
|
||||||
}
|
}
|
||||||
|
|
||||||
export const enum ProjectMessage {
|
export const enum ProjectMessage {
|
||||||
PROJECT_EXISTS = "پروژه مورد نظر شما از قبل وجود دارد!",
|
PROJECT_EXISTS = "پروژه مورد نظر شما از قبل وجود دارد!",
|
||||||
PROJECT_NOT_FOUND = "پروژه مورد نظر شما وجود ندارد!",
|
PROJECT_NOT_FOUND = "پروژه مورد نظر شما وجود ندارد!",
|
||||||
PROJECT_CONTAINS_TASK_PHASES = "پروژه شامل فاز تسک است. لطفا ابتدا فاز تسک های این پروژه را حذف کنید."
|
PROJECT_CONTAINS_TASK_PHASES = "پروژه شامل فاز تسک است. لطفا ابتدا فاز تسک های این پروژه را حذف کنید.",
|
||||||
}
|
}
|
||||||
@@ -10,6 +10,7 @@ import { PermissionsDec } from "../../../common/decorators/permission.decorator"
|
|||||||
import { PermissionEnum } from "../../users/enums/permission.enum";
|
import { PermissionEnum } from "../../users/enums/permission.enum";
|
||||||
import { UserDec } from "../../../common/decorators/user.decorator";
|
import { UserDec } from "../../../common/decorators/user.decorator";
|
||||||
import { AuthGuards } from "../../../common/decorators/auth-guard.decorator";
|
import { AuthGuards } from "../../../common/decorators/auth-guard.decorator";
|
||||||
|
import { ParamDto } from "../../../common/DTO/param.dto";
|
||||||
|
|
||||||
@AuthGuards()
|
@AuthGuards()
|
||||||
@AdminRoute()
|
@AdminRoute()
|
||||||
@@ -67,13 +68,15 @@ export class ProjectController {
|
|||||||
return this.projectService.remove(id);
|
return this.projectService.remove(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get("/user")
|
@Get("/user/workspace/:id")
|
||||||
@ApiOperation({ summary: "Get user projects!" })
|
@ApiOperation({ summary: "Get user projects!" })
|
||||||
@ApiResponse({ status: 200, description: "Got user projects successfully!" })
|
@ApiResponse({ status: 200, description: "Got user projects successfully!" })
|
||||||
|
@ApiResponse({status: 400, description: "Bad Request!"})
|
||||||
findUserProjects(
|
findUserProjects(
|
||||||
@UserDec("id") userId: string,
|
@UserDec("id") userId: string,
|
||||||
|
@Param() paramDto : ParamDto,
|
||||||
@Query() pagination: PaginationDto,
|
@Query() pagination: PaginationDto,
|
||||||
): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
|
): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
|
||||||
return this.projectService.findUserProjects(userId, pagination);
|
return this.projectService.findUserProjects(userId, paramDto.id, pagination);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,12 +124,12 @@ export class ProjectService {
|
|||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
async findUserProjects(userId: string, pagination: PaginationDto): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
|
async findUserProjects(userId: string, wsId: string, pagination: PaginationDto): Promise<{ projects: TMProject[]; count: number; paginate: true }> {
|
||||||
const page = pagination.page ?? 1;
|
const page = pagination.page ?? 1;
|
||||||
const limit = pagination.limit ?? 10;
|
const limit = pagination.limit ?? 10;
|
||||||
const skip = (page - 1) * limit;
|
const skip = (page - 1) * limit;
|
||||||
|
|
||||||
const [projects, count] = await this.projectRepository.findUserProjects(userId, skip, limit);
|
const [projects, count] = await this.projectRepository.findUserProjects(userId, wsId, skip, limit);
|
||||||
|
|
||||||
return { projects, count, paginate: true };
|
return { projects, count, paginate: true };
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,14 @@ export class ProjectRepository extends Repository<TMProject> {
|
|||||||
super(projectRepository.target, projectRepository.manager, projectRepository.queryRunner);
|
super(projectRepository.target, projectRepository.manager, projectRepository.queryRunner);
|
||||||
}
|
}
|
||||||
|
|
||||||
async findUserProjects(userId: string, skip?: number, take?: number): Promise<[TMProject[], number]> {
|
async findUserProjects(userId: string, wsId: string, skip?: number, take?: number): Promise<[TMProject[], number]> {
|
||||||
return this.createQueryBuilder('project')
|
return this.createQueryBuilder('project')
|
||||||
|
.innerJoin('project.workspace', 'workspace')
|
||||||
.innerJoin('project.users', 'user')
|
.innerJoin('project.users', 'user')
|
||||||
.where('user.id = :userId', {userId})
|
.where('workspace.id = :wsId', {wsId})
|
||||||
|
.andWhere('user.id = :userId', {userId})
|
||||||
.skip(skip ?? 0)
|
.skip(skip ?? 0)
|
||||||
.take(take ?? 0)
|
.take(take ?? 10)
|
||||||
.getManyAndCount();
|
.getManyAndCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user