-
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
#541 24-chuseok event ban middleware #544
base: dev
Are you sure you want to change the base?
Changes from 1 commit
9798ecc
b9efeeb
793157c
cc87bc3
07d6c3b
6f64cac
a4ef34a
fd4437a
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,32 @@ | ||
const { eventStatusModel } = require("../modules/stores/mongo"); | ||
const logger = require("../../modules/logger"); | ||
|
||
/** | ||
* 사용자가 차단 되었는지 여부를 판단합니다. | ||
* 차단된 사용자는 이벤트에 한하여 서비스 이용에 제재를 받습니다. | ||
* @param {*} req eventStatus가 성공적일 경우 req.eventStatus = eventStatus로 들어갑니다. | ||
* @param {*} res | ||
* @param {*} next | ||
* @returns | ||
*/ | ||
const eventValidator = async (req, res, next) => { | ||
try { | ||
const eventStatus = await eventStatusModel | ||
.findOne({ userId: req.userOid }) | ||
.lean(); | ||
if (!eventStatus) { | ||
return res | ||
.status(400) | ||
.json({ error: "eventValidator: nonexistent eventStatus" }); | ||
} | ||
req.eventStatus = eventStatus; | ||
} catch (err) { | ||
logger.error(err); | ||
res.error(500).json({ | ||
error: "eventValidator: internal server error", | ||
}); | ||
} | ||
next(); | ||
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. 에러 발생했을 땐 next를 호출하면 안됩니다! |
||
}; | ||
|
||
module.exports = eventValidator; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -109,8 +109,8 @@ const quests = buildQuests({ | |
* @returns {Promise} | ||
* @usage lottery/globalState - createUserGlobalStateHandler | ||
*/ | ||
const completeFirstLoginQuest = async (userId, timestamp) => { | ||
return await completeQuest(userId, timestamp, quests.firstLogin); | ||
const completeFirstLoginQuest = async (req, userId, 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. req에 이미 userOid가 포함되어 있어서, req를 받을거라면 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 await completeQuest(req, userId, timestamp, quests.firstLogin); | ||
}; | ||
|
||
/** | ||
|
@@ -121,8 +121,8 @@ const completeFirstLoginQuest = async (userId, timestamp) => { | |
* @description 방을 만들 때마다 호출해 주세요. | ||
* @usage rooms - createHandler | ||
*/ | ||
const completeFirstRoomCreationQuest = async (userId, timestamp) => { | ||
return await completeQuest(userId, timestamp, quests.firstRoomCreation); | ||
const completeFirstRoomCreationQuest = async (req, userId, timestamp) => { | ||
return await completeQuest(req, userId, timestamp, quests.firstRoomCreation); | ||
}; | ||
|
||
/** | ||
|
@@ -137,7 +137,12 @@ const completeFirstRoomCreationQuest = async (userId, timestamp) => { | |
* @description 정산 요청이 이루어질 때마다 호출해 주세요. | ||
* @usage rooms - commitSettlementHandler | ||
*/ | ||
const completeFareSettlementQuest = async (userId, timestamp, roomObject) => { | ||
const completeFareSettlementQuest = async ( | ||
req, | ||
userId, | ||
timestamp, | ||
roomObject | ||
) => { | ||
logger.info( | ||
`User ${userId} requested to complete fareSettlementQuest in Room ${roomObject._id}` | ||
); | ||
|
@@ -150,7 +155,7 @@ const completeFareSettlementQuest = async (userId, timestamp, roomObject) => { | |
) | ||
return null; // 택시 출발 시각이 이벤트 기간 내에 포함되지 않는 경우 퀘스트 완료 요청을 하지 않습니다. | ||
|
||
return await completeQuest(userId, timestamp, quests.fareSettlement); | ||
return await completeQuest(req, userId, timestamp, quests.fareSettlement); | ||
}; | ||
|
||
/** | ||
|
@@ -165,7 +170,7 @@ const completeFareSettlementQuest = async (userId, timestamp, roomObject) => { | |
* @description 송금이 이루어질 때마다 호출해 주세요. | ||
* @usage rooms - commitPaymentHandler | ||
*/ | ||
const completeFarePaymentQuest = async (userId, timestamp, roomObject) => { | ||
const completeFarePaymentQuest = async (req, userId, timestamp, roomObject) => { | ||
logger.info( | ||
`User ${userId} requested to complete farePaymentQuest in Room ${roomObject._id}` | ||
); | ||
|
@@ -178,7 +183,7 @@ const completeFarePaymentQuest = async (userId, timestamp, roomObject) => { | |
) | ||
return null; // 택시 출발 시각이 이벤트 기간 내에 포함되지 않는 경우 퀘스트 완료 요청을 하지 않습니다. | ||
|
||
return await completeQuest(userId, timestamp, quests.farePayment); | ||
return await completeQuest(req, userId, timestamp, quests.farePayment); | ||
}; | ||
|
||
/** | ||
|
@@ -189,8 +194,8 @@ const completeFarePaymentQuest = async (userId, timestamp, roomObject) => { | |
* @description 닉네임을 변경할 때마다 호출해 주세요. | ||
* @usage users - editNicknameHandler | ||
*/ | ||
const completeNicknameChangingQuest = async (userId, timestamp) => { | ||
return await completeQuest(userId, timestamp, quests.nicknameChanging); | ||
const completeNicknameChangingQuest = async (req, userId, timestamp) => { | ||
return await completeQuest(req, userId, timestamp, quests.nicknameChanging); | ||
}; | ||
|
||
/** | ||
|
@@ -202,10 +207,15 @@ const completeNicknameChangingQuest = async (userId, timestamp) => { | |
* @description 계좌를 변경할 때마다 호출해 주세요. | ||
* @usage users - editAccountHandler | ||
*/ | ||
const completeAccountChangingQuest = async (userId, timestamp, newAccount) => { | ||
const completeAccountChangingQuest = async ( | ||
req, | ||
userId, | ||
timestamp, | ||
newAccount | ||
) => { | ||
if (newAccount === "") return null; | ||
|
||
return await completeQuest(userId, timestamp, quests.accountChanging); | ||
return await completeQuest(req, userId, timestamp, quests.accountChanging); | ||
}; | ||
|
||
/** | ||
|
@@ -218,13 +228,14 @@ const completeAccountChangingQuest = async (userId, timestamp, newAccount) => { | |
* @usage notifications - editOptionsHandler | ||
*/ | ||
const completeAdPushAgreementQuest = async ( | ||
req, | ||
userId, | ||
timestamp, | ||
advertisement | ||
) => { | ||
if (!advertisement) return null; | ||
|
||
return await completeQuest(userId, timestamp, quests.adPushAgreement); | ||
return await completeQuest(req, userId, timestamp, quests.adPushAgreement); | ||
}; | ||
|
||
/** | ||
|
@@ -234,8 +245,8 @@ const completeAdPushAgreementQuest = async ( | |
* @returns {Promise} | ||
* @usage lottery/globalState - createUserGlobalStateHandler | ||
*/ | ||
const completeEventSharingQuest = async (userId, timestamp) => { | ||
return await completeQuest(userId, timestamp, quests.eventSharing); | ||
const completeEventSharingQuest = async (req, userId, timestamp) => { | ||
return await completeQuest(req, userId, timestamp, quests.eventSharing); | ||
}; | ||
|
||
/** | ||
|
@@ -245,8 +256,8 @@ const completeEventSharingQuest = async (userId, timestamp) => { | |
* @returns {Promise} | ||
* @description 상품을 구입할 때마다 호출해 주세요. | ||
*/ | ||
const completeItemPurchaseQuest = async (userId, timestamp) => { | ||
return await completeQuest(userId, timestamp, quests.itemPurchase); | ||
const completeItemPurchaseQuest = async (req, userId, timestamp) => { | ||
return await completeQuest(req, userId, timestamp, quests.itemPurchase); | ||
}; | ||
|
||
module.exports = { | ||
|
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.
개인적으로는 이렇게 eventStatus를 가져오는 미들웨어보다는 필요한 services에서만 가져다 쓰는게 좋을 것 같다고 생각해요. 기존 코드에 user를 가져오는 미들웨어가 없고 필요한 services에서 직접 조회해서 쓰는 것처럼요. 물론 성능 차이는 거의 없겠지만, service에 따라 eventStatus를 단순히 조회만 하는 경우가 있고, 수정해야 하는 경우도 있는데 후자의 경우에는 (미들웨어가 있으면) query가 2번 발생하게 됩니다.
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.
계속 사용하는 것으로 결정