Skip to content

Commit

Permalink
Merge pull request #51 from depromeet/dev
Browse files Browse the repository at this point in the history
기능개선 , 유저 리워드 기능 추가
  • Loading branch information
ImNM authored May 10, 2022
2 parents b238d9e + ec255ae commit 18379d7
Show file tree
Hide file tree
Showing 13 changed files with 297 additions and 21 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: 15 additions & 0 deletions src/apis/users/dto/sendLigningSuccessDto.res.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose } from 'class-transformer';

export class SendLightningSuccessDtoResDto {
constructor(sendLightningSuccess: boolean) {
this.sendLightningSuccess = sendLightningSuccess;
}
@ApiProperty({
type: Boolean,
default: false,
description: '번개보낸 성공여부',
})
@Expose()
sendLightningSuccess: boolean;
}
34 changes: 32 additions & 2 deletions src/apis/users/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import { UserProfileDto } from 'src/common/dtos/UserProfile.dto';
import { ReportResultDtoResDto } from './dto/reportResultDto.res.dto';
import { CanChangeNicknameResDto } from './dto/canChangeNickname.res.dto';
import { NewAlarmStateResDto } from './dto/newAlarmState.res.dto';
import { SendLightningSuccessDtoResDto } from './dto/sendLigningSuccessDto.res.dto';

@ApiTags('user')
@Controller('user')
Expand Down Expand Up @@ -67,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 @@ -92,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 @@ -102,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 Expand Up @@ -153,4 +165,22 @@ export class UserController {
toggleAppAlarm(@ReqUser() user: User) {
return this.userService.toggleAlarmAlarm(user.userIdDto);
}

@ApiOperation({
summary: '상대방에게 번개를 보낸다',
})
@Post(':userId/lightning')
@ApiResponse({
status: 201,
description: '요청 성공시',
type: SendLightningSuccessDtoResDto,
})
@ApiResponse({
status: 201,
description: '이미 요청되었으면하루에 한번 ',
type: SendLightningSuccessDtoResDto,
})
sendLightningToUser(@ReqUser() user: User, @Param() userIdDto: UserIdDto) {
return this.userService.sendLightningToUser(user.userIdDto, userIdDto);
}
}
10 changes: 9 additions & 1 deletion src/apis/users/user.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { forwardRef, Module } from '@nestjs/common';
import { MongooseModule } from '@nestjs/mongoose';
import { AuthModule } from 'src/auth/auth.module';
import { Lightning, LightningSchema } from 'src/models/lightning.model';
import { Report, ReportSchema } from 'src/models/report.model';
import { User, UserSchema } from 'src/models/user.model';
import { LightningRepository } from 'src/repositories/lightning.repository';
import { ReportRepository } from 'src/repositories/report.repository';
import { UserRepository } from 'src/repositories/user.repository';
import { UserController } from './user.controller';
Expand All @@ -13,11 +15,17 @@ import { UserService } from './user.service';
MongooseModule.forFeature([
{ name: User.name, schema: UserSchema },
{ name: Report.name, schema: ReportSchema },
{ name: Lightning.name, schema: LightningSchema },
]),
forwardRef(() => AuthModule),
],
controllers: [UserController],
providers: [UserRepository, UserService, ReportRepository],
providers: [
UserRepository,
UserService,
ReportRepository,
LightningRepository,
],
exports: [UserService, ReportRepository, UserRepository],
})
export class UserModule {}
73 changes: 67 additions & 6 deletions src/apis/users/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ import { NewAlarmStateResDto } from './dto/newAlarmState.res.dto';
import { UserProfileDto } from 'src/common/dtos/UserProfile.dto';
import { BlockedUserDto } from 'src/common/dtos/BlockedUserList.dto';
import { AuthService } from 'src/auth/auth.service';
import { LightningRepository } from 'src/repositories/lightning.repository';
import { SendLightningSuccessDtoResDto } from './dto/sendLigningSuccessDto.res.dto';
import {
USER_LEVELUP_COUNT_TYPE,
USER_LEVEL_TYPE,
} from 'src/common/consts/enum';

