Skip to content
Merged

fix #67

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
6 changes: 3 additions & 3 deletions src/users/dto/search.users.filters.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ArrayMinSize, IsInt, IsOptional } from "class-validator";
import { ArrayMinSize, IsInt, IsNumber, IsOptional } from "class-validator";
import { ApiProperty } from "@nestjs/swagger";
import { IsRange } from "../../utils";
import { RangeObject } from "../../utils/range";
Expand All @@ -8,14 +8,14 @@ export class SearchUsersFilters {
birthyear?: RangeObject;

@Transform(({ value }) => value && RangeObject.fromRange(value))
@IsInt({ each: true })
@IsNumber({}, { each: true })
@IsRange()
@IsOptional()
@ApiProperty({ type: "string", pattern: "^(\\d)-(\\d)$", required: false })
experience?: RangeObject;

@ArrayMinSize(1)
@IsInt({ each: true })
@IsNumber({}, { each: true })

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.

high

For consistency and correctness, positionIds should be validated as integers. This property, like techIds and interestIds which still use @IsInt, represents entity identifiers which are typically integers. Using @IsNumber allows for floating-point values, which could lead to unexpected behavior or invalid data. It's recommended to revert this to use @IsInt.

Suggested change
@IsNumber({}, { each: true })
@IsInt({ each: true })

@IsOptional()
@ApiProperty({ type: [Number], minLength: 1, required: false })
positionIds?: number[];
Expand Down
2 changes: 1 addition & 1 deletion src/utils/decorator/is-range.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function __IsRange(validationOptions?: ValidationOptions) {

export function IsRange (options?: ValidationOptions) {
return applyDecorators(
Matches(/^(\d)-(\d)$/),
Matches(/^(\d+)-(\d+)$/),
Transform(({ value }) =>
value && value.split('-')
.map(s => Number(s.trim()))
Expand Down