From c434a3a10c24cd4a264026a00d4616e27a8c95b9 Mon Sep 17 00:00:00 2001 From: GeunH Date: Mon, 4 Dec 2023 11:46:57 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=88=98=EC=A0=95=20=EC=A0=95=EB=B3=B4=20=EC=82=AC?= =?UTF-8?q?=EC=A7=84=20=EB=93=B1=EB=A1=9D=20=EB=A9=80=ED=8B=B0=ED=8C=8C?= =?UTF-8?q?=ED=8A=B8=20=EA=B5=AC=ED=98=84=20#172?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- be/src/user/user.controller.ts | 4 +++- be/src/user/user.service.ts | 30 ++++++++++++++++-------------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/be/src/user/user.controller.ts b/be/src/user/user.controller.ts index f6728615..54558762 100644 --- a/be/src/user/user.controller.ts +++ b/be/src/user/user.controller.ts @@ -403,6 +403,7 @@ export class UserController { @ApiTags("Mypage") @Put() + @UseInterceptors(FileInterceptor('profileImage', multerOptions)) @UseGuards(AuthGuard("jwt")) @ApiBearerAuth() @ApiOperation({ summary: "유저 회원정보 수정" }) @@ -411,9 +412,10 @@ export class UserController { @ApiResponse({ status: 400, description: "부적절한 요청" }) @UsePipes(new ValidationPipe()) async updateMypageUserInfo( + @UploadedFile() file: Express.Multer.File, @GetUser() tokenInfo: TokenInfo, @Body() userInfoDto: UserInfoDto ) { - return await this.userService.updateMypageUserInfo(tokenInfo, userInfoDto); + return await this.userService.updateMypageUserInfo(file, tokenInfo, userInfoDto); } } diff --git a/be/src/user/user.service.ts b/be/src/user/user.service.ts index 6c6f920c..83477cb6 100644 --- a/be/src/user/user.service.ts +++ b/be/src/user/user.service.ts @@ -31,6 +31,7 @@ export class UserService { private authService: AuthService ) { } async signup(@UploadedFile() file: Express.Multer.File, userInfoDto: UserInfoDto) { + userInfoDto.password = await hashPassword(userInfoDto.password); let profileImage; if (file) { const uuid = v4(); @@ -303,24 +304,25 @@ export class UserService { async deleteUserAccount(tokenInfo: TokenInfo) { return await this.usersRepository.deleteUserAccount(tokenInfo.id); } - async updateMypageUserInfo(tokenInfo: TokenInfo, userInfoDto: UserInfoDto) { + async updateMypageUserInfo(file: Express.Multer.File, tokenInfo: TokenInfo, userInfoDto: UserInfoDto) { userInfoDto.password = await hashPassword(userInfoDto.password); + let profileImage; + if (file) { + const uuid = v4(); + profileImage = `profile/images/${uuid}.png`; + await this.awsService.uploadToS3(profileImage, file.buffer); + } else { + profileImage = "profile/images/defaultprofile.png"; + } const user = { ...userInfoDto, - profileImage: "profile/images/defaultprofile.png", + profileImage: profileImage }; - - if (userInfoDto.profileImage) { - const uuid = v4(); - user.profileImage = `profile/images/${uuid}.png`; - } - const newUser = this.usersRepository.create(user); - const result = await this.usersRepository.updateMypageUserInfo( - tokenInfo.id, - newUser - ); - if (userInfoDto.profileImage) this.awsService.uploadToS3(user.profileImage, userInfoDto.profileImage); - return result; + const updatedUser = await this.usersRepository.updateMypageUserInfo(tokenInfo.id, newUser); + if (file) { + this.awsService.uploadToS3(`profile/images/${file.filename}`, file.buffer); + } + return updatedUser; } }