Skip to content

Commit

Permalink
refactor: 사용자 document에 커뮤니티 추가 시 객체 생성 #86, #95
Browse files Browse the repository at this point in the history
  • Loading branch information
NaayoungKwon authored and soomanbaek committed Nov 25, 2022
1 parent 0c65e48 commit b732d65
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions server/apps/api/src/community/community.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,14 @@ export class CommunityService {
...createCommunityDto,
users: [createCommunityDto.managerId],
});
const newCommunity = {};
newCommunity[`communities.${community._id.toString()}`] = { _id: community._id.toString() };
const newCommunity = this.makeCommunityObj(community._id.toString());
await this.userRepository.updateObject({ _id: createCommunityDto.managerId }, newCommunity);
return community;
}

async appendParticipantsToCommunity(appendUsersToCommunityDto: AppendUsersToCommunityDto) {
const communityId = appendUsersToCommunityDto.community_id;
const newCommunity = this.makeCommunityObj(communityId);
await Promise.all(
appendUsersToCommunityDto.users.map(async (user_id) => {
const user = await this.userRepository.findById(user_id);
Expand Down Expand Up @@ -110,4 +111,13 @@ export class CommunityService {
},
);
}

makeCommunityObj(community_id: string) {
const newCommunity = {};
newCommunity[`communities.${community_id}`] = {
_id: community_id,
channels: {},
};
return newCommunity;
}
}

0 comments on commit b732d65

Please sign in to comment.