Skip to content

Commit

Permalink
Merge pull request #44 from depromeet/dev
Browse files Browse the repository at this point in the history
정지, 차단 기능 추가
  • Loading branch information
ImNM authored May 6, 2022
2 parents a5fbae4 + 507b41f commit b238d9e
Show file tree
Hide file tree
Showing 22 changed files with 366 additions and 75 deletions.
16 changes: 12 additions & 4 deletions src/apis/letter/letter.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { LetterRoomDto } from './dto/LetterRoom.res.dto';
import { LetterRoomIdDto } from 'src/common/dtos/LetterRoomId.dto';
import { ResLetterDto } from './dto/Letter.res.dto';
import { SuccessInterceptor } from 'src/common/interceptors/sucess.interceptor';
import { BlockedUserDto } from 'src/common/dtos/BlockedUserList.dto';

@ApiTags('letters')
@Controller('letters')
Expand All @@ -51,6 +52,10 @@ export class LetterController {
description: '요청 성공시',
type: ResLetterDto,
})
@ApiResponse({
status: 400,
description: '차단된 유저 ,또는 없는 유저일경우',
})
@Post(':userId')
sendLetterToReciever(
@Query() receiver: UserIdDto,
Expand All @@ -61,6 +66,7 @@ export class LetterController {
return this.letterService.sendLetterToReciever(
twoUserList,
messageStringDto,
user.blockedUserDto,
);
}

Expand All @@ -78,7 +84,7 @@ export class LetterController {
) {
return this.letterService.getLettersByRoomId(
letterRoomIdDto,
new UserIdDto(user._id),
user.userIdDto,
);
}

Expand All @@ -91,9 +97,10 @@ export class LetterController {
@Get('')
async getLetterRooms(@ReqUser() user: User) {
const list = await this.letterService.getRoomsByMyUserId(
new UserIdDto(user._id),
user.userIdDto,
user.blockedUserDto,
);
console.log(instanceToPlain(list[0]));

return list;
}

Expand All @@ -110,7 +117,8 @@ export class LetterController {
) {
return this.letterService.leaveLetterRoomByRoomId(
letterRoomIdDto,
new UserIdDto(user._id),
user.userIdDto,
user.blockedUserDto,
);
}
}
20 changes: 18 additions & 2 deletions src/apis/letter/letter.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { BadRequestException, Injectable, Type } from '@nestjs/common';
import { ObjectId, Types } from 'mongoose';
import { CATEGORY_TYPE, FIND_ROOM_FILTER_TYPE } from 'src/common/consts/enum';
import { BlockedUserDto } from 'src/common/dtos/BlockedUserList.dto';
import { LetterRoomIdDto } from 'src/common/dtos/LetterRoomId.dto';
import { MongoId } from 'src/common/dtos/MongoId.dto';
import { RoomIdDto } from 'src/common/dtos/RoomId.dto';
Expand All @@ -24,10 +25,20 @@ export class LetterService {
private readonly userRepository: UserRepository,
) {}

private checkBlocked(userIdDto: UserIdDto, blockedUserDto: BlockedUserDto) {
// console.log('asdfasdfasdfasdfasdf', userIdDto.userId);
if (blockedUserDto.blockedUsers.find((id) => id.equals(userIdDto.userId))) {
throw new BadRequestException('차단된 유저입니다.');
}
}

async sendLetterToReciever(
twoUserList: TwoUserListDto,
messageStringDto: MessageStringDto,
blockedUserDto: BlockedUserDto,
) {
this.checkBlocked(new UserIdDto(twoUserList.recevier), blockedUserDto);

if (twoUserList.userList[0].equals(twoUserList.userList[1])) {
throw new BadRequestException('유저 아이디가 같음');
}
Expand Down Expand Up @@ -70,9 +81,13 @@ export class LetterService {
return filterMyLetters;
}

async getRoomsByMyUserId(myUserId: UserIdDto): Promise<LetterRoomDto[]> {
async getRoomsByMyUserId(
myUserId: UserIdDto,
blockedUserDto: BlockedUserDto,
): Promise<LetterRoomDto[]> {
const myLetterRooms = await this.letterRepository.getRoomsByMyUserId(
myUserId,
blockedUserDto,
);
console.log(myLetterRooms);

Expand All @@ -85,6 +100,7 @@ export class LetterService {
async leaveLetterRoomByRoomId(
letterRoomIdDto: LetterRoomIdDto,
myUserId: UserIdDto,
blockedUserDto: BlockedUserDto,
): Promise<LetterRoomDto[]> {
await this.checkRoomJoin(myUserId, letterRoomIdDto);

Expand All @@ -100,7 +116,7 @@ export class LetterService {
// 길이가 2가되면 두명다 나간거므로 삭제 진행
await this.deleteRoomAndLetters(letterRoomIdDto);
}
return this.getRoomsByMyUserId(myUserId);
return this.getRoomsByMyUserId(myUserId, blockedUserDto);
}

private async deleteRoomAndLetters(letterRoomIdDto: LetterRoomIdDto) {
Expand Down
2 changes: 2 additions & 0 deletions src/apis/questions/questions.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export class QuestionsController {
return this.questionService.findQuestions(
user.userIdDto,
questionFindRequestDto,
user.blockedUserDto,
);
}

Expand Down Expand Up @@ -88,6 +89,7 @@ export class QuestionsController {
return await this.questionService.findQuestionById(
user.userIdDto,
questionIdDto,
user.blockedUserDto,
);
}

Expand Down
28 changes: 26 additions & 2 deletions src/apis/questions/questions.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { BadRequestException, Injectable } from '@nestjs/common';
import { plainToClass, plainToInstance } from 'class-transformer';
import { QUESTION_FIND_FILTER_TYPE } from 'src/common/consts/enum';
import { returnValueToDto } from 'src/common/decorators/returnValueToDto.decorator';
import { BlockedUserDto } from 'src/common/dtos/BlockedUserList.dto';
import { CommentIdDto } from 'src/common/dtos/CommentId.dto';
import { QuestionIdDto } from 'src/common/dtos/QuestionId.dto';
import { RoomIdDto } from 'src/common/dtos/RoomId.dto';
Expand All @@ -22,6 +23,17 @@ export class QuestionsService {
private questionRepository: QuestionRepository,
) {}

private filterRemoveBlockedUserFromCommentList(
commentList: Comment[],
blockedUserDto: BlockedUserDto,
): Comment[] {
// 값이 없으면 언디파인드임.
return commentList.filter(
(comment) =>
!blockedUserDto.blockedUsers.find((e) => e.equals(comment.user._id)),
);
}

// always should check if i join the room.
private async checkMyRoom(userIdDto: UserIdDto): Promise<RoomIdDto> {
const user = await this.userRepository.findOneByUserId(userIdDto);
Expand All @@ -35,6 +47,7 @@ export class QuestionsService {
async findQuestions(
userIdDto: UserIdDto,
questionFindRequestDto: QuestionFindRequestDto,
blockUserListDto: BlockedUserDto,
): Promise<QuestionListShowDto[]> {
// 내 아이디 정보를 넣어서 비교로직 추가가 필요함.
const myRoomIdDto = await this.checkMyRoom(userIdDto);
Expand All @@ -43,16 +56,19 @@ export class QuestionsService {
case QUESTION_FIND_FILTER_TYPE.NOTANSWERED:
result = await this.questionRepository.getQuestionsByRoomIdNotAnswerd(
myRoomIdDto,
blockUserListDto,
);
break;
case QUESTION_FIND_FILTER_TYPE.OLDORDER:
result = await this.questionRepository.getQuestionsByRoomIdOldOrder(
myRoomIdDto,
blockUserListDto,
);
break;
case QUESTION_FIND_FILTER_TYPE.NEWORDER:
result = await this.questionRepository.getQuestionsByRoomIdNewOrder(
myRoomIdDto,
blockUserListDto,
);

break;
Expand All @@ -66,7 +82,11 @@ export class QuestionsService {
}

@returnValueToDto(QuestionShowDto)
async findQuestionById(userIdDto: UserIdDto, questionIdDto: QuestionIdDto) {
async findQuestionById(
userIdDto: UserIdDto,
questionIdDto: QuestionIdDto,
blockUserListDto: BlockedUserDto,
) {
// 내 아이디 정보를 넣어서 비교로직 추가가 필요함.
await this.checkMyRoom(userIdDto);
const question = await this.questionRepository.getQuestionByQuestionId(
Expand All @@ -75,8 +95,12 @@ export class QuestionsService {
if (!question) {
throw new BadRequestException('질문 없음');
}
question.myUserId = userIdDto.userId;

question.myUserId = userIdDto.userId;
question.commentList = this.filterRemoveBlockedUserFromCommentList(
question.commentList,
blockUserListDto,
);
return question;
}

Expand Down
18 changes: 11 additions & 7 deletions src/apis/rooms/rooms.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export class RoomsController {
console.log(user);
// console.log(FindRoomDto);
// 경도lng 위도lat
return this.roomsService.findRoom(FindRoomDto, new UserIdDto(user._id));
return this.roomsService.findRoom(FindRoomDto, user.userIdDto);
}
//TODO : 안읽은 채팅 갯수 ?
@ApiOperation({ summary: '(채팅탭용)내 룸 정보 가져옴' })
Expand All @@ -94,7 +94,7 @@ export class RoomsController {
getMyRoomShortCutInfo(@ReqUser() user: User) {
// console.log(FindRoomDto);
// 경도lng 위도lat
return this.roomsService.getMyRoomShortCutInfo(new UserIdDto(user._id));
return this.roomsService.getMyRoomShortCutInfo(user.userIdDto);
}

@ApiOperation({ summary: '(채팅탭용)내가 즐겨찾기한 채팅방 뽑아옴' })
Expand Down Expand Up @@ -133,14 +133,18 @@ export class RoomsController {
})
joinRoom(@Param() roomId: RoomIdDto, @ReqUser() user: User) {
// 조인 룸시에 다른 룸에서 자동으로 나가져야함
return this.roomsService.addUserToRoom(roomId, new UserIdDto(user._id));
return this.roomsService.addUserToRoom(
roomId,
user.userIdDto,
user.blockedUserDto,
);
}

@ApiOperation({ summary: '유저가 채팅방에서 아예 나가버릴때' })
@Delete(':roomId/join')
outRoom(@Param() roomId: RoomIdDto, @ReqUser() user: User) {
// 조인 룸시에 다른 룸에서 자동으로 나가져야함
return this.roomsService.pullUserFromRoom(roomId, new UserIdDto(user._id));
return this.roomsService.pullUserFromRoom(roomId, user.userIdDto);
}

@ApiOperation({ summary: '유저가 룸을 즐겨찾기에서 빼고넣는다' })
Expand All @@ -156,7 +160,7 @@ export class RoomsController {
) {
return this.roomsService.toggleRoomToUserFavoriteList(
roomId,
new UserIdDto(user._id),
user.userIdDto,
);
}

Expand All @@ -168,12 +172,12 @@ export class RoomsController {
type: ResChatAlarmToggleDto,
})
turnOnChatAlarm(@Param() roomId: RoomIdDto, @ReqUser() user: User) {
return this.roomsService.toggleChatAlarm(new UserIdDto(user._id));
return this.roomsService.toggleChatAlarm(user.userIdDto);
}

// @ApiOperation({ summary: '유저가 채팅 알림을 끈다' })
// @Delete(':roomId/alarm')
// turnOffChatAlarm(@Param() roomId: RoomIdDto, @ReqUser() user: User) {
// return this.roomsService.turnOffChatAlarm(new UserIdDto(user._id));
// 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 @@ -3,10 +3,12 @@ import { plainToInstance } from 'class-transformer';
import { ObjectId, Types } from 'mongoose';
import { CATEGORY_TYPE, FIND_ROOM_FILTER_TYPE } from 'src/common/consts/enum';
import { returnValueToDto } from 'src/common/decorators/returnValueToDto.decorator';
import { BlockedUserDto } from 'src/common/dtos/BlockedUserList.dto';
import { MongoId } from 'src/common/dtos/MongoId.dto';
import { RoomIdDto } from 'src/common/dtos/RoomId.dto';
import { ResShortCutRoomDto } from 'src/common/dtos/shortCutRoomInfo.res.dto';
import { UserIdDto } from 'src/common/dtos/UserId.dto';
import { UserProfileDto } from 'src/common/dtos/UserProfile.dto';
import { Room } from 'src/models/room.model';
import { User } from 'src/models/user.model';
import { RoomRepository } from 'src/repositories/room.repository';
Expand All @@ -27,6 +29,15 @@ export class RoomsService {
private readonly userRepository: UserRepository,
) {}

private filterRemoveBlockedUserFromUserList(
userList: UserProfileDto[],
blockedUserDto: BlockedUserDto,
) {
return userList.filter(
(user) => !blockedUserDto.blockedUsers.find((e) => e.equals(user._id)),
);
}

/**
* 룸을 생성할 수 있음 좌표정보, 룸 이름, 반경정보 등이 필요함
* @param createRoomDto
Expand Down Expand Up @@ -96,9 +107,11 @@ export class RoomsService {
* @param userIdDto
* @returns
*/
// 차단 로직 적용필요
async addUserToRoom(
roomIdDto: RoomIdDto,
userIdDto: UserIdDto,
blockUserListDto: BlockedUserDto,
): Promise<ResFindOneRoomDto> {
// 이전 룸에서 빼주는 로직 추가해야함
const user = await this.userRepository.findOneByUserId(userIdDto);
Expand All @@ -117,6 +130,12 @@ export class RoomsService {
: false;
// const isFavoritRoom = user.favoriteRoomList.includes(user.myRoom._id);
const room = await this.roomRepository.findOneByRoomId(roomIdDto);

// 차단 유저아웃
room.userList = this.filterRemoveBlockedUserFromUserList(
room.userList,
blockUserListDto,
);
const result = { ...room, iFavorite, iAlarm: user.chatAlarm };

return plainToInstance(ResFindOneRoomDto, result, {
Expand All @@ -141,6 +160,12 @@ export class RoomsService {
? true
: false;

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

const result = { ...room, iFavorite, iAlarm: true };
// console.log(result);
return plainToInstance(ResFindOneRoomDto, result, {
Expand Down
11 changes: 9 additions & 2 deletions src/apis/users/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,17 @@ export class UserController {
description: '요청 성공시',
type: UserProfileDto,
})
@ApiResponse({
status: 400,
description: '차단된 유저 ,또는 없는 유저일경우',
})
@Get(':userId')
async getOtherUserInfo(@Param() UserIdDto: UserIdDto) {
async getOtherUserInfo(@Param() UserIdDto: UserIdDto, @ReqUser() user: User) {
// findOneByUserId
return await this.userService.getOtherUserInfo(UserIdDto);
return await this.userService.getOtherUserInfo(
UserIdDto,
user.blockedUserDto,
);
}

@ApiOperation({ summary: '상대방 유저를 차단한다' })
Expand Down
4 changes: 2 additions & 2 deletions src/apis/users/user.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import { UserService } from './user.service';
forwardRef(() => AuthModule),
],
controllers: [UserController],
providers: [UserService, UserRepository, ReportRepository],
exports: [UserService, UserRepository, ReportRepository],
providers: [UserRepository, UserService, ReportRepository],
exports: [UserService, ReportRepository, UserRepository],
})
export class UserModule {}
Loading

0 comments on commit b238d9e

Please sign in to comment.