Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[hotfix] Revise the membership withdrawal logic #145

Merged
merged 5 commits into from
Apr 28, 2022
Merged
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
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