Skip to content

Commit

Permalink
refactor(#325): setting constraints with user constant
Browse files Browse the repository at this point in the history
  • Loading branch information
hobiJeong committed Mar 7, 2024
1 parent 6862ddf commit e094445
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 18 deletions.
7 changes: 5 additions & 2 deletions src/mentors/dtos/mentor-list-page-query.dto.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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({
Expand Down
8 changes: 8 additions & 0 deletions src/mentors/dtos/user-intro-response.dto.ts
Original file line number Diff line number Diff line change
@@ -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<UserIntro, 'shortIntro' | 'customCategory'>
{
@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;
}
6 changes: 6 additions & 0 deletions src/mentors/dtos/user-with-image-and-intro.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -14,6 +15,8 @@ export class UserWithImageAndIntroDto extends PickType(UserForJoinDto, [

@ApiProperty({
description: '유저 이름',
minLength: USER_NAME_LENGTH.MIN,
maxLength: USER_NAME_LENGTH.MAX,
})
name: string;

Expand All @@ -22,6 +25,7 @@ export class UserWithImageAndIntroDto extends PickType(UserForJoinDto, [

@ApiProperty({
description: '유저 랭크',
format: 'integer',
})
rank: number;

Expand All @@ -32,11 +36,13 @@ export class UserWithImageAndIntroDto extends PickType(UserForJoinDto, [

@ApiProperty({
description: '멘토 리뷰 후기 당한 개수',
format: 'integer',
})
mentorReviewCount: number;

@ApiProperty({
description: '멘토 게시판 글쓴 갯수',
format: 'integer',
})
mentorBoardCount: number;

Expand Down
3 changes: 3 additions & 0 deletions src/search/dtos/search-all-mentor.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<User, 'id' | 'name' | 'isMentor'>
Expand All @@ -13,6 +14,8 @@ export class SearchAllMentorDto

@ApiProperty({
description: '멘토 유저 이름',
minLength: USER_NAME_LENGTH.MIN,
maxLength: USER_NAME_LENGTH.MAX,
})
name: string;

Expand Down
3 changes: 3 additions & 0 deletions src/search/dtos/search-user-dto.ts
Original file line number Diff line number Diff line change
@@ -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<User, 'id' | 'name'> {
@ApiProperty({
Expand All @@ -11,6 +12,8 @@ export class SearchUserDto implements Pick<User, 'id' | 'name'> {

@ApiProperty({
description: '작성자 이름',
minLength: USER_NAME_LENGTH.MIN,
maxLength: USER_NAME_LENGTH.MAX,
})
name: string;

Expand Down
7 changes: 4 additions & 3 deletions src/users/dtos/create-user.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/users/dtos/get-my-intro.dto.ts
Original file line number Diff line number Diff line change
@@ -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<UserIntro, 'user'> {
Expand All @@ -11,31 +19,43 @@ export class MyIntroDto implements Omit<UserIntro, 'user'> {

@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;

Expand Down
41 changes: 31 additions & 10 deletions src/users/dtos/update-user-intro-dto.ts
Original file line number Diff line number Diff line change
@@ -1,70 +1,91 @@
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({
example: 1,
description: '희망 카테고리 id',
})
@IsOptional()
@IsNumber()
@IsPositiveInt()
hopeCategoryId?: number;

@ApiPropertyOptional({
example: 1,
description: '활동 카테고리 id',
})
@IsOptional()
@IsNumber()
@IsPositiveInt()
activityCategoryId?: number;

@ApiPropertyOptional({
Expand Down
24 changes: 21 additions & 3 deletions src/users/dtos/user-info.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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;

Expand Down

0 comments on commit e094445

Please sign in to comment.