From 3ed0d612da7ad2b4264543c682b6e94122d1fc70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E1=84=8B=E1=85=B5=E1=84=8E=E1=85=A1=E1=86=AB=E1=84=8C?= =?UTF-8?q?=E1=85=B5=E1=86=AB?= Date: Mon, 1 Aug 2022 00:19:24 +0900 Subject: [PATCH] =?UTF-8?q?:rocket:=20feat(room)=20:=20subtitle=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80,=20=EC=B9=B4=ED=85=8C=EA=B3=A0=EB=A6=AC=20?= =?UTF-8?q?=EC=88=98=EC=A0=95,=EC=82=AD=EC=A0=9C=20api=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=EC=97=90=EC=84=9C=20=EC=97=86?= =?UTF-8?q?=EC=95=B0=20(=20=EB=B3=B4=EC=95=88=20)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/apis/rooms/dto/find-room.res.dto copy.ts | 1 + src/apis/rooms/dto/findOne-room.res.dto.ts | 3 +- src/apis/rooms/dto/myRoomInfo.res.dto.ts | 17 +- src/apis/utils/utils.controller.ts | 49 +++--- src/common/dtos/shortCutRoomInfo.res.dto.ts | 13 +- src/models/room.model.ts | 39 +++-- src/repositories/room.repository.ts | 10 +- src/repositories/user.repository.ts | 169 ++++++++++--------- 8 files changed, 161 insertions(+), 140 deletions(-) diff --git a/src/apis/rooms/dto/find-room.res.dto copy.ts b/src/apis/rooms/dto/find-room.res.dto copy.ts index 4f2b3fc..dc188d8 100644 --- a/src/apis/rooms/dto/find-room.res.dto copy.ts +++ b/src/apis/rooms/dto/find-room.res.dto copy.ts @@ -11,6 +11,7 @@ export class ResFindRoomDto extends PickType(Room, [ 'userList', 'geometry', 'userCount', + 'subtitle' ] as const) { @Expose({ toClassOnly: true }) @Exclude({ toPlainOnly: true }) diff --git a/src/apis/rooms/dto/findOne-room.res.dto.ts b/src/apis/rooms/dto/findOne-room.res.dto.ts index 532ef19..63b65ac 100644 --- a/src/apis/rooms/dto/findOne-room.res.dto.ts +++ b/src/apis/rooms/dto/findOne-room.res.dto.ts @@ -10,6 +10,7 @@ export class ResFindOneRoomDto extends PickType(Room, [ 'userList', 'geometry', 'userCount', + 'subtitle' ] as const) { @ApiProperty({ description: '내가 즐겨찾기 했는지', type: Boolean }) @Expose() @@ -36,7 +37,7 @@ export class ResFindOneRoomDto extends PickType(Room, [ iAlarm: boolean; @ApiProperty({ description: '유저명수' }) - @Transform((value) => value.obj.userList.length, { toPlainOnly: true }) + @Transform(value => value.obj.userList.length, { toPlainOnly: true }) @Expose() userCount: number; // get userCount(): number { diff --git a/src/apis/rooms/dto/myRoomInfo.res.dto.ts b/src/apis/rooms/dto/myRoomInfo.res.dto.ts index 641dee1..02032e9 100644 --- a/src/apis/rooms/dto/myRoomInfo.res.dto.ts +++ b/src/apis/rooms/dto/myRoomInfo.res.dto.ts @@ -10,9 +10,9 @@ import { Geometry } from 'src/models/room.model'; export class MyRoomInfoDto { @ApiProperty({ description: '방의 고유 아이디', - type: String, + type: String }) - @Transform((value) => value.obj._id, { toClassOnly: true }) + @Transform(value => value.obj._id, { toClassOnly: true }) @TransformObjectIdToString({ toClassOnly: true }) @Expose() _id: string; @@ -29,10 +29,19 @@ export class MyRoomInfoDto { @Expose() userCount: number; + @ApiProperty({ + description: '채팅방 부제목', + type: String, + nullable: true, + default: null + }) + @Expose() + subtitle: string; + //추가됨 @ApiProperty({ description: '아직 읽지 않은 채팅 숫자 0이면 표시안하시면 됩니다.', - default: 0, + default: 0 }) @Expose() notReadChatCount: number; @@ -41,7 +50,7 @@ export class MyRoomInfoDto { description: '최신 채팅 정보 채팅 dto로 하나 또는 null', type: Chat, nullable: true, - default: null, + default: null }) @Type(() => Chat) @Expose() diff --git a/src/apis/utils/utils.controller.ts b/src/apis/utils/utils.controller.ts index f770bf3..3be8fbc 100644 --- a/src/apis/utils/utils.controller.ts +++ b/src/apis/utils/utils.controller.ts @@ -1,16 +1,5 @@ -import { - Body, - Controller, - Delete, - Get, - Post, - UseGuards, -} from '@nestjs/common'; -import { - ApiBearerAuth, - ApiOperation, - ApiTags, -} from '@nestjs/swagger'; +import { Body, Controller, Delete, Get, Post, UseGuards } from '@nestjs/common'; +import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; import { JwtAuthGuard } from 'src/auth/guards/jwt.guard'; import { CategoryDto } from 'src/common/dtos/Category.dto'; import { CategoryIdDto } from 'src/common/dtos/CategoryId.dto'; @@ -21,29 +10,29 @@ import { UtilsService } from './utils.service'; @ApiBearerAuth('accessToken') @UseGuards(JwtAuthGuard) export class UtilsController { - constructor(private readonly utilsService: UtilsService) { } + constructor(private readonly utilsService: UtilsService) {} @ApiOperation({ - summary: '카테고리 정보', + summary: '카테고리 정보' }) @Get('category') async getCategory() { - return await this.utilsService.findAllCategory() + return await this.utilsService.findAllCategory(); } - @ApiOperation({ - summary: '카테고리 추가', - }) - @Post('category') - async createCategory(@Body() categoryDto: CategoryDto): Promise { - return await this.utilsService.createCategory(categoryDto) - } + // @ApiOperation({ + // summary: '카테고리 추가', + // }) + // @Post('category') + // async createCategory(@Body() categoryDto: CategoryDto): Promise { + // return await this.utilsService.createCategory(categoryDto) + // } - @ApiOperation({ - summary: '카테고리 삭제', - }) - @Delete('category') - async deleteCategory(@Body() categoryIdDto: CategoryIdDto) { - return await this.utilsService.deleteCategory(categoryIdDto) - } + // @ApiOperation({ + // summary: '카테고리 삭제', + // }) + // @Delete('category') + // async deleteCategory(@Body() categoryIdDto: CategoryIdDto) { + // return await this.utilsService.deleteCategory(categoryIdDto) + // } } diff --git a/src/common/dtos/shortCutRoomInfo.res.dto.ts b/src/common/dtos/shortCutRoomInfo.res.dto.ts index ddc5495..0bfabe8 100644 --- a/src/common/dtos/shortCutRoomInfo.res.dto.ts +++ b/src/common/dtos/shortCutRoomInfo.res.dto.ts @@ -8,9 +8,9 @@ import { TransformObjectIdToString } from '../decorators/Expose.decorator'; export class ResShortCutRoomDto { @ApiProperty({ description: '방의 고유 아이디', - type: String, + type: String }) - @Transform((value) => value.obj._id, { toClassOnly: true }) + @Transform(value => value.obj._id, { toClassOnly: true }) @TransformObjectIdToString({ toClassOnly: true }) @Expose() _id: string; @@ -32,6 +32,15 @@ export class ResShortCutRoomDto { @Exclude({ toPlainOnly: true }) geometry: Geometry; + @ApiProperty({ + description: '채팅방 부제목', + type: String, + nullable: true, + default: null + }) + @Expose() + subtitle: string; + @ApiProperty({ description: '위도 가로선', type: Number }) @Expose() get lat(): number { diff --git a/src/models/room.model.ts b/src/models/room.model.ts index 954f16a..5a4321b 100644 --- a/src/models/room.model.ts +++ b/src/models/room.model.ts @@ -5,7 +5,7 @@ import { IsNotEmpty, IsNumber, IsObject, - IsString, + IsString } from 'class-validator'; import { Prop, Schema, SchemaFactory, SchemaOptions } from '@nestjs/mongoose'; import { CATEGORY_TYPE } from 'src/common/consts/enum'; @@ -18,7 +18,7 @@ import { UserProfileDto } from 'src/common/dtos/UserProfile.dto'; const options: SchemaOptions = { // rooms default 로 s 붙여지는데 디폴트로가는게 좋을것 같아요! (이찬진) collection: 'room', - timestamps: true, + timestamps: true }; @Schema({ _id: false }) @@ -40,24 +40,24 @@ export class Geometry { export class Room { @ApiProperty({ description: '유저의 고유아이디', - type: String, + type: String }) // 시리얼 라이제이션 할때 사용 @TransformObjectIdToString({ toPlainOnly: true }) - @Transform((value) => value.obj._id, { toClassOnly: true }) + @Transform(value => value.obj._id, { toClassOnly: true }) @Type(() => Types.ObjectId) @Expose() _id: Types.ObjectId; @Prop({ required: true, - type: String, + type: String }) @ApiProperty({ type: String, title: '채팅방 이름', description: '채팅방의 이름입니다', - example: '홍익대학교', + example: '홍익대학교' }) @IsNotEmpty() @IsString() @@ -66,14 +66,14 @@ export class Room { @Prop({ required: true, - enum: CATEGORY_TYPE, + enum: CATEGORY_TYPE }) @ApiProperty({ enum: CATEGORY_TYPE, title: '카테고리', description: '카테고리를 나타내는 상태입니다. 기획안 따라 지속적으로 추가할 예정입니다.', - example: 'UNIVERCITY', + example: 'UNIVERCITY' }) @IsNotEmpty() @IsEnum(CATEGORY_TYPE) @@ -85,7 +85,7 @@ export class Room { type: Number, title: '반경정보', description: '미터 단위의 반경정보입니다', - example: 2000, + example: 2000 }) @IsNotEmpty() @IsNumber() @@ -94,15 +94,15 @@ export class Room { @Prop({ required: true, - type: [{ type: Types.ObjectId, ref: 'User' }], + type: [{ type: Types.ObjectId, ref: 'User' }] }) @ApiProperty({ type: [UserProfileDto], - title: '방에들어간 유저 리스트 정보', + title: '방에들어간 유저 리스트 정보' }) @IsNotEmpty() @IsArray() - @Transform((value) => value.obj.userList, { toClassOnly: true }) + @Transform(value => value.obj.userList, { toClassOnly: true }) @Type(() => UserProfileDto) @Expose() userList: UserProfileDto[]; @@ -115,7 +115,7 @@ export class Room { @IsObject() @Prop({ type: Geometry, - index: '2dsphere', + index: '2dsphere' }) @Type(() => Geometry) @Expose({ toClassOnly: true }) @@ -130,12 +130,15 @@ export class Room { @Expose() userCount: number; - @ApiProperty({ description: '채팅방 부제목' }) - @Prop({ required: false, type: String, default: "" }) - @IsNotEmpty() - @IsString() + @ApiProperty({ + description: '채팅방 부제목', + type: String, + nullable: true, + default: null + }) + @Prop({ required: false, type: String, default: null }) @Expose() - subtitle: string + subtitle: string; } const _RoomSchema = SchemaFactory.createForClass(Room); diff --git a/src/repositories/room.repository.ts b/src/repositories/room.repository.ts index 887722c..8152cc6 100644 --- a/src/repositories/room.repository.ts +++ b/src/repositories/room.repository.ts @@ -61,7 +61,8 @@ export class RoomRepository { userCount: { $size: '$userList' }, radius: 1, distance: 1, - geometry: 1 + geometry: 1, + subtitle: 1 } } // 몽고디비 디폴트 100개임 최대 100개를 뽑아올수있는데 여기서 조정을 해야함 @@ -102,7 +103,8 @@ export class RoomRepository { userCount: { $size: '$userList' }, radius: 1, distance: 1, - geometry: 1 + geometry: 1, + subtitle: 1 } } // 몽고디비 디폴트 100개임 최대 100개를 뽑아올수있는데 여기서 조정을 해야함 @@ -143,7 +145,8 @@ export class RoomRepository { userCount: { $size: '$userList' }, radius: 1, distance: 1, - geometry: 1 + geometry: 1, + subtitle: 1 } } // 몽고디비 디폴트 100개임 최대 100개를 뽑아올수있는데 여기서 조정을 해야함 @@ -234,6 +237,7 @@ export class RoomRepository { name: 1, category: 1, geometry: 1, + subtitle: 1, userCount: { $size: '$userList' } } }, diff --git a/src/repositories/user.repository.ts b/src/repositories/user.repository.ts index 294260d..43f85cb 100644 --- a/src/repositories/user.repository.ts +++ b/src/repositories/user.repository.ts @@ -6,7 +6,7 @@ import { HttpException, BadRequestException, UseInterceptors, - InternalServerErrorException, + InternalServerErrorException } from '@nestjs/common'; import { Model } from 'mongoose'; import { User } from 'src/models/user.model'; @@ -19,7 +19,7 @@ import { ResShortCutRoomDto } from 'src/common/dtos/shortCutRoomInfo.res.dto'; import { STATUS_TYPE, USER_LEVEL_TYPE } from 'src/common/consts/enum'; import { UserFcmInfoDto, - userFcmInfoSelect, + userFcmInfoSelect } from 'src/apis/alarm/dto/userFcmInfo.dto'; import { Types } from 'mongoose'; import { FlagInfoDto } from 'src/apis/users/dto/flagInfo.dto'; @@ -28,20 +28,20 @@ import { FCMUpdateDto } from 'src/apis/users/dto/fcmUpdate.dto'; @Injectable() export class UserRepository { constructor( - @InjectModel(User.name) private readonly userModel: Model, + @InjectModel(User.name) private readonly userModel: Model ) {} async banUser(userIdDto: UserIdDto) { return await this.userModel.findOneAndUpdate( { _id: userIdDto.userId }, - { status: STATUS_TYPE.FORBIDDEN }, + { status: STATUS_TYPE.FORBIDDEN } ); } async unBanuser(userIdDto: UserIdDto) { return await this.userModel.findOneAndUpdate( { _id: userIdDto.userId }, - { status: STATUS_TYPE.NORMAL }, + { status: STATUS_TYPE.NORMAL } ); } @@ -52,8 +52,8 @@ export class UserRepository { status: STATUS_TYPE.SIGNOUT, phoneNumber: null, nickname: '(탈퇴한 사용자)', - FCMToken: '', - }, + FCMToken: '' + } ); } @@ -62,7 +62,7 @@ export class UserRepository { .findOne({ _id: userIdDto.userId }) .populate({ path: 'iBlockUsers', - select: UserProfileSelect, + select: UserProfileSelect }) .populate({ path: 'myRoom', @@ -71,8 +71,9 @@ export class UserRepository { name: 1, category: 1, geometry: 1, - userCount: { $size: '$userList' }, - }, + subtitle: 1, + userCount: { $size: '$userList' } + } }) .lean({ defaults: true }); return user; @@ -96,15 +97,15 @@ export class UserRepository { async updateProfile( userIdDto: UserIdDto, - updateProfileDto: UpdateProfileReqDto, + updateProfileDto: UpdateProfileReqDto ): Promise { return await this.userModel .findOneAndUpdate({ _id: userIdDto.userId }, updateProfileDto, { - new: true, + new: true }) .populate({ path: 'iBlockUsers', - select: UserProfileSelect, + select: UserProfileSelect }) .populate({ path: 'myRoom', @@ -112,17 +113,17 @@ export class UserRepository { _id: 1, name: 1, geometry: 1, - + subtitle: 1, category: 1, - userCount: { $size: '$userList' }, - }, + userCount: { $size: '$userList' } + } }) .lean({ defaults: true }); } async blockUser( myUserIdDto: UserIdDto, - otherUserIdDto: UserIdDto, + otherUserIdDto: UserIdDto ): Promise { // 상대방은 보여지면 안되는 부분에서 나를 추가 await this.userModel.findOneAndUpdate( @@ -130,10 +131,10 @@ export class UserRepository { { $addToSet: { blockedUsers: myUserIdDto.userId, - opBlockedUsers: myUserIdDto.userId, - }, + opBlockedUsers: myUserIdDto.userId + } }, - { new: true }, + { new: true } ); // 내부분은 보여지면 안되는 부분 , 내 차단목록에 추가 return await this.userModel @@ -142,14 +143,14 @@ export class UserRepository { { $addToSet: { blockedUsers: otherUserIdDto.userId, - iBlockUsers: otherUserIdDto.userId, - }, + iBlockUsers: otherUserIdDto.userId + } }, - { new: true }, + { new: true } ) .populate({ path: 'iBlockUsers', - select: UserProfileSelect, + select: UserProfileSelect }) .populate({ path: 'myRoom', @@ -158,8 +159,9 @@ export class UserRepository { name: 1, geometry: 1, category: 1, - userCount: { $size: '$userList' }, - }, + subtitle: 1, + userCount: { $size: '$userList' } + } }) .lean({ defaults: true }); } @@ -209,17 +211,17 @@ export class UserRepository { async unBlockUser( myUserIdDto: UserIdDto, - otherUserIdDto: UserIdDto, + otherUserIdDto: UserIdDto ): Promise { await this.userModel.findOneAndUpdate( { _id: otherUserIdDto.userId }, { $pull: { blockedUsers: myUserIdDto.userId, - opBlockedUsers: myUserIdDto.userId, - }, + opBlockedUsers: myUserIdDto.userId + } }, - { new: true }, + { new: true } ); return await this.userModel .findOneAndUpdate( @@ -227,14 +229,14 @@ export class UserRepository { { $pull: { blockedUsers: otherUserIdDto.userId, - iBlockUsers: otherUserIdDto.userId, - }, + iBlockUsers: otherUserIdDto.userId + } }, - { new: true }, + { new: true } ) .populate({ path: 'iBlockUsers', - select: UserProfileSelect, + select: UserProfileSelect }) .populate({ path: 'myRoom', @@ -243,8 +245,9 @@ export class UserRepository { name: 1, category: 1, geometry: 1, - userCount: { $size: '$userList' }, - }, + subtitle: 1, + userCount: { $size: '$userList' } + } }) .lean({ defaults: true }); } @@ -254,7 +257,7 @@ export class UserRepository { const user = (await this.userModel.findOneAndUpdate( { _id: userIdDto.userId }, [{ $set: { appAlarm: { $eq: [false, '$appAlarm'] } } }], - { new: true }, + { new: true } )) as User; return user.appAlarm; } @@ -268,18 +271,18 @@ export class UserRepository { */ async pushRoomToFavoriteList( userIdDto: UserIdDto, - roomIdDto: RoomIdDto, + roomIdDto: RoomIdDto ): Promise { const user = await this.userModel.findOneAndUpdate( { - _id: userIdDto.userId, + _id: userIdDto.userId }, { $addToSet: { - favoriteRoomList: roomIdDto.roomId, - }, + favoriteRoomList: roomIdDto.roomId + } }, - { new: true }, + { new: true } ); if (!user) { throw new BadRequestException('user does not exist'); @@ -296,18 +299,18 @@ export class UserRepository { */ async pullRoomToFavoriteList( userIdDto: UserIdDto, - roomIdDto: RoomIdDto, + roomIdDto: RoomIdDto ): Promise { const user = await this.userModel.findOneAndUpdate( { - _id: userIdDto.userId, + _id: userIdDto.userId }, { $pull: { - favoriteRoomList: roomIdDto.roomId, - }, + favoriteRoomList: roomIdDto.roomId + } }, - { new: true }, + { new: true } ); if (!user) { throw new BadRequestException('user does not exist'); @@ -325,7 +328,7 @@ export class UserRepository { const user = await this.userModel.findOneAndUpdate( { _id: userIdDto.userId }, [{ $set: { chatAlarm: { $eq: [false, '$chatAlarm'] } } }], - { new: true }, + { new: true } ); if (!user) { @@ -342,14 +345,14 @@ export class UserRepository { async turnOnChatAlarm(userIdDto: UserIdDto): Promise { const user = await this.userModel.findOneAndUpdate( { - _id: userIdDto.userId, + _id: userIdDto.userId }, { $set: { - chatAlarm: true, - }, + chatAlarm: true + } }, - { new: true }, + { new: true } ); if (!user) { throw new BadRequestException('user does not exist'); @@ -359,27 +362,27 @@ export class UserRepository { } async findMyFavoriteRooms( - userIdDto: UserIdDto, + userIdDto: UserIdDto ): Promise { const myFavoriteRoomList = await this.userModel.aggregate([ { $match: { - _id: userIdDto.userId, - }, + _id: userIdDto.userId + } }, { $lookup: { from: 'room', localField: 'favoriteRoomList', foreignField: '_id', - as: 'favoriteRoomList', - }, + as: 'favoriteRoomList' + } }, { - $unwind: '$favoriteRoomList', + $unwind: '$favoriteRoomList' }, { - $replaceRoot: { newRoot: '$favoriteRoomList' }, + $replaceRoot: { newRoot: '$favoriteRoomList' } }, { $project: { @@ -387,10 +390,11 @@ export class UserRepository { name: 1, category: 1, geometry: 1, - userCount: { $size: '$userList' }, - }, + subtitle: 1, + userCount: { $size: '$userList' } + } }, - { $sort: { userCount: -1 } }, + { $sort: { userCount: -1 } } ]); // .populate("favoriteRoomList" , {}); @@ -399,19 +403,19 @@ export class UserRepository { async setMyRoom( userIdDto: UserIdDto, - roomId: RoomIdDto | null, + roomId: RoomIdDto | null ): Promise { const user = await this.userModel.findOneAndUpdate( { - _id: userIdDto.userId, + _id: userIdDto.userId }, { $set: { // 룸에서 나간경우 Null로 설정 - myRoom: roomId ? roomId.roomId : null, - }, + myRoom: roomId ? roomId.roomId : null + } }, - { new: true }, + { new: true } ); if (!user) { throw new BadRequestException('user does not exist'); @@ -424,22 +428,22 @@ export class UserRepository { const roomInfo = await this.userModel.aggregate([ { $match: { - _id: userIdDto.userId, - }, + _id: userIdDto.userId + } }, { $lookup: { from: 'room', localField: 'myRoom', foreignField: '_id', - as: 'myRoom', - }, + as: 'myRoom' + } }, { - $unwind: '$myRoom', + $unwind: '$myRoom' }, { - $replaceRoot: { newRoot: '$myRoom' }, + $replaceRoot: { newRoot: '$myRoom' } }, { $project: { @@ -447,9 +451,10 @@ export class UserRepository { name: 1, category: 1, geometry: 1, - userCount: { $size: '$userList' }, - }, - }, + subtitle: 1, + userCount: { $size: '$userList' } + } + } ]); console.log(roomInfo); @@ -460,7 +465,7 @@ export class UserRepository { return (await this.userModel.findOneAndUpdate( { _id: userIdDto.userId }, { $inc: { lightningScore: 1 } }, - { new: true }, + { new: true } )) as User; } @@ -468,12 +473,12 @@ export class UserRepository { return (await this.userModel.findOneAndUpdate( { _id: userIdDto.userId }, { level: userlevel }, - { new: true }, + { new: true } )) as User; } async findUserFcmToken( - userIdArray: Types.ObjectId[], + userIdArray: Types.ObjectId[] ): Promise { return await this.userModel .find({ _id: { $in: userIdArray } }) @@ -483,12 +488,12 @@ export class UserRepository { async updateUserFCMToken( myUserIdDto: UserIdDto, - FCMTokenDto: FCMUpdateDto, + FCMTokenDto: FCMUpdateDto ): Promise { const user = await this.userModel.findOneAndUpdate( { _id: myUserIdDto.userId }, { FCMToken: FCMTokenDto.FCMToken }, - { new: true }, + { new: true } ); console.log(user); if (!user) { @@ -502,7 +507,7 @@ export class UserRepository { .findOneAndUpdate( { _id: myUserIdDto.userId }, [{ $set: { flagInfo: { $eq: [false, '$flagInfo'] } } }], - { new: true }, + { new: true } ) .lean({ defaults: true }); if (!user) {