@Injectable()
export class UserService {
Expand All @@ -26,6 +32,7 @@ export class UserService {
private reportRepository: ReportRepository,
@Inject(forwardRef(() => AuthService))
private authService: AuthService,
private lightnignRepository: LightningRepository,
) {}

private checkBlocked(userIdDto: UserIdDto, blockedUserDto: BlockedUserDto) {
Expand Down Expand Up @@ -57,17 +64,19 @@ export class UserService {
updateProfileReqDto: UpdateProfileReqDto,
): Promise<User> {
// auto 시리얼 라이징

//TODO : 닉네임 변경시에 한번더 밸리데이션? 내프로필 정보랑 닉네임 일치하면 변경하고..
return await this.userRepository.updateProfile(
userIdDto,
updateProfileReqDto,
);
}

@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 @@ -88,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 @@ -172,4 +186,51 @@ export class UserService {
const appAlarm = await this.userRepository.toggleApptAlarm(myUserIdDto);
return { appAlarm: appAlarm };
}

@returnValueToDto(SendLightningSuccessDtoResDto)
async sendLightningToUser(
sender: UserIdDto,
receive: UserIdDto,
): Promise<SendLightningSuccessDtoResDto> {
const checkReportExist = this.lightnignRepository.findOneLightningByUserId(
sender,
receive,
);
if (checkReportExist) {
return { sendLightningSuccess: false };
}

const expireAt = new Date();
// utc 한국시간 기준으로 자정으로 설정
expireAt.setUTCHours(15, 0, 0, 0);
// expireAt.setHours()
await this.lightnignRepository.saveLighting(sender, receive, expireAt);
const addUserScore = await this.userRepository.addUserLigthningScore(
receive,
);

switch (addUserScore.lightningScore) {
case USER_LEVELUP_COUNT_TYPE.LEVEL1:
await this.userRepository.levelUpUser(receive, USER_LEVEL_TYPE.LEVEL1);
break;
case USER_LEVELUP_COUNT_TYPE.LEVEL2:
await this.userRepository.levelUpUser(receive, USER_LEVEL_TYPE.LEVEL2);
break;
case USER_LEVELUP_COUNT_TYPE.LEVEL3:
await this.userRepository.levelUpUser(receive, USER_LEVEL_TYPE.LEVEL3);
break;
default:
break;
}
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;
}
}
23 changes: 20 additions & 3 deletions src/common/consts/enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,29 @@ 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 {
LEVEL0 = 0, //대학교
LEVEL1 = 1, //공연장
LEVEL2 = 2, //한강공원
LEVEL3 = 2, //한강공원
}

enum USER_LEVELUP_COUNT_TYPE {
LEVEL0 = 0, //대학교
LEVEL1 = 5, //공연장
LEVEL2 = 25, //한강공원
LEVEL3 = 100, //한강공원
}

export {
USER_LEVELUP_COUNT_TYPE,
USER_LEVEL_TYPE,
QUESTION_FIND_FILTER_TYPE,
getEnumToArray,
getEnumTypeValues,
Expand Down
14 changes: 11 additions & 3 deletions src/common/dtos/UserProfile.dto.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose, Transform, Type } from 'class-transformer';
import { Profile } from 'src/models/user.model';
import { Profile, User } from 'src/models/user.model';
import { Types } from 'mongoose';
import { TransformObjectIdToString } from '../decorators/Expose.decorator';

export class UserProfileDto {
constructor(user) {
constructor(user: User) {
if (user) {
this._id = user._id;
this.nickname = user.nickname;
this.profile = user.profile;
this.level = user.level;
}
}
@ApiProperty({ type: String, example: '626cf238b51596721c21289b' })
Expand All @@ -26,6 +27,13 @@ export class UserProfileDto {
@Type(() => Profile)
@Expose()
profile: Profile;

@ApiProperty({
type: Number,
description: '유저의 확성기 레벨',
})
@Expose()
level: number;
}

export const UserProfileSelect = { _id: 1, nickname: 1, profile: 1 };
export const UserProfileSelect = { _id: 1, nickname: 1, profile: 1, level: 1 };
Loading

0 comments on commit 18379d7

Please sign in to comment.