Skip to content

Commit

Permalink
🚀 feat(room): 채팅방 내부 사이드바 열었을 때 유저 리스트만 불러오는 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ImNM committed Jun 1, 2022
1 parent 10b42f3 commit 6bd2a4d
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/apis/rooms/dto/roomUserList.res.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Room } from 'src/models/room.model';
import { PickType } from '@nestjs/swagger';

export class RoomUserListDto extends PickType(Room, [
'userList',
'userCount',
] as const) {}
26 changes: 20 additions & 6 deletions src/apis/rooms/rooms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { ResFavoriteToggleDto } from './dto/FavoriteToggle.res.dto';
import { Room } from 'src/models/room.model';
import { ResShortCutRoomDto } from 'src/common/dtos/shortCutRoomInfo.res.dto';
import { MyRoomInfoDto } from './dto/myRoomInfo.res.dto';
import { RoomUserListDto } from './dto/roomUserList.res.dto';

@ApiTags('rooms')
@Controller('rooms')
Expand Down Expand Up @@ -135,6 +136,25 @@ export class RoomsController {
return this.roomsService.pullUserFromRoom(roomId, user.userIdDto);
}

@ApiOperation({
summary: '채팅방 내부에서 사이드바를 열었을때 불러오는 유저 리스트',
})
@Get(':roomId/userList')
@ApiResponse({
status: 200,
description: '요청 성공시',
type: RoomUserListDto,
})
@ApiResponse({
status: 400,
description:
'유저가 들어간 방 정보 없음 ,유저가 들어간 방정보와 파라미터가 일치하지 않음',
})
getRoomUserList(@Param() roomId: RoomIdDto, @ReqUser() user: User) {
// 조인 룸시에 다른 룸에서 자동으로 나가져야함
return this.roomsService.findRoomInUserList(roomId, user);
}

@ApiOperation({ summary: '유저가 룸을 즐겨찾기에서 빼고넣는다' })
@ApiResponse({
status: 200,
Expand Down Expand Up @@ -162,10 +182,4 @@ export class RoomsController {
turnOnChatAlarm(@Param() roomId: RoomIdDto, @ReqUser() user: User) {
return this.roomsService.toggleChatAlarm(user.userIdDto);
}

// @ApiOperation({ summary: '유저가 채팅 알림을 끈다' })
// @Delete(':roomId/alarm')
// turnOffChatAlarm(@Param() roomId: RoomIdDto, @ReqUser() user: User) {
// return this.roomsService.turnOffChatAlarm(user.userIdDto);
// }
}
25 changes: 25 additions & 0 deletions src/apis/rooms/rooms.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { ResFindRoomDto } from './dto/find-room.res.dto copy';
import { ResFindOneRoomDto } from './dto/findOne-room.res.dto';
import { LeftRoomResultResDto } from './dto/leftRoomResult.res.dto';
import { MyRoomInfoDto } from './dto/myRoomInfo.res.dto';
import { RoomUserListDto } from './dto/roomUserList.res.dto';

@Injectable()
export class RoomsService {
Expand Down Expand Up @@ -310,4 +311,28 @@ export class RoomsService {
console.log('asdfasdfa');
return await this.roomRepository.getPopularRooms();
}

@returnValueToDto(RoomUserListDto)
async findRoomInUserList(
roomIdDto: RoomIdDto,
user: User,
// userIdDto: UserIdDto,
// blockUserListDto: BlockedUserDto,
) {
if (user.myRoom == null) {
throw new BadRequestException('유저가 들어간 방 정보 없음');
}
if (!user.myRoom._id.equals(roomIdDto.roomId)) {
throw new BadRequestException(
'유저가 들어간 방정보와 파라미터가 일치하지 않음',
);
}
const room = await this.roomRepository.findOneByRoomId(roomIdDto);

const filteredUserList = this.filterRemoveBlockedUserFromUserList(
room.userList,
user.blockedUserDto,
);
return { userList: filteredUserList, userCount: filteredUserList.length };
}
}
4 changes: 4 additions & 0 deletions src/models/room.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export class Room {
required: true,
type: [{ type: Types.ObjectId, ref: 'User' }],
})
@ApiProperty({
type: [UserProfileDto],
title: '방에들어간 유저 리스트 정보',
})
@IsNotEmpty()
@IsArray()
@Transform((value) => value.obj.userList, { toClassOnly: true })
Expand Down

0 comments on commit 6bd2a4d

Please sign in to comment.