Skip to content
Merged

fix #68

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
2 changes: 1 addition & 1 deletion src/users/api/search.adjacent.users.query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@ export class SearchAdjacentUsersQuery extends OmitType(
) {
@IsRange()
@IsOptional()
@ApiProperty({ name: "age", type: "string", pattern: "^(\\d)-(\\d)$", required: false })
@ApiProperty({ name: "age", type: "string", pattern: "^(\\d+),(\\d+)$", required: false })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To maintain consistency with the suggested change in the IsRange decorator's validation regex, this ApiProperty pattern should also be updated to allow for optional whitespace around the comma. This ensures the API documentation accurately reflects the validation logic.

Suggested change
@ApiProperty({ name: "age", type: "string", pattern: "^(\\d+),(\\d+)$", required: false })
@ApiProperty({ name: "age", type: "string", pattern: "^(\\d+)\\s*,\\s*(\\d+)$", required: false })

age?: [number, number];
}
2 changes: 1 addition & 1 deletion src/users/dto/search.users.filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class SearchUsersFilters {
@IsNumber({}, { each: true })
@IsRange()
@IsOptional()
@ApiProperty({ type: "string", pattern: "^(\\d)-(\\d)$", required: false })
@ApiProperty({ type: "string", pattern: "^(\\d+),(\\d+)$", required: false })

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

To maintain consistency with the suggested change in the IsRange decorator's validation regex, this ApiProperty pattern should also be updated to allow for optional whitespace around the comma. This ensures the API documentation accurately reflects the validation logic.

Suggested change
@ApiProperty({ type: "string", pattern: "^(\\d+),(\\d+)$", required: false })
@ApiProperty({ type: "string", pattern: "^(\\d+)\\s*,\\s*(\\d+)$", required: false })

experience?: RangeObject;

@ArrayMinSize(1)
Expand Down
4 changes: 2 additions & 2 deletions src/utils/decorator/is-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ function __IsRange(validationOptions?: ValidationOptions) {

export function IsRange (options?: ValidationOptions) {
return applyDecorators(
Matches(/^(\d+)-(\d+)$/),
Matches(/^(\d+),(\d+)$/),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

The s.trim() call on line 26 suggests that whitespace around the comma is expected, but the current regex ^(\d+),(\d+)$ doesn't allow it. This makes the .trim() call redundant. To make the validation more robust and align with the transformation logic, consider allowing optional whitespace in the regex.

Suggested change
Matches(/^(\d+),(\d+)$/),
Matches(/^(\d+)\s*,\s*(\d+)$/),

Transform(({ value }) =>
value && value.split('-')
value && value.split(',')
.map(s => Number(s.trim()))
),
__IsRange(options),
Expand Down