Skip to content

Commit

Permalink
Merge pull request #186 from TeamSparker/feature/#174
Browse files Browse the repository at this point in the history
[FEAT] 습관방 리스트에, 쉴래요 여부 전달
  • Loading branch information
youngkwon02 authored Feb 17, 2022
2 parents 31f632c + 4fc28b2 commit 89e3387
Showing 1 changed file with 12 additions and 18 deletions.
30 changes: 12 additions & 18 deletions functions/api/routes/room/roomListGET.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const util = require('../../../lib/util');
const statusCode = require('../../../constants/statusCode');
const responseMessage = require('../../../constants/responseMessage');
const db = require('../../../db/db');
const { userDB, roomDB, sparkDB } = require('../../../db');
const jwtHandlers = require('../../../lib/jwtHandlers');
const { roomDB } = require('../../../db');
const slackAPI = require('../../../middlewares/slackAPI');
const dayjs = require('dayjs');
const { filter } = require('lodash');
const _ = require('lodash');
const roomPOST = require('./roomPOST');

/**
* @습관방_리스트_조회
* @route GET /room?lastId=&size=
* @error
* 1. 잘못된 lastId
* 1. lastId 또는 size 값이 전달되지 않음
* 2. 잘못된 lastId
*/

module.exports = async (req, res) => {
const lastId = Number(req.query.lastId);
const size = Number(req.query.size);
console.log(lastId, size);
const user = req.user;
console.log(user.userId);

// @error 1. lastId 또는 size 값이 전달되지 않음
if (!lastId || !size) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.NULL_VALUE));
}

let client;

Expand All @@ -37,8 +37,7 @@ module.exports = async (req, res) => {
waitingRooms = _.sortBy(waitingRooms, 'createdAt').reverse(); // 최근에 생성된 대기방이 위로
let ongoingRooms = rawRooms.filter((rawRoom) => rawRoom.status === 'ONGOING');
ongoingRooms = _.sortBy(ongoingRooms, 'startAt').reverse(); // 최근에 시작한 습관방이 위로
// console.log("waitingRooms", waitingRooms);
// console.log("ongoingRooms", ongoingRooms);

const waitingRoomIds = [...new Set(waitingRooms.filter(Boolean).map((room) => room.roomId))];
const ongoingRoomIds = [...new Set(ongoingRooms.filter(Boolean).map((room) => room.roomId))];
const roomIds = waitingRoomIds.concat(ongoingRoomIds);
Expand All @@ -50,7 +49,7 @@ module.exports = async (req, res) => {
// 최초 요청이 아닐시
if (lastId !== -1) {
const lastIndex = _.indexOf(roomIds, lastId);
// @error 1. 잘못된 last id
// @error 2. 잘못된 last Id
if (lastIndex === -1) {
return res.status(statusCode.BAD_REQUEST).send(util.fail(statusCode.BAD_REQUEST, responseMessage.INVALID_LASTID));
}
Expand Down Expand Up @@ -93,11 +92,7 @@ module.exports = async (req, res) => {
return false;
});

if (userStatus[0].status === 'DONE') {
roomUserStatus.push(true);
} else {
roomUserStatus.push(false);
}
roomUserStatus.push(userStatus[0].status);

const doneMembers = profiles.filter(Boolean).filter((o) => {
if (o.roomId === roomId && o.status === 'DONE') {
Expand Down Expand Up @@ -126,7 +121,6 @@ module.exports = async (req, res) => {
});

let rooms = [];
// console.log("roomInfo", roomInfo);
for (let i = 0; i < responseRoomIds.length; i++) {
const endDate = dayjs(roomInfo[i].endAt);
const leftDay = endDate.diff(today, 'day');
Expand All @@ -137,7 +131,7 @@ module.exports = async (req, res) => {
profileImg: roomProfileImg[i],
life: roomInfo[i].life,
isStarted: roomInfo[i].status === 'NONE' ? false : true,
isDone: roomUserStatus[i],
myStatus: roomUserStatus[i],
memberNum: roomMemberNum[i],
doneMemberNum: roomDoneMemberNum[i],
};
Expand Down

0 comments on commit 89e3387

Please sign in to comment.