Skip to content

Commit

Permalink
Merge pull request #50 from depromeet/refactor/issue-46
Browse files Browse the repository at this point in the history
Refactor/issue 46
  • Loading branch information
ImNM authored May 10, 2022
2 parents 3ac5b35 + f8438c6 commit ec255ae
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 16 deletions.
7 changes: 7 additions & 0 deletions src/apis/questions/questions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,13 @@ export class QuestionsService {
blockUserListDto,
);

break;
case QUESTION_FIND_FILTER_TYPE.RECENT:
result = await this.questionRepository.getRecent2Questions(
myRoomIdDto,
blockUserListDto,
);

break;
}

Expand Down
22 changes: 17 additions & 5 deletions src/apis/rooms/rooms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export class RoomsService {
// 유저가현재 들어가있는 방이있으면
// safe 어프로치 populate 안때려도 가상으로 데려감 몽고디비 Document 형식이면
// console.log(typeof roomIdDto.roomId, roomIdDto.roomId, user.myRoom._id);
const room = await this.roomRepository.findOneByRoomId(roomIdDto);

if (user.myRoom) {
// 유저가 들어간 채팅방이 있을경우
Expand All @@ -129,7 +130,6 @@ export class RoomsService {
? true
: false;
// const isFavoritRoom = user.favoriteRoomList.includes(user.myRoom._id);
const room = await this.roomRepository.findOneByRoomId(roomIdDto);

// 차단 유저아웃
room.userList = this.filterRemoveBlockedUserFromUserList(
Expand All @@ -143,16 +143,28 @@ export class RoomsService {
});
} else {
// 다른 룸일 경우 다른룸에서 해당 유저를 빼줌
// 300명인지 체크하는 로직추가
if (room.userCount >= 300) {
throw new BadRequestException('유저수가 300명이 넘었습니다.');
}

await this.roomRepository.pullUserFromRoom(
new RoomIdDto(user.myRoom._id),
userIdDto,
);
}
}
// 300명인지 체크하는 로직추가
if (room.userCount >= 300) {
throw new BadRequestException('유저수가 300명이 넘었습니다.');
}
// 룸에 새로 들어갈때,,,?
await this.userRepository.setMyRoom(userIdDto, roomIdDto);
await this.userRepository.turnOnChatAlarm(userIdDto);
const room = await this.roomRepository.addUserToRoom(roomIdDto, userIdDto);
const newRoom = await this.roomRepository.addUserToRoom(
roomIdDto,
userIdDto,
);
//check
const iFavorite = user.favoriteRoomList.find((room) =>
room._id.equals(roomIdDto.roomId),
Expand All @@ -161,12 +173,12 @@ export class RoomsService {
: false;

// 차단 유저아웃
room.userList = this.filterRemoveBlockedUserFromUserList(
room.userList,
newRoom.userList = this.filterRemoveBlockedUserFromUserList(
newRoom.userList,
blockUserListDto,
);

const result = { ...room, iFavorite, iAlarm: true };
const result = { ...newRoom, iFavorite, iAlarm: true };
// console.log(result);
return plainToInstance(ResFindOneRoomDto, result, {
excludeExtraneousValues: true,
Expand Down
15 changes: 13 additions & 2 deletions src/apis/users/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ export class UserController {
updateProfileReqDto,
);
}

@ApiOperation({ summary: '내 차단유저 목록을 불러온다' })
@Get('/block')
@ApiResponse({
status: 201,
description: '요청 성공시',
type: [UserProfileDto],
})
getMyBlockUser(@ReqUser() user: User) {
return this.userService.getMyBlockUser(user.userIdDto);
}
//
@ApiOperation({ summary: '상대방 유저정보를 가져온다.' })
@ApiResponse({
Expand All @@ -93,7 +104,7 @@ export class UserController {
@ApiResponse({
status: 201,
description: '요청 성공시',
type: User,
type: [UserProfileDto],
})
blockUser(@Param() otherUSerIdDto: UserIdDto, @ReqUser() user: User) {
return this.userService.blockUser(user.userIdDto, otherUSerIdDto);
Expand All @@ -103,7 +114,7 @@ export class UserController {
@ApiResponse({
status: 200,
description: '요청 성공시',
type: User,
type: [UserProfileDto],
})
@Delete(':userId/block')
unblockUser(@Param() otherUSerIdDto: UserIdDto, @ReqUser() user: User) {
Expand Down
26 changes: 20 additions & 6 deletions src/apis/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ export class UserService {
);
}

@returnValueToDto(User)
@returnValueToDto(UserProfileDto)
async blockUser(
myUserIdDto: UserIdDto,
otherUserIdDto: UserIdDto,
): Promise<User> {
): Promise<UserProfileDto[]> {
if (myUserIdDto.userId.equals(otherUserIdDto.userId)) {
throw new BadRequestException('내 자신 차단');
}
Expand All @@ -97,15 +97,20 @@ export class UserService {
);
console.log('asdfasdfasdfasdfasdf', returnUser);
// auto 시리얼 라이징
return returnUser;
return returnUser.iBlockUsers;
}
@returnValueToDto(User)
@returnValueToDto(UserProfileDto)
async upBlockUser(
myUserIdDto: UserIdDto,
otherUserIdDto: UserIdDto,
): Promise<User> {
): Promise<UserProfileDto[]> {
// auto 시리얼 라이징
return await this.userRepository.unBlockUser(myUserIdDto, otherUserIdDto);
const user = await this.userRepository.unBlockUser(
myUserIdDto,
otherUserIdDto,
);

return user.iBlockUsers;
}

async reportUser(
Expand Down Expand Up @@ -219,4 +224,13 @@ export class UserService {
}
return { sendLightningSuccess: true };
}

@returnValueToDto(UserProfileDto)
async getMyBlockUser(myUserIdDto: UserIdDto) {
console.log('check');
const user = await this.userRepository.findOneByUserId(myUserIdDto);
console.log(user);

return user.iBlockUsers;
}
}
7 changes: 4 additions & 3 deletions src/common/consts/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,10 @@ enum NOTIFICATION_POST_TYPE {

//카테고리 타입 한글로
enum QUESTION_FIND_FILTER_TYPE {
NOTANSWERED = 'NOTANSWERED', //대학교
OLDORDER = 'OLDORDER', //공연장
NEWORDER = 'NEWORDER', //한강공원
NOTANSWERED = 'NOTANSWERED', // 답변못받은거
OLDORDER = 'OLDORDER', //오래된순
NEWORDER = 'NEWORDER', //최신순
RECENT = 'RECENT', //최신순
}

enum USER_LEVEL_TYPE {
Expand Down
17 changes: 17 additions & 0 deletions src/repositories/question.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ export class QuestionRepository {
.lean<Question[]>({ defaults: true });
}

async getRecent2Questions(
roomIdDto: RoomIdDto,
blockUserListDto: BlockedUserDto,
): Promise<Question[]> {
return await this.questionModel
.find({
room: roomIdDto.roomId,
user: { $nin: blockUserListDto.blockedUsers },
})
.sort({ createdAt: -1 })
.limit(2)
.populate({
path: 'user',
select: UserProfileSelect,
})
.lean<Question[]>({ defaults: true });
}
async getQuestionsByRoomIdNotAnswerd(
roomIdDto: RoomIdDto,
blockUserListDto: BlockedUserDto,
Expand Down

0 comments on commit ec255ae

Please sign in to comment.