-
Notifications
You must be signed in to change notification settings - Fork 0
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
[GET] /myroom/:roomId 특정 습관방 사진 모아보기 #66
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
bff3f9b
feat: 특정 습관방 사진 모아보기
xxeol2 79677f9
fix: merge conflict
xxeol2 388b4e8
feat: 페이지네이션
xxeol2 d275a04
style: 필요없는 코드 삭제
xxeol2 5fad5b0
style: 필요 없는 주석 삭제
xxeol2 793c7ba
style: 필요없는 코드 삭제
xxeol2 c7b75d4
refactor: 필요없는 코드 삭제
xxeol2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
const functions = require('firebase-functions'); | ||
const util = require('../../../lib/util'); | ||
const statusCode = require('../../../constants/statusCode'); | ||
const responseMessage = require('../../../constants/responseMessage'); | ||
const db = require('../../../db/db'); | ||
const { roomDB, sparkDB, recordDB } = require('../../../db'); | ||
const slackAPI = require('../../../middlewares/slackAPI'); | ||
const _ = require('lodash'); | ||
|
||
/** | ||
* @인증사진_모아보기 | ||
* @route GET /myroom/room/:roomId?lastid=&size= | ||
* @error | ||
* 1. roomId가 없음 | ||
* 2. 존재하지 않는 습관방인 경우 | ||
* 3. 접근 권한이 없는 유저인 경우 | ||
*/ | ||
|
||
|
||
module.exports = async (req, res) => { | ||
let lastId = Number(req.query.lastid); | ||
const size = Number(req.query.size); | ||
const user = req.user; | ||
const { roomId } = req.params; | ||
let client; | ||
|
||
// @error 1. roomId가 없음 | ||
if (!roomId) { | ||
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE)); | ||
} | ||
|
||
try { | ||
client = await db.connect(req); | ||
|
||
const room = await roomDB.getRoomById(client, roomId); | ||
// @error 2. 존재하지 않는 습관방인 경우 | ||
if (!room) { | ||
res.status(statusCode.NO_CONTENT).send(util.fail(statusCode.NO_CONTENT, responseMessage.GET_ROOM_DATA_FAIL)); | ||
} | ||
|
||
// @error 3. 접근 권한이 없는 유저인 경우 | ||
const entry = await roomDB.checkEnteredById(client, roomId, user.userId); | ||
if (!entry) { | ||
res.status(statusCode.UNAUTHORIZED).send(util.fail(statusCode.UNAUTHORIZED, responseMessage.NOT_MEMBER)); | ||
} | ||
|
||
const pagedRecords = await recordDB.getPagedRecordsByEntryId(client, entry.entryId, lastId, size); | ||
|
||
// 해당하는 record가 없을 경우 | ||
if (!pagedRecords.length) { | ||
const data = { | ||
roomName: room.roomName, | ||
records: [] | ||
}; | ||
return res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.GET_MYROOM_DETAIL_SUCCESS, data)); | ||
} | ||
|
||
const recordIds = pagedRecords.map((o) => o.recordId); | ||
|
||
const sparkNums = await sparkDB.countSparkByRecordIds(client, recordIds); | ||
|
||
const records = pagedRecords.map((record) => { | ||
const sparkCount = _.find(sparkNums, {'recordId': record.recordId}); | ||
const sparkNum = sparkCount? Number(sparkCount.sparkNum): 0; | ||
return { | ||
recordId: record.recordId, | ||
leftDay: 66-record.dayjs, | ||
certifyingImg: record.certifyingImg, | ||
sparkNum, | ||
status: record.status | ||
} | ||
}); | ||
|
||
const data = { | ||
roomName: room.roomName, | ||
records | ||
}; | ||
|
||
res.status(statusCode.OK).send(util.success(statusCode.OK, responseMessage.GET_MYROOM_DETAIL_SUCCESS, data)); | ||
} catch (error) { | ||
console.log(error); | ||
functions.logger.error(`[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl}`, `[CONTENT] ${error}`); | ||
const slackMessage = `[ERROR] [${req.method.toUpperCase()}] ${req.originalUrl} ${error} ${JSON.stringify(error)}`; | ||
slackAPI.sendMessageToSlack(slackMessage, slackAPI.DEV_WEB_HOOK_ERROR_MONITORING); | ||
res.status(statusCode.INTERNAL_SERVER_ERROR).send(util.fail(statusCode.INTERNAL_SERVER_ERROR, responseMessage.INTERNAL_SERVER_ERROR)); | ||
} finally { | ||
client.release(); | ||
} | ||
}; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
수정했어요!