-
Notifications
You must be signed in to change notification settings - Fork 1
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
#520 ban 여부에 따른 서비스 이용 제한 #530
The head ref may contain hidden characters: "#520-ban-\uC5EC\uBD80\uC5D0-\uB530\uB978-\uC11C\uBE44\uC2A4-\uC774\uC6A9-\uC81C\uD55C"
Conversation
…520-ban-여부에-따른-서비스-이용-제한
…-kaist/taxi-back into #520-ban-여부에-따른-서비스-이용-제한
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
banRecord 확인과 관련하여 중복되는 코드가 많은데, 미들웨어로 분리하면 어떨까요?
src/modules/ban.js
Outdated
switch (service) { | ||
case "Rooms/create": | ||
case "Rooms/join": | ||
var _serviceName = "service"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저희 컨벤션상 var
는 사용하면 안됩니다!
src/modules/ban.js
Outdated
.split(".")[0]; | ||
switch (service) { | ||
case "Rooms/create": | ||
var banErrorMessage = `Rooms/create : user ${req.userId} (${req.session.loginInfo.sid}) is temporarily restricted from creating rooms until ${formattedExpireAt}.`; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
나중에 case가 너무 많아질 것 같아서 염려가 됩니다. Endpoint 이름은 service
변수에 담겨있으니 그것을 사용하면 될 것 같고, 에러 메세지의 경우에는 언제까지 차단됐다는 메세지만 포함해도 괜찮을 것 같습니다. (그리고 제가 알기론 req.userId랑 req.session.loginInfo.sid가 같은 값으로 알고 있어요!)
src/modules/ban.js
Outdated
const bans = await banModel.find({ | ||
userSid: req.session.loginInfo.sid, | ||
expireAt: { | ||
$gte: req.timestamp, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
큰 차이는 없을 것 같은데 저는 이럴 때 gte보다는 gt를 사용하는걸 선호하긴 합니다! (expireAt이 이때부터 차단 해제된다는 의미니까요) 이건 그냥 optional로 원하시면 수정해주셔도 될 것 같습니다.
src/modules/ban.js
Outdated
); | ||
return; | ||
} | ||
if (banRecord != undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!==
사용해 주세요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 고생하셨습니다~!
src/modules/ban.js
Outdated
banRecord = bans.reduce( | ||
(max, ban) => (ban.expireAt > max.expireAt ? ban : max), | ||
bans[0] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
디비에서 가져올때 expireAt 순서로 소팅해서 가져오면 불필요한 .reduce()를 줄일 수 있을 것 같아요..!
src/services/rooms.js
Outdated
|
||
const createHandler = async (req, res) => { | ||
const { name, from, to, time, maxPartLength } = req.body; | ||
|
||
try { | ||
// 사용자가 방 생성 기능에 대하여 이용 정지 상태인지 확인합니다. | ||
const banErrorMessage = await validateServiceBanRecord(req, "Rooms/create"); | ||
if (banErrorMessage != undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도 !==
로 부탁드려요!
src/services/rooms.js
Outdated
@@ -237,6 +246,14 @@ const joinHandler = async (req, res) => { | |||
.findOne({ id: req.userId }) | |||
.populate("ongoingRoom"); | |||
|
|||
// 사용자가 방 참여 기능에 대하여 이용 정지 상태인지 확인합니다. | |||
const banErrorMessage = await validateServiceBanRecord(req, "Rooms/join"); | |||
if (banErrorMessage != undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
여기도 !==
로 부탁드려요!
src/middlewares/ban.js
Outdated
const { validateServiceBanRecord } = require("../modules/ban"); | ||
|
||
const banMiddleware = async (req, res, next) => { | ||
console.log(`req.originalUrl: ${req.originalUrl}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
저희 로그 남길 땐 logger
사용해야 합니다. 그리고 특이사항이 있는게 아니라면 이 내용은 로깅 안하는게 더 좋을 것 같아요!
src/middlewares/ban.js
Outdated
const banMiddleware = async (req, res, next) => { | ||
console.log(`req.originalUrl: ${req.originalUrl}`); | ||
const serviceMapper = { | ||
"/rooms/create": "service", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 상황에는 Object 대신 Map을 쓰는게 좋아요!
src/routes/rooms.js
Outdated
@@ -43,6 +43,9 @@ router.get( | |||
roomHandlers.infoHandler | |||
); | |||
|
|||
// 방 생성/참여전 ban 여부 확인 | |||
router.use(require("../middlewares/ban")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
router.use
보다는 각 Endpoint마다 미들웨어를 달아주는게 좋을 것 같아용
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
auth middleware 바로 아래로 올리는 것으로 논의 완료
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM..! 많은 요청사항 들어주셔서 감사합니다
Summary
It closes #520