-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#457 추천인 시스템 구현
- Loading branch information
Showing
12 changed files
with
231 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
const { eventConfig } = require("../../../../loadenv"); | ||
const apiPrefix = `/events/${eventConfig?.mode}/invite`; | ||
|
||
const inviteDocs = {}; | ||
inviteDocs[`${apiPrefix}/search/:inviter`] = { | ||
get: { | ||
tags: [`${apiPrefix}`], | ||
summary: "초대자 정보 조회", | ||
description: "초대자의 정보를 조회합니다.", | ||
requestBody: { | ||
description: "", | ||
content: { | ||
"application/json": { | ||
schema: { | ||
$ref: "#/components/schemas/searchInviterHandler", | ||
}, | ||
}, | ||
}, | ||
}, | ||
responses: { | ||
200: { | ||
description: "", | ||
content: { | ||
"application/json": { | ||
schema: { | ||
type: "object", | ||
required: ["nickname", "profileImageUrl"], | ||
properties: { | ||
nickname: { | ||
type: "string", | ||
description: "초대자의 닉네임", | ||
example: "asdf", | ||
}, | ||
profileImageUrl: { | ||
type: "string", | ||
description: "초대자의 프로필 이미지 URL", | ||
example: "IMAGE URL", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
inviteDocs[`${apiPrefix}/create`] = { | ||
post: { | ||
tags: [`${apiPrefix}`], | ||
summary: "초대 링크 생성", | ||
description: "초대 링크를 생성합니다.", | ||
responses: { | ||
200: { | ||
description: "", | ||
content: { | ||
"application/json": { | ||
schema: { | ||
type: "object", | ||
required: ["inviteUrl"], | ||
properties: { | ||
inviteUrl: { | ||
type: "string", | ||
description: "초대 링크", | ||
example: "INVITE URL", | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
|
||
module.exports = inviteDocs; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
const inviteSchema = { | ||
searchInviterHandler: { | ||
type: "object", | ||
required: ["inviter"], | ||
properties: { | ||
inviter: { | ||
type: "string", | ||
pattern: "^[a-fA-F\\d]{24}$", | ||
}, | ||
}, | ||
errorMessage: "validation: bad request", | ||
}, | ||
}; | ||
|
||
module.exports = inviteSchema; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ const questsSchema = { | |
enum: ["roomSharing"], | ||
}, | ||
}, | ||
errorMessage: "validation: bad request", | ||
}, | ||
}; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
const express = require("express"); | ||
|
||
const router = express.Router(); | ||
const inviteHandlers = require("../services/invite"); | ||
|
||
const { validateParams } = require("../../middlewares/ajv"); | ||
const inviteSchema = require("./docs/inviteSchema"); | ||
|
||
router.get( | ||
"/search/:inviter", | ||
validateParams(inviteSchema.searchInviterHandler), | ||
inviteHandlers.searchInviterHandler | ||
); | ||
|
||
// 아래의 Endpoint 접근 시 로그인, 차단 여부 체크 및 시각 체크 필요 | ||
router.use(require("../../middlewares/auth")); | ||
router.use(require("../middlewares/checkBanned")); | ||
router.use(require("../middlewares/timestampValidator")); | ||
|
||
router.post("/create", inviteHandlers.createInviteUrlHandler); | ||
|
||
module.exports = router; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
const { eventStatusModel } = require("../modules/stores/mongo"); | ||
const { userModel } = require("../../modules/stores/mongo"); | ||
const logger = require("../../modules/logger"); | ||
|
||
const { eventConfig } = require("../../../loadenv"); | ||
|
||
const searchInviterHandler = async (req, res) => { | ||
try { | ||
const { inviter } = req.params; | ||
const inviterStatus = await eventStatusModel.findOne({ _id: inviter }); | ||
if ( | ||
!inviterStatus || | ||
!inviterStatus.isEnabledInviteUrl || | ||
inviterStatus.isBanned | ||
) | ||
return res.status(400).json({ error: "Invite/Search : invalid inviter" }); | ||
|
||
const inviterInfo = await userModel.findOne({ _id: inviterStatus.userId }); | ||
if (!inviterInfo) | ||
return res | ||
.status(500) | ||
.json({ error: "Invite/Search : internal server error" }); | ||
|
||
return res.json({ | ||
nickname: inviterInfo.nickname, | ||
profileImageUrl: inviterInfo.profileImageUrl, | ||
}); | ||
} catch (err) { | ||
logger.error(err); | ||
res.status(500).json({ error: "Invite/Search : internal server error" }); | ||
} | ||
}; | ||
|
||
const createInviteUrlHandler = async (req, res) => { | ||
try { | ||
const inviteUrl = `${req.origin}/event/${eventConfig?.mode}-invite/${req.eventStatus._id}`; | ||
|
||
if (req.eventStatus.isEnabledInviteUrl) return res.json({ inviteUrl }); | ||
|
||
const eventStatus = await eventStatusModel | ||
.findOneAndUpdate( | ||
{ | ||
_id: req.eventStatus._id, | ||
isEnabledInviteUrl: false, | ||
}, | ||
{ | ||
isEnabledInviteUrl: true, | ||
} | ||
) | ||
.lean(); | ||
if (!eventStatus) | ||
return res | ||
.status(500) | ||
.json({ error: "Invite/Create : internal server error" }); | ||
|
||
return res.json({ inviteUrl }); | ||
} catch (err) { | ||
logger.error(err); | ||
res.status(500).json({ error: "Invite/Create : internal server error" }); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
searchInviterHandler, | ||
createInviteUrlHandler, | ||
}; |