Skip to content

Commit

Permalink
feat: channel 정보 보낼 때 유저 정보를 같이 보내도록 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
soomanbaek authored and NaayoungKwon committed Dec 1, 2022
1 parent a8d5324 commit e7d8404
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
7 changes: 5 additions & 2 deletions server/apps/api/src/channel/channel.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ export class ChannelController {
async createChannel(@Body() createChannelDto: CreateChannelDto, @Req() req: any) {
const requestUserId = req.user._id;
try {
await this.channelService.createChannel({ ...createChannelDto, managerId: requestUserId });
return responseForm(200, { message: '채널 생성 성공!' });
const newChannel = await this.channelService.createChannel({
...createChannelDto,
managerId: requestUserId,
});
return responseForm(200, newChannel);
} catch (error) {
this.logger.error(JSON.stringify(error.response));
throw error;
Expand Down
13 changes: 11 additions & 2 deletions server/apps/api/src/channel/channel.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ export class ChannelService {
// 공개 채널일 경우 : 채널 유저에 커뮤니티 사용자 모두 존재
await this.addUserToChannel(community._id, channel._id, community.users);
}

return getChannelBasicInfo(channel);
}

async modifyChannel(modifyChannelDto: ModifyChannelDto) {
Expand Down Expand Up @@ -86,8 +88,15 @@ export class ChannelService {
}

async getChannelInfo(channel_id) {
const channelInfo = await this.channelRepository.findOne({ _id: channel_id });
return getChannelBasicInfo(channelInfo);
const channel = await this.channelRepository.findOne({ _id: channel_id });
const users = await Promise.all(
channel.users.map(async (user_id) => {
const user = await this.userRepository.findById(user_id);
return getUserBasicInfo(user);
}),
);
channel['users'] = users as any;
return getChannelBasicInfo(channel);
}

async exitChannel(exitChannelDto: ExitChannelDto) {
Expand Down
1 change: 0 additions & 1 deletion server/apps/api/src/channel/helper/getChannelBasicInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export const getChannelBasicInfo = (channel) => {
type: channel.type,
isPrivate: channel.isPrivate,
users: channel.users,
chatLists: channel.chatLists,
deletedAt: channel.deletedAt,
};
};

0 comments on commit e7d8404

Please sign in to comment.