Skip to content

ContextId Changes In List API#7

Merged
Shubham4026 merged 1 commit into
mainfrom
dev-release
May 13, 2026
Merged

ContextId Changes In List API#7
Shubham4026 merged 1 commit into
mainfrom
dev-release

Conversation

@Shubham4026
Copy link
Copy Markdown
Collaborator

No description provided.

@Shubham4026 Shubham4026 merged commit b7e99e9 into main May 13, 2026
1 check failed
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for filtering responses by context IDs in the findAll method. The changes involve updating the controller and service to accept an optional array of context IDs and applying a filter to the database query using TypeORM's In operator. A reviewer recommended migrating the inline request body type to a dedicated DTO to improve type safety and enable validation via class-validator.

public async findAll(
@Req() request: Request,
@Body() body: { page?: number; limit?: number; sortBy?: string; sortOrder?: 'ASC' | 'DESC' },
@Body() body: { page?: number; limit?: number; sortBy?: string; sortOrder?: 'ASC' | 'DESC'; contextIds?: string[] },
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Using an inline type for the request body bypasses the ValidationPipe. This means properties like page, limit, and the new contextIds are not validated for their type or format, which could lead to unexpected errors.

It's recommended to create a dedicated Data Transfer Object (DTO) class for the request body. This allows you to leverage class-validator decorators to enforce type and format constraints.

For example, you could create a ListResponsesDto class:

import { IsOptional, IsInt, IsString, IsIn, IsArray, IsUUID, Min } from 'class-validator';
import { Type } from 'class-transformer';

export class ListResponsesDto {
  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  page?: number;

  @IsOptional()
  @Type(() => Number)
  @IsInt()
  @Min(1)
  limit?: number;

  @IsOptional()
  @IsString()
  sortBy?: string;

  @IsOptional()
  @IsString()
  @IsIn(['ASC', 'DESC'])
  sortOrder?: 'ASC' | 'DESC';

  @IsOptional()
  @IsArray()
  @IsUUID('all', { each: true })
  contextIds?: string[];
}

You can then use this DTO in the controller (@Body() body: ListResponsesDto) and in the service (pagination: ListResponsesDto) for better type safety and validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant