Skip to content

Commit

Permalink
Merge pull request #145 from TeamBookTez/hotfix/withdrawal-logic
Browse files Browse the repository at this point in the history
[hotfix] Revise the membership withdrawal logic
  • Loading branch information
holmir97 authored Apr 28, 2022
2 parents 9b10723 + 7e14656 commit 5daff15
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 26 deletions.
23 changes: 14 additions & 9 deletions src/scheduler/userScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@ export const userScan = schedule.scheduleJob("0 0 0 * * *", async () => {
// 삭제 예정 유저
const deletedUsers = await User.find(keysToSnake({ isDeleted: true }));

deletedUsers.forEach(async (user) => {
// 현재 날짜가 만료 날짜 이후
if (current.getTime() >= user.expired_at.getTime()) {
// 해당 유저가 가진 리뷰 모두 삭제
await Review.deleteMany(keysToSnake({ userID: user._id }));
// 해당 유저 삭제
await user.deleteOne(keysToSnake({ _id: user._id }));
}
});
await Promise.all(
deletedUsers.map(async (user) => {
// 현재 날짜가 만료 날짜 이후
if (current.getTime() >= user.expired_at.getTime()) {
// 해당 유저가 가진 리뷰 모두 삭제
const { deletedCount } = await Review.deleteMany(
keysToSnake({ userId: user._id })
);
// 해당 유저 삭제
await user.deleteOne(keysToSnake({ _id: user._id }));
console.log("Delete Count: " + deletedCount);
}
})
);
console.log("Complete scanning...");
});
27 changes: 10 additions & 17 deletions src/service/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,7 @@ const getEmailService = async (email?: string) => {

// email이 이미 존재할 때
// TODO: DB에서 isDeleted string으로 되있는 것 변경
const emailExist = await User.exists(
keysToSnake({ email, isDeleted: false })
);
const emailExist = await User.exists({ email });
if (emailExist) {
return constant.EMAIL_ALREADY_EXIST;
}
Expand Down Expand Up @@ -72,10 +70,7 @@ const getNicknameService = async (nickname?: string) => {
}

// nickname이 이미 존재할 때
const nicknameExist = await User.find({
nickname,
isDeleted: false,
});
const nicknameExist = await User.find({ nickname });

if (nicknameExist.length > 0) {
return constant.NICKNAME_ALREADY_EXIST;
Expand All @@ -99,10 +94,12 @@ const postLoginService = async (email: string, password: string) => {
}

// 존재하지 않는 이메일
const user = await User.findOne({
email,
isDeleted: false,
});
const user = await User.findOne(
keysToSnake({
email,
isDeleted: false,
})
);
if (!user) {
return constant.EMAIL_NOT_FOUND;
}
Expand Down Expand Up @@ -163,17 +160,13 @@ const postSignupService = async (
}

// email이 이미 존재할 때
const emailExist = await User.exists(
keysToSnake({ email, isDeleted: false })
);
const emailExist = await User.exists({ email });
if (emailExist) {
return constant.EMAIL_ALREADY_EXIST;
}

// nickname이 이미 존재할 때
const nicknameExist = await User.exists(
keysToSnake({ nickname, isDeleted: false })
);
const nicknameExist = await User.exists({ nickname });
if (nicknameExist) {
return constant.NICKNAME_ALREADY_EXIST;
}
Expand Down

0 comments on commit 5daff15

Please sign in to comment.