Skip to content

Commit

Permalink
Merge pull request #103 from bookmaru/feature_yz
Browse files Browse the repository at this point in the history
[UPDATE] 채팅 불러오기 페이지네이션
  • Loading branch information
predictyson authored Sep 17, 2020
2 parents ab97d22 + 44c1fcd commit 478e0ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 7 additions & 1 deletion MARU/controllers/chatController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,15 @@ const chat = {
res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, resMessage.NULL_VALUE));
return;
}
const {pageStart, pageEnd} = req.query;

if (pageStart === undefined || pageEnd === undefined) {
res.status(statusCode.BAD_REQUEST).send(statusCode.BAD_REQUEST, resMessage.NULL_VALUE);
return;
}

try {
const getChat = await chatModel.getChat(roomIdx);
const getChat = await chatModel.getChat(roomIdx, pageStart -1 , pageEnd);
res.status(statusCode.OK).send(util.success(statusCode.OK, resMessage.POSSIBLE_JOIN_ROOM, getChat));
return;
} catch (err) {
Expand Down
4 changes: 2 additions & 2 deletions MARU/models/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ const chat = {
},

//db에서 내용 가져오기
getChat: async (roomIdx) => {
const query = `SELECT * FROM ${table} WHERE roomIdx = ${roomIdx}`;
getChat: async (roomIdx, pageStart, pageEnd) => {
const query = `SELECT * FROM ${table} WHERE roomIdx = ${roomIdx} ORDER BY roomIdx DESC LIMIT ${pageStart}, ${pageEnd} `;
try {
const result = await pool.queryParamArr(query);
return result;
Expand Down

0 comments on commit 478e0ce

Please sign in to comment.