From 43a76a79c7804543cacb38ec1a94b42837deb718 Mon Sep 17 00:00:00 2001 From: NaayoungKwon Date: Sat, 26 Nov 2022 00:41:36 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=BB=A4=EB=AE=A4=EB=8B=88=ED=8B=B0=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=20=EC=A0=84=EB=8B=AC=20=EC=8B=9C=20=EC=BB=A4?= =?UTF-8?q?=EB=AE=A4=EB=8B=88=ED=8B=B0=20=EB=B0=8F=20=EC=B1=84=EB=84=90?= =?UTF-8?q?=EC=9D=98=20=EA=B8=B0=EB=B3=B8=20=EC=A0=95=EB=B3=B4=20=ED=8F=AC?= =?UTF-8?q?=ED=95=A8=20=20#115?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/src/channel/dto/channel-basic-info.dto.ts | 11 +++++++++++ .../apps/api/src/community/community.service.ts | 15 ++++++++++----- .../src/community/dto/community-basic-info.dto.ts | 10 ++++++++++ 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 server/apps/api/src/channel/dto/channel-basic-info.dto.ts create mode 100644 server/apps/api/src/community/dto/community-basic-info.dto.ts diff --git a/server/apps/api/src/channel/dto/channel-basic-info.dto.ts b/server/apps/api/src/channel/dto/channel-basic-info.dto.ts new file mode 100644 index 00000000..66aa558f --- /dev/null +++ b/server/apps/api/src/channel/dto/channel-basic-info.dto.ts @@ -0,0 +1,11 @@ +export const getChannelBasicInfo = (channel) => { + return { + _id: channel._id, + name: channel.name, + managerId: channel.managerId, + type: channel.type, + isPrivate: channel.isPrivate, + profileUrl: channel.profileUrl, + description: channel.description, + }; +}; diff --git a/server/apps/api/src/community/community.service.ts b/server/apps/api/src/community/community.service.ts index 83b58722..57115574 100644 --- a/server/apps/api/src/community/community.service.ts +++ b/server/apps/api/src/community/community.service.ts @@ -10,6 +10,8 @@ import { import { IsUserInCommunity, makeCommunityObj } from '@community/helper'; import { communityInUser } from '@user/dto/community-in-user.dto'; import { ChannelRepository } from '@repository/channel.repository'; +import { getCommunityBasicInfo } from '@community/dto/community-basic-info.dto'; +import { getChannelBasicInfo } from '@api/src/channel/dto/channel-basic-info.dto'; @Injectable() export class CommunityService { @@ -19,8 +21,8 @@ export class CommunityService { private readonly channelRepository: ChannelRepository, ) {} - async getCommunities(user) { - // const user = await this.userRepository.findById('637f2abb146636e4082885b1'); // 검증용 + async getCommunities(user2) { + const user = await this.userRepository.findById('637f2abb146636e4082885b1'); // 검증용 const infos = []; await Promise.all( Array.from(user.communities.values()).map(async (userCommunity) => { @@ -36,7 +38,7 @@ export class CommunityService { console.log(result); throw new BadRequestException('커뮤니티에 없는 비정상적인 채널이 존재합니다.'); } - const info = { [_id]: [] }; + const channelsInfo = []; await Promise.all( Array.from(channels.keys()).map(async (channelId) => { const lastRead = channels.get(channelId); @@ -44,11 +46,14 @@ export class CommunityService { if (!channel || channel.deletedAt) { throw new BadRequestException('존재하지 않는 채널입니다.'); } + const channelInfo = getChannelBasicInfo(channel); // TODO : channel document의 updatedAt 아니고 다르값 비교 - info[_id].push({ [channelId]: lastRead.getTime() >= channel.updatedAt.getTime() }); + channelInfo['lastRead'] = lastRead.getTime() >= channel.updatedAt.getTime(); + channelsInfo.push(channelInfo); }), ); - infos.push(info); + const communityInfo = getCommunityBasicInfo(community, channelsInfo); + infos.push(communityInfo); }), ); return { communities: infos }; diff --git a/server/apps/api/src/community/dto/community-basic-info.dto.ts b/server/apps/api/src/community/dto/community-basic-info.dto.ts new file mode 100644 index 00000000..436d922b --- /dev/null +++ b/server/apps/api/src/community/dto/community-basic-info.dto.ts @@ -0,0 +1,10 @@ +export const getCommunityBasicInfo = (community, channels) => { + return { + _id: community._id, + name: community.name, + managerId: community.managerId, + profileUrl: community.profileUrl, + description: community.description, + channels, + }; +};