Skip to content
Merged

Fix #67

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions repositorys/followRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,17 @@ const createFollow = async (followerId, followingId) => {
};

const deleteFollow = async (userId, targetUserId) => {
const followCheck = await prisma.follow.findUnique({
where: {
follower_id_following_id: {
follower_id: userId,
following_id: targetUserId,
},
},
});
if (!followCheck) {
throw new Error('팔로우 관계가 존재하지 않습니다.');
}
const follow = await prisma.follow.delete({
where: {
follower_id_following_id: {
Expand All @@ -197,6 +208,17 @@ const deleteFollow = async (userId, targetUserId) => {
};

const deleteFollower = async (userId, targetUserId) => {
const followCheck = await prisma.follow.findUnique({
where: {
follower_id_following_id: {
follower_id: targetUserId,
following_id: userId,
},
},
});
if (!followCheck) {
throw new Error('팔로우 관계가 존재하지 않습니다.');
}
const follow = await prisma.follow.delete({
where: {
follower_id_following_id: {
Expand Down
42 changes: 28 additions & 14 deletions repositorys/userRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,21 +303,35 @@ const checkEmail = async (email) => {
};

const resetPassword = async (email) => {
const user = await prisma.user.findUnique({
where: { email },
});
if (!user) {
throw new Error('존재하지 않는 이메일입니다.');
}
const newPassword = Math.random().toString(36).substring(2, 15);
const hashedPassword = await bcrypt.hash(newPassword, 10);
await sendEmailAuth(email, newPassword);
await prisma.user.update({
where: { email },
data: { password: hashedPassword },
});
try {
const result = await prisma.$transaction(async (tx) => {
const user = await tx.user.findUnique({
where: { email },
});
if (!user) {
throw new Error('존재하지 않는 이메일입니다.');
}

return;
const newPassword = Math.random().toString(36).substring(2, 15);
const hashedPassword = await bcrypt.hash(newPassword, 10);

await sendEmailAuth(email, newPassword);

await tx.user.update({
where: { email },
data: { password: hashedPassword },
});

return newPassword;
});

return result;
} catch (error) {
if (error.message === '존재하지 않는 이메일입니다.') {
throw error;
}
throw new Error('비밀번호 재설정 중 오류가 발생했습니다.');
}
};

const passwordChange = async (userId, newPassword, confirmPassword) => {
Expand Down
Loading