Skip to content

Commit

Permalink
feat : 마이페이지 수정 정보 사진 등록 멀티파트 구현 #172
Browse files Browse the repository at this point in the history
  • Loading branch information
GeunH committed Dec 4, 2023
1 parent b3c20e1 commit c434a3a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
4 changes: 3 additions & 1 deletion be/src/user/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,7 @@ export class UserController {

@ApiTags("Mypage")
@Put()
@UseInterceptors(FileInterceptor('profileImage', multerOptions))
@UseGuards(AuthGuard("jwt"))
@ApiBearerAuth()
@ApiOperation({ summary: "유저 회원정보 수정" })
Expand All @@ -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);
}
}
30 changes: 16 additions & 14 deletions be/src/user/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}

0 comments on commit c434a3a

Please sign in to comment.