Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions backend/src/reports/relatorios/dto/filter-relatorio-v2.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { ApiProperty } from '@nestjs/swagger';
import { FonteRelatorio, RelatorioVisibilidade, TipoRelatorio } from '@prisma/client';
import { Transform, TransformFnParams } from 'class-transformer';
import { IsDateString, IsEnum, IsInt, IsOptional, IsString, Max, Min } from 'class-validator';

export class FilterRelatorioV2Dto {
@IsOptional()
@ApiProperty({ description: 'ID do PDM para filtrar relatórios', required: false })
@IsInt()
@Transform(({ value }: TransformFnParams) => (value === '' || value == null ? undefined : +value))
pdm_id?: number;

@IsOptional()
@ApiProperty({ enum: FonteRelatorio, enumName: 'FonteRelatorio' })
@IsEnum(FonteRelatorio)
fonte?: FonteRelatorio;

@IsOptional()
@ApiProperty({ enum: TipoRelatorio, enumName: 'TipoRelatorio' })
@IsEnum(TipoRelatorio)
tipo?: TipoRelatorio;

@IsOptional()
@ApiProperty({ enum: RelatorioVisibilidade, enumName: 'RelatorioVisibilidade' })
@IsEnum(RelatorioVisibilidade)
visibilidade?: RelatorioVisibilidade;

@IsOptional()
@IsDateString()
criado_em_de?: string;

@IsOptional()
@IsDateString()
criado_em_ate?: string;
Comment on lines +28 to +34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add API documentation for date fields.

The date fields are missing @ApiProperty decorators for consistency with other fields and proper API documentation.

Apply this diff to add API documentation:

 @IsOptional()
+@ApiProperty({ description: 'Data de criação inicial (ISO string)', required: false })
 @IsDateString()
 criado_em_de?: string;

 @IsOptional()
+@ApiProperty({ description: 'Data de criação final (ISO string)', required: false })
 @IsDateString()
 criado_em_ate?: string;

Consider adding business logic validation to ensure criado_em_de <= criado_em_ate in the service layer.

🤖 Prompt for AI Agents
In backend/src/reports/relatorios/dto/filter-relatorio-v2.dto.ts around lines 27
to 33, the date fields criado_em_de and criado_em_ate lack @ApiProperty
decorators, which are needed for consistent API documentation. Add @ApiProperty
decorators above each date field with appropriate descriptions and example
values. Additionally, implement business logic validation in the service layer
to ensure that criado_em_de is less than or equal to criado_em_ate.


@IsOptional()
@IsString()
token_paginacao?: string;
Comment on lines +36 to +38
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add API documentation for pagination token.

The pagination token field is missing @ApiProperty decorator for consistency and proper API documentation.

Apply this diff to add API documentation:

 @IsOptional()
+@ApiProperty({ description: 'Token de paginação JWT para continuação', required: false })
 @IsString()
 token_paginacao?: string;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@IsOptional()
@IsString()
token_paginacao?: string;
@IsOptional()
@ApiProperty({ description: 'Token de paginação JWT para continuação', required: false })
@IsString()
token_paginacao?: string;
🤖 Prompt for AI Agents
In backend/src/reports/relatorios/dto/filter-relatorio-v2.dto.ts around lines 35
to 37, the token_paginacao field lacks the @ApiProperty decorator, which is
needed for consistent and complete API documentation. Add the @ApiProperty
decorator above the token_paginacao declaration, specifying that the field is
optional and describing its purpose as the pagination token.


@IsOptional()
@IsInt()
@Min(1)
@Transform((a: TransformFnParams) => (a.value === '' ? 1 : +a.value))
pagina?: number = 1;

@IsOptional()
@IsInt()
@Max(500)
@Min(1)
@Transform((a: TransformFnParams) => (a.value === '' ? 25 : +a.value))
ipp?: number = 25;
Comment on lines +40 to +51
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add API documentation and clarify default value handling.

The pagination parameters need improvements:

  1. Missing API documentation: Add @ApiProperty decorators
  2. Redundant default values: Property defaults (= 1, = 25) are redundant since the transform functions handle defaults

Apply this diff to improve the implementation:

 @IsOptional()
+@ApiProperty({ description: 'Número da página', minimum: 1, default: 1, required: false })
 @IsInt()
 @Min(1)
 @Transform((a: TransformFnParams) => (a.value === '' ? 1 : +a.value))
-pagina?: number = 1;
+pagina?: number;

 @IsOptional()
+@ApiProperty({ description: 'Itens por página', minimum: 1, maximum: 500, default: 25, required: false })
 @IsInt()
 @Max(500)
 @Min(1)
 @Transform((a: TransformFnParams) => (a.value === '' ? 25 : +a.value))
-ipp?: number = 25;
+ipp?: number;

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In backend/src/reports/relatorios/dto/filter-relatorio-v2.dto.ts lines 39 to 50,
add @ApiProperty decorators to the pagination parameters 'pagina' and 'ipp' to
provide API documentation. Remove the redundant default value assignments (= 1
and = 25) from these properties since the @Transform functions already handle
default values when the input is an empty string.

}
21 changes: 21 additions & 0 deletions backend/src/reports/relatorios/reports.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import { CreateReportDto } from './dto/create-report.dto';
import { FilterRelatorioDto } from './dto/filter-relatorio.dto';
import { RelatorioDto } from './entities/report.entity';
import { ReportsService } from './reports.service';
import { PaginatedWithPagesDto } from '../../common/dto/paginated.dto';
import { ApiPaginatedWithPagesResponse } from '../../auth/decorators/paginated.decorator';
import { FilterRelatorioV2Dto } from './dto/filter-relatorio-v2.dto';

@ApiTags('Relatórios')
@Controller('relatorios')
Expand Down Expand Up @@ -82,4 +85,22 @@ export class ReportsController {
await this.reportsService.syncRelatoriosParametros();
return '';
}

@ApiBearerAuth('access-token')
@Get('v2')
@Roles([
'Reports.executar.CasaCivil',
'Reports.executar.PDM',
'Reports.executar.Projetos',
'Reports.executar.MDO',
'Reports.executar.PlanoSetorial',
'Reports.executar.ProgramaDeMetas',
])
@ApiPaginatedWithPagesResponse(RelatorioDto) // New decorator for counted pagination
async findAllV2(
@Query() filters: FilterRelatorioV2Dto, // Use the new DTO
@CurrentUser() user: PessoaFromJwt
): Promise<PaginatedWithPagesDto<RelatorioDto>> { // Use the new response type
return await this.reportsService.findAllV2(filters, user);
}
}
Loading