-
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"
Changes from 10 commits
b679c03
5f4a9b9
89cc169
2c280c8
1f52f5c
6bb6fe0
f6c49ae
c381eff
a8c35ef
56bd968
7eceae0
eecc5f6
ab69625
b341a33
074d357
8da0c4a
0729f66
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
const logger = require("./logger"); | ||
const { banModel } = require("./stores/mongo"); | ||
|
||
/** | ||
* | ||
* @param {*} req | ||
* @param {String} service | ||
*/ | ||
const validateServiceBanRecord = async (req, service) => { | ||
switch (service) { | ||
case "Rooms/create": | ||
case "Rooms/join": | ||
var _serviceName = "service"; | ||
break; | ||
default: | ||
logger.error( | ||
"Error occured while validateServiceBanRecord: given service is not defined." | ||
); | ||
return; | ||
} | ||
try { | ||
// 현재 시각이 expireAt 보다 작고, 본인인 경우(ban의 userId가 userId랑 같은 경우) 중 serviceName이 "service"인 record를 모두 가져옴 | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. 큰 차이는 없을 것 같은데 저는 이럴 때 gte보다는 gt를 사용하는걸 선호하긴 합니다! (expireAt이 이때부터 차단 해제된다는 의미니까요) 이건 그냥 optional로 원하시면 수정해주셔도 될 것 같습니다. |
||
}, | ||
serviceName: _serviceName, | ||
}); | ||
var banRecord = undefined; | ||
if (bans.length > 0) { | ||
// 가장 expireAt이 큰 정지 기록만 반환함. | ||
var banRecord = bans.reduce( | ||
(max, ban) => (ban.expireAt > max.expireAt ? ban : max), | ||
bans[0] | ||
); | ||
} | ||
} catch (err) { | ||
logger.error( | ||
"Error occured while getValidServiceBanRecord: " + err.message | ||
); | ||
return; | ||
} | ||
if (banRecord != undefined) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const formattedExpireAt = banRecord.expireAt | ||
.toISOString() | ||
.replace("T", " ") | ||
.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 commentThe reason will be displayed to describe this comment to others. Learn more. 나중에 case가 너무 많아질 것 같아서 염려가 됩니다. Endpoint 이름은 |
||
break; | ||
case "Rooms/join": | ||
var banErrorMessage = `Rooms/join : user ${req.userId} (${req.session.loginInfo.sid}) is temporarily restricted from joining rooms until ${formattedExpireAt}.`; | ||
break; | ||
} | ||
return banErrorMessage; | ||
} | ||
return; | ||
}; | ||
|
||
module.exports = { | ||
validateServiceBanRecord, | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,11 +21,20 @@ const eventPeriod = eventConfig && { | |
endAt: new Date(eventConfig.period.endAt), | ||
}; | ||
const { contracts } = require("../lottery"); | ||
const { validateServiceBanRecord } = require("../modules/ban"); | ||
|
||
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 commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 |
||
return res.status(400).json({ | ||
error: banErrorMessage, | ||
}); | ||
} | ||
|
||
if (from === to) { | ||
return res.status(400).json({ | ||
error: "Rooms/create : locations are same", | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. 여기도 |
||
return res.status(400).json({ | ||
error: banErrorMessage, | ||
}); | ||
} | ||
|
||
// 사용자의 참여중인 진행중인 방이 5개 이상이면 오류를 반환합니다. | ||
if (user.ongoingRoom.length >= 5) { | ||
return res.status(400).json({ | ||
|
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
는 사용하면 안됩니다!