Skip to content

Commit 591bcf7

Browse files
authored
Merge pull request #30 from oodd-team/OD-33
유저 정보 수정 기능 수정
2 parents 7e51d8f + 94e20c1 commit 591bcf7

File tree

4 files changed

+75
-17
lines changed

4 files changed

+75
-17
lines changed

src/user/dto/patch-user.request.ts

+46-5
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,57 @@
1-
import { IsOptional, IsString, IsUrl, MaxLength } from 'class-validator';
1+
import {
2+
IsEmail,
3+
IsNotEmpty,
4+
IsOptional,
5+
IsString,
6+
IsUrl,
7+
MaxLength,
8+
} from 'class-validator';
29
import { ApiProperty } from '@nestjs/swagger';
310

411
export class PatchUserRequest {
12+
@IsOptional()
13+
@IsString()
14+
@MaxLength(100, { message: '이름은 최대 100자까지 입력할 수 있습니다.' })
15+
@IsNotEmpty({ message: '이름을 비울 수 없습니다.' })
16+
@ApiProperty({
17+
description: '수정할 이름',
18+
example: '새 이름',
19+
required: false,
20+
})
21+
name?: string;
22+
23+
@IsOptional()
24+
@IsString()
25+
@MaxLength(15, { message: '전화번호는 최대 15자까지 입력할 수 있습니다.' })
26+
@IsNotEmpty({ message: '전화번호를 비울 수 없습니다.' })
27+
@ApiProperty({
28+
description: '수정할 전화번호',
29+
example: '010-9876-5432',
30+
required: false,
31+
})
32+
phoneNumber?: string;
33+
34+
@IsOptional()
35+
@IsEmail()
36+
@MaxLength(100, { message: '이메일은 최대 100자까지 입력할 수 있습니다.' })
37+
@IsNotEmpty({ message: '이메일을 비울 수 없습니다.' })
38+
@ApiProperty({
39+
description: '수정할 이메일',
40+
example: '[email protected]',
41+
required: false,
42+
})
43+
email?: string;
44+
545
@IsOptional()
646
@IsString()
747
@MaxLength(10, { message: '닉네임은 최대 10자까지 입력할 수 있습니다.' })
48+
@IsNotEmpty({ message: '닉네임을 비울 수 없습니다.' })
849
@ApiProperty({
950
description: '수정할 닉네임',
10-
example: '새닉네임',
51+
example: '새 닉네임',
1152
required: false,
1253
})
13-
nickname?: string | null;
54+
nickname?: string;
1455

1556
@IsOptional()
1657
@IsUrl({}, { message: '유효한 URL 형식이어야 합니다.' })
@@ -19,7 +60,7 @@ export class PatchUserRequest {
1960
example: 'https://example.com/profile.jpg',
2061
required: false,
2162
})
22-
profilePictureUrl?: string | null;
63+
profilePictureUrl?: string;
2364

2465
@IsOptional()
2566
@IsString()
@@ -29,5 +70,5 @@ export class PatchUserRequest {
2970
example: '소개글~~~^^',
3071
required: false,
3172
})
32-
bio?: string | null;
73+
bio?: string;
3374
}

src/user/dto/patch-user.response.ts

+21-3
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,37 @@ export class PatchUserResponse {
88
userId: number;
99

1010
@ApiProperty({
11-
description: '수정된 닉네임',
11+
description: '수정 후 이름',
12+
example: '새 이름',
13+
})
14+
name: string;
15+
16+
@ApiProperty({
17+
description: '수정 후 전화번호',
18+
example: '010-9876-5432',
19+
})
20+
phoneNumber: string;
21+
22+
@ApiProperty({
23+
description: '수정 후 이메일',
24+
example: '[email protected]',
25+
})
26+
email: string;
27+
28+
@ApiProperty({
29+
description: '수정 후 닉네임',
1230
example: '새 닉네임',
1331
})
1432
nickname: string;
1533

1634
@ApiProperty({
17-
description: '수정된 프로필 사진 URL',
35+
description: '수정 후 프로필 사진 URL',
1836
example: 'https://example.com/profile.jpg',
1937
})
2038
profilePictureUrl: string;
2139

2240
@ApiProperty({
23-
description: '수정된 자기소개',
41+
description: '수정 후 자기소개',
2442
example: '소개글~~~^^',
2543
})
2644
bio: string;

src/user/user.controller.ts

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ export class UserController {
6262

6363
return new BaseResponse<PatchUserResponse>(true, '유저 정보 수정 성공', {
6464
userId: updatedUser.id,
65+
name: updatedUser.name,
66+
phoneNumber: updatedUser.phoneNumber,
67+
email: updatedUser.email,
6568
nickname: updatedUser.nickname,
6669
profilePictureUrl: updatedUser.profilePictureUrl,
6770
bio: updatedUser.bio,

src/user/user.service.ts

+5-9
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,11 @@ export class UserService {
6464
});
6565

6666
try {
67-
if (patchUserRequest.nickname !== undefined) {
68-
user.nickname = patchUserRequest.nickname;
69-
}
70-
if (patchUserRequest.profilePictureUrl !== undefined) {
71-
user.profilePictureUrl = patchUserRequest.profilePictureUrl;
72-
}
73-
if (patchUserRequest.bio !== undefined) {
74-
user.bio = patchUserRequest.bio;
75-
}
67+
Object.entries(patchUserRequest).forEach(([key, value]) => {
68+
if (value !== undefined) {
69+
user[key] = value;
70+
}
71+
});
7672

7773
return await this.userRepository.save(user);
7874
} catch (error) {

0 commit comments

Comments
 (0)