From e0944452927b945dea514dd654321ad69b299cb6 Mon Sep 17 00:00:00 2001 From: hobiJeong Date: Fri, 8 Mar 2024 03:08:09 +0900 Subject: [PATCH] refactor(#325): setting constraints with user constant --- .../dtos/mentor-list-page-query.dto.ts | 7 +++- src/mentors/dtos/user-intro-response.dto.ts | 8 ++++ .../dtos/user-with-image-and-intro.dto.ts | 6 +++ src/search/dtos/search-all-mentor.dto.ts | 3 ++ src/search/dtos/search-user-dto.ts | 3 ++ src/users/dtos/create-user.dto.ts | 7 ++-- src/users/dtos/get-my-intro.dto.ts | 20 +++++++++ src/users/dtos/update-user-intro-dto.ts | 41 ++++++++++++++----- src/users/dtos/user-info.dto.ts | 24 +++++++++-- 9 files changed, 101 insertions(+), 18 deletions(-) diff --git a/src/mentors/dtos/mentor-list-page-query.dto.ts b/src/mentors/dtos/mentor-list-page-query.dto.ts index 92988ee3..f596ed4f 100644 --- a/src/mentors/dtos/mentor-list-page-query.dto.ts +++ b/src/mentors/dtos/mentor-list-page-query.dto.ts @@ -1,10 +1,11 @@ import { PageQueryDto } from '@src/common/dto/page-query.dto'; import { SortOrder } from '@src/common/constants/sort-order.enum'; import { ApiPropertyOptional } from '@nestjs/swagger'; -import { IsEnum, IsNotEmpty, IsOptional } from 'class-validator'; +import { IsEnum, IsOptional, Length } from 'class-validator'; import { IsPositiveInt } from '@src/common/decorators/validators/is-positive-int.decorator'; import { MentorOrderField } from '@src/mentors/constants/mentor-order-field.enum'; import { User } from '@src/entities/User'; +import { USER_NAME_LENGTH } from '@src/users/constants/user.constant'; export class MentorListPageQueryDto extends PageQueryDto @@ -20,9 +21,11 @@ export class MentorListPageQueryDto @ApiPropertyOptional({ description: '멘토 이름 필터링', + minLength: USER_NAME_LENGTH.MIN, + maxLength: USER_NAME_LENGTH.MAX, }) @IsOptional() - @IsNotEmpty() + @Length(USER_NAME_LENGTH.MIN, USER_NAME_LENGTH.MAX) name?: string; @ApiPropertyOptional({ diff --git a/src/mentors/dtos/user-intro-response.dto.ts b/src/mentors/dtos/user-intro-response.dto.ts index 0730732d..6109703a 100644 --- a/src/mentors/dtos/user-intro-response.dto.ts +++ b/src/mentors/dtos/user-intro-response.dto.ts @@ -1,16 +1,24 @@ import { ApiProperty } from '@nestjs/swagger'; import { UserIntro } from '@src/entities/UserIntro'; +import { + USER_CUSTOM_CATEGORY_LENGTH, + USER_SHORT_INTRO_LENGTH, +} from '@src/users/constants/user.constant'; export class UserIntroResponseDto implements Pick { @ApiProperty({ description: '멘토 짧은 소개', + minLength: USER_SHORT_INTRO_LENGTH.MIN, + maxLength: USER_SHORT_INTRO_LENGTH.MAX, }) shortIntro: string; @ApiProperty({ description: '멘토 커스텀 카테고리', + minLength: USER_CUSTOM_CATEGORY_LENGTH.MIN, + maxLength: USER_CUSTOM_CATEGORY_LENGTH.MAX, }) customCategory: string; } diff --git a/src/mentors/dtos/user-with-image-and-intro.dto.ts b/src/mentors/dtos/user-with-image-and-intro.dto.ts index 6d1629e4..14fa6e13 100644 --- a/src/mentors/dtos/user-with-image-and-intro.dto.ts +++ b/src/mentors/dtos/user-with-image-and-intro.dto.ts @@ -2,6 +2,7 @@ import { ApiProperty, PickType } from '@nestjs/swagger'; import { Exclude } from 'class-transformer'; import { UserForJoinDto } from '@src/users/dtos/user-for-join.dto'; import { UserIntroResponseDto } from '@src/mentors/dtos/user-intro-response.dto'; +import { USER_NAME_LENGTH } from '@src/users/constants/user.constant'; export class UserWithImageAndIntroDto extends PickType(UserForJoinDto, [ 'userImage', @@ -14,6 +15,8 @@ export class UserWithImageAndIntroDto extends PickType(UserForJoinDto, [ @ApiProperty({ description: '유저 이름', + minLength: USER_NAME_LENGTH.MIN, + maxLength: USER_NAME_LENGTH.MAX, }) name: string; @@ -22,6 +25,7 @@ export class UserWithImageAndIntroDto extends PickType(UserForJoinDto, [ @ApiProperty({ description: '유저 랭크', + format: 'integer', }) rank: number; @@ -32,11 +36,13 @@ export class UserWithImageAndIntroDto extends PickType(UserForJoinDto, [ @ApiProperty({ description: '멘토 리뷰 후기 당한 개수', + format: 'integer', }) mentorReviewCount: number; @ApiProperty({ description: '멘토 게시판 글쓴 갯수', + format: 'integer', }) mentorBoardCount: number; diff --git a/src/search/dtos/search-all-mentor.dto.ts b/src/search/dtos/search-all-mentor.dto.ts index 4817ee91..ce5b4cfe 100644 --- a/src/search/dtos/search-all-mentor.dto.ts +++ b/src/search/dtos/search-all-mentor.dto.ts @@ -2,6 +2,7 @@ import { ApiProperty } from '@nestjs/swagger'; import { User } from '@src/entities/User'; import { UserImage } from '@src/entities/UserImage'; import { UserIntro } from '@src/entities/UserIntro'; +import { USER_NAME_LENGTH } from '@src/users/constants/user.constant'; export class SearchAllMentorDto implements Pick @@ -13,6 +14,8 @@ export class SearchAllMentorDto @ApiProperty({ description: '멘토 유저 이름', + minLength: USER_NAME_LENGTH.MIN, + maxLength: USER_NAME_LENGTH.MAX, }) name: string; diff --git a/src/search/dtos/search-user-dto.ts b/src/search/dtos/search-user-dto.ts index 5001e762..6c693516 100644 --- a/src/search/dtos/search-user-dto.ts +++ b/src/search/dtos/search-user-dto.ts @@ -1,6 +1,7 @@ import { ApiProperty } from '@nestjs/swagger'; import { User } from '@src/entities/User'; import { UserImage } from '@src/entities/UserImage'; +import { USER_NAME_LENGTH } from '@src/users/constants/user.constant'; export class SearchUserDto implements Pick { @ApiProperty({ @@ -11,6 +12,8 @@ export class SearchUserDto implements Pick { @ApiProperty({ description: '작성자 이름', + minLength: USER_NAME_LENGTH.MIN, + maxLength: USER_NAME_LENGTH.MAX, }) name: string; diff --git a/src/users/dtos/create-user.dto.ts b/src/users/dtos/create-user.dto.ts index 124ff05d..11cc4c3d 100644 --- a/src/users/dtos/create-user.dto.ts +++ b/src/users/dtos/create-user.dto.ts @@ -1,9 +1,10 @@ +import { UserProvider } from '@src/auth/enums/user-provider.enum'; import { UserRole } from '@src/users/constants/user-role.enum'; -import { IsBoolean, IsEmail, IsString } from 'class-validator'; +import { IsBoolean, IsEmail, IsEnum, IsString } from 'class-validator'; export class CreateUserDto { - @IsString() - readonly provider: string; + @IsEnum(UserProvider) + readonly provider: UserProvider; @IsString() readonly name: string; diff --git a/src/users/dtos/get-my-intro.dto.ts b/src/users/dtos/get-my-intro.dto.ts index 71922db0..09aa63d8 100644 --- a/src/users/dtos/get-my-intro.dto.ts +++ b/src/users/dtos/get-my-intro.dto.ts @@ -1,5 +1,13 @@ import { ApiProperty } from '@nestjs/swagger'; import { UserIntro } from '@src/entities/UserIntro'; +import { + USER_CAREER_LENGTH, + USER_CUSTOM_CATEGORY_LENGTH, + USER_DETAIL_LENGTH, + USER_PORTFOLIO_LENGTH, + USER_SHORT_INTRO_LENGTH, + USER_SNS_LENGTH, +} from '@src/users/constants/user.constant'; import { Exclude } from 'class-transformer'; export class MyIntroDto implements Omit { @@ -11,31 +19,43 @@ export class MyIntroDto implements Omit { @ApiProperty({ description: '커스텀 카테고리', + minLength: USER_CUSTOM_CATEGORY_LENGTH.MIN, + maxLength: USER_CUSTOM_CATEGORY_LENGTH.MAX, }) customCategory: string; @ApiProperty({ description: '한 줄 소개', + minLength: USER_SHORT_INTRO_LENGTH.MIN, + maxLength: USER_SHORT_INTRO_LENGTH.MAX, }) shortIntro: string; @ApiProperty({ description: '경력', + minLength: USER_CAREER_LENGTH.MIN, + maxLength: USER_CAREER_LENGTH.MAX, }) career: string; @ApiProperty({ description: '세부 사항', + minLength: USER_DETAIL_LENGTH.MIN, + maxLength: USER_DETAIL_LENGTH.MAX, }) detail: string; @ApiProperty({ description: '포트폴리오', + minLength: USER_PORTFOLIO_LENGTH.MIN, + maxLength: USER_PORTFOLIO_LENGTH.MAX, }) portfolio: string; @ApiProperty({ description: 'SNS', + minLength: USER_SNS_LENGTH.MIN, + maxLength: USER_SNS_LENGTH.MAX, }) sns: string; diff --git a/src/users/dtos/update-user-intro-dto.ts b/src/users/dtos/update-user-intro-dto.ts index 0ea6f806..b1e02b7a 100644 --- a/src/users/dtos/update-user-intro-dto.ts +++ b/src/users/dtos/update-user-intro-dto.ts @@ -1,54 +1,75 @@ -import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger'; -import { IsBoolean, IsNumber, IsOptional, IsString } from 'class-validator'; +import { ApiPropertyOptional } from '@nestjs/swagger'; +import { IsPositiveInt } from '@src/common/decorators/validators/is-positive-int.decorator'; +import { + USER_CAREER_LENGTH, + USER_CUSTOM_CATEGORY_LENGTH, + USER_DETAIL_LENGTH, + USER_PORTFOLIO_LENGTH, + USER_SHORT_INTRO_LENGTH, + USER_SNS_LENGTH, +} from '@src/users/constants/user.constant'; +import { IsBoolean, IsOptional, Length } from 'class-validator'; export class UpdateUserIntroDTO { @ApiPropertyOptional({ example: '안녕하세요', description: '한 줄 소개', + minLength: USER_SHORT_INTRO_LENGTH.MIN, + maxLength: USER_SHORT_INTRO_LENGTH.MAX, }) @IsOptional() - @IsString() + @Length(USER_SHORT_INTRO_LENGTH.MIN, USER_SHORT_INTRO_LENGTH.MAX) shortIntro?: string; @ApiPropertyOptional({ example: '숨쉬기 경력 20년', description: '경력', + minLength: USER_CAREER_LENGTH.MIN, + maxLength: USER_CAREER_LENGTH.MAX, }) @IsOptional() - @IsString() + @Length(USER_CAREER_LENGTH.MIN, USER_CAREER_LENGTH.MAX) career?: string; @ApiPropertyOptional({ example: '코로 숨쉬기, 입으로 숨쉬기', description: '커스텀 카테고리', + minLength: USER_CUSTOM_CATEGORY_LENGTH.MIN, + maxLength: USER_CUSTOM_CATEGORY_LENGTH.MAX, }) @IsOptional() - @IsString() + @Length(USER_CUSTOM_CATEGORY_LENGTH.MIN, USER_CUSTOM_CATEGORY_LENGTH.MAX) customCategory?: string; @ApiPropertyOptional({ example: '안녕하세요. 저는 트위치에서 방송을 하고 있는 스트리머 케인입니다.', description: '상세 소개(옵션)', + minLength: USER_DETAIL_LENGTH.MIN, + maxLength: USER_DETAIL_LENGTH.MAX, }) @IsOptional() - @IsString() + @Length(USER_DETAIL_LENGTH.MIN, USER_DETAIL_LENGTH.MAX) detail?: string; @ApiPropertyOptional({ example: 'https://www.naver.com', description: '포트폴리오 링크', + minLength: USER_PORTFOLIO_LENGTH.MIN, + maxLength: USER_PORTFOLIO_LENGTH.MAX, }) @IsOptional() - @IsString() + @Length(USER_PORTFOLIO_LENGTH.MIN, USER_PORTFOLIO_LENGTH.MAX) portfolio?: string; @ApiPropertyOptional({ example: 'https://www.naver.com', description: 'sns 링크', + minLength: USER_SNS_LENGTH.MIN, + maxLength: USER_SNS_LENGTH.MAX, }) @IsOptional() - @IsString() + @Length(USER_SNS_LENGTH.MIN, USER_SNS_LENGTH.MAX) sns?: string; @ApiPropertyOptional({ @@ -56,7 +77,7 @@ export class UpdateUserIntroDTO { description: '희망 카테고리 id', }) @IsOptional() - @IsNumber() + @IsPositiveInt() hopeCategoryId?: number; @ApiPropertyOptional({ @@ -64,7 +85,7 @@ export class UpdateUserIntroDTO { description: '활동 카테고리 id', }) @IsOptional() - @IsNumber() + @IsPositiveInt() activityCategoryId?: number; @ApiPropertyOptional({ diff --git a/src/users/dtos/user-info.dto.ts b/src/users/dtos/user-info.dto.ts index 98ac7e43..8f0b1936 100644 --- a/src/users/dtos/user-info.dto.ts +++ b/src/users/dtos/user-info.dto.ts @@ -4,6 +4,10 @@ import { UserStatus } from '@src/users/constants/user-status.enum'; import { UserProvider } from '@src/auth/enums/user-provider.enum'; import { UserRole } from '@src/users/constants/user-role.enum'; import { User } from '@src/entities/User'; +import { + USER_EMAIL_LENGTH, + USER_NAME_LENGTH, +} from '@src/users/constants/user.constant'; export class UserInfoDto implements @@ -33,16 +37,23 @@ export class UserInfoDto { @ApiProperty({ description: '유저 아이디', + format: 'integer', + minLength: 1, }) id: number; @ApiProperty({ - description: '이름', + description: '유저 이름', + minLength: USER_NAME_LENGTH.MIN, + maxLength: USER_NAME_LENGTH.MAX, }) name: string; @ApiProperty({ - description: '이메일', + description: '유저 이메일', + format: 'email', + minLength: USER_EMAIL_LENGTH.MIN, + maxLength: USER_EMAIL_LENGTH.MAX, }) email: string; @@ -59,22 +70,29 @@ export class UserInfoDto @ApiProperty({ description: '희망 카테고리 id', + format: 'integer', + minimum: 1, }) hopeCategoryId: number; @ApiProperty({ description: '활동 카테고리 id', + format: 'integer', + minimum: 1, }) activityCategoryId: number; @ApiProperty({ - description: '점수', + description: '등급', + format: 'integer', + minimum: 1, }) rank: number; @ApiProperty({ description: '휴대폰 인증 여부', nullable: true, + type: () => String, }) phone: string | null;