Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(be): apply runtime typecheck on create-usertest-submission-dto #2238

Merged
merged 3 commits into from
Jan 7, 2025

Conversation

Jaehyeon1020
Copy link
Member

Description

closes TAS-1080

CreateUserTestSubmissionDto에 잘못된 속성 입력(in을 input으로 넣는다던지)에 대한 예외가 발생하지 않는 문제를 해결합니다.

Additional context

  • 원인 - 해결방법

    • 일단 아래와 같이 배열 안에 들어가는 객체에 대한 검사가 되지 않고 있었습니다.
    export class CreateSubmissionDto {
      @ValidateNested({ each: true })
      @Type(() => Snippet)
      code: Snippet[]
    
      @IsEnum(Language)
      @IsNotEmpty()
      language: Language
    }
    
    export class CreateUserTestSubmissionDto extends CreateSubmissionDto {
      @IsNotEmpty()
      userTestcases: { id: number; in: string; out: string }[]
    }
    • 그래서 아래와 같이 고쳤는데, 그래도 객체 내의 속성들에 대한 검사가 작동하지 않았습니다.
    export class CreateSubmissionDto {
      @ValidateNested({ each: true })
      @Type(() => Snippet)
      code: Snippet[]
    
      @IsEnum(Language)
      @IsNotEmpty()
      language: Language
    }
    
    export class CreateUserTestSubmissionDto extends CreateSubmissionDto {
      @IsArray()
      @ValidateNested({ each: true })
      @Type(() => UserTestcase)
      userTestcases: UserTestcase[]
    }
    
    export class UserTestcase {
      @IsInt()
      @IsNotEmpty()
      id: number;
    
      @IsString()
      @IsNotEmpty()
      in: string
    
      @IsString()
      @IsNotEmpty()
      out: string
    }
    • 원인은 CreateUserTestSubmissionDto를 import할 때 type으로 가져왔기 때문이었습니다 …

Before submitting the PR, please make sure you do the following

@gyunseo gyunseo requested a review from jspark2000 January 3, 2025 12:35
Copy link
Member

@jspark2000 jspark2000 left a comment

Choose a reason for hiding this comment

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

LGTM!

@Jaehyeon1020 Jaehyeon1020 merged commit 517ed9b into main Jan 7, 2025
8 checks passed
@Jaehyeon1020 Jaehyeon1020 deleted the t1080-apply-class-validator-on-user-tc branch January 7, 2025 12:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants