Skip to content

Commit

Permalink
Merge pull request #8725 from ever-co/feat/find-tasks-with-advanced-f…
Browse files Browse the repository at this point in the history
…iltering

[Feature] Find Tasks with advanced filtering
  • Loading branch information
rahul-rocket authored Jan 11, 2025
2 parents baff084 + 10b7a30 commit 11d59aa
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 58 deletions.
37 changes: 23 additions & 14 deletions packages/contracts/src/lib/task.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,26 +89,13 @@ export interface IGetTaskById {
includeRootEpic?: boolean;
}

export interface IGetTasksByViewFilters extends IBasePerTenantAndOrganizationEntityModel {
projects?: ID[];
teams?: ID[];
modules?: ID[];
sprints?: ID[];
members?: ID[];
tags?: ID[];
statusIds?: ID[];
export interface IGetTasksByViewFilters extends IBasePerTenantAndOrganizationEntityModel, ITaskAdvancedFilter {
statuses?: TaskStatusEnum[];
priorityIds?: ID[];
priorities?: TaskPriorityEnum[];
sizeIds?: ID[];
sizes?: TaskSizeEnum[];
types?: TaskTypeEnum[];
startDates?: Date[];
dueDates?: Date[];
creators?: ID[];

// Relations
relations?: string[];
}

export interface ITaskDateFilterInput
Expand All @@ -122,3 +109,25 @@ export interface ITaskDateFilterInput
dueDateFrom?: Date;
dueDateTo?: Date;
}

export interface ITaskAdvancedFilter {
projects?: ID[];
teams?: ID[];
modules?: ID[];
sprints?: ID[];
members?: ID[];
tags?: ID[];
statusIds?: ID[];
priorityIds?: ID[];
sizeIds?: ID[];
parentIds?: ID[];
creators?: ID[];
dailyPlans?: ID[];

// Relations
relations?: string[];
}

export interface IAdvancedTaskFiltering {
filters?: ITaskAdvancedFilter;
}
1 change: 1 addition & 0 deletions packages/core/src/lib/tasks/dto/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './task-max-number-query.dto';
export * from './update-task.dto';
export * from './get-task-by-id.dto';
export * from './get-task-by-date-filter.dto';
export * from './task-advanced-filter.dto';
82 changes: 82 additions & 0 deletions packages/core/src/lib/tasks/dto/task-advanced-filter.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { ArrayMaxSize, IsArray, IsOptional, IsUUID } from 'class-validator';
import { ID, ITaskAdvancedFilter } from '@gauzy/contracts';

export class TaskAdvancedFilterDTO implements ITaskAdvancedFilter {
@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
projects?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
teams?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
modules?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
sprints?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
members?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
tags?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
statusIds?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
priorityIds?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
sizeIds?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
parentIds?: ID[] = [];

@ApiPropertyOptional({ type: Array })
@IsOptional()
@IsArray()
@ArrayMaxSize(25)
@IsUUID('all', { each: true })
creators?: ID[] = [];
}
31 changes: 24 additions & 7 deletions packages/core/src/lib/tasks/task.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,14 @@ import { CrudController, PaginationParams } from './../core/crud';
import { Task } from './task.entity';
import { TaskService } from './task.service';
import { TaskCreateCommand, TaskUpdateCommand } from './commands';
import { CreateTaskDTO, GetTaskByIdDTO, TaskDateFilterInputDTO, TaskMaxNumberQueryDTO, UpdateTaskDTO } from './dto';
import {
CreateTaskDTO,
GetTaskByIdDTO,
TaskAdvancedFilterDTO,
TaskDateFilterInputDTO,
TaskMaxNumberQueryDTO,
UpdateTaskDTO
} from './dto';

@ApiTags('Tasks')
@UseGuards(TenantPermissionGuard, PermissionGuard)
Expand Down Expand Up @@ -62,7 +69,9 @@ export class TaskController extends CrudController<Task> {
@ApiOperation({ summary: 'Get tasks by pagination.' })
@ApiResponse({ status: HttpStatus.OK, description: 'Tasks retrieved successfully.' })
@ApiResponse({ status: HttpStatus.BAD_REQUEST, description: 'Invalid input.' })
async pagination(@Query() params: PaginationParams<Task>): Promise<IPagination<ITask>> {
async pagination(
@Query() params: PaginationParams<Task> & { filters?: TaskAdvancedFilterDTO }
): Promise<IPagination<ITask>> {
return this.taskService.pagination(params);
}

Expand Down Expand Up @@ -110,7 +119,9 @@ export class TaskController extends CrudController<Task> {
@Permissions(PermissionsEnum.ALL_ORG_VIEW, PermissionsEnum.ORG_TASK_VIEW)
@Get('/employee')
@UseValidationPipe({ transform: true })
async findEmployeeTask(@Query() params: PaginationParams<Task>): Promise<IPagination<ITask>> {
async findEmployeeTask(
@Query() params: PaginationParams<Task> & { filters?: TaskAdvancedFilterDTO }
): Promise<IPagination<ITask>> {
return this.taskService.getEmployeeTasks(params);
}

Expand All @@ -126,7 +137,9 @@ export class TaskController extends CrudController<Task> {
@Permissions(PermissionsEnum.ALL_ORG_VIEW, PermissionsEnum.ORG_TASK_VIEW)
@Get('/team')
@UseValidationPipe({ transform: true })
async findTeamTasks(@Query() params: PaginationParams<Task>): Promise<IPagination<ITask>> {
async findTeamTasks(
@Query() params: PaginationParams<Task> & { filters?: TaskAdvancedFilterDTO }
): Promise<IPagination<ITask>> {
return this.taskService.findTeamTasks(params);
}

Expand All @@ -142,7 +155,9 @@ export class TaskController extends CrudController<Task> {
@Permissions(PermissionsEnum.ALL_ORG_VIEW, PermissionsEnum.ORG_TASK_VIEW)
@Get('/module')
@UseValidationPipe({ transform: true })
async findModuleTasks(@Query() params: PaginationParams<Task>): Promise<IPagination<ITask>> {
async findModuleTasks(
@Query() params: PaginationParams<Task> & { filters?: TaskAdvancedFilterDTO }
): Promise<IPagination<ITask>> {
return this.taskService.findModuleTasks(params);
}

Expand Down Expand Up @@ -209,7 +224,7 @@ export class TaskController extends CrudController<Task> {
@UseValidationPipe()
async getAllTasksByEmployee(
@Param('id') employeeId: ID,
@Query() params: PaginationParams<Task>
@Query() params: PaginationParams<Task> & { filters?: TaskAdvancedFilterDTO }
): Promise<ITask[]> {
return this.taskService.getAllTasksByEmployee(employeeId, params);
}
Expand All @@ -226,7 +241,9 @@ export class TaskController extends CrudController<Task> {
@Permissions(PermissionsEnum.ALL_ORG_VIEW, PermissionsEnum.ORG_TASK_VIEW)
@Get('/')
@UseValidationPipe()
async findAll(@Query() params: PaginationParams<Task>): Promise<IPagination<ITask>> {
async findAll(
@Query() params: PaginationParams<Task> & { filters?: TaskAdvancedFilterDTO }
): Promise<IPagination<ITask>> {
return this.taskService.findAll(params);
}

Expand Down
Loading

0 comments on commit 11d59aa

Please sign in to comment.