Skip to content

Commit

Permalink
feat(#88) : 프로필 수정 API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
Jieun Kim committed Feb 4, 2024
1 parent 0c9aaf9 commit 63a7ffe
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/controller/authController.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export const getUserInfo = async (req, res, next) => {
*/
export const updateUserInfo = async (req, res, next) => {
const { _id, email } = req.user;
const { nickname, phone, profile_image, password } = req.body;
const { nickname, phone, password } = req.body;
const fileUrl =
req.file && req.file.location
? req.file.location
Expand Down Expand Up @@ -230,6 +230,8 @@ export const updateUserInfo = async (req, res, next) => {
}

// password 수정 시, password 유효성 검사 & 암호화
let hashedPassword;

if (password) {
if (validPasswordCheck(password) == false) {
return res.send(
Expand All @@ -239,23 +241,26 @@ export const updateUserInfo = async (req, res, next) => {
)
);
}
const hashedPassword = await bcrypt.hash(password, 10);
hashedPassword = await bcrypt.hash(password, 10);
}

// S3 업로드 된 이미지 삭제
const findUser = await User.findOne({ email });
const fileKey = findUser.profile_image;
await deleteImage(fileKey);
console.log("이미지 삭제 성공");

if (findUser.profile_image && findUser.profile_image !== "파일을 업로드하지 않았습니다.") {
const fileKey = findUser.profile_image;
await deleteImage(fileKey);
console.log("이미지 삭제 성공");
}

const updateUser = await User.findOneAndUpdate(
{ email: email },
{
$set: {
nickname: nickname,
phone: phone,
profile_image: fileUrl,
password: password,
password: hashedPassword,
},
},
{ new: true }
Expand Down

0 comments on commit 63a7ffe

Please sign in to comment.