Skip to content

Commit

Permalink
feat: 커뮤니티 정보 전달 시 커뮤니티 및 채널의 기본 정보 포함 #115
Browse files Browse the repository at this point in the history
  • Loading branch information
NaayoungKwon authored and soomanbaek committed Nov 25, 2022
1 parent 11a47c4 commit 43a76a7
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
11 changes: 11 additions & 0 deletions server/apps/api/src/channel/dto/channel-basic-info.dto.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};
15 changes: 10 additions & 5 deletions server/apps/api/src/community/community.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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) => {
Expand All @@ -36,19 +38,22 @@ 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);
const channel = (await this.channelRepository.findById(channelId)) as any;
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 };
Expand Down
10 changes: 10 additions & 0 deletions server/apps/api/src/community/dto/community-basic-info.dto.ts
Original file line number Diff line number Diff line change
@@ -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,
};
};

1 comment on commit 43a76a7

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests Skipped Failures Errors Time
11 0 💤 0 ❌ 0 🔥 1m 9s ⏱️

Please sign in to comment.