Skip to content
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

[UPDATE] 채팅 불러오기 페이지네이션 #103

Merged
merged 1 commit into from
Sep 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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