From 70bb19bd6689f0db160e67ad7e70a9f98df707f8 Mon Sep 17 00:00:00 2001 From: hoseok Date: Mon, 11 Aug 2025 12:15:12 +0900 Subject: [PATCH] fix --- src/users/api/search.adjacent.users.query.ts | 2 +- src/users/dto/search.users.filters.ts | 2 +- src/utils/decorator/index.ts | 1 - src/utils/decorator/is-pair.ts | 10 ---------- src/utils/decorator/is-range.ts | 5 ++--- src/utils/range/range.object.ts | 9 +++++++++ 6 files changed, 13 insertions(+), 16 deletions(-) delete mode 100644 src/utils/decorator/is-pair.ts diff --git a/src/users/api/search.adjacent.users.query.ts b/src/users/api/search.adjacent.users.query.ts index 7b90af5..9cf94c3 100644 --- a/src/users/api/search.adjacent.users.query.ts +++ b/src/users/api/search.adjacent.users.query.ts @@ -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 }) age?: [number, number]; } \ No newline at end of file diff --git a/src/users/dto/search.users.filters.ts b/src/users/dto/search.users.filters.ts index e79eb42..d7b6f85 100644 --- a/src/users/dto/search.users.filters.ts +++ b/src/users/dto/search.users.filters.ts @@ -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 }) experience?: RangeObject; @ArrayMinSize(1) diff --git a/src/utils/decorator/index.ts b/src/utils/decorator/index.ts index ccd6233..3a48f6e 100644 --- a/src/utils/decorator/index.ts +++ b/src/utils/decorator/index.ts @@ -1,3 +1,2 @@ export * from "./http.decorators"; -export * from "./is-pair"; export * from "./is-range"; \ No newline at end of file diff --git a/src/utils/decorator/is-pair.ts b/src/utils/decorator/is-pair.ts deleted file mode 100644 index 3efeacd..0000000 --- a/src/utils/decorator/is-pair.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { applyDecorators } from "@nestjs/common"; -import { ArrayMaxSize, ArrayMinSize, IsArray, ValidationOptions } from "class-validator"; - -export function IsPair(options?: ValidationOptions) { - return applyDecorators( - IsArray(options), - ArrayMinSize(2), - ArrayMaxSize(2) - ); -} \ No newline at end of file diff --git a/src/utils/decorator/is-range.ts b/src/utils/decorator/is-range.ts index fa1ccd9..7266b3f 100644 --- a/src/utils/decorator/is-range.ts +++ b/src/utils/decorator/is-range.ts @@ -1,4 +1,4 @@ -import { Matches, registerDecorator, ValidationArguments, ValidationOptions } from "class-validator"; +import { registerDecorator, ValidationArguments, ValidationOptions } from "class-validator"; import { applyDecorators } from "@nestjs/common"; import { Transform } from "class-transformer"; @@ -20,9 +20,8 @@ function __IsRange(validationOptions?: ValidationOptions) { export function IsRange (options?: ValidationOptions) { return applyDecorators( - Matches(/^(\d+),(\d+)$/), Transform(({ value }) => - value && value.split(',') + value && value.split('-') .map(s => Number(s.trim())) ), __IsRange(options), diff --git a/src/utils/range/range.object.ts b/src/utils/range/range.object.ts index 176f7e4..cca28eb 100644 --- a/src/utils/range/range.object.ts +++ b/src/utils/range/range.object.ts @@ -1,6 +1,15 @@ +import { ApiProperty } from "@nestjs/swagger"; +import { IsNumber, IsOptional } from "class-validator"; export class RangeObject { + @IsNumber() + @IsOptional() + @ApiProperty({ type: "number", required: false }) lower?: number; + + @IsNumber() + @IsOptional() + @ApiProperty({ type: "number", required: false }) upper?: number; static fromRange(range: [number, number]): RangeObject {